From 9889e9f91f7ee62e21aeeb274beadeaf3df6a161 Mon Sep 17 00:00:00 2001 From: jsteemann Date: Thu, 5 Jan 2017 16:53:00 +0100 Subject: [PATCH] remove revision id from storage engine if write locker cannot be acquired --- arangod/VocBase/LogicalCollection.cpp | 57 ++++++++++++++------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/arangod/VocBase/LogicalCollection.cpp b/arangod/VocBase/LogicalCollection.cpp index 0d3d20f60c..8b549533da 100644 --- a/arangod/VocBase/LogicalCollection.cpp +++ b/arangod/VocBase/LogicalCollection.cpp @@ -2064,55 +2064,56 @@ int LogicalCollection::insert(Transaction* trx, VPackSlice const slice, try { insertRevision(revisionId, marker->vpack(), 0, true); + // and go on with the insertion... } catch (basics::Exception const& ex) { - res = ex.code(); + return ex.code(); } catch (std::bad_alloc const&) { - res = TRI_ERROR_OUT_OF_MEMORY; + return TRI_ERROR_OUT_OF_MEMORY; } catch (...) { - res = TRI_ERROR_INTERNAL; - } - if (res != TRI_ERROR_NO_ERROR) { - try { - removeRevision(revisionId, false); - } catch (basics::Exception const& ex) { - res = ex.code(); - } catch (std::bad_alloc const&) { - res = TRI_ERROR_OUT_OF_MEMORY; - } catch (...) { - res = TRI_ERROR_INTERNAL; - } - return res; + return TRI_ERROR_INTERNAL; } { - // use lock + // use lock? bool const useDeadlockDetector = (lock && !trx->isSingleOperationTransaction()); - arangodb::CollectionWriteLocker collectionLocker(this, useDeadlockDetector, - lock); - try { - // insert into indexes - res = insertDocument(trx, revisionId, doc, operation, marker, - options.waitForSync); - } catch (basics::Exception const& ex) { - res = ex.code(); - } catch (std::bad_alloc const&) { - res = TRI_ERROR_OUT_OF_MEMORY; + arangodb::CollectionWriteLocker collectionLocker(this, useDeadlockDetector, + lock); + + try { + // insert into indexes + res = insertDocument(trx, revisionId, doc, operation, marker, + options.waitForSync); + } catch (basics::Exception const& ex) { + res = ex.code(); + } catch (std::bad_alloc const&) { + res = TRI_ERROR_OUT_OF_MEMORY; + } catch (...) { + res = TRI_ERROR_INTERNAL; + } } catch (...) { - res = TRI_ERROR_INTERNAL; + // the collectionLocker may have thrown in its constructor... + // if it did, then we need to manually remove the revision id + // from the list of revisions + try { + removeRevision(revisionId, false); + } catch (...) { + } + throw; } if (res != TRI_ERROR_NO_ERROR) { operation.revert(trx); } } + if (res == TRI_ERROR_NO_ERROR) { readRevision(trx, result, revisionId); // store the tick that was used for writing the document resultMarkerTick = operation.tick(); - } + } return res; }