From 20733a81aecd0916d3d882f6c8c61c65b929cd69 Mon Sep 17 00:00:00 2001 From: Michael Hackstein Date: Fri, 15 Apr 2016 14:48:44 +0200 Subject: [PATCH] Improved baby errors in cluster --- arangod/Cluster/ClusterMethods.cpp | 10 ++++++- .../tests/shell/shell-document-babies.js | 29 ++++++++++++++----- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/arangod/Cluster/ClusterMethods.cpp b/arangod/Cluster/ClusterMethods.cpp index 9f86b2d08c..a2f4b5aadf 100644 --- a/arangod/Cluster/ClusterMethods.cpp +++ b/arangod/Cluster/ClusterMethods.cpp @@ -1129,6 +1129,9 @@ int deleteDocumentOnCoordinator( // If we get here we get exactly one result for every shard. TRI_ASSERT(allResults.size() == shardList->size()); mergeResultsAllShards(allResults, resultBody, errorCounter, shardList->size()); + responseCode = + (options.waitForSync ? GeneralResponse::ResponseCode::OK + : GeneralResponse::ResponseCode::ACCEPTED); return TRI_ERROR_NO_ERROR; } @@ -2042,7 +2045,9 @@ int modifyDocumentOnCoordinator( // Local data structores are automatically freed return error; } - TRI_ASSERT(res.answer_code == arangodb::GeneralResponse::ResponseCode::OK); + TRI_ASSERT(res.answer_code == arangodb::GeneralResponse::ResponseCode::OK || + res.answer_code == + arangodb::GeneralResponse::ResponseCode::ACCEPTED); TRI_ASSERT(res.answer != nullptr); allResults.emplace_back(res.answer->toVelocyPack(&VPackOptions::Defaults)); extractErrorCodes(res, errorCounter, false); @@ -2050,6 +2055,9 @@ int modifyDocumentOnCoordinator( // If we get here we get exactly one result for every shard. TRI_ASSERT(allResults.size() == shardList->size()); mergeResultsAllShards(allResults, resultBody, errorCounter, shardList->size()); + responseCode = + (options.waitForSync ? GeneralResponse::ResponseCode::OK + : GeneralResponse::ResponseCode::ACCEPTED); return TRI_ERROR_NO_ERROR; } diff --git a/js/common/tests/shell/shell-document-babies.js b/js/common/tests/shell/shell-document-babies.js index 2395e9169b..572a8e6a9b 100644 --- a/js/common/tests/shell/shell-document-babies.js +++ b/js/common/tests/shell/shell-document-babies.js @@ -29,6 +29,7 @@ var ERRORS = arangodb.errors; var db = arangodb.db; var internal = require("internal"); var wait = internal.wait; +var cluster = require("@arangodb/cluster"); //////////////////////////////////////////////////////////////////////////////// /// @brief test suite: babies for documents @@ -763,14 +764,26 @@ function CollectionDocumentSuiteBabies() { } // Replace - docs = collection.replace([x, x, x], [{}, {}, {}]); - assertEqual(docs.length, expectedLength); - for (var i = 0; i < expectedLength; ++i) { - assertEqual(docs[i].error, true); - if (typeof x === "string") { - assertEqual(docs[i].errorNum, ERRORS.ERROR_ARANGO_DOCUMENT_NOT_FOUND.code); - } else { - assertEqual(docs[i].errorNum, ERRORS.ERROR_ARANGO_DOCUMENT_HANDLE_BAD.code); + if (typeof x === "object" && !Array.isArray(x) && + cluster.isCoordinator()) { + try { + docs = collection.replace([x, x, x], [{}, {}, {}]); + fail(); + } catch (err) { + // In this case the coordinator will directly figure out that no + // keys are given + assertEqual(err.errorNum, ERRORS.ERROR_CLUSTER_NOT_ALL_SHARDING_ATTRIBUTES_GIVEN.code); + } + } else { + docs = collection.replace([x, x, x], [{}, {}, {}]); + assertEqual(docs.length, expectedLength); + for (var i = 0; i < expectedLength; ++i) { + assertEqual(docs[i].error, true); + if (typeof x === "string") { + assertEqual(docs[i].errorNum, ERRORS.ERROR_ARANGO_DOCUMENT_NOT_FOUND.code); + } else { + assertEqual(docs[i].errorNum, ERRORS.ERROR_ARANGO_DOCUMENT_HANDLE_BAD.code); + } } }