Documentation ¶
Overview ¶
huffleraft provides a package to run a distributed key value store driven by dgraph-io/badger for storage and hashicorp/raft for consensus. It can be integrated wtihin code much like embedded storage systems like leveldb. The package can be imported and does NOT require the user to make HTTP requests through curl and treat the system as an external application. Rather, using the API, this system can be embedded within applications. Firstly, the user makes a new badger store using NewBadgerKV. This is the storage for the key-value pairs for each raft node. A RaftStore using an appropriate port and directory. Start() is called on the RaftStore which starts the HTTP server to accept requests. This RaftStore can be interacted with by using Get, Set, Delete, and Join (to add nodes to a cluster). Check out the fsm.go file to see how logs are truncated using raft's Snapshot, Restore, and Persist mechanism. For more details check out the github repo: https://github.com/s4ayub/huffleraft and also the examples/ folder!!!
Index ¶
- type BadgerKV
- type RaftStore
- func (rs *RaftStore) Close()
- func (rs *RaftStore) Delete(key string) error
- func (rs *RaftStore) Get(key string) ([]byte, error)
- func (rs *RaftStore) Join(addr string) error
- func (rs *RaftStore) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (rs *RaftStore) Set(key, value string) error
- func (rs *RaftStore) Start() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BadgerKV ¶
type BadgerKV struct {
// contains filtered or unexported fields
}
func NewBadgerKV ¶
NewBadgerKV returns a BadgerKV. If the directory in which the data will be stored does not exist, then that directory will be made for the user.
type RaftStore ¶
A RaftStore encapsulates the http server (httpAddr, ln), a raft node (raftDir string, raftAddr string, RaftServer *raft.Raft) and a key-value store (kvs *BadgerKV).
func NewRaftKV ¶
NewRaftKV returns a RaftStore. nableSingle is used to determine whether a node should be allowed to elect itself as a leader. Set this option to true if you plan to send commands to a single node.
func (*RaftStore) Close ¶
func (rs *RaftStore) Close()
Close closes the HTTP server of the RaftStore.
func (*RaftStore) Delete ¶
Sends a request to delete a key to the http server of the leader node in the raft cluster. This key is deleted inside the badger stores of the RaftStore instances throughout cluster. This command REQUIRES a leader in a cluster.
func (*RaftStore) Join ¶
The addr provided is that of the node that would like to join a cluster, and the method Join is run on a node within that cluster. It sends a request to join a cluster to the http server of the leader node in the cluster. If there is no leader, then the http address of the node this method was run on will be used. This command does not require a leader in a cluster.
func (*RaftStore) ServeHTTP ¶
func (rs *RaftStore) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP allows the RaftStore to serve HTTP requests.
func (*RaftStore) Set ¶
Sends a request to set a key-value to the http server of the leader node in the raft cluster. This pair is then stored inside the badger stores of the RaftStore instances throughout cluster. This command REQUIRES a leader in a cluster.
func (*RaftStore) Start ¶
Start starts the http service using the listener within a RaftStore. The HTTP server is used to redirect commands like Set, Delete and Join to the leader RaftStore in a cluster. The HTTP address is always one away from the Raft address which the raft node uses for communication with other raft nodes.