diff --git a/UnitTests/Basics/structure-size-test.cpp b/UnitTests/Basics/structure-size-test.cpp index 414afbdf86..fba767ee3e 100644 --- a/UnitTests/Basics/structure-size-test.cpp +++ b/UnitTests/Basics/structure-size-test.cpp @@ -30,8 +30,8 @@ #define BOOST_TEST_INCLUDED #include +#include "arangod/VocBase/collection.h" #include "arangod/VocBase/datafile.h" -#include "arangod/VocBase/document-collection.h" #include "arangod/Wal/Marker.h" template size_t offsetOf (U T::*member) { diff --git a/arangod/Aql/AqlValue.cpp b/arangod/Aql/AqlValue.cpp index 4cbe00f497..e22413a22b 100644 --- a/arangod/Aql/AqlValue.cpp +++ b/arangod/Aql/AqlValue.cpp @@ -27,7 +27,6 @@ #include "Utils/AqlTransaction.h" #include "V8/v8-conv.h" #include "V8/v8-vpack.h" -#include "VocBase/document-collection.h" #include #include diff --git a/arangod/Aql/AqlValue.h b/arangod/Aql/AqlValue.h index f0cbbc484c..5f3aff246f 100644 --- a/arangod/Aql/AqlValue.h +++ b/arangod/Aql/AqlValue.h @@ -30,7 +30,7 @@ #include "Aql/types.h" #include "Basics/ConditionalDeleter.h" #include "Basics/VelocyPackHelper.h" -#include "VocBase/document-collection.h" +#include "VocBase/collection.h" #include #include diff --git a/arangod/Aql/Collection.cpp b/arangod/Aql/Collection.cpp index 344dc33251..f67bf8b399 100644 --- a/arangod/Aql/Collection.cpp +++ b/arangod/Aql/Collection.cpp @@ -28,7 +28,7 @@ #include "Cluster/ClusterInfo.h" #include "Cluster/ClusterMethods.h" #include "Cluster/ServerState.h" -#include "VocBase/document-collection.h" +#include "VocBase/collection.h" #include "VocBase/transaction.h" #include "VocBase/vocbase.h" @@ -55,7 +55,7 @@ Collection::Collection(std::string const& name, TRI_vocbase_t* vocbase, Collection::~Collection() {} /// @brief get the pointer to the document collection -TRI_document_collection_t* Collection::documentCollection() const { +TRI_collection_t* Collection::documentCollection() const { TRI_ASSERT(collection != nullptr); TRI_ASSERT(collection->_collection != nullptr); diff --git a/arangod/Aql/Collection.h b/arangod/Aql/Collection.h index 4be88fb238..6b57d5ac52 100644 --- a/arangod/Aql/Collection.h +++ b/arangod/Aql/Collection.h @@ -28,7 +28,7 @@ #include "VocBase/transaction.h" #include "VocBase/vocbase.h" -struct TRI_document_collection_t; +struct TRI_collection_t; namespace arangodb { namespace aql { @@ -71,7 +71,7 @@ struct Collection { } /// @brief get the pointer to the document collection - TRI_document_collection_t* documentCollection() const; + TRI_collection_t* documentCollection() const; /// @brief count the LOCAL number of documents in the collection size_t count() const; diff --git a/arangod/CMakeLists.txt b/arangod/CMakeLists.txt index 4b3dea4dd0..7bf904f89d 100644 --- a/arangod/CMakeLists.txt +++ b/arangod/CMakeLists.txt @@ -322,7 +322,6 @@ add_executable(${BIN_ARANGOD} VocBase/collection.cpp VocBase/compactor.cpp VocBase/datafile.cpp - VocBase/document-collection.cpp VocBase/modes.cpp VocBase/replication-applier.cpp VocBase/replication-common.cpp diff --git a/arangod/Cluster/ClusterInfo.cpp b/arangod/Cluster/ClusterInfo.cpp index 7ec487ecf8..2d2fd91139 100644 --- a/arangod/Cluster/ClusterInfo.cpp +++ b/arangod/Cluster/ClusterInfo.cpp @@ -41,7 +41,7 @@ #include "Cluster/ServerState.h" #include "Logger/Logger.h" #include "Rest/HttpResponse.h" -#include "VocBase/document-collection.h" +#include "VocBase/collection.h" #ifdef _WIN32 // turn off warnings about too long type name for debug symbols blabla in MSVC diff --git a/arangod/Cluster/ClusterMethods.h b/arangod/Cluster/ClusterMethods.h index 7d21d9fefe..bbc79ca1b0 100644 --- a/arangod/Cluster/ClusterMethods.h +++ b/arangod/Cluster/ClusterMethods.h @@ -27,7 +27,7 @@ #include "Basics/Common.h" #include "Cluster/AgencyComm.h" #include "Rest/HttpResponse.h" -#include "VocBase/document-collection.h" +#include "VocBase/collection.h" #include "VocBase/voc-types.h" #include diff --git a/arangod/Indexes/EdgeIndex.cpp b/arangod/Indexes/EdgeIndex.cpp index 7f42aafbe8..4f7984ba05 100644 --- a/arangod/Indexes/EdgeIndex.cpp +++ b/arangod/Indexes/EdgeIndex.cpp @@ -32,7 +32,7 @@ #include "Utils/CollectionNameResolver.h" #include "Utils/Transaction.h" #include "Utils/TransactionContext.h" -#include "VocBase/document-collection.h" +#include "VocBase/collection.h" #include "VocBase/transaction.h" #include diff --git a/arangod/Indexes/FulltextIndex.cpp b/arangod/Indexes/FulltextIndex.cpp index 07d660a7ef..237eb82737 100644 --- a/arangod/Indexes/FulltextIndex.cpp +++ b/arangod/Indexes/FulltextIndex.cpp @@ -25,7 +25,7 @@ #include "Logger/Logger.h" #include "Basics/Utf8Helper.h" #include "FulltextIndex/fulltext-index.h" -#include "VocBase/document-collection.h" +#include "VocBase/collection.h" #include "VocBase/transaction.h" #include diff --git a/arangod/Indexes/GeoIndex2.cpp b/arangod/Indexes/GeoIndex2.cpp index b5a3d8a8d7..a0171ccdfc 100644 --- a/arangod/Indexes/GeoIndex2.cpp +++ b/arangod/Indexes/GeoIndex2.cpp @@ -23,7 +23,7 @@ #include "GeoIndex2.h" #include "Logger/Logger.h" -#include "VocBase/document-collection.h" +#include "VocBase/collection.h" #include "VocBase/transaction.h" using namespace arangodb; diff --git a/arangod/Indexes/HashIndex.cpp b/arangod/Indexes/HashIndex.cpp index a7a776aa2d..58e36fefad 100644 --- a/arangod/Indexes/HashIndex.cpp +++ b/arangod/Indexes/HashIndex.cpp @@ -29,7 +29,7 @@ #include "Basics/VelocyPackHelper.h" #include "Indexes/SimpleAttributeEqualityMatcher.h" #include "Utils/TransactionContext.h" -#include "VocBase/document-collection.h" +#include "VocBase/collection.h" #include "VocBase/transaction.h" #include diff --git a/arangod/Indexes/Index.cpp b/arangod/Indexes/Index.cpp index cdfaf9a7f9..492a6407d0 100644 --- a/arangod/Indexes/Index.cpp +++ b/arangod/Indexes/Index.cpp @@ -28,7 +28,7 @@ #include "Basics/Exceptions.h" #include "Basics/VelocyPackHelper.h" #include "Basics/StringUtils.h" -#include "VocBase/document-collection.h" +#include "VocBase/collection.h" #include "VocBase/ticks.h" #include diff --git a/arangod/Indexes/PrimaryIndex.cpp b/arangod/Indexes/PrimaryIndex.cpp index a161a59205..f54aac90d6 100644 --- a/arangod/Indexes/PrimaryIndex.cpp +++ b/arangod/Indexes/PrimaryIndex.cpp @@ -30,7 +30,7 @@ #include "Indexes/SimpleAttributeEqualityMatcher.h" #include "Utils/Transaction.h" #include "Utils/TransactionContext.h" -#include "VocBase/document-collection.h" +#include "VocBase/collection.h" #include "VocBase/transaction.h" #include diff --git a/arangod/Indexes/RocksDBIndex.cpp b/arangod/Indexes/RocksDBIndex.cpp index ea9e6609ad..c60a1372ec 100644 --- a/arangod/Indexes/RocksDBIndex.cpp +++ b/arangod/Indexes/RocksDBIndex.cpp @@ -31,7 +31,7 @@ #include "Indexes/RocksDBFeature.h" #include "Indexes/RocksDBKeyComparator.h" #include "Utils/Transaction.h" -#include "VocBase/document-collection.h" +#include "VocBase/collection.h" #include #include diff --git a/arangod/Indexes/SkiplistIndex.cpp b/arangod/Indexes/SkiplistIndex.cpp index 32955f0bd2..566afb851d 100644 --- a/arangod/Indexes/SkiplistIndex.cpp +++ b/arangod/Indexes/SkiplistIndex.cpp @@ -29,7 +29,7 @@ #include "Basics/debugging.h" #include "Basics/VelocyPackHelper.h" #include "Utils/Transaction.h" -#include "VocBase/document-collection.h" +#include "VocBase/collection.h" #include #include diff --git a/arangod/Replication/ContinuousSyncer.cpp b/arangod/Replication/ContinuousSyncer.cpp index c6fc4ebf07..72e58893a6 100644 --- a/arangod/Replication/ContinuousSyncer.cpp +++ b/arangod/Replication/ContinuousSyncer.cpp @@ -36,7 +36,7 @@ #include "SimpleHttpClient/SimpleHttpResult.h" #include "Utils/CollectionGuard.h" #include "Utils/SingleCollectionTransaction.h" -#include "VocBase/document-collection.h" +#include "VocBase/collection.h" #include "VocBase/transaction.h" #include "VocBase/vocbase.h" #include "VocBase/voc-types.h" diff --git a/arangod/Replication/InitialSyncer.cpp b/arangod/Replication/InitialSyncer.cpp index 245d7ced6f..45ea4500e5 100644 --- a/arangod/Replication/InitialSyncer.cpp +++ b/arangod/Replication/InitialSyncer.cpp @@ -36,7 +36,7 @@ #include "SimpleHttpClient/SimpleHttpResult.h" #include "Utils/CollectionGuard.h" #include "VocBase/DatafileHelper.h" -#include "VocBase/document-collection.h" +#include "VocBase/collection.h" #include "VocBase/vocbase.h" #include "VocBase/voc-types.h" @@ -1031,7 +1031,7 @@ int InitialSyncer::handleSyncKeys(TRI_vocbase_col_t* col, // fetch all local keys from primary index std::vector markers; - TRI_document_collection_t* document = nullptr; + TRI_collection_t* document = nullptr; DocumentDitch* ditch = nullptr; // acquire a replication ditch so no datafiles are thrown away from now on @@ -1849,7 +1849,7 @@ int InitialSyncer::handleCollection(VPackSlice const& parameters, trx.orderDitch(col->_cid); // will throw when it fails - TRI_document_collection_t* document = trx.documentCollection(); + TRI_collection_t* document = trx.documentCollection(); TRI_ASSERT(document != nullptr); for (auto const& idxDef : VPackArrayIterator(indexes)) { diff --git a/arangod/Replication/Syncer.cpp b/arangod/Replication/Syncer.cpp index 3aef4dbf3c..eaaa722d39 100644 --- a/arangod/Replication/Syncer.cpp +++ b/arangod/Replication/Syncer.cpp @@ -34,7 +34,6 @@ #include "Utils/OperationResult.h" #include "Utils/SingleCollectionTransaction.h" #include "VocBase/collection.h" -#include "VocBase/document-collection.h" #include "VocBase/transaction.h" #include "VocBase/vocbase.h" #include "VocBase/voc-types.h" @@ -558,7 +557,7 @@ int Syncer::createIndex(VPackSlice const& slice) { return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND; } - TRI_document_collection_t* document = guard.collection()->_collection; + TRI_collection_t* document = guard.collection()->_collection; SingleCollectionTransaction trx(StandaloneTransactionContext::Create(_vocbase), guard.collection()->_cid, TRI_TRANSACTION_WRITE); @@ -616,7 +615,7 @@ int Syncer::dropIndex(arangodb::velocypack::Slice const& slice) { return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND; } - TRI_document_collection_t* document = guard.collection()->_collection; + TRI_collection_t* document = guard.collection()->_collection; bool result = document->dropIndex(iid, true); diff --git a/arangod/RestHandler/RestDocumentHandler.cpp b/arangod/RestHandler/RestDocumentHandler.cpp index 885a87941b..7fabc342ec 100644 --- a/arangod/RestHandler/RestDocumentHandler.cpp +++ b/arangod/RestHandler/RestDocumentHandler.cpp @@ -29,7 +29,7 @@ #include "Rest/HttpRequest.h" #include "Utils/SingleCollectionTransaction.h" #include "Utils/StandaloneTransactionContext.h" -#include "VocBase/document-collection.h" +#include "VocBase/collection.h" #include "VocBase/vocbase.h" using namespace arangodb; diff --git a/arangod/RestHandler/RestQueryHandler.cpp b/arangod/RestHandler/RestQueryHandler.cpp index 96dd4b310b..ad82503b41 100644 --- a/arangod/RestHandler/RestQueryHandler.cpp +++ b/arangod/RestHandler/RestQueryHandler.cpp @@ -36,7 +36,7 @@ #include "Cluster/ClusterMethods.h" #include "Cluster/ServerState.h" #include "Rest/HttpRequest.h" -#include "VocBase/document-collection.h" +#include "VocBase/collection.h" #include "VocBase/vocbase.h" using namespace arangodb; diff --git a/arangod/RestHandler/RestReplicationHandler.cpp b/arangod/RestHandler/RestReplicationHandler.cpp index 1d5572455b..37043bfc4a 100644 --- a/arangod/RestHandler/RestReplicationHandler.cpp +++ b/arangod/RestHandler/RestReplicationHandler.cpp @@ -1775,7 +1775,7 @@ int RestReplicationHandler::processRestoreCollectionCoordinator( // create a dummy primary index { - TRI_document_collection_t* doc = nullptr; + TRI_collection_t* doc = nullptr; std::unique_ptr primaryIndex( new arangodb::PrimaryIndex(doc)); toMerge.openObject(); @@ -1882,7 +1882,7 @@ int RestReplicationHandler::processRestoreIndexes(VPackSlice const& collection, try { CollectionGuard guard(_vocbase, name.c_str()); - TRI_document_collection_t* document = guard.collection()->_collection; + TRI_collection_t* document = guard.collection()->_collection; SingleCollectionTransaction trx( StandaloneTransactionContext::Create(_vocbase), document->_info.id(), @@ -3858,7 +3858,7 @@ void RestReplicationHandler::handleCommandAddFollower() { return; } - TRI_document_collection_t* docColl = col->_collection; + TRI_collection_t* docColl = col->_collection; if (docColl == nullptr) { generateError(GeneralResponse::ResponseCode::SERVER_ERROR, TRI_ERROR_ARANGO_COLLECTION_NOT_LOADED, @@ -3915,7 +3915,7 @@ void RestReplicationHandler::handleCommandRemoveFollower() { return; } - TRI_document_collection_t* docColl = col->_collection; + TRI_collection_t* docColl = col->_collection; if (docColl == nullptr) { generateError(GeneralResponse::ResponseCode::SERVER_ERROR, TRI_ERROR_ARANGO_COLLECTION_NOT_LOADED, @@ -3989,7 +3989,7 @@ void RestReplicationHandler::handleCommandHoldReadLockCollection() { } } - TRI_document_collection_t* docColl = col->_collection; + TRI_collection_t* docColl = col->_collection; if (docColl == nullptr) { generateError(GeneralResponse::ResponseCode::SERVER_ERROR, TRI_ERROR_ARANGO_COLLECTION_NOT_LOADED, diff --git a/arangod/RestHandler/RestVocbaseBaseHandler.cpp b/arangod/RestHandler/RestVocbaseBaseHandler.cpp index 3de2e40399..7f659efd1a 100644 --- a/arangod/RestHandler/RestVocbaseBaseHandler.cpp +++ b/arangod/RestHandler/RestVocbaseBaseHandler.cpp @@ -33,7 +33,7 @@ #include "Rest/HttpRequest.h" #include "Utils/StandaloneTransactionContext.h" #include "Utils/Transaction.h" -#include "VocBase/document-collection.h" +#include "VocBase/collection.h" #include #include diff --git a/arangod/RestServer/CheckVersionFeature.cpp b/arangod/RestServer/CheckVersionFeature.cpp index a62c48ffe0..c24a80ba54 100644 --- a/arangod/RestServer/CheckVersionFeature.cpp +++ b/arangod/RestServer/CheckVersionFeature.cpp @@ -30,6 +30,7 @@ #include "V8Server/V8DealerFeature.h" #include "V8Server/v8-query.h" #include "V8Server/v8-vocbase.h" +#include "VocBase/vocbase.h" using namespace arangodb; using namespace arangodb::application_features; diff --git a/arangod/Utils/AqlTransaction.h b/arangod/Utils/AqlTransaction.h index 2470136eca..fe85e86add 100644 --- a/arangod/Utils/AqlTransaction.h +++ b/arangod/Utils/AqlTransaction.h @@ -112,7 +112,7 @@ class AqlTransaction : public Transaction { /// @brief documentCollection ////////////////////////////////////////////////////////////////////////////// - TRI_document_collection_t* documentCollection(TRI_voc_cid_t cid) { + TRI_collection_t* documentCollection(TRI_voc_cid_t cid) { TRI_transaction_collection_t* trxColl = this->trxCollection(cid); TRI_ASSERT(trxColl != nullptr); return trxColl->_collection->_collection; diff --git a/arangod/Utils/CollectionExport.cpp b/arangod/Utils/CollectionExport.cpp index 839e57c2b0..cfddb92dfc 100644 --- a/arangod/Utils/CollectionExport.cpp +++ b/arangod/Utils/CollectionExport.cpp @@ -29,7 +29,7 @@ #include "Utils/StandaloneTransactionContext.h" #include "VocBase/compactor.h" #include "VocBase/Ditch.h" -#include "VocBase/document-collection.h" +#include "VocBase/collection.h" #include "VocBase/vocbase.h" using namespace arangodb; diff --git a/arangod/Utils/CollectionExport.h b/arangod/Utils/CollectionExport.h index 7a88e75c05..46dc5ec188 100644 --- a/arangod/Utils/CollectionExport.h +++ b/arangod/Utils/CollectionExport.h @@ -28,7 +28,7 @@ #include "Utils/CollectionNameResolver.h" #include "VocBase/voc-types.h" -struct TRI_document_collection_t; +struct TRI_collection_t; struct TRI_vocbase_t; namespace arangodb { @@ -62,7 +62,7 @@ class CollectionExport { private: arangodb::CollectionGuard* _guard; - struct TRI_document_collection_t* _document; + struct TRI_collection_t* _document; arangodb::DocumentDitch* _ditch; std::string const _name; arangodb::CollectionNameResolver _resolver; diff --git a/arangod/Utils/CollectionKeys.cpp b/arangod/Utils/CollectionKeys.cpp index ade440dade..faea12aa80 100644 --- a/arangod/Utils/CollectionKeys.cpp +++ b/arangod/Utils/CollectionKeys.cpp @@ -30,7 +30,7 @@ #include "VocBase/compactor.h" #include "VocBase/DatafileHelper.h" #include "VocBase/Ditch.h" -#include "VocBase/document-collection.h" +#include "VocBase/collection.h" #include "VocBase/ticks.h" #include "VocBase/vocbase.h" #include "Wal/LogfileManager.h" diff --git a/arangod/Utils/CollectionKeys.h b/arangod/Utils/CollectionKeys.h index 5470be2a81..0b95b94a2a 100644 --- a/arangod/Utils/CollectionKeys.h +++ b/arangod/Utils/CollectionKeys.h @@ -33,7 +33,7 @@ #include struct TRI_df_marker_t; -struct TRI_document_collection_t; +struct TRI_collection_t; struct TRI_vocbase_t; namespace arangodb { @@ -116,7 +116,7 @@ class CollectionKeys { private: struct TRI_vocbase_t* _vocbase; arangodb::CollectionGuard* _guard; - struct TRI_document_collection_t* _document; + struct TRI_collection_t* _document; arangodb::DocumentDitch* _ditch; std::string const _name; arangodb::CollectionNameResolver _resolver; diff --git a/arangod/Utils/Cursor.cpp b/arangod/Utils/Cursor.cpp index 5d8a03f9d2..76c7b5e94b 100644 --- a/arangod/Utils/Cursor.cpp +++ b/arangod/Utils/Cursor.cpp @@ -29,7 +29,7 @@ #include "Utils/CollectionNameResolver.h" #include "Utils/StandaloneTransactionContext.h" #include "Utils/TransactionContext.h" -#include "VocBase/document-collection.h" +#include "VocBase/collection.h" #include "VocBase/vocbase.h" #include diff --git a/arangod/Utils/SingleCollectionTransaction.cpp b/arangod/Utils/SingleCollectionTransaction.cpp index c782bf89e0..70abc71e7f 100644 --- a/arangod/Utils/SingleCollectionTransaction.cpp +++ b/arangod/Utils/SingleCollectionTransaction.cpp @@ -26,7 +26,7 @@ #include "Utils/Transaction.h" #include "Utils/TransactionContext.h" #include "VocBase/Ditch.h" -#include "VocBase/document-collection.h" +#include "VocBase/collection.h" #include "VocBase/transaction.h" using namespace arangodb; @@ -97,7 +97,7 @@ TRI_transaction_collection_t* SingleCollectionTransaction::trxCollection() { /// in two different situations //////////////////////////////////////////////////////////////////////////////// -TRI_document_collection_t* SingleCollectionTransaction::documentCollection() { +TRI_collection_t* SingleCollectionTransaction::documentCollection() { if (_documentCollection != nullptr) { return _documentCollection; } diff --git a/arangod/Utils/SingleCollectionTransaction.h b/arangod/Utils/SingleCollectionTransaction.h index 00f32df980..0c9a5fbf64 100644 --- a/arangod/Utils/SingleCollectionTransaction.h +++ b/arangod/Utils/SingleCollectionTransaction.h @@ -70,7 +70,7 @@ class SingleCollectionTransaction : public Transaction { /// in two different situations ////////////////////////////////////////////////////////////////////////////// - TRI_document_collection_t* documentCollection(); + TRI_collection_t* documentCollection(); ////////////////////////////////////////////////////////////////////////////// /// @brief get the underlying collection's id @@ -133,10 +133,10 @@ class SingleCollectionTransaction : public Transaction { TRI_transaction_collection_t* _trxCollection; ////////////////////////////////////////////////////////////////////////////// - /// @brief TRI_document_collection_t* cache + /// @brief TRI_collection_t* cache ////////////////////////////////////////////////////////////////////////////// - TRI_document_collection_t* _documentCollection; + TRI_collection_t* _documentCollection; ////////////////////////////////////////////////////////////////////////////// /// @brief collection access type diff --git a/arangod/Utils/Transaction.cpp b/arangod/Utils/Transaction.cpp index 0df22b0c6c..62116a6c9f 100644 --- a/arangod/Utils/Transaction.cpp +++ b/arangod/Utils/Transaction.cpp @@ -46,9 +46,9 @@ #include "Utils/TransactionContext.h" #include "VocBase/DatafileHelper.h" #include "VocBase/Ditch.h" -#include "VocBase/document-collection.h" #include "VocBase/KeyGenerator.h" #include "VocBase/MasterPointers.h" +#include "VocBase/collection.h" #include "VocBase/ticks.h" #include "Wal/LogfileManager.h" @@ -588,7 +588,7 @@ DocumentDitch* Transaction::orderDitch(TRI_voc_cid_t cid) { TRI_ASSERT(trxCollection->_collection != nullptr); - TRI_document_collection_t* document = + TRI_collection_t* document = trxCollection->_collection->_collection; TRI_ASSERT(document != nullptr); @@ -951,7 +951,7 @@ void Transaction::extractKeyAndRevFromDocument(VPackSlice slice, /// added to the builder in the argument as a single object. ////////////////////////////////////////////////////////////////////////////// -void Transaction::buildDocumentIdentity(TRI_document_collection_t* document, +void Transaction::buildDocumentIdentity(TRI_collection_t* document, VPackBuilder& builder, TRI_voc_cid_t cid, StringRef const& key, @@ -1242,7 +1242,7 @@ void Transaction::invokeOnAllElements(std::string const& collectionName, TRI_voc_cid_t cid = addCollectionAtRuntime(collectionName); TRI_transaction_collection_t* trxCol = trxCollection(cid); - TRI_document_collection_t* document = documentCollection(trxCol); + TRI_collection_t* document = documentCollection(trxCol); orderDitch(cid); // will throw when it fails @@ -1293,7 +1293,7 @@ int Transaction::documentFastPath(std::string const& collectionName, } TRI_voc_cid_t cid = addCollectionAtRuntime(collectionName); - TRI_document_collection_t* document = documentCollection(trxCollection(cid)); + TRI_collection_t* document = documentCollection(trxCollection(cid)); orderDitch(cid); // will throw when it fails @@ -1331,7 +1331,7 @@ int Transaction::documentFastPathLocal(std::string const& collectionName, TRI_ASSERT(getStatus() == TRI_TRANSACTION_RUNNING); TRI_voc_cid_t cid = addCollectionAtRuntime(collectionName); - TRI_document_collection_t* document = documentCollection(trxCollection(cid)); + TRI_collection_t* document = documentCollection(trxCollection(cid)); orderDitch(cid); // will throw when it fails @@ -1416,7 +1416,7 @@ OperationResult Transaction::documentLocal(std::string const& collectionName, OperationOptions& options) { TIMER_START(TRANSACTION_DOCUMENT_LOCAL); TRI_voc_cid_t cid = addCollectionAtRuntime(collectionName); - TRI_document_collection_t* document = documentCollection(trxCollection(cid)); + TRI_collection_t* document = documentCollection(trxCollection(cid)); if (!options.silent) { orderDitch(cid); // will throw when it fails @@ -1575,7 +1575,7 @@ OperationResult Transaction::insertLocal(std::string const& collectionName, OperationOptions& options) { TIMER_START(TRANSACTION_INSERT_LOCAL); TRI_voc_cid_t cid = addCollectionAtRuntime(collectionName); - TRI_document_collection_t* document = documentCollection(trxCollection(cid)); + TRI_collection_t* document = documentCollection(trxCollection(cid)); // First see whether or not we have to do synchronous replication: std::shared_ptr const> followers; @@ -1919,7 +1919,7 @@ OperationResult Transaction::modifyLocal( TRI_voc_document_operation_e operation) { TRI_voc_cid_t cid = addCollectionAtRuntime(collectionName); - TRI_document_collection_t* document = documentCollection(trxCollection(cid)); + TRI_collection_t* document = documentCollection(trxCollection(cid)); if (options.returnOld || options.returnNew) { orderDitch(cid); // will throw when it fails @@ -2187,7 +2187,7 @@ OperationResult Transaction::removeLocal(std::string const& collectionName, VPackSlice const value, OperationOptions& options) { TRI_voc_cid_t cid = addCollectionAtRuntime(collectionName); - TRI_document_collection_t* document = documentCollection(trxCollection(cid)); + TRI_collection_t* document = documentCollection(trxCollection(cid)); if (options.returnOld) { orderDitch(cid); // will throw when it fails @@ -2494,7 +2494,7 @@ OperationResult Transaction::truncateLocal(std::string const& collectionName, return OperationResult(res); } - TRI_document_collection_t* document = documentCollection(trxCollection(cid)); + TRI_collection_t* document = documentCollection(trxCollection(cid)); VPackBuilder keyBuilder; auto primaryIndex = document->primaryIndex(); @@ -2629,7 +2629,7 @@ OperationResult Transaction::countLocal(std::string const& collectionName) { return OperationResult(res); } - TRI_document_collection_t* document = documentCollection(trxCollection(cid)); + TRI_collection_t* document = documentCollection(trxCollection(cid)); uint64_t num = document->_numberDocuments; @@ -2867,7 +2867,7 @@ std::unique_ptr Transaction::indexScan( } TRI_voc_cid_t cid = addCollectionAtRuntime(collectionName); - TRI_document_collection_t* document = documentCollection(trxCollection(cid)); + TRI_collection_t* document = documentCollection(trxCollection(cid)); orderDitch(cid); // will throw when it fails @@ -2938,7 +2938,7 @@ std::unique_ptr Transaction::indexScan( /// @brief return the collection //////////////////////////////////////////////////////////////////////////////// -TRI_document_collection_t* Transaction::documentCollection( +TRI_collection_t* Transaction::documentCollection( TRI_transaction_collection_t const* trxCollection) const { TRI_ASSERT(_trx != nullptr); TRI_ASSERT(trxCollection != nullptr); @@ -2953,7 +2953,7 @@ TRI_document_collection_t* Transaction::documentCollection( /// @brief return the collection //////////////////////////////////////////////////////////////////////////////// -TRI_document_collection_t* Transaction::documentCollection( +TRI_collection_t* Transaction::documentCollection( TRI_voc_cid_t cid) const { TRI_ASSERT(_trx != nullptr); TRI_ASSERT(getStatus() == TRI_TRANSACTION_RUNNING); @@ -3039,7 +3039,7 @@ int Transaction::addCollection(std::string const& name, TRI_transaction_type_e t /// @brief test if a collection is already locked //////////////////////////////////////////////////////////////////////////////// -bool Transaction::isLocked(TRI_document_collection_t* document, +bool Transaction::isLocked(TRI_collection_t* document, TRI_transaction_type_e type) { if (_trx == nullptr || getStatus() != TRI_TRANSACTION_RUNNING) { return false; @@ -3090,7 +3090,7 @@ std::vector> Transaction::indexesForCollection( // For a DBserver we use the local case. TRI_voc_cid_t cid = addCollectionAtRuntime(collectionName); - TRI_document_collection_t* document = documentCollection(trxCollection(cid)); + TRI_collection_t* document = documentCollection(trxCollection(cid)); // Wrap fake shared pointers around the raw pointers: std::shared_ptr dummy; @@ -3256,7 +3256,7 @@ Transaction::IndexHandle Transaction::getIndexByIdentifier( } TRI_voc_cid_t cid = addCollectionAtRuntime(collectionName); - TRI_document_collection_t* document = documentCollection(trxCollection(cid)); + TRI_collection_t* document = documentCollection(trxCollection(cid)); if (indexHandle.empty()) { THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_BAD_PARAMETER, diff --git a/arangod/Utils/Transaction.h b/arangod/Utils/Transaction.h index 9ab61352b3..18a256ca1d 100644 --- a/arangod/Utils/Transaction.h +++ b/arangod/Utils/Transaction.h @@ -42,7 +42,7 @@ class Transaction; } #endif -struct TRI_document_collection_t; +struct TRI_collection_t; namespace arangodb { @@ -602,7 +602,7 @@ class Transaction { /// @brief test if a collection is already locked ////////////////////////////////////////////////////////////////////////////// - bool isLocked(TRI_document_collection_t*, TRI_transaction_type_e); + bool isLocked(TRI_collection_t*, TRI_transaction_type_e); ////////////////////////////////////////////////////////////////////////////// /// @brief return the setup state @@ -610,7 +610,7 @@ class Transaction { int setupState() { return _setupState; } - TRI_document_collection_t* documentCollection(TRI_voc_cid_t) const; + TRI_collection_t* documentCollection(TRI_voc_cid_t) const; ////////////////////////////////////////////////////////////////////////////// /// @brief get the index by it's identifier. Will either throw or @@ -643,7 +643,7 @@ class Transaction { /// argument as a single object. ////////////////////////////////////////////////////////////////////////////// - void buildDocumentIdentity(TRI_document_collection_t* document, + void buildDocumentIdentity(TRI_collection_t* document, VPackBuilder& builder, TRI_voc_cid_t cid, StringRef const& key, @@ -724,7 +724,7 @@ class Transaction { /// @brief return the collection ////////////////////////////////////////////////////////////////////////////// - TRI_document_collection_t* documentCollection( + TRI_collection_t* documentCollection( TRI_transaction_collection_t const*) const; ////////////////////////////////////////////////////////////////////////////// diff --git a/arangod/Utils/TransactionContext.cpp b/arangod/Utils/TransactionContext.cpp index fc24cc0a7d..f29e515f4c 100644 --- a/arangod/Utils/TransactionContext.cpp +++ b/arangod/Utils/TransactionContext.cpp @@ -27,7 +27,7 @@ #include "Utils/Transaction.h" #include "VocBase/DatafileHelper.h" #include "VocBase/Ditch.h" -#include "VocBase/document-collection.h" +#include "VocBase/collection.h" #include "Wal/LogfileManager.h" #include @@ -120,7 +120,7 @@ VPackCustomTypeHandler* TransactionContext::createCustomTypeHandler(TRI_vocbase_ /// function will return a nullptr! ////////////////////////////////////////////////////////////////////////////// -DocumentDitch* TransactionContext::orderDitch(TRI_document_collection_t* document) { +DocumentDitch* TransactionContext::orderDitch(TRI_collection_t* document) { TRI_voc_cid_t cid = document->_info.id(); auto it = _ditches.find(cid); diff --git a/arangod/Utils/TransactionContext.h b/arangod/Utils/TransactionContext.h index a480471646..561882d508 100644 --- a/arangod/Utils/TransactionContext.h +++ b/arangod/Utils/TransactionContext.h @@ -30,7 +30,7 @@ #include -struct TRI_document_collection_t; +struct TRI_collection_t; struct TRI_transaction_t; struct TRI_vocbase_t; @@ -88,7 +88,7 @@ class TransactionContext { /// function will return a nullptr! ////////////////////////////////////////////////////////////////////////////// - DocumentDitch* orderDitch(TRI_document_collection_t*); + DocumentDitch* orderDitch(TRI_collection_t*); ////////////////////////////////////////////////////////////////////////////// /// @brief return the ditch for a collection diff --git a/arangod/V8Server/V8Traverser.cpp b/arangod/V8Server/V8Traverser.cpp index a73b7b0614..b969f19304 100644 --- a/arangod/V8Server/V8Traverser.cpp +++ b/arangod/V8Server/V8Traverser.cpp @@ -23,7 +23,7 @@ #include "V8Traverser.h" #include "VocBase/SingleServerTraverser.h" -#include "VocBase/document-collection.h" +#include "VocBase/collection.h" #include #include diff --git a/arangod/V8Server/v8-collection.cpp b/arangod/V8Server/v8-collection.cpp index c47f631dcd..40f29600a5 100644 --- a/arangod/V8Server/v8-collection.cpp +++ b/arangod/V8Server/v8-collection.cpp @@ -952,7 +952,7 @@ static TRI_doc_collection_info_t* GetFigures(TRI_vocbase_col_t* collection) { // READ-LOCK start trx.lockRead(); - TRI_document_collection_t* document = collection->_collection; + TRI_collection_t* document = collection->_collection; TRI_doc_collection_info_t* info = document->figures(); trx.finish(res); @@ -1111,7 +1111,7 @@ static void JS_LeaderResign(v8::FunctionCallbackInfo const& args) { if (res != TRI_ERROR_NO_ERROR) { TRI_V8_THROW_EXCEPTION(res); } - TRI_document_collection_t* docColl = trx.documentCollection(); + TRI_collection_t* docColl = trx.documentCollection(); docColl->followers()->clear(); } @@ -1364,7 +1364,7 @@ static void JS_PropertiesVocbaseCol( return; } - TRI_document_collection_t* document = collection->_collection; + TRI_collection_t* document = collection->_collection; // check if we want to change some parameters if (0 < args.Length()) { @@ -2056,7 +2056,7 @@ static void JS_RotateVocbaseCol( TRI_THROW_SHARDING_COLLECTION_NOT_YET_IMPLEMENTED(collection); - TRI_document_collection_t* document = collection->_collection; + TRI_collection_t* document = collection->_collection; int res = document->rotateActiveJournal(); diff --git a/arangod/V8Server/v8-query.cpp b/arangod/V8Server/v8-query.cpp index c0a758cba1..af8f35249f 100644 --- a/arangod/V8Server/v8-query.cpp +++ b/arangod/V8Server/v8-query.cpp @@ -36,7 +36,7 @@ #include "V8/v8-vpack.h" #include "V8Server/v8-vocbase.h" #include "V8Server/v8-vocindex.h" -#include "VocBase/document-collection.h" +#include "VocBase/collection.h" #include "VocBase/vocbase.h" #include @@ -365,7 +365,7 @@ static void JS_ChecksumCollection( trx.orderDitch(col->_cid); // will throw when it fails // get last tick - TRI_document_collection_t* document = trx.documentCollection(); + TRI_collection_t* document = trx.documentCollection(); std::string const revisionId = std::to_string(document->_info.revision()); uint64_t hash = 0; diff --git a/arangod/V8Server/v8-util.cpp b/arangod/V8Server/v8-util.cpp index 25e47dff72..c46f030969 100644 --- a/arangod/V8Server/v8-util.cpp +++ b/arangod/V8Server/v8-util.cpp @@ -23,6 +23,7 @@ #include "v8-vocbaseprivate.h" #include "Basics/conversions.h" +#include "Basics/StaticStrings.h" #include "VocBase/KeyGenerator.h" #include "V8/v8-conv.h" diff --git a/arangod/V8Server/v8-vocbase.cpp b/arangod/V8Server/v8-vocbase.cpp index f10308aa71..9e50c7e120 100644 --- a/arangod/V8Server/v8-vocbase.cpp +++ b/arangod/V8Server/v8-vocbase.cpp @@ -105,10 +105,10 @@ int32_t const WRP_VOCBASE_COL_TYPE = 2; struct CollectionDitchInfo { arangodb::DocumentDitch* ditch; - TRI_document_collection_t* col; + TRI_collection_t* col; CollectionDitchInfo(arangodb::DocumentDitch* ditch, - TRI_document_collection_t* col) + TRI_collection_t* col) : ditch(ditch), col(col) {} }; diff --git a/arangod/V8Server/v8-vocbase.h b/arangod/V8Server/v8-vocbase.h index 0b88c7b5bc..a54c686128 100644 --- a/arangod/V8Server/v8-vocbase.h +++ b/arangod/V8Server/v8-vocbase.h @@ -26,7 +26,6 @@ #include "Basics/Common.h" #include "V8/v8-globals.h" -#include "VocBase/document-collection.h" struct TRI_vocbase_t; diff --git a/arangod/V8Server/v8-vocbaseprivate.h b/arangod/V8Server/v8-vocbaseprivate.h index 6e3d6586fe..750545f75a 100644 --- a/arangod/V8Server/v8-vocbaseprivate.h +++ b/arangod/V8Server/v8-vocbaseprivate.h @@ -26,7 +26,10 @@ #include "Basics/Common.h" #include "V8/v8-utils.h" -#include "v8-vocbase.h" +#include "V8Server/v8-vocbase.h" +#include "VocBase/voc-types.h" + +#include //////////////////////////////////////////////////////////////////////////////// /// @brief wrapped class for TRI_vocbase_t diff --git a/arangod/V8Server/v8-vocindex.cpp b/arangod/V8Server/v8-vocindex.cpp index 42bc27e837..13772d2247 100644 --- a/arangod/V8Server/v8-vocindex.cpp +++ b/arangod/V8Server/v8-vocindex.cpp @@ -590,7 +590,7 @@ static void EnsureIndexLocal(v8::FunctionCallbackInfo const& args, TRI_V8_THROW_EXCEPTION(res); } - TRI_document_collection_t* document = trx.documentCollection(); + TRI_collection_t* document = trx.documentCollection(); std::string const& collectionName = std::string(collection->_name); // disallow index creation in read-only mode @@ -1056,7 +1056,7 @@ static void CreateCollectionCoordinator( ArrayBuilder ab(&velocy, "indexes"); // create a dummy primary index - TRI_document_collection_t* doc = nullptr; + TRI_collection_t* doc = nullptr; std::unique_ptr primaryIndex( new arangodb::PrimaryIndex(doc)); @@ -1207,7 +1207,7 @@ static void JS_DropIndexVocbaseCol( TRI_V8_THROW_EXCEPTION(res); } - TRI_document_collection_t* document = trx.documentCollection(); + TRI_collection_t* document = trx.documentCollection(); auto idx = TRI_LookupIndexByHandle(isolate, trx.resolver(), collection, args[0], true); @@ -1304,7 +1304,7 @@ static void JS_GetIndexesVocbaseCol( // READ-LOCK start trx.lockRead(); - TRI_document_collection_t* document = trx.documentCollection(); + TRI_collection_t* document = trx.documentCollection(); std::string const& collectionName = std::string(collection->_name); // get list of indexes diff --git a/arangod/VocBase/CleanupThread.cpp b/arangod/VocBase/CleanupThread.cpp index 6f1f303218..f3d5ab350c 100644 --- a/arangod/VocBase/CleanupThread.cpp +++ b/arangod/VocBase/CleanupThread.cpp @@ -31,8 +31,8 @@ #include "Logger/Logger.h" #include "Utils/CursorRepository.h" #include "VocBase/Ditch.h" +#include "VocBase/collection.h" #include "VocBase/compactor.h" -#include "VocBase/document-collection.h" #include "Wal/LogfileManager.h" using namespace arangodb; @@ -82,7 +82,7 @@ void CleanupThread::run() { for (auto& collection : collections) { TRI_ASSERT(collection != nullptr); - TRI_document_collection_t* document; + TRI_collection_t* document; { READ_LOCKER(readLocker, collection->_lock); @@ -152,7 +152,7 @@ void CleanupThread::cleanupCursors(bool force) { /// @brief checks all datafiles of a collection void CleanupThread::cleanupCollection(TRI_vocbase_col_t* collection, - TRI_document_collection_t* document) { + TRI_collection_t* document) { // unload operations can normally only be executed when a collection is fully // garbage collected bool unloadChecked = false; diff --git a/arangod/VocBase/CleanupThread.h b/arangod/VocBase/CleanupThread.h index 0111f6c776..2c74846afa 100644 --- a/arangod/VocBase/CleanupThread.h +++ b/arangod/VocBase/CleanupThread.h @@ -27,7 +27,7 @@ #include "Basics/Common.h" #include "Basics/Thread.h" -struct TRI_document_collection_t; +struct TRI_collection_t; struct TRI_vocbase_col_t; struct TRI_vocbase_t; @@ -56,7 +56,7 @@ class CleanupThread : public Thread { void cleanupCursors(bool force); /// @brief checks all datafiles of a collection - void cleanupCollection(TRI_vocbase_col_t* collection, TRI_document_collection_t* document); + void cleanupCollection(TRI_vocbase_col_t* collection, TRI_collection_t* document); private: TRI_vocbase_t* _vocbase; diff --git a/arangod/VocBase/Ditch.cpp b/arangod/VocBase/Ditch.cpp index 84bd62aef4..c40c9dc207 100644 --- a/arangod/VocBase/Ditch.cpp +++ b/arangod/VocBase/Ditch.cpp @@ -24,7 +24,7 @@ #include "Ditch.h" #include "Logger/Logger.h" #include "Basics/MutexLocker.h" -#include "VocBase/document-collection.h" +#include "VocBase/collection.h" using namespace arangodb; diff --git a/arangod/VocBase/SingleServerTraverser.h b/arangod/VocBase/SingleServerTraverser.h index 42dfb93e13..8ae2e2c6ea 100644 --- a/arangod/VocBase/SingleServerTraverser.h +++ b/arangod/VocBase/SingleServerTraverser.h @@ -266,7 +266,7 @@ public: bool vertexMatchesConditions(std::string const&, size_t); - std::vector _edgeCols; + std::vector _edgeCols; ////////////////////////////////////////////////////////////////////////////// /// @brief Outer top level transaction diff --git a/arangod/VocBase/collection.cpp b/arangod/VocBase/collection.cpp index 3754b0f21c..d844aa4013 100644 --- a/arangod/VocBase/collection.cpp +++ b/arangod/VocBase/collection.cpp @@ -59,7 +59,6 @@ #include "VocBase/DatafileHelper.h" #include "VocBase/IndexPoolFeature.h" #include "VocBase/KeyGenerator.h" -#include "VocBase/document-collection.h" #include "VocBase/ticks.h" #include "VocBase/vocbase.h" #include "Wal/DocumentOperation.h" @@ -1089,8 +1088,8 @@ TRI_datafile_t* TRI_collection_t::createDatafile(TRI_voc_fid_t fid, TRI_voc_size_t journalSize, bool isCompactor) { TRI_ASSERT(fid > 0); - TRI_document_collection_t* document = - static_cast(this); + TRI_collection_t* document = + static_cast(this); TRI_ASSERT(document != nullptr); // create an entry for the new datafile @@ -5117,3 +5116,550 @@ int TRI_collection_t::indexFromVelocyPack(arangodb::Transaction* trx, return TRI_ERROR_NOT_IMPLEMENTED; } +/// @brief state during opening of a collection +struct open_iterator_state_t { + TRI_collection_t* _document; + TRI_voc_tid_t _tid; + TRI_voc_fid_t _fid; + std::unordered_map _stats; + DatafileStatisticsContainer* _dfi; + TRI_vocbase_t* _vocbase; + arangodb::Transaction* _trx; + uint64_t _deletions; + uint64_t _documents; + int64_t _initialCount; + + open_iterator_state_t(TRI_collection_t* document, + TRI_vocbase_t* vocbase) + : _document(document), + _tid(0), + _fid(0), + _stats(), + _dfi(nullptr), + _vocbase(vocbase), + _trx(nullptr), + _deletions(0), + _documents(0), + _initialCount(-1) {} + + ~open_iterator_state_t() { + for (auto& it : _stats) { + delete it.second; + } + } +}; + +/// @brief find a statistics container for a given file id +static DatafileStatisticsContainer* FindDatafileStats( + open_iterator_state_t* state, TRI_voc_fid_t fid) { + auto it = state->_stats.find(fid); + + if (it != state->_stats.end()) { + return (*it).second; + } + + auto stats = std::make_unique(); + + state->_stats.emplace(fid, stats.get()); + auto p = stats.release(); + + return p; +} + +/// @brief process a document (or edge) marker when opening a collection +static int OpenIteratorHandleDocumentMarker(TRI_df_marker_t const* marker, + TRI_datafile_t* datafile, + open_iterator_state_t* state) { + auto const fid = datafile->_fid; + TRI_collection_t* document = state->_document; + arangodb::Transaction* trx = state->_trx; + + VPackSlice const slice(reinterpret_cast(marker) + DatafileHelper::VPackOffset(TRI_DF_MARKER_VPACK_DOCUMENT)); + VPackSlice keySlice; + TRI_voc_rid_t revisionId; + + Transaction::extractKeyAndRevFromDocument(slice, keySlice, revisionId); + + document->setLastRevision(revisionId, false); + VPackValueLength length; + char const* p = keySlice.getString(length); + document->_keyGenerator->track(p, length); + + ++state->_documents; + + if (state->_fid != fid) { + // update the state + state->_fid = fid; // when we're here, we're looking at a datafile + state->_dfi = FindDatafileStats(state, fid); + } + + auto primaryIndex = document->primaryIndex(); + + // no primary index lock required here because we are the only ones reading + // from the index ATM + auto found = primaryIndex->lookupKey(trx, keySlice); + + // it is a new entry + if (found == nullptr) { + TRI_doc_mptr_t* header = document->_masterPointers.request(); + + if (header == nullptr) { + return TRI_ERROR_OUT_OF_MEMORY; + } + + header->setFid(fid, false); + header->setHash(primaryIndex->calculateHash(trx, keySlice)); + header->setVPackFromMarker(marker); + + // insert into primary index + void const* result = nullptr; + int res = primaryIndex->insertKey(trx, header, &result); + + if (res != TRI_ERROR_NO_ERROR) { + document->_masterPointers.release(header); + LOG(ERR) << "inserting document into primary index failed with error: " << TRI_errno_string(res); + + return res; + } + + ++document->_numberDocuments; + + // update the datafile info + state->_dfi->numberAlive++; + state->_dfi->sizeAlive += DatafileHelper::AlignedMarkerSize(marker); + } + + // it is an update, but only if found has a smaller revision identifier + else { + // save the old data + TRI_doc_mptr_t oldData = *found; + + // update the header info + found->setFid(fid, false); // when we're here, we're looking at a datafile + found->setVPackFromMarker(marker); + + // update the datafile info + DatafileStatisticsContainer* dfi; + if (oldData.getFid() == state->_fid) { + dfi = state->_dfi; + } else { + dfi = FindDatafileStats(state, oldData.getFid()); + } + + if (oldData.vpack() != nullptr) { + int64_t size = static_cast(oldData.markerSize()); + + dfi->numberAlive--; + dfi->sizeAlive -= DatafileHelper::AlignedSize(size); + dfi->numberDead++; + dfi->sizeDead += DatafileHelper::AlignedSize(size); + } + + state->_dfi->numberAlive++; + state->_dfi->sizeAlive += DatafileHelper::AlignedMarkerSize(marker); + } + + return TRI_ERROR_NO_ERROR; +} + +/// @brief process a deletion marker when opening a collection +static int OpenIteratorHandleDeletionMarker(TRI_df_marker_t const* marker, + TRI_datafile_t* datafile, + open_iterator_state_t* state) { + TRI_collection_t* document = state->_document; + arangodb::Transaction* trx = state->_trx; + + VPackSlice const slice(reinterpret_cast(marker) + DatafileHelper::VPackOffset(TRI_DF_MARKER_VPACK_REMOVE)); + + VPackSlice keySlice; + TRI_voc_rid_t revisionId; + + Transaction::extractKeyAndRevFromDocument(slice, keySlice, revisionId); + + document->setLastRevision(revisionId, false); + VPackValueLength length; + char const* p = keySlice.getString(length); + document->_keyGenerator->track(p, length); + + ++state->_deletions; + + if (state->_fid != datafile->_fid) { + // update the state + state->_fid = datafile->_fid; + state->_dfi = FindDatafileStats(state, datafile->_fid); + } + + // no primary index lock required here because we are the only ones reading + // from the index ATM + auto primaryIndex = document->primaryIndex(); + TRI_doc_mptr_t* found = primaryIndex->lookupKey(trx, keySlice); + + // it is a new entry, so we missed the create + if (found == nullptr) { + // update the datafile info + state->_dfi->numberDeletions++; + } + + // it is a real delete + else { + // update the datafile info + DatafileStatisticsContainer* dfi; + + if (found->getFid() == state->_fid) { + dfi = state->_dfi; + } else { + dfi = FindDatafileStats(state, found->getFid()); + } + + TRI_ASSERT(found->vpack() != nullptr); + + int64_t size = DatafileHelper::AlignedSize(found->markerSize()); + + dfi->numberAlive--; + dfi->sizeAlive -= DatafileHelper::AlignedSize(size); + dfi->numberDead++; + dfi->sizeDead += DatafileHelper::AlignedSize(size); + state->_dfi->numberDeletions++; + + document->deletePrimaryIndex(trx, found); + --document->_numberDocuments; + + // free the header + document->_masterPointers.release(found); + } + + return TRI_ERROR_NO_ERROR; +} + +/// @brief iterator for open +static bool OpenIterator(TRI_df_marker_t const* marker, void* data, + TRI_datafile_t* datafile) { + TRI_collection_t* document = + static_cast(data)->_document; + TRI_voc_tick_t const tick = marker->getTick(); + TRI_df_marker_type_t const type = marker->getType(); + + int res; + + if (type == TRI_DF_MARKER_VPACK_DOCUMENT) { + res = OpenIteratorHandleDocumentMarker(marker, datafile, + static_cast(data)); + + if (datafile->_dataMin == 0) { + datafile->_dataMin = tick; + } + + if (tick > datafile->_dataMax) { + datafile->_dataMax = tick; + } + } else if (type == TRI_DF_MARKER_VPACK_REMOVE) { + res = OpenIteratorHandleDeletionMarker(marker, datafile, + static_cast(data)); + } else { + if (type == TRI_DF_MARKER_HEADER) { + // ensure there is a datafile info entry for each datafile of the + // collection + FindDatafileStats(static_cast(data), datafile->_fid); + } + + LOG(TRACE) << "skipping marker type " << TRI_NameMarkerDatafile(marker); + res = TRI_ERROR_NO_ERROR; + } + + if (datafile->_tickMin == 0) { + datafile->_tickMin = tick; + } + + if (tick > datafile->_tickMax) { + datafile->_tickMax = tick; + } + + if (tick > document->_tickMax) { + if (type != TRI_DF_MARKER_HEADER && + type != TRI_DF_MARKER_FOOTER && + type != TRI_DF_MARKER_COL_HEADER && + type != TRI_DF_MARKER_PROLOGUE) { + document->_tickMax = tick; + } + } + + return (res == TRI_ERROR_NO_ERROR); +} + +/// @brief initializes a document collection +static bool InitDocumentCollection(TRI_collection_t* document) { + // create primary index + std::unique_ptr primaryIndex( + new arangodb::PrimaryIndex(document)); + + try { + document->addIndex(primaryIndex.get()); + primaryIndex.release(); + } catch (...) { + TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY); + + return false; + } + + // create edges index + if (document->_info.type() == TRI_COL_TYPE_EDGE) { + TRI_idx_iid_t iid = document->_info.id(); + if (document->_info.planId() > 0) { + iid = document->_info.planId(); + } + + try { + std::unique_ptr edgeIndex( + new arangodb::EdgeIndex(iid, document)); + + document->addIndex(edgeIndex.get()); + edgeIndex.release(); + } catch (...) { + TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY); + + return false; + } + } + + return true; +} + +/// @brief iterate all markers of the collection +static int IterateMarkersCollection(arangodb::Transaction* trx, + TRI_collection_t* collection) { + auto document = reinterpret_cast(collection); + + // initialize state for iteration + open_iterator_state_t openState(document, collection->_vocbase); + + if (collection->_info.initialCount() != -1) { + auto primaryIndex = document->primaryIndex(); + + int res = primaryIndex->resize( + trx, static_cast(collection->_info.initialCount() * 1.1)); + + if (res != TRI_ERROR_NO_ERROR) { + return res; + } + + openState._initialCount = collection->_info.initialCount(); + } + + // read all documents and fill primary index + auto cb = [&openState](TRI_df_marker_t const* marker, TRI_datafile_t* datafile) -> bool { + return OpenIterator(marker, &openState, datafile); + }; + + collection->iterateDatafiles(cb); + + LOG(TRACE) << "found " << openState._documents << " document markers, " << openState._deletions << " deletion markers for collection '" << collection->_info.name() << "'"; + + // update the real statistics for the collection + try { + for (auto& it : openState._stats) { + document->_datafileStatistics.create(it.first, *(it.second)); + } + } catch (basics::Exception const& ex) { + return ex.code(); + } catch (...) { + return TRI_ERROR_INTERNAL; + } + + return TRI_ERROR_NO_ERROR; +} + +/// @brief creates a new collection +TRI_collection_t* TRI_CreateDocumentCollection( + TRI_vocbase_t* vocbase, VocbaseCollectionInfo& parameters, + TRI_voc_cid_t cid) { + if (cid > 0) { + TRI_UpdateTickServer(cid); + } else { + cid = TRI_NewTickServer(); + } + + parameters.setCollectionId(cid); + + // check if we can generate the key generator + std::shared_ptr const> buffer = + parameters.keyOptions(); + + VPackSlice slice; + if (buffer != nullptr) { + slice = VPackSlice(buffer->data()); + } + + std::unique_ptr keyGenerator(KeyGenerator::factory(slice)); + + if (keyGenerator == nullptr) { + TRI_set_errno(TRI_ERROR_ARANGO_INVALID_KEY_GENERATOR); + return nullptr; + } + + auto document = std::make_unique(vocbase); + document->_keyGenerator.reset(keyGenerator.release()); + + TRI_collection_t* collection = + TRI_CreateCollection(vocbase, document.get(), parameters); + + if (collection == nullptr) { + LOG(ERR) << "cannot create document collection"; + + return nullptr; + } + + // create document collection + if (false == InitDocumentCollection(document.get())) { + LOG(ERR) << "cannot initialize document collection"; + return nullptr; + } + + // save the parameters block (within create, no need to lock) + bool doSync = application_features::ApplicationServer::getFeature("Database")->forceSyncProperties(); + int res = parameters.saveToFile(collection->path(), doSync); + + if (res != TRI_ERROR_NO_ERROR) { + LOG(ERR) << "cannot save collection parameters in directory '" << collection->path() << "': '" << TRI_last_error() << "'"; + return nullptr; + } + + // remove the temporary file + std::string tmpfile = collection->path() + ".tmp"; + TRI_UnlinkFile(tmpfile.c_str()); + + return document.release(); +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief opens an existing collection +//////////////////////////////////////////////////////////////////////////////// + +TRI_collection_t* TRI_OpenDocumentCollection(TRI_vocbase_t* vocbase, + TRI_vocbase_col_t* col, + bool ignoreErrors) { + // first open the document collection + auto document = std::make_unique(vocbase); + + TRI_ASSERT(document != nullptr); + + double start = TRI_microtime(); + LOG_TOPIC(TRACE, Logger::PERFORMANCE) + << "open-document-collection { collection: " << vocbase->name() << "/" + << col->name() << " }"; + + int res = document->open(col->path(), ignoreErrors); + + if (res != TRI_ERROR_NO_ERROR) { + LOG(ERR) << "cannot open document collection from path '" << col->path() << "'"; + + return nullptr; + } + + // create document collection + if (false == InitDocumentCollection(document.get())) { + LOG(ERR) << "cannot initialize document collection"; + return nullptr; + } + + // check if we can generate the key generator + std::shared_ptr const> buffer = document->_info.keyOptions(); + + VPackSlice slice; + if (buffer.get() != nullptr) { + slice = VPackSlice(buffer->data()); + } + + std::unique_ptr keyGenerator(KeyGenerator::factory(slice)); + + if (keyGenerator == nullptr) { + TRI_set_errno(TRI_ERROR_ARANGO_INVALID_KEY_GENERATOR); + + return nullptr; + } + + document->_keyGenerator.reset(keyGenerator.release()); + + arangodb::SingleCollectionTransaction trx( + arangodb::StandaloneTransactionContext::Create(vocbase), + document->_info.id(), TRI_TRANSACTION_WRITE); + + // build the primary index + res = TRI_ERROR_INTERNAL; + + try { + double start = TRI_microtime(); + + LOG_TOPIC(TRACE, Logger::PERFORMANCE) + << "iterate-markers { collection: " << vocbase->name() << "/" + << document->_info.name() << " }"; + + // iterate over all markers of the collection + res = IterateMarkersCollection(&trx, document.get()); + + LOG_TOPIC(TRACE, Logger::PERFORMANCE) << "[timer] " << Logger::FIXED(TRI_microtime() - start) << " s, iterate-markers { collection: " << vocbase->name() << "/" << document->_info.name() << " }"; + } catch (arangodb::basics::Exception const& ex) { + res = ex.code(); + } catch (std::bad_alloc const&) { + res = TRI_ERROR_OUT_OF_MEMORY; + } catch (...) { + res = TRI_ERROR_INTERNAL; + } + + if (res != TRI_ERROR_NO_ERROR) { + LOG(ERR) << "cannot iterate data of document collection"; + TRI_set_errno(res); + + return nullptr; + } + + // build the indexes meta-data, but do not fill the indexes yet + { + auto old = document->useSecondaryIndexes(); + + // turn filling of secondary indexes off. we're now only interested in getting + // the indexes' definition. we'll fill them below ourselves. + document->useSecondaryIndexes(false); + + try { + document->detectIndexes(&trx); + document->useSecondaryIndexes(old); + } catch (...) { + document->useSecondaryIndexes(old); + LOG(ERR) << "cannot initialize collection indexes"; + return nullptr; + } + } + + + if (!arangodb::wal::LogfileManager::instance()->isInRecovery()) { + // build the index structures, and fill the indexes + document->fillIndexes(&trx, col); + } + + LOG_TOPIC(TRACE, Logger::PERFORMANCE) + << "[timer] " << Logger::FIXED(TRI_microtime() - start) + << " s, open-document-collection { collection: " << vocbase->name() << "/" + << document->_info.name() << " }"; + + return document.release(); +} + +/// @brief closes an open collection +int TRI_CloseDocumentCollection(TRI_collection_t* document, + bool updateStats) { + auto primaryIndex = document->primaryIndex(); + auto idxSize = primaryIndex->size(); + + if (!document->_info.deleted() && + document->_info.initialCount() != static_cast(idxSize)) { + document->_info.updateCount(idxSize); + + bool doSync = application_features::ApplicationServer::getFeature("Database")->forceSyncProperties(); + // Ignore the error? + document->_info.saveToFile(document->path(), doSync); + } + + // closes all open compactors, journals, datafiles + document->close(); + return TRI_ERROR_NO_ERROR; +} diff --git a/arangod/VocBase/collection.h b/arangod/VocBase/collection.h index 7ef9e06093..258c3436e4 100644 --- a/arangod/VocBase/collection.h +++ b/arangod/VocBase/collection.h @@ -636,4 +636,16 @@ struct TRI_collection_t { TRI_collection_t* TRI_CreateCollection(TRI_vocbase_t*, TRI_collection_t*, arangodb::VocbaseCollectionInfo const&); +/// @brief creates a new collection +TRI_collection_t* TRI_CreateDocumentCollection( + TRI_vocbase_t*, arangodb::VocbaseCollectionInfo&, + TRI_voc_cid_t); + +/// @brief opens an existing collection +TRI_collection_t* TRI_OpenDocumentCollection(TRI_vocbase_t*, + TRI_vocbase_col_t*, bool); + +/// @brief closes an open collection +int TRI_CloseDocumentCollection(TRI_collection_t*, bool); + #endif diff --git a/arangod/VocBase/compactor.cpp b/arangod/VocBase/compactor.cpp index 2025bde9a4..5b6328e5fa 100644 --- a/arangod/VocBase/compactor.cpp +++ b/arangod/VocBase/compactor.cpp @@ -41,7 +41,7 @@ #include "Utils/StandaloneTransactionContext.h" #include "VocBase/DatafileHelper.h" #include "VocBase/DatafileStatistics.h" -#include "VocBase/document-collection.h" +#include "VocBase/collection.h" #include "VocBase/ticks.h" #include "VocBase/vocbase.h" @@ -139,7 +139,7 @@ static int const COMPACTOR_INTERVAL = (1 * 1000 * 1000); struct compaction_initial_context_t { arangodb::Transaction* _trx; - TRI_document_collection_t* _document; + TRI_collection_t* _document; int64_t _targetSize; TRI_voc_fid_t _fid; bool _keepDeletions; @@ -152,7 +152,7 @@ struct compaction_initial_context_t { struct compaction_context_t { arangodb::Transaction* _trx; - TRI_document_collection_t* _document; + TRI_collection_t* _document; TRI_datafile_t* _compactor; DatafileStatisticsContainer _dfi; bool _keepDeletions; @@ -168,7 +168,7 @@ struct compaction_info_t { }; /// @brief determine the number of documents in the collection -static uint64_t GetNumberOfDocuments(TRI_document_collection_t* document) { +static uint64_t GetNumberOfDocuments(TRI_collection_t* document) { TRI_vocbase_t* vocbase = document->_vocbase; SingleCollectionTransaction trx(StandaloneTransactionContext::Create(vocbase), document->_info.id(), TRI_TRANSACTION_READ); @@ -189,7 +189,7 @@ static uint64_t GetNumberOfDocuments(TRI_document_collection_t* document) { /// @brief write a copy of the marker into the datafile //////////////////////////////////////////////////////////////////////////////// -static int CopyMarker(TRI_document_collection_t* document, +static int CopyMarker(TRI_collection_t* document, TRI_datafile_t* compactor, TRI_df_marker_t const* marker, TRI_df_marker_t** result) { int res = TRI_ReserveElementDatafile(compactor, marker->getSize(), result, 0); @@ -208,8 +208,7 @@ static int CopyMarker(TRI_document_collection_t* document, //////////////////////////////////////////////////////////////////////////////// static void DropDatafileCallback(TRI_datafile_t* datafile, void* data) { - TRI_document_collection_t* document = - static_cast(data); + TRI_collection_t* document = static_cast(data); TRI_voc_fid_t fid = datafile->_fid; std::string copy; @@ -274,7 +273,7 @@ static void RenameDatafileCallback(TRI_datafile_t* datafile, void* data) { auto* context = static_cast(data); TRI_datafile_t* compactor = context->_compactor; - TRI_document_collection_t* document = context->_document; + TRI_collection_t* document = context->_document; bool ok = false; TRI_ASSERT(datafile->_fid == compactor->_fid); @@ -325,7 +324,7 @@ static void RenameDatafileCallback(TRI_datafile_t* datafile, void* data) { static bool Compactifier(TRI_df_marker_t const* marker, void* data, TRI_datafile_t* datafile) { auto* context = static_cast(data); - TRI_document_collection_t* document = context->_document; + TRI_collection_t* document = context->_document; TRI_voc_fid_t const targetFid = context->_compactor->_fid; TRI_df_marker_type_t const type = marker->getType(); @@ -399,7 +398,7 @@ static bool Compactifier(TRI_df_marker_t const* marker, void* data, /// @brief remove an empty compactor file //////////////////////////////////////////////////////////////////////////////// -static int RemoveCompactor(TRI_document_collection_t* document, +static int RemoveCompactor(TRI_collection_t* document, TRI_datafile_t* compactor) { LOG_TOPIC(DEBUG, Logger::COMPACTOR) << "removing empty compaction file '" << compactor->getName(compactor) << "'"; @@ -431,7 +430,7 @@ static int RemoveCompactor(TRI_document_collection_t* document, /// @brief remove an empty datafile //////////////////////////////////////////////////////////////////////////////// -static int RemoveDatafile(TRI_document_collection_t* document, +static int RemoveDatafile(TRI_collection_t* document, TRI_datafile_t* df) { LOG_TOPIC(DEBUG, Logger::COMPACTOR) << "removing empty datafile '" << df->getName(df) << "'"; @@ -456,7 +455,7 @@ static int RemoveDatafile(TRI_document_collection_t* document, static bool CalculateSize(TRI_df_marker_t const* marker, void* data, TRI_datafile_t* datafile) { auto* context = static_cast(data); - TRI_document_collection_t* document = context->_document; + TRI_collection_t* document = context->_document; TRI_df_marker_type_t const type = marker->getType(); @@ -495,7 +494,7 @@ static bool CalculateSize(TRI_df_marker_t const* marker, void* data, //////////////////////////////////////////////////////////////////////////////// static compaction_initial_context_t InitCompaction( - arangodb::Transaction* trx, TRI_document_collection_t* document, + arangodb::Transaction* trx, TRI_collection_t* document, std::vector const& toCompact) { compaction_initial_context_t context; @@ -555,7 +554,7 @@ static compaction_initial_context_t InitCompaction( //////////////////////////////////////////////////////////////////////////////// static void CompactifyDatafiles( - TRI_document_collection_t* document, + TRI_collection_t* document, std::vector const& toCompact) { TRI_datafile_t* compactor; compaction_context_t context; @@ -738,7 +737,7 @@ static void CompactifyDatafiles( /// @brief checks all datafiles of a collection //////////////////////////////////////////////////////////////////////////////// -static bool CompactifyDocumentCollection(TRI_document_collection_t* document) { +static bool CompactifyDocumentCollection(TRI_collection_t* document) { // we can hopefully get away without the lock here... // if (! document->isFullyCollected()) { // return false; @@ -1132,7 +1131,7 @@ void TRI_CompactorVocBase(void* data) { continue; } - TRI_document_collection_t* document = collection->_collection; + TRI_collection_t* document = collection->_collection; if (document == nullptr) { continue; diff --git a/arangod/VocBase/document-collection.cpp b/arangod/VocBase/document-collection.cpp deleted file mode 100644 index 595bb47c2f..0000000000 --- a/arangod/VocBase/document-collection.cpp +++ /dev/null @@ -1,654 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -/// DISCLAIMER -/// -/// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany -/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany -/// -/// Licensed under the Apache License, Version 2.0 (the "License"); -/// you may not use this file except in compliance with the License. -/// You may obtain a copy of the License at -/// -/// http://www.apache.org/licenses/LICENSE-2.0 -/// -/// Unless required by applicable law or agreed to in writing, software -/// distributed under the License is distributed on an "AS IS" BASIS, -/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -/// See the License for the specific language governing permissions and -/// limitations under the License. -/// -/// Copyright holder is ArangoDB GmbH, Cologne, Germany -/// -/// @author Dr. Frank Celler -//////////////////////////////////////////////////////////////////////////////// - -#include "document-collection.h" - -#include "ApplicationFeatures/ApplicationServer.h" -#include "Aql/QueryCache.h" -#include "Basics/Barrier.h" -#include "Basics/conversions.h" -#include "Basics/Exceptions.h" -#include "Basics/FileUtils.h" -#include "Basics/HybridLogicalClock.h" -#include "Basics/Timers.h" -#include "Basics/files.h" -#include "Basics/tri-strings.h" -#include "Basics/StaticStrings.h" -#include "Basics/ThreadPool.h" -#include "Basics/VelocyPackHelper.h" -#include "Basics/WriteLocker.h" -#include "Cluster/ServerState.h" -#include "Cluster/ClusterMethods.h" -#include "FulltextIndex/fulltext-index.h" -#include "Indexes/EdgeIndex.h" -#include "Indexes/FulltextIndex.h" -#include "Indexes/GeoIndex2.h" -#include "Indexes/HashIndex.h" -#include "Indexes/PrimaryIndex.h" -#include "Indexes/SkiplistIndex.h" -#include "Logger/Logger.h" -#include "RestServer/DatabaseFeature.h" -#include "Utils/CollectionNameResolver.h" -#include "Utils/CollectionReadLocker.h" -#include "Utils/CollectionWriteLocker.h" -#include "Utils/SingleCollectionTransaction.h" -#include "Utils/StandaloneTransactionContext.h" -#include "VocBase/DatafileHelper.h" -#include "VocBase/Ditch.h" -#include "VocBase/IndexPoolFeature.h" -#include "VocBase/KeyGenerator.h" -#include "VocBase/MasterPointers.h" -#include "VocBase/ticks.h" -#include "Wal/DocumentOperation.h" -#include "Wal/LogfileManager.h" -#include "Wal/Marker.h" -#include "Wal/Slots.h" - -#ifdef ARANGODB_ENABLE_ROCKSDB -#include "Indexes/RocksDBIndex.h" - -#include -#include -#include -#include -#endif - -#include -#include -#include -#include - -using namespace arangodb; -using namespace arangodb::basics; - -//////////////////////////////////////////////////////////////////////////////// -/// @brief state during opening of a collection -//////////////////////////////////////////////////////////////////////////////// - -struct open_iterator_state_t { - TRI_document_collection_t* _document; - TRI_voc_tid_t _tid; - TRI_voc_fid_t _fid; - std::unordered_map _stats; - DatafileStatisticsContainer* _dfi; - TRI_vocbase_t* _vocbase; - arangodb::Transaction* _trx; - uint64_t _deletions; - uint64_t _documents; - int64_t _initialCount; - - open_iterator_state_t(TRI_document_collection_t* document, - TRI_vocbase_t* vocbase) - : _document(document), - _tid(0), - _fid(0), - _stats(), - _dfi(nullptr), - _vocbase(vocbase), - _trx(nullptr), - _deletions(0), - _documents(0), - _initialCount(-1) {} - - ~open_iterator_state_t() { - for (auto& it : _stats) { - delete it.second; - } - } -}; - -//////////////////////////////////////////////////////////////////////////////// -/// @brief find a statistics container for a given file id -//////////////////////////////////////////////////////////////////////////////// - -static DatafileStatisticsContainer* FindDatafileStats( - open_iterator_state_t* state, TRI_voc_fid_t fid) { - auto it = state->_stats.find(fid); - - if (it != state->_stats.end()) { - return (*it).second; - } - - auto stats = std::make_unique(); - - state->_stats.emplace(fid, stats.get()); - auto p = stats.release(); - - return p; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief process a document (or edge) marker when opening a collection -//////////////////////////////////////////////////////////////////////////////// - -static int OpenIteratorHandleDocumentMarker(TRI_df_marker_t const* marker, - TRI_datafile_t* datafile, - open_iterator_state_t* state) { - auto const fid = datafile->_fid; - TRI_document_collection_t* document = state->_document; - arangodb::Transaction* trx = state->_trx; - - VPackSlice const slice(reinterpret_cast(marker) + DatafileHelper::VPackOffset(TRI_DF_MARKER_VPACK_DOCUMENT)); - VPackSlice keySlice; - TRI_voc_rid_t revisionId; - - Transaction::extractKeyAndRevFromDocument(slice, keySlice, revisionId); - - document->setLastRevision(revisionId, false); - VPackValueLength length; - char const* p = keySlice.getString(length); - document->_keyGenerator->track(p, length); - - ++state->_documents; - - if (state->_fid != fid) { - // update the state - state->_fid = fid; // when we're here, we're looking at a datafile - state->_dfi = FindDatafileStats(state, fid); - } - - auto primaryIndex = document->primaryIndex(); - - // no primary index lock required here because we are the only ones reading - // from the index ATM - auto found = primaryIndex->lookupKey(trx, keySlice); - - // it is a new entry - if (found == nullptr) { - TRI_doc_mptr_t* header = document->_masterPointers.request(); - - if (header == nullptr) { - return TRI_ERROR_OUT_OF_MEMORY; - } - - header->setFid(fid, false); - header->setHash(primaryIndex->calculateHash(trx, keySlice)); - header->setVPackFromMarker(marker); - - // insert into primary index - void const* result = nullptr; - int res = primaryIndex->insertKey(trx, header, &result); - - if (res != TRI_ERROR_NO_ERROR) { - document->_masterPointers.release(header); - LOG(ERR) << "inserting document into primary index failed with error: " << TRI_errno_string(res); - - return res; - } - - ++document->_numberDocuments; - - // update the datafile info - state->_dfi->numberAlive++; - state->_dfi->sizeAlive += DatafileHelper::AlignedMarkerSize(marker); - } - - // it is an update, but only if found has a smaller revision identifier - else { - // save the old data - TRI_doc_mptr_t oldData = *found; - - // update the header info - found->setFid(fid, false); // when we're here, we're looking at a datafile - found->setVPackFromMarker(marker); - - // update the datafile info - DatafileStatisticsContainer* dfi; - if (oldData.getFid() == state->_fid) { - dfi = state->_dfi; - } else { - dfi = FindDatafileStats(state, oldData.getFid()); - } - - if (oldData.vpack() != nullptr) { - int64_t size = static_cast(oldData.markerSize()); - - dfi->numberAlive--; - dfi->sizeAlive -= DatafileHelper::AlignedSize(size); - dfi->numberDead++; - dfi->sizeDead += DatafileHelper::AlignedSize(size); - } - - state->_dfi->numberAlive++; - state->_dfi->sizeAlive += DatafileHelper::AlignedMarkerSize(marker); - } - - return TRI_ERROR_NO_ERROR; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief process a deletion marker when opening a collection -//////////////////////////////////////////////////////////////////////////////// - -static int OpenIteratorHandleDeletionMarker(TRI_df_marker_t const* marker, - TRI_datafile_t* datafile, - open_iterator_state_t* state) { - TRI_document_collection_t* document = state->_document; - arangodb::Transaction* trx = state->_trx; - - VPackSlice const slice(reinterpret_cast(marker) + DatafileHelper::VPackOffset(TRI_DF_MARKER_VPACK_REMOVE)); - - VPackSlice keySlice; - TRI_voc_rid_t revisionId; - - Transaction::extractKeyAndRevFromDocument(slice, keySlice, revisionId); - - document->setLastRevision(revisionId, false); - VPackValueLength length; - char const* p = keySlice.getString(length); - document->_keyGenerator->track(p, length); - - ++state->_deletions; - - if (state->_fid != datafile->_fid) { - // update the state - state->_fid = datafile->_fid; - state->_dfi = FindDatafileStats(state, datafile->_fid); - } - - // no primary index lock required here because we are the only ones reading - // from the index ATM - auto primaryIndex = document->primaryIndex(); - TRI_doc_mptr_t* found = primaryIndex->lookupKey(trx, keySlice); - - // it is a new entry, so we missed the create - if (found == nullptr) { - // update the datafile info - state->_dfi->numberDeletions++; - } - - // it is a real delete - else { - // update the datafile info - DatafileStatisticsContainer* dfi; - - if (found->getFid() == state->_fid) { - dfi = state->_dfi; - } else { - dfi = FindDatafileStats(state, found->getFid()); - } - - TRI_ASSERT(found->vpack() != nullptr); - - int64_t size = DatafileHelper::AlignedSize(found->markerSize()); - - dfi->numberAlive--; - dfi->sizeAlive -= DatafileHelper::AlignedSize(size); - dfi->numberDead++; - dfi->sizeDead += DatafileHelper::AlignedSize(size); - state->_dfi->numberDeletions++; - - document->deletePrimaryIndex(trx, found); - --document->_numberDocuments; - - // free the header - document->_masterPointers.release(found); - } - - return TRI_ERROR_NO_ERROR; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief iterator for open -//////////////////////////////////////////////////////////////////////////////// - -static bool OpenIterator(TRI_df_marker_t const* marker, void* data, - TRI_datafile_t* datafile) { - TRI_document_collection_t* document = - static_cast(data)->_document; - TRI_voc_tick_t const tick = marker->getTick(); - TRI_df_marker_type_t const type = marker->getType(); - - int res; - - if (type == TRI_DF_MARKER_VPACK_DOCUMENT) { - res = OpenIteratorHandleDocumentMarker(marker, datafile, - static_cast(data)); - - if (datafile->_dataMin == 0) { - datafile->_dataMin = tick; - } - - if (tick > datafile->_dataMax) { - datafile->_dataMax = tick; - } - } else if (type == TRI_DF_MARKER_VPACK_REMOVE) { - res = OpenIteratorHandleDeletionMarker(marker, datafile, - static_cast(data)); - } else { - if (type == TRI_DF_MARKER_HEADER) { - // ensure there is a datafile info entry for each datafile of the - // collection - FindDatafileStats(static_cast(data), datafile->_fid); - } - - LOG(TRACE) << "skipping marker type " << TRI_NameMarkerDatafile(marker); - res = TRI_ERROR_NO_ERROR; - } - - if (datafile->_tickMin == 0) { - datafile->_tickMin = tick; - } - - if (tick > datafile->_tickMax) { - datafile->_tickMax = tick; - } - - if (tick > document->_tickMax) { - if (type != TRI_DF_MARKER_HEADER && - type != TRI_DF_MARKER_FOOTER && - type != TRI_DF_MARKER_COL_HEADER && - type != TRI_DF_MARKER_PROLOGUE) { - document->_tickMax = tick; - } - } - - return (res == TRI_ERROR_NO_ERROR); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief initializes a document collection -//////////////////////////////////////////////////////////////////////////////// - -static bool InitDocumentCollection(TRI_document_collection_t* document) { - // create primary index - std::unique_ptr primaryIndex( - new arangodb::PrimaryIndex(document)); - - try { - document->addIndex(primaryIndex.get()); - primaryIndex.release(); - } catch (...) { - TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY); - - return false; - } - - // create edges index - if (document->_info.type() == TRI_COL_TYPE_EDGE) { - TRI_idx_iid_t iid = document->_info.id(); - if (document->_info.planId() > 0) { - iid = document->_info.planId(); - } - - try { - std::unique_ptr edgeIndex( - new arangodb::EdgeIndex(iid, document)); - - document->addIndex(edgeIndex.get()); - edgeIndex.release(); - } catch (...) { - TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY); - - return false; - } - } - - return true; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief iterate all markers of the collection -//////////////////////////////////////////////////////////////////////////////// - -static int IterateMarkersCollection(arangodb::Transaction* trx, - TRI_collection_t* collection) { - auto document = reinterpret_cast(collection); - - // initialize state for iteration - open_iterator_state_t openState(document, collection->_vocbase); - - if (collection->_info.initialCount() != -1) { - auto primaryIndex = document->primaryIndex(); - - int res = primaryIndex->resize( - trx, static_cast(collection->_info.initialCount() * 1.1)); - - if (res != TRI_ERROR_NO_ERROR) { - return res; - } - - openState._initialCount = collection->_info.initialCount(); - } - - // read all documents and fill primary index - auto cb = [&openState](TRI_df_marker_t const* marker, TRI_datafile_t* datafile) -> bool { - return OpenIterator(marker, &openState, datafile); - }; - - collection->iterateDatafiles(cb); - - LOG(TRACE) << "found " << openState._documents << " document markers, " << openState._deletions << " deletion markers for collection '" << collection->_info.name() << "'"; - - // update the real statistics for the collection - try { - for (auto& it : openState._stats) { - document->_datafileStatistics.create(it.first, *(it.second)); - } - } catch (basics::Exception const& ex) { - return ex.code(); - } catch (...) { - return TRI_ERROR_INTERNAL; - } - - return TRI_ERROR_NO_ERROR; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief creates a new collection -//////////////////////////////////////////////////////////////////////////////// - -TRI_document_collection_t* TRI_CreateDocumentCollection( - TRI_vocbase_t* vocbase, VocbaseCollectionInfo& parameters, - TRI_voc_cid_t cid) { - if (cid > 0) { - TRI_UpdateTickServer(cid); - } else { - cid = TRI_NewTickServer(); - } - - parameters.setCollectionId(cid); - - // check if we can generate the key generator - std::shared_ptr const> buffer = - parameters.keyOptions(); - - VPackSlice slice; - if (buffer != nullptr) { - slice = VPackSlice(buffer->data()); - } - - std::unique_ptr keyGenerator(KeyGenerator::factory(slice)); - - if (keyGenerator == nullptr) { - TRI_set_errno(TRI_ERROR_ARANGO_INVALID_KEY_GENERATOR); - return nullptr; - } - - auto document = std::make_unique(vocbase); - document->_keyGenerator.reset(keyGenerator.release()); - - TRI_collection_t* collection = - TRI_CreateCollection(vocbase, document.get(), parameters); - - if (collection == nullptr) { - LOG(ERR) << "cannot create document collection"; - - return nullptr; - } - - // create document collection - if (false == InitDocumentCollection(document.get())) { - LOG(ERR) << "cannot initialize document collection"; - return nullptr; - } - - // save the parameters block (within create, no need to lock) - bool doSync = application_features::ApplicationServer::getFeature("Database")->forceSyncProperties(); - int res = parameters.saveToFile(collection->path(), doSync); - - if (res != TRI_ERROR_NO_ERROR) { - LOG(ERR) << "cannot save collection parameters in directory '" << collection->path() << "': '" << TRI_last_error() << "'"; - return nullptr; - } - - // remove the temporary file - std::string tmpfile = collection->path() + ".tmp"; - TRI_UnlinkFile(tmpfile.c_str()); - - return document.release(); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief opens an existing collection -//////////////////////////////////////////////////////////////////////////////// - -TRI_document_collection_t* TRI_OpenDocumentCollection(TRI_vocbase_t* vocbase, - TRI_vocbase_col_t* col, - bool ignoreErrors) { - // first open the document collection - auto document = std::make_unique(vocbase); - - TRI_ASSERT(document != nullptr); - - double start = TRI_microtime(); - LOG_TOPIC(TRACE, Logger::PERFORMANCE) - << "open-document-collection { collection: " << vocbase->name() << "/" - << col->name() << " }"; - - int res = document->open(col->path(), ignoreErrors); - - if (res != TRI_ERROR_NO_ERROR) { - LOG(ERR) << "cannot open document collection from path '" << col->path() << "'"; - - return nullptr; - } - - // create document collection - if (false == InitDocumentCollection(document.get())) { - LOG(ERR) << "cannot initialize document collection"; - return nullptr; - } - - // check if we can generate the key generator - std::shared_ptr const> buffer = document->_info.keyOptions(); - - VPackSlice slice; - if (buffer.get() != nullptr) { - slice = VPackSlice(buffer->data()); - } - - std::unique_ptr keyGenerator(KeyGenerator::factory(slice)); - - if (keyGenerator == nullptr) { - TRI_set_errno(TRI_ERROR_ARANGO_INVALID_KEY_GENERATOR); - - return nullptr; - } - - document->_keyGenerator.reset(keyGenerator.release()); - - arangodb::SingleCollectionTransaction trx( - arangodb::StandaloneTransactionContext::Create(vocbase), - document->_info.id(), TRI_TRANSACTION_WRITE); - - // build the primary index - res = TRI_ERROR_INTERNAL; - - try { - double start = TRI_microtime(); - - LOG_TOPIC(TRACE, Logger::PERFORMANCE) - << "iterate-markers { collection: " << vocbase->name() << "/" - << document->_info.name() << " }"; - - // iterate over all markers of the collection - res = IterateMarkersCollection(&trx, document.get()); - - LOG_TOPIC(TRACE, Logger::PERFORMANCE) << "[timer] " << Logger::FIXED(TRI_microtime() - start) << " s, iterate-markers { collection: " << vocbase->name() << "/" << document->_info.name() << " }"; - } catch (arangodb::basics::Exception const& ex) { - res = ex.code(); - } catch (std::bad_alloc const&) { - res = TRI_ERROR_OUT_OF_MEMORY; - } catch (...) { - res = TRI_ERROR_INTERNAL; - } - - if (res != TRI_ERROR_NO_ERROR) { - LOG(ERR) << "cannot iterate data of document collection"; - TRI_set_errno(res); - - return nullptr; - } - - // build the indexes meta-data, but do not fill the indexes yet - { - auto old = document->useSecondaryIndexes(); - - // turn filling of secondary indexes off. we're now only interested in getting - // the indexes' definition. we'll fill them below ourselves. - document->useSecondaryIndexes(false); - - try { - document->detectIndexes(&trx); - document->useSecondaryIndexes(old); - } catch (...) { - document->useSecondaryIndexes(old); - LOG(ERR) << "cannot initialize collection indexes"; - return nullptr; - } - } - - - if (!arangodb::wal::LogfileManager::instance()->isInRecovery()) { - // build the index structures, and fill the indexes - document->fillIndexes(&trx, col); - } - - LOG_TOPIC(TRACE, Logger::PERFORMANCE) - << "[timer] " << Logger::FIXED(TRI_microtime() - start) - << " s, open-document-collection { collection: " << vocbase->name() << "/" - << document->_info.name() << " }"; - - return document.release(); -} - -/// @brief closes an open collection -int TRI_CloseDocumentCollection(TRI_document_collection_t* document, - bool updateStats) { - auto primaryIndex = document->primaryIndex(); - auto idxSize = primaryIndex->size(); - - if (!document->_info.deleted() && - document->_info.initialCount() != static_cast(idxSize)) { - document->_info.updateCount(idxSize); - - bool doSync = application_features::ApplicationServer::getFeature("Database")->forceSyncProperties(); - // Ignore the error? - document->_info.saveToFile(document->path(), doSync); - } - - // closes all open compactors, journals, datafiles - document->close(); - return TRI_ERROR_NO_ERROR; -} diff --git a/arangod/VocBase/document-collection.h b/arangod/VocBase/document-collection.h deleted file mode 100644 index 4cf6103c8a..0000000000 --- a/arangod/VocBase/document-collection.h +++ /dev/null @@ -1,78 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -/// DISCLAIMER -/// -/// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany -/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany -/// -/// Licensed under the Apache License, Version 2.0 (the "License"); -/// you may not use this file except in compliance with the License. -/// You may obtain a copy of the License at -/// -/// http://www.apache.org/licenses/LICENSE-2.0 -/// -/// Unless required by applicable law or agreed to in writing, software -/// distributed under the License is distributed on an "AS IS" BASIS, -/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -/// See the License for the specific language governing permissions and -/// limitations under the License. -/// -/// Copyright holder is ArangoDB GmbH, Cologne, Germany -/// -/// @author Dr. Frank Celler -//////////////////////////////////////////////////////////////////////////////// - -#ifndef ARANGOD_VOC_BASE_DOCUMENT_COLLECTION_H -#define ARANGOD_VOC_BASE_DOCUMENT_COLLECTION_H 1 - -#include "Basics/Common.h" -#include "Basics/ReadWriteLock.h" -#include "Basics/StringRef.h" -#include "Cluster/ClusterInfo.h" -#include "VocBase/collection.h" -#include "VocBase/DatafileHelper.h" -#include "VocBase/DatafileStatistics.h" -#include "VocBase/Ditch.h" -#include "VocBase/MasterPointer.h" -#include "VocBase/MasterPointers.h" -#include "VocBase/voc-types.h" -#include "Wal/Marker.h" - -struct TRI_vocbase_t; - -namespace arangodb { -class Index; -struct OperationOptions; -class Transaction; -namespace velocypack { -class Builder; -class Slice; -} -namespace wal { -struct DocumentOperation; -} -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief document collection with global read-write lock -/// -/// A document collection is a collection with a single read-write lock. This -/// lock is used to coordinate the read and write transactions. -//////////////////////////////////////////////////////////////////////////////// - -struct TRI_document_collection_t : public TRI_collection_t { - TRI_document_collection_t(TRI_vocbase_t* vocbase) : TRI_collection_t(vocbase) {} -}; - -/// @brief creates a new collection -TRI_document_collection_t* TRI_CreateDocumentCollection( - TRI_vocbase_t*, arangodb::VocbaseCollectionInfo&, - TRI_voc_cid_t); - -/// @brief opens an existing collection -TRI_document_collection_t* TRI_OpenDocumentCollection(TRI_vocbase_t*, - TRI_vocbase_col_t*, bool); - -/// @brief closes an open collection -int TRI_CloseDocumentCollection(TRI_document_collection_t*, bool); - -#endif diff --git a/arangod/VocBase/replication-applier.cpp b/arangod/VocBase/replication-applier.cpp index 99da4063ad..2fa33b75bc 100644 --- a/arangod/VocBase/replication-applier.cpp +++ b/arangod/VocBase/replication-applier.cpp @@ -40,7 +40,6 @@ #include "StorageEngine/EngineSelectorFeature.h" #include "StorageEngine/StorageEngine.h" #include "VocBase/collection.h" -#include "VocBase/document-collection.h" #include "VocBase/transaction.h" #include "VocBase/vocbase.h" diff --git a/arangod/VocBase/replication-dump.cpp b/arangod/VocBase/replication-dump.cpp index 0760b1fdd4..1591553317 100644 --- a/arangod/VocBase/replication-dump.cpp +++ b/arangod/VocBase/replication-dump.cpp @@ -28,7 +28,7 @@ #include "VocBase/collection.h" #include "VocBase/DatafileHelper.h" #include "VocBase/datafile.h" -#include "VocBase/document-collection.h" +#include "VocBase/collection.h" #include "VocBase/vocbase.h" #include "Wal/Logfile.h" #include "Wal/LogfileManager.h" @@ -146,7 +146,7 @@ static void IterateDatafiles(std::vector const& datafiles, //////////////////////////////////////////////////////////////////////////////// static std::vector GetRangeDatafiles( - TRI_document_collection_t* document, TRI_voc_tick_t dataMin, + TRI_collection_t* document, TRI_voc_tick_t dataMin, TRI_voc_tick_t dataMax) { LOG(TRACE) << "getting datafiles in data range " << dataMin << " - " << dataMax; @@ -457,7 +457,7 @@ static bool MustReplicateWalMarker( //////////////////////////////////////////////////////////////////////////////// static int DumpCollection(TRI_replication_dump_t* dump, - TRI_document_collection_t* document, + TRI_collection_t* document, TRI_voc_tick_t databaseId, TRI_voc_cid_t collectionId, TRI_voc_tick_t dataMin, TRI_voc_tick_t dataMax, bool withTicks) { @@ -617,7 +617,7 @@ int TRI_DumpCollectionReplication(TRI_replication_dump_t* dump, auto customTypeHandler = dump->_transactionContext->orderCustomTypeHandler(); dump->_vpackOptions.customTypeHandler = customTypeHandler.get(); - TRI_document_collection_t* document = col->_collection; + TRI_collection_t* document = col->_collection; // create a barrier so the underlying collection is not unloaded auto b = document->ditches()->createReplicationDitch(__FILE__, __LINE__); diff --git a/arangod/VocBase/transaction.cpp b/arangod/VocBase/transaction.cpp index ef707bdbc0..f709f8d391 100644 --- a/arangod/VocBase/transaction.cpp +++ b/arangod/VocBase/transaction.cpp @@ -27,7 +27,6 @@ #include "Basics/Exceptions.h" #include "VocBase/DatafileHelper.h" #include "VocBase/collection.h" -#include "VocBase/document-collection.h" #include "VocBase/ticks.h" #include "Wal/DocumentOperation.h" #include "Wal/LogfileManager.h" diff --git a/arangod/VocBase/vocbase.cpp b/arangod/VocBase/vocbase.cpp index 5a0063714f..11f75d1451 100644 --- a/arangod/VocBase/vocbase.cpp +++ b/arangod/VocBase/vocbase.cpp @@ -41,7 +41,6 @@ #include "Basics/WriteLocker.h" #include "Basics/conversions.h" #include "Basics/files.h" -#include "Basics/hashes.h" #include "Basics/locks.h" #include "Basics/memory-map.h" #include "Basics/threads.h" @@ -54,8 +53,8 @@ #include "Utils/CursorRepository.h" #include "V8Server/v8-user-structures.h" #include "VocBase/Ditch.h" +#include "VocBase/collection.h" #include "VocBase/compactor.h" -#include "VocBase/document-collection.h" #include "VocBase/replication-applier.h" #include "VocBase/ticks.h" #include "VocBase/transaction.h" @@ -271,7 +270,7 @@ static bool UnloadCollectionCallback(TRI_collection_t* col, void* data) { return false; } - TRI_document_collection_t* document = collection->_collection; + TRI_collection_t* document = collection->_collection; TRI_ASSERT(document != nullptr); @@ -317,7 +316,7 @@ bool TRI_vocbase_t::DropCollectionCallback(TRI_collection_t* col, void* data) { // ............................................................................. if (collection->_collection != nullptr) { - TRI_document_collection_t* document = collection->_collection; + TRI_collection_t* document = collection->_collection; int res = TRI_CloseDocumentCollection(document, false); @@ -469,7 +468,7 @@ TRI_vocbase_col_t* TRI_vocbase_t::createCollectionWorker( } // ok, construct the collection - TRI_document_collection_t* document = nullptr; + TRI_collection_t* document = nullptr; try { document = TRI_CreateDocumentCollection(this, parameters, cid); } catch (...) { @@ -733,7 +732,7 @@ int TRI_vocbase_t::loadCollection(TRI_vocbase_col_t* collection, ignoreDatafileErrors = DatabaseFeature::DATABASE->ignoreDatafileErrors(); } - TRI_document_collection_t* document = nullptr; + TRI_collection_t* document = nullptr; try { document = TRI_OpenDocumentCollection(this, collection, ignoreDatafileErrors); } catch (...) { diff --git a/arangod/VocBase/vocbase.h b/arangod/VocBase/vocbase.h index 28fc3626c8..49e904a9f1 100644 --- a/arangod/VocBase/vocbase.h +++ b/arangod/VocBase/vocbase.h @@ -39,7 +39,6 @@ #include "velocypack/velocypack-aliases.h" struct TRI_collection_t; -struct TRI_document_collection_t; class TRI_replication_applier_t; class TRI_vocbase_col_t; @@ -537,7 +536,7 @@ class TRI_vocbase_col_t { arangodb::basics::ReadWriteLock _lock; // lock protecting the status and name TRI_vocbase_col_status_e _status; // status of the collection - TRI_document_collection_t* _collection; // NULL or pointer to loaded collection + TRI_collection_t* _collection; // NULL or pointer to loaded collection std::string const _dbName; // name of the database std::string _name; // name of the collection std::string const _path; // storage path diff --git a/arangod/Wal/CollectorThread.cpp b/arangod/Wal/CollectorThread.cpp index 6a60e10666..11896531ef 100644 --- a/arangod/Wal/CollectorThread.cpp +++ b/arangod/Wal/CollectorThread.cpp @@ -37,7 +37,7 @@ #include "Utils/StandaloneTransactionContext.h" #include "VocBase/DatafileHelper.h" #include "VocBase/DatafileStatistics.h" -#include "VocBase/document-collection.h" +#include "VocBase/collection.h" #include "Wal/Logfile.h" #include "Wal/LogfileManager.h" @@ -564,7 +564,7 @@ size_t CollectorThread::numQueuedOperations() { /// @brief process a single marker in collector step 2 void CollectorThread::processCollectionMarker( arangodb::SingleCollectionTransaction& trx, - TRI_document_collection_t* document, CollectorCache* cache, + TRI_collection_t* document, CollectorCache* cache, CollectorOperation const& operation) { auto const* walMarker = reinterpret_cast(operation.walPosition); TRI_ASSERT(walMarker != nullptr); @@ -635,7 +635,7 @@ int CollectorThread::processCollectionOperations(CollectorCache* cache) { TRI_ASSERT(collection != nullptr); - TRI_document_collection_t* document = collection->_collection; + TRI_collection_t* document = collection->_collection; // first try to read-lock the compactor-lock, afterwards try to write-lock the // collection @@ -860,7 +860,7 @@ int CollectorThread::transferMarkers(Logfile* logfile, TRI_vocbase_col_t* collection = collectionGuard.collection(); TRI_ASSERT(collection != nullptr); - TRI_document_collection_t* document = collection->_collection; + TRI_collection_t* document = collection->_collection; TRI_ASSERT(document != nullptr); LOG_TOPIC(TRACE, Logger::COLLECTOR) << "collector transferring markers for '" @@ -910,7 +910,7 @@ int CollectorThread::transferMarkers(Logfile* logfile, /// @brief transfer markers into a collection, actual work /// the collection must have been prepared to call this function -int CollectorThread::executeTransferMarkers(TRI_document_collection_t* document, +int CollectorThread::executeTransferMarkers(TRI_collection_t* document, CollectorCache* cache, OperationsType const& operations) { // used only for crash / recovery tests @@ -1020,7 +1020,7 @@ int CollectorThread::queueOperations(arangodb::wal::Logfile* logfile, /// @brief update a collection's datafile information int CollectorThread::updateDatafileStatistics( - TRI_document_collection_t* document, CollectorCache* cache) { + TRI_collection_t* document, CollectorCache* cache) { // iterate over all datafile infos and update the collection's datafile stats for (auto it = cache->dfi.begin(); it != cache->dfi.end(); /* no hoisting */) { @@ -1037,7 +1037,7 @@ int CollectorThread::updateDatafileStatistics( /// @brief sync all journals of a collection int CollectorThread::syncJournalCollection( - TRI_document_collection_t* document) { + TRI_collection_t* document) { TRI_IF_FAILURE("CollectorThread::syncDatafileCollection") { return TRI_ERROR_DEBUG; } @@ -1047,7 +1047,7 @@ int CollectorThread::syncJournalCollection( /// @brief get the next position for a marker of the specified size char* CollectorThread::nextFreeMarkerPosition( - TRI_document_collection_t* document, TRI_voc_tick_t tick, + TRI_collection_t* document, TRI_voc_tick_t tick, TRI_df_marker_type_t type, TRI_voc_size_t size, CollectorCache* cache) { // align the specified size @@ -1105,7 +1105,7 @@ char* CollectorThread::nextFreeMarkerPosition( /// @brief set the tick of a marker and calculate its CRC value void CollectorThread::finishMarker(char const* walPosition, char* datafilePosition, - TRI_document_collection_t* document, + TRI_collection_t* document, TRI_voc_tick_t tick, CollectorCache* cache) { TRI_df_marker_t* marker = reinterpret_cast(datafilePosition); diff --git a/arangod/Wal/CollectorThread.h b/arangod/Wal/CollectorThread.h index bce369cf37..c168e96777 100644 --- a/arangod/Wal/CollectorThread.h +++ b/arangod/Wal/CollectorThread.h @@ -35,9 +35,9 @@ #include "VocBase/voc-types.h" #include "Wal/Logfile.h" +struct TRI_collection_t; struct TRI_datafile_t; struct TRI_df_marker_t; -struct TRI_document_collection_t; namespace arangodb { namespace wal { @@ -175,7 +175,7 @@ class CollectorThread : public Thread { /// @brief process a single marker in collector step 2 void processCollectionMarker( arangodb::SingleCollectionTransaction&, - TRI_document_collection_t*, CollectorCache*, CollectorOperation const&); + TRI_collection_t*, CollectorCache*, CollectorOperation const&); /// @brief return the number of queued operations size_t numQueuedOperations(); @@ -197,25 +197,25 @@ class CollectorThread : public Thread { int64_t, OperationsType const&); /// @brief transfer markers into a collection - int executeTransferMarkers(TRI_document_collection_t*, CollectorCache*, + int executeTransferMarkers(TRI_collection_t*, CollectorCache*, OperationsType const&); /// @brief insert the collect operations into a per-collection queue int queueOperations(arangodb::wal::Logfile*, CollectorCache*&); /// @brief update a collection's datafile information - int updateDatafileStatistics(TRI_document_collection_t*, CollectorCache*); + int updateDatafileStatistics(TRI_collection_t*, CollectorCache*); /// @brief sync the journal of a collection - int syncJournalCollection(struct TRI_document_collection_t*); + int syncJournalCollection(TRI_collection_t*); /// @brief get the next free position for a new marker of the specified size - char* nextFreeMarkerPosition(struct TRI_document_collection_t*, + char* nextFreeMarkerPosition(TRI_collection_t*, TRI_voc_tick_t, TRI_df_marker_type_t, TRI_voc_size_t, CollectorCache*); /// @brief set the tick of a marker and calculate its CRC value - void finishMarker(char const*, char*, struct TRI_document_collection_t*, + void finishMarker(char const*, char*, TRI_collection_t*, TRI_voc_tick_t, CollectorCache*); private: diff --git a/arangod/Wal/DocumentOperation.h b/arangod/Wal/DocumentOperation.h index 5835aaed8d..2750a0cd23 100644 --- a/arangod/Wal/DocumentOperation.h +++ b/arangod/Wal/DocumentOperation.h @@ -3,7 +3,7 @@ #define ARANGOD_WAL_DOCUMENT_OPERATION_H 1 #include "Basics/Common.h" -#include "VocBase/document-collection.h" +#include "VocBase/collection.h" #include "VocBase/MasterPointers.h" #include "VocBase/voc-types.h" #include "Wal/Marker.h" diff --git a/arangod/Wal/RecoverState.cpp b/arangod/Wal/RecoverState.cpp index dbcfe060b9..f6fea16e39 100644 --- a/arangod/Wal/RecoverState.cpp +++ b/arangod/Wal/RecoverState.cpp @@ -206,7 +206,7 @@ TRI_vocbase_col_t* RecoverState::useCollection(TRI_vocbase_t* vocbase, return nullptr; } - TRI_document_collection_t* document = collection->_collection; + TRI_collection_t* document = collection->_collection; TRI_ASSERT(document != nullptr); // disable secondary indexes for the moment @@ -221,7 +221,7 @@ TRI_vocbase_col_t* RecoverState::useCollection(TRI_vocbase_t* vocbase, /// the collection will be opened after this call and inserted into a local /// cache for faster lookups /// returns nullptr if the collection does not exist -TRI_document_collection_t* RecoverState::getCollection( +TRI_collection_t* RecoverState::getCollection( TRI_voc_tick_t databaseId, TRI_voc_cid_t collectionId) { TRI_vocbase_t* vocbase = useDatabase(databaseId); @@ -238,7 +238,7 @@ TRI_document_collection_t* RecoverState::getCollection( return nullptr; } - TRI_document_collection_t* document = collection->_collection; + TRI_collection_t* document = collection->_collection; TRI_ASSERT(document != nullptr); return document; @@ -635,7 +635,7 @@ bool RecoverState::ReplayMarker(TRI_df_marker_t const* marker, void* data, return true; } - TRI_document_collection_t* document = + TRI_collection_t* document = state->getCollection(databaseId, collectionId); if (document == nullptr) { @@ -685,7 +685,7 @@ bool RecoverState::ReplayMarker(TRI_df_marker_t const* marker, void* data, return true; } - TRI_document_collection_t* document = + TRI_collection_t* document = state->getCollection(databaseId, collectionId); if (document == nullptr) { @@ -922,7 +922,7 @@ bool RecoverState::ReplayMarker(TRI_df_marker_t const* marker, void* data, return true; } - TRI_document_collection_t* document = + TRI_collection_t* document = state->getCollection(databaseId, collectionId); if (document == nullptr) { // if the underlying collection gone, we can go on @@ -1145,7 +1145,7 @@ int RecoverState::fillIndexes() { for (auto it = openedCollections.begin(); it != openedCollections.end(); ++it) { TRI_vocbase_col_t* collection = (*it).second; - TRI_document_collection_t* document = collection->_collection; + TRI_collection_t* document = collection->_collection; TRI_ASSERT(document != nullptr); diff --git a/arangod/Wal/RecoverState.h b/arangod/Wal/RecoverState.h index 3e5cad2b1b..bfff50fb6b 100644 --- a/arangod/Wal/RecoverState.h +++ b/arangod/Wal/RecoverState.h @@ -27,13 +27,14 @@ #include "Basics/Common.h" #include "Utils/SingleCollectionTransaction.h" #include "VocBase/datafile.h" -#include "VocBase/document-collection.h" #include "VocBase/ticks.h" #include "VocBase/voc-types.h" #include "VocBase/vocbase.h" #include "Wal/Logfile.h" #include "Wal/Marker.h" +struct TRI_collection_t; + namespace arangodb { class DatabaseFeature; @@ -124,7 +125,7 @@ struct RecoverState { /// the collection will be opened after this call and inserted into a local /// cache for faster lookups /// returns nullptr if the collection does not exist - TRI_document_collection_t* getCollection(TRI_voc_tick_t, TRI_voc_cid_t); + TRI_collection_t* getCollection(TRI_voc_tick_t, TRI_voc_cid_t); /// @brief executes a single operation inside a transaction int executeSingleOperation(