2022-04-22 13:29:43 +00:00
|
|
|
package shard
|
|
|
|
|
|
|
|
import (
|
2023-04-13 12:36:20 +00:00
|
|
|
"context"
|
2023-08-16 15:30:33 +00:00
|
|
|
"strconv"
|
2023-04-13 12:36:20 +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/util/logicerr"
|
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-04-22 13:29:43 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ pilorama.Forest = (*Shard)(nil)
|
|
|
|
|
2022-07-18 10:16:23 +00:00
|
|
|
// ErrPiloramaDisabled is returned when pilorama was disabled in the configuration.
|
2022-10-31 07:02:30 +00:00
|
|
|
var ErrPiloramaDisabled = logicerr.New("pilorama is disabled")
|
2022-07-18 10:16:23 +00:00
|
|
|
|
2022-04-22 13:29:43 +00:00
|
|
|
// TreeMove implements the pilorama.Forest interface.
|
2023-04-13 12:36:20 +00:00
|
|
|
func (s *Shard) TreeMove(ctx context.Context, d pilorama.CIDDescriptor, treeID string, m *pilorama.Move) (*pilorama.Move, error) {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "Shard.TreeMove",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("shard_id", s.ID().String()),
|
|
|
|
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()
|
|
|
|
|
2022-07-18 10:16:23 +00:00
|
|
|
if s.pilorama == nil {
|
|
|
|
return nil, ErrPiloramaDisabled
|
|
|
|
}
|
2022-12-07 17:42:35 +00:00
|
|
|
|
|
|
|
s.m.RLock()
|
|
|
|
defer s.m.RUnlock()
|
|
|
|
|
|
|
|
if s.info.Mode.ReadOnly() {
|
2022-05-16 13:02:35 +00:00
|
|
|
return nil, ErrReadOnlyMode
|
|
|
|
}
|
2023-04-05 07:46:59 +00:00
|
|
|
if s.info.Mode.NoMetabase() {
|
|
|
|
return nil, ErrDegradedMode
|
|
|
|
}
|
2023-04-13 12:36:20 +00:00
|
|
|
return s.pilorama.TreeMove(ctx, d, treeID, m)
|
2022-04-22 13:29:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TreeAddByPath implements the pilorama.Forest interface.
|
2023-04-13 12:36:20 +00:00
|
|
|
func (s *Shard) TreeAddByPath(ctx context.Context, d pilorama.CIDDescriptor, treeID string, attr string, path []string, meta []pilorama.KeyValue) ([]pilorama.Move, error) {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "Shard.TreeAddByPath",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("shard_id", s.ID().String()),
|
|
|
|
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(meta)),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
defer span.End()
|
|
|
|
|
2022-07-18 10:16:23 +00:00
|
|
|
if s.pilorama == nil {
|
|
|
|
return nil, ErrPiloramaDisabled
|
|
|
|
}
|
2022-12-07 17:42:35 +00:00
|
|
|
|
|
|
|
s.m.RLock()
|
|
|
|
defer s.m.RUnlock()
|
|
|
|
|
|
|
|
if s.info.Mode.ReadOnly() {
|
2022-05-16 13:02:35 +00:00
|
|
|
return nil, ErrReadOnlyMode
|
|
|
|
}
|
2023-04-05 07:46:59 +00:00
|
|
|
if s.info.Mode.NoMetabase() {
|
|
|
|
return nil, ErrDegradedMode
|
|
|
|
}
|
2023-04-13 12:36:20 +00:00
|
|
|
return s.pilorama.TreeAddByPath(ctx, d, treeID, attr, path, meta)
|
2022-04-22 13:29:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TreeApply implements the pilorama.Forest interface.
|
2023-04-13 12:36:20 +00:00
|
|
|
func (s *Shard) TreeApply(ctx context.Context, cnr cidSDK.ID, treeID string, m *pilorama.Move, backgroundSync bool) error {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "Shard.TreeApply",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("shard_id", s.ID().String()),
|
|
|
|
attribute.String("container_id", cnr.EncodeToString()),
|
|
|
|
attribute.String("tree_id", treeID),
|
|
|
|
attribute.Bool("background", backgroundSync),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
defer span.End()
|
|
|
|
|
2022-07-18 10:16:23 +00:00
|
|
|
if s.pilorama == nil {
|
|
|
|
return ErrPiloramaDisabled
|
|
|
|
}
|
2022-12-07 17:42:35 +00:00
|
|
|
|
|
|
|
s.m.RLock()
|
|
|
|
defer s.m.RUnlock()
|
|
|
|
|
|
|
|
if s.info.Mode.ReadOnly() {
|
2022-05-16 13:02:35 +00:00
|
|
|
return ErrReadOnlyMode
|
|
|
|
}
|
2023-04-05 07:46:59 +00:00
|
|
|
if s.info.Mode.NoMetabase() {
|
|
|
|
return ErrDegradedMode
|
|
|
|
}
|
2023-04-13 12:36:20 +00:00
|
|
|
return s.pilorama.TreeApply(ctx, cnr, treeID, m, backgroundSync)
|
2022-04-22 13:29:43 +00:00
|
|
|
}
|
|
|
|
|
2024-10-30 08:02:52 +00:00
|
|
|
// TreeApplyBatch implements the pilorama.Forest interface.
|
|
|
|
func (s *Shard) TreeApplyBatch(ctx context.Context, cnr cidSDK.ID, treeID string, m []*pilorama.Move) error {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "Shard.TreeApplyBatch",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("shard_id", s.ID().String()),
|
|
|
|
attribute.String("container_id", cnr.EncodeToString()),
|
|
|
|
attribute.String("tree_id", treeID),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
defer span.End()
|
|
|
|
|
|
|
|
if s.pilorama == nil {
|
|
|
|
return ErrPiloramaDisabled
|
|
|
|
}
|
|
|
|
|
|
|
|
s.m.RLock()
|
|
|
|
defer s.m.RUnlock()
|
|
|
|
|
|
|
|
if s.info.Mode.ReadOnly() {
|
|
|
|
return ErrReadOnlyMode
|
|
|
|
}
|
|
|
|
if s.info.Mode.NoMetabase() {
|
|
|
|
return ErrDegradedMode
|
|
|
|
}
|
|
|
|
return s.pilorama.TreeApplyBatch(ctx, cnr, treeID, m)
|
|
|
|
}
|
|
|
|
|
2022-04-22 13:29:43 +00:00
|
|
|
// TreeGetByPath implements the pilorama.Forest interface.
|
2023-04-13 12:36:20 +00:00
|
|
|
func (s *Shard) TreeGetByPath(ctx context.Context, cid cidSDK.ID, treeID string, attr string, path []string, latest bool) ([]pilorama.Node, error) {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "Shard.TreeGetByPath",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("shard_id", s.ID().String()),
|
|
|
|
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-07-18 10:16:23 +00:00
|
|
|
if s.pilorama == nil {
|
|
|
|
return nil, ErrPiloramaDisabled
|
|
|
|
}
|
2023-04-05 07:46:59 +00:00
|
|
|
|
|
|
|
s.m.RLock()
|
|
|
|
defer s.m.RUnlock()
|
|
|
|
|
|
|
|
if s.info.Mode.NoMetabase() {
|
|
|
|
return nil, ErrDegradedMode
|
|
|
|
}
|
2023-04-13 12:36:20 +00:00
|
|
|
return s.pilorama.TreeGetByPath(ctx, cid, treeID, attr, path, latest)
|
2022-04-22 13:29:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TreeGetMeta implements the pilorama.Forest interface.
|
2023-04-13 12:36:20 +00:00
|
|
|
func (s *Shard) TreeGetMeta(ctx context.Context, cid cidSDK.ID, treeID string, nodeID pilorama.Node) (pilorama.Meta, uint64, error) {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "Shard.TreeGetMeta",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("shard_id", s.ID().String()),
|
|
|
|
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-07-18 10:16:23 +00:00
|
|
|
if s.pilorama == nil {
|
|
|
|
return pilorama.Meta{}, 0, ErrPiloramaDisabled
|
|
|
|
}
|
2023-04-05 07:46:59 +00:00
|
|
|
|
|
|
|
s.m.RLock()
|
|
|
|
defer s.m.RUnlock()
|
|
|
|
|
|
|
|
if s.info.Mode.NoMetabase() {
|
|
|
|
return pilorama.Meta{}, 0, ErrDegradedMode
|
|
|
|
}
|
2023-04-13 12:36:20 +00:00
|
|
|
return s.pilorama.TreeGetMeta(ctx, cid, treeID, nodeID)
|
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 (s *Shard) 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, "Shard.TreeGetChildren",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("shard_id", s.ID().String()),
|
|
|
|
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-07-18 10:16:23 +00:00
|
|
|
if s.pilorama == nil {
|
|
|
|
return nil, ErrPiloramaDisabled
|
|
|
|
}
|
2023-04-05 07:46:59 +00:00
|
|
|
|
|
|
|
s.m.RLock()
|
|
|
|
defer s.m.RUnlock()
|
|
|
|
|
|
|
|
if s.info.Mode.NoMetabase() {
|
|
|
|
return nil, ErrDegradedMode
|
|
|
|
}
|
2023-04-13 12:36:20 +00:00
|
|
|
return s.pilorama.TreeGetChildren(ctx, cid, treeID, nodeID)
|
2022-04-29 10:06:10 +00:00
|
|
|
}
|
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 (s *Shard) 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, "Shard.TreeSortedByFilename",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("shard_id", s.ID().String()),
|
|
|
|
attribute.String("container_id", cid.EncodeToString()),
|
|
|
|
attribute.String("tree_id", treeID),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
defer span.End()
|
|
|
|
|
|
|
|
if s.pilorama == nil {
|
2024-04-04 07:40:21 +00:00
|
|
|
return nil, last, ErrPiloramaDisabled
|
2024-03-28 12:53:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
s.m.RLock()
|
|
|
|
defer s.m.RUnlock()
|
|
|
|
|
|
|
|
if s.info.Mode.NoMetabase() {
|
2024-04-04 07:40:21 +00:00
|
|
|
return nil, last, ErrDegradedMode
|
2024-03-28 12:53:26 +00:00
|
|
|
}
|
|
|
|
return s.pilorama.TreeSortedByFilename(ctx, cid, treeID, nodeID, last, count)
|
|
|
|
}
|
|
|
|
|
2022-05-11 13:29:04 +00:00
|
|
|
// TreeGetOpLog implements the pilorama.Forest interface.
|
2023-04-13 12:36:20 +00:00
|
|
|
func (s *Shard) TreeGetOpLog(ctx context.Context, cid cidSDK.ID, treeID string, height uint64) (pilorama.Move, error) {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "Shard.TreeGetOpLog",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("shard_id", s.ID().String()),
|
|
|
|
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-07-18 10:16:23 +00:00
|
|
|
if s.pilorama == nil {
|
|
|
|
return pilorama.Move{}, ErrPiloramaDisabled
|
|
|
|
}
|
2023-04-05 07:46:59 +00:00
|
|
|
|
|
|
|
s.m.RLock()
|
|
|
|
defer s.m.RUnlock()
|
|
|
|
|
|
|
|
if s.info.Mode.NoMetabase() {
|
|
|
|
return pilorama.Move{}, ErrDegradedMode
|
|
|
|
}
|
2023-04-13 12:36:20 +00:00
|
|
|
return s.pilorama.TreeGetOpLog(ctx, cid, treeID, height)
|
2022-05-11 13:29:04 +00:00
|
|
|
}
|
2022-09-07 08:46:13 +00:00
|
|
|
|
|
|
|
// TreeDrop implements the pilorama.Forest interface.
|
2023-04-13 12:36:20 +00:00
|
|
|
func (s *Shard) TreeDrop(ctx context.Context, cid cidSDK.ID, treeID string) error {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "Shard.TreeDrop",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("shard_id", s.ID().String()),
|
|
|
|
attribute.String("container_id", cid.EncodeToString()),
|
|
|
|
attribute.String("tree_id", treeID),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
defer span.End()
|
|
|
|
|
2022-09-07 08:46:13 +00:00
|
|
|
if s.pilorama == nil {
|
|
|
|
return ErrPiloramaDisabled
|
|
|
|
}
|
2023-04-05 07:46:59 +00:00
|
|
|
|
|
|
|
s.m.RLock()
|
|
|
|
defer s.m.RUnlock()
|
|
|
|
|
|
|
|
if s.info.Mode.NoMetabase() {
|
|
|
|
return ErrDegradedMode
|
|
|
|
}
|
2023-04-13 12:36:20 +00:00
|
|
|
return s.pilorama.TreeDrop(ctx, cid, treeID)
|
2022-09-07 08:46:13 +00:00
|
|
|
}
|
2022-10-18 11:59:32 +00:00
|
|
|
|
|
|
|
// TreeList implements the pilorama.Forest interface.
|
2023-04-13 12:36:20 +00:00
|
|
|
func (s *Shard) TreeList(ctx context.Context, cid cidSDK.ID) ([]string, error) {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "Shard.TreeList",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("shard_id", s.ID().String()),
|
|
|
|
attribute.String("container_id", cid.EncodeToString()),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
defer span.End()
|
|
|
|
|
2022-10-18 12:49:40 +00:00
|
|
|
if s.pilorama == nil {
|
|
|
|
return nil, ErrPiloramaDisabled
|
|
|
|
}
|
2023-04-05 07:46:59 +00:00
|
|
|
|
|
|
|
s.m.RLock()
|
|
|
|
defer s.m.RUnlock()
|
|
|
|
|
|
|
|
if s.info.Mode.NoMetabase() {
|
|
|
|
return nil, ErrDegradedMode
|
|
|
|
}
|
2023-04-13 12:36:20 +00:00
|
|
|
return s.pilorama.TreeList(ctx, cid)
|
2022-10-18 11:59:32 +00:00
|
|
|
}
|
2022-10-06 16:06:19 +00:00
|
|
|
|
2023-06-13 08:26:59 +00:00
|
|
|
func (s *Shard) TreeHeight(ctx context.Context, cid cidSDK.ID, treeID string) (uint64, error) {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "Shard.TreeHeight",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("shard_id", s.ID().String()),
|
|
|
|
attribute.String("container_id", cid.EncodeToString()),
|
|
|
|
attribute.String("tree_id", treeID),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
defer span.End()
|
|
|
|
|
2023-06-20 08:59:18 +00:00
|
|
|
s.m.RLock()
|
|
|
|
defer s.m.RUnlock()
|
|
|
|
|
|
|
|
if s.info.Mode.NoMetabase() {
|
|
|
|
return 0, ErrDegradedMode
|
|
|
|
}
|
|
|
|
|
2023-06-13 08:26:59 +00:00
|
|
|
if s.pilorama == nil {
|
|
|
|
return 0, ErrPiloramaDisabled
|
|
|
|
}
|
|
|
|
return s.pilorama.TreeHeight(ctx, cid, treeID)
|
|
|
|
}
|
|
|
|
|
2022-10-06 16:06:19 +00:00
|
|
|
// TreeExists implements the pilorama.Forest interface.
|
2023-04-13 12:36:20 +00:00
|
|
|
func (s *Shard) TreeExists(ctx context.Context, cid cidSDK.ID, treeID string) (bool, error) {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "Shard.TreeExists",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("shard_id", s.ID().String()),
|
|
|
|
attribute.String("container_id", cid.EncodeToString()),
|
|
|
|
attribute.String("tree_id", treeID),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
defer span.End()
|
|
|
|
|
2022-10-06 16:06:19 +00:00
|
|
|
if s.pilorama == nil {
|
|
|
|
return false, ErrPiloramaDisabled
|
|
|
|
}
|
2023-04-05 07:46:59 +00:00
|
|
|
|
|
|
|
s.m.RLock()
|
|
|
|
defer s.m.RUnlock()
|
|
|
|
|
|
|
|
if s.info.Mode.NoMetabase() {
|
|
|
|
return false, ErrDegradedMode
|
|
|
|
}
|
2023-04-13 12:36:20 +00:00
|
|
|
return s.pilorama.TreeExists(ctx, cid, treeID)
|
2022-10-06 16:06:19 +00:00
|
|
|
}
|
2023-01-25 10:25:45 +00:00
|
|
|
|
|
|
|
// TreeUpdateLastSyncHeight implements the pilorama.Forest interface.
|
2023-04-13 12:36:20 +00:00
|
|
|
func (s *Shard) TreeUpdateLastSyncHeight(ctx context.Context, cid cidSDK.ID, treeID string, height uint64) error {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "Shard.TreeUpdateLastSyncHeight",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("shard_id", s.ID().String()),
|
|
|
|
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()
|
|
|
|
|
2023-01-25 10:25:45 +00:00
|
|
|
if s.pilorama == nil {
|
|
|
|
return ErrPiloramaDisabled
|
|
|
|
}
|
2023-04-05 07:46:59 +00:00
|
|
|
|
|
|
|
s.m.RLock()
|
|
|
|
defer s.m.RUnlock()
|
|
|
|
|
|
|
|
if s.info.Mode.ReadOnly() {
|
|
|
|
return ErrReadOnlyMode
|
|
|
|
}
|
|
|
|
if s.info.Mode.NoMetabase() {
|
|
|
|
return ErrDegradedMode
|
|
|
|
}
|
2023-04-13 12:36:20 +00:00
|
|
|
return s.pilorama.TreeUpdateLastSyncHeight(ctx, cid, treeID, height)
|
2023-01-25 10:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TreeLastSyncHeight implements the pilorama.Forest interface.
|
2023-04-13 12:36:20 +00:00
|
|
|
func (s *Shard) TreeLastSyncHeight(ctx context.Context, cid cidSDK.ID, treeID string) (uint64, error) {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "Shard.TreeLastSyncHeight",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("shard_id", s.ID().String()),
|
|
|
|
attribute.String("container_id", cid.EncodeToString()),
|
|
|
|
attribute.String("tree_id", treeID),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
defer span.End()
|
|
|
|
|
2023-01-25 10:25:45 +00:00
|
|
|
if s.pilorama == nil {
|
|
|
|
return 0, ErrPiloramaDisabled
|
|
|
|
}
|
2023-04-05 07:46:59 +00:00
|
|
|
|
|
|
|
s.m.RLock()
|
|
|
|
defer s.m.RUnlock()
|
|
|
|
|
|
|
|
if s.info.Mode.NoMetabase() {
|
|
|
|
return 0, ErrDegradedMode
|
|
|
|
}
|
2023-04-13 12:36:20 +00:00
|
|
|
return s.pilorama.TreeLastSyncHeight(ctx, cid, treeID)
|
2023-01-25 10:25:45 +00:00
|
|
|
}
|
2024-02-05 11:09:58 +00:00
|
|
|
|
|
|
|
func (s *Shard) TreeListTrees(ctx context.Context, prm pilorama.TreeListTreesPrm) (*pilorama.TreeListTreesResult, error) {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "Shard.TreeListTrees",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("shard_id", s.ID().String()),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
defer span.End()
|
|
|
|
|
|
|
|
if s.pilorama == nil {
|
|
|
|
return nil, ErrPiloramaDisabled
|
|
|
|
}
|
|
|
|
|
|
|
|
s.m.RLock()
|
|
|
|
defer s.m.RUnlock()
|
|
|
|
|
|
|
|
if s.info.Mode.NoMetabase() {
|
|
|
|
return nil, ErrDegradedMode
|
|
|
|
}
|
|
|
|
return s.pilorama.TreeListTrees(ctx, prm)
|
|
|
|
}
|
2024-02-06 10:59:50 +00:00
|
|
|
|
|
|
|
func (s *Shard) PiloramaEnabled() bool {
|
|
|
|
return s.pilorama != nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Shard) TreeApplyStream(ctx context.Context, cnr cidSDK.ID, treeID string, source <-chan *pilorama.Move) error {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "Shard.TreeApplyStream",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("shard_id", s.ID().String()),
|
|
|
|
attribute.String("container_id", cnr.EncodeToString()),
|
|
|
|
attribute.String("tree_id", treeID)),
|
|
|
|
)
|
|
|
|
defer span.End()
|
|
|
|
|
|
|
|
if s.pilorama == nil {
|
|
|
|
return ErrPiloramaDisabled
|
|
|
|
}
|
|
|
|
|
|
|
|
s.m.RLock()
|
|
|
|
defer s.m.RUnlock()
|
|
|
|
|
|
|
|
if s.info.Mode.ReadOnly() {
|
|
|
|
return ErrReadOnlyMode
|
|
|
|
}
|
|
|
|
if s.info.Mode.NoMetabase() {
|
|
|
|
return ErrDegradedMode
|
|
|
|
}
|
|
|
|
return s.pilorama.TreeApplyStream(ctx, cnr, treeID, source)
|
|
|
|
}
|