2022-07-05 13:47:39 +00:00
|
|
|
package blobovniczatree
|
2020-11-30 08:11:37 +00:00
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"errors"
|
2020-11-30 08:11:37 +00:00
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/compression"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
|
|
"git.frostfs.info/TrueCloudLab/hrw"
|
2020-11-30 08:11:37 +00:00
|
|
|
)
|
|
|
|
|
2022-07-05 13:47:39 +00:00
|
|
|
// Blobovniczas represents the storage of the "small" objects.
|
2020-11-30 08:11:37 +00:00
|
|
|
//
|
|
|
|
// Each object is stored in Blobovnicza's (B-s).
|
|
|
|
// B-s are structured in a multilevel directory hierarchy
|
|
|
|
// with fixed depth and width (configured by BlobStor).
|
|
|
|
//
|
|
|
|
// Example (width = 4, depth = 3):
|
|
|
|
//
|
|
|
|
// x===============================x
|
|
|
|
// |[0] [1] [2] [3]|
|
|
|
|
// | \ / |
|
|
|
|
// | \ / |
|
|
|
|
// | \ / |
|
|
|
|
// | \ / |
|
|
|
|
// |[0] [1] [2] [3]|
|
|
|
|
// | | / |
|
|
|
|
// | | / |
|
|
|
|
// | | / |
|
|
|
|
// | | / |
|
|
|
|
// |[0](F) [1](A) [X] [X]|
|
|
|
|
// x===============================x
|
|
|
|
//
|
|
|
|
// Elements of the deepest level are B-s.
|
|
|
|
// B-s are allocated dynamically. At each moment of the time there is
|
|
|
|
// an active B (ex. A), set of already filled B-s (ex. F) and
|
2022-04-21 11:28:05 +00:00
|
|
|
// a list of not yet initialized B-s (ex. X). After filling the active B
|
2020-11-30 08:11:37 +00:00
|
|
|
// it becomes full, and next B becomes initialized and active.
|
|
|
|
//
|
|
|
|
// Active B and some of the full B-s are cached (LRU). All cached
|
|
|
|
// B-s are intitialized and opened.
|
|
|
|
//
|
|
|
|
// Object is saved as follows:
|
2022-08-19 14:29:53 +00:00
|
|
|
// 1. at each level, according to HRW, the next one is selected and
|
|
|
|
// dives into it until we reach the deepest;
|
|
|
|
// 2. at the B-s level object is saved to the active B. If active B
|
|
|
|
// is full, next B is opened, initialized and cached. If there
|
|
|
|
// is no more X candidates, goto 1 and process next level.
|
2020-11-30 08:11:37 +00:00
|
|
|
//
|
|
|
|
// After the object is saved in B, path concatenation is returned
|
|
|
|
// in system path format as B identifier (ex. "0/1/1" or "3/2/1").
|
2022-07-05 13:47:39 +00:00
|
|
|
type Blobovniczas struct {
|
|
|
|
cfg
|
2020-11-30 08:11:37 +00:00
|
|
|
|
2023-08-30 20:36:48 +00:00
|
|
|
commondbManager *dbManager
|
|
|
|
activeDBManager *activeDBManager
|
2023-08-31 08:32:09 +00:00
|
|
|
dbCache *dbCache
|
2020-11-30 08:11:37 +00:00
|
|
|
}
|
|
|
|
|
2022-07-08 07:09:48 +00:00
|
|
|
var _ common.Storage = (*Blobovniczas)(nil)
|
|
|
|
|
2020-11-30 08:11:37 +00:00
|
|
|
var errPutFailed = errors.New("could not save the object in any blobovnicza")
|
|
|
|
|
2023-08-18 08:14:10 +00:00
|
|
|
// NewBlobovniczaTree returns new instance of blobovniczas tree.
|
2022-07-05 13:47:39 +00:00
|
|
|
func NewBlobovniczaTree(opts ...Option) (blz *Blobovniczas) {
|
|
|
|
blz = new(Blobovniczas)
|
|
|
|
initConfig(&blz.cfg)
|
|
|
|
|
|
|
|
for i := range opts {
|
|
|
|
opts[i](&blz.cfg)
|
|
|
|
}
|
|
|
|
|
2023-08-18 06:08:26 +00:00
|
|
|
if blz.blzLeafWidth == 0 {
|
|
|
|
blz.blzLeafWidth = blz.blzShallowWidth
|
|
|
|
}
|
|
|
|
|
2023-08-30 20:36:48 +00:00
|
|
|
blz.commondbManager = newDBManager(blz.rootPath, blz.blzOpts, blz.blzLeafWidth, blz.readOnly, blz.metrics.Blobovnicza(), blz.log)
|
|
|
|
blz.activeDBManager = newActiveDBManager(blz.commondbManager, blz.blzLeafWidth)
|
2023-08-31 08:32:09 +00:00
|
|
|
blz.dbCache = newDBCache(blz.openedCacheSize, blz.commondbManager)
|
2022-07-05 13:47:39 +00:00
|
|
|
|
|
|
|
return blz
|
2020-11-30 08:11:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// returns hash of the object address.
|
2022-05-31 17:00:41 +00:00
|
|
|
func addressHash(addr *oid.Address, path string) uint64 {
|
2020-11-30 08:11:37 +00:00
|
|
|
var a string
|
|
|
|
|
|
|
|
if addr != nil {
|
2022-05-31 17:00:41 +00:00
|
|
|
a = addr.EncodeToString()
|
2020-11-30 08:11:37 +00:00
|
|
|
}
|
|
|
|
|
2023-06-02 12:39:16 +00:00
|
|
|
return hrw.StringHash(a + path)
|
2020-11-30 08:11:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// converts uint64 to hex string.
|
|
|
|
func u64ToHexString(ind uint64) string {
|
|
|
|
return strconv.FormatUint(ind, 16)
|
|
|
|
}
|
|
|
|
|
|
|
|
// converts uint64 hex string to uint64.
|
|
|
|
func u64FromHexString(str string) uint64 {
|
|
|
|
v, err := strconv.ParseUint(str, 16, 64)
|
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Sprintf("blobovnicza name is not an index %s", str))
|
|
|
|
}
|
|
|
|
|
|
|
|
return v
|
|
|
|
}
|
2022-07-08 11:33:49 +00:00
|
|
|
|
2022-09-20 12:42:56 +00:00
|
|
|
// Type is blobovniczatree storage type used in logs and configuration.
|
|
|
|
const Type = "blobovnicza"
|
|
|
|
|
2022-07-08 11:33:49 +00:00
|
|
|
// Type implements common.Storage.
|
|
|
|
func (b *Blobovniczas) Type() string {
|
2022-09-20 12:42:56 +00:00
|
|
|
return Type
|
2022-07-08 11:33:49 +00:00
|
|
|
}
|
2022-07-11 12:34:17 +00:00
|
|
|
|
2022-10-05 12:11:12 +00:00
|
|
|
// Path implements common.Storage.
|
|
|
|
func (b *Blobovniczas) Path() string {
|
|
|
|
return b.rootPath
|
|
|
|
}
|
|
|
|
|
2022-07-11 12:34:17 +00:00
|
|
|
// SetCompressor implements common.Storage.
|
2022-08-19 14:29:53 +00:00
|
|
|
func (b *Blobovniczas) SetCompressor(cc *compression.Config) {
|
|
|
|
b.compression = cc
|
2022-07-11 12:34:17 +00:00
|
|
|
}
|
2022-11-09 10:59:24 +00:00
|
|
|
|
2023-08-09 12:54:08 +00:00
|
|
|
func (b *Blobovniczas) Compressor() *compression.Config {
|
|
|
|
return b.compression
|
|
|
|
}
|
|
|
|
|
2022-11-09 10:59:24 +00:00
|
|
|
// SetReportErrorFunc implements common.Storage.
|
|
|
|
func (b *Blobovniczas) SetReportErrorFunc(f func(string, error)) {
|
|
|
|
b.reportError = f
|
|
|
|
}
|
2023-06-07 11:39:03 +00:00
|
|
|
|
|
|
|
func (b *Blobovniczas) SetParentID(parentID string) {
|
|
|
|
b.metrics.SetParentID(parentID)
|
|
|
|
}
|