Coder Social home page Coder Social logo

hlc's Introduction

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

hlc's People

Contributors

benoitc avatar c-bik avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.