From e5c5bb75528a31fc550f4b7c589f917af59a53d4 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 1 Oct 2013 16:15:07 -0700 Subject: [PATCH] completion of fix for requesting AC on DS restart --- domain-server/src/DomainServer.cpp | 90 +++++++++++++++++------------- domain-server/src/DomainServer.h | 1 + 2 files changed, 52 insertions(+), 39 deletions(-) diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 302590af41..11408e8a6d 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -339,6 +339,51 @@ bool DomainServer::checkInWithUUIDMatchesExistingNode(sockaddr* nodePublicSocket 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() { _staticAssignmentFile.unmap(_staticAssignmentFileData); _staticAssignmentFile.close(); @@ -485,45 +530,8 @@ int DomainServer::run() { qDebug("Received a request for assignment.\n"); - // 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 (!_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 - 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(); - } - } + if (_hasCompletedRestartHold) { + possiblyAddStaticAssignmentsBackToQueueAfterRestart(&startTime); } if (_assignmentQueue.size() > 0) { @@ -592,6 +600,10 @@ int DomainServer::run() { } } } + + if (!_hasCompletedRestartHold) { + possiblyAddStaticAssignmentsBackToQueueAfterRestart(&startTime); + } } this->cleanup(); diff --git a/domain-server/src/DomainServer.h b/domain-server/src/DomainServer.h index 5ecf00e843..05ab3bd074 100644 --- a/domain-server/src/DomainServer.h +++ b/domain-server/src/DomainServer.h @@ -46,6 +46,7 @@ private: Assignment* deployableAssignmentForRequest(Assignment& requestAssignment); void removeAssignmentFromQueue(Assignment* removableAssignment); bool checkInWithUUIDMatchesExistingNode(sockaddr* nodePublicSocket, sockaddr* nodeLocalSocket, const uchar* checkInData); + void possiblyAddStaticAssignmentsBackToQueueAfterRestart(timeval* startTime); void cleanup();