Skip to content

Commit

Permalink
fix: dedup - use writeBatch to put keys in badger (#5204)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidddddarth authored Oct 17, 2024
1 parent bf2b4c6 commit 9683021
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions services/dedup/badger/badger.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,17 @@ func (d *BadgerDB) Get(key string) (int64, bool, error) {

func (d *BadgerDB) Set(kvs []types.KeyValue) error {
defer d.stats.NewTaggedStat("dedup_commit_duration_seconds", stats.TimerType, stats.Tags{"mode": "badger"}).RecordDuration()()

txn := d.badgerDB.NewTransaction(true)
for _, message := range kvs {
wb := d.badgerDB.NewWriteBatch()
defer wb.Cancel()
for i := range kvs {
message := kvs[i]
value := strconv.FormatInt(message.Value, 10)
e := badger.NewEntry([]byte(message.Key), []byte(value)).WithTTL(d.window.Load())
err := txn.SetEntry(e)
if err == badger.ErrTxnTooBig {
if err = txn.Commit(); err != nil {
return err
}
txn = d.badgerDB.NewTransaction(true)
if err = txn.SetEntry(e); err != nil {
return err
}
} else if err != nil {
if err := wb.SetEntry(e); err != nil {
return err
}
}
return txn.Commit()
return wb.Flush()
}

func (d *BadgerDB) Close() {
Expand Down

0 comments on commit 9683021

Please sign in to comment.