summaryrefslogtreecommitdiff
path: root/src/mongo/db/storage
diff options
context:
space:
mode:
authorGeert Bosch <geert@mongodb.com>2019-04-17 16:18:22 -0400
committerGeert Bosch <geert@mongodb.com>2019-04-26 16:18:38 -0400
commit8cbbba49935f632e876037f9f2d9eecc779eb96a (patch)
treef1b4416f63dd87ed97223751c2c0d4eff4063628 /src/mongo/db/storage
parent93dd23880759430872510ef0b539e746192e44e2 (diff)
downloadmongo-8cbbba49935f632e876037f9f2d9eecc779eb96a.tar.gz
SERVER-40724 Change namespace arguments to use NamespaceString
Diffstat (limited to 'src/mongo/db/storage')
-rw-r--r--src/mongo/db/storage/kv/kv_catalog.cpp117
-rw-r--r--src/mongo/db/storage/kv/kv_catalog.h39
-rw-r--r--src/mongo/db/storage/kv/kv_catalog_test_fixture.h5
-rw-r--r--src/mongo/db/storage/kv/kv_collection_catalog_entry.cpp30
-rw-r--r--src/mongo/db/storage/kv/kv_engine.h4
-rw-r--r--src/mongo/db/storage/kv/kv_engine_test_harness.cpp73
-rw-r--r--src/mongo/db/storage/kv/kv_storage_engine.cpp31
-rw-r--r--src/mongo/db/storage/kv/kv_storage_engine.h2
-rw-r--r--src/mongo/db/storage/kv/kv_storage_engine_test.cpp6
-rw-r--r--src/mongo/db/storage/kv/kv_storage_engine_test_fixture.h13
-rw-r--r--src/mongo/db/storage/storage_engine.h2
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp10
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h2
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp22
14 files changed, 185 insertions, 171 deletions
diff --git a/src/mongo/db/storage/kv/kv_catalog.cpp b/src/mongo/db/storage/kv/kv_catalog.cpp
index 534a83c9e40..69b39c30192 100644
--- a/src/mongo/db/storage/kv/kv_catalog.cpp
+++ b/src/mongo/db/storage/kv/kv_catalog.cpp
@@ -361,11 +361,11 @@ std::string KVCatalog::getFilesystemPathForDb(const std::string& dbName) const {
}
}
-std::string KVCatalog::_newUniqueIdent(StringData ns, const char* kind) {
+std::string KVCatalog::_newUniqueIdent(const NamespaceString& nss, const char* kind) {
// If this changes to not put _rand at the end, _hasEntryCollidingWithRand will need fixing.
StringBuilder buf;
if (_directoryPerDb) {
- buf << escapeDbName(nsToDatabaseSubstring(ns)) << '/';
+ buf << escapeDbName(nss.db()) << '/';
}
buf << kind;
buf << (_directoryForIndexes ? '/' : '-');
@@ -407,11 +407,13 @@ void KVCatalog::init(OperationContext* opCtx) {
}
}
-void KVCatalog::getAllCollections(std::vector<std::string>* out) const {
+std::vector<NamespaceString> KVCatalog::getAllCollections() const {
stdx::lock_guard<stdx::mutex> lk(_identsLock);
+ std::vector<NamespaceString> result;
for (NSToIdentMap::const_iterator it = _idents.begin(); it != _idents.end(); ++it) {
- out->push_back(it->first);
+ result.push_back(NamespaceString(it->first));
}
+ return result;
}
Status KVCatalog::_addEntry(OperationContext* opCtx,
@@ -420,7 +422,7 @@ Status KVCatalog::_addEntry(OperationContext* opCtx,
KVPrefix prefix) {
invariant(opCtx->lockState()->isDbLockedForMode(nss.db(), MODE_IX));
- const string ident = _newUniqueIdent(nss.ns(), "collection");
+ const string ident = _newUniqueIdent(nss, "collection");
stdx::lock_guard<stdx::mutex> lk(_identsLock);
Entry& old = _idents[nss.toString()];
@@ -451,31 +453,33 @@ Status KVCatalog::_addEntry(OperationContext* opCtx,
return Status::OK();
}
-std::string KVCatalog::getCollectionIdent(StringData ns) const {
+std::string KVCatalog::getCollectionIdent(const NamespaceString& nss) const {
stdx::lock_guard<stdx::mutex> lk(_identsLock);
- NSToIdentMap::const_iterator it = _idents.find(ns.toString());
+ NSToIdentMap::const_iterator it = _idents.find(nss.toString());
invariant(it != _idents.end());
return it->second.ident;
}
std::string KVCatalog::getIndexIdent(OperationContext* opCtx,
- StringData ns,
+ const NamespaceString& nss,
StringData idxName) const {
- BSONObj obj = _findEntry(opCtx, ns);
+ BSONObj obj = _findEntry(opCtx, nss);
BSONObj idxIdent = obj["idxIdent"].Obj();
return idxIdent[idxName].String();
}
-BSONObj KVCatalog::_findEntry(OperationContext* opCtx, StringData ns, RecordId* out) const {
+BSONObj KVCatalog::_findEntry(OperationContext* opCtx,
+ const NamespaceString& nss,
+ RecordId* out) const {
RecordId dl;
{
stdx::lock_guard<stdx::mutex> lk(_identsLock);
- NSToIdentMap::const_iterator it = _idents.find(ns.toString());
- invariant(it != _idents.end(), str::stream() << "Did not find collection. Ns: " << ns);
+ NSToIdentMap::const_iterator it = _idents.find(nss.toString());
+ invariant(it != _idents.end(), str::stream() << "Did not find collection. Ns: " << nss);
dl = it->second.storedLoc;
}
- LOG(3) << "looking up metadata for: " << ns << " @ " << dl;
+ LOG(3) << "looking up metadata for: " << nss << " @ " << dl;
RecordData data;
if (!_rs->findRecord(opCtx, dl, &data)) {
// since the in memory meta data isn't managed with mvcc
@@ -491,8 +495,8 @@ BSONObj KVCatalog::_findEntry(OperationContext* opCtx, StringData ns, RecordId*
}
BSONCollectionCatalogEntry::MetaData KVCatalog::getMetaData(OperationContext* opCtx,
- StringData ns) const {
- BSONObj obj = _findEntry(opCtx, ns);
+ const NamespaceString& nss) const {
+ BSONObj obj = _findEntry(opCtx, nss);
LOG(3) << " fetched CCE metadata: " << obj;
BSONCollectionCatalogEntry::MetaData md;
const BSONElement mdElement = obj["md"];
@@ -504,10 +508,10 @@ BSONCollectionCatalogEntry::MetaData KVCatalog::getMetaData(OperationContext* op
}
void KVCatalog::putMetaData(OperationContext* opCtx,
- StringData ns,
+ const NamespaceString& nss,
BSONCollectionCatalogEntry::MetaData& md) {
RecordId loc;
- BSONObj obj = _findEntry(opCtx, ns, &loc);
+ BSONObj obj = _findEntry(opCtx, nss, &loc);
{
// rebuilt doc
@@ -528,7 +532,7 @@ void KVCatalog::putMetaData(OperationContext* opCtx,
continue;
}
// missing, create new
- newIdentMap.append(name, _newUniqueIdent(ns, "index"));
+ newIdentMap.append(name, _newUniqueIdent(nss, "index"));
}
b.append("idxIdent", newIdentMap.obj());
@@ -543,19 +547,19 @@ void KVCatalog::putMetaData(OperationContext* opCtx,
}
Status KVCatalog::_replaceEntry(OperationContext* opCtx,
- StringData fromNS,
- StringData toNS,
+ const NamespaceString& fromNss,
+ const NamespaceString& toNss,
bool stayTemp) {
RecordId loc;
- BSONObj old = _findEntry(opCtx, fromNS, &loc).getOwned();
+ BSONObj old = _findEntry(opCtx, fromNss, &loc).getOwned();
{
BSONObjBuilder b;
- b.append("ns", toNS);
+ b.append("ns", toNss.ns());
BSONCollectionCatalogEntry::MetaData md;
md.parse(old["md"].Obj());
- md.rename(toNS);
+ md.rename(toNss.ns());
if (!stayTemp)
md.options.temp = false;
b.append("md", md.toBSON());
@@ -568,29 +572,30 @@ Status KVCatalog::_replaceEntry(OperationContext* opCtx,
}
stdx::lock_guard<stdx::mutex> lk(_identsLock);
- const NSToIdentMap::iterator fromIt = _idents.find(fromNS.toString());
+ const NSToIdentMap::iterator fromIt = _idents.find(fromNss.toString());
invariant(fromIt != _idents.end());
- opCtx->recoveryUnit()->registerChange(new RemoveIdentChange(this, fromNS, fromIt->second));
- opCtx->recoveryUnit()->registerChange(new AddIdentChange(this, toNS));
+ opCtx->recoveryUnit()->registerChange(
+ new RemoveIdentChange(this, fromNss.ns(), fromIt->second));
+ opCtx->recoveryUnit()->registerChange(new AddIdentChange(this, toNss.ns()));
_idents.erase(fromIt);
- _idents[toNS.toString()] = Entry(old["ident"].String(), loc);
+ _idents[toNss.toString()] = Entry(old["ident"].String(), loc);
return Status::OK();
}
-Status KVCatalog::_removeEntry(OperationContext* opCtx, StringData ns) {
- invariant(opCtx->lockState()->isCollectionLockedForMode(NamespaceString(ns), MODE_X));
+Status KVCatalog::_removeEntry(OperationContext* opCtx, const NamespaceString& nss) {
+ invariant(opCtx->lockState()->isCollectionLockedForMode(nss, MODE_X));
stdx::lock_guard<stdx::mutex> lk(_identsLock);
- const NSToIdentMap::iterator it = _idents.find(ns.toString());
+ const NSToIdentMap::iterator it = _idents.find(nss.toString());
if (it == _idents.end()) {
return Status(ErrorCodes::NamespaceNotFound, "collection not found");
}
- opCtx->recoveryUnit()->registerChange(new RemoveIdentChange(this, ns, it->second));
+ opCtx->recoveryUnit()->registerChange(new RemoveIdentChange(this, nss.ns(), it->second));
- LOG(1) << "deleting metadata for " << ns << " @ " << it->second.storedLoc;
+ LOG(1) << "deleting metadata for " << nss << " @ " << it->second.storedLoc;
_rs->deleteRecord(opCtx, it->second.storedLoc);
_idents.erase(it);
@@ -702,14 +707,16 @@ StatusWith<std::string> KVCatalog::newOrphanedIdent(OperationContext* opCtx, std
return StatusWith<std::string>(std::move(ns));
}
-void KVCatalog::initCollection(OperationContext* opCtx, const std::string& ns, bool forRepair) {
- BSONCollectionCatalogEntry::MetaData md = getMetaData(opCtx, ns);
+void KVCatalog::initCollection(OperationContext* opCtx,
+ const NamespaceString& nss,
+ bool forRepair) {
+ BSONCollectionCatalogEntry::MetaData md = getMetaData(opCtx, nss);
uassert(ErrorCodes::MustDowngrade,
- str::stream() << "Collection does not have UUID in KVCatalog. Collection: " << ns,
+ str::stream() << "Collection does not have UUID in KVCatalog. Collection: " << nss,
md.options.uuid);
auto uuid = md.options.uuid.get();
- auto ident = getCollectionIdent(ns);
+ auto ident = getCollectionIdent(nss);
std::unique_ptr<RecordStore> rs;
if (forRepair) {
@@ -717,21 +724,21 @@ void KVCatalog::initCollection(OperationContext* opCtx, const std::string& ns, b
// repaired. This also ensures that if we try to use it, it will blow up.
rs = nullptr;
} else {
- rs = _engine->getEngine()->getGroupedRecordStore(opCtx, ns, ident, md.options, md.prefix);
+ rs = _engine->getEngine()->getGroupedRecordStore(
+ opCtx, nss.ns(), ident, md.options, md.prefix);
invariant(rs);
}
UUIDCatalog::get(getGlobalServiceContext())
- .registerCatalogEntry(
- uuid,
- std::make_unique<KVCollectionCatalogEntry>(_engine, this, ns, ident, std::move(rs)));
+ .registerCatalogEntry(uuid,
+ std::make_unique<KVCollectionCatalogEntry>(
+ _engine, this, nss.ns(), ident, std::move(rs)));
}
-void KVCatalog::reinitCollectionAfterRepair(OperationContext* opCtx, const std::string& ns) {
- auto nss = NamespaceString(ns);
+void KVCatalog::reinitCollectionAfterRepair(OperationContext* opCtx, const NamespaceString& nss) {
auto& uuidCatalog = UUIDCatalog::get(getGlobalServiceContext());
uuidCatalog.deregisterCatalogEntry(uuidCatalog.lookupUUIDByNSS(nss).get());
- initCollection(opCtx, ns, false);
+ initCollection(opCtx, nss, false);
}
Status KVCatalog::createCollection(OperationContext* opCtx,
@@ -753,7 +760,7 @@ Status KVCatalog::createCollection(OperationContext* opCtx,
if (!status.isOK())
return status;
- std::string ident = getCollectionIdent(nss.ns());
+ std::string ident = getCollectionIdent(nss);
status =
_engine->getEngine()->createGroupedRecordStore(opCtx, nss.ns(), ident, options, prefix);
@@ -788,27 +795,26 @@ Status KVCatalog::createCollection(OperationContext* opCtx,
}
Status KVCatalog::renameCollection(OperationContext* opCtx,
- StringData fromNS,
- StringData toNS,
+ const NamespaceString& fromNss,
+ const NamespaceString& toNss,
bool stayTemp) {
- const NamespaceString fromNss(fromNS);
- const NamespaceString toNss(toNS);
// TODO SERVER-39518 : Temporarily comment this out because dropCollection uses
// this function and now it only takes a database IX lock. We can change
// this invariant to IX once renameCollection only MODE_IX as well.
// invariant(opCtx->lockState()->isDbLockedForMode(fromNss.db(), MODE_X));
- const std::string identFrom = _engine->getCatalog()->getCollectionIdent(fromNS);
+ const std::string identFrom = _engine->getCatalog()->getCollectionIdent(fromNss);
- Status status = _engine->getEngine()->okToRename(opCtx, fromNS, toNS, identFrom, nullptr);
+ Status status =
+ _engine->getEngine()->okToRename(opCtx, fromNss.ns(), toNss.ns(), identFrom, nullptr);
if (!status.isOK())
return status;
- status = _replaceEntry(opCtx, fromNS, toNS, stayTemp);
+ status = _replaceEntry(opCtx, fromNss, toNss, stayTemp);
if (!status.isOK())
return status;
- const std::string identTo = getCollectionIdent(toNS);
+ const std::string identTo = getCollectionIdent(toNss);
invariant(identFrom == identTo);
return Status::OK();
@@ -837,8 +843,7 @@ private:
CollectionUUID _uuid;
};
-Status KVCatalog::dropCollection(OperationContext* opCtx, StringData ns) {
- NamespaceString nss(ns);
+Status KVCatalog::dropCollection(OperationContext* opCtx, const NamespaceString& nss) {
invariant(opCtx->lockState()->isCollectionLockedForMode(nss, MODE_X));
CollectionCatalogEntry* const entry =
@@ -862,10 +867,10 @@ Status KVCatalog::dropCollection(OperationContext* opCtx, StringData ns) {
invariant(entry->getTotalIndexCount(opCtx) == 0);
- const std::string ident = getCollectionIdent(ns);
+ const std::string ident = getCollectionIdent(nss);
// Remove metadata from mdb_catalog
- Status status = _removeEntry(opCtx, ns);
+ Status status = _removeEntry(opCtx, nss);
if (!status.isOK()) {
return status;
}
diff --git a/src/mongo/db/storage/kv/kv_catalog.h b/src/mongo/db/storage/kv/kv_catalog.h
index 62451d73495..23b5c3cb561 100644
--- a/src/mongo/db/storage/kv/kv_catalog.h
+++ b/src/mongo/db/storage/kv/kv_catalog.h
@@ -63,15 +63,18 @@ public:
void init(OperationContext* opCtx);
- void getAllCollections(std::vector<std::string>* out) const;
+ std::vector<NamespaceString> getAllCollections() const;
- std::string getCollectionIdent(StringData ns) const;
+ std::string getCollectionIdent(const NamespaceString& nss) const;
- std::string getIndexIdent(OperationContext* opCtx, StringData ns, StringData idName) const;
+ std::string getIndexIdent(OperationContext* opCtx,
+ const NamespaceString& nss,
+ StringData idName) const;
- BSONCollectionCatalogEntry::MetaData getMetaData(OperationContext* opCtx, StringData ns) const;
+ BSONCollectionCatalogEntry::MetaData getMetaData(OperationContext* opCtx,
+ const NamespaceString& nss) const;
void putMetaData(OperationContext* opCtx,
- StringData ns,
+ const NamespaceString& nss,
BSONCollectionCatalogEntry::MetaData& md);
std::vector<std::string> getAllIdentsForDB(StringData db) const;
@@ -107,9 +110,9 @@ public:
*/
std::string newInternalIdent();
- void initCollection(OperationContext* opCtx, const std::string& ns, bool forRepair);
+ void initCollection(OperationContext* opCtx, const NamespaceString& nss, bool forRepair);
- void reinitCollectionAfterRepair(OperationContext* opCtx, const std::string& ns);
+ void reinitCollectionAfterRepair(OperationContext* opCtx, const NamespaceString& nss);
Status createCollection(OperationContext* opCtx,
const NamespaceString& nss,
@@ -117,11 +120,11 @@ public:
bool allocateDefaultSpace);
Status renameCollection(OperationContext* opCtx,
- StringData fromNS,
- StringData toNS,
+ const NamespaceString& fromNss,
+ const NamespaceString& toNss,
bool stayTemp);
- Status dropCollection(OperationContext* opCtx, StringData ns);
+ Status dropCollection(OperationContext* opCtx, const NamespaceString& nss);
private:
class AddIdentChange;
@@ -132,23 +135,25 @@ private:
friend class KVCatalogTest;
friend class KVStorageEngineTest;
- BSONObj _findEntry(OperationContext* opCtx, StringData ns, RecordId* out = NULL) const;
+ BSONObj _findEntry(OperationContext* opCtx,
+ const NamespaceString& nss,
+ RecordId* out = nullptr) const;
Status _addEntry(OperationContext* opCtx,
- const NamespaceString& ns,
+ const NamespaceString& nss,
const CollectionOptions& options,
KVPrefix prefix);
Status _replaceEntry(OperationContext* opCtx,
- StringData fromNS,
- StringData toNS,
+ const NamespaceString& fromNss,
+ const NamespaceString& toNss,
bool stayTemp);
- Status _removeEntry(OperationContext* opCtx, StringData ns);
+ Status _removeEntry(OperationContext* opCtx, const NamespaceString& nss);
/**
* Generates a new unique identifier for a new "thing".
- * @param ns - the containing ns
+ * @param nss - the containing namespace
* @param kind - what this "thing" is, likely collection or index
*/
- std::string _newUniqueIdent(StringData ns, const char* kind);
+ std::string _newUniqueIdent(const NamespaceString& nss, const char* kind);
// Helpers only used by constructor and init(). Don't call from elsewhere.
static std::string _newRand();
diff --git a/src/mongo/db/storage/kv/kv_catalog_test_fixture.h b/src/mongo/db/storage/kv/kv_catalog_test_fixture.h
index 10f0251a4e3..eaf9af0ba98 100644
--- a/src/mongo/db/storage/kv/kv_catalog_test_fixture.h
+++ b/src/mongo/db/storage/kv/kv_catalog_test_fixture.h
@@ -47,11 +47,12 @@ protected:
StringData toNS,
bool stayTemp,
KVCatalog* catalog) {
- return catalog->_replaceEntry(opCtx, fromNS, toNS, stayTemp);
+ return catalog->_replaceEntry(
+ opCtx, NamespaceString(fromNS), NamespaceString(toNS), stayTemp);
}
Status dropCollection(OperationContext* opCtx, StringData ns, KVCatalog* catalog) {
- return catalog->_removeEntry(opCtx, ns);
+ return catalog->_removeEntry(opCtx, NamespaceString(ns));
}
};
}
diff --git a/src/mongo/db/storage/kv/kv_collection_catalog_entry.cpp b/src/mongo/db/storage/kv/kv_collection_catalog_entry.cpp
index 20bad4a699d..7c63a745530 100644
--- a/src/mongo/db/storage/kv/kv_collection_catalog_entry.cpp
+++ b/src/mongo/db/storage/kv/kv_collection_catalog_entry.cpp
@@ -176,7 +176,7 @@ bool KVCollectionCatalogEntry::setIndexIsMultikey(OperationContext* opCtx,
}
}
- _catalog->putMetaData(opCtx, ns().toString(), md);
+ _catalog->putMetaData(opCtx, ns(), md);
return true;
}
@@ -196,7 +196,7 @@ void KVCollectionCatalogEntry::setIndexHead(OperationContext* opCtx,
int offset = md.findIndexOffset(indexName);
invariant(offset >= 0);
md.indexes[offset].head = newHead;
- _catalog->putMetaData(opCtx, ns().toString(), md);
+ _catalog->putMetaData(opCtx, ns(), md);
}
Status KVCollectionCatalogEntry::removeIndex(OperationContext* opCtx, StringData indexName) {
@@ -205,10 +205,10 @@ Status KVCollectionCatalogEntry::removeIndex(OperationContext* opCtx, StringData
if (md.findIndexOffset(indexName) < 0)
return Status::OK(); // never had the index so nothing to do.
- const string ident = _catalog->getIndexIdent(opCtx, ns().ns(), indexName);
+ const string ident = _catalog->getIndexIdent(opCtx, ns(), indexName);
md.eraseIndex(indexName);
- _catalog->putMetaData(opCtx, ns().toString(), md);
+ _catalog->putMetaData(opCtx, ns(), md);
// Lazily remove to isolate underlying engine from rollback.
opCtx->recoveryUnit()->registerChange(new RemoveIndexChange(
@@ -250,9 +250,9 @@ Status KVCollectionCatalogEntry::prepareForIndexBuild(OperationContext* opCtx,
}
md.indexes.push_back(imd);
- _catalog->putMetaData(opCtx, ns().toString(), md);
+ _catalog->putMetaData(opCtx, ns(), md);
- string ident = _catalog->getIndexIdent(opCtx, ns().ns(), spec->indexName());
+ string ident = _catalog->getIndexIdent(opCtx, ns(), spec->indexName());
auto kvEngine = _engine->getEngine();
const Status status = kvEngine->createGroupedSortedDataInterface(opCtx, ident, spec, prefix);
@@ -294,7 +294,7 @@ void KVCollectionCatalogEntry::setIndexBuildScanning(
md.indexes[offset].buildPhase = kIndexBuildScanning.toString();
md.indexes[offset].sideWritesIdent = sideWritesIdent;
md.indexes[offset].constraintViolationsIdent = constraintViolationsIdent;
- _catalog->putMetaData(opCtx, ns().toString(), md);
+ _catalog->putMetaData(opCtx, ns(), md);
}
bool KVCollectionCatalogEntry::isIndexBuildScanning(OperationContext* opCtx,
@@ -315,7 +315,7 @@ void KVCollectionCatalogEntry::setIndexBuildDraining(OperationContext* opCtx,
invariant(md.indexes[offset].buildPhase == kIndexBuildScanning.toString());
md.indexes[offset].buildPhase = kIndexBuildDraining.toString();
- _catalog->putMetaData(opCtx, ns().toString(), md);
+ _catalog->putMetaData(opCtx, ns(), md);
}
bool KVCollectionCatalogEntry::isIndexBuildDraining(OperationContext* opCtx,
@@ -335,7 +335,7 @@ void KVCollectionCatalogEntry::indexBuildSuccess(OperationContext* opCtx, String
md.indexes[offset].buildPhase = boost::none;
md.indexes[offset].sideWritesIdent = boost::none;
md.indexes[offset].constraintViolationsIdent = boost::none;
- _catalog->putMetaData(opCtx, ns().toString(), md);
+ _catalog->putMetaData(opCtx, ns(), md);
}
boost::optional<std::string> KVCollectionCatalogEntry::getSideWritesIdent(
@@ -361,13 +361,13 @@ void KVCollectionCatalogEntry::updateTTLSetting(OperationContext* opCtx,
int offset = md.findIndexOffset(idxName);
invariant(offset >= 0);
md.indexes[offset].updateTTLSetting(newExpireSeconds);
- _catalog->putMetaData(opCtx, ns().toString(), md);
+ _catalog->putMetaData(opCtx, ns(), md);
}
void KVCollectionCatalogEntry::updateIndexMetadata(OperationContext* opCtx,
const IndexDescriptor* desc) {
// Update any metadata Ident has for this index
- const string ident = _catalog->getIndexIdent(opCtx, ns().ns(), desc->indexName());
+ const string ident = _catalog->getIndexIdent(opCtx, ns(), desc->indexName());
auto kvEngine = _engine->getEngine();
kvEngine->alterIdentMetadata(opCtx, ident, desc);
}
@@ -386,23 +386,23 @@ void KVCollectionCatalogEntry::updateValidator(OperationContext* opCtx,
md.options.validator = validator;
md.options.validationLevel = validationLevel.toString();
md.options.validationAction = validationAction.toString();
- _catalog->putMetaData(opCtx, ns().toString(), md);
+ _catalog->putMetaData(opCtx, ns(), md);
}
void KVCollectionCatalogEntry::setIsTemp(OperationContext* opCtx, bool isTemp) {
MetaData md = _getMetaData(opCtx);
md.options.temp = isTemp;
- _catalog->putMetaData(opCtx, ns().toString(), md);
+ _catalog->putMetaData(opCtx, ns(), md);
}
void KVCollectionCatalogEntry::updateCappedSize(OperationContext* opCtx, long long size) {
MetaData md = _getMetaData(opCtx);
md.options.cappedSize = size;
- _catalog->putMetaData(opCtx, ns().toString(), md);
+ _catalog->putMetaData(opCtx, ns(), md);
}
BSONCollectionCatalogEntry::MetaData KVCollectionCatalogEntry::_getMetaData(
OperationContext* opCtx) const {
- return _catalog->getMetaData(opCtx, ns().toString());
+ return _catalog->getMetaData(opCtx, ns());
}
}
diff --git a/src/mongo/db/storage/kv/kv_engine.h b/src/mongo/db/storage/kv/kv_engine.h
index 621314e1a3d..ebdf490b78f 100644
--- a/src/mongo/db/storage/kv/kv_engine.h
+++ b/src/mongo/db/storage/kv/kv_engine.h
@@ -186,10 +186,10 @@ public:
* it still exists when recovered.
*/
virtual Status recoverOrphanedIdent(OperationContext* opCtx,
- StringData ns,
+ const NamespaceString& nss,
StringData ident,
const CollectionOptions& options) {
- auto status = createRecordStore(opCtx, ns, ident, options);
+ auto status = createRecordStore(opCtx, nss.ns(), ident, options);
if (status.isOK()) {
return {ErrorCodes::DataModifiedByRepair, "Orphan recovery created a new record store"};
}
diff --git a/src/mongo/db/storage/kv/kv_engine_test_harness.cpp b/src/mongo/db/storage/kv/kv_engine_test_harness.cpp
index 1bbeb4d3b55..81c8d5f5256 100644
--- a/src/mongo/db/storage/kv/kv_engine_test_harness.cpp
+++ b/src/mongo/db/storage/kv/kv_engine_test_harness.cpp
@@ -305,11 +305,11 @@ TEST_F(KVCatalogTest, Coll1) {
CollectionOptions(),
KVPrefix::kNotPrefixed,
catalog.get()));
- ASSERT_NOT_EQUALS("a.b", catalog->getCollectionIdent("a.b"));
+ ASSERT_NOT_EQUALS("a.b", catalog->getCollectionIdent(NamespaceString("a.b")));
uow.commit();
}
- string ident = catalog->getCollectionIdent("a.b");
+ string ident = catalog->getCollectionIdent(NamespaceString("a.b"));
{
MyOperationContext opCtx(engine);
WriteUnitOfWork uow(&opCtx);
@@ -317,7 +317,7 @@ TEST_F(KVCatalogTest, Coll1) {
catalog->init(&opCtx);
uow.commit();
}
- ASSERT_EQUALS(ident, catalog->getCollectionIdent("a.b"));
+ ASSERT_EQUALS(ident, catalog->getCollectionIdent(NamespaceString("a.b")));
{
MyOperationContext opCtx(engine);
@@ -331,7 +331,7 @@ TEST_F(KVCatalogTest, Coll1) {
.transitional_ignore();
uow.commit();
}
- ASSERT_NOT_EQUALS(ident, catalog->getCollectionIdent("a.b"));
+ ASSERT_NOT_EQUALS(ident, catalog->getCollectionIdent(NamespaceString("a.b")));
}
TEST_F(KVCatalogTest, Idx1) {
@@ -357,8 +357,8 @@ TEST_F(KVCatalogTest, Idx1) {
CollectionOptions(),
KVPrefix::kNotPrefixed,
catalog.get()));
- ASSERT_NOT_EQUALS("a.b", catalog->getCollectionIdent("a.b"));
- ASSERT_TRUE(catalog->isUserDataIdent(catalog->getCollectionIdent("a.b")));
+ ASSERT_NOT_EQUALS("a.b", catalog->getCollectionIdent(NamespaceString("a.b")));
+ ASSERT_TRUE(catalog->isUserDataIdent(catalog->getCollectionIdent(NamespaceString("a.b"))));
uow.commit();
}
@@ -378,20 +378,21 @@ TEST_F(KVCatalogTest, Idx1) {
imd.prefix = KVPrefix::kNotPrefixed;
imd.isBackgroundSecondaryBuild = false;
md.indexes.push_back(imd);
- catalog->putMetaData(&opCtx, "a.b", md);
+ catalog->putMetaData(&opCtx, NamespaceString("a.b"), md);
uow.commit();
}
string idxIndent;
{
MyOperationContext opCtx(engine);
- idxIndent = catalog->getIndexIdent(&opCtx, "a.b", "foo");
+ idxIndent = catalog->getIndexIdent(&opCtx, NamespaceString("a.b"), "foo");
}
{
MyOperationContext opCtx(engine);
- ASSERT_EQUALS(idxIndent, catalog->getIndexIdent(&opCtx, "a.b", "foo"));
- ASSERT_TRUE(catalog->isUserDataIdent(catalog->getIndexIdent(&opCtx, "a.b", "foo")));
+ ASSERT_EQUALS(idxIndent, catalog->getIndexIdent(&opCtx, NamespaceString("a.b"), "foo"));
+ ASSERT_TRUE(catalog->isUserDataIdent(
+ catalog->getIndexIdent(&opCtx, NamespaceString("a.b"), "foo")));
}
{
@@ -400,7 +401,7 @@ TEST_F(KVCatalogTest, Idx1) {
BSONCollectionCatalogEntry::MetaData md;
md.ns = "a.b";
- catalog->putMetaData(&opCtx, "a.b", md); // remove index
+ catalog->putMetaData(&opCtx, NamespaceString("a.b"), md); // remove index
BSONCollectionCatalogEntry::IndexMetaData imd;
imd.spec = BSON("name"
@@ -411,13 +412,13 @@ TEST_F(KVCatalogTest, Idx1) {
imd.prefix = KVPrefix::kNotPrefixed;
imd.isBackgroundSecondaryBuild = false;
md.indexes.push_back(imd);
- catalog->putMetaData(&opCtx, "a.b", md);
+ catalog->putMetaData(&opCtx, NamespaceString("a.b"), md);
uow.commit();
}
{
MyOperationContext opCtx(engine);
- ASSERT_NOT_EQUALS(idxIndent, catalog->getIndexIdent(&opCtx, "a.b", "foo"));
+ ASSERT_NOT_EQUALS(idxIndent, catalog->getIndexIdent(&opCtx, NamespaceString("a.b"), "foo"));
}
}
@@ -444,8 +445,8 @@ TEST_F(KVCatalogTest, DirectoryPerDb1) {
CollectionOptions(),
KVPrefix::kNotPrefixed,
catalog.get()));
- ASSERT_STRING_CONTAINS(catalog->getCollectionIdent("a.b"), "a/");
- ASSERT_TRUE(catalog->isUserDataIdent(catalog->getCollectionIdent("a.b")));
+ ASSERT_STRING_CONTAINS(catalog->getCollectionIdent(NamespaceString("a.b")), "a/");
+ ASSERT_TRUE(catalog->isUserDataIdent(catalog->getCollectionIdent(NamespaceString("a.b"))));
uow.commit();
}
@@ -465,9 +466,10 @@ TEST_F(KVCatalogTest, DirectoryPerDb1) {
imd.prefix = KVPrefix::kNotPrefixed;
imd.isBackgroundSecondaryBuild = false;
md.indexes.push_back(imd);
- catalog->putMetaData(&opCtx, "a.b", md);
- ASSERT_STRING_CONTAINS(catalog->getIndexIdent(&opCtx, "a.b", "foo"), "a/");
- ASSERT_TRUE(catalog->isUserDataIdent(catalog->getIndexIdent(&opCtx, "a.b", "foo")));
+ catalog->putMetaData(&opCtx, NamespaceString("a.b"), md);
+ ASSERT_STRING_CONTAINS(catalog->getIndexIdent(&opCtx, NamespaceString("a.b"), "foo"), "a/");
+ ASSERT_TRUE(catalog->isUserDataIdent(
+ catalog->getIndexIdent(&opCtx, NamespaceString("a.b"), "foo")));
uow.commit();
}
}
@@ -495,8 +497,8 @@ TEST_F(KVCatalogTest, Split1) {
CollectionOptions(),
KVPrefix::kNotPrefixed,
catalog.get()));
- ASSERT_STRING_CONTAINS(catalog->getCollectionIdent("a.b"), "collection/");
- ASSERT_TRUE(catalog->isUserDataIdent(catalog->getCollectionIdent("a.b")));
+ ASSERT_STRING_CONTAINS(catalog->getCollectionIdent(NamespaceString("a.b")), "collection/");
+ ASSERT_TRUE(catalog->isUserDataIdent(catalog->getCollectionIdent(NamespaceString("a.b"))));
uow.commit();
}
@@ -516,9 +518,11 @@ TEST_F(KVCatalogTest, Split1) {
imd.prefix = KVPrefix::kNotPrefixed;
imd.isBackgroundSecondaryBuild = false;
md.indexes.push_back(imd);
- catalog->putMetaData(&opCtx, "a.b", md);
- ASSERT_STRING_CONTAINS(catalog->getIndexIdent(&opCtx, "a.b", "foo"), "index/");
- ASSERT_TRUE(catalog->isUserDataIdent(catalog->getIndexIdent(&opCtx, "a.b", "foo")));
+ catalog->putMetaData(&opCtx, NamespaceString("a.b"), md);
+ ASSERT_STRING_CONTAINS(catalog->getIndexIdent(&opCtx, NamespaceString("a.b"), "foo"),
+ "index/");
+ ASSERT_TRUE(catalog->isUserDataIdent(
+ catalog->getIndexIdent(&opCtx, NamespaceString("a.b"), "foo")));
uow.commit();
}
}
@@ -546,8 +550,9 @@ TEST_F(KVCatalogTest, DirectoryPerAndSplit1) {
CollectionOptions(),
KVPrefix::kNotPrefixed,
catalog.get()));
- ASSERT_STRING_CONTAINS(catalog->getCollectionIdent("a.b"), "a/collection/");
- ASSERT_TRUE(catalog->isUserDataIdent(catalog->getCollectionIdent("a.b")));
+ ASSERT_STRING_CONTAINS(catalog->getCollectionIdent(NamespaceString("a.b")),
+ "a/collection/");
+ ASSERT_TRUE(catalog->isUserDataIdent(catalog->getCollectionIdent(NamespaceString("a.b"))));
uow.commit();
}
@@ -567,9 +572,11 @@ TEST_F(KVCatalogTest, DirectoryPerAndSplit1) {
imd.prefix = KVPrefix::kNotPrefixed;
imd.isBackgroundSecondaryBuild = false;
md.indexes.push_back(imd);
- catalog->putMetaData(&opCtx, "a.b", md);
- ASSERT_STRING_CONTAINS(catalog->getIndexIdent(&opCtx, "a.b", "foo"), "a/index/");
- ASSERT_TRUE(catalog->isUserDataIdent(catalog->getIndexIdent(&opCtx, "a.b", "foo")));
+ catalog->putMetaData(&opCtx, NamespaceString("a.b"), md);
+ ASSERT_STRING_CONTAINS(catalog->getIndexIdent(&opCtx, NamespaceString("a.b"), "foo"),
+ "a/index/");
+ ASSERT_TRUE(catalog->isUserDataIdent(
+ catalog->getIndexIdent(&opCtx, NamespaceString("a.b"), "foo")));
uow.commit();
}
}
@@ -600,8 +607,9 @@ TEST_F(KVCatalogTest, RestartForPrefixes) {
WriteUnitOfWork uow(&opCtx);
ASSERT_OK(newCollection(
&opCtx, NamespaceString("a.b"), CollectionOptions(), abCollPrefix, catalog.get()));
- ASSERT_NOT_EQUALS("a.b", catalog->getCollectionIdent("a.b"));
- ASSERT_TRUE(catalog->isUserDataIdent(catalog->getCollectionIdent("a.b")));
+ ASSERT_NOT_EQUALS("a.b", catalog->getCollectionIdent(NamespaceString("a.b")));
+ ASSERT_TRUE(
+ catalog->isUserDataIdent(catalog->getCollectionIdent(NamespaceString("a.b"))));
uow.commit();
}
@@ -622,7 +630,7 @@ TEST_F(KVCatalogTest, RestartForPrefixes) {
imd.isBackgroundSecondaryBuild = false;
md.indexes.push_back(imd);
md.prefix = abCollPrefix;
- catalog->putMetaData(&opCtx, "a.b", md);
+ catalog->putMetaData(&opCtx, NamespaceString("a.b"), md);
uow.commit();
}
}
@@ -637,7 +645,8 @@ TEST_F(KVCatalogTest, RestartForPrefixes) {
stdx::make_unique<KVCatalog>(rs.get(), false, false, nullptr);
catalog->init(&opCtx);
- const BSONCollectionCatalogEntry::MetaData md = catalog->getMetaData(&opCtx, "a.b");
+ const BSONCollectionCatalogEntry::MetaData md =
+ catalog->getMetaData(&opCtx, NamespaceString("a.b"));
ASSERT_EQ("a.b", md.ns);
ASSERT_EQ(abCollPrefix, md.prefix);
ASSERT_EQ(fooIndexPrefix, md.indexes[md.findIndexOffset("foo")].prefix);
diff --git a/src/mongo/db/storage/kv/kv_storage_engine.cpp b/src/mongo/db/storage/kv/kv_storage_engine.cpp
index 5e409902648..f0a1fb6dc96 100644
--- a/src/mongo/db/storage/kv/kv_storage_engine.cpp
+++ b/src/mongo/db/storage/kv/kv_storage_engine.cpp
@@ -135,8 +135,7 @@ void KVStorageEngine::loadCatalog(OperationContext* opCtx) {
std::sort(identsKnownToStorageEngine.begin(), identsKnownToStorageEngine.end());
}
- std::vector<std::string> collectionsKnownToCatalog;
- _catalog->getAllCollections(&collectionsKnownToCatalog);
+ auto collectionsKnownToCatalog = _catalog->getAllCollections();
if (_options.forRepair) {
// It's possible that there are collection files on disk that are unknown to the catalog. In
@@ -148,7 +147,8 @@ void KVStorageEngine::loadCatalog(OperationContext* opCtx) {
bool isOrphan = !std::any_of(collectionsKnownToCatalog.begin(),
collectionsKnownToCatalog.end(),
[this, &ident](const auto& coll) {
- return _catalog->getCollectionIdent(coll) == ident;
+ return _catalog->getCollectionIdent(
+ NamespaceString(coll)) == ident;
});
if (isOrphan) {
// If the catalog does not have information about this
@@ -258,9 +258,9 @@ Status KVStorageEngine::_recoverOrphanedCollection(OperationContext* opCtx,
<< collectionIdent;
WriteUnitOfWork wuow(opCtx);
- const auto metadata = _catalog->getMetaData(opCtx, collectionName.toString());
- auto status = _engine->recoverOrphanedIdent(
- opCtx, collectionName.toString(), collectionIdent, metadata.options);
+ const auto metadata = _catalog->getMetaData(opCtx, collectionName);
+ auto status =
+ _engine->recoverOrphanedIdent(opCtx, collectionName, collectionIdent, metadata.options);
bool dataModified = status.code() == ErrorCodes::DataModifiedByRepair;
@@ -361,8 +361,7 @@ KVStorageEngine::reconcileCatalogAndIdents(OperationContext* opCtx) {
// engine. An omission here is fatal. A missing ident could mean a collection drop was rolled
// back. Note that startup already attempts to open tables; this should only catch errors in
// other contexts such as `recoverToStableTimestamp`.
- std::vector<std::string> collections;
- _catalog->getAllCollections(&collections);
+ auto collections = _catalog->getAllCollections();
if (!_options.forRepair) {
for (const auto& coll : collections) {
const auto& identForColl = _catalog->getCollectionIdent(coll);
@@ -398,7 +397,7 @@ KVStorageEngine::reconcileCatalogAndIdents(OperationContext* opCtx) {
if (indexMetaData.ready && !foundIdent) {
log() << "Expected index data is missing, rebuilding. Collection: " << coll
<< " Index: " << indexName;
- ret.emplace_back(coll, indexName);
+ ret.emplace_back(coll.ns(), indexName);
continue;
}
@@ -435,7 +434,7 @@ KVStorageEngine::reconcileCatalogAndIdents(OperationContext* opCtx) {
log()
<< "Expected background index build did not complete, rebuilding. Collection: "
<< coll << " Index: " << indexName;
- ret.emplace_back(coll, indexName);
+ ret.emplace_back(coll.ns(), indexName);
continue;
}
@@ -571,7 +570,7 @@ Status KVStorageEngine::_dropCollectionsNoTimestamp(OperationContext* opCtx,
WriteUnitOfWork untimestampedDropWuow(opCtx);
for (auto& nss : toDrop) {
invariant(getCatalog());
- Status result = getCatalog()->dropCollection(opCtx, nss.ns());
+ Status result = getCatalog()->dropCollection(opCtx, nss);
if (!result.isOK() && firstError.isOK()) {
firstError = result;
}
@@ -627,21 +626,21 @@ SnapshotManager* KVStorageEngine::getSnapshotManager() const {
return _engine->getSnapshotManager();
}
-Status KVStorageEngine::repairRecordStore(OperationContext* opCtx, const std::string& ns) {
+Status KVStorageEngine::repairRecordStore(OperationContext* opCtx, const NamespaceString& nss) {
auto repairObserver = StorageRepairObserver::get(getGlobalServiceContext());
invariant(repairObserver->isIncomplete());
- Status status = _engine->repairIdent(opCtx, _catalog->getCollectionIdent(ns));
+ Status status = _engine->repairIdent(opCtx, _catalog->getCollectionIdent(nss));
bool dataModified = status.code() == ErrorCodes::DataModifiedByRepair;
if (!status.isOK() && !dataModified) {
return status;
}
if (dataModified) {
- repairObserver->onModification(str::stream() << "Collection " << ns << ": "
+ repairObserver->onModification(str::stream() << "Collection " << nss << ": "
<< status.reason());
}
- _catalog->reinitCollectionAfterRepair(opCtx, ns);
+ _catalog->reinitCollectionAfterRepair(opCtx, nss);
return Status::OK();
}
@@ -923,7 +922,7 @@ int64_t KVStorageEngine::sizeOnDiskForDb(OperationContext* opCtx, StringData dbN
for (size_t i = 0; i < indexNames.size(); i++) {
std::string ident =
- _catalog->getIndexIdent(opCtx, catalogEntry->ns().ns(), indexNames[i]);
+ _catalog->getIndexIdent(opCtx, catalogEntry->ns(), indexNames[i]);
size += _engine->getIdentSize(opCtx, ident);
}
diff --git a/src/mongo/db/storage/kv/kv_storage_engine.h b/src/mongo/db/storage/kv/kv_storage_engine.h
index a84d82678a1..8bba8926a9a 100644
--- a/src/mongo/db/storage/kv/kv_storage_engine.h
+++ b/src/mongo/db/storage/kv/kv_storage_engine.h
@@ -107,7 +107,7 @@ public:
virtual bool isEphemeral() const;
- virtual Status repairRecordStore(OperationContext* opCtx, const std::string& ns);
+ virtual Status repairRecordStore(OperationContext* opCtx, const NamespaceString& nss);
virtual std::unique_ptr<TemporaryRecordStore> makeTemporaryRecordStore(
OperationContext* opCtx) override;
diff --git a/src/mongo/db/storage/kv/kv_storage_engine_test.cpp b/src/mongo/db/storage/kv/kv_storage_engine_test.cpp
index 33d076d7ce7..370677f8f1c 100644
--- a/src/mongo/db/storage/kv/kv_storage_engine_test.cpp
+++ b/src/mongo/db/storage/kv/kv_storage_engine_test.cpp
@@ -175,8 +175,7 @@ TEST_F(KVStorageEngineTest, ReconcileDoesNotDropIndexBuildTempTables) {
auto sideWrites = makeTemporary(opCtx.get());
auto constraintViolations = makeTemporary(opCtx.get());
- const auto indexIdent =
- _storageEngine->getCatalog()->getIndexIdent(opCtx.get(), ns.ns(), indexName);
+ const auto indexIdent = _storageEngine->getCatalog()->getIndexIdent(opCtx.get(), ns, indexName);
indexBuildScan(opCtx.get(),
ns,
@@ -217,8 +216,7 @@ TEST_F(KVStorageEngineTest, ReconcileDoesNotDropIndexBuildTempTablesBackgroundSe
auto sideWrites = makeTemporary(opCtx.get());
auto constraintViolations = makeTemporary(opCtx.get());
- const auto indexIdent =
- _storageEngine->getCatalog()->getIndexIdent(opCtx.get(), ns.ns(), indexName);
+ const auto indexIdent = _storageEngine->getCatalog()->getIndexIdent(opCtx.get(), ns, indexName);
indexBuildScan(opCtx.get(),
ns,
diff --git a/src/mongo/db/storage/kv/kv_storage_engine_test_fixture.h b/src/mongo/db/storage/kv/kv_storage_engine_test_fixture.h
index 4a5e00d4547..d530ebb4922 100644
--- a/src/mongo/db/storage/kv/kv_storage_engine_test_fixture.h
+++ b/src/mongo/db/storage/kv/kv_storage_engine_test_fixture.h
@@ -59,7 +59,7 @@ public:
return ret;
}
- return _storageEngine->getCatalog()->getCollectionIdent(ns.ns());
+ return _storageEngine->getCatalog()->getCollectionIdent(ns);
}
std::unique_ptr<TemporaryRecordStore> makeTemporary(OperationContext* opCtx) {
@@ -76,8 +76,7 @@ public:
}
Status dropIndexTable(OperationContext* opCtx, NamespaceString nss, std::string indexName) {
- std::string indexIdent =
- _storageEngine->getCatalog()->getIndexIdent(opCtx, nss.ns(), indexName);
+ std::string indexIdent = _storageEngine->getCatalog()->getIndexIdent(opCtx, nss, indexName);
return dropIdent(opCtx, indexIdent);
}
@@ -95,10 +94,8 @@ public:
}
bool collectionExists(OperationContext* opCtx, const NamespaceString& nss) {
- std::vector<std::string> allCollections;
- _storageEngine->getCatalog()->getAllCollections(&allCollections);
- return std::find(allCollections.begin(), allCollections.end(), nss.toString()) !=
- allCollections.end();
+ auto allCollections = _storageEngine->getCatalog()->getAllCollections();
+ return std::count(allCollections.begin(), allCollections.end(), nss);
}
bool identExists(OperationContext* opCtx, const std::string& ident) {
auto idents = getAllKVEngineIdents(opCtx);
@@ -167,7 +164,7 @@ public:
}
Status removeEntry(OperationContext* opCtx, StringData ns, KVCatalog* catalog) {
- return catalog->_removeEntry(opCtx, ns);
+ return catalog->_removeEntry(opCtx, NamespaceString(ns));
}
KVStorageEngine* _storageEngine;
diff --git a/src/mongo/db/storage/storage_engine.h b/src/mongo/db/storage/storage_engine.h
index d7172eb3d85..c74c7de72ab 100644
--- a/src/mongo/db/storage/storage_engine.h
+++ b/src/mongo/db/storage/storage_engine.h
@@ -285,7 +285,7 @@ public:
* Generally, this method should not be called directly except by the repairDatabase()
* free function.
*/
- virtual Status repairRecordStore(OperationContext* opCtx, const std::string& ns) = 0;
+ virtual Status repairRecordStore(OperationContext* opCtx, const NamespaceString& nss) = 0;
/**
* Creates a temporary RecordStore on the storage engine. This record store will drop itself
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp
index 862545bb8c3..561469471dc 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp
@@ -1118,7 +1118,7 @@ Status WiredTigerKVEngine::createGroupedRecordStore(OperationContext* opCtx,
}
Status WiredTigerKVEngine::recoverOrphanedIdent(OperationContext* opCtx,
- StringData ns,
+ const NamespaceString& nss,
StringData ident,
const CollectionOptions& options) {
#ifdef _WIN32
@@ -1148,10 +1148,9 @@ Status WiredTigerKVEngine::recoverOrphanedIdent(OperationContext* opCtx,
return status;
}
- log() << "Creating new RecordStore for collection " + ns + " with UUID: " +
- (options.uuid ? options.uuid->toString() : "none");
+ log() << "Creating new RecordStore for collection " << nss << " with UUID: " << options.uuid;
- status = createGroupedRecordStore(opCtx, ns, ident, options, KVPrefix::kNotPrefixed);
+ status = createGroupedRecordStore(opCtx, nss.ns(), ident, options, KVPrefix::kNotPrefixed);
if (!status.isOK()) {
return status;
}
@@ -1176,7 +1175,8 @@ Status WiredTigerKVEngine::recoverOrphanedIdent(OperationContext* opCtx,
WiredTigerSession sessionWrapper(_conn);
WT_SESSION* session = sessionWrapper.getSession();
- status = wtRCToStatus(session->salvage(session, _uri(ident).c_str(), NULL), "Salvage failed: ");
+ status =
+ wtRCToStatus(session->salvage(session, _uri(ident).c_str(), nullptr), "Salvage failed: ");
if (status.isOK()) {
return {ErrorCodes::DataModifiedByRepair,
str::stream() << "Salvaged data for ident " << ident};
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h
index 1b1c9af1648..1f07e81debc 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h
@@ -181,7 +181,7 @@ public:
Status repairIdent(OperationContext* opCtx, StringData ident) override;
Status recoverOrphanedIdent(OperationContext* opCtx,
- StringData ns,
+ const NamespaceString& nss,
StringData ident,
const CollectionOptions& options) override;
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp
index ef37d8dc573..c6e0da77906 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp
@@ -119,14 +119,14 @@ public:
TEST_F(WiredTigerKVEngineRepairTest, OrphanedDataFilesCanBeRecovered) {
auto opCtxPtr = makeOperationContext();
- std::string ns = "a.b";
+ NamespaceString nss("a.b");
std::string ident = "collection-1234";
std::string record = "abcd";
CollectionOptions options;
std::unique_ptr<RecordStore> rs;
- ASSERT_OK(_engine->createRecordStore(opCtxPtr.get(), ns, ident, options));
- rs = _engine->getRecordStore(opCtxPtr.get(), ns, ident, options);
+ ASSERT_OK(_engine->createRecordStore(opCtxPtr.get(), nss.ns(), ident, options));
+ rs = _engine->getRecordStore(opCtxPtr.get(), nss.ns(), ident, options);
ASSERT(rs);
RecordId loc;
@@ -149,7 +149,7 @@ TEST_F(WiredTigerKVEngineRepairTest, OrphanedDataFilesCanBeRecovered) {
ASSERT(!boost::filesystem::exists(tmpFile));
#ifdef _WIN32
- auto status = _engine->recoverOrphanedIdent(opCtxPtr.get(), ns, ident, options);
+ auto status = _engine->recoverOrphanedIdent(opCtxPtr.get(), nss, ident, options);
ASSERT_EQ(ErrorCodes::CommandNotSupported, status.code());
#else
// Move the data file out of the way so the ident can be dropped. This not permitted on Windows
@@ -166,7 +166,7 @@ TEST_F(WiredTigerKVEngineRepairTest, OrphanedDataFilesCanBeRecovered) {
boost::filesystem::rename(tmpFile, *dataFilePath, err);
ASSERT(!err) << err.message();
- auto status = _engine->recoverOrphanedIdent(opCtxPtr.get(), ns, ident, options);
+ auto status = _engine->recoverOrphanedIdent(opCtxPtr.get(), nss, ident, options);
ASSERT_EQ(ErrorCodes::DataModifiedByRepair, status.code());
#endif
}
@@ -174,14 +174,14 @@ TEST_F(WiredTigerKVEngineRepairTest, OrphanedDataFilesCanBeRecovered) {
TEST_F(WiredTigerKVEngineRepairTest, UnrecoverableOrphanedDataFilesAreRebuilt) {
auto opCtxPtr = makeOperationContext();
- std::string ns = "a.b";
+ NamespaceString nss("a.b");
std::string ident = "collection-1234";
std::string record = "abcd";
CollectionOptions options;
std::unique_ptr<RecordStore> rs;
- ASSERT_OK(_engine->createRecordStore(opCtxPtr.get(), ns, ident, options));
- rs = _engine->getRecordStore(opCtxPtr.get(), ns, ident, options);
+ ASSERT_OK(_engine->createRecordStore(opCtxPtr.get(), nss.ns(), ident, options));
+ rs = _engine->getRecordStore(opCtxPtr.get(), nss.ns(), ident, options);
ASSERT(rs);
RecordId loc;
@@ -203,7 +203,7 @@ TEST_F(WiredTigerKVEngineRepairTest, UnrecoverableOrphanedDataFilesAreRebuilt) {
ASSERT_OK(_engine->dropIdent(opCtxPtr.get(), ident));
#ifdef _WIN32
- auto status = _engine->recoverOrphanedIdent(opCtxPtr.get(), ns, ident, options);
+ auto status = _engine->recoverOrphanedIdent(opCtxPtr.get(), nss, ident, options);
ASSERT_EQ(ErrorCodes::CommandNotSupported, status.code());
#else
// The ident may not get immediately dropped, so ensure it is completely gone.
@@ -221,13 +221,13 @@ TEST_F(WiredTigerKVEngineRepairTest, UnrecoverableOrphanedDataFilesAreRebuilt) {
// This should recreate an empty data file successfully and move the old one to a name that ends
// in ".corrupt".
- auto status = _engine->recoverOrphanedIdent(opCtxPtr.get(), ns, ident, options);
+ auto status = _engine->recoverOrphanedIdent(opCtxPtr.get(), nss, ident, options);
ASSERT_EQ(ErrorCodes::DataModifiedByRepair, status.code()) << status.reason();
boost::filesystem::path corruptFile = (dataFilePath->string() + ".corrupt");
ASSERT(boost::filesystem::exists(corruptFile));
- rs = _engine->getRecordStore(opCtxPtr.get(), ns, ident, options);
+ rs = _engine->getRecordStore(opCtxPtr.get(), nss.ns(), ident, options);
RecordData data;
ASSERT_FALSE(rs->findRecord(opCtxPtr.get(), loc, &data));
#endif