[#927] metabase: Delete GC marks

`key` is changed inside `db.get`, so encode address again after get.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2024-01-24 18:41:02 +03:00
parent 931a5e9aaf
commit 5ed330e436
2 changed files with 43 additions and 0 deletions

View file

@ -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)

View file

@ -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...)