mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-22 22:03: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;
|
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() { }
|
virtual ~IAllocationRequestHandler() { }
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -126,6 +131,9 @@ class AllocationRequestManager
|
|||||||
|
|
||||||
void handleAllocation(const ReceivedDataStructure<Allocation>& msg)
|
void handleAllocation(const ReceivedDataStructure<Allocation>& msg)
|
||||||
{
|
{
|
||||||
|
trace(TraceAllocationActivity, msg.getSrcNodeID().get());
|
||||||
|
handler_.handleAllocationActivityDetection(msg);
|
||||||
|
|
||||||
if (!msg.isAnonymousTransfer())
|
if (!msg.isAnonymousTransfer())
|
||||||
{
|
{
|
||||||
return; // This is a response from another allocator, ignore
|
return; // This is a response from another allocator, ignore
|
||||||
|
|||||||
@@ -763,7 +763,8 @@ public:
|
|||||||
{
|
{
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
append_entries_client_.setCallback(AppendEntriesResponseCallback(this, &RaftCore::handleAppendEntriesResponse));
|
append_entries_client_.setCallback(AppendEntriesResponseCallback(this,
|
||||||
|
&RaftCore::handleAppendEntriesResponse));
|
||||||
append_entries_client_.setRequestTimeout(update_interval_);
|
append_entries_client_.setRequestTimeout(update_interval_);
|
||||||
|
|
||||||
for (uint8_t i = 0; i < NumRequestVoteClients; i++)
|
for (uint8_t i = 0; i < NumRequestVoteClients; i++)
|
||||||
@@ -773,7 +774,8 @@ public:
|
|||||||
{
|
{
|
||||||
return res;
|
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_);
|
request_vote_clients_[i]->setRequestTimeout(update_interval_);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -785,6 +787,14 @@ public:
|
|||||||
return 0;
|
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.
|
* 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
|
* Methods of INodeDiscoveryHandler
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ enum TraceCode
|
|||||||
TraceAllocationRequestAccepted, // number of bytes of unique ID after request
|
TraceAllocationRequestAccepted, // number of bytes of unique ID after request
|
||||||
TraceAllocationExchangeComplete, // first 8 bytes of unique ID interpreted as signed 64 bit big endian
|
TraceAllocationExchangeComplete, // first 8 bytes of unique ID interpreted as signed 64 bit big endian
|
||||||
TraceAllocationResponse, // allocated node ID
|
TraceAllocationResponse, // allocated node ID
|
||||||
Trace11,
|
TraceAllocationActivity, // source node ID of the message
|
||||||
Trace12,
|
Trace12,
|
||||||
// 40
|
// 40
|
||||||
TraceDiscoveryNewNodeFound, // node ID
|
TraceDiscoveryNewNodeFound, // node ID
|
||||||
|
|||||||
@@ -30,6 +30,12 @@ public:
|
|||||||
return can_followup;
|
return can_followup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void handleAllocationActivityDetection(
|
||||||
|
const uavcan::ReceivedDataStructure<uavcan::protocol::dynamic_node_id::Allocation>& msg)
|
||||||
|
{
|
||||||
|
std::cout << "ALLOCATION ACTIVITY\n" << msg << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
bool matchAndPopLastRequest(const UniqueID& unique_id, uavcan::NodeID preferred_node_id)
|
bool matchAndPopLastRequest(const UniqueID& unique_id, uavcan::NodeID preferred_node_id)
|
||||||
{
|
{
|
||||||
if (requests_.empty())
|
if (requests_.empty())
|
||||||
|
|||||||
Reference in New Issue
Block a user