Open
Description
What would you like to be added?
In contrib/raftexample/main.go
there is definition of kvstore
and raftNode
:
// raft provides a commit stream for the proposals from the http api
var kvs *kvstore
getSnapshot := func() ([]byte, error) { return kvs.getSnapshot() }
commitC, errorC, snapshotterReady := newRaftNode(*id, strings.Split(*cluster, ","), *join, getSnapshot, proposeC, confChangeC)
kvs = newKVStore(<-snapshotterReady, proposeC, commitC, errorC)
// the key-value http handler will propose updates to raft
serveHTTPKVAPI(kvs, *kvport, confChangeC, errorC)
I see some circularity in these definitions: we use getSnapshot
which is defined via (empty) kvs
store in order to create raftNode
and to use this raft node in order to initialize kvs
store. It does not seem to be good design.
I don't have the solution ATM since I'm just getting into codebase, but I would like to start some discussion on that one.
Side question: Wouldn't it be better to rename kvstore
to kvStore
?
Why is this needed?
Separation of concerns. Code readability would be improved.