mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-17 01:40:34 +08:00
Raft logic fix: forcing active mode when allocation activity is detected
This commit is contained in:
+8
@@ -35,6 +35,11 @@ public:
|
||||
*/
|
||||
virtual void handleAllocationRequest(const UniqueID& unique_id, NodeID preferred_node_id) = 0;
|
||||
|
||||
/**
|
||||
* This method will be invoked when there's an Allocation message detected on the bus.
|
||||
*/
|
||||
virtual void handleAllocationActivityDetection(const ReceivedDataStructure<Allocation>& msg) = 0;
|
||||
|
||||
virtual ~IAllocationRequestHandler() { }
|
||||
};
|
||||
|
||||
@@ -126,6 +131,9 @@ class AllocationRequestManager
|
||||
|
||||
void handleAllocation(const ReceivedDataStructure<Allocation>& msg)
|
||||
{
|
||||
trace(TraceAllocationActivity, msg.getSrcNodeID().get());
|
||||
handler_.handleAllocationActivityDetection(msg);
|
||||
|
||||
if (!msg.isAnonymousTransfer())
|
||||
{
|
||||
return; // This is a response from another allocator, ignore
|
||||
|
||||
@@ -763,7 +763,8 @@ public:
|
||||
{
|
||||
return res;
|
||||
}
|
||||
append_entries_client_.setCallback(AppendEntriesResponseCallback(this, &RaftCore::handleAppendEntriesResponse));
|
||||
append_entries_client_.setCallback(AppendEntriesResponseCallback(this,
|
||||
&RaftCore::handleAppendEntriesResponse));
|
||||
append_entries_client_.setRequestTimeout(update_interval_);
|
||||
|
||||
for (uint8_t i = 0; i < NumRequestVoteClients; i++)
|
||||
@@ -773,7 +774,8 @@ public:
|
||||
{
|
||||
return res;
|
||||
}
|
||||
request_vote_clients_[i]->setCallback(RequestVoteResponseCallback(this, &RaftCore::handleRequestVoteResponse));
|
||||
request_vote_clients_[i]->setCallback(RequestVoteResponseCallback(this,
|
||||
&RaftCore::handleRequestVoteResponse));
|
||||
request_vote_clients_[i]->setRequestTimeout(update_interval_);
|
||||
}
|
||||
|
||||
@@ -785,6 +787,14 @@ public:
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normally should be called when there's allocation activity on the bus.
|
||||
*/
|
||||
void forceActiveMode()
|
||||
{
|
||||
setActiveMode(true); // If the current state was Follower, active mode may be toggling quickly for some time
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is mostly needed for testing.
|
||||
*/
|
||||
|
||||
@@ -135,6 +135,11 @@ class Server : IAllocationRequestHandler
|
||||
}
|
||||
}
|
||||
|
||||
virtual void handleAllocationActivityDetection(const ReceivedDataStructure<Allocation>&)
|
||||
{
|
||||
raft_core_.forceActiveMode();
|
||||
}
|
||||
|
||||
/*
|
||||
* Methods of INodeDiscoveryHandler
|
||||
*/
|
||||
|
||||
@@ -65,7 +65,7 @@ enum TraceCode
|
||||
TraceAllocationRequestAccepted, // number of bytes of unique ID after request
|
||||
TraceAllocationExchangeComplete, // first 8 bytes of unique ID interpreted as signed 64 bit big endian
|
||||
TraceAllocationResponse, // allocated node ID
|
||||
Trace11,
|
||||
TraceAllocationActivity, // source node ID of the message
|
||||
Trace12,
|
||||
// 40
|
||||
TraceDiscoveryNewNodeFound, // node ID
|
||||
|
||||
Reference in New Issue
Block a user