Introduction
The govclock project offers full vector clock support for the Go language. Vector clocks allow recording and analyzing the inherent partial ordering of events in a distributed system in a comfortable way. The following pair of blog posts from Basho describes them in a nicely understandable way:
The following features are offered by govclock, in addition to basic event tracking:
- Compact serialization and deserialization
- Flexible truncation (min/max entries, min/max update time)
- Unit-independent update times
- Traditional merging
- Fast and memory efficient
API documentation
The API documentation is currently available at:
Example
Here is a simple example simulating a few sequential and concurrent operations and comparing the resulting vector clocks.
package main
import (
"launchpad.net/govclock"
"fmt"
)
func main() {
vc1 := govclock.New()
vc1.Update([]byte("A"), 1)
vc2 := vc1.Copy()
vc2.Update([]byte("B"), 0)
fmt.Println(vc2.Compare(vc1, govclock.Ancestor)) // => true
fmt.Println(vc1.Compare(vc2, govclock.Descendant)) // => true
vc1.Update([]byte("C"), 5)
fmt.Println(vc1.Compare(vc2, govclock.Descendant)) // => false
fmt.Println(vc1.Compare(vc2, govclock.Concurrent)) // => true
vc2.Merge(vc1)
fmt.Println(vc1.Compare(vc2, govclock.Descendant)) // => true
data := vc2.Bytes()
fmt.Printf("%#v\n", string(data))
// => "\x01\x01\x01\x01A\x01\x01\x01B\x01\x00\x01C"
vc3, err := govclock.FromBytes(data)
if err != nil { panic(err.String()) }
fmt.Println(vc3.Compare(vc2, govclock.Equal)) // => true
}
Source code
To obtain the source code, use Bazaar to download it from Launchpad:
$ bzr branch lp:govclock
Reporting bugs
Please report bugs at:
How to build and install govclock
Just use goinstall:
$ goinstall launchpad.net/govclock
License
govclock is made available under the simplified BSD license.
Contact
Gustavo Niemeyer <gustavo@niemeyer.net>