Skip to content

Commit

Permalink
[Refactor] Doxygen style comments (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
greensky00 authored May 14, 2020
1 parent 88b4de3 commit 498cc30
Show file tree
Hide file tree
Showing 4 changed files with 457 additions and 188 deletions.
55 changes: 46 additions & 9 deletions include/libnuraft/context.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,34 @@ public:
, params_( cs_new<raft_params>(params) )
{}

/**
* Register an event callback function.
*
* @param func Callback function to register.
*/
void set_cb_func(cb_func::func_type func) {
cb_func_ = cb_func(func);
}

/**
* Return the pointer to current Raft parameters.
*
* WARNING:
* It is just a pointer so that the contents
* shouldn't be changed directly.
*
* @return Pointer to parameter instance.
*/
ptr<raft_params> get_params() const {
std::lock_guard<std::mutex> l(ctx_lock_);
return params_;
}

/**
* Update Raft parameters.
*
* @param to New Raft parameters to set.
*/
void set_params(ptr<raft_params>& to) {
std::lock_guard<std::mutex> l(ctx_lock_);
params_ = to;
Expand All @@ -72,31 +91,49 @@ public:
__nocopy__(context);

public:
// State manager instance.
/**
* State manager instance.
*/
ptr<state_mgr> state_mgr_;

// State machine instance.
/**
* State machine instance.
*/
ptr<state_machine> state_machine_;

// RPC listener instance.
/**
* RPC listener instance.
*/
ptr<rpc_listener> rpc_listener_;

// System logger instance.
/**
* System logger instance.
*/
ptr<logger> logger_;

// RPC client factory.
/**
* RPC client factory.
*/
ptr<rpc_client_factory> rpc_cli_factory_;

// Timer instance.
/**
* Timer instance.
*/
ptr<delayed_task_scheduler> scheduler_;

// Raft parameters.
/**
* Raft parameters.
*/
std::shared_ptr<raft_params> params_;

// Callback function for hooking the operation.
/**
* Callback function for hooking the operation.
*/
cb_func cb_func_;

// Lock.
/**
* Lock.
*/
mutable std::mutex ctx_lock_;
};

Expand Down
186 changes: 134 additions & 52 deletions include/libnuraft/peer.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,28 @@ namespace nuraft {
class snapshot;
class peer {
public:
// Max number of warnings before suppressing it.
/**
* Max number of warnings before suppressing it.
*/
static const int32 WARNINGS_LIMIT = 20;

// If a node is not responding more than this limit,
// we treat that node as dead.
/**
* If a node is not responding more than this limit,
* we treat that node as dead.
*/
static const int32 RESPONSE_LIMIT = 20;

// If connection is silent longer than this limit
// (multiplied by heartbeat interval), re-establish
// the connection.
/**
* If connection is silent longer than this limit
* (multiplied by heartbeat interval), re-establish
* the connection.
*/
static const int32 RECONNECT_LIMIT = 50;

// If removed node is not responding more than this limit,
// just force remove it from server list.
/**
* If removed node is not responding more than this limit,
* just force remove it from server list.
*/
static const int32 LEAVE_LIMIT = 5;

peer( ptr<srv_config>& config,
Expand Down Expand Up @@ -314,123 +322,197 @@ private:
ptr<resp_msg>& resp,
ptr<rpc_exception>& err);

// Information (config) of this server.
/**
* Information (config) of this server.
*/
ptr<srv_config> config_;

// Heartbeat scheduler for this server.
/**
* Heartbeat scheduler for this server.
*/
ptr<delayed_task_scheduler> scheduler_;

// RPC client to this server.
/**
* RPC client to this server.
*/
ptr<rpc_client> rpc_;

// Guard of `rpc_`.
/**
* Guard of `rpc_`.
*/
std::mutex rpc_protector_;

// Current heartbeat interval after adding back-off.
/**
* Current heartbeat interval after adding back-off.
*/
std::atomic<int32> current_hb_interval_;

// Original heartbeat interval.
/**
* Original heartbeat interval.
*/
int32 hb_interval_;

// RPC backoff.
/**
* RPC backoff.
*/
int32 rpc_backoff_;

// Upper limit of heartbeat interval.
/**
* Upper limit of heartbeat interval.
*/
int32 max_hb_interval_;

// Next log index of this server.
/**
* Next log index of this server.
*/
std::atomic<ulong> next_log_idx_;

// Hint of the next log batch size in bytes.
/**
* Hint of the next log batch size in bytes.
*/
std::atomic<ulong> next_batch_size_hint_in_bytes_;

// The last log index whose term matches up with the leader.
/**
* The last log index whose term matches up with the leader.
*/
ulong matched_idx_;

// `true` if we sent message to this server and waiting for
// the response.
/**
* `true` if we sent message to this server and waiting for
* the response.
*/
std::atomic<bool> busy_flag_;

// `true` if we need to send follow-up request immediately
// for commiting logs.
/**
* `true` if we need to send follow-up request immediately
* for commiting logs.
*/
std::atomic<bool> pending_commit_flag_;

// `true` if heartbeat is enabled.
/**
* `true` if heartbeat is enabled.
*/
bool hb_enabled_;

// Heartbeat task.
/**
* Heartbeat task.
*/
ptr<delayed_task> hb_task_;

// Snapshot context if snapshot transmission is in progress.
/**
* Snapshot context if snapshot transmission is in progress.
*/
ptr<snapshot_sync_ctx> snp_sync_ctx_;

// Lock for this peer.
/**
* Lock for this peer.
*/
std::mutex lock_;

// --- For tracking long pause ---
// Timestamp when the last request was sent.
/**
* Timestamp when the last request was sent.
*/
timer_helper last_sent_timer_;

// Timestamp when the last (successful) response was received.
/**
* Timestamp when the last (successful) response was received.
*/
timer_helper last_resp_timer_;

// Timestamp when the last active network activity was detected.
/**
* Timestamp when the last active network activity was detected.
*/
timer_helper last_active_timer_;

// Counter of long pause warnings.
/**
* Counter of long pause warnings.
*/
std::atomic<int32> long_pause_warnings_;

// Counter of recoveries after long pause.
/**
* Counter of recoveries after long pause.
*/
std::atomic<int32> network_recoveries_;

// `true` if user manually clear the `busy_flag_` before
// getting response from this server.
/**
* `true` if user manually clear the `busy_flag_` before
* getting response from this server.
*/
std::atomic<bool> manual_free_;

// For tracking RPC error.
/**
* For tracking RPC error.
*/
std::atomic<int32> rpc_errs_;

// Start log index of the last sent append entries request.
/**
* Start log index of the last sent append entries request.
*/
std::atomic<ulong> last_sent_idx_;

// Number of count where start log index is the same as previous.
/**
* Number of count where start log index is the same as previous.
*/
std::atomic<int32> cnt_not_applied_;

// True if leave request has been sent to this peer.
/**
* `true` if leave request has been sent to this peer.
*/
std::atomic<bool> leave_requested_;

// Number of HB timeout after leave requested.
/**
* Number of HB timeout after leave requested.
*/
std::atomic<int32> hb_cnt_since_leave_;

// True if this peer responded to leave request so that
// will be removed from cluster soon.
// To avoid HB timer trying to do something with this peer.
/**
* `true` if this peer responded to leave request so that
* will be removed from cluster soon.
* To avoid HB timer trying to do something with this peer.
*/
std::atomic<bool> stepping_down_;

// For re-connection.
/**
* For re-connection.
*/
std::atomic<bool> reconn_scheduled_;

// Back-off timer to avoid superfluous reconnection.
/**
* Back-off timer to avoid superfluous reconnection.
*/
timer_helper reconn_timer_;

// For exp backoff of reconnection.
/**
* For exp backoff of reconnection.
*/
timer_helper reconn_backoff_;

// If `true`, we will lower the log level of the RPC error
// from this server.
/**
* If `true`, we will lower the log level of the RPC error
* from this server.
*/
std::atomic<bool> suppress_following_error_;

// if `true`, this peer is removed and shut down.
// All operations on this peer should be rejected.
/**
* if `true`, this peer is removed and shut down.
* All operations on this peer should be rejected.
*/
std::atomic<bool> abandoned_;

// Reserved message that should be sent next time.
/**
* Reserved message that should be sent next time.
*/
ptr<req_msg> rsv_msg_;

// Handler for reserved message.
/**
* Handler for reserved message.
*/
rpc_handler rsv_msg_handler_;

// Logger instance.
/**
* Logger instance.
*/
ptr<logger> l_;
};

Expand Down
Loading

0 comments on commit 498cc30

Please sign in to comment.