diff options
author | Michael Muré <batolettre@gmail.com> | 2018-09-24 12:46:39 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2018-09-24 12:46:39 +0200 |
commit | c3a5213f829444452e1971822529a57da613831d (patch) | |
tree | cc5aa403b75428e9ebbde1e0bf62e55eec25a11d /util | |
parent | 921cd18cf98ecfc1f7fa82f57d64f1b1f9077e64 (diff) | |
download | git-bug-c3a5213f829444452e1971822529a57da613831d.tar.gz |
repo: more documentation
Diffstat (limited to 'util')
-rw-r--r-- | util/lamport/lamport.go | 3 | ||||
-rw-r--r-- | util/lamport/persisted_lamport.go | 5 |
2 files changed, 8 insertions, 0 deletions
diff --git a/util/lamport/lamport.go b/util/lamport/lamport.go index 640c58bc..0372bb6f 100644 --- a/util/lamport/lamport.go +++ b/util/lamport/lamport.go @@ -41,12 +41,15 @@ type Clock struct { // Time is the value of a Clock. type Time uint64 +// NewClock create a new clock with the value 1. +// Value 0 is considered as invalid. func NewClock() Clock { return Clock{ counter: 1, } } +// NewClockWithTime create a new clock with a value. func NewClockWithTime(time uint64) Clock { return Clock{ counter: time, diff --git a/util/lamport/persisted_lamport.go b/util/lamport/persisted_lamport.go index 22b23dcb..ab4b93b1 100644 --- a/util/lamport/persisted_lamport.go +++ b/util/lamport/persisted_lamport.go @@ -12,6 +12,7 @@ type Persisted struct { filePath string } +// NewPersisted create a new persisted Lamport clock func NewPersisted(filePath string) (*Persisted, error) { clock := &Persisted{ Clock: NewClock(), @@ -27,6 +28,7 @@ func NewPersisted(filePath string) (*Persisted, error) { return clock, nil } +// LoadPersisted load a persisted Lamport clock from a file func LoadPersisted(filePath string) (*Persisted, error) { clock := &Persisted{ filePath: filePath, @@ -40,11 +42,14 @@ func LoadPersisted(filePath string) (*Persisted, error) { return clock, nil } +// Increment is used to return the value of the lamport clock and increment it afterwards func (c *Persisted) Increment() (Time, error) { time := c.Clock.Increment() return time, c.Write() } +// Witness is called to update our local clock if necessary after +// witnessing a clock value received from another process func (c *Persisted) Witness(time Time) error { // TODO: rework so that we write only when the clock was actually updated c.Clock.Witness(time) |