From 672255fad712b843df6b09619461a23864e7b1b5 Mon Sep 17 00:00:00 2001 From: jsteemann Date: Tue, 30 Aug 2016 13:01:34 +0200 Subject: [PATCH] removed some TRI_collection_t instances --- .../StorageEngine/MMFilesCleanupThread.cpp | 23 ++++++++----------- arangod/StorageEngine/MMFilesCleanupThread.h | 4 +--- .../StorageEngine/MMFilesCompactorThread.cpp | 8 +++---- .../StorageEngine/MMFilesCompactorThread.h | 4 +--- arangod/StorageEngine/MMFilesEngine.cpp | 20 ++++------------ arangod/Utils/CollectionKeys.h | 1 - arangod/Utils/Transaction.h | 2 -- arangod/VocBase/LogicalCollection.h | 1 + arangod/Wal/CollectorThread.h | 2 -- arangod/Wal/RecoverState.h | 2 -- 10 files changed, 19 insertions(+), 48 deletions(-) diff --git a/arangod/StorageEngine/MMFilesCleanupThread.cpp b/arangod/StorageEngine/MMFilesCleanupThread.cpp index 509b234035..f266dfc2e1 100644 --- a/arangod/StorageEngine/MMFilesCleanupThread.cpp +++ b/arangod/StorageEngine/MMFilesCleanupThread.cpp @@ -84,19 +84,14 @@ void MMFilesCleanupThread::run() { for (auto& collection : collections) { TRI_ASSERT(collection != nullptr); - TRI_collection_t* document = nullptr; { READ_LOCKER(readLocker, collection->_lock); - document = collection->_collection; + if (collection->_collection == nullptr) { + // collection currently not loaded + continue; + } } - if (document == nullptr) { - // collection currently not loaded - continue; - } - - TRI_ASSERT(document != nullptr); - // we're the only ones that can unload the collection, so using // the collection pointer outside the lock is ok @@ -106,7 +101,7 @@ void MMFilesCleanupThread::run() { collection->cleanupIndexes(); } - cleanupCollection(collection, document); + cleanupCollection(collection); } }, false); @@ -149,18 +144,18 @@ void MMFilesCleanupThread::cleanupCursors(bool force) { } /// @brief checks all datafiles of a collection -void MMFilesCleanupThread::cleanupCollection(arangodb::LogicalCollection* collection, - TRI_collection_t* document) { +void MMFilesCleanupThread::cleanupCollection(arangodb::LogicalCollection* collection) { // unload operations can normally only be executed when a collection is fully // garbage collected bool unloadChecked = false; // but if we are in server shutdown, we can force unloading of collections bool isInShutdown = application_features::ApplicationServer::isStopping(); - - TRI_ASSERT(document != nullptr); + + TRI_collection_t* document = collection->_collection; // loop until done + while (true) { auto ditches = document->ditches(); diff --git a/arangod/StorageEngine/MMFilesCleanupThread.h b/arangod/StorageEngine/MMFilesCleanupThread.h index d0d2fe7202..e2678cb985 100644 --- a/arangod/StorageEngine/MMFilesCleanupThread.h +++ b/arangod/StorageEngine/MMFilesCleanupThread.h @@ -28,7 +28,6 @@ #include "Basics/ConditionVariable.h" #include "Basics/Thread.h" -struct TRI_collection_t; struct TRI_vocbase_t; namespace arangodb { @@ -58,8 +57,7 @@ class MMFilesCleanupThread final : public Thread { void cleanupCursors(bool force); /// @brief checks all datafiles of a collection - void cleanupCollection(arangodb::LogicalCollection* collection, - TRI_collection_t* document); + void cleanupCollection(arangodb::LogicalCollection* collection); private: TRI_vocbase_t* _vocbase; diff --git a/arangod/StorageEngine/MMFilesCompactorThread.cpp b/arangod/StorageEngine/MMFilesCompactorThread.cpp index 1395a8074c..79fe335cd3 100644 --- a/arangod/StorageEngine/MMFilesCompactorThread.cpp +++ b/arangod/StorageEngine/MMFilesCompactorThread.cpp @@ -347,7 +347,6 @@ void MMFilesCompactorThread::compactDatafiles(LogicalCollection* collection, TRI_voc_fid_t const targetFid = context._compactor->fid(); TRI_df_marker_type_t const type = marker->getType(); - TRI_collection_t* document = collection->_collection; // new or updated document if (type == TRI_DF_MARKER_VPACK_DOCUMENT) { @@ -372,7 +371,7 @@ void MMFilesCompactorThread::compactDatafiles(LogicalCollection* collection, // write to compactor files TRI_df_marker_t* result; - int res = copyMarker(document, context._compactor, marker, &result); + int res = copyMarker(context._compactor, marker, &result); if (res != TRI_ERROR_NO_ERROR) { // TODO: dont fail but recover from this state @@ -400,7 +399,7 @@ void MMFilesCompactorThread::compactDatafiles(LogicalCollection* collection, if (context._keepDeletions) { // write to compactor files TRI_df_marker_t* result; - int res = copyMarker(document, context._compactor, marker, &result); + int res = copyMarker(context._compactor, marker, &result); if (res != TRI_ERROR_NO_ERROR) { // TODO: dont fail but recover from this state @@ -970,8 +969,7 @@ uint64_t MMFilesCompactorThread::getNumberOfDocuments(LogicalCollection* collect } /// @brief write a copy of the marker into the datafile -int MMFilesCompactorThread::copyMarker(TRI_collection_t* document, - TRI_datafile_t* compactor, TRI_df_marker_t const* marker, +int MMFilesCompactorThread::copyMarker(TRI_datafile_t* compactor, TRI_df_marker_t const* marker, TRI_df_marker_t** result) { int res = compactor->reserveElement(marker->getSize(), result, 0); diff --git a/arangod/StorageEngine/MMFilesCompactorThread.h b/arangod/StorageEngine/MMFilesCompactorThread.h index 323b0f338f..2a9c02e294 100644 --- a/arangod/StorageEngine/MMFilesCompactorThread.h +++ b/arangod/StorageEngine/MMFilesCompactorThread.h @@ -29,7 +29,6 @@ #include "Basics/Thread.h" #include "VocBase/voc-types.h" -struct TRI_collection_t; struct TRI_datafile_t; struct TRI_df_marker_t; struct TRI_vocbase_t; @@ -94,8 +93,7 @@ class MMFilesCompactorThread final : public Thread { uint64_t getNumberOfDocuments(LogicalCollection* collection); /// @brief write a copy of the marker into the datafile - int copyMarker(TRI_collection_t* document, - TRI_datafile_t* compactor, TRI_df_marker_t const* marker, + int copyMarker(TRI_datafile_t* compactor, TRI_df_marker_t const* marker, TRI_df_marker_t** result); /// @brief wait time between compaction runs when idle diff --git a/arangod/StorageEngine/MMFilesEngine.cpp b/arangod/StorageEngine/MMFilesEngine.cpp index 234308c7d6..9d1713a40d 100644 --- a/arangod/StorageEngine/MMFilesEngine.cpp +++ b/arangod/StorageEngine/MMFilesEngine.cpp @@ -1227,30 +1227,18 @@ TRI_vocbase_t* MMFilesEngine::openExistingDatabase(TRI_voc_tick_t id, std::strin for (auto const& it : VPackArrayIterator(slice)) { // we found a collection that is still active // FIXME Check if it is correct to free the collection here - std::unique_ptr c; - TRI_ASSERT(!it.get("cid").isNone()); - try { - c.reset(StorageEngine::registerCollection(ConditionalWriteLocker::DoLock(), - vocbase.get(), it)); - } catch (...) { - // if we caught an exception, c is still a nullptr - } + arangodb::LogicalCollection* collection = StorageEngine::registerCollection(ConditionalWriteLocker::DoLock(), vocbase.get(), it); - if (c == nullptr) { - LOG(ERR) << "failed to add document collection '" << it.get("name").copyString() << "'"; - THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_CORRUPTED_COLLECTION); - } - - registerCollectionPath(vocbase->id(), c->cid(), c->path()); + registerCollectionPath(vocbase->id(), collection->cid(), collection->path()); if (!wasCleanShutdown) { // iterating markers may be time-consuming. we'll only do it if // we have to - findMaxTickInJournals(c->path()); + findMaxTickInJournals(collection->path()); } - LOG(DEBUG) << "added document collection '" << c->name() << "'"; + LOG(DEBUG) << "added document collection '" << collection->name() << "'"; } // start cleanup thread diff --git a/arangod/Utils/CollectionKeys.h b/arangod/Utils/CollectionKeys.h index 31f40746c7..c1eb4d7e29 100644 --- a/arangod/Utils/CollectionKeys.h +++ b/arangod/Utils/CollectionKeys.h @@ -33,7 +33,6 @@ #include struct TRI_df_marker_t; -struct TRI_collection_t; struct TRI_vocbase_t; namespace arangodb { diff --git a/arangod/Utils/Transaction.h b/arangod/Utils/Transaction.h index 94508dceab..22c4ff8a4b 100644 --- a/arangod/Utils/Transaction.h +++ b/arangod/Utils/Transaction.h @@ -42,8 +42,6 @@ class Transaction; } #endif -struct TRI_collection_t; - namespace arangodb { namespace basics { diff --git a/arangod/VocBase/LogicalCollection.h b/arangod/VocBase/LogicalCollection.h index 95565bbc4b..a8801c8876 100644 --- a/arangod/VocBase/LogicalCollection.h +++ b/arangod/VocBase/LogicalCollection.h @@ -33,6 +33,7 @@ #include +struct TRI_collection_t; struct TRI_datafile_t; struct TRI_df_marker_t; diff --git a/arangod/Wal/CollectorThread.h b/arangod/Wal/CollectorThread.h index bf0901538a..5a19fe45ee 100644 --- a/arangod/Wal/CollectorThread.h +++ b/arangod/Wal/CollectorThread.h @@ -35,8 +35,6 @@ #include "Wal/CollectorCache.h" #include "Wal/Logfile.h" -struct TRI_collection_t; - namespace arangodb { class LogicalCollection; diff --git a/arangod/Wal/RecoverState.h b/arangod/Wal/RecoverState.h index a23823d147..f993d603e1 100644 --- a/arangod/Wal/RecoverState.h +++ b/arangod/Wal/RecoverState.h @@ -33,8 +33,6 @@ #include "Wal/Logfile.h" #include "Wal/Marker.h" -struct TRI_collection_t; - namespace arangodb { class DatabaseFeature;