vClock

package module
v0.0.0-...-98dea0f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2022 License: MIT Imports: 4 Imported by: 1

README

Vector-clock based event ordering

package main

import "github.com/Ishan27gOrg/vClock"

// VectorClock : provides interface to implement vector clock
type VectorClock interface {
	// SendEvent returns the current vector clock after first updating self clock and then
	// updating the individual clocks for corresponding addresses
	SendEvent(id string, addresses []string) vClock.EventClock
	// Get returns the current vector clock
	Get(id string) vClock.EventClock
	// ReceiveEvent updates the current vector clock using element wise maximum with the passed vector clock
	ReceiveEvent(id string, v vClock.EventClock)
	Clear(id string)
	print()
}
// Events : provides interface to merge and order events based on vector clocks
type Events interface {
	// MergeEvents merges the current event clocks with received event clocks, new events are added to current list
	MergeEvents(es ...vClock.Event)
	// MergeEvent takes an eventId & clock and merges with existing clock, new events are added to current list
	MergeEvent(e vClock.Event)
	// GetCurrentEvents returns the events currently saved. Not in order
	GetCurrentEvents() []vClock.Event
	// GetEventsOrder returns the eventIds ordered according to vector clock for the events
	GetEventsOrder() (ids []string)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	EventId    string     `json:"event_id"`
	EventClock EventClock `json:"event_clock"`
}

Event contains value for eventClocks tree

type EventClock

type EventClock map[string]int

EventClock is vector-clock of peer-address and its individual clock

func MergeClocks

func MergeClocks(v1 EventClock, v2 EventClock) *EventClock

MergeClocks merges the current event clock with the provided event clock. unique entries from both clocks are kept

type Events

type Events interface {
	// MergeEvents merges the current event clocks with received event clocks.
	// New events are added to current list
	MergeEvents(es ...Event)
	// MergeEvent takes an eventId & clock and merges with existing clock
	// New events are added to current list
	MergeEvent(e Event)
	// GetCurrentEvents returns the events currently saved. Not in order
	GetCurrentEvents() []Event
	// GetEventsOrder returns the eventIds ordered according to vector clock for the events
	GetEventsOrder() (orderedEvents []Event)
}

Events : provides interface for a process with lease/leader-role receives `new-events` from followers with eventId and followers vector clock

func NewEventVector

func NewEventVector() Events

type VectorClock

type VectorClock interface {
	// Get returns the current vector clock
	Get(eventIdOrHash string) EventClock
	// SendEvent returns the current vector clock after first updating self clock and then
	// updating the individual clocks for corresponding addresses
	SendEvent(eventIdOrHash string, addresses []string) EventClock
	// ReceiveEvent updates the current vector clock using element wise maximum with the passed vector clock
	ReceiveEvent(eventIdOrHash string, v EventClock)
	Clear(eventIdOrHash string)
	// contains filtered or unexported methods
}

VectorClock provides interface to implement vector clock

func Copy

func Copy(v VectorClock) VectorClock

func Init

func Init(self string) VectorClock

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL