Class: VectorClock

Clusterluck.VectorClock(nodeopt, countopt)

VectorClock VectorClock

Constructor

new VectorClock(nodeopt, countopt)

Vector clock implementation. Maintains a map from node IDs to clock information, containing an updated UNIX timestamp and an atomic counter (node-side).

Parameters:
Name Type Attributes Description
node String <optional>

Node to start vector clock with.

count Number <optional>

Count of node to initialize with.

Source:

Methods

descends(vclock) → {Boolean}

Returns whether this vector clocks descends from vclock.

Parameters:
Name Type Description
vclock Clusterluck.VectorClock

Vector clock to check if this instance descends from.

Source:
Returns:

Whether this vector clock descends from vclock.

Type
Boolean

equals(vclock) → {Boolean}

Returns whether this vector clock equals vclock.

Parameters:
Name Type Description
vclock Clusterluck.VectorClock

Vector clock to check equality with.

Source:
Returns:

Whether this vector clock equals vclock.

Type
Boolean

get(node) → {Object}

Get state from this vector clock at node.

Parameters:
Name Type Description
node String

Node to return state of.

Source:
Returns:

State of node.

Type
Object

getCount(node) → {Number}

Gets the count stored node in this vector clock.

Parameters:
Name Type Description
node String

Node to return count of.

Source:
Returns:

Count of node.

Type
Number

getInsert(node) → {Number}

Gets the microsecond UNIX insert timestamp stored at node in this vector clock.

Parameters:
Name Type Description
node String

Node to return insert time of.

Source:
Returns:

Microsecond UNIX timestamp of node.

Type
Number

getTimestamp(node) → {Number}

Gets the UNIX timestamp stored at node in this vector clock.

Parameters:
Name Type Description
node String

Node to return timestamp of.

Source:
Returns:

UNIX timestamp of node.

Type
Number

has(node) → {Boolean}

Returns whether node exists in this vector clock.

Parameters:
Name Type Description
node String

Node to check existence of.

Source:
Returns:

Whether node has an entry in this vector clock.

Type
Boolean

increment(node) → {Clusterluck.VectorClock}

Increments the counter stored at node in this vector clock. If node doesn't exist, it's inserted and incremented. The timestamp stored at node is updated to the current UNIX timestamp.

Parameters:
Name Type Description
node String

Node to increment counter of.

Source:
Returns:

This instance.

Type
Clusterluck.VectorClock

insert(node) → {Clusterluck.VectorClock}

Inserts node into this vector clock. Initializes node state with a 0 counter and the current UNIX timestamp on this node.

Parameters:
Name Type Description
node String

Node to insert into this instance.

Source:
Returns:

This instance.

Type
Clusterluck.VectorClock

merge(vclock) → {Clusterluck.VectorClock}

Merges two vector clocks, using the following policy:

  • If entry exists in v1 but not in v2, entry in v1 doesn't change
  • If entry exists in v2 but not in v1, entry is added into v1 as is
  • If entry exists in both v1 and v2 but the count at v2 is smaller than v1, the state of v1 is kept
  • If entry exists in both v1 and v2 but the count at v1 is smaller than v2, the state of v2 is used
  • If entry exists in both v1 and v2 and the counts are the same, prioritize based on UNIX timestamp
Parameters:
Name Type Description
vclock Clusterluck.VectorClock

Vector clock to merge this instance with.

Source:
Returns:

This instance.

Type
Clusterluck.VectorClock

nodes() → {Array}

Returns the nodes present in this vector clock.

Source:
Returns:

Node IDs in this vector clock.

Type
Array

remove(node) → {Clusterluck.VectorClock}

Removes node from this vector clock.

Parameters:
Name Type Description
node String

Node to remove from this vector clock.

Source:
Returns:

This instance.

Type
Clusterluck.VectorClock

size() → {Number}

Returns the number of entries in this vector clock.

Source:
Returns:

Number of entries in this vector clock.

Type
Number

trim(threshold, opts) → {Clusterluck.VectorClock}

Trims this vector clock. Requires that the number of entries in this clock be greater than lowerBound, and the oldest entry be older than threshold-youngBound. Any entries older than oldBound will be trimmed, as well as any entries above the upperBound limit.

Parameters:
Name Type Description
threshold Number

UNIX timestamp to check clock entries against.

opts Object

Object containing trim parameters.

Properties
Name Type Description
lowerBound Number

Number of entries required from trimming to occur.

youngBound Number

Minimum difference between oldest entry and threshold for trimming to occur.

upperBound Number

Maximum number of entries this vector clock can contain.

oldBound Number

Maximum difference between any entry and threshold.

Source:
Returns:

This instance.

Type
Clusterluck.VectorClock

update(node, count, timeopt) → {Clusterluck.VectorClock}

Updates the state of node in this vector clock with a counter and an optional UNIX timestamp. If time isn't provided, uses current UNIX timestamp.

Parameters:
Name Type Attributes Description
node String

Node to insert into this vector clock.

count Number

Count to update node state with.

time Number <optional>

UNIX timestamp to update node state with.

Source:
Returns:

This instance.

Type
Clusterluck.VectorClock