mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 20:56:52 +02:00
Merge pull request #1006 from birarda/master
fix DS bug with AC talking on restart
This commit is contained in:
commit
bac16cc5cf
2 changed files with 52 additions and 39 deletions
|
@ -339,6 +339,51 @@ bool DomainServer::checkInWithUUIDMatchesExistingNode(sockaddr* nodePublicSocket
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DomainServer::possiblyAddStaticAssignmentsBackToQueueAfterRestart(timeval* startTime) {
|
||||||
|
// if the domain-server has just restarted,
|
||||||
|
// check if there are static assignments in the file that we need to
|
||||||
|
// throw into the assignment queue
|
||||||
|
const uint64_t RESTART_HOLD_TIME_USECS = 5 * 1000 * 1000;
|
||||||
|
|
||||||
|
if (usecTimestampNow() - usecTimestamp(startTime) > RESTART_HOLD_TIME_USECS) {
|
||||||
|
_hasCompletedRestartHold = true;
|
||||||
|
|
||||||
|
// pull anything in the static assignment file that isn't spoken for and add to the assignment queue
|
||||||
|
for (int i = 0; i < MAX_STATIC_ASSIGNMENT_FILE_ASSIGNMENTS; i++) {
|
||||||
|
if (_staticAssignments[i].getUUID().isNull()) {
|
||||||
|
// reached the end of static assignments, bail
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool foundMatchingAssignment = false;
|
||||||
|
|
||||||
|
NodeList* nodeList = NodeList::getInstance();
|
||||||
|
|
||||||
|
// enumerate the nodes and check if there is one with an attached assignment with matching UUID
|
||||||
|
for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
|
||||||
|
if (node->getLinkedData()) {
|
||||||
|
Assignment* linkedAssignment = (Assignment*) node->getLinkedData();
|
||||||
|
if (linkedAssignment->getUUID() == _staticAssignments[i].getUUID()) {
|
||||||
|
foundMatchingAssignment = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!foundMatchingAssignment) {
|
||||||
|
// this assignment has not been fulfilled - reset the UUID and add it to the assignment queue
|
||||||
|
_staticAssignments[i].resetUUID();
|
||||||
|
|
||||||
|
qDebug() << "Adding static assignment to queue -" << _staticAssignments[i] << "\n";
|
||||||
|
|
||||||
|
_assignmentQueueMutex.lock();
|
||||||
|
_assignmentQueue.push_back(&_staticAssignments[i]);
|
||||||
|
_assignmentQueueMutex.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DomainServer::cleanup() {
|
void DomainServer::cleanup() {
|
||||||
_staticAssignmentFile.unmap(_staticAssignmentFileData);
|
_staticAssignmentFile.unmap(_staticAssignmentFileData);
|
||||||
_staticAssignmentFile.close();
|
_staticAssignmentFile.close();
|
||||||
|
@ -485,6 +530,10 @@ int DomainServer::run() {
|
||||||
|
|
||||||
qDebug("Received a request for assignment.\n");
|
qDebug("Received a request for assignment.\n");
|
||||||
|
|
||||||
|
if (_hasCompletedRestartHold) {
|
||||||
|
possiblyAddStaticAssignmentsBackToQueueAfterRestart(&startTime);
|
||||||
|
}
|
||||||
|
|
||||||
if (_assignmentQueue.size() > 0) {
|
if (_assignmentQueue.size() > 0) {
|
||||||
// construct the requested assignment from the packet data
|
// construct the requested assignment from the packet data
|
||||||
Assignment requestAssignment(packetData, receivedBytes);
|
Assignment requestAssignment(packetData, receivedBytes);
|
||||||
|
@ -552,45 +601,8 @@ int DomainServer::run() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint64_t RESTART_HOLD_TIME_USECS = 5 * 1000 * 1000;
|
if (!_hasCompletedRestartHold) {
|
||||||
|
possiblyAddStaticAssignmentsBackToQueueAfterRestart(&startTime);
|
||||||
qDebug("%d - %llu\n", _hasCompletedRestartHold, usecTimestampNow() - usecTimestamp(&startTime));
|
|
||||||
|
|
||||||
if (!_hasCompletedRestartHold && usecTimestampNow() - usecTimestamp(&startTime) > RESTART_HOLD_TIME_USECS) {
|
|
||||||
_hasCompletedRestartHold = true;
|
|
||||||
|
|
||||||
// pull anything in the static assignment file that isn't spoken for and add to the assignment queue
|
|
||||||
for (int i = 0; i < MAX_STATIC_ASSIGNMENT_FILE_ASSIGNMENTS; i++) {
|
|
||||||
if (_staticAssignments[i].getUUID().isNull()) {
|
|
||||||
// reached the end of static assignments, bail
|
|
||||||
qDebug() << "Reached the end of SA file with i at" << i << "\n";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool foundMatchingAssignment = false;
|
|
||||||
|
|
||||||
// enumerate the nodes and check if there is one with an attached assignment with matching UUID
|
|
||||||
for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
|
|
||||||
if (node->getLinkedData()) {
|
|
||||||
Assignment* linkedAssignment = (Assignment*) node->getLinkedData();
|
|
||||||
if (linkedAssignment->getUUID() == _staticAssignments[i].getUUID()) {
|
|
||||||
foundMatchingAssignment = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!foundMatchingAssignment) {
|
|
||||||
// this assignment has not been fulfilled - reset the UUID and add it to the assignment queue
|
|
||||||
_staticAssignments[i].resetUUID();
|
|
||||||
|
|
||||||
qDebug() << "Adding static assignment to queue -" << _staticAssignments[i] << "\n";
|
|
||||||
|
|
||||||
_assignmentQueueMutex.lock();
|
|
||||||
_assignmentQueue.push_back(&_staticAssignments[i]);
|
|
||||||
_assignmentQueueMutex.unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,7 @@ private:
|
||||||
Assignment* deployableAssignmentForRequest(Assignment& requestAssignment);
|
Assignment* deployableAssignmentForRequest(Assignment& requestAssignment);
|
||||||
void removeAssignmentFromQueue(Assignment* removableAssignment);
|
void removeAssignmentFromQueue(Assignment* removableAssignment);
|
||||||
bool checkInWithUUIDMatchesExistingNode(sockaddr* nodePublicSocket, sockaddr* nodeLocalSocket, const uchar* checkInData);
|
bool checkInWithUUIDMatchesExistingNode(sockaddr* nodePublicSocket, sockaddr* nodeLocalSocket, const uchar* checkInData);
|
||||||
|
void possiblyAddStaticAssignmentsBackToQueueAfterRestart(timeval* startTime);
|
||||||
|
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue