[#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
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:
parent
cdde125f9d
commit
11366f56b6
4 changed files with 30 additions and 52 deletions
|
@ -130,17 +130,9 @@ func TestDeleteECObject_WithoutSplit(t *testing.T) {
|
|||
require.NoError(t, db.IterateOverGraveyard(context.Background(), graveyardIterationPrm))
|
||||
require.Equal(t, 2, len(tombstonedObjects))
|
||||
|
||||
var tombstones []oid.Address
|
||||
for _, tss := range tombstonedObjects {
|
||||
tombstones = append(tombstones, tss.tomb)
|
||||
}
|
||||
inhumePrm.SetAddresses(tombstones...)
|
||||
inhumePrm.SetGCMark()
|
||||
_, err = db.Inhume(context.Background(), inhumePrm)
|
||||
_, err = db.InhumeTombstones(context.Background(), tombstonedObjects)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NoError(t, db.DropGraves(context.Background(), tombstonedObjects))
|
||||
|
||||
// GC finds tombstone as garbage and deletes it
|
||||
|
||||
garbageAddresses = nil
|
||||
|
@ -374,17 +366,9 @@ func testDeleteECObjectWithSplit(t *testing.T, chunksCount int, withLinking bool
|
|||
require.NoError(t, db.IterateOverGraveyard(context.Background(), graveyardIterationPrm))
|
||||
require.True(t, len(tombstonedObjects) == parentCount+chunksCount)
|
||||
|
||||
var tombstones []oid.Address
|
||||
for _, tss := range tombstonedObjects {
|
||||
tombstones = append(tombstones, tss.tomb)
|
||||
}
|
||||
inhumePrm.SetAddresses(tombstones...)
|
||||
inhumePrm.SetGCMark()
|
||||
_, err = db.Inhume(context.Background(), inhumePrm)
|
||||
_, err = db.InhumeTombstones(context.Background(), tombstonedObjects)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NoError(t, db.DropGraves(context.Background(), tombstonedObjects))
|
||||
|
||||
// GC finds tombstone as garbage and deletes it
|
||||
|
||||
garbageAddresses = nil
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/metaerr"
|
||||
"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"
|
||||
"go.etcd.io/bbolt"
|
||||
)
|
||||
|
@ -255,46 +256,58 @@ func graveFromKV(k, v []byte) (res TombstonedObject, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
// DropGraves deletes tombstoned objects from the
|
||||
// InhumeTombstones deletes tombstoned objects from the
|
||||
// graveyard bucket.
|
||||
//
|
||||
// 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 (
|
||||
startedAt = time.Now()
|
||||
success = false
|
||||
)
|
||||
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()
|
||||
|
||||
db.modeMtx.RLock()
|
||||
defer db.modeMtx.RUnlock()
|
||||
|
||||
if db.mode.NoMetabase() {
|
||||
return ErrDegradedMode
|
||||
return InhumeRes{}, ErrDegradedMode
|
||||
} else if db.mode.ReadOnly() {
|
||||
return ErrReadOnlyMode
|
||||
return InhumeRes{}, ErrReadOnlyMode
|
||||
}
|
||||
|
||||
buf := make([]byte, addressKeySize)
|
||||
prm := InhumePrm{forceRemoval: true}
|
||||
currEpoch := db.epochState.CurrentEpoch()
|
||||
|
||||
return db.boltDB.Batch(func(tx *bbolt.Tx) error {
|
||||
bkt := tx.Bucket(graveyardBucketName)
|
||||
if bkt == nil {
|
||||
return nil
|
||||
var res InhumeRes
|
||||
|
||||
err := db.boltDB.Batch(func(tx *bbolt.Tx) error {
|
||||
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 {
|
||||
err := bkt.Delete(addressKey(ts.Address(), buf))
|
||||
if err != nil {
|
||||
for i := range tss {
|
||||
if err := db.inhumeTxSingle(bkt, value, graveyardBKT, garbageBKT, tss[i].Tombstone(), buf, currEpoch, prm, &res); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := graveyardBKT.Delete(addressKey(tss[i].Address(), buf)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
return res, err
|
||||
}
|
||||
|
|
|
@ -435,7 +435,7 @@ func TestDB_DropGraves(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
require.Equal(t, 2, counter)
|
||||
|
||||
err = db.DropGraves(context.Background(), buriedTS)
|
||||
_, err = db.InhumeTombstones(context.Background(), buriedTS)
|
||||
require.NoError(t, err)
|
||||
|
||||
counter = 0
|
||||
|
|
|
@ -634,19 +634,7 @@ func (s *Shard) HandleExpiredTombstones(ctx context.Context, tss []meta.Tombston
|
|||
return
|
||||
}
|
||||
|
||||
// Mark tombstones as garbage.
|
||||
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)
|
||||
res, err := s.metaBase.InhumeTombstones(ctx, tss)
|
||||
if err != nil {
|
||||
s.log.Warn(ctx, logs.ShardCouldNotMarkTombstonesAsGarbage,
|
||||
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))
|
||||
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.
|
||||
|
|
Loading…
Reference in a new issue