@@ -200,11 +200,7 @@ func (c *Cache) CreateSnapshots(ctx context.Context, w map[uint32]io.Writer) (ui
200
200
hashRangesMap [hashRange ] = struct {}{}
201
201
}
202
202
203
- var (
204
- maxVersion uint64
205
- keysToDelete = make ([][]byte , 0 )
206
- keysToDeleteMu = sync.Mutex {}
207
- )
203
+ var maxVersion uint64
208
204
stream := c .cache .NewStream ()
209
205
stream .NumGo = c .conf .GetInt ("BadgerDB.Dedup.Snapshots.NumGoroutines" , 10 )
210
206
stream .Prefix = []byte ("hr" )
@@ -216,13 +212,7 @@ func (c *Cache) CreateSnapshots(ctx context.Context, w map[uint32]io.Writer) (ui
216
212
hashRange , _ := strconv .ParseUint (string (parts [0 ][2 :]), 10 , 32 )
217
213
_ , ok = hashRangesMap [uint32 (hashRange )]
218
214
}
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
226
216
}
227
217
stream .Send = func (buf * z.Buffer ) error {
228
218
list , err := badger .BufferToKVList (buf )
@@ -292,37 +282,6 @@ func (c *Cache) CreateSnapshots(ctx context.Context, w map[uint32]io.Writer) (ui
292
282
c .snapshotting = false
293
283
c .snapshottingLock .Unlock ()
294
284
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
-
326
285
return since , nil
327
286
}
328
287
0 commit comments