From 75e4e6e8159c2eb04b0d28fde9d6a38e4953e246 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Tue, 24 Nov 2015 17:34:23 +0100 Subject: [PATCH] added transaction to all signatures --- arangod/Aql/QueryRegistry.cpp | 11 - arangod/Indexes/CapConstraint.cpp | 30 +- arangod/Indexes/CapConstraint.h | 21 +- arangod/Indexes/EdgeIndex.cpp | 25 +- arangod/Indexes/EdgeIndex.h | 7 +- arangod/Indexes/FulltextIndex.cpp | 6 +- arangod/Indexes/FulltextIndex.h | 4 +- arangod/Indexes/GeoIndex2.cpp | 8 +- arangod/Indexes/GeoIndex2.h | 4 +- arangod/Indexes/HashIndex.cpp | 22 +- arangod/Indexes/HashIndex.h | 11 +- arangod/Indexes/Index.cpp | 7 +- arangod/Indexes/Index.h | 8 +- arangod/Indexes/PrimaryIndex.cpp | 6 +- arangod/Indexes/PrimaryIndex.h | 4 +- arangod/Indexes/SkiplistIndex.cpp | 14 +- arangod/Indexes/SkiplistIndex.h | 4 +- arangod/Replication/ContinuousSyncer.cpp | 6 +- arangod/Replication/InitialSyncer.cpp | 121 +++--- arangod/Replication/InitialSyncer.h | 6 +- arangod/Replication/Syncer.cpp | 15 +- arangod/Replication/Syncer.h | 4 +- .../RestHandler/RestReplicationHandler.cpp | 22 +- arangod/RestHandler/RestReplicationHandler.h | 7 +- arangod/Utils/Transaction.cpp | 19 - arangod/Utils/Transaction.h | 44 +- arangod/V8Server/V8Traverser.cpp | 5 - arangod/V8Server/v8-vocindex.cpp | 34 +- arangod/VocBase/compactor.cpp | 4 - arangod/VocBase/document-collection.cpp | 405 +++++++++--------- arangod/VocBase/document-collection.h | 89 ++-- arangod/VocBase/replication-dump.cpp | 11 - arangod/VocBase/voc-types.h | 125 ------ arangod/Wal/CollectorThread.cpp | 3 - arangod/Wal/DocumentOperation.h | 15 +- arangod/Wal/RecoverState.cpp | 38 +- 36 files changed, 493 insertions(+), 672 deletions(-) diff --git a/arangod/Aql/QueryRegistry.cpp b/arangod/Aql/QueryRegistry.cpp index f45919c877..17881139d5 100644 --- a/arangod/Aql/QueryRegistry.cpp +++ b/arangod/Aql/QueryRegistry.cpp @@ -112,9 +112,6 @@ void QueryRegistry::insert (QueryId id, TRI_ASSERT_EXPENSIVE(_queries.find(vocbase->_name)->second.find(id) != _queries.find(vocbase->_name)->second.end()); - // Also, we need to count down the debugging counters for transactions: - triagens::arango::TransactionBase::increaseNumbers(-1, -1); - // If we have set _makeNolockHeaders, we need to unset it: if (Transaction::_makeNolockHeaders != nullptr) { if (Transaction::_makeNolockHeaders == query->engine()->lockedShards()) { @@ -157,9 +154,6 @@ Query* QueryRegistry::open (TRI_vocbase_t* vocbase, } qi->_isOpen = true; - // We need to count up the debugging counters for transactions: - triagens::arango::TransactionBase::increaseNumbers(1, 1); - // If we had set _makeNolockHeaders, we need to reset it: if (qi->_query->engine()->lockedShards() != nullptr) { if (Transaction::_makeNolockHeaders == nullptr) { @@ -198,9 +192,6 @@ void QueryRegistry::close (TRI_vocbase_t* vocbase, QueryId id, double ttl) { "query with given vocbase and id is not open"); } - // We need to count down the debugging counters for transactions: - triagens::arango::TransactionBase::increaseNumbers(-1, -1); - // If we have set _makeNolockHeaders, we need to unset it: if (Transaction::_makeNolockHeaders != nullptr) { if (Transaction::_makeNolockHeaders == qi->_query->engine()->lockedShards()) { @@ -248,8 +239,6 @@ void QueryRegistry::destroy (std::string const& vocbase, // to register the transaction with the current context and adjust // the debugging counters for transactions: if (! qi->_isOpen) { - // We need to count up the debugging counters for transactions: - triagens::arango::TransactionBase::increaseNumbers(1, 1); // If we had set _makeNolockHeaders, we need to reset it: if (qi->_query->engine()->lockedShards() != nullptr) { if (Transaction::_makeNolockHeaders == nullptr) { diff --git a/arangod/Indexes/CapConstraint.cpp b/arangod/Indexes/CapConstraint.cpp index 70c99013a9..a334f653b2 100644 --- a/arangod/Indexes/CapConstraint.cpp +++ b/arangod/Indexes/CapConstraint.cpp @@ -55,8 +55,6 @@ CapConstraint::CapConstraint (TRI_idx_iid_t iid, : Index(iid, collection, std::vector>(), false, false), _count(count), _size(static_cast(size)) { - - initialize(); } CapConstraint::~CapConstraint () { @@ -96,7 +94,8 @@ triagens::basics::Json CapConstraint::toJsonFigures (TRI_memory_zone_t* zone) co return json; } -int CapConstraint::insert (TRI_doc_mptr_t const* doc, +int CapConstraint::insert (triagens::arango::Transaction*, + TRI_doc_mptr_t const* doc, bool) { if (_size > 0) { // there is a size restriction @@ -111,27 +110,25 @@ int CapConstraint::insert (TRI_doc_mptr_t const* doc, return TRI_ERROR_NO_ERROR; } -int CapConstraint::remove (TRI_doc_mptr_t const*, +int CapConstraint::remove (triagens::arango::Transaction*, + TRI_doc_mptr_t const*, bool) { return TRI_ERROR_NO_ERROR; } -int CapConstraint::postInsert (TRI_transaction_collection_t* trxCollection, +int CapConstraint::postInsert (triagens::arango::Transaction* trx, + TRI_transaction_collection_t* trxCollection, TRI_doc_mptr_t const*) { TRI_ASSERT(_count > 0 || _size > 0); - return apply(trxCollection->_collection->_collection, trxCollection); + return apply(trx, trxCollection->_collection->_collection, trxCollection); } -// ----------------------------------------------------------------------------- -// --SECTION-- private methods -// ----------------------------------------------------------------------------- - //////////////////////////////////////////////////////////////////////////////// /// @brief initialize the cap constraint //////////////////////////////////////////////////////////////////////////////// -int CapConstraint::initialize () { +int CapConstraint::initialize (triagens::arango::Transaction* trx) { TRI_ASSERT(_count > 0 || _size > 0); TRI_headers_t* headers = _collection->_headersPtr; // ONLY IN INDEX (CAP) @@ -160,7 +157,7 @@ int CapConstraint::initialize () { } TRI_transaction_collection_t* trxCollection = trx.trxCollection(); - res = apply(_collection, trxCollection); + res = apply(&trx, _collection, trxCollection); res = trx.finish(res); @@ -168,11 +165,16 @@ int CapConstraint::initialize () { } } +// ----------------------------------------------------------------------------- +// --SECTION-- private methods +// ----------------------------------------------------------------------------- + //////////////////////////////////////////////////////////////////////////////// /// @brief apply the cap constraint for the collection //////////////////////////////////////////////////////////////////////////////// -int CapConstraint::apply (TRI_document_collection_t* document, +int CapConstraint::apply (triagens::arango::Transaction* trx, + TRI_document_collection_t* document, TRI_transaction_collection_t* trxCollection) { TRI_headers_t* headers = document->_headersPtr; // PROTECTED by trx in trxCollection int64_t currentCount = static_cast(headers->count()); @@ -192,7 +194,7 @@ int CapConstraint::apply (TRI_document_collection_t* document, TRI_ASSERT(oldSize > 0); if (trxCollection != nullptr) { - res = TRI_DeleteDocumentDocumentCollection(trxCollection, nullptr, oldest); + res = TRI_DeleteDocumentDocumentCollection(trx, trxCollection, nullptr, oldest); if (res != TRI_ERROR_NO_ERROR) { LOG_WARNING("cannot cap collection: %s", TRI_errno_string(res)); diff --git a/arangod/Indexes/CapConstraint.h b/arangod/Indexes/CapConstraint.h index 90a53460f2..62b9c3e86b 100644 --- a/arangod/Indexes/CapConstraint.h +++ b/arangod/Indexes/CapConstraint.h @@ -102,11 +102,17 @@ namespace triagens { triagens::basics::Json toJson (TRI_memory_zone_t*, bool) const override final; triagens::basics::Json toJsonFigures (TRI_memory_zone_t*) const override final; - int insert (struct TRI_doc_mptr_t const*, bool) override final; + int insert (triagens::arango::Transaction*, struct TRI_doc_mptr_t const*, bool) override final; - int remove (struct TRI_doc_mptr_t const*, bool) override final; + int remove (triagens::arango::Transaction*, struct TRI_doc_mptr_t const*, bool) override final; - int postInsert (struct TRI_transaction_collection_s*, struct TRI_doc_mptr_t const*) override final; + int postInsert (triagens::arango::Transaction*, struct TRI_transaction_collection_s*, struct TRI_doc_mptr_t const*) override final; + +//////////////////////////////////////////////////////////////////////////////// +/// @brief initialize the cap constraint +//////////////////////////////////////////////////////////////////////////////// + + int initialize (triagens::arango::Transaction*); // ----------------------------------------------------------------------------- // --SECTION-- private methods @@ -114,17 +120,12 @@ namespace triagens { private: -//////////////////////////////////////////////////////////////////////////////// -/// @brief initialize the cap constraint -//////////////////////////////////////////////////////////////////////////////// - - int initialize (); - //////////////////////////////////////////////////////////////////////////////// /// @brief apply the cap constraint for the collection //////////////////////////////////////////////////////////////////////////////// - int apply (TRI_document_collection_t*, + int apply (triagens::arango::Transaction*, + TRI_document_collection_t*, struct TRI_transaction_collection_s*); // ----------------------------------------------------------------------------- diff --git a/arangod/Indexes/EdgeIndex.cpp b/arangod/Indexes/EdgeIndex.cpp index f30ef34933..ef0e92e688 100644 --- a/arangod/Indexes/EdgeIndex.cpp +++ b/arangod/Indexes/EdgeIndex.cpp @@ -76,7 +76,7 @@ static uint64_t HashElementEdgeFrom (void const* data, } else { TRI_doc_mptr_t const* mptr = static_cast(data); - TRI_df_marker_t const* marker = static_cast(mptr->getDataPtrUnchecked()); // ONLY IN INDEX, PROTECTED by RUNTIME + TRI_df_marker_t const* marker = static_cast(mptr->getDataPtr()); // ONLY IN INDEX, PROTECTED by RUNTIME if (marker->_type == TRI_DOC_MARKER_KEY_EDGE) { TRI_doc_edge_key_marker_t const* edge = reinterpret_cast(marker); // ONLY IN INDEX, PROTECTED by RUNTIME @@ -116,7 +116,7 @@ static uint64_t HashElementEdgeTo (void const* data, } else { TRI_doc_mptr_t const* mptr = static_cast(data); - TRI_df_marker_t const* marker = static_cast(mptr->getDataPtrUnchecked()); // ONLY IN INDEX, PROTECTED by RUNTIME + TRI_df_marker_t const* marker = static_cast(mptr->getDataPtr()); // ONLY IN INDEX, PROTECTED by RUNTIME if (marker->_type == TRI_DOC_MARKER_KEY_EDGE) { TRI_doc_edge_key_marker_t const* edge = reinterpret_cast(marker); // ONLY IN INDEX, PROTECTED by RUNTIME @@ -156,7 +156,7 @@ static bool IsEqualKeyEdgeFrom (void const* left, char const* lKey = l->_key; TRI_doc_mptr_t const* rMptr = static_cast(right); - TRI_df_marker_t const* marker = static_cast(rMptr->getDataPtrUnchecked()); // ONLY IN INDEX, PROTECTED by RUNTIME + TRI_df_marker_t const* marker = static_cast(rMptr->getDataPtr()); // ONLY IN INDEX, PROTECTED by RUNTIME if (marker->_type == TRI_DOC_MARKER_KEY_EDGE) { TRI_doc_edge_key_marker_t const* rEdge = reinterpret_cast(marker); // ONLY IN INDEX, PROTECTED by RUNTIME @@ -192,7 +192,7 @@ static bool IsEqualKeyEdgeTo (void const* left, char const* lKey = l->_key; TRI_doc_mptr_t const* rMptr = static_cast(right); - TRI_df_marker_t const* marker = static_cast(rMptr->getDataPtrUnchecked()); // ONLY IN INDEX, PROTECTED by RUNTIME + TRI_df_marker_t const* marker = static_cast(rMptr->getDataPtr()); // ONLY IN INDEX, PROTECTED by RUNTIME if (marker->_type == TRI_DOC_MARKER_KEY_EDGE) { TRI_doc_edge_key_marker_t const* rEdge = reinterpret_cast(marker); // ONLY IN INDEX, PROTECTED by RUNTIME @@ -240,7 +240,7 @@ static bool IsEqualElementEdgeFromByKey (void const* left, // left element TRI_doc_mptr_t const* lMptr = static_cast(left); - marker = static_cast(lMptr->getDataPtrUnchecked()); // ONLY IN INDEX, PROTECTED by RUNTIME + marker = static_cast(lMptr->getDataPtr()); // ONLY IN INDEX, PROTECTED by RUNTIME if (marker->_type == TRI_DOC_MARKER_KEY_EDGE) { TRI_doc_edge_key_marker_t const* lEdge = reinterpret_cast(marker); // ONLY IN INDEX, PROTECTED by RUNTIME @@ -255,7 +255,7 @@ static bool IsEqualElementEdgeFromByKey (void const* left, // right element TRI_doc_mptr_t const* rMptr = static_cast(right); - marker = static_cast(rMptr->getDataPtrUnchecked()); // ONLY IN INDEX, PROTECTED by RUNTIME + marker = static_cast(rMptr->getDataPtr()); // ONLY IN INDEX, PROTECTED by RUNTIME if (marker->_type == TRI_DOC_MARKER_KEY_EDGE) { TRI_doc_edge_key_marker_t const* rEdge = reinterpret_cast(marker); // ONLY IN INDEX, PROTECTED by RUNTIME @@ -294,7 +294,7 @@ static bool IsEqualElementEdgeToByKey (void const* left, // left element TRI_doc_mptr_t const* lMptr = static_cast(left); - marker = static_cast(lMptr->getDataPtrUnchecked()); // ONLY IN INDEX, PROTECTED by RUNTIME + marker = static_cast(lMptr->getDataPtr()); // ONLY IN INDEX, PROTECTED by RUNTIME if (marker->_type == TRI_DOC_MARKER_KEY_EDGE) { TRI_doc_edge_key_marker_t const* lEdge = reinterpret_cast(marker); // ONLY IN INDEX, PROTECTED by RUNTIME @@ -309,7 +309,7 @@ static bool IsEqualElementEdgeToByKey (void const* left, // right element TRI_doc_mptr_t const* rMptr = static_cast(right); - marker = static_cast(rMptr->getDataPtrUnchecked()); // ONLY IN INDEX, PROTECTED by RUNTIME + marker = static_cast(rMptr->getDataPtr()); // ONLY IN INDEX, PROTECTED by RUNTIME if (marker->_type == TRI_DOC_MARKER_KEY_EDGE) { TRI_doc_edge_key_marker_t const* rEdge = reinterpret_cast(marker); // ONLY IN INDEX, PROTECTED by RUNTIME @@ -506,7 +506,8 @@ triagens::basics::Json EdgeIndex::toJsonFigures (TRI_memory_zone_t* zone) const return json; } -int EdgeIndex::insert (TRI_doc_mptr_t const* doc, +int EdgeIndex::insert (triagens::arango::Transaction*, + TRI_doc_mptr_t const* doc, bool isRollback) { auto element = const_cast(doc); _edgesFrom->insert(element, true, isRollback); @@ -522,7 +523,8 @@ int EdgeIndex::insert (TRI_doc_mptr_t const* doc, return TRI_ERROR_NO_ERROR; } -int EdgeIndex::remove (TRI_doc_mptr_t const* doc, +int EdgeIndex::remove (triagens::arango::Transaction*, + TRI_doc_mptr_t const* doc, bool) { _edgesFrom->remove(doc); _edgesTo->remove(doc); @@ -530,7 +532,8 @@ int EdgeIndex::remove (TRI_doc_mptr_t const* doc, return TRI_ERROR_NO_ERROR; } -int EdgeIndex::batchInsert (std::vector const* documents, +int EdgeIndex::batchInsert (triagens::arango::Transaction*, + std::vector const* documents, size_t numThreads) { _edgesFrom->batchInsert(reinterpret_cast const*>(documents), numThreads); _edgesTo->batchInsert(reinterpret_cast const*>(documents), numThreads); diff --git a/arangod/Indexes/EdgeIndex.h b/arangod/Indexes/EdgeIndex.h index bd2f6dabff..e6da155793 100644 --- a/arangod/Indexes/EdgeIndex.h +++ b/arangod/Indexes/EdgeIndex.h @@ -147,11 +147,12 @@ namespace triagens { triagens::basics::Json toJson (TRI_memory_zone_t*, bool) const override final; triagens::basics::Json toJsonFigures (TRI_memory_zone_t*) const override final; - int insert (struct TRI_doc_mptr_t const*, bool) override final; + int insert (triagens::arango::Transaction*, struct TRI_doc_mptr_t const*, bool) override final; - int remove (struct TRI_doc_mptr_t const*, bool) override final; + int remove (triagens::arango::Transaction*, struct TRI_doc_mptr_t const*, bool) override final; - int batchInsert (std::vector const*, + int batchInsert (triagens::arango::Transaction*, + std::vector const*, size_t) override final; //////////////////////////////////////////////////////////////////////////////// diff --git a/arangod/Indexes/FulltextIndex.cpp b/arangod/Indexes/FulltextIndex.cpp index d1ac451481..b09303b005 100644 --- a/arangod/Indexes/FulltextIndex.cpp +++ b/arangod/Indexes/FulltextIndex.cpp @@ -186,7 +186,8 @@ triagens::basics::Json FulltextIndex::toJsonFigures (TRI_memory_zone_t* zone) co return json; } -int FulltextIndex::insert (TRI_doc_mptr_t const* doc, +int FulltextIndex::insert (triagens::arango::Transaction*, + TRI_doc_mptr_t const* doc, bool isRollback) { int res = TRI_ERROR_NO_ERROR; @@ -212,7 +213,8 @@ int FulltextIndex::insert (TRI_doc_mptr_t const* doc, return res; } -int FulltextIndex::remove (TRI_doc_mptr_t const* doc, +int FulltextIndex::remove (triagens::arango::Transaction*, + TRI_doc_mptr_t const* doc, bool) { TRI_DeleteDocumentFulltextIndex(_fulltextIndex, (TRI_fulltext_doc_t) ((uintptr_t) doc)); diff --git a/arangod/Indexes/FulltextIndex.h b/arangod/Indexes/FulltextIndex.h index de1c70ceee..e20b576600 100644 --- a/arangod/Indexes/FulltextIndex.h +++ b/arangod/Indexes/FulltextIndex.h @@ -90,9 +90,9 @@ namespace triagens { triagens::basics::Json toJson (TRI_memory_zone_t*, bool) const override final; triagens::basics::Json toJsonFigures (TRI_memory_zone_t*) const override final; - int insert (struct TRI_doc_mptr_t const*, bool) override final; + int insert (triagens::arango::Transaction*, struct TRI_doc_mptr_t const*, bool) override final; - int remove (struct TRI_doc_mptr_t const*, bool) override final; + int remove (triagens::arango::Transaction*, struct TRI_doc_mptr_t const*, bool) override final; int cleanup () override final; diff --git a/arangod/Indexes/GeoIndex2.cpp b/arangod/Indexes/GeoIndex2.cpp index 80977e0a50..3d3f17e57c 100644 --- a/arangod/Indexes/GeoIndex2.cpp +++ b/arangod/Indexes/GeoIndex2.cpp @@ -181,7 +181,8 @@ triagens::basics::Json GeoIndex2::toJsonFigures (TRI_memory_zone_t* zone) const return json; } -int GeoIndex2::insert (TRI_doc_mptr_t const* doc, +int GeoIndex2::insert (triagens::arango::Transaction*, + TRI_doc_mptr_t const* doc, bool) { auto shaper = _collection->getShaper(); // ONLY IN INDEX, PROTECTED by RUNTIME @@ -236,8 +237,9 @@ int GeoIndex2::insert (TRI_doc_mptr_t const* doc, return TRI_ERROR_NO_ERROR; } -int GeoIndex2::remove (TRI_doc_mptr_t const* doc, - bool) { +int GeoIndex2::remove (triagens::arango::Transaction*, + TRI_doc_mptr_t const* doc, + bool) { TRI_shaped_json_t shapedJson; auto shaper = _collection->getShaper(); // ONLY IN INDEX, PROTECTED by RUNTIME diff --git a/arangod/Indexes/GeoIndex2.h b/arangod/Indexes/GeoIndex2.h index 06fadc74db..a1f92cbb7b 100644 --- a/arangod/Indexes/GeoIndex2.h +++ b/arangod/Indexes/GeoIndex2.h @@ -118,9 +118,9 @@ namespace triagens { triagens::basics::Json toJson (TRI_memory_zone_t*, bool) const override final; triagens::basics::Json toJsonFigures (TRI_memory_zone_t*) const override final; - int insert (struct TRI_doc_mptr_t const*, bool) override final; + int insert (triagens::arango::Transaction*, struct TRI_doc_mptr_t const*, bool) override final; - int remove (struct TRI_doc_mptr_t const*, bool) override final; + int remove (triagens::arango::Transaction*, struct TRI_doc_mptr_t const*, bool) override final; //////////////////////////////////////////////////////////////////////////////// /// @brief looks up all points within a given radius diff --git a/arangod/Indexes/HashIndex.cpp b/arangod/Indexes/HashIndex.cpp index cff8bb099f..32244c7f4b 100644 --- a/arangod/Indexes/HashIndex.cpp +++ b/arangod/Indexes/HashIndex.cpp @@ -417,11 +417,13 @@ triagens::basics::Json HashIndex::toJsonFigures (TRI_memory_zone_t* zone) const return json; } -int HashIndex::insert (TRI_doc_mptr_t const* doc, +int HashIndex::insert (triagens::arango::Transaction*, + TRI_doc_mptr_t const* doc, bool isRollback) { if (_unique) { return insertUnique(doc, isRollback); } + return insertMulti(doc, isRollback); } @@ -429,22 +431,26 @@ int HashIndex::insert (TRI_doc_mptr_t const* doc, /// @brief removes an entry from the hash array part of the hash index //////////////////////////////////////////////////////////////////////////////// -int HashIndex::remove (TRI_doc_mptr_t const* doc, +int HashIndex::remove (triagens::arango::Transaction*, + TRI_doc_mptr_t const* doc, bool isRollback) { if (_unique) { return removeUnique(doc, isRollback); } + return removeMulti(doc, isRollback); } -int HashIndex::batchInsert (std::vector const* documents, +int HashIndex::batchInsert (triagens::arango::Transaction* trx, + std::vector const* documents, size_t numThreads) { if (_unique) { - return batchInsertUnique(documents, numThreads); + return batchInsertUnique(trx, documents, numThreads); } - return batchInsertMulti(documents, numThreads); + + return batchInsertMulti(trx, documents, numThreads); } //////////////////////////////////////////////////////////////////////////////// @@ -612,7 +618,8 @@ int HashIndex::insertUnique (TRI_doc_mptr_t const* doc, return res; } -int HashIndex::batchInsertUnique (std::vector const* documents, +int HashIndex::batchInsertUnique (triagens::arango::Transaction*, + std::vector const* documents, size_t numThreads) { std::vector elements; elements.reserve(documents->size()); @@ -704,7 +711,8 @@ int HashIndex::insertMulti (TRI_doc_mptr_t const* doc, return TRI_ERROR_NO_ERROR; } -int HashIndex::batchInsertMulti (std::vector const* documents, +int HashIndex::batchInsertMulti (triagens::arango::Transaction*, + std::vector const* documents, size_t numThreads) { std::vector elements; diff --git a/arangod/Indexes/HashIndex.h b/arangod/Indexes/HashIndex.h index a9a7933724..8022e8a693 100644 --- a/arangod/Indexes/HashIndex.h +++ b/arangod/Indexes/HashIndex.h @@ -149,11 +149,12 @@ namespace triagens { triagens::basics::Json toJson (TRI_memory_zone_t*, bool) const override final; triagens::basics::Json toJsonFigures (TRI_memory_zone_t*) const override final; - int insert (struct TRI_doc_mptr_t const*, bool) override final; + int insert (triagens::arango::Transaction*, struct TRI_doc_mptr_t const*, bool) override final; - int remove (struct TRI_doc_mptr_t const*, bool) override final; + int remove (triagens::arango::Transaction*, struct TRI_doc_mptr_t const*, bool) override final; - int batchInsert (std::vector const*, + int batchInsert (triagens::arango::Transaction*, + std::vector const*, size_t) override final; int sizeHint (size_t) override final; @@ -205,11 +206,11 @@ namespace triagens { int insertUnique (struct TRI_doc_mptr_t const*, bool); - int batchInsertUnique (std::vector const*, size_t); + int batchInsertUnique (triagens::arango::Transaction*, std::vector const*, size_t); int insertMulti (struct TRI_doc_mptr_t const*, bool); - int batchInsertMulti (std::vector const*, size_t); + int batchInsertMulti (triagens::arango::Transaction*, std::vector const*, size_t); int removeUniqueElement (TRI_index_element_t*, bool); diff --git a/arangod/Indexes/Index.cpp b/arangod/Indexes/Index.cpp index 03b9c79e6d..eb8b41d964 100644 --- a/arangod/Indexes/Index.cpp +++ b/arangod/Indexes/Index.cpp @@ -451,7 +451,9 @@ double Index::selectivityEstimate () const { /// @brief default implementation for selectivityEstimate //////////////////////////////////////////////////////////////////////////////// -int Index::batchInsert (std::vector const*, size_t) { +int Index::batchInsert (triagens::arango::Transaction*, + std::vector const*, + size_t) { THROW_ARANGO_EXCEPTION(TRI_ERROR_NOT_IMPLEMENTED); } @@ -459,7 +461,8 @@ int Index::batchInsert (std::vector const*, size_t) { /// @brief default implementation for postInsert //////////////////////////////////////////////////////////////////////////////// -int Index::postInsert (struct TRI_transaction_collection_s*, +int Index::postInsert (triagens::arango::Transaction*, + struct TRI_transaction_collection_s*, struct TRI_doc_mptr_t const*) { // do nothing return TRI_ERROR_NO_ERROR; diff --git a/arangod/Indexes/Index.h b/arangod/Indexes/Index.h index ec2fe2e0aa..f6ba62ae3d 100644 --- a/arangod/Indexes/Index.h +++ b/arangod/Indexes/Index.h @@ -339,10 +339,10 @@ namespace triagens { virtual triagens::basics::Json toJsonFigures (TRI_memory_zone_t*) const; virtual bool dumpFields () const = 0; - virtual int insert (struct TRI_doc_mptr_t const*, bool) = 0; - virtual int remove (struct TRI_doc_mptr_t const*, bool) = 0; - virtual int postInsert (struct TRI_transaction_collection_s*, struct TRI_doc_mptr_t const*); - virtual int batchInsert (std::vector const*, size_t); + virtual int insert (triagens::arango::Transaction*, struct TRI_doc_mptr_t const*, bool) = 0; + virtual int remove (triagens::arango::Transaction*, struct TRI_doc_mptr_t const*, bool) = 0; + virtual int postInsert (triagens::arango::Transaction*, struct TRI_transaction_collection_s*, struct TRI_doc_mptr_t const*); + virtual int batchInsert (triagens::arango::Transaction*, std::vector const*, size_t); // a garbage collection function for the index virtual int cleanup (); diff --git a/arangod/Indexes/PrimaryIndex.cpp b/arangod/Indexes/PrimaryIndex.cpp index 1b64cf109d..8937e59d12 100644 --- a/arangod/Indexes/PrimaryIndex.cpp +++ b/arangod/Indexes/PrimaryIndex.cpp @@ -195,12 +195,14 @@ triagens::basics::Json PrimaryIndex::toJsonFigures (TRI_memory_zone_t* zone) con return json; } -int PrimaryIndex::insert (TRI_doc_mptr_t const*, +int PrimaryIndex::insert (triagens::arango::Transaction*, + TRI_doc_mptr_t const*, bool) { THROW_ARANGO_EXCEPTION(TRI_ERROR_NOT_IMPLEMENTED); } -int PrimaryIndex::remove (TRI_doc_mptr_t const*, +int PrimaryIndex::remove (triagens::arango::Transaction*, + TRI_doc_mptr_t const*, bool) { THROW_ARANGO_EXCEPTION(TRI_ERROR_NOT_IMPLEMENTED); } diff --git a/arangod/Indexes/PrimaryIndex.h b/arangod/Indexes/PrimaryIndex.h index 75d633178b..5351df6bec 100644 --- a/arangod/Indexes/PrimaryIndex.h +++ b/arangod/Indexes/PrimaryIndex.h @@ -137,9 +137,9 @@ namespace triagens { triagens::basics::Json toJson (TRI_memory_zone_t*, bool) const override final; triagens::basics::Json toJsonFigures (TRI_memory_zone_t*) const override final; - int insert (TRI_doc_mptr_t const*, bool) override final; + int insert (triagens::arango::Transaction*, TRI_doc_mptr_t const*, bool) override final; - int remove (TRI_doc_mptr_t const*, bool) override final; + int remove (triagens::arango::Transaction*, TRI_doc_mptr_t const*, bool) override final; TRI_doc_mptr_t* lookupKey (char const*) const; diff --git a/arangod/Indexes/SkiplistIndex.cpp b/arangod/Indexes/SkiplistIndex.cpp index 3d2629d570..d054007e16 100644 --- a/arangod/Indexes/SkiplistIndex.cpp +++ b/arangod/Indexes/SkiplistIndex.cpp @@ -834,7 +834,7 @@ size_t SkiplistIndex::memory () const { //////////////////////////////////////////////////////////////////////////////// triagens::basics::Json SkiplistIndex::toJson (TRI_memory_zone_t* zone, - bool withFigures) const { + bool withFigures) const { auto json = Index::toJson(zone, withFigures); json("unique", triagens::basics::Json(zone, _unique)) @@ -859,8 +859,9 @@ triagens::basics::Json SkiplistIndex::toJsonFigures (TRI_memory_zone_t* zone) co /// @brief inserts a document into a skiplist index //////////////////////////////////////////////////////////////////////////////// -int SkiplistIndex::insert (TRI_doc_mptr_t const* doc, - bool) { +int SkiplistIndex::insert (triagens::arango::Transaction*, + TRI_doc_mptr_t const* doc, + bool) { std::vector elements; @@ -909,8 +910,9 @@ int SkiplistIndex::insert (TRI_doc_mptr_t const* doc, /// @brief removes a document from a skiplist index //////////////////////////////////////////////////////////////////////////////// -int SkiplistIndex::remove (TRI_doc_mptr_t const* doc, - bool) { +int SkiplistIndex::remove (triagens::arango::Transaction*, + TRI_doc_mptr_t const* doc, + bool) { std::vector elements; @@ -990,8 +992,6 @@ int SkiplistIndex::KeyElementComparator::operator() (TRI_skiplist_index_key_t co return 0; } - - //////////////////////////////////////////////////////////////////////////////// /// @brief compares two elements in a skip list, this is the generic callback //////////////////////////////////////////////////////////////////////////////// diff --git a/arangod/Indexes/SkiplistIndex.h b/arangod/Indexes/SkiplistIndex.h index 292a656c2a..dbcd06df33 100644 --- a/arangod/Indexes/SkiplistIndex.h +++ b/arangod/Indexes/SkiplistIndex.h @@ -290,9 +290,9 @@ namespace triagens { triagens::basics::Json toJson (TRI_memory_zone_t*, bool) const override final; triagens::basics::Json toJsonFigures (TRI_memory_zone_t*) const override final; - int insert (struct TRI_doc_mptr_t const*, bool) override final; + int insert (triagens::arango::Transaction*, struct TRI_doc_mptr_t const*, bool) override final; - int remove (struct TRI_doc_mptr_t const*, bool) override final; + int remove (triagens::arango::Transaction*, struct TRI_doc_mptr_t const*, bool) override final; //////////////////////////////////////////////////////////////////////////////// /// @brief attempts to locate an entry in the skip list index diff --git a/arangod/Replication/ContinuousSyncer.cpp b/arangod/Replication/ContinuousSyncer.cpp index 612197b117..0368f5b93e 100644 --- a/arangod/Replication/ContinuousSyncer.cpp +++ b/arangod/Replication/ContinuousSyncer.cpp @@ -457,7 +457,8 @@ int ContinuousSyncer::processDocument (TRI_replication_operation_e type, return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND; } - int res = applyCollectionDumpMarker(trxCollection, + int res = applyCollectionDumpMarker(trx, + trxCollection, type, (const TRI_voc_key_t) keyJson->_value._string.data, rid, @@ -491,7 +492,8 @@ int ContinuousSyncer::processDocument (TRI_replication_operation_e type, return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND; } - res = applyCollectionDumpMarker(trxCollection, + res = applyCollectionDumpMarker(&trx, + trxCollection, type, (const TRI_voc_key_t) keyJson->_value._string.data, rid, diff --git a/arangod/Replication/InitialSyncer.cpp b/arangod/Replication/InitialSyncer.cpp index 2d636aff92..cc3e619e7f 100644 --- a/arangod/Replication/InitialSyncer.cpp +++ b/arangod/Replication/InitialSyncer.cpp @@ -469,7 +469,8 @@ int InitialSyncer::sendFinishBatch () { /// @brief apply the data from a collection dump //////////////////////////////////////////////////////////////////////////////// -int InitialSyncer::applyCollectionDump (TRI_transaction_collection_t* trxCollection, +int InitialSyncer::applyCollectionDump (triagens::arango::Transaction* trx, + TRI_transaction_collection_t* trxCollection, SimpleHttpResult* response, uint64_t& markersProcessed, string& errorMsg) { @@ -562,7 +563,7 @@ int InitialSyncer::applyCollectionDump (TRI_transaction_collection_t* trxCollect } ++markersProcessed; - int res = applyCollectionDumpMarker(trxCollection, type, (const TRI_voc_key_t) key, rid, doc, errorMsg); + int res = applyCollectionDumpMarker(trx, trxCollection, type, (const TRI_voc_key_t) key, rid, doc, errorMsg); if (res != TRI_ERROR_NO_ERROR) { return res; @@ -577,7 +578,8 @@ int InitialSyncer::applyCollectionDump (TRI_transaction_collection_t* trxCollect /// @brief incrementally fetch data from a collection //////////////////////////////////////////////////////////////////////////////// -int InitialSyncer::handleCollectionDump (string const& cid, +int InitialSyncer::handleCollectionDump (triagens::arango::Transaction* trx, + string const& cid, TRI_transaction_collection_t* trxCollection, string const& collectionName, TRI_voc_tick_t maxTick, @@ -686,7 +688,7 @@ int InitialSyncer::handleCollectionDump (string const& cid, } if (res == TRI_ERROR_NO_ERROR) { - res = applyCollectionDump(trxCollection, response.get(), markersProcessed, errorMsg); + res = applyCollectionDump(trx, trxCollection, response.get(), markersProcessed, errorMsg); } if (res != TRI_ERROR_NO_ERROR) { @@ -943,7 +945,7 @@ int InitialSyncer::handleSyncKeys (std::string const& keysId, break; } - TRI_RemoveShapedJsonDocumentCollection(trx.trxCollection(), (TRI_voc_key_t) key, 0, nullptr, &policy, false, false); + TRI_RemoveShapedJsonDocumentCollection(&trx, trx.trxCollection(), (TRI_voc_key_t) key, 0, nullptr, &policy, false, false); } // last high @@ -960,7 +962,7 @@ int InitialSyncer::handleSyncKeys (std::string const& keysId, break; } - TRI_RemoveShapedJsonDocumentCollection(trx.trxCollection(), (TRI_voc_key_t) key, 0, nullptr, &policy, false, false); + TRI_RemoveShapedJsonDocumentCollection(&trx, trx.trxCollection(), (TRI_voc_key_t) key, 0, nullptr, &policy, false, false); } } @@ -1074,7 +1076,7 @@ int InitialSyncer::handleSyncKeys (std::string const& keysId, if (res < 0) { // we have a local key that is not present remotely - TRI_RemoveShapedJsonDocumentCollection(trx.trxCollection(), (TRI_voc_key_t) localKey, 0, nullptr, &policy, false, false); + TRI_RemoveShapedJsonDocumentCollection(&trx, trx.trxCollection(), (TRI_voc_key_t) localKey, 0, nullptr, &policy, false, false); ++nextStart; } else { @@ -1119,7 +1121,7 @@ int InitialSyncer::handleSyncKeys (std::string const& keysId, if (res < 0) { // we have a local key that is not present remotely - TRI_RemoveShapedJsonDocumentCollection(trx.trxCollection(), (TRI_voc_key_t) localKey, 0, nullptr, &policy, false, false); + TRI_RemoveShapedJsonDocumentCollection(&trx, trx.trxCollection(), (TRI_voc_key_t) localKey, 0, nullptr, &policy, false, false); ++nextStart; } else if (res >= 0) { @@ -1289,15 +1291,15 @@ int InitialSyncer::handleSyncKeys (std::string const& keysId, if (res == TRI_ERROR_NO_ERROR) { if (mptr != nullptr && isEdge) { // must remove existing edge first - TRI_RemoveShapedJsonDocumentCollection(trx.trxCollection(), (TRI_voc_key_t) documentKey.c_str(), 0, nullptr, &policy, false, false); + TRI_RemoveShapedJsonDocumentCollection(&trx, trx.trxCollection(), (TRI_voc_key_t) documentKey.c_str(), 0, nullptr, &policy, false, false); } - res = TRI_InsertShapedJsonDocumentCollection(trx.trxCollection(), (TRI_voc_key_t) documentKey.c_str(), rid, nullptr, &result, shaped, e, false, false, true); + res = TRI_InsertShapedJsonDocumentCollection(&trx, trx.trxCollection(), (TRI_voc_key_t) documentKey.c_str(), rid, nullptr, &result, shaped, e, false, false, true); } } else { // UPDATE - res = TRI_UpdateShapedJsonDocumentCollection(trx.trxCollection(), (TRI_voc_key_t) documentKey.c_str(), rid, nullptr, &result, shaped, &policy, false, false); + res = TRI_UpdateShapedJsonDocumentCollection(&trx, trx.trxCollection(), (TRI_voc_key_t) documentKey.c_str(), rid, nullptr, &result, shaped, &policy, false, false); } TRI_FreeShapedJson(shaper->memoryZone(), shaped); @@ -1543,73 +1545,72 @@ int InitialSyncer::handleCollection (TRI_json_t const* parameters, res = handleCollectionSync(StringUtils::itoa(cid), trx, masterName, _masterInfo._lastLogTick, errorMsg); } else { - res = handleCollectionDump(StringUtils::itoa(cid), trxCollection, masterName, _masterInfo._lastLogTick, errorMsg); + res = handleCollectionDump(&trx, StringUtils::itoa(cid), trxCollection, masterName, _masterInfo._lastLogTick, errorMsg); } } - res = trx.finish(res); - } + if (res == TRI_ERROR_NO_ERROR) { + // now create indexes + size_t const n = TRI_LengthVector(&indexes->_value._objects); - if (res == TRI_ERROR_NO_ERROR) { - // now create indexes - size_t const n = TRI_LengthVector(&indexes->_value._objects); + if (n > 0) { + string const progress = "creating indexes for " + collectionMsg; + setProgress(progress); - if (n > 0) { - string const progress = "creating indexes for " + collectionMsg; - setProgress(progress); + READ_LOCKER(_vocbase->_inventoryLock); - READ_LOCKER(_vocbase->_inventoryLock); + try { + triagens::arango::CollectionGuard guard(_vocbase, col->_cid, false); + TRI_vocbase_col_t* col = guard.collection(); - try { - triagens::arango::CollectionGuard guard(_vocbase, col->_cid, false); - TRI_vocbase_col_t* col = guard.collection(); + if (col == nullptr) { + res = TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND; + } + else { + TRI_document_collection_t* document = col->_collection; + TRI_ASSERT(document != nullptr); - if (col == nullptr) { - res = TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND; - } - else { - TRI_document_collection_t* document = col->_collection; - TRI_ASSERT(document != nullptr); + TRI_WRITE_LOCK_DOCUMENTS_INDEXES_PRIMARY_COLLECTION(document); - // create a fake transaction object to avoid assertions - TransactionBase trx(true); - TRI_WRITE_LOCK_DOCUMENTS_INDEXES_PRIMARY_COLLECTION(document); - - for (size_t i = 0; i < n; ++i) { - TRI_json_t const* idxDef = static_cast(TRI_AtVector(&indexes->_value._objects, i)); - triagens::arango::Index* idx = nullptr; - - // {"id":"229907440927234","type":"hash","unique":false,"fields":["x","Y"]} - - res = TRI_FromJsonIndexDocumentCollection(document, idxDef, &idx); - - if (res != TRI_ERROR_NO_ERROR) { - errorMsg = "could not create index: " + string(TRI_errno_string(res)); - break; - } - else { - TRI_ASSERT(idx != nullptr); - - res = TRI_SaveIndex(document, idx, true); + for (size_t i = 0; i < n; ++i) { + TRI_json_t const* idxDef = static_cast(TRI_AtVector(&indexes->_value._objects, i)); + triagens::arango::Index* idx = nullptr; + + // {"id":"229907440927234","type":"hash","unique":false,"fields":["x","Y"]} + + res = TRI_FromJsonIndexDocumentCollection(&trx, document, idxDef, &idx); if (res != TRI_ERROR_NO_ERROR) { - errorMsg = "could not save index: " + string(TRI_errno_string(res)); + errorMsg = "could not create index: " + string(TRI_errno_string(res)); break; } + else { + TRI_ASSERT(idx != nullptr); + + res = TRI_SaveIndex(document, idx, true); + + if (res != TRI_ERROR_NO_ERROR) { + errorMsg = "could not save index: " + string(TRI_errno_string(res)); + break; + } + } } + + TRI_WRITE_UNLOCK_DOCUMENTS_INDEXES_PRIMARY_COLLECTION(document); } - - TRI_WRITE_UNLOCK_DOCUMENTS_INDEXES_PRIMARY_COLLECTION(document); } - } - catch (triagens::basics::Exception const& ex) { - res = ex.code(); - } - catch (...) { - res = TRI_ERROR_INTERNAL; - } + catch (triagens::basics::Exception const& ex) { + res = ex.code(); + } + catch (...) { + res = TRI_ERROR_INTERNAL; + } + } } + + res = trx.finish(res); + } return res; diff --git a/arangod/Replication/InitialSyncer.h b/arangod/Replication/InitialSyncer.h index 10826df757..be886c9fe9 100644 --- a/arangod/Replication/InitialSyncer.h +++ b/arangod/Replication/InitialSyncer.h @@ -195,7 +195,8 @@ namespace triagens { /// @brief apply the data from a collection dump //////////////////////////////////////////////////////////////////////////////// - int applyCollectionDump (struct TRI_transaction_collection_s*, + int applyCollectionDump (triagens::arango::Transaction*, + struct TRI_transaction_collection_s*, httpclient::SimpleHttpResult*, uint64_t&, std::string&); @@ -205,7 +206,8 @@ namespace triagens { /// @brief incrementally fetch data from a collection //////////////////////////////////////////////////////////////////////////////// - int handleCollectionDump (std::string const&, + int handleCollectionDump (triagens::arango::Transaction*, + std::string const&, struct TRI_transaction_collection_s*, std::string const&, TRI_voc_tick_t, diff --git a/arangod/Replication/Syncer.cpp b/arangod/Replication/Syncer.cpp index 8933bb2851..a1a8a0ed61 100644 --- a/arangod/Replication/Syncer.cpp +++ b/arangod/Replication/Syncer.cpp @@ -203,7 +203,8 @@ TRI_voc_cid_t Syncer::getCid (TRI_json_t const* json) const { /// @brief apply the data from a collection dump or the continuous log //////////////////////////////////////////////////////////////////////////////// -int Syncer::applyCollectionDumpMarker (TRI_transaction_collection_t* trxCollection, +int Syncer::applyCollectionDumpMarker (triagens::arango::Transaction* trx, + TRI_transaction_collection_t* trxCollection, TRI_replication_operation_e type, const TRI_voc_key_t key, const TRI_voc_rid_t rid, @@ -230,7 +231,7 @@ int Syncer::applyCollectionDumpMarker (TRI_transaction_collection_t* trxCollecti TRI_doc_mptr_copy_t mptr; bool const isLocked = TRI_IsLockedCollectionTransaction(trxCollection); - int res = TRI_ReadShapedJsonDocumentCollection(trxCollection, key, &mptr, ! isLocked); + int res = TRI_ReadShapedJsonDocumentCollection(trx, trxCollection, key, &mptr, ! isLocked); if (res == TRI_ERROR_ARANGO_DOCUMENT_NOT_FOUND) { // insert @@ -261,7 +262,7 @@ int Syncer::applyCollectionDumpMarker (TRI_transaction_collection_t* trxCollecti } if (res == TRI_ERROR_NO_ERROR) { - res = TRI_InsertShapedJsonDocumentCollection(trxCollection, key, rid, nullptr, &mptr, shaped, &edge, ! isLocked, false, true); + res = TRI_InsertShapedJsonDocumentCollection(trx, trxCollection, key, rid, nullptr, &mptr, shaped, &edge, ! isLocked, false, true); } } else { @@ -270,13 +271,13 @@ int Syncer::applyCollectionDumpMarker (TRI_transaction_collection_t* trxCollecti res = TRI_ERROR_ARANGO_COLLECTION_TYPE_INVALID; } else { - res = TRI_InsertShapedJsonDocumentCollection(trxCollection, key, rid, nullptr, &mptr, shaped, nullptr, ! isLocked, false, true); + res = TRI_InsertShapedJsonDocumentCollection(trx, trxCollection, key, rid, nullptr, &mptr, shaped, nullptr, ! isLocked, false, true); } } } else { // update - res = TRI_UpdateShapedJsonDocumentCollection(trxCollection, key, rid, nullptr, &mptr, shaped, &_policy, ! isLocked, false); + res = TRI_UpdateShapedJsonDocumentCollection(trx, trxCollection, key, rid, nullptr, &mptr, shaped, &_policy, ! isLocked, false); } TRI_FreeShapedJson(zone, shaped); @@ -300,7 +301,7 @@ int Syncer::applyCollectionDumpMarker (TRI_transaction_collection_t* trxCollecti bool const isLocked = TRI_IsLockedCollectionTransaction(trxCollection); try { - res = TRI_RemoveShapedJsonDocumentCollection(trxCollection, key, rid, nullptr, &_policy, ! isLocked, false); + res = TRI_RemoveShapedJsonDocumentCollection(trx, trxCollection, key, rid, nullptr, &_policy, ! isLocked, false); if (res != TRI_ERROR_NO_ERROR && res == TRI_ERROR_ARANGO_DOCUMENT_NOT_FOUND) { // ignore this error @@ -486,7 +487,7 @@ int Syncer::createIndex (TRI_json_t const* json) { } triagens::arango::Index* idx = nullptr; - res = TRI_FromJsonIndexDocumentCollection(document, indexJson, &idx); + res = TRI_FromJsonIndexDocumentCollection(&trx, document, indexJson, &idx); if (res == TRI_ERROR_NO_ERROR) { res = TRI_SaveIndex(document, idx, true); diff --git a/arangod/Replication/Syncer.h b/arangod/Replication/Syncer.h index 5e6789ea9e..7bf5336b2c 100644 --- a/arangod/Replication/Syncer.h +++ b/arangod/Replication/Syncer.h @@ -61,6 +61,7 @@ namespace triagens { } namespace arango { + class Transaction; // ----------------------------------------------------------------------------- // --SECTION-- Syncer @@ -113,7 +114,8 @@ namespace triagens { /// @brief apply a single marker from the collection dump //////////////////////////////////////////////////////////////////////////////// - int applyCollectionDumpMarker (struct TRI_transaction_collection_s*, + int applyCollectionDumpMarker (triagens::arango::Transaction*, + struct TRI_transaction_collection_s*, TRI_replication_operation_e, const TRI_voc_key_t, const TRI_voc_rid_t, diff --git a/arangod/RestHandler/RestReplicationHandler.cpp b/arangod/RestHandler/RestReplicationHandler.cpp index 0a2fb03e76..213e6bff56 100644 --- a/arangod/RestHandler/RestReplicationHandler.cpp +++ b/arangod/RestHandler/RestReplicationHandler.cpp @@ -2326,7 +2326,7 @@ int RestReplicationHandler::processRestoreIndexes (TRI_json_t const* collection, // {"id":"229907440927234","type":"hash","unique":false,"fields":["x","Y"]} - res = TRI_FromJsonIndexDocumentCollection(document, idxDef, &idx); + res = TRI_FromJsonIndexDocumentCollection(&trx, document, idxDef, &idx); if (res != TRI_ERROR_NO_ERROR) { errorMsg = "could not create index: " + string(TRI_errno_string(res)); @@ -2438,7 +2438,8 @@ int RestReplicationHandler::processRestoreIndexesCoordinator ( /// @brief apply the data from a collection dump or the continuous log //////////////////////////////////////////////////////////////////////////////// -int RestReplicationHandler::applyCollectionDumpMarker (CollectionNameResolver const& resolver, +int RestReplicationHandler::applyCollectionDumpMarker (triagens::arango::Transaction* trx, + CollectionNameResolver const& resolver, TRI_transaction_collection_t* trxCollection, TRI_replication_operation_e type, const TRI_voc_key_t key, @@ -2465,7 +2466,7 @@ int RestReplicationHandler::applyCollectionDumpMarker (CollectionNameResolver co try { TRI_doc_mptr_copy_t mptr; - int res = TRI_ReadShapedJsonDocumentCollection(trxCollection, key, &mptr, false); + int res = TRI_ReadShapedJsonDocumentCollection(trx, trxCollection, key, &mptr, false); if (res == TRI_ERROR_ARANGO_DOCUMENT_NOT_FOUND) { // insert @@ -2494,7 +2495,7 @@ int RestReplicationHandler::applyCollectionDumpMarker (CollectionNameResolver co } if (res == TRI_ERROR_NO_ERROR) { - res = TRI_InsertShapedJsonDocumentCollection(trxCollection, key, rid, nullptr, &mptr, shaped, &edge, false, false, true); + res = TRI_InsertShapedJsonDocumentCollection(trx, trxCollection, key, rid, nullptr, &mptr, shaped, &edge, false, false, true); } } } @@ -2504,7 +2505,7 @@ int RestReplicationHandler::applyCollectionDumpMarker (CollectionNameResolver co res = TRI_ERROR_ARANGO_COLLECTION_TYPE_INVALID; } else { - res = TRI_InsertShapedJsonDocumentCollection(trxCollection, key, rid, nullptr, &mptr, shaped, nullptr, false, false, true); + res = TRI_InsertShapedJsonDocumentCollection(trx, trxCollection, key, rid, nullptr, &mptr, shaped, nullptr, false, false, true); } } } @@ -2513,7 +2514,7 @@ int RestReplicationHandler::applyCollectionDumpMarker (CollectionNameResolver co // init the update policy TRI_doc_update_policy_t policy(TRI_DOC_UPDATE_LAST_WRITE, 0, nullptr); - res = TRI_UpdateShapedJsonDocumentCollection(trxCollection, key, rid, nullptr, &mptr, shaped, &policy, false, false); + res = TRI_UpdateShapedJsonDocumentCollection(trx, trxCollection, key, rid, nullptr, &mptr, shaped, &policy, false, false); } TRI_FreeShapedJson(zone, shaped); @@ -2538,7 +2539,7 @@ int RestReplicationHandler::applyCollectionDumpMarker (CollectionNameResolver co int res = TRI_ERROR_INTERNAL; try { - res = TRI_RemoveShapedJsonDocumentCollection(trxCollection, key, rid, nullptr, &policy, false, false); + res = TRI_RemoveShapedJsonDocumentCollection(trx, trxCollection, key, rid, nullptr, &policy, false, false); if (res != TRI_ERROR_NO_ERROR && res == TRI_ERROR_ARANGO_DOCUMENT_NOT_FOUND) { // ignore this error @@ -2570,7 +2571,8 @@ int RestReplicationHandler::applyCollectionDumpMarker (CollectionNameResolver co /// @brief restores the data of a collection TODO MOVE //////////////////////////////////////////////////////////////////////////////// -int RestReplicationHandler::processRestoreDataBatch (CollectionNameResolver const& resolver, +int RestReplicationHandler::processRestoreDataBatch (triagens::arango::Transaction* trx, + CollectionNameResolver const& resolver, TRI_transaction_collection_t* trxCollection, bool useRevision, bool force, @@ -2658,7 +2660,7 @@ int RestReplicationHandler::processRestoreDataBatch (CollectionNameResolver cons return TRI_ERROR_HTTP_BAD_PARAMETER; } - int res = applyCollectionDumpMarker(resolver, trxCollection, type, (const TRI_voc_key_t) key, rid, doc, errorMsg); + int res = applyCollectionDumpMarker(trx, resolver, trxCollection, type, (const TRI_voc_key_t) key, rid, doc, errorMsg); TRI_FreeJson(TRI_CORE_MEM_ZONE, json); @@ -2705,7 +2707,7 @@ int RestReplicationHandler::processRestoreData (CollectionNameResolver const& re trxCollection->_waitForSync = false; // create a fake transaction to avoid assertion failures. TODO: use proper transaction here - res = processRestoreDataBatch(resolver, trxCollection, useRevision, force, errorMsg); + res = processRestoreDataBatch(&trx, resolver, trxCollection, useRevision, force, errorMsg); } res = trx.finish(res); diff --git a/arangod/RestHandler/RestReplicationHandler.h b/arangod/RestHandler/RestReplicationHandler.h index da683844d5..d28585fc06 100644 --- a/arangod/RestHandler/RestReplicationHandler.h +++ b/arangod/RestHandler/RestReplicationHandler.h @@ -49,6 +49,7 @@ struct TRI_vocbase_col_s; namespace triagens { namespace arango { + class Transaction; //////////////////////////////////////////////////////////////////////////////// /// @brief replication request handler @@ -258,7 +259,8 @@ namespace triagens { /// @brief apply a single marker from the collection dump //////////////////////////////////////////////////////////////////////////////// - int applyCollectionDumpMarker (CollectionNameResolver const&, + int applyCollectionDumpMarker (triagens::arango::Transaction*, + CollectionNameResolver const&, struct TRI_transaction_collection_s*, TRI_replication_operation_e, const TRI_voc_key_t, @@ -270,7 +272,8 @@ namespace triagens { /// @brief restores the data of a collection TODO MOVE //////////////////////////////////////////////////////////////////////////////// - int processRestoreDataBatch (CollectionNameResolver const&, + int processRestoreDataBatch (triagens::arango::Transaction*, + CollectionNameResolver const&, struct TRI_transaction_collection_s*, bool, bool, diff --git a/arangod/Utils/Transaction.cpp b/arangod/Utils/Transaction.cpp index 7b74c2a80f..5f9dcc741b 100644 --- a/arangod/Utils/Transaction.cpp +++ b/arangod/Utils/Transaction.cpp @@ -32,25 +32,6 @@ using namespace triagens::arango; -//////////////////////////////////////////////////////////////////////////////// -/// @brief the following is for the runtime protection check, number of -/// transaction objects in scope in the current thread -//////////////////////////////////////////////////////////////////////////////// - -#ifdef TRI_ENABLE_MAINTAINER_MODE -thread_local int TransactionBase::_numberTrxInScope = 0; -#endif - -//////////////////////////////////////////////////////////////////////////////// -/// @brief the following is for the runtime protection check, number of -/// transaction objects in the current thread that are active (between -/// begin and commit()/abort(). -//////////////////////////////////////////////////////////////////////////////// - -#ifdef TRI_ENABLE_MAINTAINER_MODE -thread_local int TransactionBase::_numberTrxActive = 0; -#endif - //////////////////////////////////////////////////////////////////////////////// /// @brief if this pointer is set to an actual set, then for each request /// sent to a shardId using the ClusterComm library, an X-Arango-Nolock diff --git a/arangod/Utils/Transaction.h b/arangod/Utils/Transaction.h index 8763b3bd83..1bb440b621 100644 --- a/arangod/Utils/Transaction.h +++ b/arangod/Utils/Transaction.h @@ -63,7 +63,7 @@ namespace triagens { // --SECTION-- class Transaction // ----------------------------------------------------------------------------- - class Transaction : public TransactionBase { + class Transaction { //////////////////////////////////////////////////////////////////////////////// /// @brief Transaction @@ -299,11 +299,6 @@ namespace triagens { return _setupState; } -#ifdef TRI_ENABLE_MAINTAINER_MODE - TRI_ASSERT(_numberTrxActive == _numberTrxInScope - 1); - _numberTrxActive++; // Every transaction gets here at most once -#endif - if (! _isReal) { if (_nestingLevel == 0) { _trx->_status = TRI_TRANSACTION_RUNNING; @@ -331,22 +326,11 @@ namespace triagens { if (_nestingLevel == 0) { _trx->_status = TRI_TRANSACTION_COMMITTED; } -#ifdef TRI_ENABLE_MAINTAINER_MODE - TRI_ASSERT(_numberTrxActive == _numberTrxInScope); - TRI_ASSERT(_numberTrxActive > 0); - _numberTrxActive--; // Every transaction gets here at most once -#endif return TRI_ERROR_NO_ERROR; } int res = TRI_CommitTransaction(_trx, _nestingLevel); -#ifdef TRI_ENABLE_MAINTAINER_MODE - TRI_ASSERT(_numberTrxActive == _numberTrxInScope); - TRI_ASSERT(_numberTrxActive > 0); - _numberTrxActive--; // Every transaction gets here at most once -#endif - return res; } @@ -365,22 +349,11 @@ namespace triagens { _trx->_status = TRI_TRANSACTION_ABORTED; } -#ifdef TRI_ENABLE_MAINTAINER_MODE - TRI_ASSERT(_numberTrxActive == _numberTrxInScope); - TRI_ASSERT(_numberTrxActive > 0); - _numberTrxActive--; // Every transaction gets here at most once -#endif return TRI_ERROR_NO_ERROR; } int res = TRI_AbortTransaction(_trx, _nestingLevel); -#ifdef TRI_ENABLE_MAINTAINER_MODE - TRI_ASSERT(_numberTrxActive == _numberTrxInScope); - TRI_ASSERT(_numberTrxActive > 0); - _numberTrxActive--; // Every transaction gets here at most once -#endif - return res; } @@ -485,7 +458,8 @@ namespace triagens { TRI_doc_update_policy_t updatePolicy(policy, expectedRevision, actualRevision); try { - return TRI_RemoveShapedJsonDocumentCollection(trxCollection, + return TRI_RemoveShapedJsonDocumentCollection(this, + trxCollection, (TRI_voc_key_t) key.c_str(), rid, nullptr, @@ -594,7 +568,8 @@ namespace triagens { } try { - return TRI_ReadShapedJsonDocumentCollection(trxCollection, + return TRI_ReadShapedJsonDocumentCollection(this, + trxCollection, (TRI_voc_key_t) key.c_str(), mptr, ! isLocked(trxCollection, TRI_TRANSACTION_READ)); @@ -893,7 +868,8 @@ namespace triagens { bool lock = ! isLocked(trxCollection, TRI_TRANSACTION_WRITE); try { - return TRI_InsertShapedJsonDocumentCollection(trxCollection, + return TRI_InsertShapedJsonDocumentCollection(this, + trxCollection, key, rid, nullptr, @@ -933,7 +909,8 @@ namespace triagens { } try { - return TRI_UpdateShapedJsonDocumentCollection(trxCollection, + return TRI_UpdateShapedJsonDocumentCollection(this, + trxCollection, (const TRI_voc_key_t) key.c_str(), rid, nullptr, @@ -975,7 +952,8 @@ namespace triagens { try { for (auto const& it : ids) { - res = TRI_RemoveShapedJsonDocumentCollection(trxCollection, + res = TRI_RemoveShapedJsonDocumentCollection(this, + trxCollection, (TRI_voc_key_t) it.c_str(), 0, nullptr, // marker diff --git a/arangod/V8Server/V8Traverser.cpp b/arangod/V8Server/V8Traverser.cpp index 2a490fd278..4db2650164 100644 --- a/arangod/V8Server/V8Traverser.cpp +++ b/arangod/V8Server/V8Traverser.cpp @@ -113,9 +113,6 @@ class MultiCollectionEdgeExpander { void operator() (VertexId& source, vector& result) { - TransactionBase fake(true); // Fake a transaction to please checks. - // This is due to multi-threading - equal_to eq; for (auto const& edgeCollection : _edgeCollections) { auto edges = edgeCollection->getEdges(_direction, source); @@ -182,8 +179,6 @@ class SimpleEdgeExpander { void operator() (VertexId& source, vector& result) { - TransactionBase fake(true); // Fake a transaction to please checks. - // This is due to multi-threading auto edges = _edgeCollection->getEdges(_direction, source); equal_to eq; diff --git a/arangod/V8Server/v8-vocindex.cpp b/arangod/V8Server/v8-vocindex.cpp index 7dadf7374d..f4b8868934 100644 --- a/arangod/V8Server/v8-vocindex.cpp +++ b/arangod/V8Server/v8-vocindex.cpp @@ -662,7 +662,8 @@ static void EnsureIndexLocal (const v8::FunctionCallbackInfo& args, } if (create) { - idx = static_cast(TRI_EnsureGeoIndex1DocumentCollection(document, + idx = static_cast(TRI_EnsureGeoIndex1DocumentCollection(&trx, + document, iid, attributes[0], geoJson, @@ -682,7 +683,8 @@ static void EnsureIndexLocal (const v8::FunctionCallbackInfo& args, } if (create) { - idx = static_cast(TRI_EnsureGeoIndex2DocumentCollection(document, + idx = static_cast(TRI_EnsureGeoIndex2DocumentCollection(&trx, + document, iid, attributes[0], attributes[1], @@ -702,7 +704,8 @@ static void EnsureIndexLocal (const v8::FunctionCallbackInfo& args, } if (create) { - idx = static_cast(TRI_EnsureHashIndexDocumentCollection(document, + idx = static_cast(TRI_EnsureHashIndexDocumentCollection(&trx, + document, iid, attributes, sparse, @@ -725,18 +728,19 @@ static void EnsureIndexLocal (const v8::FunctionCallbackInfo& args, } if (create) { - idx = static_cast(TRI_EnsureSkiplistIndexDocumentCollection(document, - iid, - attributes, - sparse, - unique, - &created)); + idx = static_cast(TRI_EnsureSkiplistIndexDocumentCollection(&trx, + document, + iid, + attributes, + sparse, + unique, + &created)); } else { idx = static_cast(TRI_LookupSkiplistIndexDocumentCollection(document, - attributes, - sparsity, - unique)); + attributes, + sparsity, + unique)); } break; } @@ -757,7 +761,8 @@ static void EnsureIndexLocal (const v8::FunctionCallbackInfo& args, } if (create) { - idx = static_cast(TRI_EnsureFulltextIndexDocumentCollection(document, + idx = static_cast(TRI_EnsureFulltextIndexDocumentCollection(&trx, + document, iid, attributes[0], minWordLength, @@ -785,7 +790,8 @@ static void EnsureIndexLocal (const v8::FunctionCallbackInfo& args, } if (create) { - idx = static_cast(TRI_EnsureCapConstraintDocumentCollection(document, + idx = static_cast(TRI_EnsureCapConstraintDocumentCollection(&trx, + document, iid, size, byteSize, diff --git a/arangod/VocBase/compactor.cpp b/arangod/VocBase/compactor.cpp index 45c3be07c1..efdf7e034b 100644 --- a/arangod/VocBase/compactor.cpp +++ b/arangod/VocBase/compactor.cpp @@ -769,10 +769,6 @@ static void CompactifyDatafiles (TRI_document_collection_t* document, size_t const n = TRI_LengthVector(compactions); TRI_ASSERT(n > 0); - // create a fake transaction - triagens::arango::TransactionBase trx(true); - - initial = InitCompaction(document, compactions); if (initial._failed) { diff --git a/arangod/VocBase/document-collection.cpp b/arangod/VocBase/document-collection.cpp index 7bef45fe0a..bda45b631f 100644 --- a/arangod/VocBase/document-collection.cpp +++ b/arangod/VocBase/document-collection.cpp @@ -65,51 +65,6 @@ using namespace triagens::arango; -//////////////////////////////////////////////////////////////////////////////// -/// @brief return a pointer to the beginning of the marker -//////////////////////////////////////////////////////////////////////////////// - -#ifdef TRI_ENABLE_MAINTAINER_MODE -void const* TRI_doc_mptr_t::getDataPtr () const { - TransactionBase::assertCurrentTrxActive(); - return _dataptr; -} -#endif - -//////////////////////////////////////////////////////////////////////////////// -/// @brief set the pointer to the beginning of the memory for the marker -//////////////////////////////////////////////////////////////////////////////// - -#ifdef TRI_ENABLE_MAINTAINER_MODE -void TRI_doc_mptr_t::setDataPtr (void const* d) { - TransactionBase::assertCurrentTrxActive(); - _dataptr = d; -} -#endif - -//////////////////////////////////////////////////////////////////////////////// -/// @brief return a pointer to the beginning of the marker, copy object -//////////////////////////////////////////////////////////////////////////////// - -#ifdef TRI_ENABLE_MAINTAINER_MODE -void const* TRI_doc_mptr_copy_t::getDataPtr () const { - TransactionBase::assertSomeTrxInScope(); - return _dataptr; -} -#endif - -//////////////////////////////////////////////////////////////////////////////// -/// @brief set the pointer to the beginning of the memory for the marker, -/// copy object -//////////////////////////////////////////////////////////////////////////////// - -#ifdef TRI_ENABLE_MAINTAINER_MODE -void TRI_doc_mptr_copy_t::setDataPtr (void const* d) { - TransactionBase::assertSomeTrxInScope(); - _dataptr = d; -} -#endif - //////////////////////////////////////////////////////////////////////////////// /// @brief create a document collection //////////////////////////////////////////////////////////////////////////////// @@ -598,7 +553,6 @@ triagens::arango::Index* TRI_document_collection_t::lookupIndex (TRI_idx_iid_t i #ifdef TRI_ENABLE_MAINTAINER_MODE VocShaper* TRI_document_collection_t::getShaper () const { if (! _ditches.contains(triagens::arango::Ditch::TRI_DITCH_DOCUMENT)) { - TransactionBase::assertSomeTrxInScope(); } return _shaper; } @@ -614,30 +568,36 @@ int TRI_AddOperationTransaction (TRI_transaction_t*, triagens::wal::DocumentOper // --SECTION-- forward declarations // ----------------------------------------------------------------------------- -static int FillIndex (TRI_document_collection_t*, +static int FillIndex (triagens::arango::Transaction*, + TRI_document_collection_t*, triagens::arango::Index*); -static int CapConstraintFromJson (TRI_document_collection_t*, +static int CapConstraintFromJson (triagens::arango::Transaction*, + TRI_document_collection_t*, TRI_json_t const*, TRI_idx_iid_t, triagens::arango::Index**); -static int GeoIndexFromJson (TRI_document_collection_t*, +static int GeoIndexFromJson (triagens::arango::Transaction*, + TRI_document_collection_t*, TRI_json_t const*, TRI_idx_iid_t, triagens::arango::Index**); -static int HashIndexFromJson (TRI_document_collection_t*, +static int HashIndexFromJson (triagens::arango::Transaction*, + TRI_document_collection_t*, TRI_json_t const*, TRI_idx_iid_t, triagens::arango::Index**); -static int SkiplistIndexFromJson (TRI_document_collection_t*, +static int SkiplistIndexFromJson (triagens::arango::Transaction*, + TRI_document_collection_t*, TRI_json_t const*, TRI_idx_iid_t, triagens::arango::Index**); -static int FulltextIndexFromJson (TRI_document_collection_t*, +static int FulltextIndexFromJson (triagens::arango::Transaction*, + TRI_document_collection_t*, TRI_json_t const*, TRI_idx_iid_t, triagens::arango::Index**); @@ -721,7 +681,8 @@ static void EnsureErrorCode (int code) { /// @brief creates a new entry in the primary index //////////////////////////////////////////////////////////////////////////////// -static int InsertPrimaryIndex (TRI_document_collection_t* document, +static int InsertPrimaryIndex (triagens::arango::Transaction* trx, + TRI_document_collection_t* document, TRI_doc_mptr_t* header, bool isRollback) { TRI_IF_FAILURE("InsertPrimaryIndex") { @@ -761,7 +722,8 @@ static int InsertPrimaryIndex (TRI_document_collection_t* document, /// @brief creates a new entry in the secondary indexes //////////////////////////////////////////////////////////////////////////////// -static int InsertSecondaryIndexes (TRI_document_collection_t* document, +static int InsertSecondaryIndexes (triagens::arango::Transaction* trx, + TRI_document_collection_t* document, TRI_doc_mptr_t const* header, bool isRollback) { TRI_IF_FAILURE("InsertSecondaryIndexes") { @@ -779,7 +741,7 @@ static int InsertSecondaryIndexes (TRI_document_collection_t* document, for (size_t i = 1; i < n; ++i) { auto idx = indexes[i]; - int res = idx->insert(header, isRollback); + int res = idx->insert(trx, header, isRollback); // in case of no-memory, return immediately if (res == TRI_ERROR_OUT_OF_MEMORY) { @@ -801,7 +763,8 @@ static int InsertSecondaryIndexes (TRI_document_collection_t* document, /// @brief deletes an entry from the primary index //////////////////////////////////////////////////////////////////////////////// -static int DeletePrimaryIndex (TRI_document_collection_t* document, +static int DeletePrimaryIndex (triagens::arango::Transaction* trx, + TRI_document_collection_t* document, TRI_doc_mptr_t const* header, bool isRollback) { TRI_IF_FAILURE("DeletePrimaryIndex") { @@ -822,7 +785,8 @@ static int DeletePrimaryIndex (TRI_document_collection_t* document, /// @brief deletes an entry from the secondary indexes //////////////////////////////////////////////////////////////////////////////// -static int DeleteSecondaryIndexes (TRI_document_collection_t* document, +static int DeleteSecondaryIndexes (triagens::arango::Transaction* trx, + TRI_document_collection_t* document, TRI_doc_mptr_t const* header, bool isRollback) { if (! document->useSecondaryIndexes()) { @@ -840,7 +804,7 @@ static int DeleteSecondaryIndexes (TRI_document_collection_t* document, for (size_t i = 1; i < n; ++i) { auto idx = indexes[i]; - int res = idx->remove(header, isRollback); + int res = idx->remove(trx, header, isRollback); if (res != TRI_ERROR_NO_ERROR) { // an error occurred @@ -998,7 +962,8 @@ static int CleanupIndexes (TRI_document_collection_t* document) { /// @brief post-insert operation //////////////////////////////////////////////////////////////////////////////// -static int PostInsertIndexes (TRI_transaction_collection_t* trxCollection, +static int PostInsertIndexes (triagens::arango::Transaction* trx, + TRI_transaction_collection_t* trxCollection, TRI_doc_mptr_t* header) { TRI_document_collection_t* document = trxCollection->_collection->_collection; @@ -1011,7 +976,7 @@ static int PostInsertIndexes (TRI_transaction_collection_t* trxCollection, for (size_t i = 1; i < n; ++i) { auto idx = indexes[i]; - idx->postInsert(trxCollection, header); + idx->postInsert(trx, trxCollection, header); } // post-insert will never return an error @@ -1035,7 +1000,8 @@ static inline TRI_voc_rid_t GetRevisionId (TRI_voc_rid_t previous) { /// @brief insert a document //////////////////////////////////////////////////////////////////////////////// -static int InsertDocument (TRI_transaction_collection_t* trxCollection, +static int InsertDocument (triagens::arango::Transaction* trx, + TRI_transaction_collection_t* trxCollection, TRI_doc_mptr_t* header, triagens::wal::DocumentOperation& operation, TRI_doc_mptr_copy_t* mptr, @@ -1050,7 +1016,7 @@ static int InsertDocument (TRI_transaction_collection_t* trxCollection, // ............................................................................. // insert into primary index first - int res = InsertPrimaryIndex(document, header, false); + int res = InsertPrimaryIndex(trx, document, header, false); if (res != TRI_ERROR_NO_ERROR) { // insert has failed @@ -1058,11 +1024,11 @@ static int InsertDocument (TRI_transaction_collection_t* trxCollection, } // insert into secondary indexes - res = InsertSecondaryIndexes(document, header, false); + res = InsertSecondaryIndexes(trx, document, header, false); if (res != TRI_ERROR_NO_ERROR) { - DeleteSecondaryIndexes(document, header, true); - DeletePrimaryIndex(document, header, true); + DeleteSecondaryIndexes(trx, document, header, true); + DeletePrimaryIndex(trx, document, header, true); return res; } @@ -1086,7 +1052,7 @@ static int InsertDocument (TRI_transaction_collection_t* trxCollection, *mptr = *header; - res = PostInsertIndexes(trxCollection, header); + res = PostInsertIndexes(trx, trxCollection, header); return res; } @@ -1096,7 +1062,8 @@ static int InsertDocument (TRI_transaction_collection_t* trxCollection, /// the caller must make sure the read lock on the collection is held //////////////////////////////////////////////////////////////////////////////// -static int LookupDocument (TRI_document_collection_t* document, +static int LookupDocument (triagens::arango::Transaction* trx, + TRI_document_collection_t* document, TRI_voc_key_t key, TRI_doc_update_policy_t const* policy, TRI_doc_mptr_t*& header) { @@ -1118,7 +1085,8 @@ static int LookupDocument (TRI_document_collection_t* document, /// @brief updates an existing document //////////////////////////////////////////////////////////////////////////////// -static int UpdateDocument (TRI_transaction_collection_t* trxCollection, +static int UpdateDocument (triagens::arango::Transaction* trx, + TRI_transaction_collection_t* trxCollection, TRI_doc_mptr_t* oldHeader, triagens::wal::DocumentOperation& operation, TRI_doc_mptr_copy_t* mptr, @@ -1135,11 +1103,11 @@ static int UpdateDocument (TRI_transaction_collection_t* trxCollection, // remove old document from secondary indexes // (it will stay in the primary index as the key won't change) - int res = DeleteSecondaryIndexes(document, oldHeader, false); + int res = DeleteSecondaryIndexes(trx, document, oldHeader, false); if (res != TRI_ERROR_NO_ERROR) { // re-enter the document in case of failure, ignore errors during rollback - InsertSecondaryIndexes(document, oldHeader, true); + InsertSecondaryIndexes(trx, document, oldHeader, true); return res; } @@ -1155,16 +1123,16 @@ static int UpdateDocument (TRI_transaction_collection_t* trxCollection, newHeader->setDataPtr(operation.marker->mem()); // PROTECTED by trx in trxCollection // insert new document into secondary indexes - res = InsertSecondaryIndexes(document, newHeader, false); + res = InsertSecondaryIndexes(trx, document, newHeader, false); if (res != TRI_ERROR_NO_ERROR) { // rollback - DeleteSecondaryIndexes(document, newHeader, true); + DeleteSecondaryIndexes(trx, document, newHeader, true); // copy back old header data oldHeader->copy(oldData); - InsertSecondaryIndexes(document, oldHeader, true); + InsertSecondaryIndexes(trx, document, oldHeader, true); return res; } @@ -1332,6 +1300,7 @@ typedef struct open_iterator_state_s { TRI_doc_datafile_info_t* _dfi; TRI_vector_t _operations; TRI_vocbase_t* _vocbase; + triagens::arango::Transaction* _trx; uint64_t _deletions; uint64_t _documents; int64_t _initialCount; @@ -1379,6 +1348,7 @@ static int OpenIteratorNoteFailedTransaction (open_iterator_state_t const* state static int OpenIteratorApplyInsert (open_iterator_state_t* state, open_iterator_operation_t const* operation) { TRI_document_collection_t* document = state->_document; + triagens::arango::Transaction* trx = state->_trx; TRI_df_marker_t const* marker = operation->_marker; TRI_doc_document_key_marker_t const* d = reinterpret_cast(marker); @@ -1458,7 +1428,7 @@ static int OpenIteratorApplyInsert (open_iterator_state_t* state, } else { // use regular insert method - res = InsertPrimaryIndex(document, header, false); + res = InsertPrimaryIndex(trx, document, header, false); if (res != TRI_ERROR_NO_ERROR) { // insertion failed @@ -1540,15 +1510,13 @@ static int OpenIteratorApplyInsert (open_iterator_state_t* state, static int OpenIteratorApplyRemove (open_iterator_state_t* state, open_iterator_operation_t const* operation) { - TRI_df_marker_t const* marker; - TRI_doc_deletion_key_marker_t const* d; TRI_doc_mptr_t* found; - TRI_voc_key_t key; TRI_document_collection_t* document = state->_document; + triagens::arango::Transaction* trx = state->_trx; - marker = operation->_marker; - d = (TRI_doc_deletion_key_marker_t const*) marker; + TRI_df_marker_t const* marker = operation->_marker; + TRI_doc_deletion_key_marker_t const* d = (TRI_doc_deletion_key_marker_t const*) marker; SetRevision(document, d->_rid, false); @@ -1560,7 +1528,7 @@ static int OpenIteratorApplyRemove (open_iterator_state_t* state, state->_dfi = TRI_FindDatafileInfoDocumentCollection(document, operation->_fid, true); } - key = ((char*) d) + d->_offsetKey; + TRI_voc_key_t key = ((char*) d) + d->_offsetKey; #ifdef TRI_ENABLE_MAINTAINER_MODE LOG_TRACE("deletion: fid %llu, key %s, rid %llu, deletion %llu", @@ -1612,7 +1580,7 @@ static int OpenIteratorApplyRemove (open_iterator_state_t* state, state->_dfi->_numberDeletion++; } - DeletePrimaryIndex(document, found, false); + DeletePrimaryIndex(trx, document, found, false); --document->_numberDocuments; // free the header @@ -2084,6 +2052,11 @@ static bool OpenIterator (TRI_df_marker_t const* marker, // --SECTION-- private functions // ----------------------------------------------------------------------------- +struct OpenIndexIteratorContext { + triagens::arango::Transaction* trx; + TRI_document_collection_t* collection; +}; + //////////////////////////////////////////////////////////////////////////////// /// @brief iterator for index open //////////////////////////////////////////////////////////////////////////////// @@ -2091,21 +2064,19 @@ static bool OpenIterator (TRI_df_marker_t const* marker, static bool OpenIndexIterator (char const* filename, void* data) { // load json description of the index - TRI_json_t* json = TRI_JsonFile(TRI_CORE_MEM_ZONE, filename, nullptr); + std::unique_ptr json(TRI_JsonFile(TRI_UNKNOWN_MEM_ZONE, filename, nullptr)); // json must be a index description - if (! TRI_IsObjectJson(json)) { + if (! TRI_IsObjectJson(json.get())) { LOG_ERROR("cannot read index definition from '%s'", filename); - - if (json != nullptr) { - TRI_FreeJson(TRI_CORE_MEM_ZONE, json); - } - return false; } - int res = TRI_FromJsonIndexDocumentCollection(static_cast(data), json, nullptr); - TRI_FreeJson(TRI_CORE_MEM_ZONE, json); + auto ctx = static_cast(data); + triagens::arango::Transaction* trx = ctx->trx; + TRI_document_collection_t* collection = ctx->collection; + + int res = TRI_FromJsonIndexDocumentCollection(trx, collection, json.get(), nullptr); if (res != TRI_ERROR_NO_ERROR) { // error was already printed if we get here @@ -2155,11 +2126,8 @@ static void DestroyBaseDocumentCollection (TRI_document_collection_t* document) TRI_DestroyReadWriteLock(&document->_compactionLock); - { - TransactionBase trx(true); // just to protect the following call - if (document->getShaper() != nullptr) { // PROTECTED by trx here - delete document->getShaper(); // PROTECTED by trx here - } + if (document->getShaper() != nullptr) { // PROTECTED by trx here + delete document->getShaper(); // PROTECTED by trx here } if (document->_headersPtr != nullptr) { @@ -2260,13 +2228,15 @@ static bool InitDocumentCollection (TRI_document_collection_t* document, /// @brief iterate all markers of the collection //////////////////////////////////////////////////////////////////////////////// -static int IterateMarkersCollection (TRI_collection_t* collection) { +static int IterateMarkersCollection (triagens::arango::Transaction* trx, + TRI_collection_t* collection) { auto document = reinterpret_cast(collection); // initialize state for iteration open_iterator_state_t openState; openState._document = document; openState._vocbase = collection->_vocbase; + openState._trx = trx; openState._tid = 0; openState._trxPrepared = false; openState._trxCollections = 0; @@ -2405,7 +2375,6 @@ TRI_document_collection_t* TRI_CreateDocumentCollection (TRI_vocbase_t* vocbase, TRI_UnlinkFile(tmpfile); TRI_Free(TRI_CORE_MEM_ZONE, tmpfile); - TransactionBase trx(true); // just to protect the following call TRI_ASSERT(document->getShaper() != nullptr); // ONLY IN COLLECTION CREATION, PROTECTED by trx here return document; @@ -2666,10 +2635,10 @@ TRI_datafile_t* TRI_CreateDatafileDocumentCollection (TRI_document_collection_t* /// to ensure the collection is properly locked //////////////////////////////////////////////////////////////////////////////// -size_t TRI_DocumentIteratorDocumentCollection (TransactionBase const*, - TRI_document_collection_t* document, - void* data, - bool (*callback)(TRI_doc_mptr_t const*, TRI_document_collection_t*, void*)) { +size_t TRI_DocumentIteratorDocumentCollection (triagens::arango::Transaction* trx, + TRI_document_collection_t* document, + void* data, + bool (*callback)(TRI_doc_mptr_t const*, TRI_document_collection_t*, void*)) { // The first argument is only used to make the compiler prove that a // transaction is ongoing. We need this to prove that accesses to // master pointers and their data pointers in the callback are @@ -2698,7 +2667,8 @@ size_t TRI_DocumentIteratorDocumentCollection (TransactionBase const*, /// @brief create an index, based on a JSON description //////////////////////////////////////////////////////////////////////////////// -int TRI_FromJsonIndexDocumentCollection (TRI_document_collection_t* document, +int TRI_FromJsonIndexDocumentCollection (triagens::arango::Transaction* trx, + TRI_document_collection_t* document, TRI_json_t const* json, triagens::arango::Index** idx) { TRI_ASSERT(TRI_IsObjectJson(json)); @@ -2740,7 +2710,7 @@ int TRI_FromJsonIndexDocumentCollection (TRI_document_collection_t* document, // ........................................................................... if (TRI_EqualString(typeStr, "cap")) { - return CapConstraintFromJson(document, json, iid, idx); + return CapConstraintFromJson(trx, document, json, iid, idx); } // ........................................................................... @@ -2748,7 +2718,7 @@ int TRI_FromJsonIndexDocumentCollection (TRI_document_collection_t* document, // ........................................................................... else if (TRI_EqualString(typeStr, "geo1") || TRI_EqualString(typeStr, "geo2")) { - return GeoIndexFromJson(document, json, iid, idx); + return GeoIndexFromJson(trx, document, json, iid, idx); } // ........................................................................... @@ -2756,7 +2726,7 @@ int TRI_FromJsonIndexDocumentCollection (TRI_document_collection_t* document, // ........................................................................... else if (TRI_EqualString(typeStr, "hash")) { - return HashIndexFromJson(document, json, iid, idx); + return HashIndexFromJson(trx, document, json, iid, idx); } // ........................................................................... @@ -2764,7 +2734,7 @@ int TRI_FromJsonIndexDocumentCollection (TRI_document_collection_t* document, // ........................................................................... else if (TRI_EqualString(typeStr, "skiplist")) { - return SkiplistIndexFromJson(document, json, iid, idx); + return SkiplistIndexFromJson(trx, document, json, iid, idx); } // ........................................................................... @@ -2772,7 +2742,7 @@ int TRI_FromJsonIndexDocumentCollection (TRI_document_collection_t* document, // ........................................................................... else if (TRI_EqualString(typeStr, "fulltext")) { - return FulltextIndexFromJson(document, json, iid, idx); + return FulltextIndexFromJson(trx, document, json, iid, idx); } // ........................................................................... @@ -2793,15 +2763,16 @@ int TRI_FromJsonIndexDocumentCollection (TRI_document_collection_t* document, /// @brief rolls back a document operation //////////////////////////////////////////////////////////////////////////////// -int TRI_RollbackOperationDocumentCollection (TRI_document_collection_t* document, +int TRI_RollbackOperationDocumentCollection (triagens::arango::Transaction* trx, + TRI_document_collection_t* document, TRI_voc_document_operation_e type, TRI_doc_mptr_t* header, TRI_doc_mptr_copy_t const* oldData) { if (type == TRI_VOC_DOCUMENT_OPERATION_INSERT) { // ignore any errors we're getting from this - DeletePrimaryIndex(document, header, true); - DeleteSecondaryIndexes(document, header, true); + DeletePrimaryIndex(trx, document, header, true); + DeleteSecondaryIndexes(trx, document, header, true); TRI_ASSERT(document->_numberDocuments > 0); document->_numberDocuments--; @@ -2813,11 +2784,11 @@ int TRI_RollbackOperationDocumentCollection (TRI_document_collection_t* document TRI_doc_mptr_copy_t copy = *header; // remove the current values from the indexes - DeleteSecondaryIndexes(document, header, true); + DeleteSecondaryIndexes(trx,document, header, true); // revert to the old state header->copy(*oldData); // re-insert old state - int res = InsertSecondaryIndexes(document, header, true); + int res = InsertSecondaryIndexes(trx, document, header, true); // revert again to the new state, because other parts of the new state // will be reverted at some other place header->copy(copy); @@ -2825,10 +2796,10 @@ int TRI_RollbackOperationDocumentCollection (TRI_document_collection_t* document return res; } else if (type == TRI_VOC_DOCUMENT_OPERATION_REMOVE) { - int res = InsertPrimaryIndex(document, header, true); + int res = InsertPrimaryIndex(trx,document, header, true); if (res == TRI_ERROR_NO_ERROR) { - res = InsertSecondaryIndexes(document, header, true); + res = InsertSecondaryIndexes(trx, document, header, true); document->_numberDocuments++; } else { @@ -2920,20 +2891,21 @@ bool TRI_CloseDatafileDocumentCollection (TRI_document_collection_t* document, class IndexFiller { public: - IndexFiller (TRI_document_collection_t* document, + IndexFiller (triagens::arango::Transaction* trx, + TRI_document_collection_t* document, triagens::arango::Index* idx, std::function callback) - : _document(document), + : _trx(trx), + _document(document), _idx(idx), _callback(callback) { } void operator() () { - TransactionBase trx(true); int res = TRI_ERROR_INTERNAL; try { - res = FillIndex(_document, _idx); + res = FillIndex(_trx, _document, _idx); } catch (...) { } @@ -2943,16 +2915,18 @@ class IndexFiller { private: - TRI_document_collection_t* _document; - triagens::arango::Index* _idx; - std::function _callback; + triagens::arango::Transaction* _trx; + TRI_document_collection_t* _document; + triagens::arango::Index* _idx; + std::function _callback; }; //////////////////////////////////////////////////////////////////////////////// /// @brief fill the additional (non-primary) indexes //////////////////////////////////////////////////////////////////////////////// -int TRI_FillIndexesDocumentCollection (TRI_vocbase_col_t* collection, +int TRI_FillIndexesDocumentCollection (triagens::arango::Transaction* trx, + TRI_vocbase_col_t* collection, TRI_document_collection_t* document) { auto old = document->useSecondaryIndexes(); @@ -2961,8 +2935,11 @@ int TRI_FillIndexesDocumentCollection (TRI_vocbase_col_t* collection, document->useSecondaryIndexes(false); try { - TRI_collection_t* collection = reinterpret_cast(document); - TRI_IterateIndexCollection(collection, OpenIndexIterator, collection); + OpenIndexIteratorContext ctx; + ctx.trx = trx; + ctx.collection = document; + + TRI_IterateIndexCollection(reinterpret_cast(document), OpenIndexIterator, static_cast(&ctx)); document->useSecondaryIndexes(old); } catch (...) { @@ -3014,7 +2991,7 @@ int TRI_FillIndexesDocumentCollection (TRI_vocbase_col_t* collection, // prevent distribution to threads if (indexPool != nullptr && i != (n - 1)) { // move task into thread pool - IndexFiller indexTask(document, idx, callback); + IndexFiller indexTask(trx, document, idx, callback); try { static_cast(indexPool)->enqueue(indexTask); @@ -3032,7 +3009,7 @@ int TRI_FillIndexesDocumentCollection (TRI_vocbase_col_t* collection, int res; try { - res = FillIndex(document, idx); + res = FillIndex(trx, document, idx); } catch (...) { res = TRI_ERROR_INTERNAL; @@ -3120,8 +3097,7 @@ TRI_document_collection_t* TRI_OpenDocumentCollection (TRI_vocbase_t* vocbase, document->_keyGenerator = keyGenerator; - // create a fake transaction for loading the collection - TransactionBase trx(true); + triagens::arango::SingleCollectionWriteTransaction trx(new triagens::arango::StandaloneTransactionContext(), vocbase, document->_info._cid); // build the primary index { @@ -3132,7 +3108,7 @@ TRI_document_collection_t* TRI_OpenDocumentCollection (TRI_vocbase_t* vocbase, document->_info._name); // iterate over all markers of the collection - int res = IterateMarkersCollection(collection); + int res = IterateMarkersCollection(&trx, collection); LOG_TIMER((TRI_microtime() - start), "iterate-markers { collection: %s/%s }", @@ -3156,7 +3132,7 @@ TRI_document_collection_t* TRI_OpenDocumentCollection (TRI_vocbase_t* vocbase, TRI_ASSERT(document->getShaper() != nullptr); // ONLY in OPENCOLLECTION, PROTECTED by fake trx here if (! triagens::wal::LogfileManager::instance()->isInRecovery()) { - TRI_FillIndexesDocumentCollection(col, document); + TRI_FillIndexesDocumentCollection(&trx, col, document); } LOG_TIMER((TRI_microtime() - start), @@ -3188,7 +3164,6 @@ int TRI_CloseDocumentCollection (TRI_document_collection_t* document, // closes all open compactors, journals, datafiles int res = TRI_CloseCollection(document); - TransactionBase trx(true); // just to protect the following call delete document->getShaper(); // ONLY IN CLOSECOLLECTION, PROTECTED by fake trx here document->setShaper(nullptr); @@ -3253,7 +3228,8 @@ static TRI_json_t* ExtractFields (TRI_json_t const* json, /// @brief fill an index in batches //////////////////////////////////////////////////////////////////////////////// -static int FillIndexBatch (TRI_document_collection_t* document, +static int FillIndexBatch (triagens::arango::Transaction* trx, + TRI_document_collection_t* document, triagens::arango::Index* idx) { auto indexPool = document->_vocbase->_server->_indexPool; TRI_ASSERT(indexPool != nullptr); @@ -3302,7 +3278,7 @@ static int FillIndexBatch (TRI_document_collection_t* document, documents.emplace_back(mptr); if (documents.size() == blockSize) { - res = idx->batchInsert(&documents, indexPool->numThreads()); + res = idx->batchInsert(trx, &documents, indexPool->numThreads()); documents.clear(); // some error occurred @@ -3316,7 +3292,7 @@ static int FillIndexBatch (TRI_document_collection_t* document, // process the remainder of the documents if (res == TRI_ERROR_NO_ERROR && ! documents.empty()) { - res = idx->batchInsert(&documents, indexPool->numThreads()); + res = idx->batchInsert(trx, &documents, indexPool->numThreads()); } LOG_TIMER((TRI_microtime() - start), @@ -3334,7 +3310,8 @@ static int FillIndexBatch (TRI_document_collection_t* document, /// @brief fill an index sequentially //////////////////////////////////////////////////////////////////////////////// -static int FillIndexSequential (TRI_document_collection_t* document, +static int FillIndexSequential (triagens::arango::Transaction* trx, + TRI_document_collection_t* document, triagens::arango::Index* idx) { double start = TRI_microtime(); @@ -3367,7 +3344,7 @@ static int FillIndexSequential (TRI_document_collection_t* document, break; } - int res = idx->insert(mptr, false); + int res = idx->insert(trx, mptr, false); if (res != TRI_ERROR_NO_ERROR) { return res; @@ -3398,7 +3375,8 @@ static int FillIndexSequential (TRI_document_collection_t* document, /// @brief initializes an index with all existing documents //////////////////////////////////////////////////////////////////////////////// -static int FillIndex (TRI_document_collection_t* document, +static int FillIndex (triagens::arango::Transaction* trx, + TRI_document_collection_t* document, triagens::arango::Index* idx) { if (! document->useSecondaryIndexes()) { @@ -3418,10 +3396,10 @@ static int FillIndex (TRI_document_collection_t* document, // use batch insert if there is an index pool, // the collection has more than one index bucket // and it contains a significant amount of documents - res = FillIndexBatch(document, idx); + res = FillIndexBatch(trx, document, idx); } else { - res = FillIndexSequential(document, idx); + res = FillIndexSequential(trx, document, idx); } return res; @@ -3563,10 +3541,12 @@ static triagens::arango::Index* LookupPathIndexDocumentCollection (TRI_document_ /// @brief restores a path based index (template) //////////////////////////////////////////////////////////////////////////////// -static int PathBasedIndexFromJson (TRI_document_collection_t* document, +static int PathBasedIndexFromJson (triagens::arango::Transaction* trx, + TRI_document_collection_t* document, TRI_json_t const* definition, TRI_idx_iid_t iid, - triagens::arango::Index* (*creator) (TRI_document_collection_t*, + triagens::arango::Index* (*creator) (triagens::arango::Transaction*, + TRI_document_collection_t*, std::vector const&, TRI_idx_iid_t, bool, @@ -3638,7 +3618,7 @@ static int PathBasedIndexFromJson (TRI_document_collection_t* document, } // create the index - auto idx = creator(document, attributes, iid, sparse, unique, nullptr); + auto idx = creator(trx, document, attributes, iid, sparse, unique, nullptr); if (dst != nullptr) { *dst = idx; @@ -3937,7 +3917,8 @@ static int PidNamesByAttributeNames (std::vector const& attributes, /// @brief adds a cap constraint to a collection //////////////////////////////////////////////////////////////////////////////// -static triagens::arango::Index* CreateCapConstraintDocumentCollection (TRI_document_collection_t* document, +static triagens::arango::Index* CreateCapConstraintDocumentCollection (triagens::arango::Transaction* trx, + TRI_document_collection_t* document, size_t count, int64_t size, TRI_idx_iid_t iid, @@ -3964,11 +3945,14 @@ static triagens::arango::Index* CreateCapConstraintDocumentCollection (TRI_docum } // create a new index - std::unique_ptr capConstraint(new triagens::arango::CapConstraint(iid, document, count, size)); + auto cc = new triagens::arango::CapConstraint(iid, document, count, size); + std::unique_ptr capConstraint(cc); + + cc->initialize(trx); triagens::arango::Index* idx = static_cast(capConstraint.get()); // initializes the index with all existing documents - int res = FillIndex(document, idx); + int res = FillIndex(trx, document, idx); if (res != TRI_ERROR_NO_ERROR) { TRI_set_errno(res); @@ -3998,7 +3982,8 @@ static triagens::arango::Index* CreateCapConstraintDocumentCollection (TRI_docum /// @brief restores an index //////////////////////////////////////////////////////////////////////////////// -static int CapConstraintFromJson (TRI_document_collection_t* document, +static int CapConstraintFromJson (triagens::arango::Transaction* trx, + TRI_document_collection_t* document, TRI_json_t const* definition, TRI_idx_iid_t iid, triagens::arango::Index** dst) { @@ -4036,7 +4021,7 @@ static int CapConstraintFromJson (TRI_document_collection_t* document, return TRI_set_errno(TRI_ERROR_BAD_PARAMETER); } - auto idx = CreateCapConstraintDocumentCollection(document, count, size, iid, nullptr); + auto idx = CreateCapConstraintDocumentCollection(trx, document, count, size, iid, nullptr); if (dst != nullptr) { *dst = idx; @@ -4061,7 +4046,8 @@ triagens::arango::Index* TRI_LookupCapConstraintDocumentCollection (TRI_document /// @brief ensures that a cap constraint exists //////////////////////////////////////////////////////////////////////////////// -triagens::arango::Index* TRI_EnsureCapConstraintDocumentCollection (TRI_document_collection_t* document, +triagens::arango::Index* TRI_EnsureCapConstraintDocumentCollection (triagens::arango::Transaction* trx, + TRI_document_collection_t* document, TRI_idx_iid_t iid, size_t count, int64_t size, @@ -4070,7 +4056,7 @@ triagens::arango::Index* TRI_EnsureCapConstraintDocumentCollection (TRI_document TRI_WRITE_LOCK_DOCUMENTS_INDEXES_PRIMARY_COLLECTION(document); - auto idx = CreateCapConstraintDocumentCollection(document, count, size, iid, created); + auto idx = CreateCapConstraintDocumentCollection(trx, document, count, size, iid, created); if (idx != nullptr) { if (created) { @@ -4101,7 +4087,8 @@ triagens::arango::Index* TRI_EnsureCapConstraintDocumentCollection (TRI_document /// @brief adds a geo index to a collection //////////////////////////////////////////////////////////////////////////////// -static triagens::arango::Index* CreateGeoIndexDocumentCollection (TRI_document_collection_t* document, +static triagens::arango::Index* CreateGeoIndexDocumentCollection (triagens::arango::Transaction* trx, + TRI_document_collection_t* document, std::string const& location, std::string const& latitude, std::string const& longitude, @@ -4197,7 +4184,7 @@ static triagens::arango::Index* CreateGeoIndexDocumentCollection (TRI_document_c } // initializes the index with all existing documents - int res = FillIndex(document, idx); + int res = FillIndex(trx, document, idx); if (res != TRI_ERROR_NO_ERROR) { TRI_set_errno(res); @@ -4227,7 +4214,8 @@ static triagens::arango::Index* CreateGeoIndexDocumentCollection (TRI_document_c /// @brief restores an index //////////////////////////////////////////////////////////////////////////////// -static int GeoIndexFromJson (TRI_document_collection_t* document, +static int GeoIndexFromJson (triagens::arango::Transaction* trx, + TRI_document_collection_t* document, TRI_json_t const* definition, TRI_idx_iid_t iid, triagens::arango::Index** dst) { @@ -4267,7 +4255,8 @@ static int GeoIndexFromJson (TRI_document_collection_t* document, if (fieldCount == 1) { auto loc = static_cast(TRI_AtVector(&fld->_value._objects, 0)); - idx = CreateGeoIndexDocumentCollection(document, + idx = CreateGeoIndexDocumentCollection(trx, + document, std::string(loc->_value._string.data, loc->_value._string.length - 1), std::string(), std::string(), @@ -4295,7 +4284,8 @@ static int GeoIndexFromJson (TRI_document_collection_t* document, auto lat = static_cast(TRI_AtVector(&fld->_value._objects, 0)); auto lon = static_cast(TRI_AtVector(&fld->_value._objects, 1)); - idx = CreateGeoIndexDocumentCollection(document, + idx = CreateGeoIndexDocumentCollection(trx, + document, std::string(), std::string(lat->_value._string.data, lat->_value._string.length - 1), std::string(lon->_value._string.data, lon->_value._string.length - 1), @@ -4389,7 +4379,8 @@ triagens::arango::Index* TRI_LookupGeoIndex2DocumentCollection (TRI_document_col /// @brief ensures that a geo index exists, list style //////////////////////////////////////////////////////////////////////////////// -triagens::arango::Index* TRI_EnsureGeoIndex1DocumentCollection (TRI_document_collection_t* document, +triagens::arango::Index* TRI_EnsureGeoIndex1DocumentCollection (triagens::arango::Transaction* trx, + TRI_document_collection_t* document, TRI_idx_iid_t iid, std::string const& location, bool geoJson, @@ -4398,7 +4389,7 @@ triagens::arango::Index* TRI_EnsureGeoIndex1DocumentCollection (TRI_document_col TRI_WRITE_LOCK_DOCUMENTS_INDEXES_PRIMARY_COLLECTION(document); - auto idx = CreateGeoIndexDocumentCollection(document, location, std::string(), std::string(), geoJson, iid, created); + auto idx = CreateGeoIndexDocumentCollection(trx, document, location, std::string(), std::string(), geoJson, iid, created); if (idx != nullptr) { if (created) { @@ -4420,7 +4411,8 @@ triagens::arango::Index* TRI_EnsureGeoIndex1DocumentCollection (TRI_document_col /// @brief ensures that a geo index exists, attribute style //////////////////////////////////////////////////////////////////////////////// -triagens::arango::Index* TRI_EnsureGeoIndex2DocumentCollection (TRI_document_collection_t* document, +triagens::arango::Index* TRI_EnsureGeoIndex2DocumentCollection (triagens::arango::Transaction* trx, + TRI_document_collection_t* document, TRI_idx_iid_t iid, std::string const& latitude, std::string const& longitude, @@ -4429,7 +4421,7 @@ triagens::arango::Index* TRI_EnsureGeoIndex2DocumentCollection (TRI_document_col TRI_WRITE_LOCK_DOCUMENTS_INDEXES_PRIMARY_COLLECTION(document); - auto idx = CreateGeoIndexDocumentCollection(document, std::string(), latitude, longitude, false, iid, created); + auto idx = CreateGeoIndexDocumentCollection(trx, document, std::string(), latitude, longitude, false, iid, created); if (idx != nullptr) { if (created) { @@ -4459,7 +4451,8 @@ triagens::arango::Index* TRI_EnsureGeoIndex2DocumentCollection (TRI_document_col /// @brief adds a hash index to the collection //////////////////////////////////////////////////////////////////////////////// -static triagens::arango::Index* CreateHashIndexDocumentCollection (TRI_document_collection_t* document, +static triagens::arango::Index* CreateHashIndexDocumentCollection (triagens::arango::Transaction* trx, + TRI_document_collection_t* document, std::vector const& attributes, TRI_idx_iid_t iid, bool sparse, @@ -4514,7 +4507,7 @@ static triagens::arango::Index* CreateHashIndexDocumentCollection (TRI_document_ idx = static_cast(hashIndex.get()); // initializes the index with all existing documents - res = FillIndex(document, idx); + res = FillIndex(trx, document, idx); if (res != TRI_ERROR_NO_ERROR) { TRI_set_errno(res); @@ -4544,11 +4537,12 @@ static triagens::arango::Index* CreateHashIndexDocumentCollection (TRI_document_ /// @brief restores an index //////////////////////////////////////////////////////////////////////////////// -static int HashIndexFromJson (TRI_document_collection_t* document, +static int HashIndexFromJson (triagens::arango::Transaction* trx, + TRI_document_collection_t* document, TRI_json_t const* definition, TRI_idx_iid_t iid, triagens::arango::Index** dst) { - return PathBasedIndexFromJson(document, definition, iid, CreateHashIndexDocumentCollection, dst); + return PathBasedIndexFromJson(trx, document, definition, iid, CreateHashIndexDocumentCollection, dst); } // ----------------------------------------------------------------------------- @@ -4586,7 +4580,8 @@ triagens::arango::Index* TRI_LookupHashIndexDocumentCollection (TRI_document_col /// @brief ensures that a hash index exists //////////////////////////////////////////////////////////////////////////////// -triagens::arango::Index* TRI_EnsureHashIndexDocumentCollection (TRI_document_collection_t* document, +triagens::arango::Index* TRI_EnsureHashIndexDocumentCollection (triagens::arango::Transaction* trx, + TRI_document_collection_t* document, TRI_idx_iid_t iid, std::vector const& attributes, bool sparse, @@ -4596,7 +4591,7 @@ triagens::arango::Index* TRI_EnsureHashIndexDocumentCollection (TRI_document_col TRI_WRITE_LOCK_DOCUMENTS_INDEXES_PRIMARY_COLLECTION(document); - auto idx = CreateHashIndexDocumentCollection(document, attributes, iid, sparse, unique, created); + auto idx = CreateHashIndexDocumentCollection(trx, document, attributes, iid, sparse, unique, created); if (idx != nullptr) { if (created) { @@ -4626,7 +4621,8 @@ triagens::arango::Index* TRI_EnsureHashIndexDocumentCollection (TRI_document_col /// @brief adds a skiplist index to the collection //////////////////////////////////////////////////////////////////////////////// -static triagens::arango::Index* CreateSkiplistIndexDocumentCollection (TRI_document_collection_t* document, +static triagens::arango::Index* CreateSkiplistIndexDocumentCollection (triagens::arango::Transaction* trx, + TRI_document_collection_t* document, std::vector const& attributes, TRI_idx_iid_t iid, bool sparse, @@ -4678,7 +4674,7 @@ static triagens::arango::Index* CreateSkiplistIndexDocumentCollection (TRI_docum idx = static_cast(skiplistIndex.get()); // initializes the index with all existing documents - res = FillIndex(document, idx); + res = FillIndex(trx, document, idx); if (res != TRI_ERROR_NO_ERROR) { TRI_set_errno(res); @@ -4708,11 +4704,12 @@ static triagens::arango::Index* CreateSkiplistIndexDocumentCollection (TRI_docum /// @brief restores an index //////////////////////////////////////////////////////////////////////////////// -static int SkiplistIndexFromJson (TRI_document_collection_t* document, +static int SkiplistIndexFromJson (triagens::arango::Transaction* trx, + TRI_document_collection_t* document, TRI_json_t const* definition, TRI_idx_iid_t iid, triagens::arango::Index** dst) { - return PathBasedIndexFromJson(document, definition, iid, CreateSkiplistIndexDocumentCollection, dst); + return PathBasedIndexFromJson(trx, document, definition, iid, CreateSkiplistIndexDocumentCollection, dst); } // ----------------------------------------------------------------------------- @@ -4750,7 +4747,8 @@ triagens::arango::Index* TRI_LookupSkiplistIndexDocumentCollection (TRI_document /// @brief ensures that a skiplist index exists //////////////////////////////////////////////////////////////////////////////// -triagens::arango::Index* TRI_EnsureSkiplistIndexDocumentCollection (TRI_document_collection_t* document, +triagens::arango::Index* TRI_EnsureSkiplistIndexDocumentCollection (triagens::arango::Transaction* trx, + TRI_document_collection_t* document, TRI_idx_iid_t iid, std::vector const& attributes, bool sparse, @@ -4760,7 +4758,7 @@ triagens::arango::Index* TRI_EnsureSkiplistIndexDocumentCollection (TRI_document TRI_WRITE_LOCK_DOCUMENTS_INDEXES_PRIMARY_COLLECTION(document); - auto idx = CreateSkiplistIndexDocumentCollection(document, attributes, iid, sparse, unique, created); + auto idx = CreateSkiplistIndexDocumentCollection(trx, document, attributes, iid, sparse, unique, created); if (idx != nullptr) { if (created) { @@ -4806,7 +4804,8 @@ static triagens::arango::Index* LookupFulltextIndexDocumentCollection (TRI_docum /// @brief adds a fulltext index to the collection //////////////////////////////////////////////////////////////////////////////// -static triagens::arango::Index* CreateFulltextIndexDocumentCollection (TRI_document_collection_t* document, +static triagens::arango::Index* CreateFulltextIndexDocumentCollection (triagens::arango::Transaction* trx, + TRI_document_collection_t* document, std::string const& attribute, int minWordLength, TRI_idx_iid_t iid, @@ -4837,7 +4836,7 @@ static triagens::arango::Index* CreateFulltextIndexDocumentCollection (TRI_docum idx = static_cast(fulltextIndex.get()); // initializes the index with all existing documents - int res = FillIndex(document, idx); + int res = FillIndex(trx, document, idx); if (res != TRI_ERROR_NO_ERROR) { TRI_set_errno(res); @@ -4867,7 +4866,8 @@ static triagens::arango::Index* CreateFulltextIndexDocumentCollection (TRI_docum /// @brief restores an index //////////////////////////////////////////////////////////////////////////////// -static int FulltextIndexFromJson (TRI_document_collection_t* document, +static int FulltextIndexFromJson (triagens::arango::Transaction* trx, + TRI_document_collection_t* document, TRI_json_t const* definition, TRI_idx_iid_t iid, triagens::arango::Index** dst) { @@ -4913,7 +4913,7 @@ static int FulltextIndexFromJson (TRI_document_collection_t* document, if (idx == nullptr) { bool created; - idx = CreateFulltextIndexDocumentCollection(document, attribute, minWordLengthValue, iid, &created); + idx = CreateFulltextIndexDocumentCollection(trx, document, attribute, minWordLengthValue, iid, &created); } if (dst != nullptr) { @@ -4947,7 +4947,8 @@ triagens::arango::Index* TRI_LookupFulltextIndexDocumentCollection (TRI_document /// @brief ensures that a fulltext index exists //////////////////////////////////////////////////////////////////////////////// -triagens::arango::Index* TRI_EnsureFulltextIndexDocumentCollection (TRI_document_collection_t* document, +triagens::arango::Index* TRI_EnsureFulltextIndexDocumentCollection (triagens::arango::Transaction* trx, + TRI_document_collection_t* document, TRI_idx_iid_t iid, std::string const& attribute, int minWordLength, @@ -4956,7 +4957,7 @@ triagens::arango::Index* TRI_EnsureFulltextIndexDocumentCollection (TRI_document TRI_WRITE_LOCK_DOCUMENTS_INDEXES_PRIMARY_COLLECTION(document); - auto idx = CreateFulltextIndexDocumentCollection(document, attribute, minWordLength, iid, created); + auto idx = CreateFulltextIndexDocumentCollection(trx, document, attribute, minWordLength, iid, created); if (idx != nullptr) { if (created) { @@ -5013,10 +5014,12 @@ std::vector TRI_SelectByExample ( /// @brief deletes a document given by a master pointer //////////////////////////////////////////////////////////////////////////////// -int TRI_DeleteDocumentDocumentCollection (TRI_transaction_collection_t* trxCollection, +int TRI_DeleteDocumentDocumentCollection (triagens::arango::Transaction* trx, + TRI_transaction_collection_t* trxCollection, TRI_doc_update_policy_t const* policy, TRI_doc_mptr_t* doc) { - return TRI_RemoveShapedJsonDocumentCollection(trxCollection, + return TRI_RemoveShapedJsonDocumentCollection(trx, + trxCollection, (const TRI_voc_key_t) TRI_EXTRACT_MARKER_KEY(doc), 0, nullptr, @@ -5059,7 +5062,8 @@ int TRI_RotateJournalDocumentCollection (TRI_document_collection_t* document) { /// @brief reads an element from the document collection //////////////////////////////////////////////////////////////////////////////// -int TRI_ReadShapedJsonDocumentCollection (TRI_transaction_collection_t* trxCollection, +int TRI_ReadShapedJsonDocumentCollection (triagens::arango::Transaction* trx, + TRI_transaction_collection_t* trxCollection, const TRI_voc_key_t key, TRI_doc_mptr_copy_t* mptr, bool lock) { @@ -5081,7 +5085,7 @@ int TRI_ReadShapedJsonDocumentCollection (TRI_transaction_collection_t* trxColle triagens::arango::CollectionReadLocker collectionLocker(document, lock); TRI_doc_mptr_t* header; - int res = LookupDocument(document, key, nullptr, header); + int res = LookupDocument(trx, document, key, nullptr, header); if (res != TRI_ERROR_NO_ERROR) { return res; @@ -5101,7 +5105,8 @@ int TRI_ReadShapedJsonDocumentCollection (TRI_transaction_collection_t* trxColle /// @brief removes a shaped-json document (or edge) //////////////////////////////////////////////////////////////////////////////// -int TRI_RemoveShapedJsonDocumentCollection (TRI_transaction_collection_t* trxCollection, +int TRI_RemoveShapedJsonDocumentCollection (triagens::arango::Transaction* trx, + TRI_transaction_collection_t* trxCollection, TRI_voc_key_t key, TRI_voc_rid_t rid, triagens::wal::Marker* marker, @@ -5150,9 +5155,9 @@ int TRI_RemoveShapedJsonDocumentCollection (TRI_transaction_collection_t* trxCol triagens::arango::CollectionWriteLocker collectionLocker(document, lock); - triagens::wal::DocumentOperation operation(marker, freeMarker, document, TRI_VOC_DOCUMENT_OPERATION_REMOVE, rid); + triagens::wal::DocumentOperation operation(trx, marker, freeMarker, document, TRI_VOC_DOCUMENT_OPERATION_REMOVE, rid); - res = LookupDocument(document, key, policy, header); + res = LookupDocument(trx, document, key, policy, header); if (res != TRI_ERROR_NO_ERROR) { return res; @@ -5164,17 +5169,17 @@ int TRI_RemoveShapedJsonDocumentCollection (TRI_transaction_collection_t* trxCol operation.init(); // delete from indexes - res = DeleteSecondaryIndexes(document, header, false); + res = DeleteSecondaryIndexes(trx, document, header, false); if (res != TRI_ERROR_NO_ERROR) { - InsertSecondaryIndexes(document, header, true); + InsertSecondaryIndexes(trx, document, header, true); return res; } - res = DeletePrimaryIndex(document, header, false); + res = DeletePrimaryIndex(trx, document, header, false); if (res != TRI_ERROR_NO_ERROR) { - InsertSecondaryIndexes(document, header, true); + InsertSecondaryIndexes(trx, document, header, true); return res; } @@ -5214,7 +5219,8 @@ int TRI_RemoveShapedJsonDocumentCollection (TRI_transaction_collection_t* trxCol /// note: key might be NULL. in this case, a key is auto-generated //////////////////////////////////////////////////////////////////////////////// -int TRI_InsertShapedJsonDocumentCollection (TRI_transaction_collection_t* trxCollection, +int TRI_InsertShapedJsonDocumentCollection (triagens::arango::Transaction* trx, + TRI_transaction_collection_t* trxCollection, const TRI_voc_key_t key, TRI_voc_rid_t rid, triagens::wal::Marker* marker, @@ -5291,7 +5297,7 @@ int TRI_InsertShapedJsonDocumentCollection (TRI_transaction_collection_t* trxCol triagens::arango::CollectionWriteLocker collectionLocker(document, lock); - triagens::wal::DocumentOperation operation(marker, freeMarker, document, TRI_VOC_DOCUMENT_OPERATION_INSERT, rid); + triagens::wal::DocumentOperation operation(trx, marker, freeMarker, document, TRI_VOC_DOCUMENT_OPERATION_INSERT, rid); TRI_IF_FAILURE("InsertDocumentNoHeader") { // test what happens if no header can be acquired @@ -5318,7 +5324,7 @@ int TRI_InsertShapedJsonDocumentCollection (TRI_transaction_collection_t* trxCol header->_hash = hash; // insert into indexes - res = InsertDocument(trxCollection, header, operation, mptr, forceSync); + res = InsertDocument(trx, trxCollection, header, operation, mptr, forceSync); if (res != TRI_ERROR_NO_ERROR) { operation.revert(); @@ -5344,7 +5350,8 @@ int TRI_InsertShapedJsonDocumentCollection (TRI_transaction_collection_t* trxCol /// @brief updates a document in the collection from shaped json //////////////////////////////////////////////////////////////////////////////// -int TRI_UpdateShapedJsonDocumentCollection (TRI_transaction_collection_t* trxCollection, +int TRI_UpdateShapedJsonDocumentCollection (triagens::arango::Transaction* trx, + TRI_transaction_collection_t* trxCollection, TRI_voc_key_t key, TRI_voc_rid_t rid, triagens::wal::Marker* marker, @@ -5377,7 +5384,7 @@ int TRI_UpdateShapedJsonDocumentCollection (TRI_transaction_collection_t* trxCol // get the header pointer of the previous revision TRI_doc_mptr_t* oldHeader; - res = LookupDocument(document, key, policy, oldHeader); + res = LookupDocument(trx, document, key, policy, oldHeader); if (res != TRI_ERROR_NO_ERROR) { return res; @@ -5419,11 +5426,11 @@ int TRI_UpdateShapedJsonDocumentCollection (TRI_transaction_collection_t* trxCol TRI_ASSERT(marker != nullptr); - triagens::wal::DocumentOperation operation(marker, freeMarker, document, TRI_VOC_DOCUMENT_OPERATION_UPDATE, rid); + triagens::wal::DocumentOperation operation(trx, marker, freeMarker, document, TRI_VOC_DOCUMENT_OPERATION_UPDATE, rid); operation.header = oldHeader; operation.init(); - res = UpdateDocument(trxCollection, oldHeader, operation, mptr, forceSync); + res = UpdateDocument(trx, trxCollection, oldHeader, operation, mptr, forceSync); if (res != TRI_ERROR_NO_ERROR) { operation.revert(); @@ -5476,7 +5483,7 @@ int TRI_document_collection_t::insert (Transaction* trx, triagens::arango::CollectionWriteLocker collectionLocker(this, lock); - triagens::wal::DocumentOperation operation(marker.get(), false, this, TRI_VOC_DOCUMENT_OPERATION_INSERT, 0 /*rid*/); // TODO: fix rid + triagens::wal::DocumentOperation operation(trx, marker.get(), false, this, TRI_VOC_DOCUMENT_OPERATION_INSERT, 0 /*rid*/); // TODO: fix rid TRI_IF_FAILURE("InsertDocumentNoHeader") { // test what happens if no header can be acquired @@ -5557,7 +5564,7 @@ int TRI_document_collection_t::remove (triagens::arango::Transaction* trx, triagens::arango::CollectionWriteLocker collectionLocker(this, lock); - triagens::wal::DocumentOperation operation(marker.get(), false, this, TRI_VOC_DOCUMENT_OPERATION_REMOVE, 0 /*rid*/); // TODO: fix rid + triagens::wal::DocumentOperation operation(trx, marker.get(), false, this, TRI_VOC_DOCUMENT_OPERATION_REMOVE, 0 /*rid*/); // TODO: fix rid res = lookupDocument(trx, slice, policy, header); @@ -5796,7 +5803,7 @@ int TRI_document_collection_t::insertSecondaryIndexes (triagens::arango::Transac for (size_t i = 1; i < n; ++i) { auto idx = indexes[i]; - int res = idx->insert(header, isRollback); + int res = idx->insert(trx, header, isRollback); // in case of no-memory, return immediately if (res == TRI_ERROR_OUT_OF_MEMORY) { @@ -5855,7 +5862,7 @@ int TRI_document_collection_t::deleteSecondaryIndexes (triagens::arango::Transac for (size_t i = 1; i < n; ++i) { auto idx = indexes[i]; - int res = idx->remove(header, isRollback); + int res = idx->remove(trx, header, isRollback); if (res != TRI_ERROR_NO_ERROR) { // an error occurred @@ -5883,7 +5890,7 @@ int TRI_document_collection_t::postInsertIndexes (triagens::arango::Transaction* for (size_t i = 1; i < n; ++i) { auto idx = indexes[i]; - idx->postInsert(trxCollection, header); + idx->postInsert(trx, trxCollection, header); } // post-insert will never return an error diff --git a/arangod/VocBase/document-collection.h b/arangod/VocBase/document-collection.h index 806a918810..44ccf5c466 100644 --- a/arangod/VocBase/document-collection.h +++ b/arangod/VocBase/document-collection.h @@ -174,35 +174,17 @@ struct TRI_doc_mptr_t { /// @brief return a pointer to the beginning of the marker //////////////////////////////////////////////////////////////////////////////// -#ifndef TRI_ENABLE_MAINTAINER_MODE inline void const* getDataPtr () const { return _dataptr; } -#else - // The actual code has an assertion about transactions! - virtual void const* getDataPtr () const; -#endif - -//////////////////////////////////////////////////////////////////////////////// -/// @brief return a pointer to the beginning of the marker, without checking -//////////////////////////////////////////////////////////////////////////////// - - inline void const* getDataPtrUnchecked () const { - return _dataptr; - } //////////////////////////////////////////////////////////////////////////////// /// @brief set the pointer to the beginning of the memory for the marker //////////////////////////////////////////////////////////////////////////////// -#ifndef TRI_ENABLE_MAINTAINER_MODE inline void setDataPtr (void const* d) { _dataptr = d; } -#else - // The actual code has an assertion about transactions! - virtual void setDataPtr (void const* d); -#endif //////////////////////////////////////////////////////////////////////////////// /// @brief return a pointer to the beginning of the shaped json stored in the @@ -259,9 +241,6 @@ struct TRI_doc_mptr_copy_t final : public TRI_doc_mptr_t { } TRI_doc_mptr_copy_t const& operator= (TRI_doc_mptr_t const& that) { -#ifdef TRI_ENABLE_MAINTAINER_MODE - triagens::arango::TransactionBase::assertCurrentTrxActive(); -#endif copy(that); return *this; } @@ -277,23 +256,13 @@ struct TRI_doc_mptr_copy_t final : public TRI_doc_mptr_t { return std::move(*this); } -#ifndef TRI_ENABLE_MAINTAINER_MODE inline void const* getDataPtr () const { return _dataptr; } -#else - // The actual code has an assertion about transactions! - virtual void const* getDataPtr () const; -#endif -#ifndef TRI_ENABLE_MAINTAINER_MODE inline void setDataPtr (void const* d) { _dataptr = d; } -#else - // The actual code has an assertion about transactions! - virtual void setDataPtr (void const* d); -#endif }; @@ -508,11 +477,11 @@ TRI_doc_datafile_info_t* TRI_FindDatafileInfoDocumentCollection (TRI_document_co /// to ensure the collection is properly locked //////////////////////////////////////////////////////////////////////////////// -size_t TRI_DocumentIteratorDocumentCollection (triagens::arango::TransactionBase const*, - TRI_document_collection_t*, - void*, - bool (*callback)(TRI_doc_mptr_t const*, - TRI_document_collection_t*, void*)); +size_t TRI_DocumentIteratorDocumentCollection (triagens::arango::Transaction*, + TRI_document_collection_t*, + void*, + bool (*callback)(TRI_doc_mptr_t const*, + TRI_document_collection_t*, void*)); // ----------------------------------------------------------------------------- // --SECTION-- DOCUMENT COLLECTION @@ -816,7 +785,8 @@ bool TRI_IsFullyCollectedDocumentCollection (TRI_document_collection_t*); /// @brief create an index, based on a JSON description //////////////////////////////////////////////////////////////////////////////// -int TRI_FromJsonIndexDocumentCollection (TRI_document_collection_t*, +int TRI_FromJsonIndexDocumentCollection (triagens::arango::Transaction*, + TRI_document_collection_t*, struct TRI_json_t const*, triagens::arango::Index**); @@ -824,7 +794,8 @@ int TRI_FromJsonIndexDocumentCollection (TRI_document_collection_t*, /// @brief rolls back a document operation //////////////////////////////////////////////////////////////////////////////// -int TRI_RollbackOperationDocumentCollection (TRI_document_collection_t*, +int TRI_RollbackOperationDocumentCollection (triagens::arango::Transaction*, + TRI_document_collection_t*, TRI_voc_document_operation_e, TRI_doc_mptr_t*, TRI_doc_mptr_copy_t const*); @@ -850,7 +821,8 @@ bool TRI_CloseDatafileDocumentCollection (TRI_document_collection_t*, /// @brief fill the additional (non-primary) indexes //////////////////////////////////////////////////////////////////////////////// -int TRI_FillIndexesDocumentCollection (TRI_vocbase_col_t*, +int TRI_FillIndexesDocumentCollection (triagens::arango::Transaction*, + TRI_vocbase_col_t*, TRI_document_collection_t*); //////////////////////////////////////////////////////////////////////////////// @@ -919,7 +891,8 @@ triagens::arango::Index* TRI_LookupCapConstraintDocumentCollection (TRI_document /// @brief ensures that a cap constraint exists //////////////////////////////////////////////////////////////////////////////// -triagens::arango::Index* TRI_EnsureCapConstraintDocumentCollection (TRI_document_collection_t*, +triagens::arango::Index* TRI_EnsureCapConstraintDocumentCollection (triagens::arango::Transaction*, + TRI_document_collection_t*, TRI_idx_iid_t, size_t, int64_t, @@ -957,7 +930,8 @@ triagens::arango::Index* TRI_LookupGeoIndex2DocumentCollection (TRI_document_col /// @brief ensures that a geo index exists, list style //////////////////////////////////////////////////////////////////////////////// -triagens::arango::Index* TRI_EnsureGeoIndex1DocumentCollection (TRI_document_collection_t*, +triagens::arango::Index* TRI_EnsureGeoIndex1DocumentCollection (triagens::arango::Transaction*, + TRI_document_collection_t*, TRI_idx_iid_t, std::string const&, bool, @@ -967,7 +941,8 @@ triagens::arango::Index* TRI_EnsureGeoIndex1DocumentCollection (TRI_document_col /// @brief ensures that a geo index exists, attribute style //////////////////////////////////////////////////////////////////////////////// -triagens::arango::Index* TRI_EnsureGeoIndex2DocumentCollection (TRI_document_collection_t*, +triagens::arango::Index* TRI_EnsureGeoIndex2DocumentCollection (triagens::arango::Transaction*, + TRI_document_collection_t*, TRI_idx_iid_t, std::string const&, std::string const&, @@ -998,7 +973,8 @@ triagens::arango::Index* TRI_LookupHashIndexDocumentCollection (TRI_document_col /// @brief ensures that a hash index exists //////////////////////////////////////////////////////////////////////////////// -triagens::arango::Index* TRI_EnsureHashIndexDocumentCollection (TRI_document_collection_t*, +triagens::arango::Index* TRI_EnsureHashIndexDocumentCollection (triagens::arango::Transaction* trx, + TRI_document_collection_t*, TRI_idx_iid_t, std::vector const&, bool, @@ -1028,7 +1004,8 @@ triagens::arango::Index* TRI_LookupSkiplistIndexDocumentCollection (TRI_document /// @brief ensures that a skiplist index exists //////////////////////////////////////////////////////////////////////////////// -triagens::arango::Index* TRI_EnsureSkiplistIndexDocumentCollection (TRI_document_collection_t*, +triagens::arango::Index* TRI_EnsureSkiplistIndexDocumentCollection (triagens::arango::Transaction* trx, + TRI_document_collection_t*, TRI_idx_iid_t, std::vector const&, bool, @@ -1057,7 +1034,8 @@ triagens::arango::Index* TRI_LookupFulltextIndexDocumentCollection (TRI_document /// @brief ensures that a fulltext index exists //////////////////////////////////////////////////////////////////////////////// -triagens::arango::Index* TRI_EnsureFulltextIndexDocumentCollection (TRI_document_collection_t*, +triagens::arango::Index* TRI_EnsureFulltextIndexDocumentCollection (triagens::arango::Transaction* trx, + TRI_document_collection_t*, TRI_idx_iid_t, std::string const&, int, @@ -1071,10 +1049,8 @@ triagens::arango::Index* TRI_EnsureFulltextIndexDocumentCollection (TRI_document /// @brief executes a select-by-example query //////////////////////////////////////////////////////////////////////////////// -std::vector TRI_SelectByExample ( - struct TRI_transaction_collection_s*, - triagens::arango::ExampleMatcher& matcher - ); +std::vector TRI_SelectByExample (struct TRI_transaction_collection_s*, + triagens::arango::ExampleMatcher& matcher); //////////////////////////////////////////////////////////////////////////////// /// @brief executes a select-by-example query @@ -1105,7 +1081,8 @@ struct ShapedJsonEq { /// @brief deletes a documet given by a master pointer //////////////////////////////////////////////////////////////////////////////// -int TRI_DeleteDocumentDocumentCollection (struct TRI_transaction_collection_s*, +int TRI_DeleteDocumentDocumentCollection (triagens::arango::Transaction*, + struct TRI_transaction_collection_s*, TRI_doc_update_policy_t const*, TRI_doc_mptr_t*); @@ -1124,7 +1101,8 @@ int TRI_RotateJournalDocumentCollection (TRI_document_collection_t*); /// @brief reads an element from the document collection //////////////////////////////////////////////////////////////////////////////// -int TRI_ReadShapedJsonDocumentCollection (TRI_transaction_collection_t*, +int TRI_ReadShapedJsonDocumentCollection (triagens::arango::Transaction*, + TRI_transaction_collection_t*, const TRI_voc_key_t, TRI_doc_mptr_copy_t*, bool); @@ -1133,7 +1111,8 @@ int TRI_ReadShapedJsonDocumentCollection (TRI_transaction_collection_t*, /// @brief removes a shaped-json document (or edge) //////////////////////////////////////////////////////////////////////////////// -int TRI_RemoveShapedJsonDocumentCollection (TRI_transaction_collection_t*, +int TRI_RemoveShapedJsonDocumentCollection (triagens::arango::Transaction*, + TRI_transaction_collection_t*, const TRI_voc_key_t, TRI_voc_rid_t, triagens::wal::Marker*, @@ -1146,7 +1125,8 @@ int TRI_RemoveShapedJsonDocumentCollection (TRI_transaction_collection_t*, /// note: key might be NULL. in this case, a key is auto-generated //////////////////////////////////////////////////////////////////////////////// -int TRI_InsertShapedJsonDocumentCollection (TRI_transaction_collection_t*, +int TRI_InsertShapedJsonDocumentCollection (triagens::arango::Transaction*, + TRI_transaction_collection_t*, const TRI_voc_key_t, TRI_voc_rid_t, triagens::wal::Marker*, @@ -1161,7 +1141,8 @@ int TRI_InsertShapedJsonDocumentCollection (TRI_transaction_collection_t*, /// @brief updates a document in the collection from shaped json //////////////////////////////////////////////////////////////////////////////// -int TRI_UpdateShapedJsonDocumentCollection (TRI_transaction_collection_t*, +int TRI_UpdateShapedJsonDocumentCollection (triagens::arango::Transaction*, + TRI_transaction_collection_t*, const TRI_voc_key_t, TRI_voc_rid_t, triagens::wal::Marker*, diff --git a/arangod/VocBase/replication-dump.cpp b/arangod/VocBase/replication-dump.cpp index e05dc932c8..f2f30c9a50 100644 --- a/arangod/VocBase/replication-dump.cpp +++ b/arangod/VocBase/replication-dump.cpp @@ -491,9 +491,6 @@ static int AppendDocument (triagens::wal::document_marker_t const* marker, if (*((uint64_t*) legend) == 0ULL) { // marker has no legend - // create a fake transaction so no assertion fails - triagens::arango::TransactionBase trx(true); - // try to open the collection and use the shaper TRI_vocbase_t* vocbase = TRI_UseDatabaseByIdServer(dump->_vocbase->_server, marker->_databaseId); @@ -1187,14 +1184,6 @@ static int DumpCollection (TRI_replication_dump_t* dump, bool bufferFull; bool ignoreMarkers; - // The following fake transaction allows us to access data pointers - // and shapers, essentially disabling the runtime checks. This is OK, - // since the dump only considers data files (and not WAL files), so - // the collector has no trouble. Also, the data files of the collection - // are protected from the compactor by a barrier and the dump only goes - // until a certain tick. - triagens::arango::TransactionBase trx(true); - LOG_TRACE("dumping collection %llu, tick range %llu - %llu", (unsigned long long) document->_info._cid, (unsigned long long) dataMin, diff --git a/arangod/VocBase/voc-types.h b/arangod/VocBase/voc-types.h index 09872c7153..8b3cd2e076 100644 --- a/arangod/VocBase/voc-types.h +++ b/arangod/VocBase/voc-types.h @@ -154,131 +154,6 @@ typedef struct TRI_document_edge_s { } TRI_document_edge_t; -namespace triagens { - namespace arango { - -// ----------------------------------------------------------------------------- -// --SECTION-- class TransactionBase -// ----------------------------------------------------------------------------- -// - class TransactionBase { - -//////////////////////////////////////////////////////////////////////////////// -/// @brief Transaction base, every transaction class has to inherit from here -//////////////////////////////////////////////////////////////////////////////// - - public: - -//////////////////////////////////////////////////////////////////////////////// -/// @brief constructor -//////////////////////////////////////////////////////////////////////////////// - - TransactionBase () { -#ifdef TRI_ENABLE_MAINTAINER_MODE - TRI_ASSERT(_numberTrxInScope >= 0); - TRI_ASSERT(_numberTrxInScope == _numberTrxActive); - _numberTrxInScope++; -#endif - } - - explicit TransactionBase (bool standalone) { -#ifdef TRI_ENABLE_MAINTAINER_MODE - TRI_ASSERT(_numberTrxInScope >= 0); - TRI_ASSERT(_numberTrxInScope == _numberTrxActive); - _numberTrxInScope++; - if (standalone) { - _numberTrxActive++; - } -#endif - } - -//////////////////////////////////////////////////////////////////////////////// -/// @brief destructor -//////////////////////////////////////////////////////////////////////////////// - - virtual ~TransactionBase () { -#ifdef TRI_ENABLE_MAINTAINER_MODE - TRI_ASSERT(_numberTrxInScope > 0); - _numberTrxInScope--; - // Note that embedded transactions might have seen a begin() - // but no abort() or commit(), so _numberTrxActive might - // be one too big. We simply fix it here: - _numberTrxActive = _numberTrxInScope; -#endif - } - -//////////////////////////////////////////////////////////////////////////////// -/// @brief set counters, used in replication client to transfer transactions -/// between threads. -//////////////////////////////////////////////////////////////////////////////// - - static void setNumbers (int numberInScope, int numberActive) { -#ifdef TRI_ENABLE_MAINTAINER_MODE - _numberTrxInScope = numberInScope; - _numberTrxActive = numberActive; -#endif - } - -//////////////////////////////////////////////////////////////////////////////// -/// @brief increase counters, used in replication client in shutdown to -/// kill transactions of other threads. -//////////////////////////////////////////////////////////////////////////////// - - static void increaseNumbers (int numberInScope, int numberActive) { -#ifdef TRI_ENABLE_MAINTAINER_MODE - TRI_ASSERT(_numberTrxInScope + numberInScope >= 0); - TRI_ASSERT(_numberTrxActive + numberActive >= 0); - _numberTrxInScope += numberInScope; - _numberTrxActive += numberActive; -#endif - } - -//////////////////////////////////////////////////////////////////////////////// -/// @brief assert that a transaction object is in scope in the current thread -//////////////////////////////////////////////////////////////////////////////// - - static void assertSomeTrxInScope () { -#ifdef TRI_ENABLE_MAINTAINER_MODE - TRI_ASSERT(_numberTrxInScope > 0); -#endif - } - -//////////////////////////////////////////////////////////////////////////////// -/// @brief assert that the innermost transaction object in scope in the -/// current thread is actually active (between begin() and commit()/abort(). -//////////////////////////////////////////////////////////////////////////////// - - static void assertCurrentTrxActive () { -#ifdef TRI_ENABLE_MAINTAINER_MODE - TRI_ASSERT(_numberTrxInScope > 0 && - _numberTrxInScope == _numberTrxActive); -#endif - } - -//////////////////////////////////////////////////////////////////////////////// -/// @brief the following is for the runtime protection check, number of -/// transaction objects in scope in the current thread -//////////////////////////////////////////////////////////////////////////////// - - protected: - -#ifdef TRI_ENABLE_MAINTAINER_MODE - static thread_local int _numberTrxInScope; -#endif - -//////////////////////////////////////////////////////////////////////////////// -/// @brief the following is for the runtime protection check, number of -/// transaction objects in the current thread that are active (between -/// begin and commit()/abort(). -//////////////////////////////////////////////////////////////////////////////// - -#ifdef TRI_ENABLE_MAINTAINER_MODE - static thread_local int _numberTrxActive; -#endif - - }; - } -} #endif // ----------------------------------------------------------------------------- diff --git a/arangod/Wal/CollectorThread.cpp b/arangod/Wal/CollectorThread.cpp index bbb87422bd..da18d3ae3c 100644 --- a/arangod/Wal/CollectorThread.cpp +++ b/arangod/Wal/CollectorThread.cpp @@ -677,9 +677,6 @@ int CollectorThread::processCollectionOperations (CollectorCache* cache) { TRI_ASSERT(collection != nullptr); - // create a fake transaction while accessing the collection - triagens::arango::TransactionBase trx(true); - TRI_document_collection_t* document = collection->_collection; // first try to read-lock the compactor-lock, afterwards try to write-lock the collection diff --git a/arangod/Wal/DocumentOperation.h b/arangod/Wal/DocumentOperation.h index 115631c1d0..46c6d9659f 100644 --- a/arangod/Wal/DocumentOperation.h +++ b/arangod/Wal/DocumentOperation.h @@ -11,6 +11,10 @@ struct TRI_transaction_collection_s; namespace triagens { + namespace arango { + class Transaction; + } + namespace wal { class Marker; @@ -23,12 +27,14 @@ namespace triagens { REVERTED }; - DocumentOperation (Marker* marker, + DocumentOperation (triagens::arango::Transaction* trx, + Marker* marker, bool freeMarker, TRI_document_collection_t* document, TRI_voc_document_operation_e type, TRI_voc_rid_t rid) - : marker(marker), + : trx(trx), + marker(marker), document(document), header(nullptr), rid(rid), @@ -56,7 +62,7 @@ namespace triagens { } DocumentOperation* swap () { - DocumentOperation* copy = new DocumentOperation(marker, freeMarker, document, type, rid); + DocumentOperation* copy = new DocumentOperation(trx, marker, freeMarker, document, type, rid); copy->tick = tick; copy->header = header; copy->oldHeader = oldHeader; @@ -105,7 +111,7 @@ namespace triagens { } if (status == StatusType::INDEXED || status == StatusType::HANDLED) { - TRI_RollbackOperationDocumentCollection(document, type, header, &oldHeader); + TRI_RollbackOperationDocumentCollection(trx, document, type, header, &oldHeader); } if (type == TRI_VOC_DOCUMENT_OPERATION_INSERT) { @@ -124,6 +130,7 @@ namespace triagens { status = StatusType::REVERTED; } + triagens::arango::Transaction* trx; Marker* marker; TRI_document_collection_t* document; TRI_doc_mptr_t* header; diff --git a/arangod/Wal/RecoverState.cpp b/arangod/Wal/RecoverState.cpp index f106106e10..8b4f641a41 100644 --- a/arangod/Wal/RecoverState.cpp +++ b/arangod/Wal/RecoverState.cpp @@ -33,6 +33,8 @@ #include "Basics/files.h" #include "Basics/Exceptions.h" #include "Basics/memory-map.h" +#include "Utils/SingleCollectionWriteTransaction.h" +#include "Utils/StandaloneTransactionContext.h" #include "VocBase/collection.h" #include "VocBase/replication-applier.h" #include "VocBase/VocShaper.h" @@ -716,11 +718,11 @@ bool RecoverState::ReplayMarker (TRI_df_marker_t const* marker, } TRI_doc_mptr_copy_t mptr; - int res = TRI_InsertShapedJsonDocumentCollection(trx->trxCollection(), (TRI_voc_key_t) key, m->_revisionId, envelope, &mptr, &shaped, nullptr, false, false, true); + int res = TRI_InsertShapedJsonDocumentCollection(trx, trx->trxCollection(), (TRI_voc_key_t) key, m->_revisionId, envelope, &mptr, &shaped, nullptr, false, false, true); if (res == TRI_ERROR_ARANGO_UNIQUE_CONSTRAINT_VIOLATED) { state->policy.setExpectedRevision(m->_revisionId); - res = TRI_UpdateShapedJsonDocumentCollection(trx->trxCollection(), (TRI_voc_key_t) key, m->_revisionId, envelope, &mptr, &shaped, &state->policy, false, false); + res = TRI_UpdateShapedJsonDocumentCollection(trx, trx->trxCollection(), (TRI_voc_key_t) key, m->_revisionId, envelope, &mptr, &shaped, &state->policy, false, false); } return res; @@ -773,11 +775,11 @@ bool RecoverState::ReplayMarker (TRI_df_marker_t const* marker, } TRI_doc_mptr_copy_t mptr; - int res = TRI_InsertShapedJsonDocumentCollection(trx->trxCollection(), (TRI_voc_key_t) key, m->_revisionId, envelope, &mptr, &shaped, &edge, false, false, true); + int res = TRI_InsertShapedJsonDocumentCollection(trx, trx->trxCollection(), (TRI_voc_key_t) key, m->_revisionId, envelope, &mptr, &shaped, &edge, false, false, true); if (res == TRI_ERROR_ARANGO_UNIQUE_CONSTRAINT_VIOLATED) { state->policy.setExpectedRevision(m->_revisionId); - res = TRI_UpdateShapedJsonDocumentCollection(trx->trxCollection(), (TRI_voc_key_t) key, m->_revisionId, envelope, &mptr, &shaped, &state->policy, false, false); + res = TRI_UpdateShapedJsonDocumentCollection(trx, trx->trxCollection(), (TRI_voc_key_t) key, m->_revisionId, envelope, &mptr, &shaped, &state->policy, false, false); } return res; @@ -823,7 +825,7 @@ bool RecoverState::ReplayMarker (TRI_df_marker_t const* marker, // remove the document and ignore any potential errors state->policy.setExpectedRevision(m->_revisionId); - TRI_RemoveShapedJsonDocumentCollection(trx->trxCollection(), (TRI_voc_key_t) key, m->_revisionId, envelope, &state->policy, false, false); + TRI_RemoveShapedJsonDocumentCollection(trx, trx->trxCollection(), (TRI_voc_key_t) key, m->_revisionId, envelope, &state->policy, false, false); return TRI_ERROR_NO_ERROR; }); @@ -1041,9 +1043,6 @@ bool RecoverState::ReplayMarker (TRI_df_marker_t const* marker, return state->canContinue(); } - // fake transaction to satisfy assertions - triagens::arango::TransactionBase trx(true); - std::string collectionDirectory = GetCollectionDirectory(vocbase, collectionId); char* idString = TRI_StringUInt64(indexId); char* indexName = TRI_Concatenate3String("index-", idString, ".json"); @@ -1140,9 +1139,6 @@ bool RecoverState::ReplayMarker (TRI_df_marker_t const* marker, TRI_FromJsonCollectionInfo(&info, json); TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json); - // fake transaction to satisfy assertions - triagens::arango::TransactionBase trx(true); - WaitForDeletion(vocbase, collectionId, TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND); if (state->willBeDropped(collectionId)) { @@ -1225,9 +1221,6 @@ bool RecoverState::ReplayMarker (TRI_df_marker_t const* marker, TRI_vocbase_defaults_t defaults; TRI_GetDatabaseDefaultsServer(state->server, &defaults); - // fake transaction to satisfy assertions - triagens::arango::TransactionBase trx(true); - vocbase = nullptr; WaitForDeletion(state->server, databaseId, TRI_ERROR_ARANGO_DATABASE_NOT_FOUND); int res = TRI_CreateDatabaseServer(state->server, databaseId, nameString.c_str(), &defaults, &vocbase, false); @@ -1269,9 +1262,6 @@ bool RecoverState::ReplayMarker (TRI_df_marker_t const* marker, return true; } - // fake transaction to satisfy assertions - triagens::arango::TransactionBase trx(true); - // ignore any potential error returned by this call TRI_DropIndexDocumentCollection(document, indexId, false); TRI_RemoveFileIndexCollection(document, indexId); @@ -1312,9 +1302,6 @@ bool RecoverState::ReplayMarker (TRI_df_marker_t const* marker, } if (collection != nullptr) { - // fake transaction to satisfy assertions - triagens::arango::TransactionBase trx(true); - int statusCode = TRI_DropCollectionVocBase(vocbase, collection, false); WaitForDeletion(vocbase, collectionId, statusCode); } @@ -1331,9 +1318,6 @@ bool RecoverState::ReplayMarker (TRI_df_marker_t const* marker, TRI_vocbase_t* vocbase = state->releaseDatabase(databaseId); if (vocbase != nullptr) { - // fake transaction to satisfy assertions - triagens::arango::TransactionBase trx(true); - // ignore any potential error returned by this call TRI_DropByIdDatabaseServer(state->server, databaseId, false, false); } @@ -1467,13 +1451,9 @@ int RecoverState::removeEmptyLogfiles () { //////////////////////////////////////////////////////////////////////////////// int RecoverState::fillIndexes () { - // fake transaction to allow populating the secondary indexes - triagens::arango::TransactionBase trx(true); - // release all collections for (auto it = openedCollections.begin(); it != openedCollections.end(); ++it) { TRI_vocbase_col_t* collection = (*it).second; - TRI_document_collection_t* document = collection->_collection; TRI_ASSERT(document != nullptr); @@ -1481,7 +1461,9 @@ int RecoverState::fillIndexes () { // activate secondary indexes document->useSecondaryIndexes(true); - int res = TRI_FillIndexesDocumentCollection(collection, document); + triagens::arango::SingleCollectionWriteTransaction trx(new triagens::arango::StandaloneTransactionContext(), collection->_vocbase, document->_info._cid); + + int res = TRI_FillIndexesDocumentCollection(&trx, collection, document); if (res != TRI_ERROR_NO_ERROR) { return res;