metabase: Delete GC marks #927
2 changed files with 43 additions and 0 deletions
|
@ -264,6 +264,7 @@ func (db *DB) delete(tx *bbolt.Tx, addr oid.Address, refCounter referenceCounter
|
|||
return deleteSingleResult{}, err
|
||||
}
|
||||
|
||||
addrKey = addressKey(addr, key)
|
||||
// remove record from the garbage bucket
|
||||
if garbageBKT != nil {
|
||||
err := garbageBKT.Delete(addrKey)
|
||||
|
|
|
@ -140,6 +140,48 @@ func TestExpiredObject(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestDelete(t *testing.T) {
|
||||
db := newDB(t, meta.WithEpochState(epochState{currEpoch}))
|
||||
defer func() { require.NoError(t, db.Close()) }()
|
||||
|
||||
cnr := cidtest.ID()
|
||||
for i := 0; i < 10; i++ {
|
||||
obj := testutil.GenerateObjectWithCID(cnr)
|
||||
|
||||
var prm meta.PutPrm
|
||||
prm.SetObject(obj)
|
||||
prm.SetStorageID([]byte("0/0"))
|
||||
_, err := db.Put(context.Background(), prm)
|
||||
require.NoError(t, err)
|
||||
|
||||
var inhumePrm meta.InhumePrm
|
||||
inhumePrm.SetAddresses(object.AddressOf(obj))
|
||||
_, err = db.Inhume(context.Background(), inhumePrm)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
var addrs []oid.Address
|
||||
var iprm meta.GarbageIterationPrm
|
||||
iprm.SetHandler(func(o meta.GarbageObject) error {
|
||||
addrs = append(addrs, o.Address())
|
||||
return nil
|
||||
})
|
||||
require.NoError(t, db.IterateOverGarbage(context.Background(), iprm))
|
||||
require.Equal(t, 10, len(addrs))
|
||||
var deletePrm meta.DeletePrm
|
||||
deletePrm.SetAddresses(addrs...)
|
||||
_, err := db.Delete(context.Background(), deletePrm)
|
||||
require.NoError(t, err)
|
||||
|
||||
addrs = nil
|
||||
iprm.SetHandler(func(o meta.GarbageObject) error {
|
||||
addrs = append(addrs, o.Address())
|
||||
return nil
|
||||
})
|
||||
require.NoError(t, db.IterateOverGarbage(context.Background(), iprm))
|
||||
require.Equal(t, 0, len(addrs))
|
||||
}
|
||||
|
||||
func metaDelete(db *meta.DB, addrs ...oid.Address) error {
|
||||
var deletePrm meta.DeletePrm
|
||||
deletePrm.SetAddresses(addrs...)
|
||||
|
|
Loading…
Reference in a new issue