Skip to content

Commit

Permalink
fix: Use clear for mixed batch writer (#1645)
Browse files Browse the repository at this point in the history
Fixes the issue with `cap` used on `nil` slice introduced in #1553
  • Loading branch information
candiduslynx authored Apr 22, 2024
1 parent ca216b6 commit 07945ac
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions writers/mixedbatchwriter/mixedbatchwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ func (m *batchManager[A, T]) flush(ctx context.Context) error {
if err != nil {
return err
}
m.batch = nil
clear(m.batch) // GC can work
m.batch = m.batch[:0]
return nil
}

Expand Down Expand Up @@ -229,7 +230,8 @@ func (m *insertBatchManager) flush(ctx context.Context) error {
}
m.logger.Debug().Int("len", batchSize).Dur("duration", time.Since(start)).Msg("batch written successfully")

m.batch = nil
clear(m.batch) // GC can work
m.batch = m.batch[:0]
m.curBatchSizeBytes = 0
return nil
}

1 comment on commit 07945ac

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏱️ Benchmark results

  • Glob-8 ns/op: 91.34

Please sign in to comment.