Skip to content

barrel-db/hlc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hlc - Hybrid Logical Clock in Erlang.

Copyright (c) 2014-2015 Benoît Chesneau.

Version: 2.0.0

hlc implements the Hybrid Logical Clock outlined in Logical Physical Clocks and Consistent Snapshots in Globally Distributed Databases.

Note: you can use it to have timestamps that are are a combination of both a physical and a logical component to support monotonic increments without degenerate cases causing timestamps to diverge from wall clock time. It's usefull to distribute transactions or such things.

Build Status Hex pm

Documentation

Full doc is available in the hlc module.

Example of usage

Create a logical clock using hlc:new/0:

C = hlc:new()

By default, it is using the physical clock (erlang:timestamp/0 or erlang:now/0 on old systems) , but you can use hlc:new/1 to pass a function and use your own clock. Make sure to use the correct time warp mode for your system.

You can update the current clock from the members of the cluster using hlc:update/2.

❗ A clock is not locked, you need to make sure that only one user can update it at a time using the now/1 or update/2 functions.

Comparaison

Compare 2 clocks using hlc:ts_less/2 or hlc:ts_equal/2:

Ex, compare if A is inferior to B:

{MClock, MClockFun} = hlc:manual_clock(),
C = hlc:new(MClockFun),

A = hlc:timestamp(C),
B = hlc:timestamp(C),

?assert(A =:= B),

hlc:set_manual_clock(MClock, 1),
{B1, C2} = hlc:now(C),
true = hlc:less(A, B1).

To test if they are equal use hlc:ts_equal/2.

Ownership and License

The contributors are listed in AUTHORS. This project uses the MPL v2 license, see LICENSE.

hlc uses the C4.1 (Collective Code Construction Contract) process for contributions.

Development

Under C4.1 process, you are more than welcome to help us by:

  • join the discussion over anything from design to code style try out
  • and submit issue reports
  • or feature requests pick a task in
  • issues and get it done fork
  • the repository and have your own fixes send us pull requests and even
  • star this project ^_^

To run the test suite:

make test