From 73b7d6751049ebc8924677b06efd355d0f03a900 Mon Sep 17 00:00:00 2001 From: Andreas Streichardt Date: Thu, 8 Jun 2017 14:41:33 +0200 Subject: [PATCH] Response can always be a nullptr --- arangod/Aql/ClusterBlocks.cpp | 61 +++++++++++++++--------------- arangod/Cluster/ClusterFeature.cpp | 4 +- arangod/Cluster/ClusterFeature.h | 1 + 3 files changed, 34 insertions(+), 32 deletions(-) diff --git a/arangod/Aql/ClusterBlocks.cpp b/arangod/Aql/ClusterBlocks.cpp index 4f5caf6762..3784524d7b 100644 --- a/arangod/Aql/ClusterBlocks.cpp +++ b/arangod/Aql/ClusterBlocks.cpp @@ -1167,44 +1167,43 @@ static bool throwExceptionAfterBadSyncRequest(ClusterCommResult* res, } if (res->status == CL_COMM_ERROR) { - std::string errorMessage; - TRI_ASSERT(nullptr != res->result); - - arangodb::basics::StringBuffer const& responseBodyBuf(res->result->getBody()); - - // extract error number and message from response - int errorNum = TRI_ERROR_NO_ERROR; - std::shared_ptr builder = VPackParser::fromJson( - responseBodyBuf.c_str(), responseBodyBuf.length()); - VPackSlice slice = builder->slice(); - - if (!slice.hasKey("error") || slice.get("error").getBoolean()) { - errorNum = TRI_ERROR_INTERNAL; - errorMessage = std::string("Error message received from shard '") + + std::string errorMessage = std::string("Error message received from shard '") + std::string(res->shardID) + std::string("' on cluster node '") + std::string(res->serverID) + std::string("': "); - } - if (slice.isObject()) { - VPackSlice v = slice.get("errorNum"); - if (v.isNumber()) { - if (v.getNumericValue() != TRI_ERROR_NO_ERROR) { - /* if we've got an error num, error has to be true. */ - TRI_ASSERT(errorNum == TRI_ERROR_INTERNAL); - errorNum = v.getNumericValue(); + int errorNum = TRI_ERROR_INTERNAL; + std::string errorDetailMessage = std::string("(no valid response)"); + if (res->result != nullptr) { + errorNum = TRI_ERROR_NO_ERROR; + } else { + arangodb::basics::StringBuffer const& responseBodyBuf(res->result->getBody()); + std::shared_ptr builder = VPackParser::fromJson( + responseBodyBuf.c_str(), responseBodyBuf.length()); + VPackSlice slice = builder->slice(); + + if (!slice.hasKey("error") || slice.get("error").getBoolean()) { + errorNum = TRI_ERROR_INTERNAL; + } + + if (slice.isObject()) { + VPackSlice v = slice.get("errorNum"); + if (v.isNumber()) { + if (v.getNumericValue() != TRI_ERROR_NO_ERROR) { + /* if we've got an error num, error has to be true. */ + TRI_ASSERT(errorNum == TRI_ERROR_INTERNAL); + errorNum = v.getNumericValue(); + } + } + + v = slice.get("errorMessage"); + if (v.isString()) { + errorMessage += v.copyString(); + } else { + errorMessage += std::string("(no valid error in response)"); } } - - v = slice.get("errorMessage"); - if (v.isString()) { - errorMessage += v.copyString(); - } else { - errorMessage += std::string("(no valid error in response)"); - } - } else { - errorMessage += std::string("(no valid response)"); } if (isShutdown && errorNum == TRI_ERROR_QUERY_NOT_FOUND) { diff --git a/arangod/Cluster/ClusterFeature.cpp b/arangod/Cluster/ClusterFeature.cpp index a6050ada81..c43051b8d8 100644 --- a/arangod/Cluster/ClusterFeature.cpp +++ b/arangod/Cluster/ClusterFeature.cpp @@ -485,6 +485,9 @@ void ClusterFeature::start() { } } +void ClusterFeature::beginShutdown() { + ClusterComm::instance()->disable(); +} void ClusterFeature::stop() { @@ -537,7 +540,6 @@ void ClusterFeature::unprepare() { } if (!_enableCluster) { - ClusterComm::instance()->disable(); ClusterComm::cleanup(); return; } diff --git a/arangod/Cluster/ClusterFeature.h b/arangod/Cluster/ClusterFeature.h index cfdbbbbcce..e9b2fd47d7 100644 --- a/arangod/Cluster/ClusterFeature.h +++ b/arangod/Cluster/ClusterFeature.h @@ -43,6 +43,7 @@ class ClusterFeature : public application_features::ApplicationFeature { void validateOptions(std::shared_ptr) override final; void prepare() override final; void start() override final; + void beginShutdown() override final; void unprepare() override final; std::string agencyPrefix() {