Skip to content

aprimadi/vector-clock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Vector Clock

Vector clock is a building block for allowing multiple versions of data in a distributed systems. It's being used on a distributed key value store such as Dynamo. This library is an implementation of a vector clock in Golang.

Installation

go get -u github.com/aprimadi/vector-clock

Usage

package main

import (
  "github.com/aprimadi/vector-clock"
)

func main() {
  // Initialize empty vector clock
  v1 := vclock.VClock{}

  // Increment vector clock for a given process id
  v1.Tick("pid1")     // v1 = VClock{"pid1": 1}

  // Create a copy of v1 and advance clock for pid2
  v2 := v1.Copy()
  v2.Tick("pid2")     // v2 = VClock{"pid1": 1, "pid2": 1}

  // Create a copy of v1 and advance clock for pid3
  v3 := v1.Copy()
  v3.Tick("pid3")     // v3 = VClock{"pid1": 1, "pid3": 1}

  // Use relation to find out the relation of two vector clocks
  v2.Relation(v3)     // Conflict
  v2.Relation(v1)     // Descendant

  // Merge two vector clocks
  v2.Merge(v3)        // VClock{"pid1": 1, "pid2": 1, "pid3": 1}
}

Serializing/deserializing

Since VClock uses map[string]uint64 as its underlying implementation, it can be serialized directly over the network using any serialization protocol you choose such as JSON, msgpack, etc.

About

Vector Clock implementation in Go

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy