[#1385] metabase: Optimize isTomb
check
All checks were successful
Tests and linters / Run gofumpt (pull_request) Successful in 1m56s
DCO action / DCO (pull_request) Successful in 2m13s
Vulncheck / Vulncheck (pull_request) Successful in 2m22s
Pre-commit hooks / Pre-commit (pull_request) Successful in 2m39s
Build / Build Components (pull_request) Successful in 2m57s
Tests and linters / Staticcheck (pull_request) Successful in 3m19s
Tests and linters / gopls check (pull_request) Successful in 3m20s
Tests and linters / Lint (pull_request) Successful in 3m56s
Tests and linters / Tests (pull_request) Successful in 4m49s
Tests and linters / Tests with -race (pull_request) Successful in 5m47s
All checks were successful
Tests and linters / Run gofumpt (pull_request) Successful in 1m56s
DCO action / DCO (pull_request) Successful in 2m13s
Vulncheck / Vulncheck (pull_request) Successful in 2m22s
Pre-commit hooks / Pre-commit (pull_request) Successful in 2m39s
Build / Build Components (pull_request) Successful in 2m57s
Tests and linters / Staticcheck (pull_request) Successful in 3m19s
Tests and linters / gopls check (pull_request) Successful in 3m20s
Tests and linters / Lint (pull_request) Successful in 3m56s
Tests and linters / Tests (pull_request) Successful in 4m49s
Tests and linters / Tests with -race (pull_request) Successful in 5m47s
As tombstone and target must have the same containerID, do not iterate other containers. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
8b031a54e1
commit
2e35eff8cb
1 changed files with 11 additions and 18 deletions
|
@ -377,11 +377,8 @@ func (db *DB) getInhumeTargetBucketAndValue(garbageBKT, graveyardBKT *bbolt.Buck
|
||||||
return targetBucket, value, nil
|
return targetBucket, value, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) markAsGC(graveyardBKT, garbageBKT *bbolt.Bucket, key []byte) (bool, error) {
|
func (db *DB) markAsGC(graveyardBKT, garbageBKT *bbolt.Bucket, addressKey []byte) (bool, error) {
|
||||||
targetIsTomb, err := isTomb(graveyardBKT, key)
|
targetIsTomb := isTomb(graveyardBKT, addressKey)
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// do not add grave if target is a tombstone
|
// do not add grave if target is a tombstone
|
||||||
if targetIsTomb {
|
if targetIsTomb {
|
||||||
|
@ -390,7 +387,7 @@ func (db *DB) markAsGC(graveyardBKT, garbageBKT *bbolt.Bucket, key []byte) (bool
|
||||||
|
|
||||||
// if tombstone appears object must be
|
// if tombstone appears object must be
|
||||||
// additionally marked with GC
|
// additionally marked with GC
|
||||||
return false, garbageBKT.Put(key, zeroValue)
|
return false, garbageBKT.Put(addressKey, zeroValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) updateDeleteInfo(tx *bbolt.Tx, garbageBKT, graveyardBKT *bbolt.Bucket, targetKey []byte, cnr cid.ID, obj *objectSDK.Object, res *InhumeRes) error {
|
func (db *DB) updateDeleteInfo(tx *bbolt.Tx, garbageBKT, graveyardBKT *bbolt.Bucket, targetKey []byte, cnr cid.ID, obj *objectSDK.Object, res *InhumeRes) error {
|
||||||
|
@ -410,25 +407,21 @@ func (db *DB) updateDeleteInfo(tx *bbolt.Tx, garbageBKT, graveyardBKT *bbolt.Buc
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func isTomb(graveyardBucket *bbolt.Bucket, key []byte) (bool, error) {
|
func isTomb(graveyardBucket *bbolt.Bucket, addressKey []byte) bool {
|
||||||
targetIsTomb := false
|
targetIsTomb := false
|
||||||
|
|
||||||
// iterate over graveyard and check if target address
|
// iterate over graveyard and check if target address
|
||||||
// is the address of tombstone in graveyard.
|
// is the address of tombstone in graveyard.
|
||||||
err := graveyardBucket.ForEach(func(_, v []byte) error {
|
// tombstone must have the same container ID as key.
|
||||||
|
c := graveyardBucket.Cursor()
|
||||||
|
containerPrefix := addressKey[:cidSize]
|
||||||
|
for k, v := c.Seek(containerPrefix); k != nil && bytes.HasPrefix(k, containerPrefix); k, v = c.Next() {
|
||||||
// check if graveyard has record with key corresponding
|
// check if graveyard has record with key corresponding
|
||||||
// to tombstone address (at least one)
|
// to tombstone address (at least one)
|
||||||
targetIsTomb = bytes.Equal(v, key)
|
targetIsTomb = bytes.Equal(v, addressKey)
|
||||||
|
|
||||||
if targetIsTomb {
|
if targetIsTomb {
|
||||||
// break bucket iterator
|
break
|
||||||
return errBreakBucketForEach
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if err != nil && !errors.Is(err, errBreakBucketForEach) {
|
|
||||||
return false, err
|
|
||||||
}
|
}
|
||||||
return targetIsTomb, nil
|
return targetIsTomb
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue