[#927] metabase: Delete GC marks
All checks were successful
DCO action / DCO (pull_request) Successful in 6m34s
Vulncheck / Vulncheck (pull_request) Successful in 7m19s
Build / Build Components (1.20) (pull_request) Successful in 7m48s
Build / Build Components (1.21) (pull_request) Successful in 9m39s
Tests and linters / Staticcheck (pull_request) Successful in 10m36s
Tests and linters / Lint (pull_request) Successful in 11m26s
Tests and linters / Tests (1.20) (pull_request) Successful in 12m57s
Tests and linters / Tests (1.21) (pull_request) Successful in 13m8s
Tests and linters / Tests with -race (pull_request) Successful in 13m7s

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