``` goos: linux goarch: amd64 pkg: git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase cpu: 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz │ master │ expired │ │ sec/op │ sec/op vs base │ Select/string_equal-8 4.007m ± 10% 3.529m ± 11% -11.94% (p=0.000 n=10) Select/string_not_equal-8 3.834m ± 12% 3.440m ± 7% -10.29% (p=0.029 n=10) Select/common_prefix-8 3.470m ± 9% 3.240m ± 6% ~ (p=0.105 n=10) Select/unknown-8 3.156m ± 3% 3.198m ± 6% ~ (p=0.631 n=10) geomean 3.602m 3.349m -7.03% │ master │ expired │ │ B/op │ B/op vs base │ Select/string_equal-8 1.907Mi ± 0% 1.885Mi ± 0% -1.18% (p=0.000 n=10) Select/string_not_equal-8 1.907Mi ± 0% 1.885Mi ± 0% -1.18% (p=0.000 n=10) Select/common_prefix-8 1.907Mi ± 0% 1.885Mi ± 0% -1.18% (p=0.000 n=10) Select/unknown-8 1.900Mi ± 0% 1.877Mi ± 0% -1.18% (p=0.000 n=10) geomean 1.905Mi 1.883Mi -1.18% │ master │ expired │ │ allocs/op │ allocs/op vs base │ Select/string_equal-8 47.03k ± 0% 46.04k ± 0% -2.12% (p=0.000 n=10) Select/string_not_equal-8 47.03k ± 0% 46.04k ± 0% -2.12% (p=0.000 n=10) Select/common_prefix-8 47.03k ± 0% 46.04k ± 0% -2.12% (p=0.000 n=10) Select/unknown-8 46.04k ± 0% 45.05k ± 0% -2.16% (p=0.000 n=10) geomean 46.78k 45.79k -2.13% ``` Change-Id: I9c7a5e1f5c8b9eb3f25a563fd74c6ad2a9d1b92e Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
68 lines
1.7 KiB
Go
68 lines
1.7 KiB
Go
package meta
|
|
|
|
import (
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
"go.etcd.io/bbolt"
|
|
)
|
|
|
|
type bucketCache struct {
|
|
locked *bbolt.Bucket
|
|
graveyard *bbolt.Bucket
|
|
garbage *bbolt.Bucket
|
|
expired map[cid.ID]*bbolt.Bucket
|
|
}
|
|
|
|
func newBucketCache() *bucketCache {
|
|
return &bucketCache{expired: make(map[cid.ID]*bbolt.Bucket)}
|
|
}
|
|
|
|
func getLockedBucket(bc *bucketCache, tx *bbolt.Tx) *bbolt.Bucket {
|
|
if bc == nil {
|
|
return tx.Bucket(bucketNameLocked)
|
|
}
|
|
return getBucket(&bc.locked, tx, bucketNameLocked)
|
|
}
|
|
|
|
func getGraveyardBucket(bc *bucketCache, tx *bbolt.Tx) *bbolt.Bucket {
|
|
if bc == nil {
|
|
return tx.Bucket(graveyardBucketName)
|
|
}
|
|
return getBucket(&bc.graveyard, tx, graveyardBucketName)
|
|
}
|
|
|
|
func getGarbageBucket(bc *bucketCache, tx *bbolt.Tx) *bbolt.Bucket {
|
|
if bc == nil {
|
|
return tx.Bucket(garbageBucketName)
|
|
}
|
|
return getBucket(&bc.garbage, tx, garbageBucketName)
|
|
}
|
|
|
|
func getBucket(cache **bbolt.Bucket, tx *bbolt.Tx, name []byte) *bbolt.Bucket {
|
|
if *cache != nil {
|
|
return *cache
|
|
}
|
|
|
|
*cache = tx.Bucket(name)
|
|
return *cache
|
|
}
|
|
|
|
func getExpiredBucket(bc *bucketCache, tx *bbolt.Tx, cnr cid.ID) *bbolt.Bucket {
|
|
if bc == nil {
|
|
bucketName := make([]byte, bucketKeySize)
|
|
bucketName = objectToExpirationEpochBucketName(cnr, bucketName)
|
|
return tx.Bucket(bucketName)
|
|
}
|
|
return getMappedBucket(bc.expired, tx, objectToExpirationEpochBucketName, cnr)
|
|
}
|
|
|
|
func getMappedBucket(m map[cid.ID]*bbolt.Bucket, tx *bbolt.Tx, nameFunc func(cid.ID, []byte) []byte, cnr cid.ID) *bbolt.Bucket {
|
|
value, ok := m[cnr]
|
|
if ok {
|
|
return value
|
|
}
|
|
|
|
bucketName := make([]byte, bucketKeySize)
|
|
bucketName = nameFunc(cnr, bucketName)
|
|
m[cnr] = getBucket(&value, tx, bucketName)
|
|
return value
|
|
}
|