Skip to content

Commit 1db7ce5

Browse files
committed
chore: removing expired keys deletion
1 parent 6ca53f1 commit 1db7ce5

File tree

1 file changed

+2
-43
lines changed

1 file changed

+2
-43
lines changed

internal/cache/badger/badger.go

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,7 @@ func (c *Cache) CreateSnapshots(ctx context.Context, w map[uint32]io.Writer) (ui
200200
hashRangesMap[hashRange] = struct{}{}
201201
}
202202

203-
var (
204-
maxVersion uint64
205-
keysToDelete = make([][]byte, 0)
206-
keysToDeleteMu = sync.Mutex{}
207-
)
203+
var maxVersion uint64
208204
stream := c.cache.NewStream()
209205
stream.NumGo = c.conf.GetInt("BadgerDB.Dedup.Snapshots.NumGoroutines", 10)
210206
stream.Prefix = []byte("hr")
@@ -216,13 +212,7 @@ func (c *Cache) CreateSnapshots(ctx context.Context, w map[uint32]io.Writer) (ui
216212
hashRange, _ := strconv.ParseUint(string(parts[0][2:]), 10, 32)
217213
_, ok = hashRangesMap[uint32(hashRange)]
218214
}
219-
if hasExpired || !ok {
220-
keysToDeleteMu.Lock()
221-
keysToDelete = append(keysToDelete, item.Key())
222-
keysToDeleteMu.Unlock()
223-
return false
224-
}
225-
return true
215+
return ok
226216
}
227217
stream.Send = func(buf *z.Buffer) error {
228218
list, err := badger.BufferToKVList(buf)
@@ -292,37 +282,6 @@ func (c *Cache) CreateSnapshots(ctx context.Context, w map[uint32]io.Writer) (ui
292282
c.snapshotting = false
293283
c.snapshottingLock.Unlock()
294284

295-
if len(keysToDelete) > 0 {
296-
batchSize := c.conf.GetInt("BadgerDB.Dedup.Snapshots.DeleteBatchSize", 1000)
297-
keysToDeleteBatch := make([][]byte, 0, batchSize)
298-
deleteKeys := func() error {
299-
err := c.cache.Update(func(txn *badger.Txn) error {
300-
for _, key := range keysToDeleteBatch {
301-
return txn.Delete(key)
302-
}
303-
return nil
304-
})
305-
if err != nil {
306-
return fmt.Errorf("failed to delete keys: %w", err)
307-
}
308-
keysToDeleteBatch = make([][]byte, 0, batchSize)
309-
return nil
310-
}
311-
for _, key := range keysToDelete {
312-
keysToDeleteBatch = append(keysToDeleteBatch, key)
313-
if len(keysToDeleteBatch) == batchSize {
314-
if err := deleteKeys(); err != nil {
315-
return 0, fmt.Errorf("failed to delete keys: %w", err)
316-
}
317-
}
318-
}
319-
if len(keysToDeleteBatch) > 0 {
320-
if err := deleteKeys(); err != nil {
321-
return 0, fmt.Errorf("failed to delete keys: %w", err)
322-
}
323-
}
324-
}
325-
326285
return since, nil
327286
}
328287

0 commit comments

Comments
 (0)