HLClock v0.1.1 HLClock View Source

Hybrid Logical Clock

Provides globally-unique, monotonic timestamps. Timestamps are bounded by the clock synchronization constraint, max_drift.

Implementation assumes that timestamps are (at a minimum) regularly sent; a clock at rest will eventually be unable to generate timestamps due to assumed bounds on the logical clock relative to physical time.

In order to account for physical time drift within the system, timestamps should regularly be exchanged between nodes. Generate a timestamp at one node via HLClock.send_timestamp/1; at the other node, call HLClock.recv_timestamp/2 with the received timestamp from the first node.

Inspired by https://www.cse.buffalo.edu/tech-reports/2014-04.pdf

Link to this section Summary

Functions

Determines if the clock’s timestamp “happened before” a different timestamp

Ensure that System.os_time is returning in milliseconds

Configurable clock synchronization parameter, ε

clock constructor requires the node_id, a millisecond clock fn and a maximum drift parameter in milliseconds

Given the current timestamp for this node and a provided remote timestamp, perform the merge of both logical time and logical counters. Returns the new current timestamp for the local node

Generate a single HLC Timestamp for sending to other nodes or local causality tracking

Link to this section Functions

Determines if the clock’s timestamp “happened before” a different timestamp

Ensure that System.os_time is returning in milliseconds

Configurable clock synchronization parameter, ε.

Link to this function new(pt0 \\ default_time(), node_id \\ 0) View Source

clock constructor requires the node_id, a millisecond clock fn and a maximum drift parameter in milliseconds

Link to this function recv_timestamp(local, remote, pt \\ default_time()) View Source

Given the current timestamp for this node and a provided remote timestamp, perform the merge of both logical time and logical counters. Returns the new current timestamp for the local node

Link to this function send_timestamp(old, pt \\ default_time()) View Source

Generate a single HLC Timestamp for sending to other nodes or local causality tracking