2022-04-22 13:29:43 +00:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
2023-04-13 12:36:20 +00:00
|
|
|
"context"
|
2022-05-16 13:02:35 +00:00
|
|
|
"errors"
|
2023-08-16 15:30:33 +00:00
|
|
|
"strconv"
|
2022-05-16 13:02:35 +00:00
|
|
|
|
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"
|
2023-09-27 08:02:06 +00:00
|
|
|
tracingPkg "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/tracing"
|
2023-05-31 09:24:04 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
|
2023-03-07 13:38:26 +00:00
|
|
|
cidSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
2023-04-13 12:36:20 +00:00
|
|
|
"go.opentelemetry.io/otel/attribute"
|
|
|
|
"go.opentelemetry.io/otel/trace"
|
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-04-13 12:36:20 +00:00
|
|
|
func (e *StorageEngine) TreeMove(ctx context.Context, d pilorama.CIDDescriptor, treeID string, m *pilorama.Move) (*pilorama.Move, error) {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.TreeMove",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("container_id", d.CID.EncodeToString()),
|
|
|
|
attribute.Int("position", d.Position),
|
|
|
|
attribute.Int("size", d.Size),
|
|
|
|
attribute.String("tree_id", treeID),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
defer span.End()
|
|
|
|
|
|
|
|
index, lst, err := e.getTreeShard(ctx, 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
|
|
|
|
}
|
|
|
|
|
2023-04-13 12:36:20 +00:00
|
|
|
lm, err := lst[index].TreeMove(ctx, d, treeID, m)
|
2022-10-06 16:06:19 +00:00
|
|
|
if err != nil {
|
|
|
|
if !errors.Is(err, shard.ErrReadOnlyMode) && err != shard.ErrPiloramaDisabled {
|
2024-10-21 13:27:28 +00:00
|
|
|
e.reportShardError(ctx, lst[index], "can't perform `TreeMove`", err,
|
2022-05-16 14:20:18 +00:00
|
|
|
zap.Stringer("cid", d.CID),
|
2023-09-27 08:02:06 +00:00
|
|
|
zap.String("tree", treeID),
|
|
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)))
|
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-04-13 12:36:20 +00:00
|
|
|
func (e *StorageEngine) TreeAddByPath(ctx context.Context, d pilorama.CIDDescriptor, treeID string, attr string, path []string, m []pilorama.KeyValue) ([]pilorama.Move, error) {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.TreeAddByPath",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("container_id", d.CID.EncodeToString()),
|
|
|
|
attribute.Int("position", d.Position),
|
|
|
|
attribute.Int("size", d.Size),
|
|
|
|
attribute.String("tree_id", treeID),
|
|
|
|
attribute.String("attr", attr),
|
|
|
|
attribute.Int("path_count", len(path)),
|
|
|
|
attribute.Int("meta_count", len(m)),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
defer span.End()
|
|
|
|
|
|
|
|
index, lst, err := e.getTreeShard(ctx, 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
|
|
|
|
}
|
|
|
|
|
2023-04-13 12:36:20 +00:00
|
|
|
lm, err := lst[index].TreeAddByPath(ctx, d, treeID, attr, path, m)
|
2022-10-06 16:06:19 +00:00
|
|
|
if err != nil {
|
|
|
|
if !errors.Is(err, shard.ErrReadOnlyMode) && err != shard.ErrPiloramaDisabled {
|
2024-10-21 13:27:28 +00:00
|
|
|
e.reportShardError(ctx, lst[index], "can't perform `TreeAddByPath`", err,
|
2022-05-16 14:20:18 +00:00
|
|
|
zap.Stringer("cid", d.CID),
|
2023-09-27 08:02:06 +00:00
|
|
|
zap.String("tree", treeID),
|
|
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)))
|
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.
|
2023-04-13 12:36:20 +00:00
|
|
|
func (e *StorageEngine) TreeApply(ctx context.Context, cnr cidSDK.ID, treeID string, m *pilorama.Move, backgroundSync bool) error {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.TreeApply",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("container_id", cnr.EncodeToString()),
|
|
|
|
attribute.String("tree_id", treeID),
|
|
|
|
attribute.Bool("background", backgroundSync),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
defer span.End()
|
|
|
|
|
|
|
|
index, lst, err := e.getTreeShard(ctx, cnr, 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
|
|
|
|
}
|
|
|
|
|
2023-04-13 12:36:20 +00:00
|
|
|
err = lst[index].TreeApply(ctx, cnr, treeID, m, backgroundSync)
|
2022-10-06 16:06:19 +00:00
|
|
|
if err != nil {
|
|
|
|
if !errors.Is(err, shard.ErrReadOnlyMode) && err != shard.ErrPiloramaDisabled {
|
2024-10-21 13:27:28 +00:00
|
|
|
e.reportShardError(ctx, lst[index], "can't perform `TreeApply`", err,
|
2023-03-21 12:43:12 +00:00
|
|
|
zap.Stringer("cid", cnr),
|
2023-09-27 08:02:06 +00:00
|
|
|
zap.String("tree", treeID),
|
|
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)))
|
2024-10-30 08:02:52 +00:00
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// TreeApplyBatch implements the pilorama.Forest interface.
|
|
|
|
func (e *StorageEngine) TreeApplyBatch(ctx context.Context, cnr cidSDK.ID, treeID string, m []*pilorama.Move) error {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.TreeApplyBatch",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("container_id", cnr.EncodeToString()),
|
|
|
|
attribute.String("tree_id", treeID),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
defer span.End()
|
|
|
|
|
|
|
|
index, lst, err := e.getTreeShard(ctx, cnr, treeID)
|
|
|
|
if err != nil && !errors.Is(err, pilorama.ErrTreeNotFound) {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = lst[index].TreeApplyBatch(ctx, cnr, treeID, m)
|
|
|
|
if err != nil {
|
|
|
|
if !errors.Is(err, shard.ErrReadOnlyMode) && err != shard.ErrPiloramaDisabled {
|
2024-10-21 13:27:28 +00:00
|
|
|
e.reportShardError(ctx, lst[index], "can't perform `TreeApplyBatch`", err,
|
2024-10-30 08:02:52 +00:00
|
|
|
zap.Stringer("cid", cnr),
|
|
|
|
zap.String("tree", treeID),
|
|
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)))
|
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.
|
2023-04-13 12:36:20 +00:00
|
|
|
func (e *StorageEngine) TreeGetByPath(ctx context.Context, cid cidSDK.ID, treeID string, attr string, path []string, latest bool) ([]pilorama.Node, error) {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.TreeGetByPath",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("container_id", cid.EncodeToString()),
|
|
|
|
attribute.String("tree_id", treeID),
|
|
|
|
attribute.String("attr", attr),
|
|
|
|
attribute.Int("path_count", len(path)),
|
|
|
|
attribute.Bool("latest", latest),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
defer span.End()
|
|
|
|
|
2022-04-22 13:29:43 +00:00
|
|
|
var err error
|
|
|
|
var nodes []pilorama.Node
|
2024-02-26 08:19:52 +00:00
|
|
|
for _, sh := range e.sortShards(cid) {
|
2023-04-13 12:36:20 +00:00
|
|
|
nodes, err = sh.TreeGetByPath(ctx, cid, treeID, attr, path, latest)
|
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) {
|
2024-10-21 13:27:28 +00:00
|
|
|
e.reportShardError(ctx, sh, "can't perform `TreeGetByPath`", err,
|
2022-05-16 14:20:18 +00:00
|
|
|
zap.Stringer("cid", cid),
|
2023-09-27 08:02:06 +00:00
|
|
|
zap.String("tree", treeID),
|
|
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)))
|
2022-05-16 14:20:18 +00:00
|
|
|
}
|
2022-04-22 13:29:43 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
return nodes, nil
|
|
|
|
}
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// TreeGetMeta implements the pilorama.Forest interface.
|
2023-04-13 12:36:20 +00:00
|
|
|
func (e *StorageEngine) TreeGetMeta(ctx context.Context, cid cidSDK.ID, treeID string, nodeID pilorama.Node) (pilorama.Meta, uint64, error) {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.TreeGetMeta",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("container_id", cid.EncodeToString()),
|
|
|
|
attribute.String("tree_id", treeID),
|
2023-08-16 15:30:33 +00:00
|
|
|
attribute.String("node_id", strconv.FormatUint(nodeID, 10)),
|
2023-04-13 12:36:20 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
defer span.End()
|
|
|
|
|
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
|
2024-02-26 08:19:52 +00:00
|
|
|
for _, sh := range e.sortShards(cid) {
|
2023-04-13 12:36:20 +00:00
|
|
|
m, p, err = sh.TreeGetMeta(ctx, 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) {
|
2024-10-21 13:27:28 +00:00
|
|
|
e.reportShardError(ctx, sh, "can't perform `TreeGetMeta`", err,
|
2022-05-16 14:20:18 +00:00
|
|
|
zap.Stringer("cid", cid),
|
2023-09-27 08:02:06 +00:00
|
|
|
zap.String("tree", treeID),
|
|
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)))
|
2022-05-16 14:20:18 +00:00
|
|
|
}
|
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.
|
2023-07-11 08:39:17 +00:00
|
|
|
func (e *StorageEngine) TreeGetChildren(ctx context.Context, cid cidSDK.ID, treeID string, nodeID pilorama.Node) ([]pilorama.NodeInfo, error) {
|
2023-04-13 12:36:20 +00:00
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.TreeGetChildren",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("container_id", cid.EncodeToString()),
|
|
|
|
attribute.String("tree_id", treeID),
|
2023-08-16 15:30:33 +00:00
|
|
|
attribute.String("node_id", strconv.FormatUint(nodeID, 10)),
|
2023-04-13 12:36:20 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
defer span.End()
|
|
|
|
|
2022-04-29 10:06:10 +00:00
|
|
|
var err error
|
2023-07-11 08:39:17 +00:00
|
|
|
var nodes []pilorama.NodeInfo
|
2024-02-26 08:19:52 +00:00
|
|
|
for _, sh := range e.sortShards(cid) {
|
2023-04-13 12:36:20 +00:00
|
|
|
nodes, err = sh.TreeGetChildren(ctx, cid, treeID, nodeID)
|
2022-04-29 10:06:10 +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) {
|
2024-10-21 13:27:28 +00:00
|
|
|
e.reportShardError(ctx, sh, "can't perform `TreeGetChildren`", err,
|
2022-05-16 14:20:18 +00:00
|
|
|
zap.Stringer("cid", cid),
|
2023-09-27 08:02:06 +00:00
|
|
|
zap.String("tree", treeID),
|
|
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)))
|
2022-05-16 14:20:18 +00:00
|
|
|
}
|
2022-04-29 10:06:10 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
return nodes, nil
|
|
|
|
}
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-05-11 13:29:04 +00:00
|
|
|
|
2024-03-28 12:53:26 +00:00
|
|
|
// TreeSortedByFilename implements the pilorama.Forest interface.
|
2024-07-10 06:30:01 +00:00
|
|
|
func (e *StorageEngine) TreeSortedByFilename(ctx context.Context, cid cidSDK.ID, treeID string, nodeID pilorama.MultiNode, last *string, count int) ([]pilorama.MultiNodeInfo, *string, error) {
|
2024-03-28 12:53:26 +00:00
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.TreeSortedByFilename",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("container_id", cid.EncodeToString()),
|
|
|
|
attribute.String("tree_id", treeID),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
defer span.End()
|
|
|
|
|
|
|
|
var err error
|
2024-07-10 06:30:01 +00:00
|
|
|
var nodes []pilorama.MultiNodeInfo
|
2024-04-04 07:40:21 +00:00
|
|
|
var cursor *string
|
2024-03-28 12:53:26 +00:00
|
|
|
for _, sh := range e.sortShards(cid) {
|
|
|
|
nodes, cursor, err = sh.TreeSortedByFilename(ctx, cid, treeID, nodeID, last, count)
|
|
|
|
if err != nil {
|
|
|
|
if err == shard.ErrPiloramaDisabled {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if !errors.Is(err, pilorama.ErrTreeNotFound) {
|
2024-10-21 13:27:28 +00:00
|
|
|
e.reportShardError(ctx, sh, "can't perform `TreeSortedByFilename`", err,
|
2024-03-28 12:53:26 +00:00
|
|
|
zap.Stringer("cid", cid),
|
|
|
|
zap.String("tree", treeID),
|
|
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)))
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
return nodes, cursor, nil
|
|
|
|
}
|
|
|
|
return nil, last, err
|
|
|
|
}
|
|
|
|
|
2022-05-11 13:29:04 +00:00
|
|
|
// TreeGetOpLog implements the pilorama.Forest interface.
|
2023-04-13 12:36:20 +00:00
|
|
|
func (e *StorageEngine) TreeGetOpLog(ctx context.Context, cid cidSDK.ID, treeID string, height uint64) (pilorama.Move, error) {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.TreeGetOpLog",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("container_id", cid.EncodeToString()),
|
|
|
|
attribute.String("tree_id", treeID),
|
2023-08-16 15:30:33 +00:00
|
|
|
attribute.String("height", strconv.FormatUint(height, 10)),
|
2023-04-13 12:36:20 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
defer span.End()
|
|
|
|
|
2022-05-11 13:29:04 +00:00
|
|
|
var err error
|
|
|
|
var lm pilorama.Move
|
2024-02-26 08:19:52 +00:00
|
|
|
for _, sh := range e.sortShards(cid) {
|
2023-04-13 12:36:20 +00:00
|
|
|
lm, err = sh.TreeGetOpLog(ctx, cid, treeID, height)
|
2022-05-11 13:29:04 +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) {
|
2024-10-21 13:27:28 +00:00
|
|
|
e.reportShardError(ctx, sh, "can't perform `TreeGetOpLog`", err,
|
2022-05-16 14:20:18 +00:00
|
|
|
zap.Stringer("cid", cid),
|
2023-09-27 08:02:06 +00:00
|
|
|
zap.String("tree", treeID),
|
|
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)))
|
2022-05-16 14:20:18 +00:00
|
|
|
}
|
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.
|
2023-04-13 12:36:20 +00:00
|
|
|
func (e *StorageEngine) TreeDrop(ctx context.Context, cid cidSDK.ID, treeID string) error {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.TreeDrop",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("container_id", cid.EncodeToString()),
|
|
|
|
attribute.String("tree_id", treeID),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
defer span.End()
|
|
|
|
|
2022-09-07 08:46:13 +00:00
|
|
|
var err error
|
2024-02-26 08:19:52 +00:00
|
|
|
for _, sh := range e.sortShards(cid) {
|
2023-04-13 12:36:20 +00:00
|
|
|
err = sh.TreeDrop(ctx, cid, treeID)
|
2022-09-07 08:46:13 +00:00
|
|
|
if err != nil {
|
|
|
|
if err == shard.ErrPiloramaDisabled {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if !errors.Is(err, pilorama.ErrTreeNotFound) && !errors.Is(err, shard.ErrReadOnlyMode) {
|
2024-10-21 13:27:28 +00:00
|
|
|
e.reportShardError(ctx, sh, "can't perform `TreeDrop`", err,
|
2022-09-07 08:46:13 +00:00
|
|
|
zap.Stringer("cid", cid),
|
2023-09-27 08:02:06 +00:00
|
|
|
zap.String("tree", treeID),
|
|
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)))
|
2022-09-07 08:46:13 +00:00
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
2022-10-18 11:59:32 +00:00
|
|
|
|
|
|
|
// TreeList implements the pilorama.Forest interface.
|
2023-04-13 12:36:20 +00:00
|
|
|
func (e *StorageEngine) TreeList(ctx context.Context, cid cidSDK.ID) ([]string, error) {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.TreeList",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("container_id", cid.EncodeToString()),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
defer span.End()
|
|
|
|
|
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() {
|
2023-04-13 12:36:20 +00:00
|
|
|
ids, err := sh.TreeList(ctx, 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
|
|
|
|
}
|
|
|
|
|
2024-10-21 13:27:28 +00:00
|
|
|
e.reportShardError(ctx, sh, "can't perform `TreeList`", err,
|
2023-09-27 08:02:06 +00:00
|
|
|
zap.Stringer("cid", cid),
|
|
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)))
|
2022-10-18 12:49:40 +00:00
|
|
|
|
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.
|
2023-04-13 12:36:20 +00:00
|
|
|
func (e *StorageEngine) TreeExists(ctx context.Context, cid cidSDK.ID, treeID string) (bool, error) {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.TreeExists",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("container_id", cid.EncodeToString()),
|
|
|
|
attribute.String("tree_id", treeID),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
defer span.End()
|
|
|
|
|
|
|
|
_, _, err := e.getTreeShard(ctx, cid, treeID)
|
2022-10-06 16:06:19 +00:00
|
|
|
if errors.Is(err, pilorama.ErrTreeNotFound) {
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
return err == nil, err
|
|
|
|
}
|
|
|
|
|
2023-06-13 08:26:59 +00:00
|
|
|
func (e *StorageEngine) TreeHeight(ctx context.Context, cid cidSDK.ID, treeID string) (uint64, error) {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.TreeHeight",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("container_id", cid.EncodeToString()),
|
|
|
|
attribute.String("tree_id", treeID),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
defer span.End()
|
|
|
|
|
|
|
|
index, lst, err := e.getTreeShard(ctx, cid, treeID)
|
|
|
|
if err != nil {
|
|
|
|
return 0, nil
|
|
|
|
}
|
|
|
|
return lst[index].TreeHeight(ctx, cid, treeID)
|
|
|
|
}
|
|
|
|
|
2023-01-25 10:25:45 +00:00
|
|
|
// TreeUpdateLastSyncHeight implements the pilorama.Forest interface.
|
2023-04-13 12:36:20 +00:00
|
|
|
func (e *StorageEngine) TreeUpdateLastSyncHeight(ctx context.Context, cid cidSDK.ID, treeID string, height uint64) error {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.TreeUpdateLastSyncHeight",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("container_id", cid.EncodeToString()),
|
|
|
|
attribute.String("tree_id", treeID),
|
2023-08-16 15:30:33 +00:00
|
|
|
attribute.String("height", strconv.FormatUint(height, 10)),
|
2023-04-13 12:36:20 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
defer span.End()
|
|
|
|
|
|
|
|
index, lst, err := e.getTreeShard(ctx, cid, treeID)
|
2023-01-25 10:25:45 +00:00
|
|
|
if err != nil && !errors.Is(err, pilorama.ErrTreeNotFound) {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-04-13 12:36:20 +00:00
|
|
|
err = lst[index].TreeUpdateLastSyncHeight(ctx, cid, treeID, height)
|
2023-01-25 10:25:45 +00:00
|
|
|
if err != nil && !errors.Is(err, shard.ErrReadOnlyMode) && err != shard.ErrPiloramaDisabled {
|
2024-10-21 13:27:28 +00:00
|
|
|
e.reportShardError(ctx, lst[index], "can't update tree synchronization height", err,
|
2023-01-25 10:25:45 +00:00
|
|
|
zap.Stringer("cid", cid),
|
2023-09-27 08:02:06 +00:00
|
|
|
zap.String("tree", treeID),
|
|
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)))
|
2023-01-25 10:25:45 +00:00
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// TreeLastSyncHeight implements the pilorama.Forest interface.
|
2023-04-13 12:36:20 +00:00
|
|
|
func (e *StorageEngine) TreeLastSyncHeight(ctx context.Context, cid cidSDK.ID, treeID string) (uint64, error) {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.TreeLastSyncHeight",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("container_id", cid.EncodeToString()),
|
|
|
|
attribute.String("tree_id", treeID),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
defer span.End()
|
|
|
|
|
2023-01-25 10:25:45 +00:00
|
|
|
var err error
|
|
|
|
var height uint64
|
2024-02-26 08:19:52 +00:00
|
|
|
for _, sh := range e.sortShards(cid) {
|
2023-04-13 12:36:20 +00:00
|
|
|
height, err = sh.TreeLastSyncHeight(ctx, cid, treeID)
|
2023-01-25 10:25:45 +00:00
|
|
|
if err != nil {
|
|
|
|
if err == shard.ErrPiloramaDisabled {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if !errors.Is(err, pilorama.ErrTreeNotFound) {
|
2024-10-21 13:27:28 +00:00
|
|
|
e.reportShardError(ctx, sh, "can't read tree synchronization height", err,
|
2023-01-25 10:25:45 +00:00
|
|
|
zap.Stringer("cid", cid),
|
2023-09-27 08:02:06 +00:00
|
|
|
zap.String("tree", treeID),
|
|
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)))
|
2023-01-25 10:25:45 +00:00
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
return height, err
|
|
|
|
}
|
|
|
|
return height, err
|
|
|
|
}
|
|
|
|
|
2023-04-13 12:36:20 +00:00
|
|
|
func (e *StorageEngine) getTreeShard(ctx context.Context, cid cidSDK.ID, treeID string) (int, []hashedShard, error) {
|
2024-02-26 08:19:52 +00:00
|
|
|
lst := e.sortShards(cid)
|
2022-10-06 16:06:19 +00:00
|
|
|
for i, sh := range lst {
|
2023-04-13 12:36:20 +00:00
|
|
|
exists, err := sh.TreeExists(ctx, cid, treeID)
|
2022-10-06 16:06:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return 0, nil, err
|
|
|
|
}
|
|
|
|
if exists {
|
|
|
|
return i, lst, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0, lst, pilorama.ErrTreeNotFound
|
|
|
|
}
|