From e053742f4516f05b54121f485fbfbc523d84ff8b Mon Sep 17 00:00:00 2001 From: Kaveh Vahedipour Date: Thu, 9 Jun 2016 11:02:51 +0200 Subject: [PATCH 1/2] move-shard slightly changed order of actions --- arangod/Agency/MoveShard.cpp | 84 +++++++++++++++++++++++++----------- 1 file changed, 59 insertions(+), 25 deletions(-) diff --git a/arangod/Agency/MoveShard.cpp b/arangod/Agency/MoveShard.cpp index 7b87aacf75..e308ff2050 100644 --- a/arangod/Agency/MoveShard.cpp +++ b/arangod/Agency/MoveShard.cpp @@ -167,7 +167,7 @@ bool MoveShard::start() { // --- Plan changes pending.add(_agencyPrefix + planPath, VPackValue(VPackValueType::Array)); if (current[0].copyString() == _from) { // Leader - pending.add(VPackValue(std::string("_") + current[0].copyString())); + pending.add(current[0]); pending.add(VPackValue(_to)); for (size_t i = 1; i < current.length(); ++i) { pending.add(current[i]); @@ -252,9 +252,9 @@ JOB_STATUS MoveShard::status () { if (current == plan) { - if ((current[0].copyString())[0] == '_') { // Leader + if ((current[0].copyString())[0] == '_') { // Retired leader - Builder cyclic; + Builder cyclic; // Cyclic shift _serverId to end cyclic.openArray(); cyclic.openObject(); // --- Plan changes @@ -278,36 +278,70 @@ JOB_STATUS MoveShard::status () { } else { - bool found = false; + bool foundFrom = false, foundTo = false; for (auto const& srv : VPackArrayIterator(current)) { - if (srv.copyString() == _from) { - found = true; - break; + std::string srv_str = srv.copyString(); + if (srv_str == _from) { + foundFrom = true; + } + if (srv_str == _to) { + foundTo = true; } } - if (found) { - - Builder remove; - remove.openArray(); - remove.openObject(); - // --- Plan changes - remove.add(_agencyPrefix + planPath, VPackValue(VPackValueType::Array)); - for (auto const& srv : VPackArrayIterator(current)) { - if (srv.copyString() != _from) { - remove.add(srv); + if (foundFrom && foundTo) { + + LOG(WARN) << current[0].copyString() << " " << _from; + if (current[0].copyString() == _from) { // Leader + + Builder underscore; // serverId -> _serverId + underscore.openArray(); + underscore.openObject(); + // --- Plan changes + underscore.add(_agencyPrefix + planPath, + VPackValue(VPackValueType::Array)); + underscore.add( + VPackValue(std::string("_") + current[0].copyString())); + for (size_t i = 1; i < current.length(); ++i) { + underscore.add(current[i]); } + underscore.close(); + + // --- Plan version + underscore.add(_agencyPrefix + planVersion, + VPackValue(VPackValueType::Object)); + underscore.add("op", VPackValue("increment")); + underscore.close(); + underscore.close(); underscore.close(); + transact(_agent, underscore); + + } else { + + Builder remove; + remove.openArray(); + remove.openObject(); + // --- Plan changes + remove.add(_agencyPrefix + planPath, VPackValue(VPackValueType::Array)); + for (auto const& srv : VPackArrayIterator(current)) { + if (srv.copyString() != _from) { + remove.add(srv); + } + } + remove.close(); + // --- Plan version + remove.add(_agencyPrefix + planVersion, + VPackValue(VPackValueType::Object)); + remove.add("op", VPackValue("increment")); + remove.close(); + remove.close(); remove.close(); + transact(_agent, remove); + } - remove.close(); - // --- Plan version - remove.add(_agencyPrefix + planVersion, - VPackValue(VPackValueType::Object)); - remove.add("op", VPackValue("increment")); - remove.close(); - remove.close(); remove.close(); - transact(_agent, remove); return PENDING; + } else if (foundTo && !foundFrom) { + + return FINISHED; } From e806beca57e99f003a483fad309bcfe96ea4967d Mon Sep 17 00:00:00 2001 From: Kaveh Vahedipour Date: Thu, 9 Jun 2016 11:03:37 +0200 Subject: [PATCH 2/2] move-shard slightly changed order of actions --- arangod/Agency/MoveShard.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arangod/Agency/MoveShard.cpp b/arangod/Agency/MoveShard.cpp index 62b41fe6b8..d5945a567a 100644 --- a/arangod/Agency/MoveShard.cpp +++ b/arangod/Agency/MoveShard.cpp @@ -292,7 +292,6 @@ JOB_STATUS MoveShard::status () { if (foundFrom && foundTo) { - LOG(WARN) << current[0].copyString() << " " << _from; if (current[0].copyString() == _from) { // Leader Builder underscore; // serverId -> _serverId @@ -340,6 +339,7 @@ JOB_STATUS MoveShard::status () { } return PENDING; + } else if (foundTo && !foundFrom) { return FINISHED;