[#1493] metabase: Merge Inhume() and DropGraves() for tombstones
All checks were successful
DCO action / DCO (pull_request) Successful in 51s
Vulncheck / Vulncheck (pull_request) Successful in 2m11s
Pre-commit hooks / Pre-commit (pull_request) Successful in 2m41s
Build / Build Components (pull_request) Successful in 2m51s
Tests and linters / Staticcheck (pull_request) Successful in 2m44s
Tests and linters / Run gofumpt (pull_request) Successful in 2m46s
Tests and linters / gopls check (pull_request) Successful in 3m48s
Tests and linters / Lint (pull_request) Successful in 4m8s
Tests and linters / Tests (pull_request) Successful in 4m18s
Tests and linters / Tests with -race (pull_request) Successful in 4m38s

DropGraves() is only used to drop gravemarks after a tombstone
removal. Thus, it makes sense to do Inhume() and DropGraves() in one
transaction. It has less overhead and no unexpected problems in case
of sudden power failure.

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2024-10-18 14:22:07 +03:00
parent cdde125f9d
commit 11366f56b6
Signed by: fyrchik
SSH key fingerprint: SHA256:m/TTwCzjnRkXgnzEx9X92ccxy1CcVeinOgDb3NPWWmg
4 changed files with 30 additions and 52 deletions

View file

@ -130,17 +130,9 @@ func TestDeleteECObject_WithoutSplit(t *testing.T) {
require.NoError(t, db.IterateOverGraveyard(context.Background(), graveyardIterationPrm)) require.NoError(t, db.IterateOverGraveyard(context.Background(), graveyardIterationPrm))
require.Equal(t, 2, len(tombstonedObjects)) require.Equal(t, 2, len(tombstonedObjects))
var tombstones []oid.Address _, err = db.InhumeTombstones(context.Background(), tombstonedObjects)
for _, tss := range tombstonedObjects {
tombstones = append(tombstones, tss.tomb)
}
inhumePrm.SetAddresses(tombstones...)
inhumePrm.SetGCMark()
_, err = db.Inhume(context.Background(), inhumePrm)
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.DropGraves(context.Background(), tombstonedObjects))
// GC finds tombstone as garbage and deletes it // GC finds tombstone as garbage and deletes it
garbageAddresses = nil garbageAddresses = nil
@ -374,17 +366,9 @@ func testDeleteECObjectWithSplit(t *testing.T, chunksCount int, withLinking bool
require.NoError(t, db.IterateOverGraveyard(context.Background(), graveyardIterationPrm)) require.NoError(t, db.IterateOverGraveyard(context.Background(), graveyardIterationPrm))
require.True(t, len(tombstonedObjects) == parentCount+chunksCount) require.True(t, len(tombstonedObjects) == parentCount+chunksCount)
var tombstones []oid.Address _, err = db.InhumeTombstones(context.Background(), tombstonedObjects)
for _, tss := range tombstonedObjects {
tombstones = append(tombstones, tss.tomb)
}
inhumePrm.SetAddresses(tombstones...)
inhumePrm.SetGCMark()
_, err = db.Inhume(context.Background(), inhumePrm)
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, db.DropGraves(context.Background(), tombstonedObjects))
// GC finds tombstone as garbage and deletes it // GC finds tombstone as garbage and deletes it
garbageAddresses = nil garbageAddresses = nil

View file

@ -9,6 +9,7 @@ import (
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/metaerr" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/metaerr"
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing" "git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
"go.etcd.io/bbolt" "go.etcd.io/bbolt"
) )
@ -255,46 +256,58 @@ func graveFromKV(k, v []byte) (res TombstonedObject, err error) {
return return
} }
// DropGraves deletes tombstoned objects from the // InhumeTombstones deletes tombstoned objects from the
// graveyard bucket. // graveyard bucket.
// //
// Returns any error appeared during deletion process. // Returns any error appeared during deletion process.
func (db *DB) DropGraves(ctx context.Context, tss []TombstonedObject) error { func (db *DB) InhumeTombstones(ctx context.Context, tss []TombstonedObject) (InhumeRes, error) {
var ( var (
startedAt = time.Now() startedAt = time.Now()
success = false success = false
) )
defer func() { defer func() {
db.metrics.AddMethodDuration("DropGraves", time.Since(startedAt), success) db.metrics.AddMethodDuration("InhumeTombstones", time.Since(startedAt), success)
}() }()
_, span := tracing.StartSpanFromContext(ctx, "metabase.DropGraves") _, span := tracing.StartSpanFromContext(ctx, "metabase.InhumeTombstones")
defer span.End() defer span.End()
db.modeMtx.RLock() db.modeMtx.RLock()
defer db.modeMtx.RUnlock() defer db.modeMtx.RUnlock()
if db.mode.NoMetabase() { if db.mode.NoMetabase() {
return ErrDegradedMode return InhumeRes{}, ErrDegradedMode
} else if db.mode.ReadOnly() { } else if db.mode.ReadOnly() {
return ErrReadOnlyMode return InhumeRes{}, ErrReadOnlyMode
} }
buf := make([]byte, addressKeySize) buf := make([]byte, addressKeySize)
prm := InhumePrm{forceRemoval: true}
currEpoch := db.epochState.CurrentEpoch()
return db.boltDB.Batch(func(tx *bbolt.Tx) error { var res InhumeRes
bkt := tx.Bucket(graveyardBucketName)
if bkt == nil { err := db.boltDB.Batch(func(tx *bbolt.Tx) error {
return nil res = InhumeRes{inhumedByCnrID: make(map[cid.ID]ObjectCounters)}
garbageBKT := tx.Bucket(garbageBucketName)
graveyardBKT := tx.Bucket(graveyardBucketName)
bkt, value, err := db.getInhumeTargetBucketAndValue(garbageBKT, graveyardBKT, prm)
if err != nil {
return err
} }
for _, ts := range tss { for i := range tss {
err := bkt.Delete(addressKey(ts.Address(), buf)) if err := db.inhumeTxSingle(bkt, value, graveyardBKT, garbageBKT, tss[i].Tombstone(), buf, currEpoch, prm, &res); err != nil {
if err != nil { return err
}
if err := graveyardBKT.Delete(addressKey(tss[i].Address(), buf)); err != nil {
return err return err
} }
} }
return nil return nil
}) })
return res, err
} }

