Package com.usatiuk.kleppmanntree
Class KleppmannTree<TimestampT extends Comparable<TimestampT>,PeerIdT extends Comparable<PeerIdT>,MetaT extends NodeMeta,NodeIdT>
java.lang.Object
com.usatiuk.kleppmanntree.KleppmannTree<TimestampT,PeerIdT,MetaT,NodeIdT>
- Type Parameters:
TimestampT
- Type of the timestampPeerIdT
- Type of the peer IDMetaT
- Type of the node metadataNodeIdT
- Type of the node ID
public class KleppmannTree<TimestampT extends Comparable<TimestampT>,PeerIdT extends Comparable<PeerIdT>,MetaT extends NodeMeta,NodeIdT>
extends Object
An implementation of a tree as described in A highly-available move operation for replicated trees
-
Constructor Summary
ConstructorsConstructorDescriptionKleppmannTree
(StorageInterface<TimestampT, PeerIdT, MetaT, NodeIdT> storage, PeerInterface<PeerIdT> peers, Clock<TimestampT> clock, OpRecorder<TimestampT, PeerIdT, MetaT, NodeIdT> opRecorder) Constructor with all the dependencies -
Method Summary
Modifier and TypeMethodDescriptionvoid
applyExternalOp
(PeerIdT from, OpMove<TimestampT, PeerIdT, MetaT, NodeIdT> op) Apply an external operation from a remote peerfindParent
(Function<TreeNode<TimestampT, PeerIdT, MetaT, NodeIdT>, Boolean> kidPredicate) Find the parent of a node that matches the given predicate<LocalMetaT extends MetaT>
voidMove a node to a new parent with new metadatavoid
Move a node to a new parent with new metadatavoid
recordBoostrapFor
(PeerIdT host) Record the bootstrap operations for a given peer Will visit all nodes of the tree and add their effective operations to both the queue to be sent to the peer, and to the global operation log.Traverse the tree from its root node using the given list of namesvoid
updateExternalTimestamp
(PeerIdT from, TimestampT timestamp) Update the causality threshold timestamp for a peervoid
Walk the tree and apply the given consumer to each node
-
Constructor Details
-
KleppmannTree
public KleppmannTree(StorageInterface<TimestampT, PeerIdT, MetaT, NodeIdT> storage, PeerInterface<PeerIdT> peers, Clock<TimestampT> clock, OpRecorder<TimestampT, PeerIdT, MetaT, NodeIdT> opRecorder) Constructor with all the dependencies- Parameters:
storage
- Storage interfacepeers
- Peer interfaceclock
- Clock interfaceopRecorder
- Operation recorder interface
-
-
Method Details
-
traverse
Traverse the tree from its root node using the given list of names- Parameters:
names
- The list of names to traverse- Returns:
- The resulting node ID or null if not found
-
move
Move a node to a new parent with new metadata- Parameters:
newParent
- The new parent node IDnewMeta
- The new metadatachild
- The child node ID- Throws:
AlreadyExistsException
- If the node already exists and failCreatingIfExists is true
-
move
Move a node to a new parent with new metadata- Parameters:
newParent
- The new parent node IDnewMeta
- The new metadatachild
- The child node IDfailCreatingIfExists
- Whether to fail if there is a name conflict, otherwise replace the existing node- Throws:
AlreadyExistsException
- If the node already exists and failCreatingIfExists is true
-
applyExternalOp
Apply an external operation from a remote peer- Parameters:
from
- The peer IDop
- The operation to apply
-
updateExternalTimestamp
Update the causality threshold timestamp for a peer- Parameters:
from
- The peer IDtimestamp
- The timestamp received from it
-
walkTree
Walk the tree and apply the given consumer to each node- Parameters:
consumer
- The consumer to apply to each node
-
findParent
public org.apache.commons.lang3.tuple.Pair<String,NodeIdT> findParent(Function<TreeNode<TimestampT, PeerIdT, MetaT, NodeIdT>, Boolean> kidPredicate) Find the parent of a node that matches the given predicate- Parameters:
kidPredicate
- The predicate to match the child node- Returns:
- A pair containing the name of the child and the ID of the parent, or null if not found
-
recordBoostrapFor
Record the bootstrap operations for a given peer Will visit all nodes of the tree and add their effective operations to both the queue to be sent to the peer, and to the global operation log.- Parameters:
host
- The peer ID
-