Skip to content

Commit 6721871

Browse files
authored
Merge pull request #19 from toniqsystems/nm-explicit-params
make explicit what has been forgotten
2 parents 2c0357d + f68e6d1 commit 6721871

2 files changed

Lines changed: 22 additions & 9 deletions

File tree

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
# HLClock
22

3-
[![Build Status](https://travis-ci.org/toniqsystems/hlclock.svg?branch=master)](https://travis-ci.org/toniqsystems/hlclock)
3+
[![Build Status](https://travis-ci.org/toniqsystems/hlclock.svg?branch=master)](https://travis-ci.org/toniqsystems/hlclock) [![Hex pm](http://img.shields.io/hexpm/v/hlclock.svg?style=flat)](https://hex.pm/packages/hlclock)
44

55
## About
66

77
Hybrid Logical Clocks (HLC) provide a one-way causality detection using a
88
combination of logical time and physical NTP timestamp. This library adds an
99
additional mechanism for resolving conflicts between timestamps by adding a
10-
unique node id to each HLC.
10+
unique node id to each HLC timestamp.
1111

1212
These timestamps can be used in place of standard NTP timestamps in order to
1313
provide consistent snapshots and causality tracking. HLCs have a fixed space
1414
requirement and are bounded close to physical timestamps.
1515

1616
## Installation
1717

18-
Now [available in Hex](https://hex.pm/docs/publish), the package can be installed
19-
by adding `hlclock` to your list of dependencies in `mix.exs`:
18+
First, add `HLClock` to your `mix.exs` dependencies.
2019

2120
```elixir
2221
def deps do
@@ -26,19 +25,20 @@ end
2625

2726
## Usage
2827

29-
In order to generate HLCs you'll need an HLClock process:
28+
Starting in version 1.0.0, the `HLClock.Server` is not started as an application
29+
automatically. `HLClock.start_link/1` is as a short cut to manually start a process:
3030

3131
```elixir
3232
{:ok, clock} = HLClock.start_link()
3333
{:ok, ts} = HLClock.send_timestamp(clock)
3434
```
3535

36-
You can also supervise clock processes:
36+
In practice, it is best to have a single `HLClock` running on any given node.
37+
Toward that end, `HLClock` also provides a `child_spec` that accepts all
38+
standard `GenServer` opts:
3739

3840
```elixir
3941
children = [
4042
{HLClock, name: :my_hlc_server},
4143
]
4244
```
43-
44-
`HLClock.start_link/1` accepts all arguments for `GenServer`.

lib/hlclock.ex

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ defmodule HLClock do
1515
"""
1616
alias HLClock.Timestamp
1717

18+
@doc """
19+
Returns a specification to start an `HLClock.Server` under a supervisor
20+
21+
In addition to standard `GenServer` opts, this allows for two other
22+
options to be passed to the underlying server:
23+
24+
* `:node_id` - a zero arity function returning a 64 bit integer for the node ID
25+
or a constant value that was precomputed prior to starting; defaults to
26+
`HLClock.NodeId.hash/0`
27+
* `:max_drift` - the clock synchronization bound which is applied in either
28+
direction (i.e. timestamps are too far in the past or too far in the
29+
future); this value is in milliseconds and defaults to `300_000`
30+
"""
1831
def child_spec(opts) do
1932
%{
2033
id: __MODULE__,
@@ -45,7 +58,7 @@ defmodule HLClock do
4558
end
4659

4760
@doc """
48-
Functionally equivalent to using `send_timestamp/0`. This generates a timestamp
61+
Functionally equivalent to using `send_timestamp/1`. This generates a timestamp
4962
for local causality tracking.
5063
"""
5164
def now(server) do

0 commit comments

Comments
 (0)