diff options
author | Xiangyu Yao <xiangyu.yao@mongodb.com> | 2018-11-28 19:12:16 -0500 |
---|---|---|
committer | Xiangyu Yao <xiangyu.yao@mongodb.com> | 2018-11-30 13:05:09 -0500 |
commit | e0be8ba5aa04df21f6a9a42578a349a4c303776d (patch) | |
tree | 24308277dda3cf06f4870761beb9a817c1f511fd | |
parent | 839d887bbb5c857c80ad50eb329c0017cb69190d (diff) | |
download | mongo-e0be8ba5aa04df21f6a9a42578a349a4c303776d.tar.gz |
SERVER-35732 Fix dbStats.fsUsedSize behavior for database with hyphenated names
-rw-r--r-- | src/mongo/db/catalog/database_impl.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/storage/kv/kv_catalog.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/storage/kv/kv_catalog.h | 2 | ||||
-rw-r--r-- | src/mongo/db/storage/kv/kv_storage_engine.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/storage/kv/kv_storage_engine.h | 2 | ||||
-rw-r--r-- | src/mongo/db/storage/storage_engine.h | 5 |
6 files changed, 23 insertions, 5 deletions
diff --git a/src/mongo/db/catalog/database_impl.cpp b/src/mongo/db/catalog/database_impl.cpp index ad4bc521df3..a203366a869 100644 --- a/src/mongo/db/catalog/database_impl.cpp +++ b/src/mongo/db/catalog/database_impl.cpp @@ -448,11 +448,8 @@ void DatabaseImpl::getStats(OperationContext* opCtx, BSONObjBuilder* output, dou _dbEntry->appendExtraStats(opCtx, output, scale); if (!opCtx->getServiceContext()->getStorageEngine()->isEphemeral()) { - boost::filesystem::path dbpath(storageGlobalParams.dbpath); - if (storageGlobalParams.directoryperdb) { - dbpath /= _name; - } - + boost::filesystem::path dbpath( + opCtx->getServiceContext()->getStorageEngine()->getFilesystemPathForDb(_name)); boost::system::error_code ec; boost::filesystem::space_info spaceInfo = boost::filesystem::space(dbpath, ec); if (!ec) { diff --git a/src/mongo/db/storage/kv/kv_catalog.cpp b/src/mongo/db/storage/kv/kv_catalog.cpp index 28736f8598e..b28f509e80a 100644 --- a/src/mongo/db/storage/kv/kv_catalog.cpp +++ b/src/mongo/db/storage/kv/kv_catalog.cpp @@ -347,6 +347,14 @@ std::string KVCatalog::newTempIdent() { return buf.str(); } +std::string KVCatalog::getFilesystemPathForDb(const std::string& dbName) const { + if (_directoryPerDb) { + return storageGlobalParams.dbpath + '/' + escapeDbName(dbName); + } else { + return storageGlobalParams.dbpath; + } +} + std::string KVCatalog::_newUniqueIdent(StringData ns, const char* kind) { // If this changes to not put _rand at the end, _hasEntryCollidingWithRand will need fixing. StringBuilder buf; diff --git a/src/mongo/db/storage/kv/kv_catalog.h b/src/mongo/db/storage/kv/kv_catalog.h index bc99e4e1e7c..fe670d3795a 100644 --- a/src/mongo/db/storage/kv/kv_catalog.h +++ b/src/mongo/db/storage/kv/kv_catalog.h @@ -113,6 +113,8 @@ public: */ StatusWith<std::string> newOrphanedIdent(OperationContext* opCtx, std::string ident); + std::string getFilesystemPathForDb(const std::string& dbName) const; + /** * Generate a temporary ident name. */ diff --git a/src/mongo/db/storage/kv/kv_storage_engine.cpp b/src/mongo/db/storage/kv/kv_storage_engine.cpp index 7738d4eb160..11f4d4f125d 100644 --- a/src/mongo/db/storage/kv/kv_storage_engine.cpp +++ b/src/mongo/db/storage/kv/kv_storage_engine.cpp @@ -455,6 +455,10 @@ KVStorageEngine::reconcileCatalogAndIdents(OperationContext* opCtx) { return ret; } +std::string KVStorageEngine::getFilesystemPathForDb(const std::string& dbName) const { + return _catalog->getFilesystemPathForDb(dbName); +} + void KVStorageEngine::cleanShutdown() { for (DBMap::const_iterator it = _dbs.begin(); it != _dbs.end(); ++it) { delete it->second; diff --git a/src/mongo/db/storage/kv/kv_storage_engine.h b/src/mongo/db/storage/kv/kv_storage_engine.h index 4da67bc631f..0b33e837e40 100644 --- a/src/mongo/db/storage/kv/kv_storage_engine.h +++ b/src/mongo/db/storage/kv/kv_storage_engine.h @@ -187,6 +187,8 @@ public: StatusWith<std::vector<StorageEngine::CollectionIndexNamePair>> reconcileCatalogAndIdents( OperationContext* opCtx) override; + std::string getFilesystemPathForDb(const std::string& dbName) const override; + /** * When loading after an unclean shutdown, this performs cleanup on the KVCatalog and unsets the * startingAfterUncleanShutdown decoration on the global ServiceContext. diff --git a/src/mongo/db/storage/storage_engine.h b/src/mongo/db/storage/storage_engine.h index 7d5c5309fcc..170f6aecbf1 100644 --- a/src/mongo/db/storage/storage_engine.h +++ b/src/mongo/db/storage/storage_engine.h @@ -484,6 +484,11 @@ public: * a no-op implementation. */ virtual Timestamp getOldestOpenReadTimestamp() const = 0; + + /** + * Returns the path to the directory which has the data files of database with `dbName`. + */ + virtual std::string getFilesystemPathForDb(const std::string& dbName) const = 0; }; } // namespace mongo |