From ed733b66f582dcbbe16dbf8d2b10921da288ce48 Mon Sep 17 00:00:00 2001 From: Light Date: Mon, 16 Mar 2020 18:26:27 -0400 Subject: [PATCH] Added config option to TaskManager to allow node0 to be the preferred node and run tasks that are declared as "any" in taskmanager.rc --- .../src/shared/ConfigTaskManager.cpp | 1 + .../src/shared/ConfigTaskManager.h | 10 ++++++- .../TaskManager/src/shared/Locator.cpp | 26 ++++++++++++++----- .../TaskManager/src/shared/Locator.h | 1 + .../src/shared/ManagerConnection.cpp | 2 +- .../TaskManager/src/shared/TaskManager.cpp | 13 ++++++---- 6 files changed, 40 insertions(+), 13 deletions(-) diff --git a/engine/server/application/TaskManager/src/shared/ConfigTaskManager.cpp b/engine/server/application/TaskManager/src/shared/ConfigTaskManager.cpp index 20c68e81..fba9fd8a 100755 --- a/engine/server/application/TaskManager/src/shared/ConfigTaskManager.cpp +++ b/engine/server/application/TaskManager/src/shared/ConfigTaskManager.cpp @@ -82,6 +82,7 @@ void ConfigTaskManager::install(void) KEY_INT (maximumClockDriftToleranceSeconds, 10); // seconds KEY_INT (systemTimeCheckIntervalSeconds, 60); // seconds KEY_INT (clockDriftFatalIntervalSeconds, 1*60*60); // seconds + KEY_BOOL (allowPreferredServerOnMasterNode, false); int index = 0; char const * result = 0; diff --git a/engine/server/application/TaskManager/src/shared/ConfigTaskManager.h b/engine/server/application/TaskManager/src/shared/ConfigTaskManager.h index 16a78225..806744e2 100755 --- a/engine/server/application/TaskManager/src/shared/ConfigTaskManager.h +++ b/engine/server/application/TaskManager/src/shared/ConfigTaskManager.h @@ -39,6 +39,7 @@ class ConfigTaskManager int maximumClockDriftToleranceSeconds; int systemTimeCheckIntervalSeconds; int clockDriftFatalIntervalSeconds; + bool allowPreferredServerOnMasterNode; }; static const bool getAutoStart (); @@ -68,7 +69,7 @@ class ConfigTaskManager static int getMaximumClockDriftToleranceSeconds(); static int getSystemTimeCheckIntervalSeconds(); static int getClockDriftFatalIntervalSeconds(); - + static const bool getAllowPreferredServerOnMasterNode(); static void install (); static void remove (); @@ -270,4 +271,11 @@ inline int ConfigTaskManager::getClockDriftFatalIntervalSeconds() // ---------------------------------------------------------------------- +inline const bool ConfigTaskManager::getAllowPreferredServerOnMasterNode() +{ + return data->allowPreferredServerOnMasterNode; +} + +// ---------------------------------------------------------------------- + #endif // _ConfigTaskManager_H diff --git a/engine/server/application/TaskManager/src/shared/Locator.cpp b/engine/server/application/TaskManager/src/shared/Locator.cpp index 2dac97f8..b9884038 100755 --- a/engine/server/application/TaskManager/src/shared/Locator.cpp +++ b/engine/server/application/TaskManager/src/shared/Locator.cpp @@ -146,19 +146,33 @@ ManagerConnection *LocatorNamespace::getPreferredServer(std::string const &proce { ServerEntry &e = *i; if ((e.m_label != s_masterNodeLabel) && (e.hasAvailableLoad(cost))) - { + { for (std::vector::const_iterator j = s_preferredNodes.begin(); j != s_preferredNodes.end(); ++j) if ((*j).m_nodeLabel == e.m_label && (*j).match(processName, options)) return e.m_connection; - } - } + } + } return 0; } // ---------------------------------------------------------------------- -ManagerConnection *LocatorNamespace::getUnpreferredServer(float cost) +bool Locator::isMasterNodePreferred(std::string const &processName, std::string const &options, float cost) { + if(!ConfigTaskManager::getAllowPreferredServerOnMasterNode()) + return false; + + for (std::vector::const_iterator j = s_preferredNodes.begin(); j != s_preferredNodes.end(); ++j) + if ((*j).m_nodeLabel == s_masterNodeLabel && (*j).match(processName, options)) + return true; + + return false; +} + +// ---------------------------------------------------------------------- + +ManagerConnection *LocatorNamespace::getUnpreferredServer(float cost) +{ // Find a node other than the master node that can afford to run the process // and is a not marked as a preferred node for anything; if more than one // node qualifies, return the node with the lowest load @@ -190,8 +204,8 @@ ManagerConnection *LocatorNamespace::getUnpreferredServer(float cost) // ---------------------------------------------------------------------- ManagerConnection *Locator::getBestServer(std::string const &processName, std::string const &options, float cost) -{ - if (s_serverList.empty()) +{ + if (s_serverList.empty()) return 0; // first, look for a preferred node for this process diff --git a/engine/server/application/TaskManager/src/shared/Locator.h b/engine/server/application/TaskManager/src/shared/Locator.h index 1714a4b5..d0b34505 100755 --- a/engine/server/application/TaskManager/src/shared/Locator.h +++ b/engine/server/application/TaskManager/src/shared/Locator.h @@ -24,6 +24,7 @@ public: static void install(); static void closed(std::string const &label, ManagerConnection const *oldConnection); static ManagerConnection *getBestServer(std::string const &processName, std::string const &options, float cost); + static bool isMasterNodePreferred(std::string const &processName, std::string const &options, float cost); static float getMyLoad(); static float getMyMaximumLoad(); static float getServerLoad(std::string const &label); diff --git a/engine/server/application/TaskManager/src/shared/ManagerConnection.cpp b/engine/server/application/TaskManager/src/shared/ManagerConnection.cpp index 3aa53136..42db2099 100755 --- a/engine/server/application/TaskManager/src/shared/ManagerConnection.cpp +++ b/engine/server/application/TaskManager/src/shared/ManagerConnection.cpp @@ -84,7 +84,7 @@ void ManagerConnection::onConnectionClosed() void ManagerConnection::onConnectionOpened() { - DEBUG_REPORT_LOG(true, ("Manager connection opened\n")); + DEBUG_REPORT_LOG(true, ("Manager connection opened for %s \n", getRemoteAddress().c_str())); TaskConnectionIdMessage id(TaskConnectionIdMessage::TaskManager, TaskManager::getNodeLabel(), ConfigTaskManager::getClusterName()); send(id); s_managerConnectionCount++; diff --git a/engine/server/application/TaskManager/src/shared/TaskManager.cpp b/engine/server/application/TaskManager/src/shared/TaskManager.cpp index 24243de7..f4a9ec31 100755 --- a/engine/server/application/TaskManager/src/shared/TaskManager.cpp +++ b/engine/server/application/TaskManager/src/shared/TaskManager.cpp @@ -613,7 +613,6 @@ unsigned long TaskManager::startServer(const std::string & processName, const st } const ProcessEntry pe = (*f).second; - // does the process run on this box? if(pe.targetHost == "local" || pe.targetHost == getNodeLabel() || nodeLabel == getNodeLabel() || nodeLabel == "local") { @@ -646,10 +645,14 @@ unsigned long TaskManager::startServer(const std::string & processName, const st // select a task manager on which to spawn the server // find the best target float cost = getLoadForProcess(pe.processName); - ManagerConnection * conn = Locator::getBestServer(pe.processName, options, cost); - if(!conn) + if(Locator::isMasterNodePreferred(pe.processName, options, cost)) { - + pid = startServerLocal(pe, options); + } + ManagerConnection * conn = Locator::getBestServer(pe.processName, options, cost); + if(!conn && !pid) + { + if(ManagerConnection::getConnectionCount() < 1) pid = startServerLocal(pe, options); else @@ -666,7 +669,7 @@ unsigned long TaskManager::startServer(const std::string & processName, const st s_queuedSpawnRequests.push_back(r); } } - else + else if(!pid) { std::string label = "uninitialized label"; if(conn->getNodeLabel())