mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-13 08:33:34 +08:00
Better naming
This commit is contained in:
@@ -28,20 +28,20 @@ namespace distributed
|
||||
/**
|
||||
* Allocator has to implement this interface so the RaftCore can inform it when a new entry gets committed to the log.
|
||||
*/
|
||||
class ILeaderLogCommitHandler
|
||||
class IRaftLeaderMonitor
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This method will be invoked when a new log entry is committed (only if the local server is the current Leader).
|
||||
*/
|
||||
virtual void onEntryCommit(const Entry& entry) = 0;
|
||||
virtual void handleLogCommitOnLeader(const Entry& committed_entry) = 0;
|
||||
|
||||
/**
|
||||
* Assume false by default.
|
||||
*/
|
||||
virtual void onLeaderChange(bool local_node_is_leader) = 0;
|
||||
virtual void handleLocalLeadershipChange(bool local_node_is_leader) = 0;
|
||||
|
||||
virtual ~ILeaderLogCommitHandler() { }
|
||||
virtual ~IRaftLeaderMonitor() { }
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -90,7 +90,7 @@ class RaftCore : private TimerBase
|
||||
const MonotonicDuration base_activity_timeout_;
|
||||
|
||||
IEventTracer& tracer_;
|
||||
ILeaderLogCommitHandler& log_commit_handler_;
|
||||
IRaftLeaderMonitor& leader_monitor_;
|
||||
|
||||
/*
|
||||
* States
|
||||
@@ -284,7 +284,7 @@ class RaftCore : private TimerBase
|
||||
if ((ServerStateLeader == server_state_) ||
|
||||
(ServerStateLeader == new_state))
|
||||
{
|
||||
log_commit_handler_.onLeaderChange(ServerStateLeader == new_state);
|
||||
leader_monitor_.handleLocalLeadershipChange(ServerStateLeader == new_state);
|
||||
}
|
||||
|
||||
server_state_ = new_state;
|
||||
@@ -373,7 +373,7 @@ class RaftCore : private TimerBase
|
||||
trace(TraceRaftNewEntryCommitted, commit_index_);
|
||||
|
||||
// AT THIS POINT ALLOCATION IS COMPLETE
|
||||
log_commit_handler_.onEntryCommit(*persistent_state_.getLog().getEntryAtIndex(commit_index_));
|
||||
leader_monitor_.handleLogCommitOnLeader(*persistent_state_.getLog().getEntryAtIndex(commit_index_));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -677,7 +677,7 @@ public:
|
||||
RaftCore(INode& node,
|
||||
IStorageBackend& storage,
|
||||
IEventTracer& tracer,
|
||||
ILeaderLogCommitHandler& log_commit_handler,
|
||||
IRaftLeaderMonitor& leader_monitor,
|
||||
MonotonicDuration update_interval =
|
||||
MonotonicDuration::fromMSec(AppendEntries::Request::DEFAULT_REQUEST_TIMEOUT_MS),
|
||||
MonotonicDuration base_activity_timeout =
|
||||
@@ -686,7 +686,7 @@ public:
|
||||
, update_interval_(update_interval)
|
||||
, base_activity_timeout_(base_activity_timeout)
|
||||
, tracer_(tracer)
|
||||
, log_commit_handler_(log_commit_handler)
|
||||
, leader_monitor_(leader_monitor)
|
||||
, persistent_state_(storage, tracer)
|
||||
, cluster_(node, storage, persistent_state_.getLog(), tracer)
|
||||
, commit_index_(0) // Per Raft paper, commitIndex must be initialized to zero
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace distributed
|
||||
* This class implements the top-level allocation logic and server API.
|
||||
*/
|
||||
class Server : private IAllocationRequestHandler
|
||||
, private ILeaderLogCommitHandler
|
||||
, private IRaftLeaderMonitor
|
||||
{
|
||||
struct UniqueIDLogPredicate
|
||||
{
|
||||
@@ -119,12 +119,12 @@ class Server : private IAllocationRequestHandler
|
||||
}
|
||||
}
|
||||
|
||||
virtual void onEntryCommit(const protocol::dynamic_node_id::server::Entry& entry)
|
||||
virtual void handleLogCommitOnLeader(const protocol::dynamic_node_id::server::Entry& entry)
|
||||
{
|
||||
tryPublishAllocationResult(entry);
|
||||
}
|
||||
|
||||
virtual void onLeaderChange(bool local_node_is_leader)
|
||||
virtual void handleLocalLeadershipChange(bool local_node_is_leader)
|
||||
{
|
||||
UAVCAN_TRACE("dynamic_node_id_server::distributed::Server", "I am leader: %d", int(local_node_is_leader));
|
||||
allocation_request_manager_.setActive(local_node_is_leader);
|
||||
|
||||
@@ -18,16 +18,16 @@
|
||||
using uavcan::dynamic_node_id_server::UniqueID;
|
||||
|
||||
|
||||
class CommitHandler : public uavcan::dynamic_node_id_server::distributed::ILeaderLogCommitHandler
|
||||
class CommitHandler : public uavcan::dynamic_node_id_server::distributed::IRaftLeaderMonitor
|
||||
{
|
||||
const std::string id_;
|
||||
|
||||
virtual void onEntryCommit(const uavcan::protocol::dynamic_node_id::server::Entry& entry)
|
||||
virtual void handleLogCommitOnLeader(const uavcan::protocol::dynamic_node_id::server::Entry& entry)
|
||||
{
|
||||
std::cout << "ENTRY COMMITTED [" << id_ << "]\n" << entry << std::endl;
|
||||
}
|
||||
|
||||
virtual void onLeaderChange(bool local_node_is_leader)
|
||||
virtual void handleLocalLeadershipChange(bool local_node_is_leader)
|
||||
{
|
||||
std::cout << "I AM LEADER [" << id_ << "]: " << (local_node_is_leader ? "YES" : "NOT ANYMORE") << std::endl;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user