-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Add raft example #153
base: main
Are you sure you want to change the base?
Commits on Feb 21, 2024
-
Add a Linux implementation of file locking
This is taken straight from github.com/etcd-io/etcd:client/pkg/fileutil/lock_flock.go Signed-off-by: Michael Haggerty <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 247f961 - Browse repository at this point
Copy the full SHA 247f961View commit details -
Fix/suppress some linter warnings
Signed-off-by: Michael Haggerty <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for e2141f7 - Browse repository at this point
Copy the full SHA e2141f7View commit details -
Define
SnapshotStorage
interfaceThis interface defines what `kvstore` needs for saving and loading snapshots. Signed-off-by: Michael Haggerty <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 7b97b3a - Browse repository at this point
Copy the full SHA 7b97b3aView commit details -
This interface defines what `httpKVAPI` needs as the backing key-value store. Signed-off-by: Michael Haggerty <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 84b03dc - Browse repository at this point
Copy the full SHA 84b03dcView commit details -
raftNode: initialize
snapshotStorage
innewRaftNode()
Initialize the snapshot storage in `newRaftNode()` rather than in `startRaft()`. This is a step towards getting rid of the `snapshotStorageReady` channel. Signed-off-by: Michael Haggerty <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for cdd60c2 - Browse repository at this point
Copy the full SHA cdd60c2View commit details -
newRaftNode(): inline part of the goroutine's work
This is another step towards getting rid of `snapshotStorageReady`. Signed-off-by: Michael Haggerty <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 5034ccf - Browse repository at this point
Copy the full SHA 5034ccfView commit details -
startRaftNode(): replacement for
newRaftNode()
Rename `newRaftNode()` to `startRaftNode()`, and change it to replay the WAL synchronously, before returning. This doesn't change anything, because the callers were all waiting for `snapshotStorageReady` before proceeding anyway. Signed-off-by: Michael Haggerty <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for c1dd4dc - Browse repository at this point
Copy the full SHA c1dd4dcView commit details -
raftNode.snapdir: remove member
Use a local variable (in `startRaftNode()`) instead. Signed-off-by: Michael Haggerty <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 2a547ec - Browse repository at this point
Copy the full SHA 2a547ecView commit details -
raftNode.id: convert type to
uint64
This is more consistent with the types used elsewhere for IDs. Signed-off-by: Michael Haggerty <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 0fdf48b - Browse repository at this point
Copy the full SHA 0fdf48bView commit details -
startRaftNode(): take the
SnapshotStorage
as an argumentThis is the sort of thing that the caller should be able to inject, and it's not part of the raft algorithm itself. This change makes it clearer what a user of the raft algorithm must supply to it. Signed-off-by: Michael Haggerty <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 17981fa - Browse repository at this point
Copy the full SHA 17981faView commit details -
kvstore.loadAndApplySnapshot(), applyCommits(): extract methods
Extract two new methods, for clarity and to reduce code duplication. Signed-off-by: Michael Haggerty <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 34654f2 - Browse repository at this point
Copy the full SHA 34654f2View commit details -
kvstore: separate initialization from startup
Change `newKVStore()` to set up the initial state, but not start the `readCommits()` goroutine anymore. Instead, change the callers to call `processCommits()` (a renamed version of `readCommits()`) themselves (in a goroutine). The main benefit of this change is that the `kvstore` can be instantiated before calling `startRaftNode()`, meaning that `startRaftNode()` can be passed `kvs.getSnapshot` as an argument. Previously, it had to be passed an anonymous function that refers to a variable (`kvs`) that has not yet been initialized. This asynchrony was confusing and unnecessary. Signed-off-by: Michael Haggerty <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 5be8540 - Browse repository at this point
Copy the full SHA 5be8540View commit details -
kvstore.loadSnapshot(): inline method
It wasn't doing anything useful. Signed-off-by: Michael Haggerty <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 302d8a5 - Browse repository at this point
Copy the full SHA 302d8a5View commit details -
FSM: new interface, representing a finite state machine
Add a new interface, `FSM`, which represents a finite state machine that can be driven by raft. Also add `kvfsm`, which is an `FSM` view of a `kvstore`. Treating `kvstore` and `kvfsm` as separate types means that the public interface of `kvstore` is not contaminated with internal methods that are only there to support raft and should not be invoked by the user. Signed-off-by: Michael Haggerty <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 78c9106 - Browse repository at this point
Copy the full SHA 78c9106View commit details -
Move more functionality from
kvstore
tokvfsm
Signed-off-by: Michael Haggerty <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 9163a7d - Browse repository at this point
Copy the full SHA 9163a7dView commit details -
TestProposeOnCommit(): add some clarifying comments
Signed-off-by: Michael Haggerty <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 2ea3a54 - Browse repository at this point
Copy the full SHA 2ea3a54View commit details -
raftexample_test: introduce
peer
typeMake `cluster` hold an array of `peer`s, rather than one array for each peer attribute. Continue storing the names separately, since this `[]string` has to be passed to `startRaftNode()`. Signed-off-by: Michael Haggerty <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for a328306 - Browse repository at this point
Copy the full SHA a328306View commit details -
raftexample_test: give each
peer
its ownFSM
The tests can be made cleverer if each `peer` in a `cluster` can be instantiated with an arbitrary finite state machine. We'll use this to make some tests able to operate more like normal clients of `raftNode`s. Signed-off-by: Michael Haggerty <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 7b9b2cc - Browse repository at this point
Copy the full SHA 7b9b2ccView commit details -
kvfsm.applyCommits(): return an error
Signed-off-by: Michael Haggerty <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 1de94b9 - Browse repository at this point
Copy the full SHA 1de94b9View commit details -
FSM.ProcessCommits(): return an error rather than calling
log.Fatal()
Handle such errors at the caller, instead. Signed-off-by: Michael Haggerty <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for b44de5b - Browse repository at this point
Copy the full SHA b44de5bView commit details -
FSM.ApplyCommits(): new method
This is a step towards moving `ProcessCommits()` out of this interface and into `raftNode`. Signed-off-by: Michael Haggerty <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 58d3994 - Browse repository at this point
Copy the full SHA 58d3994View commit details -
newKVStore(): don't call
LoadAndApplySnapshot()
Instead, make `LoadAndApplySnapshot()` part of the `FSM` interface, and have the callers of `newKVStore()` invoke that method after calling `newKVStore()`. This is a step towards moving this functionality entirely out of `FSM`. Signed-off-by: Michael Haggerty <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 4feda00 - Browse repository at this point
Copy the full SHA 4feda00View commit details -
Make
ProcessCommits()
a method ofraftNode
Now that the `FSM` interface is more capable, there is no reason that this method, which has more to do with raft anyway, can't be implemented in `raftNode`. This makes it easier to implement new FSMs without having to reimplement this method. This means that `newRaftNode()` has to return a pointer to the `raftNode`, so make that change, too. This change will make other future changes simpler, too. Signed-off-by: Michael Haggerty <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for ba8d8ca - Browse repository at this point
Copy the full SHA ba8d8caView commit details -
newRaftNode(): call
LoadAndApplySnapshot()
hereMake this a standard part of starting up a node. Signed-off-by: Michael Haggerty <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for bb3c651 - Browse repository at this point
Copy the full SHA bb3c651View commit details -
LoadAndApplySnapshot(): move method to
raftNode
and make it privateThis is the last use of `kvstore.snapshotStorage`, so remove that field as well. Signed-off-by: Michael Haggerty <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 73ae94b - Browse repository at this point
Copy the full SHA 73ae94bView commit details -
raftNode: add a new and better way to tell when the node is done
The old method, monitoring the `errorC` channel, is not great because the error only pops out of that channel once. Which of the pieces of code that are waiting on that channel reads the error? Nobody knows! Instead, provide a `Done()` method and an `Err()` method that interested parties can use to determine when the node finishes and what error it returned. The callers haven't been changed yet. Signed-off-by: Michael Haggerty <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for c0cac21 - Browse repository at this point
Copy the full SHA c0cac21View commit details -
serveHTTPKVAPI(): monitor the raft node using its "done" channel
Use the `done` channel instead of the `errorC` channel for monitoring for the completion of the raft node. If the channel is closed, don't log the error, since the caller of `ProcessCommits()` is already taking care of that. Since this means that we're not killing the server by aborting the program, we now have to call `srv.Close()` explicitly. Signed-off-by: Michael Haggerty <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for b19e64f - Browse repository at this point
Copy the full SHA b19e64fView commit details -
cluster.Close(): read any error from the node directly
Signed-off-by: Michael Haggerty <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for b4c1a55 - Browse repository at this point
Copy the full SHA b4c1a55View commit details -
TestProposeOnCommit(): read any error from the node directly
Signed-off-by: Michael Haggerty <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for d420ab3 - Browse repository at this point
Copy the full SHA d420ab3View commit details -
cluster.Cleanup(): new method, extracted from
Close()
Signed-off-by: Michael Haggerty <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for d181e4a - Browse repository at this point
Copy the full SHA d181e4aView commit details -
TestProposeOnCommit(): change test to use
ProcessCommits()
Instead of driving the channels within the test, user a cleverer FSM and call `ProcessCommits()` to manage the channels. The old version of the test only looked at the first data item in each `commit`, even though multiple data items can be sent in a single `commit`. It also only looked at the first 100 commits, even though there is a multiplication factor because each node initiates 100 proposals. The new version checks all data items, and checks that the total number of commits is as expected (namely, 100 for each node, or 300 total). Signed-off-by: Michael Haggerty <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 0ae9c56 - Browse repository at this point
Copy the full SHA 0ae9c56View commit details -
newRaftNode(): don't return
commitC
anderrorC
Keep `commitC` and `errorC` internal to `raftNode`: don't return them from `newRaftNode()`, and don't require them as arguments to `(*raftNode).ProcessCommits()`. (Some tests still need them, but they can access the members directly on the `raftNode` instance.) Signed-off-by: Michael Haggerty <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 848ee9d - Browse repository at this point
Copy the full SHA 848ee9dView commit details -
Configuration menu - View commit details
-
Copy full SHA for cd6fbb1 - Browse repository at this point
Copy the full SHA cd6fbb1View commit details