@@ -288,7 +288,6 @@ func (db *DB) GetGarbage(limit int) ([]oid.Address, []cid.ID, error) {
288
288
initCap := min (limit , reasonableLimit )
289
289
290
290
var addrBuff oid.Address
291
- var cidBuff cid.ID
292
291
alreadyHandledContainers := make (map [cid.ID ]struct {})
293
292
resObjects := make ([]oid.Address , 0 , initCap )
294
293
resContainers := make ([]cid.ID , 0 )
@@ -299,26 +298,34 @@ func (db *DB) GetGarbage(limit int) ([]oid.Address, []cid.ID, error) {
299
298
// also be deleted as a part of non-existing
300
299
// container so no need to handle it twice
301
300
302
- bkt := tx .Bucket (garbageContainersBucketName )
303
- c := bkt .Cursor ()
304
-
305
- for k , _ := c .First (); k != nil ; k , _ = c .Next () {
306
- err := cidBuff .Decode (k )
307
- if err != nil {
308
- return fmt .Errorf ("parsing raw CID: %w" , err )
301
+ var inhumedCnrs []cid.ID
302
+ err := tx .ForEach (func (name []byte , b * bbolt.Bucket ) error {
303
+ if name [0 ] == metadataPrefix && containerMarkedGC (b .Cursor ()) {
304
+ var cnr cid.ID
305
+ cidRaw , prefix := parseContainerIDWithPrefix (& cnr , name )
306
+ if cidRaw == nil || prefix != metadataPrefix {
307
+ return nil
308
+ }
309
+ inhumedCnrs = append (inhumedCnrs , cnr )
309
310
}
311
+ return nil
312
+ })
313
+ if err != nil {
314
+ return fmt .Errorf ("scanning inhumed containers: %w" , err )
315
+ }
310
316
311
- resObjects , err = listContainerObjects (tx , cidBuff , resObjects , limit )
317
+ for _ , cnr := range inhumedCnrs {
318
+ resObjects , err = listContainerObjects (tx , cnr , resObjects , limit )
312
319
if err != nil {
313
- return fmt .Errorf ("listing objects for %s container: %w" , cidBuff , err )
320
+ return fmt .Errorf ("listing objects for %s container: %w" , cnr , err )
314
321
}
315
322
316
- alreadyHandledContainers [cidBuff ] = struct {}{}
323
+ alreadyHandledContainers [cnr ] = struct {}{}
317
324
318
325
if len (resObjects ) < limit {
319
326
// all the objects from the container were listed,
320
327
// container can be removed
321
- resContainers = append (resContainers , cidBuff )
328
+ resContainers = append (resContainers , cnr )
322
329
} else {
323
330
return nil
324
331
}
@@ -327,8 +334,8 @@ func (db *DB) GetGarbage(limit int) ([]oid.Address, []cid.ID, error) {
327
334
// deleted containers are not enough to reach the limit,
328
335
// check manually deleted objects then
329
336
330
- bkt = tx .Bucket (garbageObjectsBucketName )
331
- c = bkt .Cursor ()
337
+ bkt : = tx .Bucket (garbageObjectsBucketName )
338
+ c : = bkt .Cursor ()
332
339
333
340
for k , _ := c .First (); k != nil ; k , _ = c .Next () {
334
341
err := decodeAddressFromKey (& addrBuff , k )
0 commit comments