2022-04-22 13:29:43 +00:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
2022-05-16 13:02:35 +00:00
|
|
|
"errors"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/pilorama"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard"
|
|
|
|
cidSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
2022-05-04 09:42:32 +00:00
|
|
|
"go.uber.org/zap"
|
2022-04-22 13:29:43 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ pilorama.Forest = (*StorageEngine)(nil)
|
|
|
|
|
|
|
|
// TreeMove implements the pilorama.Forest interface.
|
2023-01-25 11:12:02 +00:00
|
|
|
func (e *StorageEngine) TreeMove(d pilorama.CIDDescriptor, treeID string, m *pilorama.Move) (*pilorama.Move, error) {
|
2022-10-06 16:06:19 +00:00
|
|
|
index, lst, err := e.getTreeShard(d.CID, treeID)
|
2022-12-07 13:27:13 +00:00
|
|
|
if err != nil && !errors.Is(err, pilorama.ErrTreeNotFound) {
|
2022-10-06 16:06:19 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
lm, err := lst[index].TreeMove(d, treeID, m)
|
|
|
|
if err != nil {
|
|
|
|
if !errors.Is(err, shard.ErrReadOnlyMode) && err != shard.ErrPiloramaDisabled {
|
|
|
|
e.reportShardError(lst[index], "can't perform `TreeMove`", err,
|
2022-05-16 14:20:18 +00:00
|
|
|
zap.Stringer("cid", d.CID),
|
|
|
|
zap.String("tree", treeID))
|
2022-04-22 13:29:43 +00:00
|
|
|
}
|
2022-10-06 16:06:19 +00:00
|
|
|
|
|
|
|
return nil, err
|
2022-04-22 13:29:43 +00:00
|
|
|
}
|
2022-10-06 16:06:19 +00:00
|
|
|
return lm, nil
|
2022-04-22 13:29:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TreeAddByPath implements the pilorama.Forest interface.
|
2023-01-25 11:12:02 +00:00
|
|
|
func (e *StorageEngine) TreeAddByPath(d pilorama.CIDDescriptor, treeID string, attr string, path []string, m []pilorama.KeyValue) ([]pilorama.Move, error) {
|
2022-10-06 16:06:19 +00:00
|
|
|
index, lst, err := e.getTreeShard(d.CID, treeID)
|
2022-10-06 16:06:19 +00:00
|
|
|
if err != nil && !errors.Is(err, pilorama.ErrTreeNotFound) {
|
2022-10-06 16:06:19 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
lm, err := lst[index].TreeAddByPath(d, treeID, attr, path, m)
|
|
|
|
if err != nil {
|
|
|
|
if !errors.Is(err, shard.ErrReadOnlyMode) && err != shard.ErrPiloramaDisabled {
|
|
|
|
e.reportShardError(lst[index], "can't perform `TreeAddByPath`", err,
|
2022-05-16 14:20:18 +00:00
|
|
|
zap.Stringer("cid", d.CID),
|
|
|
|
zap.String("tree", treeID))
|
2022-04-22 13:29:43 +00:00
|
|
|
}
|
2022-10-06 16:06:19 +00:00
|
|
|
return nil, err
|
2022-04-22 13:29:43 +00:00
|
|
|
}
|
2022-10-06 16:06:19 +00:00
|
|
|
return lm, nil
|
2022-04-22 13:29:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TreeApply implements the pilorama.Forest interface.
|
2022-12-19 16:01:57 +00:00
|
|
|
func (e *StorageEngine) TreeApply(d pilorama.CIDDescriptor, treeID string, m *pilorama.Move, backgroundSync bool) error {
|
2022-10-06 16:06:19 +00:00
|
|
|
index, lst, err := e.getTreeShard(d.CID, treeID)
|
2022-10-06 16:06:19 +00:00
|
|
|
if err != nil && !errors.Is(err, pilorama.ErrTreeNotFound) {
|
2022-10-06 16:06:19 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-12-19 16:01:57 +00:00
|
|
|
err = lst[index].TreeApply(d, treeID, m, backgroundSync)
|
2022-10-06 16:06:19 +00:00
|
|
|
if err != nil {
|
|
|
|
if !errors.Is(err, shard.ErrReadOnlyMode) && err != shard.ErrPiloramaDisabled {
|
|
|
|
e.reportShardError(lst[index], "can't perform `TreeApply`", err,
|
2022-05-16 14:20:18 +00:00
|
|
|
zap.Stringer("cid", d.CID),
|
|
|
|
zap.String("tree", treeID))
|
2022-04-22 13:29:43 +00:00
|
|
|
}
|
2022-10-06 16:06:19 +00:00
|
|
|
return err
|
2022-04-22 13:29:43 +00:00
|
|
|
}
|
2022-10-06 16:06:19 +00:00
|
|
|
return nil
|
2022-04-22 13:29:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TreeGetByPath implements the pilorama.Forest interface.
|
|
|
|
func (e *StorageEngine) TreeGetByPath(cid cidSDK.ID, treeID string, attr string, path []string, latest bool) ([]pilorama.Node, error) {
|
|
|
|
var err error
|
|
|
|
var nodes []pilorama.Node
|
|
|
|
for _, sh := range e.sortShardsByWeight(cid) {
|
|
|
|
nodes, err = sh.TreeGetByPath(cid, treeID, attr, path, latest)
|
|
|
|
if err != nil {
|
2022-07-30 04:31:13 +00:00
|
|
|
if err == shard.ErrPiloramaDisabled {
|
|
|
|
break
|
|
|
|
}
|
2022-05-16 14:20:18 +00:00
|
|
|
if !errors.Is(err, pilorama.ErrTreeNotFound) {
|
|
|
|
e.reportShardError(sh, "can't perform `TreeGetByPath`", err,
|
|
|
|
zap.Stringer("cid", cid),
|
|
|
|
zap.String("tree", treeID))
|
|
|
|
}
|
2022-04-22 13:29:43 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
return nodes, nil
|
|
|
|
}
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// TreeGetMeta implements the pilorama.Forest interface.
|
2022-05-20 08:41:37 +00:00
|
|
|
func (e *StorageEngine) TreeGetMeta(cid cidSDK.ID, treeID string, nodeID pilorama.Node) (pilorama.Meta, uint64, error) {
|
2022-04-22 13:29:43 +00:00
|
|
|
var err error
|
|
|
|
var m pilorama.Meta
|
2022-05-20 08:41:37 +00:00
|
|
|
var p uint64
|
2022-04-22 13:29:43 +00:00
|
|
|
for _, sh := range e.sortShardsByWeight(cid) {
|
2022-05-20 08:41:37 +00:00
|
|
|
m, p, err = sh.TreeGetMeta(cid, treeID, nodeID)
|
2022-04-22 13:29:43 +00:00
|
|
|
if err != nil {
|
2022-07-30 04:31:13 +00:00
|
|
|
if err == shard.ErrPiloramaDisabled {
|
|
|
|
break
|
|
|
|
}
|
2022-05-16 14:20:18 +00:00
|
|
|
if !errors.Is(err, pilorama.ErrTreeNotFound) {
|
|
|
|
e.reportShardError(sh, "can't perform `TreeGetMeta`", err,
|
|
|
|
zap.Stringer("cid", cid),
|
|
|
|
zap.String("tree", treeID))
|
|
|
|
}
|
2022-04-22 13:29:43 +00:00
|
|
|
continue
|
|
|
|
}
|
2022-05-20 08:41:37 +00:00
|
|
|
return m, p, nil
|
2022-04-22 13:29:43 +00:00
|
|
|
}
|
2022-05-20 08:41:37 +00:00
|
|
|
return pilorama.Meta{}, 0, err
|
2022-04-22 13:29:43 +00:00
|
|
|
}
|
2022-04-29 10:06:10 +00:00
|
|
|
|
|
|
|
// TreeGetChildren implements the pilorama.Forest interface.
|
|
|
|
func (e *StorageEngine) TreeGetChildren(cid cidSDK.ID, treeID string, nodeID pilorama.Node) ([]uint64, error) {
|
|
|
|
var err error
|
|
|
|
var nodes []uint64
|
|
|
|
for _, sh := range e.sortShardsByWeight(cid) {
|
|
|
|
nodes, err = sh.TreeGetChildren(cid, treeID, nodeID)
|
|
|
|
if err != nil {
|
2022-07-30 04:31:13 +00:00
|
|
|
if err == shard.ErrPiloramaDisabled {
|
|
|
|
break
|
|
|
|
}
|
2022-05-16 14:20:18 +00:00
|
|
|
if !errors.Is(err, pilorama.ErrTreeNotFound) {
|
|
|
|
e.reportShardError(sh, "can't perform `TreeGetChildren`", err,
|
|
|
|
zap.Stringer("cid", cid),
|
|
|
|
zap.String("tree", treeID))
|
|
|
|
}
|
2022-04-29 10:06:10 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
return nodes, nil
|
|
|
|
}
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-05-11 13:29:04 +00:00
|
|
|
|
|
|
|
// TreeGetOpLog implements the pilorama.Forest interface.
|
|
|
|
func (e *StorageEngine) TreeGetOpLog(cid cidSDK.ID, treeID string, height uint64) (pilorama.Move, error) {
|
|
|
|
var err error
|
|
|
|
var lm pilorama.Move
|
|
|
|
for _, sh := range e.sortShardsByWeight(cid) {
|
|
|
|
lm, err = sh.TreeGetOpLog(cid, treeID, height)
|
|
|
|
if err != nil {
|
2022-07-30 04:31:13 +00:00
|
|
|
if err == shard.ErrPiloramaDisabled {
|
|
|
|
break
|
|
|
|
}
|
2022-05-16 14:20:18 +00:00
|
|
|
if !errors.Is(err, pilorama.ErrTreeNotFound) {
|
|
|
|
e.reportShardError(sh, "can't perform `TreeGetOpLog`", err,
|
|
|
|
zap.Stringer("cid", cid),
|
|
|
|
zap.String("tree", treeID))
|
|
|
|
}
|
2022-05-11 13:29:04 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
return lm, nil
|
|
|
|
}
|
|
|
|
return lm, err
|
|
|
|
}
|
2022-09-07 08:46:13 +00:00
|
|
|
|
|
|
|
// TreeDrop implements the pilorama.Forest interface.
|
|
|
|
func (e *StorageEngine) TreeDrop(cid cidSDK.ID, treeID string) error {
|
|
|
|
var err error
|
|
|
|
for _, sh := range e.sortShardsByWeight(cid) {
|
|
|
|
err = sh.TreeDrop(cid, treeID)
|
|
|
|
if err != nil {
|
|
|
|
if err == shard.ErrPiloramaDisabled {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if !errors.Is(err, pilorama.ErrTreeNotFound) && !errors.Is(err, shard.ErrReadOnlyMode) {
|
|
|
|
e.reportShardError(sh, "can't perform `TreeDrop`", err,
|
|
|
|
zap.Stringer("cid", cid),
|
|
|
|
zap.String("tree", treeID))
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
2022-10-18 11:59:32 +00:00
|
|
|
|
|
|
|
// TreeList implements the pilorama.Forest interface.
|
|
|
|
func (e *StorageEngine) TreeList(cid cidSDK.ID) ([]string, error) {
|
2022-10-18 15:22:29 +00:00
|
|
|
var resIDs []string
|
2022-10-18 12:49:40 +00:00
|
|
|
|
2022-10-18 15:22:29 +00:00
|
|
|
for _, sh := range e.unsortedShards() {
|
|
|
|
ids, err := sh.TreeList(cid)
|
2022-10-18 12:49:40 +00:00
|
|
|
if err != nil {
|
|
|
|
if errors.Is(err, shard.ErrPiloramaDisabled) || errors.Is(err, shard.ErrReadOnlyMode) {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
e.reportShardError(sh, "can't perform `TreeList`", err,
|
|
|
|
zap.Stringer("cid", cid))
|
|
|
|
|
2022-10-18 15:22:29 +00:00
|
|
|
// returns as much info about
|
|
|
|
// trees as possible
|
2022-10-18 12:49:40 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2022-10-18 15:22:29 +00:00
|
|
|
resIDs = append(resIDs, ids...)
|
2022-10-18 12:49:40 +00:00
|
|
|
}
|
|
|
|
|
2022-10-18 15:22:29 +00:00
|
|
|
return resIDs, nil
|
2022-10-18 11:59:32 +00:00
|
|
|
}
|
2022-10-06 16:06:19 +00:00
|
|
|
|
|
|
|
// TreeExists implements the pilorama.Forest interface.
|
|
|
|
func (e *StorageEngine) TreeExists(cid cidSDK.ID, treeID string) (bool, error) {
|
|
|
|
_, _, err := e.getTreeShard(cid, treeID)
|
|
|
|
if errors.Is(err, pilorama.ErrTreeNotFound) {
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
return err == nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *StorageEngine) getTreeShard(cid cidSDK.ID, treeID string) (int, []hashedShard, error) {
|
|
|
|
lst := e.sortShardsByWeight(cid)
|
|
|
|
for i, sh := range lst {
|
|
|
|
exists, err := sh.TreeExists(cid, treeID)
|
|
|
|
if err != nil {
|
|
|
|
return 0, nil, err
|
|
|
|
}
|
|
|
|
if exists {
|
|
|
|
return i, lst, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0, lst, pilorama.ErrTreeNotFound
|
|
|
|
}
|