mirror of https://gitee.com/bigwinds/arangodb
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:
parent
c206645ebe
commit
fe7a829592
|
@ -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,
|
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
|
/// @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
|
/// 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
|
// must provide a document object or an array of documents
|
||||||
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_DOCUMENT_TYPE_INVALID);
|
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_DOCUMENT_TYPE_INVALID);
|
||||||
}
|
}
|
||||||
|
if (value.isArray() && value.length() == 0) {
|
||||||
|
return EmptyResult(options.waitForSync);
|
||||||
|
}
|
||||||
|
|
||||||
// Validate Edges
|
// Validate Edges
|
||||||
OperationOptions optionsCopy = options;
|
OperationOptions optionsCopy = options;
|
||||||
|
@ -2024,6 +2036,9 @@ OperationResult Transaction::update(std::string const& collectionName,
|
||||||
// must provide a document object or an array of documents
|
// must provide a document object or an array of documents
|
||||||
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_DOCUMENT_TYPE_INVALID);
|
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_DOCUMENT_TYPE_INVALID);
|
||||||
}
|
}
|
||||||
|
if (newValue.isArray() && newValue.length() == 0) {
|
||||||
|
return EmptyResult(options.waitForSync);
|
||||||
|
}
|
||||||
|
|
||||||
OperationOptions optionsCopy = options;
|
OperationOptions optionsCopy = options;
|
||||||
|
|
||||||
|
@ -2078,6 +2093,9 @@ OperationResult Transaction::replace(std::string const& collectionName,
|
||||||
// must provide a document object or an array of documents
|
// must provide a document object or an array of documents
|
||||||
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_DOCUMENT_TYPE_INVALID);
|
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_DOCUMENT_TYPE_INVALID);
|
||||||
}
|
}
|
||||||
|
if (newValue.isArray() && newValue.length() == 0) {
|
||||||
|
return EmptyResult(options.waitForSync);
|
||||||
|
}
|
||||||
|
|
||||||
OperationOptions optionsCopy = options;
|
OperationOptions optionsCopy = options;
|
||||||
|
|
||||||
|
@ -2338,6 +2356,9 @@ OperationResult Transaction::remove(std::string const& collectionName,
|
||||||
// must provide a document object or an array of documents
|
// must provide a document object or an array of documents
|
||||||
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_DOCUMENT_TYPE_INVALID);
|
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_DOCUMENT_TYPE_INVALID);
|
||||||
}
|
}
|
||||||
|
if (value.isArray() && value.length() == 0) {
|
||||||
|
return EmptyResult(options.waitForSync);
|
||||||
|
}
|
||||||
|
|
||||||
OperationOptions optionsCopy = options;
|
OperationOptions optionsCopy = options;
|
||||||
|
|
||||||
|
|
|
@ -882,6 +882,32 @@ function CollectionDocumentSuiteBabies() {
|
||||||
assertEqual(ERRORS.ERROR_ARANGO_DOCUMENT_TYPE_INVALID.code,
|
assertEqual(ERRORS.ERROR_ARANGO_DOCUMENT_TYPE_INVALID.code,
|
||||||
err6.errorNum);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue