pilorama

package
v0.44.0-rc.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2024 License: GPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AttributeFilename = "FileName"
	AttributeVersion  = "Version"
)
View Source
const (
	// RootID represents the ID of a root node.
	RootID = 0
	// TrashID is a parent for all removed nodes.
	TrashID = math.MaxUint64
)

Variables

View Source
var (
	// ErrTreeNotFound is returned when the requested tree is not found.
	ErrTreeNotFound = logicerr.New("tree not found")
	// ErrNotPathAttribute is returned when the path is trying to be constructed with a non-internal
	// attribute. Currently the only attribute allowed is AttributeFilename.
	ErrNotPathAttribute = logicerr.New("attribute can't be used in path construction")
)
View Source
var ErrDegradedMode = logicerr.New("pilorama is in a degraded mode")

ErrDegradedMode is returned when pilorama is in a degraded mode.

View Source
var ErrInvalidCIDDescriptor = logicerr.New("cid descriptor is invalid")

ErrInvalidCIDDescriptor is returned when info about tne node position in the container is invalid.

View Source
var ErrReadOnlyMode = logicerr.New("pilorama is in a read-only mode")

ErrReadOnlyMode is returned when pilorama is in a read-only mode.

Functions

func TreeCountAll added in v0.38.0

func TreeCountAll(ctx context.Context, f treeList) (uint64, error)

Types

type CIDDescriptor

type CIDDescriptor struct {
	CID      cidSDK.ID
	Position int
	Size     int
}

CIDDescriptor contains container ID and information about the node position in the list of container nodes.

type ContainerIDTreeID added in v0.38.0

type ContainerIDTreeID struct {
	CID    cidSDK.ID
	TreeID string
}

func TreeListAll added in v0.38.0

func TreeListAll(ctx context.Context, f treeList) ([]ContainerIDTreeID, error)

type Forest

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.
	TreeMove(ctx context.Context, d CIDDescriptor, treeID string, m *Move) (*Move, error)
	// 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.
	// Internal nodes in path should have exactly one attribute, otherwise a new node is created.
	TreeAddByPath(ctx context.Context, d CIDDescriptor, treeID string, attr string, path []string, meta []KeyValue) ([]Move, error)
	// TreeApply applies replicated operation from another node.
	// If background is true, TreeApply will first check whether an operation exists.
	TreeApply(ctx context.Context, cnr cidSDK.ID, treeID string, m *Move, backgroundSync bool) error
	// 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.
	// Should return ErrTreeNotFound if the tree is not found, and empty result if the path is not in the tree.
	TreeGetByPath(ctx context.Context, cid cidSDK.ID, treeID string, attr string, path []string, latest bool) ([]Node, error)
	// TreeGetMeta returns meta information of the node with the specified ID.
	// Should return ErrTreeNotFound if the tree is not found, and empty result if the node is not in the tree.
	TreeGetMeta(ctx context.Context, cid cidSDK.ID, treeID string, nodeID Node) (Meta, Node, error)
	// TreeGetChildren returns children of the node with the specified ID. The order is arbitrary.
	// Should return ErrTreeNotFound if the tree is not found, and empty result if the node is not in the tree.
	TreeGetChildren(ctx context.Context, cid cidSDK.ID, treeID string, nodeID Node) ([]NodeInfo, error)
	// TreeSortedByFilename returns children of the node with the specified ID. The nodes are sorted by the filename attribute..
	// Should return ErrTreeNotFound if the tree is not found, and empty result if the node is not in the tree.
	TreeSortedByFilename(ctx context.Context, cid cidSDK.ID, treeID string, nodeID MultiNode, last *string, count int) ([]MultiNodeInfo, *string, error)
	// 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(ctx context.Context, cid cidSDK.ID, treeID string, height uint64) (Move, error)
	// TreeDrop drops a tree from the database.
	// If the tree is not found, ErrTreeNotFound should be returned.
	// In case of empty treeID drops all trees related to container.
	TreeDrop(ctx context.Context, cid cidSDK.ID, treeID string) error
	// 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(ctx context.Context, cid cidSDK.ID) ([]string, error)
	// TreeExists checks if a tree exists locally.
	// If the tree is not found, false and a nil error should be returned.
	TreeExists(ctx context.Context, cid cidSDK.ID, treeID string) (bool, error)
	// TreeUpdateLastSyncHeight updates last log height synchronized with _all_ container nodes.
	TreeUpdateLastSyncHeight(ctx context.Context, cid cidSDK.ID, treeID string, height uint64) error
	// TreeLastSyncHeight returns last log height synchronized with _all_ container nodes.
	TreeLastSyncHeight(ctx context.Context, cid cidSDK.ID, treeID string) (uint64, error)
	// TreeHeight returns current tree height.
	TreeHeight(ctx context.Context, cid cidSDK.ID, treeID string) (uint64, error)
}

Forest represents CRDT tree.

type ForestStorage

