mirror of https://gitee.com/bigwinds/arangodb
Babies for document and remove, various cleanup.
This commit is contained in:
parent
7c4d4ab36c
commit
be9bf2d90f
|
@ -482,7 +482,7 @@ void Transaction::invokeOnAllElements(std::string const& collectionName,
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
OperationResult Transaction::document(std::string const& collectionName,
|
||||
VPackSlice const& value,
|
||||
VPackSlice const value,
|
||||
OperationOptions& options) {
|
||||
TRI_ASSERT(getStatus() == TRI_TRANSACTION_RUNNING);
|
||||
|
||||
|
@ -491,11 +491,6 @@ OperationResult Transaction::document(std::string const& collectionName,
|
|||
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_DOCUMENT_TYPE_INVALID);
|
||||
}
|
||||
|
||||
if (value.isArray()) {
|
||||
// multi-document variant is not yet implemented
|
||||
THROW_ARANGO_EXCEPTION(TRI_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
if (ServerState::instance()->isCoordinator()) {
|
||||
return documentCoordinator(collectionName, value, options);
|
||||
}
|
||||
|
@ -508,8 +503,13 @@ OperationResult Transaction::document(std::string const& collectionName,
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
OperationResult Transaction::documentCoordinator(std::string const& collectionName,
|
||||
VPackSlice const& value,
|
||||
VPackSlice const value,
|
||||
OperationOptions& options) {
|
||||
if (value.isArray()) {
|
||||
// multi-document variant is not yet implemented
|
||||
THROW_ARANGO_EXCEPTION(TRI_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
auto headers = std::make_unique<std::map<std::string, std::string>>();
|
||||
arangodb::rest::HttpResponse::HttpResponseCode responseCode;
|
||||
std::map<std::string, std::string> resultHeaders;
|
||||
|
@ -557,7 +557,7 @@ OperationResult Transaction::documentCoordinator(std::string const& collectionNa
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
OperationResult Transaction::documentLocal(std::string const& collectionName,
|
||||
VPackSlice const& value,
|
||||
VPackSlice const value,
|
||||
OperationOptions& options) {
|
||||
TRI_voc_cid_t cid = resolver()->getCollectionIdLocal(collectionName);
|
||||
|
||||
|
@ -565,13 +565,6 @@ OperationResult Transaction::documentLocal(std::string const& collectionName,
|
|||
return OperationResult(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND);
|
||||
}
|
||||
|
||||
std::string key(Transaction::extractKey(value));
|
||||
if (key.empty()) {
|
||||
return OperationResult(TRI_ERROR_ARANGO_DOCUMENT_KEY_BAD);
|
||||
}
|
||||
|
||||
TRI_voc_rid_t expectedRevision = Transaction::extractRevisionId(value);
|
||||
|
||||
// TODO: clean this up
|
||||
TRI_document_collection_t* document = documentCollection(trxCollection(cid));
|
||||
|
||||
|
@ -579,32 +572,56 @@ OperationResult Transaction::documentLocal(std::string const& collectionName,
|
|||
return OperationResult(TRI_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
TRI_doc_mptr_t mptr;
|
||||
int res = document->read(this, key, &mptr, !isLocked(document, TRI_TRANSACTION_READ));
|
||||
|
||||
if (res != TRI_ERROR_NO_ERROR) {
|
||||
return OperationResult(res);
|
||||
}
|
||||
|
||||
TRI_ASSERT(mptr.getDataPtr() != nullptr);
|
||||
if (expectedRevision != 0 && expectedRevision != mptr.revisionId()) {
|
||||
// still return
|
||||
VPackBuilder resultBuilder;
|
||||
buildDocumentIdentity(resultBuilder, cid, key, mptr.revisionId(), "");
|
||||
|
||||
return OperationResult(resultBuilder.steal(), nullptr, "",
|
||||
TRI_ERROR_ARANGO_CONFLICT,
|
||||
options.waitForSync || document->_info.waitForSync());
|
||||
}
|
||||
|
||||
VPackBuilder resultBuilder;
|
||||
if (!options.silent) {
|
||||
resultBuilder.add(VPackSlice(mptr.vpack()));
|
||||
|
||||
auto workOnOneDocument = [&](VPackSlice const value) -> int {
|
||||
std::string key(Transaction::extractKey(value));
|
||||
if (key.empty()) {
|
||||
return TRI_ERROR_ARANGO_DOCUMENT_KEY_BAD;
|
||||
}
|
||||
|
||||
TRI_voc_rid_t expectedRevision = 0;
|
||||
if (!options.ignoreRevs) {
|
||||
expectedRevision = Transaction::extractRevisionId(value);
|
||||
}
|
||||
|
||||
TRI_doc_mptr_t mptr;
|
||||
int res = document->read(this, key, &mptr, !isLocked(document, TRI_TRANSACTION_READ));
|
||||
|
||||
if (res != TRI_ERROR_NO_ERROR) {
|
||||
return res;
|
||||
}
|
||||
|
||||
TRI_ASSERT(mptr.getDataPtr() != nullptr);
|
||||
if (expectedRevision != 0 && expectedRevision != mptr.revisionId()) {
|
||||
// still return
|
||||
buildDocumentIdentity(resultBuilder, cid, key, mptr.revisionId(), "");
|
||||
return TRI_ERROR_ARANGO_CONFLICT;
|
||||
}
|
||||
|
||||
if (!options.silent) {
|
||||
resultBuilder.add(VPackSlice(mptr.vpack()));
|
||||
}
|
||||
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
};
|
||||
|
||||
int res = TRI_ERROR_NO_ERROR;
|
||||
if (!value.isArray()) {
|
||||
res = workOnOneDocument(value);
|
||||
} else {
|
||||
VPackArrayBuilder guard(&resultBuilder);
|
||||
for (auto const s : VPackArrayIterator(value)) {
|
||||
res = workOnOneDocument(s);
|
||||
if (res != TRI_ERROR_NO_ERROR) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return OperationResult(resultBuilder.steal(),
|
||||
transactionContext()->orderCustomTypeHandler(), "",
|
||||
TRI_ERROR_NO_ERROR, false);
|
||||
res, options.waitForSync);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -614,7 +631,7 @@ OperationResult Transaction::documentLocal(std::string const& collectionName,
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
OperationResult Transaction::insert(std::string const& collectionName,
|
||||
VPackSlice const& value,
|
||||
VPackSlice const value,
|
||||
OperationOptions const& options) {
|
||||
TRI_ASSERT(getStatus() == TRI_TRANSACTION_RUNNING);
|
||||
|
||||
|
@ -686,7 +703,7 @@ OperationResult Transaction::insert(std::string const& collectionName,
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
OperationResult Transaction::insertCoordinator(std::string const& collectionName,
|
||||
VPackSlice const& value,
|
||||
VPackSlice const value,
|
||||
OperationOptions& options) {
|
||||
|
||||
if (value.isArray()) {
|
||||
|
@ -740,7 +757,7 @@ OperationResult Transaction::insertCoordinator(std::string const& collectionName
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
OperationResult Transaction::insertLocal(std::string const& collectionName,
|
||||
VPackSlice const& value,
|
||||
VPackSlice const value,
|
||||
OperationOptions& options) {
|
||||
|
||||
TRI_voc_cid_t cid = resolver()->getCollectionIdLocal(collectionName);
|
||||
|
@ -794,7 +811,7 @@ OperationResult Transaction::insertLocal(std::string const& collectionName,
|
|||
VPackSlice insertSlice = toInsert.slice();
|
||||
|
||||
TRI_doc_mptr_t mptr;
|
||||
int res = document->insert(this, &insertSlice, &mptr, options,
|
||||
int res = document->insert(this, insertSlice, &mptr, options,
|
||||
!isLocked(document, TRI_TRANSACTION_WRITE));
|
||||
|
||||
if (res != TRI_ERROR_NO_ERROR) {
|
||||
|
@ -1093,7 +1110,7 @@ OperationResult Transaction::modifyLocal(
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
OperationResult Transaction::remove(std::string const& collectionName,
|
||||
VPackSlice const& value,
|
||||
VPackSlice const value,
|
||||
OperationOptions const& options) {
|
||||
TRI_ASSERT(getStatus() == TRI_TRANSACTION_RUNNING);
|
||||
|
||||
|
@ -1102,11 +1119,6 @@ OperationResult Transaction::remove(std::string const& collectionName,
|
|||
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_DOCUMENT_TYPE_INVALID);
|
||||
}
|
||||
|
||||
if (value.isArray()) {
|
||||
// multi-document variant is not yet implemented
|
||||
THROW_ARANGO_EXCEPTION(TRI_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
OperationOptions optionsCopy = options;
|
||||
|
||||
if (ServerState::instance()->isCoordinator()) {
|
||||
|
@ -1123,8 +1135,14 @@ OperationResult Transaction::remove(std::string const& collectionName,
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
OperationResult Transaction::removeCoordinator(std::string const& collectionName,
|
||||
VPackSlice const& value,
|
||||
VPackSlice const value,
|
||||
OperationOptions& options) {
|
||||
|
||||
if (value.isArray()) {
|
||||
// multi-document variant is not yet implemented
|
||||
THROW_ARANGO_EXCEPTION(TRI_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
auto headers = std::make_unique<std::map<std::string, std::string>>();
|
||||
arangodb::rest::HttpResponse::HttpResponseCode responseCode;
|
||||
std::map<std::string, std::string> resultHeaders;
|
||||
|
@ -1176,7 +1194,7 @@ OperationResult Transaction::removeCoordinator(std::string const& collectionName
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
OperationResult Transaction::removeLocal(std::string const& collectionName,
|
||||
VPackSlice const& value,
|
||||
VPackSlice const value,
|
||||
OperationOptions& options) {
|
||||
TRI_voc_cid_t cid = resolver()->getCollectionIdLocal(collectionName);
|
||||
|
||||
|
@ -1187,47 +1205,42 @@ OperationResult Transaction::removeLocal(std::string const& collectionName,
|
|||
// TODO: clean this up
|
||||
TRI_document_collection_t* document = documentCollection(trxCollection(cid));
|
||||
|
||||
std::string key;
|
||||
TRI_voc_rid_t const expectedRevision = Transaction::extractRevisionId(value);
|
||||
|
||||
VPackBuilder builder;
|
||||
builder.openObject();
|
||||
|
||||
// extract _key
|
||||
if (value.isObject()) {
|
||||
VPackSlice k = value.get(TRI_VOC_ATTRIBUTE_KEY);
|
||||
if (!k.isString()) {
|
||||
return OperationResult(TRI_ERROR_ARANGO_DOCUMENT_KEY_BAD);
|
||||
}
|
||||
builder.add(TRI_VOC_ATTRIBUTE_KEY, k);
|
||||
key = k.copyString();
|
||||
} else if (value.isString()) {
|
||||
builder.add(TRI_VOC_ATTRIBUTE_KEY, value);
|
||||
key = value.copyString();
|
||||
}
|
||||
|
||||
// add _rev
|
||||
builder.add(TRI_VOC_ATTRIBUTE_REV, VPackValue(std::to_string(expectedRevision)));
|
||||
builder.close();
|
||||
|
||||
VPackSlice removeSlice = builder.slice();
|
||||
|
||||
TRI_voc_rid_t actualRevision = 0;
|
||||
TRI_doc_update_policy_t updatePolicy(expectedRevision == 0 ? TRI_DOC_UPDATE_LAST_WRITE : TRI_DOC_UPDATE_ERROR, expectedRevision, &actualRevision);
|
||||
int res = document->remove(this, &removeSlice, &updatePolicy, options, !isLocked(document, TRI_TRANSACTION_WRITE));
|
||||
|
||||
if (res != TRI_ERROR_NO_ERROR) {
|
||||
return OperationResult(res);
|
||||
}
|
||||
|
||||
if (options.silent) {
|
||||
return OperationResult(TRI_ERROR_NO_ERROR);
|
||||
}
|
||||
|
||||
VPackBuilder resultBuilder;
|
||||
buildDocumentIdentity(resultBuilder, cid, key, std::to_string(actualRevision), "");
|
||||
|
||||
return OperationResult(resultBuilder.steal(), nullptr, "", TRI_ERROR_NO_ERROR,
|
||||
auto workOnOneDocument = [&](VPackSlice const value) -> int {
|
||||
TRI_voc_rid_t actualRevision = 0;
|
||||
int res = document->remove(this, value, options,
|
||||
!isLocked(document, TRI_TRANSACTION_WRITE),
|
||||
actualRevision);
|
||||
|
||||
if (res != TRI_ERROR_NO_ERROR) {
|
||||
return res;
|
||||
}
|
||||
|
||||
if (options.silent) {
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
std::string key = value.get(TRI_VOC_ATTRIBUTE_KEY).copyString();
|
||||
buildDocumentIdentity(resultBuilder, cid, key,
|
||||
std::to_string(actualRevision), "");
|
||||
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
};
|
||||
|
||||
int res = TRI_ERROR_NO_ERROR;
|
||||
if (value.isArray()) {
|
||||
VPackArrayBuilder guard(&resultBuilder);
|
||||
for (auto const s : VPackArrayIterator(value)) {
|
||||
res = workOnOneDocument(s);
|
||||
if (res != TRI_ERROR_NO_ERROR) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
res = workOnOneDocument(value);
|
||||
}
|
||||
return OperationResult(resultBuilder.steal(), nullptr, "", res,
|
||||
options.waitForSync);
|
||||
}
|
||||
|
||||
|
@ -1473,24 +1486,15 @@ OperationResult Transaction::truncateLocal(std::string const& collectionName,
|
|||
|
||||
TRI_document_collection_t* document = documentCollection(trxCollection(cid));
|
||||
|
||||
TRI_voc_rid_t actualRevision = 0;
|
||||
TRI_doc_update_policy_t updatePolicy(TRI_DOC_UPDATE_LAST_WRITE, 0, &actualRevision);
|
||||
|
||||
VPackBuilder keyBuilder;
|
||||
auto primaryIndex = document->primaryIndex();
|
||||
|
||||
std::function<bool(TRI_doc_mptr_t*)> callback = [this, &document, &keyBuilder, &updatePolicy, &options](TRI_doc_mptr_t const* mptr) {
|
||||
VPackSlice slice(mptr->vpack());
|
||||
VPackSlice keySlice = slice.get(TRI_VOC_ATTRIBUTE_KEY);
|
||||
options.ignoreRevs = true;
|
||||
|
||||
keyBuilder.clear();
|
||||
keyBuilder.openObject();
|
||||
keyBuilder.add(TRI_VOC_ATTRIBUTE_KEY, keySlice);
|
||||
keyBuilder.close();
|
||||
|
||||
VPackSlice builderSlice = keyBuilder.slice();
|
||||
|
||||
int res = document->remove(this, &builderSlice, &updatePolicy, options, false);
|
||||
auto callback = [&](TRI_doc_mptr_t const* mptr) {
|
||||
TRI_voc_rid_t actualRevision = 0;
|
||||
int res = document->remove(this, VPackSlice(mptr->vpack()), options, false,
|
||||
actualRevision);
|
||||
|
||||
if (res != TRI_ERROR_NO_ERROR) {
|
||||
THROW_ARANGO_EXCEPTION(res);
|
||||
|
|
|
@ -281,7 +281,7 @@ class Transaction {
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
OperationResult document(std::string const& collectionName,
|
||||
VPackSlice const& value,
|
||||
VPackSlice const value,
|
||||
OperationOptions& options);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -291,7 +291,7 @@ class Transaction {
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
OperationResult insert(std::string const& collectionName,
|
||||
VPackSlice const& value,
|
||||
VPackSlice const value,
|
||||
OperationOptions const& options);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -321,7 +321,7 @@ class Transaction {
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
OperationResult remove(std::string const& collectionName,
|
||||
VPackSlice const& value,
|
||||
VPackSlice const value,
|
||||
OperationOptions const& options);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -389,19 +389,19 @@ class Transaction {
|
|||
private:
|
||||
|
||||
OperationResult documentCoordinator(std::string const& collectionName,
|
||||
VPackSlice const& value,
|
||||
VPackSlice const value,
|
||||
OperationOptions& options);
|
||||
|
||||
OperationResult documentLocal(std::string const& collectionName,
|
||||
VPackSlice const& value,
|
||||
VPackSlice const value,
|
||||
OperationOptions& options);
|
||||
|
||||
OperationResult insertCoordinator(std::string const& collectionName,
|
||||
VPackSlice const& value,
|
||||
VPackSlice const value,
|
||||
OperationOptions& options);
|
||||
|
||||
OperationResult insertLocal(std::string const& collectionName,
|
||||
VPackSlice const& value,
|
||||
VPackSlice const value,
|
||||
OperationOptions& options);
|
||||
|
||||
OperationResult updateCoordinator(std::string const& collectionName,
|
||||
|
@ -418,11 +418,11 @@ class Transaction {
|
|||
TRI_voc_document_operation_e operation);
|
||||
|
||||
OperationResult removeCoordinator(std::string const& collectionName,
|
||||
VPackSlice const& value,
|
||||
VPackSlice const value,
|
||||
OperationOptions& options);
|
||||
|
||||
OperationResult removeLocal(std::string const& collectionName,
|
||||
VPackSlice const& value,
|
||||
VPackSlice const value,
|
||||
OperationOptions& options);
|
||||
|
||||
OperationResult allKeysCoordinator(std::string const& collectionName,
|
||||
|
|
|
@ -449,8 +449,6 @@ static void DocumentVocbaseVPack(
|
|||
LocalCollectionGuard g(useCollection ? nullptr
|
||||
: const_cast<TRI_vocbase_col_t*>(col));
|
||||
|
||||
|
||||
|
||||
TRI_ASSERT(col != nullptr);
|
||||
|
||||
TRI_ASSERT(!collectionName.empty());
|
||||
|
@ -468,6 +466,7 @@ static void DocumentVocbaseVPack(
|
|||
|
||||
// No options here
|
||||
OperationOptions options;
|
||||
options.ignoreRevs = false;
|
||||
OperationResult opResult = trx.document(collectionName, search, options);
|
||||
|
||||
res = trx.finish(opResult.code);
|
||||
|
@ -497,10 +496,10 @@ static void RemoveVocbaseVPack(
|
|||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::HandleScope scope(isolate);
|
||||
OperationOptions options;
|
||||
options.ignoreRevs = false;
|
||||
|
||||
// check the arguments
|
||||
uint32_t const argLength = args.Length();
|
||||
bool overwrite = false;
|
||||
|
||||
TRI_GET_GLOBALS();
|
||||
|
||||
|
@ -513,7 +512,7 @@ static void RemoveVocbaseVPack(
|
|||
v8::Handle<v8::Object> optionsObject = args[1].As<v8::Object>();
|
||||
TRI_GET_GLOBAL_STRING(OverwriteKey);
|
||||
if (optionsObject->Has(OverwriteKey)) {
|
||||
overwrite = TRI_ObjectToBoolean(optionsObject->Get(OverwriteKey));
|
||||
options.ignoreRevs = TRI_ObjectToBoolean(optionsObject->Get(OverwriteKey));
|
||||
}
|
||||
TRI_GET_GLOBAL_STRING(WaitForSyncKey);
|
||||
if (optionsObject->Has(WaitForSyncKey)) {
|
||||
|
@ -522,7 +521,7 @@ static void RemoveVocbaseVPack(
|
|||
}
|
||||
} else { // old variant replace(<document>, <data>, <overwrite>,
|
||||
// <waitForSync>)
|
||||
overwrite = TRI_ObjectToBoolean(args[1]);
|
||||
options.ignoreRevs = TRI_ObjectToBoolean(args[1]);
|
||||
if (argLength > 2) {
|
||||
options.waitForSync = TRI_ObjectToBoolean(args[2]);
|
||||
}
|
||||
|
@ -563,7 +562,7 @@ static void RemoveVocbaseVPack(
|
|||
{ VPackObjectBuilder guard(&builder);
|
||||
int res = ParseDocumentOrDocumentHandle(
|
||||
isolate, vocbase, transactionContext->getResolver(), col, collectionName, builder,
|
||||
!overwrite, args[0]);
|
||||
!options.ignoreRevs, args[0]);
|
||||
|
||||
if (res != TRI_ERROR_NO_ERROR) {
|
||||
TRI_V8_THROW_EXCEPTION(res);
|
||||
|
@ -587,7 +586,7 @@ static void RemoveVocbaseVPack(
|
|||
res = trx.finish(result.code);
|
||||
|
||||
if (!result.successful()) {
|
||||
if (result.code == TRI_ERROR_ARANGO_DOCUMENT_NOT_FOUND && overwrite) {
|
||||
if (result.code == TRI_ERROR_ARANGO_DOCUMENT_NOT_FOUND && options.ignoreRevs) {
|
||||
TRI_V8_RETURN_FALSE();
|
||||
} else {
|
||||
TRI_V8_THROW_EXCEPTION(result.code);
|
||||
|
|
|
@ -3279,17 +3279,17 @@ int TRI_document_collection_t::read(Transaction* trx, std::string const& key,
|
|||
/// @brief inserts a document or edge into the collection
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int TRI_document_collection_t::insert(Transaction* trx, VPackSlice const* slice,
|
||||
int TRI_document_collection_t::insert(Transaction* trx, VPackSlice const slice,
|
||||
TRI_doc_mptr_t* mptr,
|
||||
OperationOptions& options,
|
||||
bool lock) {
|
||||
|
||||
if (_info.type() == TRI_COL_TYPE_EDGE) {
|
||||
VPackSlice s = slice->get(TRI_VOC_ATTRIBUTE_FROM);
|
||||
VPackSlice s = slice.get(TRI_VOC_ATTRIBUTE_FROM);
|
||||
if (!s.isString()) {
|
||||
return TRI_ERROR_ARANGO_INVALID_EDGE_ATTRIBUTE;
|
||||
}
|
||||
s = slice->get(TRI_VOC_ATTRIBUTE_TO);
|
||||
s = slice.get(TRI_VOC_ATTRIBUTE_TO);
|
||||
if (!s.isString()) {
|
||||
return TRI_ERROR_ARANGO_INVALID_EDGE_ATTRIBUTE;
|
||||
}
|
||||
|
@ -3298,7 +3298,7 @@ int TRI_document_collection_t::insert(Transaction* trx, VPackSlice const* slice,
|
|||
TRI_ASSERT(mptr != nullptr);
|
||||
mptr->setDataPtr(nullptr);
|
||||
|
||||
VPackSlice const key(slice->get(TRI_VOC_ATTRIBUTE_KEY));
|
||||
VPackSlice const key(slice.get(TRI_VOC_ATTRIBUTE_KEY));
|
||||
uint64_t const hash = key.hash();
|
||||
|
||||
std::unique_ptr<arangodb::wal::Marker> marker;
|
||||
|
@ -3594,10 +3594,10 @@ int TRI_document_collection_t::replace(Transaction* trx,
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int TRI_document_collection_t::remove(arangodb::Transaction* trx,
|
||||
VPackSlice const* slice,
|
||||
TRI_doc_update_policy_t const* policy,
|
||||
VPackSlice const slice,
|
||||
OperationOptions& options,
|
||||
bool lock) {
|
||||
bool lock,
|
||||
TRI_voc_rid_t& prevRev) {
|
||||
TRI_IF_FAILURE("RemoveDocumentNoMarker") {
|
||||
// test what happens when no marker can be created
|
||||
return TRI_ERROR_DEBUG;
|
||||
|
@ -3635,30 +3635,43 @@ int TRI_document_collection_t::remove(arangodb::Transaction* trx,
|
|||
TRI_ASSERT(operation.marker != nullptr);
|
||||
TRI_ASSERT(marker == nullptr);
|
||||
|
||||
TRI_doc_mptr_t* header;
|
||||
res = lookupDocument(trx, slice, policy, header);
|
||||
|
||||
// get the header pointer of the previous revision
|
||||
TRI_doc_mptr_t* oldHeader;
|
||||
VPackSlice key = slice.get(TRI_VOC_ATTRIBUTE_KEY);
|
||||
TRI_ASSERT(!key.isNone());
|
||||
res = lookupDocument(trx, key, oldHeader);
|
||||
if (res != TRI_ERROR_NO_ERROR) {
|
||||
return res;
|
||||
}
|
||||
|
||||
prevRev = oldHeader->revisionId();
|
||||
|
||||
// Check old revision:
|
||||
if (!options.ignoreRevs) {
|
||||
VPackSlice expectedRevSlice = slice.get(TRI_VOC_ATTRIBUTE_REV);
|
||||
int res = checkRevision(trx, expectedRevSlice, prevRev);
|
||||
if (res != TRI_ERROR_NO_ERROR) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
// we found a document to remove
|
||||
TRI_ASSERT(header != nullptr);
|
||||
operation.header = header;
|
||||
TRI_ASSERT(oldHeader != nullptr);
|
||||
operation.header = oldHeader;
|
||||
operation.init();
|
||||
|
||||
// delete from indexes
|
||||
res = deleteSecondaryIndexes(trx, header, false);
|
||||
res = deleteSecondaryIndexes(trx, oldHeader, false);
|
||||
|
||||
if (res != TRI_ERROR_NO_ERROR) {
|
||||
insertSecondaryIndexes(trx, header, true);
|
||||
insertSecondaryIndexes(trx, oldHeader, true);
|
||||
return res;
|
||||
}
|
||||
|
||||
res = deletePrimaryIndex(trx, header);
|
||||
res = deletePrimaryIndex(trx, oldHeader);
|
||||
|
||||
if (res != TRI_ERROR_NO_ERROR) {
|
||||
insertSecondaryIndexes(trx, header, true);
|
||||
insertSecondaryIndexes(trx, oldHeader, true);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -3741,13 +3754,8 @@ int TRI_document_collection_t::rollbackOperation(arangodb::Transaction* trx,
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
arangodb::wal::Marker* TRI_document_collection_t::createVPackInsertMarker(
|
||||
Transaction* trx, VPackSlice const* slice) {
|
||||
return new arangodb::wal::CrudMarker(TRI_DF_MARKER_VPACK_DOCUMENT, trx->getInternals()->_id, *slice);
|
||||
}
|
||||
|
||||
arangodb::wal::Marker* TRI_document_collection_t::createVPackInsertMarker(
|
||||
Transaction* trx, VPackSlice const& slice) {
|
||||
return createVPackInsertMarker(trx, &slice);
|
||||
Transaction* trx, VPackSlice const slice) {
|
||||
return new arangodb::wal::CrudMarker(TRI_DF_MARKER_VPACK_DOCUMENT, trx->getInternals()->_id, slice);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -3755,8 +3763,8 @@ arangodb::wal::Marker* TRI_document_collection_t::createVPackInsertMarker(
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
arangodb::wal::Marker* TRI_document_collection_t::createVPackRemoveMarker(
|
||||
Transaction* trx, VPackSlice const* slice) {
|
||||
return new arangodb::wal::CrudMarker(TRI_DF_MARKER_VPACK_REMOVE, trx->getInternals()->_id, *slice);
|
||||
Transaction* trx, VPackSlice const slice) {
|
||||
return new arangodb::wal::CrudMarker(TRI_DF_MARKER_VPACK_REMOVE, trx->getInternals()->_id, slice);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -216,7 +216,7 @@ struct TRI_document_collection_t : public TRI_collection_t {
|
|||
|
||||
int read(arangodb::Transaction*, std::string const&,
|
||||
TRI_doc_mptr_t*, bool);
|
||||
int insert(arangodb::Transaction*, arangodb::velocypack::Slice const*,
|
||||
int insert(arangodb::Transaction*, arangodb::velocypack::Slice const,
|
||||
TRI_doc_mptr_t*, arangodb::OperationOptions&, bool);
|
||||
int update(arangodb::Transaction*, arangodb::velocypack::Slice const,
|
||||
TRI_doc_mptr_t*, arangodb::OperationOptions&, bool,
|
||||
|
@ -224,19 +224,17 @@ struct TRI_document_collection_t : public TRI_collection_t {
|
|||
int replace(arangodb::Transaction*, arangodb::velocypack::Slice const,
|
||||
TRI_doc_mptr_t*, arangodb::OperationOptions&, bool,
|
||||
TRI_voc_rid_t&);
|
||||
int remove(arangodb::Transaction*, arangodb::velocypack::Slice const*,
|
||||
TRI_doc_update_policy_t const*, arangodb::OperationOptions&, bool);
|
||||
int remove(arangodb::Transaction*, arangodb::velocypack::Slice const,
|
||||
arangodb::OperationOptions&, bool, TRI_voc_rid_t&);
|
||||
|
||||
int rollbackOperation(arangodb::Transaction*, TRI_voc_document_operation_e,
|
||||
TRI_doc_mptr_t*, TRI_doc_mptr_t const*);
|
||||
|
||||
private:
|
||||
arangodb::wal::Marker* createVPackInsertMarker(
|
||||
arangodb::Transaction*, arangodb::velocypack::Slice const*);
|
||||
arangodb::wal::Marker* createVPackInsertMarker(
|
||||
arangodb::Transaction*, arangodb::velocypack::Slice const&);
|
||||
arangodb::Transaction*, arangodb::velocypack::Slice const);
|
||||
arangodb::wal::Marker* createVPackRemoveMarker(
|
||||
arangodb::Transaction*, arangodb::velocypack::Slice const*);
|
||||
arangodb::Transaction*, arangodb::velocypack::Slice const);
|
||||
int lookupDocument(arangodb::Transaction*, arangodb::velocypack::Slice const*,
|
||||
TRI_doc_update_policy_t const*, TRI_doc_mptr_t*&);
|
||||
int lookupDocument(arangodb::Transaction*, arangodb::velocypack::Slice const,
|
||||
|
|
Loading…
Reference in New Issue