From a9b282a231f3d1a4671fde0c75b4f219aa6d17a2 Mon Sep 17 00:00:00 2001 From: Andreas Streichardt Date: Thu, 14 Apr 2016 13:12:57 +0200 Subject: [PATCH] Init done in one step --- arangod/Cluster/AgencyComm.cpp | 70 +++++----------------------------- arangod/Cluster/AgencyComm.h | 3 ++ 2 files changed, 12 insertions(+), 61 deletions(-) diff --git a/arangod/Cluster/AgencyComm.cpp b/arangod/Cluster/AgencyComm.cpp index b9971c7c8e..19e17563fd 100644 --- a/arangod/Cluster/AgencyComm.cpp +++ b/arangod/Cluster/AgencyComm.cpp @@ -645,18 +645,6 @@ bool AgencyComm::initialize() { ////////////////////////////////////////////////////////////////////////////// bool AgencyComm::tryInitializeStructure() { - VPackBuilder trueBuilder; - trueBuilder.add(VPackValue(true)); - - VPackSlice trueSlice = trueBuilder.slice(); - - AgencyCommResult result; - result = casValue("Init", trueSlice, false, 120.0, 0.0); - if (!result.successful()) { - // mop: we couldn"t aquire a lock. so somebody else is already initializing - return false; - } - VPackBuilder builder; try { VPackObjectBuilder b(&builder); @@ -731,6 +719,7 @@ bool AgencyComm::tryInitializeStructure() { } addEmptyVPackObject("DBServers", builder); builder.add("Lock", VPackValue("\"UNLOCKED\"")); + builder.add("InitDone", VPackValue(true)); } } catch (...) { LOG(WARN) << "Couldn't create initializing structure"; @@ -738,22 +727,16 @@ bool AgencyComm::tryInitializeStructure() { } try { - VPackSlice s = builder.slice(); + LOG(DEBUG) << "Initializing agency with " << builder.toJson(); - // now dump the Slice into an std::string - std::string buffer; - VPackStringSink sink(&buffer); - VPackDumper::dump(s, &sink); + AgencyCommResult result; + AgencyOperation initOperation("", AgencyValueOperationType::SET, builder.slice()); + AgencyTransaction initTransaction; + initTransaction.operations.push_back(initOperation); - LOG(DEBUG) << "Initializing agency with " << buffer; - - if (!initFromVPackSlice(std::string(""), s)) { - LOG(FATAL) << "Couldn't initialize agency"; - FATAL_ERROR_EXIT(); - } else { - setValue("InitDone", trueSlice, 0.0); - return true; - } + sendTransactionWithFailover(result, initTransaction); + + return result.successful(); } catch (std::exception const& e) { LOG(FATAL) << "Fatal error initializing agency " << e.what(); FATAL_ERROR_EXIT(); @@ -763,41 +746,6 @@ bool AgencyComm::tryInitializeStructure() { } } -bool AgencyComm::initFromVPackSlice(std::string key, VPackSlice s) { - bool ret = true; - AgencyCommResult result; - if (s.isObject()) { - if (!key.empty()) { - result = createDirectory(key); - if (!result.successful()) { - // mop: forbidden will be thrown if directory already exists - // need ability to recover in a case where the agency was half - // initialized - if (result.httpCode() != - (int)arangodb::GeneralResponse::ResponseCode::FORBIDDEN) { - ret = false; - return ret; - } - } - } - - for (auto const& it : VPackObjectIterator(s)) { - std::string subKey(""); - if (!key.empty()) { - subKey += key + "/"; - } - subKey += it.key.copyString(); - - ret = ret && initFromVPackSlice(subKey, it.value); - } - } else { - result = setValue(key, s.copyString(), 0.0); - ret = ret && result.successful(); - } - - return ret; -} - ////////////////////////////////////////////////////////////////////////////// /// @brief checks if the agency is initialized ////////////////////////////////////////////////////////////////////////////// diff --git a/arangod/Cluster/AgencyComm.h b/arangod/Cluster/AgencyComm.h index 355e40872d..4874bc5308 100644 --- a/arangod/Cluster/AgencyComm.h +++ b/arangod/Cluster/AgencyComm.h @@ -235,6 +235,9 @@ struct AgencyTransaction { explicit AgencyTransaction(AgencyOperation const& operation) { operations.push_back(operation); } + + explicit AgencyTransaction() { + } }; struct AgencyCommResult {