2022-04-22 13:22:40 +00:00
|
|
|
package pilorama
|
|
|
|
|
2022-05-27 12:55:02 +00:00
|
|
|
import (
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr"
|
|
|
|
cidSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
2022-05-27 12:55:02 +00:00
|
|
|
)
|
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.
|
2023-01-25 11:12:02 +00:00
|
|
|
TreeMove(d CIDDescriptor, treeID string, m *Move) (*Move, 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.
|
2023-01-25 11:12:02 +00:00
|
|
|
TreeAddByPath(d CIDDescriptor, treeID string, attr string, path []string, meta []KeyValue) ([]Move, error)
|
2022-04-22 13:22:40 +00:00
|
|
|
// TreeApply applies replicated operation from another node.
|
2022-12-19 16:01:57 +00:00
|
|
|
// If background is true, TreeApply will first check whether an operation exists.
|
|
|
|
TreeApply(d CIDDescriptor, treeID string, m *Move, backgroundSync bool) 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.
|
2022-11-08 12:32:38 +00:00
|
|
|
// In case of empty treeID drops all trees related to container.
|
2022-09-07 08:46:13 +00:00
|
|
|
TreeDrop(cid cidSDK.ID, treeID string) error
|
2022-10-18 11:59:32 +00:00
|
|
|
// TreeList returns all the tree IDs that have been added to the
|
|
|
|
// passed container ID. Nil slice should be returned if no tree found.
|
|
|
|
TreeList(cid cidSDK.ID) ([]string, error)
|
2022-10-06 16:06:19 +00:00
|
|
|
// TreeExists checks if a tree exists locally.
|
|
|
|
// If the tree is not found, false and a nil error should be returned.
|
|
|
|
TreeExists(cid cidSDK.ID, treeID string) (bool, error)
|
2023-01-25 10:25:45 +00:00
|
|
|
// TreeUpdateLastSyncHeight updates last log height synchronized with _all_ container nodes.
|
|
|
|
TreeUpdateLastSyncHeight(cid cidSDK.ID, treeID string, height uint64) error
|
|
|
|
// TreeLastSyncHeight returns last log height synchronized with _all_ container nodes.
|
|
|
|
TreeLastSyncHeight(cid cidSDK.ID, treeID string) (uint64, 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.
|
2022-10-31 07:02:30 +00:00
|
|
|
var ErrInvalidCIDDescriptor = logicerr.New("cid descriptor is invalid")
|
2022-05-27 12:55:02 +00:00
|
|
|
|
|
|
|
func (d CIDDescriptor) checkValid() bool {
|
|
|
|
return 0 <= d.Position && d.Position < d.Size
|
|
|
|
}
|