examples

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventHello = iota
	EventGoodbye
	EventInit
)
View Source
const (
	PhaseIdle = iota
	PhaseGatheringVotes
	PhaseAccessingRecord
)

algorithm phases

View Source
const (
	AccessRecordType       event.EventType = 100
	LockRecordRequestType  event.EventType = 101
	LockRecordResponseType event.EventType = 102
	LockReleasedType       event.EventType = 103
	RecordRequestType      event.EventType = 104
	RecordResponseType     event.EventType = 105
	RecordUpdateType       event.EventType = 106
)

****************************************** **************** PROTOCOL **************** ******************************************

View Source
const (
	AccessDenied = iota
	ReadAllowed
	WriteAllowed
)

Variables

This section is empty.

Functions

func CreateStaticVotingNode

func CreateStaticVotingNode(role int, addr, appPort, svcPort string, seeds []string, initialState Props) *cluster.Node

func RunHelloWorld

func RunHelloWorld()

func RunRecordAccessLoop

func RunRecordAccessLoop(node *cluster.Node, props Props)

func RunStaticVotingExample

func RunStaticVotingExample()

Types

type AccessRecord

type AccessRecord struct {
	RecId uint32
}

AccessRecord means that this node wants to access the specified shared record

type LockRecordRequest

type LockRecordRequest struct {
	RecId  uint32
	PeerId int
}

LockRecordRequest is used to indicate that someone tries to put a lock on a record with specified id.

type LockRecordResponse

type LockRecordResponse struct {
	RecId          uint32
	ReplicaVersion uint32
	Votes          int
	ToPeerId       int
}

LockRecordResponse is a response from nodes that do not want to put a lock on the record specified by the recId.

type LockReleased

type LockReleased struct {
	RecId uint32
}

LockReleased indicates that a the record with recId should be unlocked

type Props

type Props struct {
	// VotingPower defines the importance of the current
	// process' vote
	VotingPower int
	// ReadQuorum specifies how many votes a proess has to
	// gather to read a record
	ReadQuorum int
	// WriteQuorum specifies how many votes a proess has to
	// gather to modify a record
	WriteQuorum int
	// Strage represents the replicated data storage. It is
	// a simple key-value store
	Storage map[uint32]Record
	// GatheredVotes is a slice that serves as a storage
	// for votes gathered during the voting phase
	GatheredVotes []LockRecordResponse
	// Phase defines the phase of the algorithm that
	// the current process is in
	Phase int
	// AccessedRecord specifies which record is currently
	// tired to be accessed by this process
	AccessedRecord uint32
	// PeerId specifies the Id of the current process
	PeerId int
}

Props represent a single peer state. This struct contains all the variables that the event handlers share.

type Record

type Record struct {
	// Version indicates the version number of the record
	Version uint32
	// Data is the record's data field. For demonstration
	// purposes it's a simple string
	Data string
	// Locked indicates if the record is locked meaning
	// that some process wants to access it
	Locked bool
}

Record represents a piece of data shared between the nodes. Besides the data each Record contains a version that counts the value modifications.

type RecordRequest

type RecordRequest struct {
	RecId   uint32
	Version uint32
}

RecordRequest is used to get replicas from peers

type RecordResponse

type RecordResponse struct {
	RecId uint32
	Rec   Record
}

RecordResponse is used to propagate replica from local storage to other peers

type RecordUpdate

type RecordUpdate struct {
	RecId      uint32
	Rec        Record
	OldVersion uint32
}

RecordUpdate is sent by a node that succesfully locked a record and modified it. This message suggests that a local replica should be updated.

Jump to

Keyboard shortcuts

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