(add-leader-watch raft key fn)
(add-leader-watch raft key fn event-type)
Registers a function to be called with each leader change. Specify any key which can be used to unregister function later.
Function is called only when the leader change is of specified event-type, either :become-leader or :become-follower. To get called for all changes, specify an event-type of nil (default).
Function is a single-argument function that is called with a map that contains information related to the leadership change. Keys of the map include:
Important! Function is called synchronously, and therefore RAFT is stopped while processing. If function requires raft calls, it must be run asynchronously. Good to run asynchronously for anything that might be slow.
If key is already in use, overwrites existing watch function with fn.
Registers a function to be called with each leader change. Specify any key which can be used to unregister function later. Function is called only when the leader change is of specified event-type, either :become-leader or :become-follower. To get called for all changes, specify an event-type of nil (default). Function is a single-argument function that is called with a map that contains information related to the leadership change. Keys of the map include: - :key - original key the function was registered with - :event - values will be either :become-follower or :become-leader - :cause - Keyword for the cause of the event, namely the raft action that precipated the change - :message - String with a nice message explaining the cause - :old-leader - the leader before this change (will be nil or leader's name) - :new-leader - leader after this change (will be nil or leader's name) - :old-raft-state - raft state right before the change - :new-raft-state - raft state after the change - :server - this server's name Important! Function is called synchronously, and therefore RAFT is stopped while processing. If function requires raft calls, it *must* be run asynchronously. Good to run asynchronously for anything that might be slow. If key is already in use, overwrites existing watch function with fn.
(close {:keys [config] :as raft})
Closes a raft process.
Closes a raft process.
(event-chan raft)
Returns event channel for the raft instance.
Returns event channel for the raft instance.
(event-loop raft-state)
Launches an event loop where all state changes to the raft state happen.
This means all state changes are single-threaded.
Maintains appropriate timeouts (heartbeat if leader, or election timeout if not leader) to trigger appropriate actions when no activity happens between timeouts.
Events include:
append-entries - (follower) process and respond to append-entries events sent from the leader
request-vote - (follower) process a request-vote request from a leader candidate
new-command - (leader) processes a new command, will return result of operation after applied to state machine
new-command-timeout - (leader) a new command timed out, remove callback from state
append-entry-response - (leader) process response to an append-entries event
request-vote-response - (candidate) process response to request-vote
raft-state - provides current state of raft to a callback function provided.
close - gracefully closes down raft
Launches an event loop where all state changes to the raft state happen. This means all state changes are single-threaded. Maintains appropriate timeouts (heartbeat if leader, or election timeout if not leader) to trigger appropriate actions when no activity happens between timeouts. Events include: - append-entries - (follower) process and respond to append-entries events sent from the leader - request-vote - (follower) process a request-vote request from a leader candidate - new-command - (leader) processes a new command, will return result of operation after applied to state machine - new-command-timeout - (leader) a new command timed out, remove callback from state - append-entry-response - (leader) process response to an append-entries event - request-vote-response - (candidate) process response to request-vote - raft-state - provides current state of raft to a callback function provided. - close - gracefully closes down raft
(get-raft-state raft callback)
Polls raft loop and returns state to provided callback.
Polls raft loop and returns state to provided callback.
(invoke-rpc raft operation data callback)
Call this with original raft config to invoke an incoming RPC command.
Call this with original raft config to invoke an incoming RPC command.
(invoke-rpc* event-channel operation data callback)
Like invoke-rpc, but takes just the event channel instead of the full raft instance.
Like invoke-rpc, but takes just the event channel instead of the full raft instance.
(latest-stored-snapshot {:keys [snapshot-list-indexes] :as config})
(logfile raft)
Returns log file name for raft.
Returns log file name for raft.
(monitor-raft raft callback)
Debugging tool, registers a single-argument callback fn that will be called with each new raft event. To remove existing listen-fn, provide 'nil' instead of function.
Callback argument is a map with keys:
Debugging tool, registers a single-argument callback fn that will be called with each new raft event. To remove existing listen-fn, provide 'nil' instead of function. Callback argument is a map with keys: - event - event data called as a three tuple [operation data callback] - time - time that event took to process (locally) - before - raft state before command - after - raft state after command
(new-command raft command)
(new-command raft command persist-callback)
Issues a new RaftCommand (leader only) to create a new log entry.
Issues a new RaftCommand (leader only) to create a new log entry.
(new-entry raft entry callback)
(new-entry raft entry callback timeout-ms)
Creates a new log entry (leader only). Generates a RaftCommand and submits it for processing.
Creates a new log entry (leader only). Generates a RaftCommand and submits it for processing.
(raft-state-async raft)
Polls raft loop and puts state on returned channel.
Polls raft loop and puts state on returned channel.
(register-callback raft command-id timeout-ms callback)
Registers a callback for a command with specified id.
Registers a callback for a command with specified id.
(remove-leader-watch raft key)
Removes watch function with specified key.
Removes watch function with specified key.
(start config)
Config map consists of the following keys:
Config map consists of the following keys: - this-server string|keyword For example, myserver1. No default. - servers [string|keyword] For example, [myserver1, myserver2]. No default. - timeout-ms int Election timeout, good range is 10ms->500ms. By default, 500. - heartbeat-ms int By default, 100. - log-history int Number of historical log files to retain. By default 10. - snapshot-threshold int Number of log entries since last snapshot (minimum) to generate new snapshot. By default, 100. - log-directory string Directory where raft logs are stored. By default, "raftlog/" - state-machine fn See kv_example for sample. - snapshot-write fn See kv_example for sample. - snapshot-xfer fn See kv_example for sample. - snapshot-install fn See kv_example for sample. - snapshot-reify fn See kv_example for sample. - snapshot-list-indexes fn See kv_example for sample. - send-rpc-fn fn See kv_example for sample. - default-command-timeout int By default, 4000. - close-fn fn See kv_example for sample. - event-chan async/chan - command-chan async/chan - entries-max int Maximum number of entries we will send at once to any server. By default, 50. - entry-cache-size
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close