Unverified Commit 4582dfac authored by Trever Schirmer's avatar Trever Schirmer
Browse files

Add Documentation

parent 918c03ae
Pipeline #108240 passed with stages
in 16 minutes and 33 seconds
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="Go" enabled="true" />
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/coverage" />
......
......@@ -477,6 +477,14 @@ Pass `--nase-cached` to your `fred` instance to activate caching.
This improves performance for requests to `fred` but may lead to data inconsistency if configuration changes often.
By default it is turned off.
## Developer Information
### Vector Clocks
Fred uses [vector clocks](https://en.wikipedia.org/wiki/Vector_clock) to ensure ordering of writes between nodes.
Whenever an item is updated locally, `addVersion` in storeservice.go is called. This function checks if
the received version is newer, older or of the same age as the local data and acts accordingly.
## Contributing
For development, it is recommended to install [GoLand](https://www.jetbrains.com/go/).
......
......@@ -510,6 +510,7 @@ func (s *storeService) addVersion(i Item, remoteVersion vclock.VClock, expiry in
s.vCache[i.Keygroup].RLock()
defer s.vCache[i.Keygroup].RUnlock()
// if the clock does not exist yet, create it (need to get write lock for this)
if _, ok := s.vCache[i.Keygroup].clocks[i.ID]; !ok {
s.vCache[i.Keygroup].RUnlock()
s.vCache[i.Keygroup].Lock()
......
......@@ -9,11 +9,12 @@ import (
"github.com/rs/zerolog/log"
)
type Entry struct {
type entry struct {
ID string
Ticks uint64
}
// Bytes turns a vector clock into its byte representation, which can be reversed with FromBytes
func Bytes(v vclock.VClock) []byte {
ids := make([]string, len(v))
i := 0
......@@ -24,10 +25,10 @@ func Bytes(v vclock.VClock) []byte {
sort.Strings(ids)
entries := make([]Entry, len(v))
entries := make([]entry, len(v))
for i := range ids {
entries[i] = Entry{
entries[i] = entry{
ID: ids[i],
Ticks: v[ids[i]],
}
......@@ -44,11 +45,12 @@ func Bytes(v vclock.VClock) []byte {
return b.Bytes()
}
// FromBytes is the opposite of Bytes and turns a byte array back into a vector clock
func FromBytes(data []byte) (vclock.VClock, error) {
b := new(bytes.Buffer)
b.Write(data)
entries := make([]Entry, 0)
entries := make([]entry, 0)
dec := gob.NewDecoder(b)
err := dec.Decode(&entries)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment