[#977] metabase: Do not store root info for small objects
All checks were successful
DCO action / DCO (pull_request) Successful in 1m58s
Vulncheck / Vulncheck (pull_request) Successful in 3m15s
Build / Build Components (1.21) (pull_request) Successful in 4m5s
Build / Build Components (1.20) (pull_request) Successful in 4m18s
Tests and linters / Staticcheck (pull_request) Successful in 5m33s
Tests and linters / Lint (pull_request) Successful in 6m28s
Tests and linters / Tests (1.20) (pull_request) Successful in 8m21s
Tests and linters / Tests with -race (pull_request) Successful in 8m39s
Tests and linters / Tests (1.21) (pull_request) Successful in 8m50s

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2024-02-20 16:44:23 +03:00
parent 2ad433dbcb
commit 0e6fe47292
2 changed files with 33 additions and 13 deletions

View file

@ -248,19 +248,11 @@ func putUniqueIndexes(
}
// index root object
if obj.Type() == objectSDK.TypeRegular && !obj.HasParent() {
var (
err error
splitInfo []byte
)
if isParent {
splitInfo, err = si.Marshal()
if err != nil {
return fmt.Errorf("can't marshal split info: %w", err)
}
if obj.Type() == objectSDK.TypeRegular && !obj.HasParent() && isParent {
splitInfo, err := si.Marshal()
if err != nil {
return fmt.Errorf("can't marshal split info: %w", err)
}
err = putUniqueIndexItem(tx, namedBucketItem{
name: rootBucketName(cnr, bucketName),
key: objKey,

View file

@ -181,6 +181,34 @@ func selectAllFromBucket(tx *bbolt.Tx, name []byte, to map[string]int, fNum int)
})
}
// selectAllFromBucket goes through all keys in bucket and adds them in a
// resulting cache. Keys should be stringed object ids.
func selectRootObjects(tx *bbolt.Tx, cnr cid.ID, to map[string]int, fNum int) {
rootBkt := tx.Bucket(rootBucketName(cnr, make([]byte, bucketKeySize)))
if rootBkt != nil {
_ = rootBkt.ForEach(func(k, _ []byte) error {
markAddressInCache(to, fNum, string(k))
return nil
})
}
primaryBkt := tx.Bucket(primaryBucketName(cnr, make([]byte, bucketKeySize)))
if primaryBkt == nil {
return
}
_ = primaryBkt.ForEach(func(objectID, rawObject []byte) error {
obj := objectSDK.New()
if obj.Unmarshal(rawObject) != nil {
return nil
}
if !obj.HasParent() {
markAddressInCache(to, fNum, string(objectID))
}
return nil
})
}
// selectFastFilter makes fast optimized checks for well known buckets or
// looking through user attribute buckets otherwise.
func (db *DB) selectFastFilter(
@ -212,7 +240,7 @@ func (db *DB) selectFastFilter(
bucketName := splitBucketName(cnr, bucketName)
db.selectFromList(tx, bucketName, f, to, fNum)
case v2object.FilterPropertyRoot:
selectAllFromBucket(tx, rootBucketName(cnr, bucketName), to, fNum)
selectRootObjects(tx, cnr, to, fNum)
case v2object.FilterPropertyPhy:
selectAllFromBucket(tx, primaryBucketName(cnr, bucketName), to, fNum)
selectAllFromBucket(tx, tombstoneBucketName(cnr, bucketName), to, fNum)