Raft logic fix: forcing active mode when allocation activity is detected

This commit is contained in:
Pavel Kirienko 2015-05-11 13:26:53 +03:00
parent 5af19f82c3
commit d623eee54a
5 changed files with 32 additions and 3 deletions

View File

@ -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

View File

@ -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.
*/

View File

@ -135,6 +135,11 @@ class Server : IAllocationRequestHandler
}
}
virtual void handleAllocationActivityDetection(const ReceivedDataStructure<Allocation>&)
{
raft_core_.forceActiveMode();
}
/*
* Methods of INodeDiscoveryHandler
*/

View File

@ -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

View File

@ -30,6 +30,12 @@ public:
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)
{
if (requests_.empty())