hlc (hlc v3.0.4)
View Sourcehlc
implements the Hybrid Logical Clock outlined in "Logical Physical Clocks and Consistent Snapshots in Globally Distributed Databases", available online at http://www.cse.buffalo.edu/tech-reports/2014-04.pdf.
An hybrid logical clock is available as a linked process. Objects of this type model causality while maintaining a relation to physical time. Roughly speaking, timestamps consist of the largest wall clock time among all events, and a logical clock that ticks whenever an event happens in the future of the local physical clock.
Summary
Functions
compare if 2 timestamps are equal
returns the maximal offset allowed. A value of 0 means offset checking is disabled.
compare if one timestamps happen before the other
create a manually controlled physical clock
create a manually controlled physical clock and initialise it with a default ts.
returns a timestamp associated with an event from the local machine that may be sent to other members of the distributed network. This is the counterpart of Update, which is passed a timestamp received from another member of the distributed network.
timestamp in milliseconds
change the value of the manually controlled physical clock.
Sets the maximal offset from the physical clock that a call to Update may cause. A well-chosen value is large enough to ignore a reasonable amount of clock skew but will prevent ill-configured nodes from dramatically skewing the wall time of the clock into the future.
start a new hybrid logical clock with physical clock and maxoffset=0
start a new hybrid logical clock with a custom physical clock function.
start a new hybrid logical clock with a name. Clocks are always local
stop a clock
stop a manually controlled physical clock.
return a copy of the clock timestamp without adjusting it
takes a hybrid timestamp, usually originating from an event received from another member of a distributed system. The clock is updated and the hybrid timestamp associated to the receipt of the event returned. An error may only occur if offset checking is active and the remote timestamp was rejected due to clock offset, in which case the state of the clock will not have been altered. To timestamp events of local origin, use Now instead.
Types
Functions
compare if 2 timestamps are equal
-spec get_maxoffset(clock()) -> non_neg_integer().
returns the maximal offset allowed. A value of 0 means offset checking is disabled.
compare if one timestamps happen before the other
-spec manual_clock() -> {pid(), fun()}.
create a manually controlled physical clock
create a manually controlled physical clock and initialise it with a default ts.
returns a timestamp associated with an event from the local machine that may be sent to other members of the distributed network. This is the counterpart of Update, which is passed a timestamp received from another member of the distributed network.
-spec physical_clock() -> non_neg_integer().
timestamp in milliseconds
change the value of the manually controlled physical clock.
-spec set_maxoffset(non_neg_integer(), clock()) -> ok.
Sets the maximal offset from the physical clock that a call to Update may cause. A well-chosen value is large enough to ignore a reasonable amount of clock skew but will prevent ill-configured nodes from dramatically skewing the wall time of the clock into the future.
A value of zero disables this safety feature. The default value for a new instance is zero.
-spec start() -> {ok, clock()}.
-spec start(ClockFun :: clock_fun(), MaxOffset :: non_neg_integer()) -> {ok, clock()}.
-spec start(Name :: atom(), ClockFun :: clock_fun(), MaxOffset :: non_neg_integer()) -> {ok, clock()}.
-spec start_link() -> {ok, clock()}.
start a new hybrid logical clock with physical clock and maxoffset=0
-spec start_link(ClockFun :: clock_fun(), MaxOffset :: non_neg_integer()) -> {ok, clock()}.
start a new hybrid logical clock with a custom physical clock function.
-spec start_link(Name :: atom(), ClockFun :: clock_fun(), MaxOffset :: non_neg_integer()) -> {ok, clock()}.
start a new hybrid logical clock with a name. Clocks are always local
stop a clock
-spec stop_manual_clock(pid()) -> ok.
stop a manually controlled physical clock.
return a copy of the clock timestamp without adjusting it
takes a hybrid timestamp, usually originating from an event received from another member of a distributed system. The clock is updated and the hybrid timestamp associated to the receipt of the event returned. An error may only occur if offset checking is active and the remote timestamp was rejected due to clock offset, in which case the state of the clock will not have been altered. To timestamp events of local origin, use Now instead.