package
0.0.0-20150423073221-e86f22487f53
Repository: https://github.com/manishearth/cs733.git
Documentation: pkg.go.dev

# README

Raft implementation

This package contains an implementation of the Raft consensus algorithm.

Generated documentation

Sample usage:

rafts := MakeRafts(5) // 5 is hardcoded for now
for i := 0; i < 5; i++ {
    go rafts[i].Loop() // set up event loop
}
lsnget := make(chan ClientAppendResponse, 1)
// Send an Append event to the leader
rafts[0].EventCh <- ClientAppendEvent{data: "foo", ack: lsnget}
// Record the lsn
lsn := (<-lsnget).Lsn

commit := <-rafts[1].CommitCh
fmt.Printf("Found data %v, with lsn %v\n", commit.Data(), commit.Lsn())

This commit will be of type LogEntry, and will contain a committed set of data on the first server

There are various events which you can directly send to a raft instance. Notable ones include DisconnectEvent, ReconnectEvent, and DebugEvent.

The first two will disconnect and reconnect the server from the network, and the last one will return debugging data through the ack channel specified in the ChanMessage

All the events that can be sent (see documentation for details on their contents):

  • TimeoutEvent
  • ClientAppendEvent (returns ClientAppendResponse through the internal ack channel)
  • AppendRPCEvent (returns AppendRPCResponse)
  • DebugEvent (returns DebugResponse through the internal ack channel)
  • VoteRequestEvent (returns VoteResponse)
  • HeartBeatEvent
  • DisconnectEvent
  • ReconnectEvent

All responses can be sent through the EventCh as well

To make this work on a network, one will have to replace ChanCommunicationHelper with a custom one that uses RPCs under the hood and knows about the mapping of server IP/port to server id. Everything else should stay mostly the same.

Use go test -v to run the tests. The test framework defines some custom communication helpers which can drop packets or sleep between packet delivery to test robustness.