Documentation ¶
Index ¶
- Constants
- func CreateStaticVotingNode(role int, addr, appPort, svcPort string, seeds []string, initialState Props) *cluster.Node
- func RunHelloWorld()
- func RunRecordAccessLoop(node *cluster.Node, props Props)
- func RunStaticVotingExample()
- type AccessRecord
- type LockRecordRequest
- type LockRecordResponse
- type LockReleased
- type Props
- type Record
- type RecordRequest
- type RecordResponse
- type RecordUpdate
Constants ¶
const ( EventHello = iota EventGoodbye EventInit )
const ( PhaseIdle = iota PhaseGatheringVotes PhaseAccessingRecord )
algorithm phases
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 **************** ******************************************
const ( AccessDenied = iota ReadAllowed WriteAllowed )
Variables ¶
This section is empty.
Functions ¶
func CreateStaticVotingNode ¶
func RunHelloWorld ¶
func RunHelloWorld()
func RunRecordAccessLoop ¶
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 ¶
LockRecordRequest is used to indicate that someone tries to put a lock on a record with specified id.
type LockRecordResponse ¶
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 ¶
RecordRequest is used to get replicas from peers
type RecordResponse ¶
RecordResponse is used to propagate replica from local storage to other peers
type RecordUpdate ¶
RecordUpdate is sent by a node that succesfully locked a record and modified it. This message suggests that a local replica should be updated.