type ForestStorage interface {
	// DumpInfo returns information about the pilorama.
	DumpInfo() Info
	Init() error
	Open(context.Context, mode.Mode) error
	Close() error
	SetMode(m mode.Mode) error
	SetParentID(id string)
	Forest

	// TreeListTrees returns all pairs "containerID:treeID".
	TreeListTrees(ctx context.Context, prm TreeListTreesPrm) (*TreeListTreesResult, error)
	TreeApplyStream(ctx context.Context, cnr cidSDK.ID, treeID string, source <-chan *Move) error
}

func NewBoltForest

func NewBoltForest(opts ...Option) ForestStorage

NewBoltForest returns storage wrapper for storing operations on CRDT trees.

Each tree is stored in a separate bucket by `CID + treeID` key. All integers are stored in little-endian unless explicitly specified otherwise.

DB schema (for a single tree): timestamp is 8-byte, id is 4-byte.

log storage (logBucket): timestamp in big-endian -> log operation

tree storage (dataBucket): - 't' + node (id) -> timestamp when the node first appeared, - 'p' + node (id) -> parent (id), - 'm' + node (id) -> serialized meta, - 'c' + parent (id) + child (id) -> 0/1, - 'i' + 0 + attrKey + 0 + attrValue + 0 + parent (id) + node (id) -> 0/1 (1 for automatically created nodes).

func NewMemoryForest

func NewMemoryForest() ForestStorage

NewMemoryForest creates new empty forest. TODO: this function will eventually be removed and is here for debugging.

type Info

type Info struct {
	// Path contains path to the root-directory of the pilorama.
	Path string
	// Backend is the pilorama storage type. Either "boltdb" or "memory".
	Backend string
}

Info groups the information about the pilorama.

type KeyValue

type KeyValue struct {
	Key   string
	Value []byte
}

KeyValue represents a key-value pair.

type Meta

type Meta struct {
	Time  Timestamp
	Items []KeyValue
}

Meta represents arbitrary meta information. TODO: remove after the debugging or create a proper interface.

func (Meta) Bytes

func (x Meta) Bytes() []byte

func (*Meta) DecodeBinary

func (x *Meta) DecodeBinary(r *io.BinReader)

DecodeBinary implements the io.Serializable interface.

func (Meta) EncodeBinary

func (x Meta) EncodeBinary(w *io.BinWriter)

EncodeBinary implements the io.Serializable interface.

func (*Meta) FromBytes

func (x *Meta) FromBytes(data []byte) error

func (Meta) GetAttr

func (x Meta) GetAttr(name string) []byte

func (Meta) Size

func (x Meta) Size() int

Size returns size of x in bytes.

type Metrics added in v0.37.0

type Metrics interface {
	SetParentID(id string)

	SetMode(m mode.ComponentMode)
	Close()

	AddMethodDuration(method string, d time.Duration, success bool)
}

type Move

type Move struct {
	Parent Node
	Meta
	// Child represents the ID of a node being moved. If zero, new ID is generated.
	Child Node
}

Move represents a single move operation.

type MultiNode added in v0.38.9

type MultiNode []Node

MultiNode represents a group of internal nodes accessible by the same path, but having different id.

type MultiNodeInfo added in v0.38.9

type MultiNodeInfo struct {
	Children   MultiNode
	Parents    MultiNode
	Timestamps []uint64
	Meta       []KeyValue
}

MultiNodeInfo represents a group of internal nodes accessible by the same path, but having different id.

func (*MultiNodeInfo) Add added in v0.38.9

func (r *MultiNodeInfo) Add(info NodeInfo) bool

type Node

type Node = uint64

Node is used to represent nodes. TODO: remove after the debugging.

type NodeInfo added in v0.37.0

type NodeInfo struct {
	ID       Node
	Meta     Meta
	ParentID Node
}

func (NodeInfo) ToMultiNode added in v0.38.9

func (n NodeInfo) ToMultiNode() MultiNodeInfo

type Option

type Option func(*cfg)

func WithMaxBatchDelay

func WithMaxBatchDelay(d time.Duration) Option

func WithMaxBatchSize

func WithMaxBatchSize(size int) Option

func WithMetrics added in v0.37.0

func WithMetrics(m Metrics) Option

func WithNoSync

func WithNoSync(noSync bool) Option

func WithOpenFile

func WithOpenFile(openFile func(string, int, fs.FileMode) (*os.File, error)) Option

func WithPath

func WithPath(path string) Option

func WithPerm

func WithPerm(perm fs.FileMode) Option

type Timestamp

type Timestamp = uint64

Timestamp is an alias for integer timestamp type. TODO: remove after the debugging.

type TreeListTreesPrm added in v0.38.0

type TreeListTreesPrm struct {
	NextPageToken []byte
	// BatchSize is batch size to list trees. If not lower or equals zero, than treeListTreesBatchSizeDefault is used.
	BatchSize int
}

type TreeListTreesResult added in v0.38.0

type TreeListTreesResult struct {
	NextPageToken []byte
	Items         []ContainerIDTreeID
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL