@@ -288,7 +288,6 @@ func (db *DB) GetGarbage(limit int) ([]oid.Address, []cid.ID, error) {
288288 initCap := min (limit , reasonableLimit )
289289
290290 var addrBuff oid.Address
291- var cidBuff cid.ID
292291 alreadyHandledContainers := make (map [cid.ID ]struct {})
293292 resObjects := make ([]oid.Address , 0 , initCap )
294293 resContainers := make ([]cid.ID , 0 )
@@ -299,26 +298,34 @@ func (db *DB) GetGarbage(limit int) ([]oid.Address, []cid.ID, error) {
299298 // also be deleted as a part of non-existing
300299 // container so no need to handle it twice
301300
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 )
309310 }
311+ return nil
312+ })
313+ if err != nil {
314+ return fmt .Errorf ("scanning inhumed containers: %w" , err )
315+ }
310316
311- resObjects , err = listContainerObjects (tx , cidBuff , resObjects , limit )
317+ for _ , cnr := range inhumedCnrs {
318+ resObjects , err = listContainerObjects (tx , cnr , resObjects , limit )
312319 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 )
314321 }
315322
316- alreadyHandledContainers [cidBuff ] = struct {}{}
323+ alreadyHandledContainers [cnr ] = struct {}{}
317324
318325 if len (resObjects ) < limit {
319326 // all the objects from the container were listed,
320327 // container can be removed
321- resContainers = append (resContainers , cidBuff )
328+ resContainers = append (resContainers , cnr )
322329 } else {
323330 return nil
324331 }
@@ -327,8 +334,8 @@ func (db *DB) GetGarbage(limit int) ([]oid.Address, []cid.ID, error) {
327334 // deleted containers are not enough to reach the limit,
328335 // check manually deleted objects then
329336
330- bkt = tx .Bucket (garbageObjectsBucketName )
331- c = bkt .Cursor ()
337+ bkt : = tx .Bucket (garbageObjectsBucketName )
338+ c : = bkt .Cursor ()
332339
333340 for k , _ := c .First (); k != nil ; k , _ = c .Next () {
334341 err := decodeAddressFromKey (& addrBuff , k )
0 commit comments