diff --git a/arangod/Aql/ClusterBlocks.cpp b/arangod/Aql/ClusterBlocks.cpp index 4cc461b09d..10024b1329 100644 --- a/arangod/Aql/ClusterBlocks.cpp +++ b/arangod/Aql/ClusterBlocks.cpp @@ -1076,10 +1076,7 @@ static bool throwExceptionAfterBadSyncRequest(ClusterCommResult* res, bool isShutdown) { ENTER_BLOCK if (res->status == CL_COMM_TIMEOUT) { - std::string errorMessage = - std::string("Timeout in communication with shard '") + - std::string(res->shardID) + std::string("' on cluster node '") + - std::string(res->serverID) + std::string("' failed."); + std::string errorMessage = res->stringifyErrorMessage(); // No reply, we give up: THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_CLUSTER_TIMEOUT, errorMessage); @@ -1087,10 +1084,7 @@ static bool throwExceptionAfterBadSyncRequest(ClusterCommResult* res, if (res->status == CL_COMM_BACKEND_UNAVAILABLE) { // there is no result - std::string errorMessage = - std::string("Empty result in communication with shard '") + - std::string(res->shardID) + std::string("' on cluster node '") + - std::string(res->serverID) + std::string("'"); + std::string errorMessage = res->stringifyErrorMessage(); THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_CLUSTER_CONNECTION_LOST, errorMessage); } diff --git a/arangod/Aql/ExecutionEngine.cpp b/arangod/Aql/ExecutionEngine.cpp index 47aaa66d41..c434ad5dbc 100644 --- a/arangod/Aql/ExecutionEngine.cpp +++ b/arangod/Aql/ExecutionEngine.cpp @@ -559,10 +559,7 @@ struct CoordinatorInstanciator : public WalkerWorker { error += "\n"; } } else { - error += std::string("Communication with shard '") + - std::string(res.shardID) + std::string("' on cluster node '") + - std::string(res.serverID) + std::string("' failed : ") + - res.errorMessage; + error += res.stringifyErrorMessage(); } } @@ -963,11 +960,10 @@ ExecutionEngine* ExecutionEngine::instantiateFromPlan( url, "{\"code\": 0}", headers, 120.0); // Ignore result, we need to try to remove all. // However, log the incident if we have an errorMessage. - if (res->errorMessage.length() > 0) { + if (!res->errorMessage.empty()) { std::string msg("while trying to unregister query "); - msg += queryId + std::string("from shard: ") + shardId + - std::string("communication failed: ") + res->errorMessage; - LOG(WARN) << "" << msg; + msg += queryId + ": " + res->stringifyErrorMessage(); + LOG(WARN) << msg; } } else { // Remove query from registry: diff --git a/arangod/Cluster/ClusterComm.cpp b/arangod/Cluster/ClusterComm.cpp index 9eaa862291..8f989987b3 100644 --- a/arangod/Cluster/ClusterComm.cpp +++ b/arangod/Cluster/ClusterComm.cpp @@ -115,6 +115,61 @@ void ClusterCommResult::setDestination(std::string const& dest, } } } + +/// @brief stringify the internal error state +std::string ClusterCommResult::stringifyErrorMessage() const { + // append status string + std::string result(stringifyStatus(status)); + + if (!serverID.empty()) { + result.append(", cluster node: '"); + result.append(serverID); + result.push_back('\''); + } + + if (!shardID.empty()) { + result.append(", shard: '"); + result.append(shardID); + result.push_back('\''); + } + + if (!endpoint.empty()) { + result.append(", endpoint: '"); + result.append(endpoint); + result.push_back('\''); + } + + if (!errorMessage.empty()) { + result.append(", error: '"); + result.append(errorMessage); + result.push_back('\''); + } + + return result; +} + +/// @brief stringify a cluster comm status +char const* ClusterCommResult::stringifyStatus(ClusterCommOpStatus status) { + switch (status) { + case CL_COMM_SUBMITTED: + return "submitted"; + case CL_COMM_SENDING: + return "sending"; + case CL_COMM_SENT: + return "sent"; + case CL_COMM_TIMEOUT: + return "timeout"; + case CL_COMM_RECEIVED: + return "received"; + case CL_COMM_ERROR: + return "error"; + case CL_COMM_DROPPED: + return "dropped"; + case CL_COMM_BACKEND_UNAVAILABLE: + return "backend unavailable"; + } + return "unknown"; +} //////////////////////////////////////////////////////////////////////////////// /// @brief ClusterComm constructor diff --git a/arangod/Cluster/ClusterComm.h b/arangod/Cluster/ClusterComm.h index cfca78c5ac..df98db0cc4 100644 --- a/arangod/Cluster/ClusterComm.h +++ b/arangod/Cluster/ClusterComm.h @@ -212,6 +212,12 @@ struct ClusterCommResult { ////////////////////////////////////////////////////////////////////////////// void setDestination(std::string const& dest, bool logConnectionErrors); + + /// @brief stringify the internal error state + std::string stringifyErrorMessage() const; + + /// @brief stringify a cluster comm status + static char const* stringifyStatus(ClusterCommOpStatus status); }; ////////////////////////////////////////////////////////////////////////////////