View file

@ -435,7 +435,7 @@ func TestDB_DropGraves(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, 2, counter) require.Equal(t, 2, counter)
err = db.DropGraves(context.Background(), buriedTS) _, err = db.InhumeTombstones(context.Background(), buriedTS)
require.NoError(t, err) require.NoError(t, err)
counter = 0 counter = 0

View file

@ -634,19 +634,7 @@ func (s *Shard) HandleExpiredTombstones(ctx context.Context, tss []meta.Tombston
return return
} }
// Mark tombstones as garbage. res, err := s.metaBase.InhumeTombstones(ctx, tss)
var pInhume meta.InhumePrm
tsAddrs := make([]oid.Address, 0, len(tss))
for _, ts := range tss {
tsAddrs = append(tsAddrs, ts.Tombstone())
}
pInhume.SetGCMark()
pInhume.SetAddresses(tsAddrs...)
// inhume tombstones
res, err := s.metaBase.Inhume(ctx, pInhume)
if err != nil { if err != nil {
s.log.Warn(ctx, logs.ShardCouldNotMarkTombstonesAsGarbage, s.log.Warn(ctx, logs.ShardCouldNotMarkTombstonesAsGarbage,
zap.String("error", err.Error()), zap.String("error", err.Error()),
@ -666,13 +654,6 @@ func (s *Shard) HandleExpiredTombstones(ctx context.Context, tss []meta.Tombston
s.addToContainerSize(delInfo.CID.EncodeToString(), -int64(delInfo.Size)) s.addToContainerSize(delInfo.CID.EncodeToString(), -int64(delInfo.Size))
i++ i++
} }
// drop just processed expired tombstones
// from graveyard
err = s.metaBase.DropGraves(ctx, tss)
if err != nil {
s.log.Warn(ctx, logs.ShardCouldNotDropExpiredGraveRecords, zap.Error(err))
}
} }
// HandleExpiredLocks unlocks all objects which were locked by lockers. // HandleExpiredLocks unlocks all objects which were locked by lockers.