1
0
Fork 0

trx crud with empty arrays now short-circuit and return success with empty array. This lead to errors in cluster, band now is consistent with single-server.

This commit is contained in:
Michael Hackstein 2017-01-10 15:15:15 +01:00
parent c206645ebe
commit fe7a829592
2 changed files with 48 additions and 1 deletions

View File

@ -141,7 +141,7 @@ static OperationResult DBServerResponseBad(std::shared_ptr<VPackBuilder> resultB
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Insert an errror reported instead of the new document
/// @brief Insert an error reported instead of the new document
////////////////////////////////////////////////////////////////////////////////
static void createBabiesError(VPackBuilder& builder,
@ -164,6 +164,15 @@ static void createBabiesError(VPackBuilder& builder,
}
}
static OperationResult EmptyResult(bool waitForSync) {
VPackBuilder resultBuilder;
resultBuilder.openArray();
resultBuilder.close();
std::unordered_map<int, size_t> errorCounter;
return OperationResult(resultBuilder.steal(), nullptr, "", TRI_ERROR_NO_ERROR,
waitForSync, errorCounter);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief sort ORs for the same attribute so they are in ascending value
/// order. this will only work if the condition is for a single attribute
@ -1774,6 +1783,9 @@ OperationResult Transaction::insert(std::string const& collectionName,
// must provide a document object or an array of documents
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_DOCUMENT_TYPE_INVALID);
}
if (value.isArray() && value.length() == 0) {
return EmptyResult(options.waitForSync);
}
// Validate Edges
OperationOptions optionsCopy = options;
@ -2024,6 +2036,9 @@ OperationResult Transaction::update(std::string const& collectionName,
// must provide a document object or an array of documents
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_DOCUMENT_TYPE_INVALID);
}
if (newValue.isArray() && newValue.length() == 0) {
return EmptyResult(options.waitForSync);
}
OperationOptions optionsCopy = options;
@ -2078,6 +2093,9 @@ OperationResult Transaction::replace(std::string const& collectionName,
// must provide a document object or an array of documents
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_DOCUMENT_TYPE_INVALID);
}
if (newValue.isArray() && newValue.length() == 0) {
return EmptyResult(options.waitForSync);
}
OperationOptions optionsCopy = options;
@ -2338,6 +2356,9 @@ OperationResult Transaction::remove(std::string const& collectionName,
// must provide a document object or an array of documents
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_DOCUMENT_TYPE_INVALID);
}
if (value.isArray() && value.length() == 0) {
return EmptyResult(options.waitForSync);
}
OperationOptions optionsCopy = options;

View File

@ -882,6 +882,32 @@ function CollectionDocumentSuiteBabies() {
assertEqual(ERRORS.ERROR_ARANGO_DOCUMENT_TYPE_INVALID.code,
err6.errorNum);
}
},
////////////////////////////////////////////////////////////////////////////////
/// @brief test insert/replace/update/remove with empty lists
////////////////////////////////////////////////////////////////////////////////
testEmptyBabiesList: function() {
// Insert
let result = collection.insert([]);
assertTrue(Array.isArray(result));
assertEqual(result.length, 0);
// Update
result = collection.update([], []);
assertTrue(Array.isArray(result));
assertEqual(result.length, 0);
// Replace
result = collection.replace([], []);
assertTrue(Array.isArray(result));
assertEqual(result.length, 0);
// Remove
result = collection.remove([]);
assertTrue(Array.isArray(result));
assertEqual(result.length, 0);
}
};