raft 0.1.0
Loading...
Searching...
No Matches
Public Member Functions | List of all members
raft::Server Class Referenceabstract

#include <server.hpp>

Inheritance diagram for raft::Server:
Inheritance graph
[legend]
Collaboration diagram for raft::Server:
Collaboration graph
[legend]

Public Member Functions

virtual tl::expected< void, Error > start ()=0
 Starts Raft consensus.
 
virtual void shutdown ()=0
 Shuts down the Raft server.
 
virtual tl::expected< Peer, Error > getLeader () const =0
 
virtual tl::expected< EntryInfo, Error > append (std::vector< std::byte > data)=0
 
virtual void setCommitCallback (CommitCallback callback)=0
 
virtual void clearCommitCallback ()=0
 Clears the commit callback.
 
virtual void setLeaderChangedCallback (LeaderChangedCallback callback)=0
 
virtual void clearLeaderChangedCallback ()=0
 Clears the leader changed callback.
 
virtual tl::expected< uint64_t, Error > getTerm () const =0
 
virtual tl::expected< uint64_t, Error > getCommitIndex () const =0
 
virtual tl::expected< uint64_t, Error > getLogByteCount () const =0
 
virtual std::string getId () const =0
 
virtual tl::expected< Status, Error > getStatus () const =0
 
- Public Member Functions inherited from raft::ServiceHandler
virtual void handleAppendEntries (const data::AppendEntriesRequest &request, std::function< void(tl::expected< data::AppendEntriesResponse, Error >)> callback)=0
 
virtual void handleRequestVote (const data::RequestVoteRequest &request, std::function< void(tl::expected< data::RequestVoteResponse, Error >)> callback)=0
 

Detailed Description

The Raft server interface. This is the main interface for the Raft server.

All functions are thread-safe. However, callbacks may block the main Raft logic. Therefore, user callbacks should be lightweight and non-blocking.

Member Function Documentation

◆ append()

virtual tl::expected< EntryInfo, Error > raft::Server::append ( std::vector< std::byte >  data)
pure virtual

If the server is the leader, appends an entry to the log. Otherwise, returns a NotLeader error. Note that this will not wait for the entry to be committed. An appended entry is guaranteed to eventually be committed if leadership is not lost.

Parameters
dataThe data to append to the log.
Returns
Information about the appended entry or an error.

◆ getCommitIndex()

virtual tl::expected< uint64_t, Error > raft::Server::getCommitIndex ( ) const
pure virtual

Returns the current commit index.

Returns
The current commit index if the server has not been shut down.

◆ getId()

virtual std::string raft::Server::getId ( ) const
pure virtual

Returns the ID of the server.

Returns
The server's ID.

◆ getLeader()

virtual tl::expected< Peer, Error > raft::Server::getLeader ( ) const
pure virtual

Returns the last-known leader.

Returns
The leader peer information or UnknownLeader if no leader is known.

◆ getLogByteCount()

virtual tl::expected< uint64_t, Error > raft::Server::getLogByteCount ( ) const
pure virtual

Returns the total size of the log in bytes, which may be useful for snapshot strategy.

Returns
The total byte count of the log if the server has not been shut down.

◆ getStatus()

virtual tl::expected< Status, Error > raft::Server::getStatus ( ) const
pure virtual

Returns a consistent snapshot of the server's current state.

Returns
The server's status if it has not been shut down.

◆ getTerm()

virtual tl::expected< uint64_t, Error > raft::Server::getTerm ( ) const
pure virtual

Returns the current term.

Returns
The current term if the server has not been shut down.

◆ setCommitCallback()

virtual void raft::Server::setCommitCallback ( CommitCallback  callback)
pure virtual

Sets the commit callback, which runs when a log entry is committed. The callback may be called on a different thread.

Parameters
callbackThe callback function to set.

◆ setLeaderChangedCallback()

virtual void raft::Server::setLeaderChangedCallback ( LeaderChangedCallback  callback)
pure virtual

Sets the leader changed callback, which runs when the leader changes. The callback may be called on a different thread.

Parameters
callbackThe callback function to set.

The documentation for this class was generated from the following file: