diff --git a/arangod/Agency/Supervision.cpp b/arangod/Agency/Supervision.cpp index e23d414fba..6168fa6e99 100644 --- a/arangod/Agency/Supervision.cpp +++ b/arangod/Agency/Supervision.cpp @@ -165,7 +165,8 @@ std::vector Supervision::checkDBServers() { del->openArray(); del->openObject(); for (auto const& srv : todelete) { - del->add(_agencyPrefix + healthPrefix + srv, VPackValue(VPackValueType::Object)); + del->add(_agencyPrefix + healthPrefix + srv, + VPackValue(VPackValueType::Object)); del->add("op", VPackValue("delete")); del->close(); } @@ -273,7 +274,8 @@ std::vector Supervision::checkCoordinators() { del->openArray(); del->openObject(); for (auto const& srv : todelete) { - del->add(_agencyPrefix + healthPrefix + srv, VPackValue(VPackValueType::Object)); + del->add(_agencyPrefix + healthPrefix + srv, + VPackValue(VPackValueType::Object)); del->add("op", VPackValue("delete")); del->close(); } @@ -450,7 +452,8 @@ void Supervision::shrinkCluster () { // Minimum 1 DB server must remain if (availServers.size() == 1) { - LOG_TOPIC(DEBUG, Logger::AGENCY) << "Only one db server left for operation"; + LOG_TOPIC(DEBUG, Logger::AGENCY) << + "Only one db server left for operation"; return; } @@ -464,9 +467,9 @@ void Supervision::shrinkCluster () { if (replFact > maxReplFact) { maxReplFact = replFact; } - } catch (std::exception const&) { - LOG_TOPIC(DEBUG, Logger::AGENCY) << - "Cannot retrieve replication factor for collection " << collptr.first; + } catch (std::exception const& e) { + LOG_TOPIC(DEBUG, Logger::AGENCY) << "Cannot retrieve replication " << + "factor for collection " << collptr.first; return; } } @@ -537,7 +540,7 @@ void Supervision::getUniqueIds() { while (!this->isStopping()) { try { latestId = std::stoul( - _agent->readDB().get(_agencyPrefix + "/Sync/LatestID").slice().toJson()); + _agent->readDB().get(_agencyPrefix + "/Sync/LatestID").slice().toJson()); } catch (...) { std::this_thread::sleep_for (std::chrono::seconds(1)); continue; diff --git a/js/server/tests/resilience/moving-shards-cluster.js b/js/server/tests/resilience/moving-shards-cluster.js index a4d9c5c417..001b823bca 100644 --- a/js/server/tests/resilience/moving-shards-cluster.js +++ b/js/server/tests/resilience/moving-shards-cluster.js @@ -131,7 +131,13 @@ function MovingShardsSuite () { if (!ok) { return false; } + } + + // Now get to work, first get the write lock on the Plan in the Agency: + //var success = ArangoAgency.lockRead("Target/CleanedServers", 0.5); + //print(ArangoAgency.get("Target/CleanedServers", false, true)); + return true; } @@ -150,6 +156,37 @@ function MovingShardsSuite () { body: JSON.stringify(body) }); } +//////////////////////////////////////////////////////////////////////////////// +/// @brief order the cluster to reduce number of db servers +//////////////////////////////////////////////////////////////////////////////// + + function shrinkCluster(toNum) { + var coordEndpoint = global.ArangoClusterInfo.getServerEndpoint("Coordinator001"); + var request = require("@arangodb/request"); + var endpointToURL = require("@arangodb/cluster").endpointToURL; + var url = endpointToURL(coordEndpoint); + var body = {"numberOfDBServers":toNum}; + return request({ method: "PUT", + url: url + "/_admin/cluster/numberOfServers", + body: JSON.stringify(body) }); + } + +//////////////////////////////////////////////////////////////////////////////// +/// @brief order the cluster to clean out a server: +//////////////////////////////////////////////////////////////////////////////// + + function resetCleanedOutServers() { + var coordEndpoint = global.ArangoClusterInfo.getServerEndpoint("Coordinator001"); + var request = require("@arangodb/request"); + var endpointToURL = require("@arangodb/cluster").endpointToURL; + var url = endpointToURL(coordEndpoint); + var numberOfDBServers = global.ArangoClusterInfo.getDBServers().length; + var body = {"cleanedServers":[], "numberOfDBServers":numberOfDBServers}; + return request({ method: "PUT", + url: url + "/_admin/cluster/numberOfServers", + body: JSON.stringify(body) }); + } + //////////////////////////////////////////////////////////////////////////////// /// @brief move a single shard //////////////////////////////////////////////////////////////////////////////// @@ -235,6 +272,7 @@ function MovingShardsSuite () { c[i].drop(); } c = []; + resetCleanedOutServers(); }, //////////////////////////////////////////////////////////////////////////////// @@ -245,6 +283,23 @@ function MovingShardsSuite () { assertTrue(waitForSynchronousReplication("_system")); }, +//////////////////////////////////////////////////////////////////////////////// +/// @brief cleaning out collection with one shard without replication +//////////////////////////////////////////////////////////////////////////////// + +/* testShrinkNoReplication : function() { + assertTrue(waitForSynchronousReplication("_system")); + shrinkCluster(4); + assertTrue(testServerEmpty("DBServer005")); + shrinkCluster(3); + assertTrue(testServerEmpty("DBServer004")); + shrinkCluster(2); + assertTrue(testServerEmpty("DBServer003")); + shrinkCluster(1); + assert(testServerEmpty("DBServer002")); + },*/ + + //////////////////////////////////////////////////////////////////////////////// /// @brief moving away a shard from a follower ////////////////////////////////////////////////////////////////////////////////