diff options
Diffstat (limited to 'src/mongo/db/storage/storage_util.cpp')
| -rw-r--r-- | src/mongo/db/storage/storage_util.cpp | 99 |
1 files changed, 41 insertions, 58 deletions
diff --git a/src/mongo/db/storage/storage_util.cpp b/src/mongo/db/storage/storage_util.cpp index 30623a36aa0..0dace14bfd2 100644 --- a/src/mongo/db/storage/storage_util.cpp +++ b/src/mongo/db/storage/storage_util.cpp @@ -47,49 +47,40 @@ namespace mongo { namespace catalog { namespace { -auto removeEmptyDirectory = - [](ServiceContext* svcCtx, StorageEngine* storageEngine, const NamespaceString& ns) { - // Nothing to do if not using directoryperdb or there are still collections in the database. - // If we don't support supportsPendingDrops then this is executing before the collection is - // removed from the catalog. In that case, just blindly attempt to delete the directory, it - // will only succeed if it is empty which is the behavior we want. - auto collectionCatalog = CollectionCatalog::get(svcCtx); - const TenantDatabaseName tenantDbName(boost::none, ns.db()); - if (!storageEngine->isUsingDirectoryPerDb() || - (storageEngine->supportsPendingDrops() && - !collectionCatalog->range(tenantDbName).empty())) { - return; - } +auto removeEmptyDirectory = [](ServiceContext* svcCtx, + StorageEngine* storageEngine, + const NamespaceString& ns) { + // Nothing to do if not using directoryperdb or there are still collections in the database. + // If we don't support supportsPendingDrops then this is executing before the collection is + // removed from the catalog. In that case, just blindly attempt to delete the directory, it + // will only succeed if it is empty which is the behavior we want. + auto collectionCatalog = CollectionCatalog::get(svcCtx); + const TenantDatabaseName tenantDbName(boost::none, ns.db()); + if (!storageEngine->isUsingDirectoryPerDb() || + (storageEngine->supportsPendingDrops() && + collectionCatalog->begin(nullptr, tenantDbName) != collectionCatalog->end(nullptr))) { + return; + } - boost::system::error_code ec; - boost::filesystem::remove(storageEngine->getFilesystemPathForDb(tenantDbName), ec); - - if (!ec) { - LOGV2(4888200, "Removed empty database directory", "db"_attr = tenantDbName.dbName()); - } else if (collectionCatalog->range(tenantDbName).empty()) { - // It is possible for a new collection to be created in the database between when we - // check whether the database is empty and actually attempting to remove the directory. - // In this case, don't log that the removal failed because it is expected. However, - // since we attempt to remove the directory for both the collection and index ident - // drops, once the database is empty it will be still logged until the final of these - // ident drops occurs. - LOGV2_DEBUG(4888201, - 1, - "Failed to remove database directory", - "db"_attr = tenantDbName.dbName(), - "error"_attr = ec.message()); - } - }; - -BSONObj toBSON(const stdx::variant<Timestamp, StorageEngine::CheckpointIteration>& x) { - return stdx::visit(visit_helper::Overloaded{[](const Timestamp& ts) { return ts.toBSON(); }, - [](const StorageEngine::CheckpointIteration& iter) { - auto underlyingValue = uint64_t{iter}; - return BSON("checkpointIteration" - << std::to_string(underlyingValue)); - }}, - x); -} + boost::system::error_code ec; + boost::filesystem::remove(storageEngine->getFilesystemPathForDb(tenantDbName), ec); + + if (!ec) { + LOGV2(4888200, "Removed empty database directory", "db"_attr = tenantDbName.dbName()); + } else if (collectionCatalog->begin(nullptr, tenantDbName) == collectionCatalog->end(nullptr)) { + // It is possible for a new collection to be created in the database between when we + // check whether the database is empty and actually attempting to remove the directory. + // In this case, don't log that the removal failed because it is expected. However, + // since we attempt to remove the directory for both the collection and index ident + // drops, once the database is empty it will be still logged until the final of these + // ident drops occurs. + LOGV2_DEBUG(4888201, + 1, + "Failed to remove database directory", + "db"_attr = tenantDbName.dbName(), + "error"_attr = ec.message()); + } +}; } // namespace void removeIndex(OperationContext* opCtx, @@ -132,13 +123,9 @@ void removeIndex(OperationContext* opCtx, }; if (storageEngine->supportsPendingDrops()) { - stdx::variant<Timestamp, StorageEngine::CheckpointIteration> dropTime; if (!commitTimestamp) { - // Standalone mode and unreplicated drops will not provide a timestamp. Use the - // checkpoint iteration instead. - dropTime = storageEngine->getEngine()->getCheckpointIteration(); - } else { - dropTime = *commitTimestamp; + // Standalone mode will not provide a timestamp. + commitTimestamp = Timestamp::min(); } LOGV2(22206, "Deferring table drop for index", @@ -146,8 +133,8 @@ void removeIndex(OperationContext* opCtx, logAttrs(nss), "uuid"_attr = uuid, "ident"_attr = ident->getIdent(), - "dropTime"_attr = toBSON(dropTime)); - storageEngine->addDropPendingIdent(dropTime, ident, std::move(onDrop)); + "commitTimestamp"_attr = commitTimestamp); + storageEngine->addDropPendingIdent(*commitTimestamp, ident, std::move(onDrop)); } else { // Intentionally ignoring failure here. Since we've removed the metadata pointing to // the collection, we should never see it again anyway. @@ -190,20 +177,16 @@ Status dropCollection(OperationContext* opCtx, }; if (storageEngine->supportsPendingDrops()) { - stdx::variant<Timestamp, StorageEngine::CheckpointIteration> dropTime; if (!commitTimestamp) { - // Standalone mode and unreplicated drops will not provide a timestamp. Use the - // checkpoint iteration instead. - dropTime = storageEngine->getEngine()->getCheckpointIteration(); - } else { - dropTime = *commitTimestamp; + // Standalone mode will not provide a timestamp. + commitTimestamp = Timestamp::min(); } LOGV2(22214, "Deferring table drop for collection", logAttrs(nss), "ident"_attr = ident->getIdent(), - "dropTime"_attr = toBSON(dropTime)); - storageEngine->addDropPendingIdent(dropTime, ident, std::move(onDrop)); + "commitTimestamp"_attr = commitTimestamp); + storageEngine->addDropPendingIdent(*commitTimestamp, ident, std::move(onDrop)); } else { // Intentionally ignoring failure here. Since we've removed the metadata pointing to // the collection, we should never see it again anyway. |
