2022-04-22 13:22:40 +00:00
|
|
|
package pilorama
|
|
|
|
|
2022-05-27 12:55:02 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
2022-07-05 04:55:46 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode"
|
2022-05-27 12:55:02 +00:00
|
|
|
cidSDK "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
|
|
|
)
|
2022-04-22 13:22:40 +00:00
|
|
|
|
|
|
|
// Forest represents CRDT tree.
|
|
|
|
type Forest interface {
|
|
|
|
// TreeMove moves node in the tree.
|
|
|
|
// If the parent of the move operation is TrashID, the node is removed.
|
|
|
|
// If the child of the move operation is RootID, new ID is generated and added to a tree.
|
2022-05-27 12:55:02 +00:00
|
|
|
TreeMove(d CIDDescriptor, treeID string, m *Move) (*LogMove, error)
|
2022-04-22 13:22:40 +00:00
|
|
|
// TreeAddByPath adds new node in the tree using provided path.
|
|
|
|
// The path is constructed by descending from the root using the values of the attr in meta.
|
2022-05-23 11:32:24 +00:00
|
|
|
// Internal nodes in path should have exactly one attribute, otherwise a new node is created.
|
2022-05-27 12:55:02 +00:00
|
|
|
TreeAddByPath(d CIDDescriptor, treeID string, attr string, path []string, meta []KeyValue) ([]LogMove, error)
|
2022-04-22 13:22:40 +00:00
|
|
|
// TreeApply applies replicated operation from another node.
|
2022-05-27 12:55:02 +00:00
|
|
|
TreeApply(d CIDDescriptor, treeID string, m *Move) error
|
2022-04-22 13:22:40 +00:00
|
|
|
// TreeGetByPath returns all nodes corresponding to the path.
|
|
|
|
// The path is constructed by descending from the root using the values of the
|
|
|
|
// AttributeFilename in meta.
|
|
|
|
// The last argument determines whether only the node with the latest timestamp is returned.
|
2022-05-04 09:47:11 +00:00
|
|
|
// Should return ErrTreeNotFound if the tree is not found, and empty result if the path is not in the tree.
|
2022-04-22 13:22:40 +00:00
|
|
|
TreeGetByPath(cid cidSDK.ID, treeID string, attr string, path []string, latest bool) ([]Node, error)
|
|
|
|
// TreeGetMeta returns meta information of the node with the specified ID.
|
2022-05-04 09:47:11 +00:00
|
|
|
// Should return ErrTreeNotFound if the tree is not found, and empty result if the node is not in the tree.
|
2022-05-20 08:41:37 +00:00
|
|
|
TreeGetMeta(cid cidSDK.ID, treeID string, nodeID Node) (Meta, Node, error)
|
2022-04-29 10:06:10 +00:00
|
|
|
// TreeGetChildren returns children of the node with the specified ID. The order is arbitrary.
|
2022-05-04 09:47:11 +00:00
|
|
|
// Should return ErrTreeNotFound if the tree is not found, and empty result if the node is not in the tree.
|
2022-04-29 10:06:10 +00:00
|
|
|
TreeGetChildren(cid cidSDK.ID, treeID string, nodeID Node) ([]uint64, error)
|
2022-05-11 13:29:04 +00:00
|
|
|
// TreeGetOpLog returns first log operation stored at or above the height.
|
|
|
|
// In case no such operation is found, empty Move and nil error should be returned.
|
|
|
|
TreeGetOpLog(cid cidSDK.ID, treeID string, height uint64) (Move, error)
|
2022-09-07 08:46:13 +00:00
|
|
|
// TreeDrop drops a tree from the database.
|
|
|
|
// If the tree is not found, ErrTreeNotFound should be returned.
|
|
|
|
TreeDrop(cid cidSDK.ID, treeID string) error
|
2022-04-22 13:22:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ForestStorage interface {
|
2022-05-16 13:23:09 +00:00
|
|
|
// DumpInfo returns information about the pilorama.
|
|
|
|
DumpInfo() Info
|
2022-04-22 13:22:40 +00:00
|
|
|
Init() error
|
2022-06-28 13:42:50 +00:00
|
|
|
Open(bool) error
|
2022-04-22 13:22:40 +00:00
|
|
|
Close() error
|
2022-07-05 04:55:46 +00:00
|
|
|
SetMode(m mode.Mode) error
|
2022-04-22 13:22:40 +00:00
|
|
|
Forest
|
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
|
|
|
AttributeFilename = "FileName"
|
|
|
|
AttributeVersion = "Version"
|
|
|
|
)
|
2022-05-27 12:55:02 +00:00
|
|
|
|
|
|
|
// CIDDescriptor contains container ID and information about the node position
|
|
|
|
// in the list of container nodes.
|
|
|
|
type CIDDescriptor struct {
|
|
|
|
CID cidSDK.ID
|
|
|
|
Position int
|
|
|
|
Size int
|
|
|
|
}
|
|
|
|
|
|
|
|
// ErrInvalidCIDDescriptor is returned when info about tne node position
|
|
|
|
// in the container is invalid.
|
|
|
|
var ErrInvalidCIDDescriptor = errors.New("cid descriptor is invalid")
|
|
|
|
|
|
|
|
func (d CIDDescriptor) checkValid() bool {
|
|
|
|
return 0 <= d.Position && d.Position < d.Size
|
|
|
|
}
|