summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Wlodarek <gregory.wlodarek@mongodb.com>2019-07-29 21:00:16 -0400
committerGregory Wlodarek <gregory.wlodarek@mongodb.com>2019-07-29 21:06:47 -0400
commit0d6d248c39a5b4e43eefc9320b5dec3229cfcfdb (patch)
tree1fb67633d3c9c551341dbf41efb47a80c6392553
parent47d0308cd596c6d40d6a3069379be1bdaf51d47b (diff)
downloadmongo-0d6d248c39a5b4e43eefc9320b5dec3229cfcfdb.tar.gz
SERVER-41696 Remove the 'ns' field from index specs
-rw-r--r--jstests/noPassthrough/absent_ns_field_in_index_specs.js25
-rw-r--r--jstests/replsets/oplog_format_create_indexes.js6
-rw-r--r--src/mongo/db/catalog/SConscript14
-rw-r--r--src/mongo/db/catalog/collection_impl.cpp1
-rw-r--r--src/mongo/db/catalog/database_test.cpp3
-rw-r--r--src/mongo/db/catalog/disable_index_spec_namespace_generation.idl41
-rw-r--r--src/mongo/db/catalog/index_builds_manager_test.cpp4
-rw-r--r--src/mongo/db/catalog/index_catalog.h2
-rw-r--r--src/mongo/db/catalog/index_catalog_entry.h2
-rw-r--r--src/mongo/db/catalog/index_catalog_entry_impl.cpp43
-rw-r--r--src/mongo/db/catalog/index_catalog_entry_impl.h9
-rw-r--r--src/mongo/db/catalog/index_catalog_impl.cpp39
-rw-r--r--src/mongo/db/catalog/index_catalog_impl.h2
-rw-r--r--src/mongo/db/catalog/index_catalog_noop.h2
-rw-r--r--src/mongo/db/catalog/index_key_validate.cpp57
-rw-r--r--src/mongo/db/catalog/index_key_validate.h1
-rw-r--r--src/mongo/db/catalog/index_spec_validate_test.cpp200
-rw-r--r--src/mongo/db/catalog/rename_collection.cpp25
-rw-r--r--src/mongo/db/catalog/rename_collection_test.cpp2
-rw-r--r--src/mongo/db/cloner.cpp63
-rw-r--r--src/mongo/db/commands/create_indexes.cpp2
-rw-r--r--src/mongo/db/commands/dbcommands.cpp2
-rw-r--r--src/mongo/db/commands/mr.cpp10
-rw-r--r--src/mongo/db/index/index_descriptor.cpp26
-rw-r--r--src/mongo/db/index/index_descriptor.h15
-rw-r--r--src/mongo/db/index_builder.cpp27
-rw-r--r--src/mongo/db/index_builder.h13
-rw-r--r--src/mongo/db/index_builds_coordinator_mongod_test.cpp4
-rw-r--r--src/mongo/db/op_observer_impl.cpp27
-rw-r--r--src/mongo/db/pipeline/document_source_out.cpp8
-rw-r--r--src/mongo/db/repl/base_cloner_test_fixture.cpp3
-rw-r--r--src/mongo/db/repl/collection_cloner.cpp11
-rw-r--r--src/mongo/db/repl/collection_cloner_test.cpp9
-rw-r--r--src/mongo/db/repl/oplog.cpp20
-rw-r--r--src/mongo/db/repl/rollback_impl_test.cpp2
-rw-r--r--src/mongo/db/repl/rs_rollback.cpp16
-rw-r--r--src/mongo/db/repl/rs_rollback_test.cpp40
-rw-r--r--src/mongo/db/repl/storage_interface_impl_test.cpp21
-rw-r--r--src/mongo/db/repl/sync_tail_test.cpp2
-rw-r--r--src/mongo/db/s/config/sharding_catalog_manager_config_initialization_test.cpp64
-rw-r--r--src/mongo/db/s/shardsvr_shard_collection.cpp2
-rw-r--r--src/mongo/db/storage/SConscript6
-rw-r--r--src/mongo/db/storage/biggie/biggie_sorted_impl.cpp3
-rw-r--r--src/mongo/db/storage/biggie/biggie_sorted_impl_test.cpp2
-rw-r--r--src/mongo/db/storage/bson_collection_catalog_entry.cpp14
-rw-r--r--src/mongo/db/storage/durable_catalog_impl.cpp7
-rw-r--r--src/mongo/db/storage/kv/durable_catalog_test.cpp7
-rw-r--r--src/mongo/db/storage/kv/kv_engine_test_harness.cpp6
-rw-r--r--src/mongo/db/storage/storage_engine_test_fixture.h2
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_prefixed_index_test.cpp2
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_standard_index_test.cpp2
-rw-r--r--src/mongo/db/system_index.cpp22
-rw-r--r--src/mongo/dbtests/counttests.cpp2
-rw-r--r--src/mongo/dbtests/dbtests.cpp1
-rw-r--r--src/mongo/dbtests/indexcatalogtests.cpp10
-rw-r--r--src/mongo/dbtests/indexupdatetests.cpp60
-rw-r--r--src/mongo/dbtests/multikey_paths_test.cpp21
-rw-r--r--src/mongo/dbtests/query_stage_count.cpp2
-rw-r--r--src/mongo/dbtests/query_stage_ixscan.cpp5
-rw-r--r--src/mongo/dbtests/querytests.cpp1
-rw-r--r--src/mongo/dbtests/rollbacktests.cpp24
-rw-r--r--src/mongo/dbtests/storage_timestamp_tests.cpp37
-rw-r--r--src/mongo/dbtests/validate_tests.cpp81
-rw-r--r--src/mongo/dbtests/wildcard_multikey_persistence_test.cpp3
64 files changed, 340 insertions, 845 deletions
diff --git a/jstests/noPassthrough/absent_ns_field_in_index_specs.js b/jstests/noPassthrough/absent_ns_field_in_index_specs.js
index 4428415e1b3..b36beab8746 100644
--- a/jstests/noPassthrough/absent_ns_field_in_index_specs.js
+++ b/jstests/noPassthrough/absent_ns_field_in_index_specs.js
@@ -1,10 +1,5 @@
/**
- * Uses the 'disableIndexSpecNamespaceGeneration' server test parameter to disable the generation
- * of the 'ns' field for index specs to test the absence of the field.
- *
- * When the 'ns' field is missing from the index specs and the 'disableIndexSpecNamespaceGeneration'
- * server test parameter is disabled, the server should automatically add the 'ns' field to the
- * index specs missing it prior to returning them.
+ * Ensures that the 'ns' field for index specs is absent with its removal in SERVER-41696.
*
* @tags: [requires_replication, requires_persistence]
*/
@@ -25,10 +20,6 @@ const primaryColl = primaryDB.getCollection(collName);
const secondary = replSet.getSecondary();
const secondaryDB = secondary.getDB(dbName);
-// The primary will not generate the 'ns' field for index specs, but the secondary will.
-assert.commandWorked(
- primary.getDB('admin').runCommand({setParameter: 1, disableIndexSpecNamespaceGeneration: 1}));
-
assert.commandWorked(primaryColl.insert({x: 100}));
assert.commandWorked(primaryColl.createIndex({x: 1}));
@@ -40,15 +31,11 @@ let specSecondary =
assert.commandWorked(secondaryDB.runCommand({listIndexes: collName})).cursor.firstBatch[1];
assert.eq(false, specPrimary.hasOwnProperty('ns'));
-assert.eq(true, specSecondary.hasOwnProperty('ns'));
-assert.eq(dbName + '.' + collName, specSecondary.ns);
+assert.eq(false, specSecondary.hasOwnProperty('ns'));
replSet.stopSet(/*signal=*/null, /*forRestart=*/true);
-// The primaries index spec has no 'ns' field and the secondaries index spec does have the 'ns'
-// field. Restart the nodes as standalone and ensure that the primaries index spec gets updated
-// with the 'ns' field. No changes should be necessary to the secondaries index spec, but
-// verify that it still has the 'ns' field.
+// Both nodes should have no 'ns' field in the index spec on restart.
const options = {
dbpath: primary.dbpath,
noCleanData: true
@@ -59,8 +46,7 @@ assert.neq(null, conn, 'mongod was unable to start up with options: ' + tojson(o
let db = conn.getDB(dbName);
let spec = assert.commandWorked(db.runCommand({listIndexes: collName})).cursor.firstBatch[1];
-assert.eq(true, spec.hasOwnProperty('ns'));
-assert.eq(dbName + '.' + collName, spec.ns);
+assert.eq(false, spec.hasOwnProperty('ns'));
MongoRunner.stopMongod(conn);
@@ -71,8 +57,7 @@ assert.neq(null, conn, 'mongod was unable to start up with options: ' + tojson(o
db = conn.getDB(dbName);
spec = assert.commandWorked(db.runCommand({listIndexes: collName})).cursor.firstBatch[1];
-assert.eq(true, spec.hasOwnProperty('ns'));
-assert.eq(dbName + '.' + collName, spec.ns);
+assert.eq(false, spec.hasOwnProperty('ns'));
MongoRunner.stopMongod(conn);
}());
diff --git a/jstests/replsets/oplog_format_create_indexes.js b/jstests/replsets/oplog_format_create_indexes.js
index 117d5be04bb..5202a547e25 100644
--- a/jstests/replsets/oplog_format_create_indexes.js
+++ b/jstests/replsets/oplog_format_create_indexes.js
@@ -41,14 +41,10 @@ function testOplogEntryContainsIndexInfoObj(coll, keyPattern, indexOptions) {
// Because of differences between the new and old oplog entries for createIndexes,
// treat the namespace part separately and compare entries without ns field.
- const indexSpecNs = indexSpec.ns;
- delete indexSpec.ns;
const found = allOplogEntries.filter((entry) => {
- const entryNs = entry.o.ns || testDB.getName() + "." + entry.o.createIndexes;
const entrySpec = entry.o;
- delete entrySpec.ns;
delete entrySpec.createIndexes;
- return indexSpecNs === entryNs && bsonWoCompare(indexSpec, entrySpec) === 0;
+ return bsonWoCompare(indexSpec, entrySpec) === 0;
});
assert.eq(1,
found.length,
diff --git a/src/mongo/db/catalog/SConscript b/src/mongo/db/catalog/SConscript
index c2a92d5acca..369017cd7d3 100644
--- a/src/mongo/db/catalog/SConscript
+++ b/src/mongo/db/catalog/SConscript
@@ -114,16 +114,6 @@ env.Library(
)
env.Library(
- target='disable_index_spec_namespace_generation',
- source=[
- env.Idlc('disable_index_spec_namespace_generation.idl')[0],
- ],
- LIBDEPS_PRIVATE=[
- '$BUILD_DIR/mongo/idl/server_parameter',
- ],
-)
-
-env.Library(
target='index_key_validate',
source=[
"index_key_validate.cpp",
@@ -138,9 +128,6 @@ env.Library(
'$BUILD_DIR/mongo/db/query/collation/collator_factory_interface',
'$BUILD_DIR/mongo/util/fail_point',
],
- LIBDEPS_PRIVATE=[
- 'disable_index_spec_namespace_generation',
- ],
)
env.Library(
@@ -331,7 +318,6 @@ env.Library(
],
LIBDEPS_PRIVATE=[
'index_build_block',
- 'disable_index_spec_namespace_generation',
'$BUILD_DIR/mongo/db/catalog/collection_catalog_helper',
'$BUILD_DIR/mongo/db/commands/server_status_core',
'$BUILD_DIR/mongo/db/index/index_build_interceptor',
diff --git a/src/mongo/db/catalog/collection_impl.cpp b/src/mongo/db/catalog/collection_impl.cpp
index 6ebdaf1ec51..2d441c2b2f6 100644
--- a/src/mongo/db/catalog/collection_impl.cpp
+++ b/src/mongo/db/catalog/collection_impl.cpp
@@ -1051,7 +1051,6 @@ std::unique_ptr<PlanExecutor, PlanExecutor::Deleter> CollectionImpl::makePlanExe
void CollectionImpl::setNs(NamespaceString nss) {
_ns = std::move(nss);
- _indexCatalog->setNs(_ns);
_infoCache->setNs(_ns);
_recordStore.get()->setNs(_ns);
}
diff --git a/src/mongo/db/catalog/database_test.cpp b/src/mongo/db/catalog/database_test.cpp
index 542cae76e80..173e797851d 100644
--- a/src/mongo/db/catalog/database_test.cpp
+++ b/src/mongo/db/catalog/database_test.cpp
@@ -301,8 +301,7 @@ void _testDropCollectionThrowsExceptionIfThereAreIndexesInProgress(OperationCont
ASSERT_EQUALS(indexCatalog->numIndexesInProgress(opCtx), 0);
auto indexInfoObj = BSON("v" << int(IndexDescriptor::kLatestIndexVersion) << "key"
<< BSON("a" << 1) << "name"
- << "a_1"
- << "ns" << nss.ns());
+ << "a_1");
auto indexBuildBlock = std::make_unique<IndexBuildBlock>(
indexCatalog, collection->ns(), indexInfoObj, IndexBuildMethod::kHybrid);
diff --git a/src/mongo/db/catalog/disable_index_spec_namespace_generation.idl b/src/mongo/db/catalog/disable_index_spec_namespace_generation.idl
deleted file mode 100644
index c750956396c..00000000000
--- a/src/mongo/db/catalog/disable_index_spec_namespace_generation.idl
+++ /dev/null
@@ -1,41 +0,0 @@
-# Copyright (C) 2019-present MongoDB, Inc.
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the Server Side Public License, version 1,
-# as published by MongoDB, Inc.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# Server Side Public License for more details.
-#
-# You should have received a copy of the Server Side Public License
-# along with this program. If not, see
-# <http://www.mongodb.com/licensing/server-side-public-license>.
-#
-# As a special exception, the copyright holders give permission to link the
-# code of portions of this program with the OpenSSL library under certain
-# conditions as described in each individual source file and distribute
-# linked combinations including the program with the OpenSSL library. You
-# must comply with the Server Side Public License in all respects for
-# all of the code used other than as permitted herein. If you modify file(s)
-# with this exception, you may extend this exception to your version of the
-# file(s), but you are not obligated to do so. If you do not wish to do so,
-# delete this exception statement from your version. If you delete this
-# exception statement from all source files in the program, then also delete
-# it in the license file.
-#
-
-global:
- cpp_namespace: "mongo"
-
-server_parameters:
- disableIndexSpecNamespaceGeneration:
- description: "If enabled, the 'ns' field will not be generated for index specs if it's missing."
- set_at:
- - startup
- - runtime
- cpp_vartype: AtomicWord<bool>
- cpp_varname: "disableIndexSpecNamespaceGeneration"
- default: false
- test_only: true
diff --git a/src/mongo/db/catalog/index_builds_manager_test.cpp b/src/mongo/db/catalog/index_builds_manager_test.cpp
index df5e50d244c..3ca43d04039 100644
--- a/src/mongo/db/catalog/index_builds_manager_test.cpp
+++ b/src/mongo/db/catalog/index_builds_manager_test.cpp
@@ -75,8 +75,8 @@ std::vector<BSONObj> makeSpecs(const NamespaceString& nss, std::vector<std::stri
ASSERT(keys.size());
std::vector<BSONObj> indexSpecs;
for (auto keyName : keys) {
- indexSpecs.push_back(BSON("ns" << nss.toString() << "v" << 2 << "key" << BSON(keyName << 1)
- << "name" << (keyName + "_1")));
+ indexSpecs.push_back(
+ BSON("v" << 2 << "key" << BSON(keyName << 1) << "name" << (keyName + "_1")));
}
return indexSpecs;
}
diff --git a/src/mongo/db/catalog/index_catalog.h b/src/mongo/db/catalog/index_catalog.h
index de87ee6a172..8a069ea65a0 100644
--- a/src/mongo/db/catalog/index_catalog.h
+++ b/src/mongo/db/catalog/index_catalog.h
@@ -470,8 +470,6 @@ public:
const IndexDescriptor* desc,
InsertDeleteOptions* options) const = 0;
- virtual void setNs(NamespaceString ns) = 0;
-
virtual void indexBuildSuccess(OperationContext* opCtx, IndexCatalogEntry* index) = 0;
};
} // namespace mongo
diff --git a/src/mongo/db/catalog/index_catalog_entry.h b/src/mongo/db/catalog/index_catalog_entry.h
index de034469453..863718a57fc 100644
--- a/src/mongo/db/catalog/index_catalog_entry.h
+++ b/src/mongo/db/catalog/index_catalog_entry.h
@@ -138,8 +138,6 @@ public:
virtual boost::optional<Timestamp> getMinimumVisibleSnapshot() = 0;
virtual void setMinimumVisibleSnapshot(const Timestamp name) = 0;
-
- virtual void setNs(NamespaceString ns) = 0;
};
class IndexCatalogEntryContainer {
diff --git a/src/mongo/db/catalog/index_catalog_entry_impl.cpp b/src/mongo/db/catalog/index_catalog_entry_impl.cpp
index 9a30dfc9687..1cd68cd0900 100644
--- a/src/mongo/db/catalog/index_catalog_entry_impl.cpp
+++ b/src/mongo/db/catalog/index_catalog_entry_impl.cpp
@@ -37,6 +37,7 @@
#include <memory>
#include "mongo/base/init.h"
+#include "mongo/db/catalog/collection.h"
#include "mongo/db/catalog/collection_info_cache_impl.h"
#include "mongo/db/concurrency/d_concurrency.h"
#include "mongo/db/concurrency/write_conflict_exception.h"
@@ -59,15 +60,14 @@ namespace mongo {
using std::string;
IndexCatalogEntryImpl::IndexCatalogEntryImpl(OperationContext* const opCtx,
- const NamespaceString& nss,
std::unique_ptr<IndexDescriptor> descriptor,
CollectionInfoCache* const infoCache)
- : _ns(nss),
- _descriptor(std::move(descriptor)),
+ : _descriptor(std::move(descriptor)),
_infoCache(infoCache),
_ordering(Ordering::make(_descriptor->keyPattern())),
_isReady(false),
- _prefix(DurableCatalog::get(opCtx)->getIndexPrefix(opCtx, nss, _descriptor->indexName())) {
+ _prefix(DurableCatalog::get(opCtx)->getIndexPrefix(
+ opCtx, _descriptor->parentNS(), _descriptor->indexName())) {
_descriptor->_cachedEntry = this;
_isReady = _catalogIsReady(opCtx);
@@ -104,7 +104,7 @@ IndexCatalogEntryImpl::IndexCatalogEntryImpl(OperationContext* const opCtx,
MatchExpressionParser::kBanAllSpecialFeatures);
invariant(statusWithMatcher.getStatus());
_filterExpression = std::move(statusWithMatcher.getValue());
- LOG(2) << "have filter expression for " << _ns << " " << _descriptor->indexName() << " "
+ LOG(2) << "have filter expression for " << ns() << " " << _descriptor->indexName() << " "
<< redact(filter);
}
}
@@ -115,6 +115,10 @@ IndexCatalogEntryImpl::~IndexCatalogEntryImpl() {
_descriptor.reset();
}
+const NamespaceString& IndexCatalogEntryImpl::ns() const {
+ return _descriptor->parentNS();
+}
+
void IndexCatalogEntryImpl::init(std::unique_ptr<IndexAccessMethod> accessMethod) {
invariant(!_accessMethod);
_accessMethod = std::move(accessMethod);
@@ -157,7 +161,7 @@ bool IndexCatalogEntryImpl::isMultikey(OperationContext* opCtx) const {
}
for (const MultikeyPathInfo& path : txnParticipant.getUncommittedMultikeyPathInfos()) {
- if (path.nss == NamespaceString(_ns) && path.indexName == _descriptor->indexName()) {
+ if (path.nss == ns() && path.indexName == _descriptor->indexName()) {
return true;
}
}
@@ -175,7 +179,7 @@ MultikeyPaths IndexCatalogEntryImpl::getMultikeyPaths(OperationContext* opCtx) c
MultikeyPaths ret = _indexMultikeyPaths;
for (const MultikeyPathInfo& path : txnParticipant.getUncommittedMultikeyPathInfos()) {
- if (path.nss == NamespaceString(_ns) && path.indexName == _descriptor->indexName()) {
+ if (path.nss == ns() && path.indexName == _descriptor->indexName()) {
MultikeyPathTracker::mergeMultikeyPaths(&ret, path.multikeyPaths);
}
}
@@ -251,7 +255,7 @@ void IndexCatalogEntryImpl::setMultikey(OperationContext* opCtx,
// OperationContext and we can safely defer that write to the end of the batch.
if (MultikeyPathTracker::get(opCtx).isTrackingMultikeyPathInfo()) {
MultikeyPathInfo info;
- info.nss = _ns;
+ info.nss = ns();
info.indexName = _descriptor->indexName();
info.multikeyPaths = paths;
MultikeyPathTracker::get(opCtx).addMultikeyPathInfo(info);
@@ -279,7 +283,7 @@ void IndexCatalogEntryImpl::setMultikey(OperationContext* opCtx,
}
if (indexMetadataHasChanged && _infoCache) {
- LOG(1) << _ns << ": clearing plan cache - index " << _descriptor->keyPattern()
+ LOG(1) << ns() << ": clearing plan cache - index " << _descriptor->keyPattern()
<< " set to multi key.";
_infoCache->clearQueryCache();
}
@@ -294,7 +298,7 @@ void IndexCatalogEntryImpl::setMultikey(OperationContext* opCtx,
auto txnParticipant = TransactionParticipant::get(opCtx);
if (txnParticipant && txnParticipant.inMultiDocumentTransaction()) {
TransactionParticipant::SideTransactionBlock sideTxn(opCtx);
- writeConflictRetry(opCtx, "set index multikey", _ns.ns(), [&] {
+ writeConflictRetry(opCtx, "set index multikey", ns().ns(), [&] {
WriteUnitOfWork wuow(opCtx);
// If we have a prepare optime for recovery, then we always use that. During recovery of
@@ -316,7 +320,7 @@ void IndexCatalogEntryImpl::setMultikey(OperationContext* opCtx,
}
fassert(31164, status);
indexMetadataHasChanged = DurableCatalog::get(opCtx)->setIndexIsMultikey(
- opCtx, _ns, _descriptor->indexName(), paths);
+ opCtx, ns(), _descriptor->indexName(), paths);
opCtx->recoveryUnit()->onCommit(
[onMultikeyCommitFn, indexMetadataHasChanged](boost::optional<Timestamp>) {
onMultikeyCommitFn(indexMetadataHasChanged);
@@ -325,7 +329,7 @@ void IndexCatalogEntryImpl::setMultikey(OperationContext* opCtx,
});
} else {
indexMetadataHasChanged = DurableCatalog::get(opCtx)->setIndexIsMultikey(
- opCtx, _ns, _descriptor->indexName(), paths);
+ opCtx, ns(), _descriptor->indexName(), paths);
}
opCtx->recoveryUnit()->onCommit(
@@ -342,33 +346,28 @@ void IndexCatalogEntryImpl::setMultikey(OperationContext* opCtx,
// previous write in the transaction.
if (txnParticipant && txnParticipant.inMultiDocumentTransaction()) {
txnParticipant.addUncommittedMultikeyPathInfo(
- MultikeyPathInfo{_ns, _descriptor->indexName(), std::move(paths)});
+ MultikeyPathInfo{ns(), _descriptor->indexName(), std::move(paths)});
}
}
-void IndexCatalogEntryImpl::setNs(NamespaceString ns) {
- _ns = ns;
- _descriptor->setNs(std::move(ns));
-}
-
// ----
bool IndexCatalogEntryImpl::_catalogIsReady(OperationContext* opCtx) const {
- return DurableCatalog::get(opCtx)->isIndexReady(opCtx, _ns, _descriptor->indexName());
+ return DurableCatalog::get(opCtx)->isIndexReady(opCtx, ns(), _descriptor->indexName());
}
bool IndexCatalogEntryImpl::_catalogIsPresent(OperationContext* opCtx) const {
- return DurableCatalog::get(opCtx)->isIndexPresent(opCtx, _ns, _descriptor->indexName());
+ return DurableCatalog::get(opCtx)->isIndexPresent(opCtx, ns(), _descriptor->indexName());
}
bool IndexCatalogEntryImpl::_catalogIsMultikey(OperationContext* opCtx,
MultikeyPaths* multikeyPaths) const {
return DurableCatalog::get(opCtx)->isIndexMultikey(
- opCtx, _ns, _descriptor->indexName(), multikeyPaths);
+ opCtx, ns(), _descriptor->indexName(), multikeyPaths);
}
KVPrefix IndexCatalogEntryImpl::_catalogGetPrefix(OperationContext* opCtx) const {
- return DurableCatalog::get(opCtx)->getIndexPrefix(opCtx, _ns, _descriptor->indexName());
+ return DurableCatalog::get(opCtx)->getIndexPrefix(opCtx, ns(), _descriptor->indexName());
}
} // namespace mongo
diff --git a/src/mongo/db/catalog/index_catalog_entry_impl.h b/src/mongo/db/catalog/index_catalog_entry_impl.h
index cb697a3d177..525b003b878 100644
--- a/src/mongo/db/catalog/index_catalog_entry_impl.h
+++ b/src/mongo/db/catalog/index_catalog_entry_impl.h
@@ -59,17 +59,12 @@ class IndexCatalogEntryImpl : public IndexCatalogEntry {
public:
explicit IndexCatalogEntryImpl(
OperationContext* opCtx,
- const NamespaceString& nss,
std::unique_ptr<IndexDescriptor> descriptor, // ownership passes to me
CollectionInfoCache* infoCache); // not owned, optional
~IndexCatalogEntryImpl() final;
- const NamespaceString& ns() const final {
- return _ns;
- }
-
- void setNs(NamespaceString ns) final;
+ const NamespaceString& ns() const final;
void init(std::unique_ptr<IndexAccessMethod> accessMethod) final;
@@ -192,8 +187,6 @@ private:
// -----
- NamespaceString _ns;
-
std::unique_ptr<IndexDescriptor> _descriptor; // owned here
CollectionInfoCache* _infoCache; // not owned here
diff --git a/src/mongo/db/catalog/index_catalog_impl.cpp b/src/mongo/db/catalog/index_catalog_impl.cpp
index a4d4c6ec5b8..261f656d77c 100644
--- a/src/mongo/db/catalog/index_catalog_impl.cpp
+++ b/src/mongo/db/catalog/index_catalog_impl.cpp
@@ -41,7 +41,6 @@
#include "mongo/db/audit.h"
#include "mongo/db/background.h"
#include "mongo/db/catalog/collection.h"
-#include "mongo/db/catalog/disable_index_spec_namespace_generation_gen.h"
#include "mongo/db/catalog/index_build_block.h"
#include "mongo/db/catalog/index_catalog_entry_impl.h"
#include "mongo/db/catalog/index_key_validate.h"
@@ -373,7 +372,7 @@ IndexCatalogEntry* IndexCatalogImpl::createIndexEntry(OperationContext* opCtx,
auto* const descriptorPtr = descriptor.get();
auto entry = std::make_shared<IndexCatalogEntryImpl>(
- opCtx, _collection->ns(), std::move(descriptor), _collection->infoCache());
+ opCtx, std::move(descriptor), _collection->infoCache());
IndexDescriptor* desc = entry->descriptor();
@@ -531,21 +530,6 @@ Status IndexCatalogImpl::_isSpecOk(OperationContext* opCtx, const BSONObj& spec)
if (nss.isOplog())
return Status(ErrorCodes::CannotCreateIndex, "cannot have an index on the oplog");
- // If we stop generating the 'ns' field for index specs during testing, then we shouldn't
- // validate that the 'ns' field is missing.
- if (!disableIndexSpecNamespaceGeneration.load()) {
- const BSONElement specNamespace = spec["ns"];
- if (specNamespace.type() != String)
- return Status(ErrorCodes::CannotCreateIndex,
- "the index spec is missing a \"ns\" string field");
-
- if (nss.ns() != specNamespace.valueStringData())
- return Status(ErrorCodes::CannotCreateIndex,
- str::stream() << "the \"ns\" field of the index spec '"
- << specNamespace.valueStringData()
- << "' does not match the collection name '" << nss << "'");
- }
-
// logical name of the index
const BSONElement nameElem = spec["name"];
if (nameElem.type() != String)
@@ -811,7 +795,6 @@ BSONObj IndexCatalogImpl::getDefaultIdIndexSpec() const {
BSONObjBuilder b;
b.append("v", static_cast<int>(indexVersion));
b.append("name", "_id_");
- b.append("ns", _collection->ns().ns());
b.append("key", _idObj);
if (_collection->getDefaultCollator() && indexVersion >= IndexVersion::kV2) {
// Creating an index with the "collation" option requires a v=2 index.
@@ -1660,6 +1643,14 @@ StatusWith<BSONObj> IndexCatalogImpl::_fixIndexSpec(OperationContext* opCtx,
}
b.append("name", name);
+ // During repair, if the 'ns' field exists in the index spec, do not remove it as repair can be
+ // running on old data files from other mongod versions. Removing the 'ns' field during repair
+ // would prevent the data files from starting up on the original mongod version as the 'ns'
+ // field is required to be present in 3.6 and 4.0.
+ if (storageGlobalParams.repair && o.hasField("ns")) {
+ b.append("ns", o.getField("ns").String());
+ }
+
{
BSONObjIterator i(o);
while (i.more()) {
@@ -1668,8 +1659,9 @@ StatusWith<BSONObj> IndexCatalogImpl::_fixIndexSpec(OperationContext* opCtx,
if (s == "_id") {
// skip
- } else if (s == "dropDups") {
+ } else if (s == "dropDups" || s == "ns") {
// dropDups is silently ignored and removed from the spec as of SERVER-14710.
+ // ns is removed from the spec as of 4.4.
} else if (s == "v" || s == "unique" || s == "key" || s == "name") {
// covered above
} else {
@@ -1681,13 +1673,4 @@ StatusWith<BSONObj> IndexCatalogImpl::_fixIndexSpec(OperationContext* opCtx,
return b.obj();
}
-void IndexCatalogImpl::setNs(NamespaceString ns) {
- for (auto&& ice : _readyIndexes) {
- ice->setNs(ns);
- }
-
- for (auto&& ice : _buildingIndexes) {
- ice->setNs(ns);
- }
-}
} // namespace mongo
diff --git a/src/mongo/db/catalog/index_catalog_impl.h b/src/mongo/db/catalog/index_catalog_impl.h
index 813c90b3d4e..9eecee90e52 100644
--- a/src/mongo/db/catalog/index_catalog_impl.h
+++ b/src/mongo/db/catalog/index_catalog_impl.h
@@ -296,8 +296,6 @@ public:
const IndexDescriptor* desc,
InsertDeleteOptions* options) const override;
- void setNs(NamespaceString ns) override;
-
void indexBuildSuccess(OperationContext* opCtx, IndexCatalogEntry* index) override;
private:
diff --git a/src/mongo/db/catalog/index_catalog_noop.h b/src/mongo/db/catalog/index_catalog_noop.h
index a9caf06f132..8590d18b37d 100644
--- a/src/mongo/db/catalog/index_catalog_noop.h
+++ b/src/mongo/db/catalog/index_catalog_noop.h
@@ -236,8 +236,6 @@ public:
const IndexDescriptor* desc,
InsertDeleteOptions* options) const override {}
- void setNs(NamespaceString ns) override {}
-
void indexBuildSuccess(OperationContext* opCtx, IndexCatalogEntry* index) override {}
};
diff --git a/src/mongo/db/catalog/index_key_validate.cpp b/src/mongo/db/catalog/index_key_validate.cpp
index 2bc450516fb..83c6812f5b1 100644
--- a/src/mongo/db/catalog/index_key_validate.cpp
+++ b/src/mongo/db/catalog/index_key_validate.cpp
@@ -40,7 +40,6 @@
#include "mongo/base/status.h"
#include "mongo/base/status_with.h"
-#include "mongo/db/catalog/disable_index_spec_namespace_generation_gen.h"
#include "mongo/db/field_ref.h"
#include "mongo/db/index/index_descriptor.h"
#include "mongo/db/index/wildcard_key_generator.h"
@@ -255,7 +254,6 @@ BSONObj removeUnknownFields(const BSONObj& indexSpec) {
StatusWith<BSONObj> validateIndexSpec(
OperationContext* opCtx,
const BSONObj& indexSpec,
- const NamespaceString& expectedNamespace,
const ServerGlobalParams::FeatureCompatibility& featureCompatibility) {
bool hasKeyPatternField = false;
bool hasIndexNameField = false;
@@ -327,28 +325,6 @@ StatusWith<BSONObj> validateIndexSpec(
hasIndexNameField = true;
} else if (IndexDescriptor::kNamespaceFieldName == indexSpecElemFieldName) {
- if (indexSpecElem.type() != BSONType::String) {
- return {ErrorCodes::TypeMismatch,
- str::stream()
- << "The field '" << IndexDescriptor::kNamespaceFieldName
- << "' must be a string, but got " << typeName(indexSpecElem.type())};
- }
-
- StringData ns = indexSpecElem.valueStringData();
- if (ns.empty()) {
- return {ErrorCodes::BadValue,
- str::stream() << "The field '" << IndexDescriptor::kNamespaceFieldName
- << "' cannot be an empty string"};
- }
-
- if (ns != expectedNamespace.ns()) {
- return {ErrorCodes::BadValue,
- str::stream()
- << "The value of the field '" << IndexDescriptor::kNamespaceFieldName
- << "' (" << ns << ") doesn't match the namespace '" << expectedNamespace
- << "'"};
- }
-
hasNamespaceField = true;
} else if (IndexDescriptor::kIndexVersionFieldName == indexSpecElemFieldName) {
if (!indexSpecElem.isNumber()) {
@@ -485,29 +461,24 @@ StatusWith<BSONObj> validateIndexSpec(
<< static_cast<int>(*resolvedIndexVersion)};
}
- if (!hasNamespaceField || !hasVersionField) {
- BSONObjBuilder bob;
+ BSONObj modifiedSpec = indexSpec;
- // Only generate the 'ns' field for the index spec if it's missing it and if the server test
- // parameter to disable the generation isn't enabled.
- if (!hasNamespaceField && !disableIndexSpecNamespaceGeneration.load()) {
- // We create a new index specification with the 'ns' field set as 'expectedNamespace' if
- // the field was omitted.
- bob.append(IndexDescriptor::kNamespaceFieldName, expectedNamespace.ns());
- }
-
- if (!hasVersionField) {
- // We create a new index specification with the 'v' field set as 'defaultIndexVersion'
- // if the field was omitted.
- bob.append(IndexDescriptor::kIndexVersionFieldName,
- static_cast<int>(*resolvedIndexVersion));
- }
+ // Ignore any 'ns' field in the index spec because this field is dropped post-4.0. Don't remove
+ // the field during repair, as repair may run on old data files (version 3.6 and 4.0) that
+ // require the field to be present.
+ if (hasNamespaceField && !storageGlobalParams.repair) {
+ modifiedSpec = modifiedSpec.removeField(IndexDescriptor::kNamespaceFieldName);
+ }
- bob.appendElements(indexSpec);
- return bob.obj();
+ if (!hasVersionField) {
+ // We create a new index specification with the 'v' field set as 'defaultIndexVersion' if
+ // the field was omitted.
+ BSONObj versionObj = BSON(IndexDescriptor::kIndexVersionFieldName
+ << static_cast<int>(*resolvedIndexVersion));
+ modifiedSpec = modifiedSpec.addField(versionObj.firstElement());
}
- return indexSpec;
+ return modifiedSpec;
}
Status validateIdIndexSpec(const BSONObj& indexSpec) {
diff --git a/src/mongo/db/catalog/index_key_validate.h b/src/mongo/db/catalog/index_key_validate.h
index 52ba7fd3ed2..7c177c50355 100644
--- a/src/mongo/db/catalog/index_key_validate.h
+++ b/src/mongo/db/catalog/index_key_validate.h
@@ -58,7 +58,6 @@ Status validateKeyPattern(const BSONObj& key, IndexDescriptor::IndexVersion inde
StatusWith<BSONObj> validateIndexSpec(
OperationContext* opCtx,
const BSONObj& indexSpec,
- const NamespaceString& expectedNamespace,
const ServerGlobalParams::FeatureCompatibility& featureCompatibility);
/**
diff --git a/src/mongo/db/catalog/index_spec_validate_test.cpp b/src/mongo/db/catalog/index_spec_validate_test.cpp
index 6b472d09073..cb2d66df78f 100644
--- a/src/mongo/db/catalog/index_spec_validate_test.cpp
+++ b/src/mongo/db/catalog/index_spec_validate_test.cpp
@@ -55,7 +55,6 @@ using index_key_validate::validateIndexSpec;
using index_key_validate::validateIndexSpecCollation;
using unittest::EnsureFCV;
-const NamespaceString kTestNamespace("test", "index_spec_validate");
constexpr OperationContext* kDefaultOpCtx = nullptr;
/**
@@ -75,7 +74,6 @@ TEST(IndexSpecValidateTest, ReturnsAnErrorIfKeyPatternIsNotAnObject) {
validateIndexSpec(kDefaultOpCtx,
BSON("key" << 1 << "name"
<< "indexName"),
- kTestNamespace,
serverGlobalParams.featureCompatibility));
ASSERT_EQ(ErrorCodes::TypeMismatch,
validateIndexSpec(kDefaultOpCtx,
@@ -83,13 +81,11 @@ TEST(IndexSpecValidateTest, ReturnsAnErrorIfKeyPatternIsNotAnObject) {
<< "not an object"
<< "name"
<< "indexName"),
- kTestNamespace,
serverGlobalParams.featureCompatibility));
ASSERT_EQ(ErrorCodes::TypeMismatch,
validateIndexSpec(kDefaultOpCtx,
BSON("key" << BSONArray() << "name"
<< "indexName"),
- kTestNamespace,
serverGlobalParams.featureCompatibility));
}
@@ -98,7 +94,6 @@ TEST(IndexSpecValidateTest, ReturnsAnErrorIfFieldRepeatedInKeyPattern) {
validateIndexSpec(kDefaultOpCtx,
BSON("key" << BSON("field" << 1 << "field" << 1) << "name"
<< "indexName"),
- kTestNamespace,
serverGlobalParams.featureCompatibility));
ASSERT_EQ(ErrorCodes::BadValue,
validateIndexSpec(kDefaultOpCtx,
@@ -106,7 +101,6 @@ TEST(IndexSpecValidateTest, ReturnsAnErrorIfFieldRepeatedInKeyPattern) {
<< "2dsphere")
<< "name"
<< "indexName"),
- kTestNamespace,
serverGlobalParams.featureCompatibility));
}
@@ -115,7 +109,6 @@ TEST(IndexSpecValidateTest, ReturnsAnErrorIfKeyPatternIsNotPresent) {
validateIndexSpec(kDefaultOpCtx,
BSON("name"
<< "indexName"),
- kTestNamespace,
serverGlobalParams.featureCompatibility));
}
@@ -123,7 +116,6 @@ TEST(IndexSpecValidateTest, ReturnsAnErrorIfNameIsNotAString) {
ASSERT_EQ(ErrorCodes::TypeMismatch,
validateIndexSpec(kDefaultOpCtx,
BSON("key" << BSON("field" << 1) << "name" << 1),
- kTestNamespace,
serverGlobalParams.featureCompatibility));
}
@@ -131,93 +123,20 @@ TEST(IndexSpecValidateTest, ReturnsAnErrorIfNameIsNotPresent) {
ASSERT_EQ(ErrorCodes::FailedToParse,
validateIndexSpec(kDefaultOpCtx,
BSON("key" << BSON("field" << 1)),
- kTestNamespace,
serverGlobalParams.featureCompatibility));
}
-TEST(IndexSpecValidateTest, ReturnsAnErrorIfNamespaceIsNotAString) {
- ASSERT_EQ(ErrorCodes::TypeMismatch,
- validateIndexSpec(kDefaultOpCtx,
- BSON("key" << BSON("field" << 1) << "name"
- << "indexName"
- << "ns" << 1),
- kTestNamespace,
- serverGlobalParams.featureCompatibility));
- ASSERT_EQ(ErrorCodes::TypeMismatch,
- validateIndexSpec(kDefaultOpCtx,
- BSON("key" << BSON("field" << 1) << "name"
- << "indexName"
- << "ns" << BSONObj()),
- kTestNamespace,
- serverGlobalParams.featureCompatibility));
-}
-
-TEST(IndexSpecValidateTest, ReturnsAnErrorIfNamespaceIsEmptyString) {
- ASSERT_EQ(ErrorCodes::BadValue,
- validateIndexSpec(kDefaultOpCtx,
- BSON("key" << BSON("field" << 1) << "name"
- << "indexName"
- << "ns"
- << ""),
- NamespaceString(),
- serverGlobalParams.featureCompatibility));
-}
-
-TEST(IndexSpecValidateTest, ReturnsAnErrorIfNamespaceDoesNotMatch) {
- ASSERT_EQ(ErrorCodes::BadValue,
- validateIndexSpec(kDefaultOpCtx,
- BSON("key" << BSON("field" << 1) << "name"
- << "indexName"
- << "ns"
- << "some string"),
- kTestNamespace,
- serverGlobalParams.featureCompatibility));
-
- // Verify that we reject the index specification when the "ns" field only contains the
- // collection name.
- ASSERT_EQ(ErrorCodes::BadValue,
- validateIndexSpec(kDefaultOpCtx,
- BSON("key" << BSON("field" << 1) << "name"
- << "indexName"
- << "ns" << kTestNamespace.coll()),
- kTestNamespace,
- serverGlobalParams.featureCompatibility));
-}
-
-TEST(IndexSpecValidateTest, ReturnsIndexSpecWithNamespaceFilledInIfItIsNotPresent) {
+TEST(IndexSpecValidateTest, ReturnsIndexSpecUnchangedIfVersionIsPresent) {
auto result = validateIndexSpec(kDefaultOpCtx,
BSON("key" << BSON("field" << 1) << "name"
<< "indexName"
<< "v" << 1),
- kTestNamespace,
- serverGlobalParams.featureCompatibility);
- ASSERT_OK(result.getStatus());
-
- // We don't care about the order of the fields in the resulting index specification.
- ASSERT_BSONOBJ_EQ(sorted(BSON("key" << BSON("field" << 1) << "name"
- << "indexName"
- << "ns" << kTestNamespace.ns() << "v" << 1)),
- sorted(result.getValue()));
-
- // Verify that the index specification we returned is still considered valid.
- ASSERT_OK(validateIndexSpec(
- kDefaultOpCtx, result.getValue(), kTestNamespace, serverGlobalParams.featureCompatibility));
-}
-
-TEST(IndexSpecValidateTest, ReturnsIndexSpecUnchangedIfNamespaceAndVersionArePresent) {
- auto result = validateIndexSpec(kDefaultOpCtx,
- BSON("key" << BSON("field" << 1) << "name"
- << "indexName"
- << "ns" << kTestNamespace.ns() << "v" << 1),
- kTestNamespace,
serverGlobalParams.featureCompatibility);
ASSERT_OK(result.getStatus());
// We don't care about the order of the fields in the resulting index specification.
ASSERT_BSONOBJ_EQ(sorted(BSON("key" << BSON("field" << 1) << "name"
<< "indexName"
- << "ns"
- << "test.index_spec_validate"
<< "v" << 1)),
sorted(result.getValue()));
}
@@ -229,14 +148,12 @@ TEST(IndexSpecValidateTest, ReturnsAnErrorIfVersionIsNotANumber) {
<< "indexName"
<< "v"
<< "not a number"),
- kTestNamespace,
serverGlobalParams.featureCompatibility));
ASSERT_EQ(ErrorCodes::TypeMismatch,
validateIndexSpec(kDefaultOpCtx,
BSON("key" << BSON("field" << 1) << "name"
<< "indexName"
<< "v" << BSONObj()),
- kTestNamespace,
serverGlobalParams.featureCompatibility));
}
@@ -246,28 +163,24 @@ TEST(IndexSpecValidateTest, ReturnsAnErrorIfVersionIsNotRepresentableAsInt) {
BSON("key" << BSON("field" << 1) << "name"
<< "indexName"
<< "v" << 2.2),
- kTestNamespace,
serverGlobalParams.featureCompatibility));
ASSERT_EQ(ErrorCodes::BadValue,
validateIndexSpec(kDefaultOpCtx,
BSON("key" << BSON("field" << 1) << "name"
<< "indexName"
<< "v" << std::nan("1")),
- kTestNamespace,
serverGlobalParams.featureCompatibility));
ASSERT_EQ(ErrorCodes::BadValue,
validateIndexSpec(kDefaultOpCtx,
BSON("key" << BSON("field" << 1) << "name"
<< "indexName"
<< "v" << std::numeric_limits<double>::infinity()),
- kTestNamespace,
serverGlobalParams.featureCompatibility));
ASSERT_EQ(ErrorCodes::BadValue,
validateIndexSpec(kDefaultOpCtx,
BSON("key" << BSON("field" << 1) << "name"
<< "indexName"
<< "v" << std::numeric_limits<long long>::max()),
- kTestNamespace,
serverGlobalParams.featureCompatibility));
}
@@ -277,7 +190,6 @@ TEST(IndexSpecValidateTest, ReturnsAnErrorIfVersionIsV0) {
BSON("key" << BSON("field" << 1) << "name"
<< "indexName"
<< "v" << 0),
- kTestNamespace,
serverGlobalParams.featureCompatibility));
}
@@ -289,7 +201,6 @@ TEST(IndexSpecValidateTest, ReturnsAnErrorIfVersionIsUnsupported) {
<< "v" << 3 << "collation"
<< BSON("locale"
<< "en")),
- kTestNamespace,
serverGlobalParams.featureCompatibility));
ASSERT_EQ(ErrorCodes::CannotCreateIndex,
@@ -297,7 +208,6 @@ TEST(IndexSpecValidateTest, ReturnsAnErrorIfVersionIsUnsupported) {
BSON("key" << BSON("field" << 1) << "name"
<< "indexName"
<< "v" << -3LL),
- kTestNamespace,
serverGlobalParams.featureCompatibility));
}
@@ -306,49 +216,45 @@ TEST(IndexSpecValidateTest, AcceptsIndexVersionsThatAreAllowedForCreation) {
BSON("key" << BSON("field" << 1) << "name"
<< "indexName"
<< "v" << 1),
- kTestNamespace,
serverGlobalParams.featureCompatibility);
ASSERT_OK(result.getStatus());
// We don't care about the order of the fields in the resulting index specification.
ASSERT_BSONOBJ_EQ(sorted(BSON("key" << BSON("field" << 1) << "name"
<< "indexName"
- << "ns" << kTestNamespace.ns() << "v" << 1)),
+ << "v" << 1)),
sorted(result.getValue()));
result = validateIndexSpec(kDefaultOpCtx,
BSON("key" << BSON("field" << 1) << "name"
<< "indexName"
<< "v" << 2LL),
- kTestNamespace,
serverGlobalParams.featureCompatibility);
ASSERT_OK(result.getStatus());
// We don't care about the order of the fields in the resulting index specification.
ASSERT_BSONOBJ_EQ(sorted(BSON("key" << BSON("field" << 1) << "name"
<< "indexName"
- << "ns" << kTestNamespace.ns() << "v" << 2LL)),
+ << "v" << 2LL)),
sorted(result.getValue()));
}
TEST(IndexSpecValidateTest, DefaultIndexVersionIsV2) {
auto result = validateIndexSpec(kDefaultOpCtx,
BSON("key" << BSON("field" << 1) << "name"
- << "indexName"
- << "ns" << kTestNamespace.ns()),
- kTestNamespace,
+ << "indexName"),
serverGlobalParams.featureCompatibility);
ASSERT_OK(result.getStatus());
// We don't care about the order of the fields in the resulting index specification.
ASSERT_BSONOBJ_EQ(sorted(BSON("key" << BSON("field" << 1) << "name"
<< "indexName"
- << "ns" << kTestNamespace.ns() << "v" << 2)),
+ << "v" << 2)),
sorted(result.getValue()));
// Verify that the index specification we returned is still considered valid.
ASSERT_OK(validateIndexSpec(
- kDefaultOpCtx, result.getValue(), kTestNamespace, serverGlobalParams.featureCompatibility));
+ kDefaultOpCtx, result.getValue(), serverGlobalParams.featureCompatibility));
}
TEST(IndexSpecValidateTest, AcceptsIndexVersionV1) {
@@ -356,14 +262,13 @@ TEST(IndexSpecValidateTest, AcceptsIndexVersionV1) {
BSON("key" << BSON("field" << 1) << "name"
<< "indexName"
<< "v" << 1),
- kTestNamespace,
serverGlobalParams.featureCompatibility);
ASSERT_OK(result.getStatus());
// We don't care about the order of the fields in the resulting index specification.
ASSERT_BSONOBJ_EQ(sorted(BSON("key" << BSON("field" << 1) << "name"
<< "indexName"
- << "ns" << kTestNamespace.ns() << "v" << 1)),
+ << "v" << 1)),
sorted(result.getValue()));
}
@@ -373,7 +278,6 @@ TEST(IndexSpecValidateTest, ReturnsAnErrorIfCollationIsNotAnObject) {
BSON("key" << BSON("field" << 1) << "name"
<< "indexName"
<< "collation" << 1),
- kTestNamespace,
serverGlobalParams.featureCompatibility));
ASSERT_EQ(ErrorCodes::TypeMismatch,
validateIndexSpec(kDefaultOpCtx,
@@ -381,14 +285,12 @@ TEST(IndexSpecValidateTest, ReturnsAnErrorIfCollationIsNotAnObject) {
<< "indexName"
<< "collation"
<< "not an object"),
- kTestNamespace,
serverGlobalParams.featureCompatibility));
ASSERT_EQ(ErrorCodes::TypeMismatch,
validateIndexSpec(kDefaultOpCtx,
BSON("key" << BSON("field" << 1) << "name"
<< "indexName"
<< "collation" << BSONArray()),
- kTestNamespace,
serverGlobalParams.featureCompatibility));
}
@@ -398,7 +300,6 @@ TEST(IndexSpecValidateTest, ReturnsAnErrorIfCollationIsEmpty) {
BSON("key" << BSON("field" << 1) << "name"
<< "indexName"
<< "collation" << BSONObj()),
- kTestNamespace,
serverGlobalParams.featureCompatibility));
}
@@ -411,7 +312,6 @@ TEST(IndexSpecValidateTest, ReturnsAnErrorIfCollationIsPresentAndVersionIsLessTh
<< BSON("locale"
<< "simple")
<< "v" << 1),
- kTestNamespace,
serverGlobalParams.featureCompatibility));
}
@@ -422,14 +322,13 @@ TEST(IndexSpecValidateTest, AcceptsAnyNonEmptyObjectValueForCollation) {
<< "v" << 2 << "collation"
<< BSON("locale"
<< "simple")),
- kTestNamespace,
serverGlobalParams.featureCompatibility);
ASSERT_OK(result.getStatus());
// We don't care about the order of the fields in the resulting index specification.
ASSERT_BSONOBJ_EQ(sorted(BSON("key" << BSON("field" << 1) << "name"
<< "indexName"
- << "ns" << kTestNamespace.ns() << "v" << 2 << "collation"
+ << "v" << 2 << "collation"
<< BSON("locale"
<< "simple"))),
sorted(result.getValue()));
@@ -439,16 +338,15 @@ TEST(IndexSpecValidateTest, AcceptsAnyNonEmptyObjectValueForCollation) {
<< "indexName"
<< "v" << 2 << "collation"
<< BSON("unknownCollationOption" << true)),
- kTestNamespace,
serverGlobalParams.featureCompatibility);
ASSERT_OK(result.getStatus());
// We don't care about the order of the fields in the resulting index specification.
- ASSERT_BSONOBJ_EQ(sorted(BSON("key" << BSON("field" << 1) << "name"
- << "indexName"
- << "ns" << kTestNamespace.ns() << "v" << 2 << "collation"
- << BSON("unknownCollationOption" << true))),
- sorted(result.getValue()));
+ ASSERT_BSONOBJ_EQ(
+ sorted(BSON("key" << BSON("field" << 1) << "name"
+ << "indexName"
+ << "v" << 2 << "collation" << BSON("unknownCollationOption" << true))),
+ sorted(result.getValue()));
}
TEST(IndexSpecValidateTest, AcceptsIndexSpecIfCollationIsPresentAndVersionIsEqualToV2) {
@@ -458,14 +356,13 @@ TEST(IndexSpecValidateTest, AcceptsIndexSpecIfCollationIsPresentAndVersionIsEqua
<< "v" << 2 << "collation"
<< BSON("locale"
<< "en")),
- kTestNamespace,
serverGlobalParams.featureCompatibility);
ASSERT_OK(result.getStatus());
// We don't care about the order of the fields in the resulting index specification.
ASSERT_BSONOBJ_EQ(sorted(BSON("key" << BSON("field" << 1) << "name"
<< "indexName"
- << "ns" << kTestNamespace.ns() << "v" << 2 << "collation"
+ << "v" << 2 << "collation"
<< BSON("locale"
<< "en"))),
sorted(result.getValue()));
@@ -476,7 +373,6 @@ TEST(IndexSpecValidateTest, ReturnsAnErrorIfUnknownFieldIsPresentInSpecV2) {
BSON("key" << BSON("field" << 1) << "name"
<< "indexName"
<< "v" << 2 << "unknownField" << 1),
- kTestNamespace,
serverGlobalParams.featureCompatibility);
ASSERT_EQ(ErrorCodes::InvalidIndexSpecificationOption, result);
}
@@ -486,7 +382,6 @@ TEST(IndexSpecValidateTest, ReturnsAnErrorIfUnknownFieldIsPresentInSpecV1) {
BSON("key" << BSON("field" << 1) << "name"
<< "indexName"
<< "v" << 1 << "unknownField" << 1),
- kTestNamespace,
serverGlobalParams.featureCompatibility);
ASSERT_EQ(ErrorCodes::InvalidIndexSpecificationOption, result);
}
@@ -495,59 +390,53 @@ TEST(IdIndexSpecValidateTest, ReturnsAnErrorIfKeyPatternIsIncorrectForIdIndex) {
ASSERT_EQ(ErrorCodes::BadValue,
validateIdIndexSpec(BSON("key" << BSON("_id" << -1) << "name"
<< "_id_"
- << "ns" << kTestNamespace.ns() << "v" << 2)));
+ << "v" << 2)));
ASSERT_EQ(ErrorCodes::BadValue,
validateIdIndexSpec(BSON("key" << BSON("a" << 1) << "name"
<< "_id_"
- << "ns" << kTestNamespace.ns() << "v" << 2)));
+ << "v" << 2)));
}
TEST(IdIndexSpecValidateTest, ReturnsOKStatusIfKeyPatternCorrectForIdIndex) {
ASSERT_OK(validateIdIndexSpec(BSON("key" << BSON("_id" << 1) << "name"
<< "anyname"
- << "ns" << kTestNamespace.ns() << "v" << 2)));
+ << "v" << 2)));
}
TEST(IdIndexSpecValidateTest, ReturnsAnErrorIfFieldNotAllowedForIdIndex) {
ASSERT_EQ(ErrorCodes::InvalidIndexSpecificationOption,
validateIdIndexSpec(BSON("key" << BSON("_id" << 1) << "name"
<< "_id_"
- << "ns" << kTestNamespace.ns() << "v" << 2
- << "background" << false)));
+ << "v" << 2 << "background" << false)));
ASSERT_EQ(ErrorCodes::InvalidIndexSpecificationOption,
validateIdIndexSpec(BSON("key" << BSON("_id" << 1) << "name"
<< "_id_"
- << "ns" << kTestNamespace.ns() << "v" << 2 << "unique"
- << true)));
+ << "v" << 2 << "unique" << true)));
ASSERT_EQ(ErrorCodes::InvalidIndexSpecificationOption,
validateIdIndexSpec(BSON("key" << BSON("_id" << 1) << "name"
<< "_id_"
- << "ns" << kTestNamespace.ns() << "v" << 2
- << "partialFilterExpression" << BSON("a" << 5))));
+ << "v" << 2 << "partialFilterExpression"
+ << BSON("a" << 5))));
ASSERT_EQ(ErrorCodes::InvalidIndexSpecificationOption,
validateIdIndexSpec(BSON("key" << BSON("_id" << 1) << "name"
<< "_id_"
- << "ns" << kTestNamespace.ns() << "v" << 2 << "sparse"
- << false)));
+ << "v" << 2 << "sparse" << false)));
ASSERT_EQ(ErrorCodes::InvalidIndexSpecificationOption,
validateIdIndexSpec(BSON("key" << BSON("_id" << 1) << "name"
<< "_id_"
- << "ns" << kTestNamespace.ns() << "v" << 2
- << "expireAfterSeconds" << 3600)));
+ << "v" << 2 << "expireAfterSeconds" << 3600)));
ASSERT_EQ(ErrorCodes::InvalidIndexSpecificationOption,
validateIdIndexSpec(BSON("key" << BSON("_id" << 1) << "name"
<< "_id_"
- << "ns" << kTestNamespace.ns() << "v" << 2
- << "storageEngine" << BSONObj())));
+ << "v" << 2 << "storageEngine" << BSONObj())));
}
TEST(IdIndexSpecValidateTest, ReturnsOKStatusIfAllFieldsAllowedForIdIndex) {
- ASSERT_OK(
- validateIdIndexSpec(BSON("key" << BSON("_id" << 1) << "name"
- << "_id_"
- << "ns" << kTestNamespace.ns() << "v" << 2 << "collation"
- << BSON("locale"
- << "simple"))));
+ ASSERT_OK(validateIdIndexSpec(BSON("key" << BSON("_id" << 1) << "name"
+ << "_id_"
+ << "v" << 2 << "collation"
+ << BSON("locale"
+ << "simple"))));
}
TEST(IndexSpecCollationValidateTest, FillsInFullCollationSpec) {
@@ -559,8 +448,7 @@ TEST(IndexSpecCollationValidateTest, FillsInFullCollationSpec) {
auto result = validateIndexSpecCollation(opCtx.get(),
BSON("key" << BSON("field" << 1) << "name"
<< "indexName"
- << "ns" << kTestNamespace.ns() << "v" << 2
- << "collation"
+ << "v" << 2 << "collation"
<< BSON("locale"
<< "mock_reverse_string")),
defaultCollator);
@@ -570,7 +458,7 @@ TEST(IndexSpecCollationValidateTest, FillsInFullCollationSpec) {
ASSERT_BSONOBJ_EQ(
sorted(BSON("key" << BSON("field" << 1) << "name"
<< "indexName"
- << "ns" << kTestNamespace.ns() << "v" << 2 << "collation"
+ << "v" << 2 << "collation"
<< BSON("locale"
<< "mock_reverse_string"
<< "caseLevel" << false << "caseFirst"
@@ -593,8 +481,7 @@ TEST(IndexSpecCollationValidateTest, RemovesCollationFieldIfSimple) {
auto result = validateIndexSpecCollation(opCtx.get(),
BSON("key" << BSON("field" << 1) << "name"
<< "indexName"
- << "ns" << kTestNamespace.ns() << "v" << 2
- << "collation"
+ << "v" << 2 << "collation"
<< BSON("locale"
<< "simple")),
defaultCollator);
@@ -603,7 +490,7 @@ TEST(IndexSpecCollationValidateTest, RemovesCollationFieldIfSimple) {
// We don't care about the order of the fields in the resulting index specification.
ASSERT_BSONOBJ_EQ(sorted(BSON("key" << BSON("field" << 1) << "name"
<< "indexName"
- << "ns" << kTestNamespace.ns() << "v" << 2)),
+ << "v" << 2)),
sorted(result.getValue()));
}
@@ -616,7 +503,7 @@ TEST(IndexSpecCollationValidateTest, FillsInCollationFieldWithCollectionDefaultI
auto result = validateIndexSpecCollation(opCtx.get(),
BSON("key" << BSON("field" << 1) << "name"
<< "indexName"
- << "ns" << kTestNamespace.ns() << "v" << 2),
+ << "v" << 2),
&defaultCollator);
ASSERT_OK(result.getStatus());
@@ -624,7 +511,7 @@ TEST(IndexSpecCollationValidateTest, FillsInCollationFieldWithCollectionDefaultI
ASSERT_BSONOBJ_EQ(
sorted(BSON("key" << BSON("field" << 1) << "name"
<< "indexName"
- << "ns" << kTestNamespace.ns() << "v" << 2 << "collation"
+ << "v" << 2 << "collation"
<< BSON("locale"
<< "mock_reverse_string"
<< "caseLevel" << false << "caseFirst"
@@ -643,7 +530,6 @@ TEST(IndexSpecPartialFilterTest, FailsIfPartialFilterIsNotAnObject) {
BSON("key" << BSON("field" << 1) << "name"
<< "indexName"
<< "partialFilterExpression" << 1),
- kTestNamespace,
serverGlobalParams.featureCompatibility);
ASSERT_EQ(result.getStatus(), ErrorCodes::TypeMismatch);
}
@@ -654,7 +540,6 @@ TEST(IndexSpecPartialFilterTest, FailsIfPartialFilterContainsBannedFeature) {
<< "indexName"
<< "partialFilterExpression"
<< BSON("$jsonSchema" << BSONObj())),
- kTestNamespace,
serverGlobalParams.featureCompatibility);
ASSERT_EQ(result.getStatus(), ErrorCodes::QueryFeatureNotAllowed);
}
@@ -664,7 +549,6 @@ TEST(IndexSpecPartialFilterTest, AcceptsValidPartialFilterExpression) {
BSON("key" << BSON("field" << 1) << "name"
<< "indexName"
<< "partialFilterExpression" << BSON("a" << 1)),
- kTestNamespace,
serverGlobalParams.featureCompatibility);
ASSERT_OK(result.getStatus());
}
@@ -676,7 +560,6 @@ TEST(IndexSpecWildcard, SucceedsWithInclusion) {
BSON("key" << BSON("$**" << 1) << "name"
<< "indexName"
<< "wildcardProjection" << BSON("a" << 1 << "b" << 1)),
- kTestNamespace,
serverGlobalParams.featureCompatibility);
ASSERT_OK(result.getStatus());
}
@@ -688,7 +571,6 @@ TEST(IndexSpecWildcard, SucceedsWithExclusion) {
BSON("key" << BSON("$**" << 1) << "name"
<< "indexName"
<< "wildcardProjection" << BSON("a" << 0 << "b" << 0)),
- kTestNamespace,
serverGlobalParams.featureCompatibility);
ASSERT_OK(result.getStatus());
}
@@ -700,7 +582,6 @@ TEST(IndexSpecWildcard, SucceedsWithExclusionIncludingId) {
<< "indexName"
<< "wildcardProjection"
<< BSON("_id" << 1 << "a" << 0 << "b" << 0)),
- kTestNamespace,
serverGlobalParams.featureCompatibility);
ASSERT_OK(result.getStatus());
}
@@ -712,7 +593,6 @@ TEST(IndexSpecWildcard, SucceedsWithInclusionExcludingId) {
<< "indexName"
<< "wildcardProjection"
<< BSON("_id" << 0 << "a" << 1 << "b" << 1)),
- kTestNamespace,
serverGlobalParams.featureCompatibility);
ASSERT_OK(result.getStatus());
}
@@ -724,7 +604,6 @@ TEST(IndexSpecWildcard, FailsWithInclusionExcludingIdSubfield) {
<< "indexName"
<< "wildcardProjection"
<< BSON("_id.field" << 0 << "a" << 1 << "b" << 1)),
- kTestNamespace,
serverGlobalParams.featureCompatibility);
ASSERT_EQ(result.getStatus().code(), 40179);
}
@@ -736,7 +615,6 @@ TEST(IndexSpecWildcard, FailsWithExclusionIncludingIdSubfield) {
<< "indexName"
<< "wildcardProjection"
<< BSON("_id.field" << 1 << "a" << 0 << "b" << 0)),
- kTestNamespace,
serverGlobalParams.featureCompatibility);
ASSERT_EQ(result.getStatus().code(), 40178);
}
@@ -748,7 +626,6 @@ TEST(IndexSpecWildcard, FailsWithImproperFeatureCompatabilityVersion) {
auto result = validateIndexSpec(kDefaultOpCtx,
BSON("key" << BSON("$**" << 1) << "name"
<< "indexName"),
- kTestNamespace,
serverGlobalParams.featureCompatibility);
ASSERT_EQ(result.getStatus().code(), ErrorCodes::CannotCreateIndex);
}
@@ -760,7 +637,6 @@ TEST(IndexSpecWildcard, FailsWithMixedProjection) {
BSON("key" << BSON("$**" << 1) << "name"
<< "indexName"
<< "wildcardProjection" << BSON("a" << 1 << "b" << 0)),
- kTestNamespace,
serverGlobalParams.featureCompatibility);
ASSERT_EQ(result.getStatus().code(), 40178);
}
@@ -773,7 +649,6 @@ TEST(IndexSpecWildcard, FailsWithComputedFieldsInProjection) {
<< "wildcardProjection"
<< BSON("a" << 1 << "b"
<< "string")),
- kTestNamespace,
serverGlobalParams.featureCompatibility);
ASSERT_EQ(result.getStatus().code(), ErrorCodes::FailedToParse);
}
@@ -784,7 +659,6 @@ TEST(IndexSpecWildcard, FailsWhenProjectionPluginNotWildcard) {
BSON("key" << BSON("a" << 1) << "name"
<< "indexName"
<< "wildcardProjection" << BSON("a" << 1)),
- kTestNamespace,
serverGlobalParams.featureCompatibility);
ASSERT_EQ(result.getStatus().code(), ErrorCodes::BadValue);
}
@@ -795,7 +669,6 @@ TEST(IndexSpecWildcard, FailsWhenProjectionIsNotAnObject) {
BSON("key" << BSON("$**" << 1) << "name"
<< "indexName"
<< "wildcardProjection" << 4),
- kTestNamespace,
serverGlobalParams.featureCompatibility);
ASSERT_EQ(result.getStatus().code(), ErrorCodes::TypeMismatch);
}
@@ -806,7 +679,6 @@ TEST(IndexSpecWildcard, FailsWithEmptyProjection) {
BSON("key" << BSON("$**" << 1) << "name"
<< "indexName"
<< "wildcardProjection" << BSONObj()),
- kTestNamespace,
serverGlobalParams.featureCompatibility);
ASSERT_EQ(result.getStatus().code(), ErrorCodes::FailedToParse);
}
@@ -817,7 +689,6 @@ TEST(IndexSpecWildcard, FailsWhenInclusionWithSubpath) {
BSON("key" << BSON("a.$**" << 1) << "name"
<< "indexName"
<< "wildcardProjection" << BSON("a" << 1)),
- kTestNamespace,
serverGlobalParams.featureCompatibility);
ASSERT_EQ(result.getStatus().code(), ErrorCodes::FailedToParse);
}
@@ -828,7 +699,6 @@ TEST(IndexSpecWildcard, FailsWhenExclusionWithSubpath) {
BSON("key" << BSON("a.$**" << 1) << "name"
<< "indexName"
<< "wildcardProjection" << BSON("b" << 0)),
- kTestNamespace,
serverGlobalParams.featureCompatibility);
ASSERT_EQ(result.getStatus().code(), ErrorCodes::FailedToParse);
}
diff --git a/src/mongo/db/catalog/rename_collection.cpp b/src/mongo/db/catalog/rename_collection.cpp
index 8506619312b..d1df31a6dba 100644
--- a/src/mongo/db/catalog/rename_collection.cpp
+++ b/src/mongo/db/catalog/rename_collection.cpp
@@ -536,34 +536,21 @@ Status renameBetweenDBs(OperationContext* opCtx,
}
});
- // Copy the index descriptions from the source collection, adjusting the ns field.
+ // Copy the index descriptions from the source collection.
{
std::vector<BSONObj> indexesToCopy;
std::unique_ptr<IndexCatalog::IndexIterator> sourceIndIt =
sourceColl->getIndexCatalog()->getIndexIterator(opCtx, true);
while (sourceIndIt->more()) {
auto descriptor = sourceIndIt->next()->descriptor();
- if (descriptor->isIdIndex()) {
- continue;
+ if (!descriptor->isIdIndex()) {
+ indexesToCopy.push_back(descriptor->infoObj());
}
-
- const BSONObj currIndex = descriptor->infoObj();
-
- // Process the source index, adding fields in the same order as they were originally.
- BSONObjBuilder newIndex;
- for (auto&& elem : currIndex) {
- if (elem.fieldNameStringData() == "ns") {
- newIndex.append("ns", tmpName.ns());
- } else {
- newIndex.append(elem);
- }
- }
- indexesToCopy.push_back(newIndex.obj());
}
- // Create indexes using the namespace-adjusted index specs on the empty temporary collection
- // that was just created. Since each index build is possibly replicated to downstream nodes,
- // each createIndex oplog entry must have a distinct timestamp to support correct rollback
+ // Create indexes using the index specs on the empty temporary collection that was just
+ // created. Since each index build is possibly replicated to downstream nodes, each
+ // createIndex oplog entry must have a distinct timestamp to support correct rollback
// operation. This is achieved by writing the createIndexes oplog entry *before* creating
// the index. Using IndexCatalog::createIndexOnEmptyCollection() for the index creation
// allows us to add and commit the index within a single WriteUnitOfWork and avoids the
diff --git a/src/mongo/db/catalog/rename_collection_test.cpp b/src/mongo/db/catalog/rename_collection_test.cpp
index 4c7e994f061..a27769d799b 100644
--- a/src/mongo/db/catalog/rename_collection_test.cpp
+++ b/src/mongo/db/catalog/rename_collection_test.cpp
@@ -415,7 +415,7 @@ void _createIndexOnEmptyCollection(OperationContext* opCtx,
<< " because collection " << nss << " does not exist.";
auto indexInfoObj = BSON("v" << int(IndexDescriptor::kLatestIndexVersion) << "key"
- << BSON("a" << 1) << "name" << indexName << "ns" << nss.ns());
+ << BSON("a" << 1) << "name" << indexName);
auto indexCatalog = collection->getIndexCatalog();
WriteUnitOfWork wuow(opCtx);
diff --git a/src/mongo/db/cloner.cpp b/src/mongo/db/cloner.cpp
index 1d19746cd7f..2a9c6d70b24 100644
--- a/src/mongo/db/cloner.cpp
+++ b/src/mongo/db/cloner.cpp
@@ -81,33 +81,6 @@ MONGO_FAIL_POINT_DEFINE(movePrimaryFailPoint);
BSONElement getErrField(const BSONObj& o);
-namespace {
-
-/* for index info object:
- { "name" : "name_1" , "ns" : "foo.index3" , "key" : { "name" : 1.0 } }
- we need to fix up the value in the "ns" parameter so that the name prefix is correct on a
- copy to a new name.
-*/
-BSONObj fixIndexSpec(const string& newDbName, BSONObj indexSpec) {
- BSONObjBuilder bob;
-
- for (auto&& indexSpecElem : indexSpec) {
- auto indexSpecElemFieldName = indexSpecElem.fieldNameStringData();
- if (IndexDescriptor::kNamespaceFieldName == indexSpecElemFieldName) {
- uassert(10024, "bad ns field for index during dbcopy", indexSpecElem.type() == String);
- const char* p = strchr(indexSpecElem.valuestr(), '.');
- uassert(10025, "bad ns field for index during dbcopy [2]", p);
- string newname = newDbName + p;
- bob.append(IndexDescriptor::kNamespaceFieldName, newname);
- } else {
- bob.append(indexSpecElem);
- }
- }
-
- return bob.obj();
-}
-} // namespace
-
BSONObj Cloner::getIdIndexSpec(const std::list<BSONObj>& indexSpecs) {
for (auto&& indexSpec : indexSpecs) {
BSONElement indexName;
@@ -156,12 +129,13 @@ struct Cloner::Fun {
const bool createDefaultIndexes = true;
CollectionOptions collectionOptions = uassertStatusOK(CollectionOptions::parse(
from_options, CollectionOptions::ParseKind::parseForCommand));
- auto indexSpec = fixIndexSpec(to_collection.db().toString(), from_id_index);
- invariant(
- db->userCreateNS(
- opCtx, to_collection, collectionOptions, createDefaultIndexes, indexSpec),
- str::stream() << "collection creation failed during clone ["
- << to_collection.ns() << "]");
+ invariant(db->userCreateNS(opCtx,
+ to_collection,
+ collectionOptions,
+ createDefaultIndexes,
+ from_id_index),
+ str::stream() << "collection creation failed during clone ["
+ << to_collection.ns() << "]");
wunit.commit();
collection = db->getCollection(opCtx, to_collection);
invariant(collection,
@@ -337,19 +311,13 @@ void Cloner::copyIndexes(OperationContext* opCtx,
LOG(2) << "\t\t copyIndexes " << from_collection << " to " << to_collection << " on "
<< _conn->getServerAddress();
- vector<BSONObj> indexesToBuild;
- for (auto&& indexSpec : from_indexes) {
- indexesToBuild.push_back(fixIndexSpec(to_collection.db().toString(), indexSpec));
- }
-
uassert(ErrorCodes::PrimarySteppedDown,
str::stream() << "Not primary while copying indexes from " << from_collection.ns()
<< " to " << to_collection.ns() << " (Cloner)",
!opCtx->writesAreReplicated() ||
repl::ReplicationCoordinator::get(opCtx)->canAcceptWritesFor(opCtx, to_collection));
-
- if (indexesToBuild.empty())
+ if (from_indexes.empty())
return;
// We are under lock here again, so reload the database in case it may have disappeared
@@ -370,8 +338,7 @@ void Cloner::copyIndexes(OperationContext* opCtx,
to_collection,
collectionOptions,
createDefaultIndexes,
- fixIndexSpec(to_collection.db().toString(),
- getIdIndexSpec(from_indexes))),
+ getIdIndexSpec(from_indexes)),
str::stream()
<< "Collection creation failed while copying indexes from "
<< from_collection.ns() << " to " << to_collection.ns() << " (Cloner)");
@@ -383,8 +350,9 @@ void Cloner::copyIndexes(OperationContext* opCtx,
}
auto indexCatalog = collection->getIndexCatalog();
- auto prunedIndexesToBuild = indexCatalog->removeExistingIndexesNoChecks(opCtx, indexesToBuild);
- if (prunedIndexesToBuild.empty()) {
+ auto indexesToBuild = indexCatalog->removeExistingIndexesNoChecks(
+ opCtx, {std::begin(from_indexes), std::end(from_indexes)});
+ if (indexesToBuild.empty()) {
return;
}
@@ -399,7 +367,7 @@ void Cloner::copyIndexes(OperationContext* opCtx,
ON_BLOCK_EXIT([&] { indexer.cleanUpAfterBuild(opCtx, collection); });
auto indexInfoObjs = uassertStatusOK(
- indexer.init(opCtx, collection, prunedIndexesToBuild, MultiIndexBlock::kNoopOnInitFn));
+ indexer.init(opCtx, collection, indexesToBuild, MultiIndexBlock::kNoopOnInitFn));
uassertStatusOK(indexer.insertAllDocumentsInCollection(opCtx, collection));
uassertStatusOK(indexer.checkConstraints(opCtx));
@@ -624,9 +592,8 @@ Status Cloner::createCollectionsForDb(
CollectionOptions collectionOptions = uassertStatusOK(
CollectionOptions::parse(options, CollectionOptions::ParseKind::parseForStorage));
- auto indexSpec = fixIndexSpec(nss.db().toString(), params.idIndexSpec);
- Status createStatus =
- db->userCreateNS(opCtx, nss, collectionOptions, createDefaultIndexes, indexSpec);
+ Status createStatus = db->userCreateNS(
+ opCtx, nss, collectionOptions, createDefaultIndexes, params.idIndexSpec);
if (!createStatus.isOK()) {
return createStatus;
}
diff --git a/src/mongo/db/commands/create_indexes.cpp b/src/mongo/db/commands/create_indexes.cpp
index a29bf22316a..b9e872e7a4f 100644
--- a/src/mongo/db/commands/create_indexes.cpp
+++ b/src/mongo/db/commands/create_indexes.cpp
@@ -130,7 +130,7 @@ StatusWith<std::vector<BSONObj>> parseAndValidateIndexSpecs(
}
auto indexSpecStatus = index_key_validate::validateIndexSpec(
- opCtx, parsedIndexSpec, ns, featureCompatibility);
+ opCtx, parsedIndexSpec, featureCompatibility);
if (!indexSpecStatus.isOK()) {
return indexSpecStatus.getStatus().withContext(
str::stream() << "Error in specification " << parsedIndexSpec.toString());
diff --git a/src/mongo/db/commands/dbcommands.cpp b/src/mongo/db/commands/dbcommands.cpp
index a08a951f5a4..327983b3bd4 100644
--- a/src/mongo/db/commands/dbcommands.cpp
+++ b/src/mongo/db/commands/dbcommands.cpp
@@ -360,7 +360,7 @@ public:
// Perform index spec validation.
idIndexSpec = uassertStatusOK(index_key_validate::validateIndexSpec(
- opCtx, idIndexSpec, ns, serverGlobalParams.featureCompatibility));
+ opCtx, idIndexSpec, serverGlobalParams.featureCompatibility));
uassertStatusOK(index_key_validate::validateIdIndexSpec(idIndexSpec));
// Validate or fill in _id index collation.
diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp
index 0deaf4d262f..b7da9aaf4bf 100644
--- a/src/mongo/db/commands/mr.cpp
+++ b/src/mongo/db/commands/mr.cpp
@@ -532,11 +532,10 @@ void State::prepTempCollection() {
auto incColl = db->createCollection(
_opCtx, _config.incLong, options, false /* force no _id index */);
- auto rawIndexSpec =
- BSON("key" << BSON("0" << 1) << "ns" << _config.incLong.ns() << "name"
- << "_temp_0");
+ auto rawIndexSpec = BSON("key" << BSON("0" << 1) << "name"
+ << "_temp_0");
auto indexSpec = uassertStatusOK(index_key_validate::validateIndexSpec(
- _opCtx, rawIndexSpec, _config.incLong, serverGlobalParams.featureCompatibility));
+ _opCtx, rawIndexSpec, serverGlobalParams.featureCompatibility));
uassertStatusOKWithContext(
incColl->getIndexCatalog()->createIndexOnEmptyCollection(_opCtx, indexSpec),
@@ -566,13 +565,12 @@ void State::prepTempCollection() {
while (ii->more()) {
const IndexDescriptor* currIndex = ii->next()->descriptor();
BSONObjBuilder b;
- b.append("ns", _config.tempNamespace.ns());
// Copy over contents of the index descriptor's infoObj.
BSONObjIterator j(currIndex->infoObj());
while (j.more()) {
BSONElement e = j.next();
- if (e.fieldNameStringData() == "_id" || e.fieldNameStringData() == "ns")
+ if (e.fieldNameStringData() == "_id")
continue;
b.append(e);
}
diff --git a/src/mongo/db/index/index_descriptor.cpp b/src/mongo/db/index/index_descriptor.cpp
index da27ca8a2e5..8ebf493ba00 100644
--- a/src/mongo/db/index/index_descriptor.cpp
+++ b/src/mongo/db/index/index_descriptor.cpp
@@ -52,7 +52,7 @@ void populateOptionsMap(std::map<StringData, BSONElement>& theMap, const BSONObj
StringData fieldName = e.fieldNameStringData();
if (fieldName == IndexDescriptor::kKeyPatternFieldName ||
- fieldName == IndexDescriptor::kNamespaceFieldName ||
+ fieldName == IndexDescriptor::kNamespaceFieldName || // removed in 4.4
fieldName == IndexDescriptor::kIndexNameFieldName ||
fieldName ==
IndexDescriptor::kIndexVersionFieldName || // not considered for equivalence
@@ -107,7 +107,6 @@ IndexDescriptor::IndexDescriptor(Collection* collection,
_keyPattern(infoObj.getObjectField(IndexDescriptor::kKeyPatternFieldName).getOwned()),
_projection(infoObj.getObjectField(IndexDescriptor::kPathProjectionFieldName).getOwned()),
_indexName(infoObj.getStringField(IndexDescriptor::kIndexNameFieldName)),
- _parentNS(collection->ns()),
_isIdIndex(isIdIndexPattern(_keyPattern)),
_sparse(infoObj[IndexDescriptor::kSparseFieldName].trueValue()),
_unique(_isIdIndex || infoObj[kUniqueFieldName].trueValue()),
@@ -171,6 +170,10 @@ const IndexCatalog* IndexDescriptor::getIndexCatalog() const {
return _collection->getIndexCatalog();
}
+const NamespaceString& IndexDescriptor::parentNS() const {
+ return _collection->ns();
+}
+
bool IndexDescriptor::areIndexOptionsEquivalent(const IndexDescriptor* other) const {
if (isSparse() != other->isSparse()) {
return false;
@@ -201,23 +204,4 @@ bool IndexDescriptor::areIndexOptionsEquivalent(const IndexDescriptor* other) co
});
}
-void IndexDescriptor::setNs(NamespaceString ns) {
- _parentNS = ns;
-
- // Construct a new infoObj with the namespace field replaced.
- _infoObj = renameNsInIndexSpec(_infoObj, ns);
-}
-
-BSONObj IndexDescriptor::renameNsInIndexSpec(BSONObj spec, const NamespaceString& newNs) {
- BSONObjBuilder builder;
- for (auto&& elt : spec) {
- if (elt.fieldNameStringData() == kNamespaceFieldName) {
- builder.append(kNamespaceFieldName, newNs.ns());
- } else {
- builder.append(elt);
- }
- }
- return builder.obj();
-}
-
} // namespace mongo
diff --git a/src/mongo/db/index/index_descriptor.h b/src/mongo/db/index/index_descriptor.h
index e7893e85553..7e955258ab7 100644
--- a/src/mongo/db/index/index_descriptor.h
+++ b/src/mongo/db/index/index_descriptor.h
@@ -75,7 +75,7 @@ public:
static constexpr StringData kIndexVersionFieldName = "v"_sd;
static constexpr StringData kKeyPatternFieldName = "key"_sd;
static constexpr StringData kLanguageOverrideFieldName = "language_override"_sd;
- static constexpr StringData kNamespaceFieldName = "ns"_sd;
+ static constexpr StringData kNamespaceFieldName = "ns"_sd; // Removed in 4.4
static constexpr StringData kPartialFilterExprFieldName = "partialFilterExpression"_sd;
static constexpr StringData kPathProjectionFieldName = "wildcardProjection"_sd;
static constexpr StringData kSparseFieldName = "sparse"_sd;
@@ -85,12 +85,6 @@ public:
static constexpr StringData kWeightsFieldName = "weights"_sd;
/**
- * Given a BSONObj representing an index spec, returns a new owned BSONObj which is identical to
- * 'spec' after replacing the 'ns' field with the value of 'newNs'.
- */
- static BSONObj renameNsInIndexSpec(BSONObj spec, const NamespaceString& newNs);
-
- /**
* infoObj is a copy of the index-describing BSONObj contained in the catalog.
*/
IndexDescriptor(Collection* collection, const std::string& accessMethodName, BSONObj infoObj);
@@ -162,9 +156,7 @@ public:
}
// Return the name of the indexed collection.
- const NamespaceString& parentNS() const {
- return _parentNS;
- }
+ const NamespaceString& parentNS() const;
// Return the name of the access method we must use to access this index's data.
const std::string& getAccessMethodName() const {
@@ -227,8 +219,6 @@ public:
bool areIndexOptionsEquivalent(const IndexDescriptor* other) const;
- void setNs(NamespaceString ns);
-
const BSONObj& collation() const {
return _collation;
}
@@ -266,7 +256,6 @@ private:
BSONObj _keyPattern;
BSONObj _projection;
std::string _indexName;
- NamespaceString _parentNS;
bool _isIdIndex;
bool _sparse;
bool _unique;
diff --git a/src/mongo/db/index_builder.cpp b/src/mongo/db/index_builder.cpp
index c741814a663..f7430beb84b 100644
--- a/src/mongo/db/index_builder.cpp
+++ b/src/mongo/db/index_builder.cpp
@@ -79,20 +79,11 @@ std::string IndexBuilder::name() const {
return _name;
}
-Status IndexBuilder::buildInForeground(OperationContext* opCtx, Database* db) const {
- return _buildAndHandleErrors(opCtx, db, false /*buildInBackground */, nullptr);
-}
-
-Status IndexBuilder::_buildAndHandleErrors(OperationContext* opCtx,
- Database* db,
- bool buildInBackground,
- Lock::DBLock* dbLock) const {
- invariant(!buildInBackground);
- invariant(!dbLock);
+Status IndexBuilder::buildInForeground(OperationContext* opCtx,
+ Database* db,
+ Collection* coll) const {
+ invariant(opCtx->lockState()->isCollectionLockedForMode(coll->ns(), MODE_X));
- const NamespaceString ns(_index["ns"].String());
-
- Collection* coll = db->getCollection(opCtx, ns);
// Collections should not be implicitly created by the index builder.
fassert(40409, coll);
@@ -101,17 +92,12 @@ Status IndexBuilder::_buildAndHandleErrors(OperationContext* opCtx,
// The 'indexer' can throw, so ensure build cleanup occurs.
ON_BLOCK_EXIT([&] { indexer.cleanUpAfterBuild(opCtx, coll); });
- return _build(opCtx, buildInBackground, coll, indexer, dbLock);
+ return _build(opCtx, coll, indexer);
}
Status IndexBuilder::_build(OperationContext* opCtx,
- bool buildInBackground,
Collection* coll,
- MultiIndexBlock& indexer,
- Lock::DBLock* dbLock) const try {
- invariant(!buildInBackground);
- invariant(!dbLock);
-
+ MultiIndexBlock& indexer) const try {
auto ns = coll->ns();
{
@@ -163,7 +149,6 @@ Status IndexBuilder::_build(OperationContext* opCtx,
}
{
- Lock::CollectionLock collLock(opCtx, ns, MODE_IX);
// WriteConflict exceptions and statuses are not expected to escape this method.
status = indexer.insertAllDocumentsInCollection(opCtx, coll);
if (!status.isOK()) {
diff --git a/src/mongo/db/index_builder.h b/src/mongo/db/index_builder.h
index 11eeeea971c..2b68cd5ee9a 100644
--- a/src/mongo/db/index_builder.h
+++ b/src/mongo/db/index_builder.h
@@ -92,21 +92,12 @@ public:
/**
* Instead of building the index in a background thread, build on the current thread.
*/
- Status buildInForeground(OperationContext* opCtx, Database* db) const;
+ Status buildInForeground(OperationContext* opCtx, Database* db, Collection* coll) const;
static bool canBuildInBackground();
private:
- Status _buildAndHandleErrors(OperationContext* opCtx,
- Database* db,
- bool buildInBackground,
- Lock::DBLock* dbLock) const;
-
- Status _build(OperationContext* opCtx,
- bool buildInBackground,
- Collection* coll,
- MultiIndexBlock& indexer,
- Lock::DBLock* dbLock) const;
+ Status _build(OperationContext* opCtx, Collection* coll, MultiIndexBlock& indexer) const;
const BSONObj _index;
const IndexConstraints _indexConstraints;
const ReplicatedWrites _replicatedWrites;
diff --git a/src/mongo/db/index_builds_coordinator_mongod_test.cpp b/src/mongo/db/index_builds_coordinator_mongod_test.cpp
index 6ba35b27e6b..7d496ac6952 100644
--- a/src/mongo/db/index_builds_coordinator_mongod_test.cpp
+++ b/src/mongo/db/index_builds_coordinator_mongod_test.cpp
@@ -95,8 +95,8 @@ std::vector<BSONObj> makeSpecs(const NamespaceString& nss, std::vector<std::stri
invariant(keys.size());
std::vector<BSONObj> indexSpecs;
for (auto keyName : keys) {
- indexSpecs.push_back(BSON("ns" << nss.toString() << "v" << 2 << "key" << BSON(keyName << 1)
- << "name" << (keyName + "_1")));
+ indexSpecs.push_back(
+ BSON("v" << 2 << "key" << BSON(keyName << 1) << "name" << (keyName + "_1")));
}
return indexSpecs;
}
diff --git a/src/mongo/db/op_observer_impl.cpp b/src/mongo/db/op_observer_impl.cpp
index e44c135e7d2..23266878f34 100644
--- a/src/mongo/db/op_observer_impl.cpp
+++ b/src/mongo/db/op_observer_impl.cpp
@@ -243,11 +243,7 @@ void OpObserverImpl::onCreateIndex(OperationContext* opCtx,
bool fromMigrate) {
BSONObjBuilder builder;
builder.append("createIndexes", nss.coll());
-
- for (const auto& e : indexDoc) {
- if (e.fieldNameStringData() != "ns"_sd)
- builder.append(e);
- }
+ builder.appendElements(indexDoc);
MutableOplogEntry oplogEntry;
oplogEntry.setOpType(repl::OpTypeEnum::kCommand);
@@ -271,12 +267,7 @@ void OpObserverImpl::onStartIndexBuild(OperationContext* opCtx,
BSONArrayBuilder indexesArr(oplogEntryBuilder.subarrayStart("indexes"));
for (auto indexDoc : indexes) {
- BSONObjBuilder builder;
- for (const auto& e : indexDoc) {
- if (e.fieldNameStringData() != "ns"_sd)
- builder.append(e);
- }
- indexesArr.append(builder.obj());
+ indexesArr.append(indexDoc);
}
indexesArr.done();
@@ -302,12 +293,7 @@ void OpObserverImpl::onCommitIndexBuild(OperationContext* opCtx,
BSONArrayBuilder indexesArr(oplogEntryBuilder.subarrayStart("indexes"));
for (auto indexDoc : indexes) {
- BSONObjBuilder builder;
- for (const auto& e : indexDoc) {
- if (e.fieldNameStringData() != "ns"_sd)
- builder.append(e);
- }
- indexesArr.append(builder.obj());
+ indexesArr.append(indexDoc);
}
indexesArr.done();
@@ -333,12 +319,7 @@ void OpObserverImpl::onAbortIndexBuild(OperationContext* opCtx,
BSONArrayBuilder indexesArr(oplogEntryBuilder.subarrayStart("indexes"));
for (auto indexDoc : indexes) {
- BSONObjBuilder builder;
- for (const auto& e : indexDoc) {
- if (e.fieldNameStringData() != "ns"_sd)
- builder.append(e);
- }
- indexesArr.append(builder.obj());
+ indexesArr.append(indexDoc);
}
indexesArr.done();
diff --git a/src/mongo/db/pipeline/document_source_out.cpp b/src/mongo/db/pipeline/document_source_out.cpp
index 2293294534c..f4b7127a83d 100644
--- a/src/mongo/db/pipeline/document_source_out.cpp
+++ b/src/mongo/db/pipeline/document_source_out.cpp
@@ -145,13 +145,9 @@ void DocumentSourceOut::initialize() {
}
// Copy the indexes of the output collection to the temp collection.
- std::vector<BSONObj> tempNsIndexes;
- for (const auto& indexSpec : _originalIndexes) {
- // Replace the spec's 'ns' field value, which is the original collection, with the temp
- // collection.
- tempNsIndexes.push_back(indexSpec.addField(BSON("ns" << _tempNs.ns()).firstElement()));
- }
try {
+ std::vector<BSONObj> tempNsIndexes = {std::begin(_originalIndexes),
+ std::end(_originalIndexes)};
conn->createIndexes(_tempNs.ns(), tempNsIndexes);
} catch (DBException& ex) {
ex.addContext("Copying indexes for $out failed");
diff --git a/src/mongo/db/repl/base_cloner_test_fixture.cpp b/src/mongo/db/repl/base_cloner_test_fixture.cpp
index 8d9fc63f6cd..24841605f83 100644
--- a/src/mongo/db/repl/base_cloner_test_fixture.cpp
+++ b/src/mongo/db/repl/base_cloner_test_fixture.cpp
@@ -46,8 +46,7 @@ using namespace unittest;
const HostAndPort BaseClonerTest::target("localhost", -1);
const NamespaceString BaseClonerTest::nss("db.coll");
const BSONObj BaseClonerTest::idIndexSpec = BSON("v" << 1 << "key" << BSON("_id" << 1) << "name"
- << "_id_"
- << "ns" << nss.ns());
+ << "_id_");
// static
BSONObj BaseClonerTest::createCountResponse(int documentCount) {
diff --git a/src/mongo/db/repl/collection_cloner.cpp b/src/mongo/db/repl/collection_cloner.cpp
index 84c7273f001..774c0e8b36a 100644
--- a/src/mongo/db/repl/collection_cloner.cpp
+++ b/src/mongo/db/repl/collection_cloner.cpp
@@ -396,22 +396,15 @@ void CollectionCloner::_listIndexesCallback(const Fetcher::QueryResponseStatus&
}
UniqueLock lk(_mutex);
- // When listing indexes by UUID, the sync source may use a different name for the collection
- // as result of renaming or two-phase drop. As the index spec also includes a 'ns' field, this
- // must be rewritten.
- BSONObjBuilder nsFieldReplacementBuilder;
- nsFieldReplacementBuilder.append("ns", _sourceNss.ns());
- BSONElement nsFieldReplacementElem = nsFieldReplacementBuilder.done().firstElement();
// We may be called with multiple batches leading to a need to grow _indexSpecs.
_indexSpecs.reserve(_indexSpecs.size() + documents.size());
for (auto&& doc : documents) {
- // The addField replaces the 'ns' field with the correct name, see above.
if (StringData("_id_") == doc["name"].str()) {
- _idIndexSpec = doc.addField(nsFieldReplacementElem);
+ _idIndexSpec = doc;
continue;
}
- _indexSpecs.push_back(doc.addField(nsFieldReplacementElem));
+ _indexSpecs.push_back(doc);
}
lk.unlock();
diff --git a/src/mongo/db/repl/collection_cloner_test.cpp b/src/mongo/db/repl/collection_cloner_test.cpp
index 5fb4970c183..c15b95ed15f 100644
--- a/src/mongo/db/repl/collection_cloner_test.cpp
+++ b/src/mongo/db/repl/collection_cloner_test.cpp
@@ -281,11 +281,9 @@ void CollectionClonerTest::setUp() {
// Return index specs to use for secondary indexes.
std::vector<BSONObj> CollectionClonerTest::makeSecondaryIndexSpecs(const NamespaceString& nss) {
return {BSON("v" << 1 << "key" << BSON("a" << 1) << "name"
- << "a_1"
- << "ns" << nss.ns()),
+ << "a_1"),
BSON("v" << 1 << "key" << BSON("b" << 1) << "name"
- << "b_1"
- << "ns" << nss.ns())};
+ << "b_1")};
}
void CollectionClonerTest::tearDown() {
@@ -1399,8 +1397,7 @@ TEST_F(CollectionClonerRenamedBeforeStartTest, BeginCollectionWithUUID) {
ASSERT_BSONOBJ_EQ(options.toBSON(), collOptions.toBSON());
BSONObj expectedIdIndexSpec = BSON("v" << 1 << "key" << BSON("_id" << 1) << "name"
- << "_id_"
- << "ns" << alternateNss.ns());
+ << "_id_");
ASSERT_BSONOBJ_EQ(collIdIndexSpec, expectedIdIndexSpec);
auto expectedNonIdIndexSpecs = makeSecondaryIndexSpecs(alternateNss);
diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp
index ec1fa40c985..f5732e53227 100644
--- a/src/mongo/db/repl/oplog.cpp
+++ b/src/mongo/db/repl/oplog.cpp
@@ -170,9 +170,7 @@ StatusWith<std::vector<BSONObj>> parseBSONSpecsIntoVector(const BSONElement& bso
<< "' array must be objects, but found "
<< typeName(bsonElem.type())};
}
- BSONObjBuilder builder(bsonElem.Obj());
- builder.append("ns", nss.toString());
- vec.emplace_back(builder.obj());
+ vec.emplace_back(bsonElem.Obj().getOwned());
}
return vec;
}
@@ -232,11 +230,8 @@ void createIndexForApplyOps(OperationContext* opCtx,
const NamespaceString& indexNss,
IncrementOpsAppliedStatsFn incrementOpsAppliedStats,
OplogApplication::Mode mode) {
- // Lock the database if it's not locked.
- boost::optional<Lock::DBLock> dbLock;
- if (!opCtx->lockState()->isLocked()) {
- dbLock.emplace(opCtx, indexNss.db(), MODE_X);
- }
+ invariant(opCtx->lockState()->isCollectionLockedForMode(indexNss, MODE_X));
+
// Check if collection exists.
auto databaseHolder = DatabaseHolder::get(opCtx);
auto db = databaseHolder->getDb(opCtx, indexNss.ns());
@@ -263,7 +258,7 @@ void createIndexForApplyOps(OperationContext* opCtx,
if (shouldBuildInForeground(opCtx, indexSpec, indexNss, mode)) {
IndexBuilder builder(indexSpec, constraints, replicatedWrites);
- Status status = builder.buildInForeground(opCtx, db);
+ Status status = builder.buildInForeground(opCtx, db, indexCollection);
uassertStatusOK(status);
} else {
Lock::TempRelease release(opCtx->lockState());
@@ -734,7 +729,6 @@ const StringMap<ApplyOpMetadata> kOpsMap = {
idIndexSpecBuilder.append(IndexDescriptor::kIndexVersionFieldName,
static_cast<int>(IndexVersion::kV1));
idIndexSpecBuilder.append(IndexDescriptor::kIndexNameFieldName, "_id_");
- idIndexSpecBuilder.append(IndexDescriptor::kNamespaceFieldName, nss.ns());
idIndexSpecBuilder.append(IndexDescriptor::kKeyPatternFieldName, BSON("_id" << 1));
return createCollectionForApplyOps(
opCtx, nss.db().toString(), ui, cmd, idIndexSpecBuilder.done());
@@ -754,10 +748,8 @@ const StringMap<ApplyOpMetadata> kOpsMap = {
"createIndexes value must be a string",
first.type() == mongo::String);
BSONObj indexSpec = cmd.removeField("createIndexes");
- // The UUID determines the collection to build the index on, so create new 'ns' field.
- BSONObj nsObj = BSON("ns" << nss.ns());
- indexSpec = indexSpec.addField(nsObj.firstElement());
-
+ Lock::DBLock dbLock(opCtx, nss.db(), MODE_IX);
+ Lock::CollectionLock collLock(opCtx, nss, MODE_X);
createIndexForApplyOps(opCtx, indexSpec, nss, {}, mode);
return Status::OK();
},
diff --git a/src/mongo/db/repl/rollback_impl_test.cpp b/src/mongo/db/repl/rollback_impl_test.cpp
index e7fa22eef19..1f514eda2e6 100644
--- a/src/mongo/db/repl/rollback_impl_test.cpp
+++ b/src/mongo/db/repl/rollback_impl_test.cpp
@@ -1638,7 +1638,7 @@ TEST_F(RollbackImplObserverInfoTest, NamespacesForOpsExtractsNamespaceOfDropColl
TEST_F(RollbackImplObserverInfoTest, NamespacesForOpsExtractsNamespaceOfCreateIndexOplogEntry) {
auto nss = NamespaceString("test", "coll");
auto indexObj =
- BSON("createIndexes" << nss.coll() << "ns" << nss.toString() << "v"
+ BSON("createIndexes" << nss.coll() << "v"
<< static_cast<int>(IndexDescriptor::IndexVersion::kV2) << "key"
<< "x"
<< "name"
diff --git a/src/mongo/db/repl/rs_rollback.cpp b/src/mongo/db/repl/rs_rollback.cpp
index 491ace5de8b..d04bdea10b2 100644
--- a/src/mongo/db/repl/rs_rollback.cpp
+++ b/src/mongo/db/repl/rs_rollback.cpp
@@ -738,11 +738,12 @@ void rollbackCreateIndexes(OperationContext* opCtx, UUID uuid, std::set<std::str
void rollbackDropIndexes(OperationContext* opCtx,
UUID uuid,
std::map<std::string, BSONObj> indexNames) {
-
boost::optional<NamespaceString> nss = CollectionCatalog::get(opCtx).lookupNSSByUUID(uuid);
invariant(nss);
- Lock::DBLock dbLock(opCtx, nss->db(), MODE_X);
- Collection* collection = CollectionCatalog::get(opCtx).lookupCollectionByUUID(uuid);
+ Lock::DBLock dbLock(opCtx, nss->db(), MODE_IX);
+ Lock::CollectionLock collLock(opCtx, *nss, MODE_X);
+ Collection* collection = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(*nss);
+
// If we cannot find the collection, we skip over dropping the index.
if (!collection) {
LOG(2) << "Cannot find the collection with uuid: " << uuid.toString()
@@ -751,17 +752,8 @@ void rollbackDropIndexes(OperationContext* opCtx,
}
for (auto itIndex = indexNames.begin(); itIndex != indexNames.end(); itIndex++) {
-
const string indexName = itIndex->first;
BSONObj indexSpec = itIndex->second;
- // We replace the namespace field because it is possible that a
- // renameCollection command has occurred, changing the namespace of the
- // collection from what it initially was during the creation of this index.
- BSONObjBuilder updatedNss;
- updatedNss.append("ns", nss->ns());
-
- BSONObj updatedNssObj = updatedNss.obj();
- indexSpec = indexSpec.addField(updatedNssObj.firstElement());
log() << "Creating index in rollback for collection: " << *nss << ", UUID: " << uuid
<< ", index: " << indexName;
diff --git a/src/mongo/db/repl/rs_rollback_test.cpp b/src/mongo/db/repl/rs_rollback_test.cpp
index 3d12a5bac28..6d1bfbda79a 100644
--- a/src/mongo/db/repl/rs_rollback_test.cpp
+++ b/src/mongo/db/repl/rs_rollback_test.cpp
@@ -81,8 +81,8 @@ OplogInterfaceMock::Operation makeDropIndexOplogEntry(Collection* collection,
BSONObj key,
std::string indexName,
int time) {
- auto indexSpec = BSON("ns" << collection->ns().ns() << "key" << key << "name" << indexName
- << "v" << static_cast<int>(kIndexVersion));
+ auto indexSpec =
+ BSON("key" << key << "name" << indexName << "v" << static_cast<int>(kIndexVersion));
return std::make_pair(
BSON("ts" << Timestamp(Seconds(time), 0) << "op"
@@ -98,9 +98,9 @@ OplogInterfaceMock::Operation makeCreateIndexOplogEntry(Collection* collection,
BSONObj key,
std::string indexName,
int time) {
- auto indexSpec = BSON(
- "createIndexes" << collection->ns().coll() << "ns" << collection->ns().ns() << "v"
- << static_cast<int>(kIndexVersion) << "key" << key << "name" << indexName);
+ auto indexSpec =
+ BSON("createIndexes" << collection->ns().coll() << "v" << static_cast<int>(kIndexVersion)
+ << "key" << key << "name" << indexName);
return std::make_pair(BSON("ts" << Timestamp(Seconds(time), 0) << "op"
<< "c"
@@ -439,9 +439,9 @@ TEST_F(RSRollbackTest, RollbackCreateIndexCommand) {
options.uuid = UUID::gen();
NamespaceString nss("test", "coll");
auto collection = _createCollection(_opCtx.get(), nss.toString(), options);
- auto indexSpec = BSON("ns" << nss.toString() << "v" << static_cast<int>(kIndexVersion) << "key"
- << BSON("a" << 1) << "name"
- << "a_1");
+ auto indexSpec =
+ BSON("v" << static_cast<int>(kIndexVersion) << "key" << BSON("a" << 1) << "name"
+ << "a_1");
int numIndexes = _createIndexOnEmptyCollection(_opCtx.get(), collection, nss, indexSpec);
ASSERT_EQUALS(2, numIndexes);
@@ -482,10 +482,8 @@ TEST_F(RSRollbackTest, RollbackCreateIndexCommandIndexNotInCatalog) {
CollectionOptions options;
options.uuid = UUID::gen();
auto collection = _createCollection(_opCtx.get(), "test.t", options);
- auto indexSpec = BSON("ns"
- << "test.t"
- << "key" << BSON("a" << 1) << "name"
- << "a_1");
+ auto indexSpec = BSON("key" << BSON("a" << 1) << "name"
+ << "a_1");
// Skip index creation to trigger warning during rollback.
{
Lock::DBLock dbLock(_opCtx.get(), "test", MODE_S);
@@ -632,8 +630,8 @@ TEST_F(RSRollbackTest, RollingBackCreateIndexAndRenameWithLongName) {
auto collection = _createCollection(_opCtx.get(), nss.toString(), options);
auto longName = std::string(115, 'a');
- auto indexSpec = BSON("ns" << nss.toString() << "v" << static_cast<int>(kIndexVersion) << "key"
- << BSON("b" << 1) << "name" << longName);
+ auto indexSpec = BSON("v" << static_cast<int>(kIndexVersion) << "key" << BSON("b" << 1)
+ << "name" << longName);
int numIndexes = _createIndexOnEmptyCollection(_opCtx.get(), collection, nss, indexSpec);
ASSERT_EQUALS(2, numIndexes);
@@ -680,9 +678,9 @@ TEST_F(RSRollbackTest, RollingBackDropAndCreateOfSameIndexNameWithDifferentSpecs
NamespaceString nss("test", "coll");
auto collection = _createCollection(_opCtx.get(), nss.toString(), options);
- auto indexSpec = BSON("ns" << nss.toString() << "v" << static_cast<int>(kIndexVersion) << "key"
- << BSON("b" << 1) << "name"
- << "a_1");
+ auto indexSpec =
+ BSON("v" << static_cast<int>(kIndexVersion) << "key" << BSON("b" << 1) << "name"
+ << "a_1");
int numIndexes = _createIndexOnEmptyCollection(_opCtx.get(), collection, nss, indexSpec);
ASSERT_EQUALS(2, numIndexes);
@@ -779,8 +777,8 @@ std::string idxName(std::string id) {
// Create an index spec object given the namespace and the index 'id'.
BSONObj idxSpec(NamespaceString nss, std::string id) {
- return BSON("ns" << nss.toString() << "v" << static_cast<int>(kIndexVersion) << "key"
- << BSON(idxKey(id) << 1) << "name" << idxName(id));
+ return BSON("v" << static_cast<int>(kIndexVersion) << "key" << BSON(idxKey(id) << 1) << "name"
+ << idxName(id));
}
// Returns the number of indexes that exist on the given collection.
@@ -902,8 +900,8 @@ TEST_F(RSRollbackTest, RollbackCreateDropRecreateIndexOnCollection) {
// Create the necessary indexes. Index 0 is created, dropped, and created again in the
// sequence of ops, so we create that index.
- auto indexSpec = BSON("ns" << nss.toString() << "v" << static_cast<int>(kIndexVersion) << "key"
- << BSON(idxKey("0") << 1) << "name" << idxName("0"));
+ auto indexSpec = BSON("v" << static_cast<int>(kIndexVersion) << "key" << BSON(idxKey("0") << 1)
+ << "name" << idxName("0"));
int numIndexes = _createIndexOnEmptyCollection(_opCtx.get(), coll, nss, indexSpec);
ASSERT_EQUALS(2, numIndexes);
diff --git a/src/mongo/db/repl/storage_interface_impl_test.cpp b/src/mongo/db/repl/storage_interface_impl_test.cpp
index aa021037cc8..451e809ef55 100644
--- a/src/mongo/db/repl/storage_interface_impl_test.cpp
+++ b/src/mongo/db/repl/storage_interface_impl_test.cpp
@@ -66,10 +66,10 @@ using namespace mongo::repl;
const auto kIndexVersion = IndexDescriptor::IndexVersion::kV2;
BSONObj makeIdIndexSpec(const NamespaceString& nss) {
- return BSON("ns" << nss.toString() << "name"
- << "_id_"
- << "key" << BSON("_id" << 1) << "unique" << true << "v"
- << static_cast<int>(kIndexVersion));
+ return BSON("name"
+ << "_id_"
+ << "key" << BSON("_id" << 1) << "unique" << true << "v"
+ << static_cast<int>(kIndexVersion));
}
/**
@@ -616,8 +616,7 @@ TEST_F(StorageInterfaceImplTest, DestroyingUncommittedCollectionBulkLoaderDropsI
auto opCtx = getOperationContext();
auto nss = makeNamespace(_agent);
std::vector<BSONObj> indexes = {BSON("v" << 1 << "key" << BSON("x" << 1) << "name"
- << "x_1"
- << "ns" << nss.ns())};
+ << "x_1")};
auto destroyLoaderFn = [](std::unique_ptr<CollectionBulkLoader> loader) {
// Destroy 'loader' by letting it go out of scope.
};
@@ -640,8 +639,7 @@ TEST_F(StorageInterfaceImplTest,
auto opCtx = getOperationContext();
auto nss = makeNamespace(_agent);
std::vector<BSONObj> indexes = {BSON("v" << 1 << "key" << BSON("x" << 1) << "name"
- << "x_1"
- << "ns" << nss.ns())};
+ << "x_1")};
auto destroyLoaderFn = [](std::unique_ptr<CollectionBulkLoader> loader) {
// Destroy 'loader' in a new thread that does not have a Client.
stdx::thread([&loader]() { loader.reset(); }).join();
@@ -904,8 +902,7 @@ TEST_F(StorageInterfaceImplTest, FindDocumentsReturnsIndexOptionsConflictIfIndex
auto nss = makeNamespace(_agent);
std::vector<BSONObj> indexes = {BSON("v" << 1 << "key" << BSON("x" << 1) << "name"
<< "x_1"
- << "ns" << nss.ns() << "partialFilterExpression"
- << BSON("y" << 1))};
+ << "partialFilterExpression" << BSON("y" << 1))};
auto loader = unittest::assertGet(storage.createCollectionForBulkLoading(
nss, generateOptionsWithUuid(), makeIdIndexSpec(nss), indexes));
std::vector<BSONObj> docs = {BSON("_id" << 1), BSON("_id" << 1), BSON("_id" << 2)};
@@ -2643,8 +2640,8 @@ TEST_F(StorageInterfaceImplTest, SetIndexIsMultikeySucceeds) {
ASSERT_OK(storage.createCollection(opCtx, nss, CollectionOptions()));
auto indexName = "a_b_1";
- auto indexSpec = BSON("name" << indexName << "ns" << nss.ns() << "key" << BSON("a.b" << 1)
- << "v" << static_cast<int>(kIndexVersion));
+ auto indexSpec = BSON("name" << indexName << "key" << BSON("a.b" << 1) << "v"
+ << static_cast<int>(kIndexVersion));
ASSERT_EQUALS(_createIndexOnEmptyCollection(opCtx, nss, indexSpec), 2);
MultikeyPaths paths = {{1}};
diff --git a/src/mongo/db/repl/sync_tail_test.cpp b/src/mongo/db/repl/sync_tail_test.cpp
index 79fbd315d3b..d6a194ba29d 100644
--- a/src/mongo/db/repl/sync_tail_test.cpp
+++ b/src/mongo/db/repl/sync_tail_test.cpp
@@ -2180,7 +2180,7 @@ TEST_F(IdempotencyTest, CreateCollectionWithIdIndex) {
auto options1 = BSON("idIndex" << BSON("key" << fromjson("{_id: 1}") << "name"
<< "_id_"
- << "v" << 2 << "ns" << nss.ns())
+ << "v" << 2)
<< "uuid" << uuid);
auto createColl1 = makeCreateCollectionOplogEntry(nextOpTime(), nss, options1);
ASSERT_OK(runOpInitialSync(createColl1));
diff --git a/src/mongo/db/s/config/sharding_catalog_manager_config_initialization_test.cpp b/src/mongo/db/s/config/sharding_catalog_manager_config_initialization_test.cpp
index 8d4feacb60b..b88ff084d93 100644
--- a/src/mongo/db/s/config/sharding_catalog_manager_config_initialization_test.cpp
+++ b/src/mongo/db/s/config/sharding_catalog_manager_config_initialization_test.cpp
@@ -271,66 +271,38 @@ TEST_F(ConfigInitializationTest, BuildsNecessaryIndexes) {
auto expectedChunksIndexes = std::vector<BSONObj>{
BSON("v" << 2 << "key" << BSON("_id" << 1) << "name"
- << "_id_"
- << "ns"
- << "config.chunks"),
+ << "_id_"),
BSON("v" << 2 << "unique" << true << "key" << BSON("ns" << 1 << "min" << 1) << "name"
- << "ns_1_min_1"
- << "ns"
- << "config.chunks"),
+ << "ns_1_min_1"),
BSON("v" << 2 << "unique" << true << "key" << BSON("ns" << 1 << "shard" << 1 << "min" << 1)
<< "name"
- << "ns_1_shard_1_min_1"
- << "ns"
- << "config.chunks"),
+ << "ns_1_shard_1_min_1"),
BSON("v" << 2 << "unique" << true << "key" << BSON("ns" << 1 << "lastmod" << 1) << "name"
- << "ns_1_lastmod_1"
- << "ns"
- << "config.chunks")};
+ << "ns_1_lastmod_1")};
auto expectedLockpingsIndexes =
std::vector<BSONObj>{BSON("v" << 2 << "key" << BSON("_id" << 1) << "name"
- << "_id_"
- << "ns"
- << "config.lockpings"),
+ << "_id_"),
BSON("v" << 2 << "key" << BSON("ping" << 1) << "name"
- << "ping_1"
- << "ns"
- << "config.lockpings")};
+ << "ping_1")};
auto expectedLocksIndexes = std::vector<BSONObj>{
BSON("v" << 2 << "key" << BSON("_id" << 1) << "name"
- << "_id_"
- << "ns"
- << "config.locks"),
+ << "_id_"),
BSON("v" << 2 << "key" << BSON("ts" << 1) << "name"
- << "ts_1"
- << "ns"
- << "config.locks"),
+ << "ts_1"),
BSON("v" << 2 << "key" << BSON("state" << 1 << "process" << 1) << "name"
- << "state_1_process_1"
- << "ns"
- << "config.locks")};
+ << "state_1_process_1")};
auto expectedShardsIndexes = std::vector<BSONObj>{
BSON("v" << 2 << "key" << BSON("_id" << 1) << "name"
- << "_id_"
- << "ns"
- << "config.shards"),
+ << "_id_"),
BSON("v" << 2 << "unique" << true << "key" << BSON("host" << 1) << "name"
- << "host_1"
- << "ns"
- << "config.shards")};
+ << "host_1")};
auto expectedTagsIndexes = std::vector<BSONObj>{
BSON("v" << 2 << "key" << BSON("_id" << 1) << "name"
- << "_id_"
- << "ns"
- << "config.tags"),
+ << "_id_"),
BSON("v" << 2 << "unique" << true << "key" << BSON("ns" << 1 << "min" << 1) << "name"
- << "ns_1_min_1"
- << "ns"
- << "config.tags"),
+ << "ns_1_min_1"),
BSON("v" << 2 << "key" << BSON("ns" << 1 << "tag" << 1) << "name"
- << "ns_1_tag_1"
- << "ns"
- << "config.tags")};
+ << "ns_1_tag_1")};
auto foundChunksIndexes = assertGet(getIndexes(operationContext(), ChunkType::ConfigNS));
assertBSONObjsSame(expectedChunksIndexes, foundChunksIndexes);
@@ -358,13 +330,9 @@ TEST_F(ConfigInitializationTest, CompatibleIndexAlreadyExists) {
auto expectedShardsIndexes = std::vector<BSONObj>{
BSON("v" << 2 << "key" << BSON("_id" << 1) << "name"
- << "_id_"
- << "ns"
- << "config.shards"),
+ << "_id_"),
BSON("v" << 2 << "unique" << true << "key" << BSON("host" << 1) << "name"
- << "host_1"
- << "ns"
- << "config.shards")};
+ << "host_1")};
auto foundShardsIndexes = assertGet(getIndexes(operationContext(), ShardType::ConfigNS));
diff --git a/src/mongo/db/s/shardsvr_shard_collection.cpp b/src/mongo/db/s/shardsvr_shard_collection.cpp
index e229badedbc..f58f6983280 100644
--- a/src/mongo/db/s/shardsvr_shard_collection.cpp
+++ b/src/mongo/db/s/shardsvr_shard_collection.cpp
@@ -258,7 +258,7 @@ void createCollectionOrValidateExisting(OperationContext* opCtx,
// 3. If proposed key is required to be unique, additionally check for exact match.
if (hasUsefulIndexForKey && request.getUnique()) {
- BSONObj eqQuery = BSON("ns" << nss.ns() << "key" << proposedKey);
+ BSONObj eqQuery = BSON("key" << proposedKey);
BSONObj eqQueryResult;
for (const auto& idx : indexes) {
diff --git a/src/mongo/db/storage/SConscript b/src/mongo/db/storage/SConscript
index 871d3fa97db..0e933164833 100644
--- a/src/mongo/db/storage/SConscript
+++ b/src/mongo/db/storage/SConscript
@@ -79,9 +79,6 @@ env.Library(
'$BUILD_DIR/mongo/db/service_context',
'$BUILD_DIR/mongo/db/storage/kv/kv_prefix',
],
- LIBDEPS_PRIVATE=[
- '$BUILD_DIR/mongo/db/catalog/disable_index_spec_namespace_generation',
- ],
)
env.Library(
@@ -425,9 +422,6 @@ env.Library(
'$BUILD_DIR/mongo/db/storage/kv/kv_drop_pending_ident_reaper',
'$BUILD_DIR/mongo/db/storage/kv/kv_prefix',
'$BUILD_DIR/mongo/db/catalog/collection_catalog',
- ],
- LIBDEPS_PRIVATE=[
- '$BUILD_DIR/mongo/db/catalog/disable_index_spec_namespace_generation',
]
)
diff --git a/src/mongo/db/storage/biggie/biggie_sorted_impl.cpp b/src/mongo/db/storage/biggie/biggie_sorted_impl.cpp
index e4aa5eee384..15d604fe069 100644
--- a/src/mongo/db/storage/biggie/biggie_sorted_impl.cpp
+++ b/src/mongo/db/storage/biggie/biggie_sorted_impl.cpp
@@ -37,6 +37,7 @@
#include "mongo/bson/bsonobj.h"
#include "mongo/bson/bsonobjbuilder.h"
+#include "mongo/db/catalog/collection.h"
#include "mongo/db/catalog/index_catalog_entry.h"
#include "mongo/db/index/index_descriptor.h"
#include "mongo/db/storage/biggie/biggie_recovery_unit.h"
@@ -293,7 +294,7 @@ SortedDataInterface::SortedDataInterface(OperationContext* opCtx,
_prefix(ident.toString().append(1, '\1')),
// Therefore, the string ident + \2 will be greater than all elements in this ident.
_identEnd(ident.toString().append(1, '\2')),
- _collectionNamespace(desc->parentNS()),
+ _collectionNamespace(desc->getCollection()->ns()),
_indexName(desc->indexName()),
_keyPattern(desc->keyPattern()),
_isUnique(desc->unique()),
diff --git a/src/mongo/db/storage/biggie/biggie_sorted_impl_test.cpp b/src/mongo/db/storage/biggie/biggie_sorted_impl_test.cpp
index 03aa3330b60..18e6da89d58 100644
--- a/src/mongo/db/storage/biggie/biggie_sorted_impl_test.cpp
+++ b/src/mongo/db/storage/biggie/biggie_sorted_impl_test.cpp
@@ -60,7 +60,7 @@ public:
BSONObj spec = BSON("key" << BSON("a" << 1) << "name"
<< "testIndex"
<< "v" << static_cast<int>(IndexDescriptor::kLatestIndexVersion)
- << "ns" << ns << "unique" << unique);
+ << "unique" << unique);
if (partial) {
auto partialBSON =
BSON(IndexDescriptor::kPartialFilterExprFieldName.toString() << BSON(""
diff --git a/src/mongo/db/storage/bson_collection_catalog_entry.cpp b/src/mongo/db/storage/bson_collection_catalog_entry.cpp
index a90848175a0..9d07ddd60c9 100644
--- a/src/mongo/db/storage/bson_collection_catalog_entry.cpp
+++ b/src/mongo/db/storage/bson_collection_catalog_entry.cpp
@@ -32,7 +32,6 @@
#include <algorithm>
#include <numeric>
-#include "mongo/db/catalog/disable_index_spec_namespace_generation_gen.h"
#include "mongo/db/field_ref.h"
namespace mongo {
@@ -141,19 +140,6 @@ bool BSONCollectionCatalogEntry::MetaData::eraseIndex(StringData name) {
void BSONCollectionCatalogEntry::MetaData::rename(StringData toNS) {
ns = toNS.toString();
- for (size_t i = 0; i < indexes.size(); i++) {
- BSONObj spec = indexes[i].spec;
- BSONObjBuilder b;
- // Add the fields in the same order they were in the original specification.
- for (auto&& elem : spec) {
- if (elem.fieldNameStringData() == "ns") {
- b.append("ns", toNS);
- } else {
- b.append(elem);
- }
- }
- indexes[i].spec = b.obj();
- }
}
KVPrefix BSONCollectionCatalogEntry::MetaData::getMaxPrefix() const {
diff --git a/src/mongo/db/storage/durable_catalog_impl.cpp b/src/mongo/db/storage/durable_catalog_impl.cpp
index c8b849206c1..a7e8b3f5fb1 100644
--- a/src/mongo/db/storage/durable_catalog_impl.cpp
+++ b/src/mongo/db/storage/durable_catalog_impl.cpp
@@ -36,7 +36,6 @@
#include "mongo/bson/util/bson_extract.h"
#include "mongo/bson/util/builder.h"
-#include "mongo/db/catalog/disable_index_spec_namespace_generation_gen.h"
#include "mongo/db/concurrency/d_concurrency.h"
#include "mongo/db/index/index_descriptor.h"
#include "mongo/db/namespace_string.h"
@@ -1205,12 +1204,6 @@ BSONObj DurableCatalogImpl::getIndexSpec(OperationContext* opCtx,
invariant(offset >= 0);
BSONObj spec = md.indexes[offset].spec.getOwned();
- if (spec.hasField("ns") || disableIndexSpecNamespaceGeneration.load()) {
- return spec;
- }
-
- BSONObj nsObj = BSON("ns" << ns.ns());
- spec = spec.addField(nsObj.firstElement());
return spec;
}
diff --git a/src/mongo/db/storage/kv/durable_catalog_test.cpp b/src/mongo/db/storage/kv/durable_catalog_test.cpp
index f76ad1830eb..2a93def21d7 100644
--- a/src/mongo/db/storage/kv/durable_catalog_test.cpp
+++ b/src/mongo/db/storage/kv/durable_catalog_test.cpp
@@ -108,10 +108,9 @@ public:
std::string indexName = "idx" + std::to_string(numIndexesCreated);
auto collection = std::make_unique<CollectionMock>(_nss);
- IndexDescriptor desc(
- collection.get(),
- indexType,
- BSON("v" << 1 << "key" << keyPattern << "name" << indexName << "ns" << _nss.ns()));
+ IndexDescriptor desc(collection.get(),
+ indexType,
+ BSON("v" << 1 << "key" << keyPattern << "name" << indexName));
{
WriteUnitOfWork wuow(opCtx.get());
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 7b9bfb7a5f4..034d7b673f5 100644
--- a/src/mongo/db/storage/kv/kv_engine_test_harness.cpp
+++ b/src/mongo/db/storage/kv/kv_engine_test_harness.cpp
@@ -167,8 +167,8 @@ TEST(KVEngineTestHarness, SimpleSorted1) {
IndexDescriptor desc(collection.get(),
"",
- BSON("v" << static_cast<int>(IndexDescriptor::kLatestIndexVersion) << "ns"
- << ns.ns() << "key" << BSON("a" << 1)));
+ BSON("v" << static_cast<int>(IndexDescriptor::kLatestIndexVersion) << "key"
+ << BSON("a" << 1)));
std::unique_ptr<SortedDataInterface> sorted;
{
MyOperationContext opCtx(engine);
@@ -704,7 +704,7 @@ DEATH_TEST_F(DurableCatalogImplTest, TerminateOnNonNumericIndexVersion, "Fatal A
"",
BSON("v"
<< "1"
- << "ns" << ns.ns() << "key" << BSON("a" << 1)));
+ << "key" << BSON("a" << 1)));
std::unique_ptr<SortedDataInterface> sorted;
{
MyOperationContext opCtx(engine);
diff --git a/src/mongo/db/storage/storage_engine_test_fixture.h b/src/mongo/db/storage/storage_engine_test_fixture.h
index ffbb42ee70c..50cb70ae6df 100644
--- a/src/mongo/db/storage/storage_engine_test_fixture.h
+++ b/src/mongo/db/storage/storage_engine_test_fixture.h
@@ -128,7 +128,7 @@ public:
BSONObjBuilder keyObj;
builder.append("key", keyObj.append(key, 1).done());
}
- BSONObj spec = builder.append("name", key).append("ns", collNs.ns()).append("v", 2).done();
+ BSONObj spec = builder.append("name", key).append("v", 2).done();
auto collection = std::make_unique<CollectionMock>(collNs);
auto descriptor = std::make_unique<IndexDescriptor>(
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_prefixed_index_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_prefixed_index_test.cpp
index 4684e13e264..b86e2d60a85 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_prefixed_index_test.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_prefixed_index_test.cpp
@@ -77,7 +77,7 @@ public:
BSONObj spec = BSON("key" << BSON("a" << 1) << "name"
<< "testIndex"
<< "v" << static_cast<int>(IndexDescriptor::kLatestIndexVersion)
- << "ns" << ns << "unique" << unique);
+ << "unique" << unique);
if (partial) {
auto partialBSON =
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_standard_index_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_standard_index_test.cpp
index f03fc201827..1f683424598 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_standard_index_test.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_standard_index_test.cpp
@@ -77,7 +77,7 @@ public:
BSONObj spec = BSON("key" << BSON("a" << 1) << "name"
<< "testIndex"
<< "v" << static_cast<int>(IndexDescriptor::kLatestIndexVersion)
- << "ns" << ns << "unique" << unique);
+ << "unique" << unique);
if (partial) {
auto partialBSON =
diff --git a/src/mongo/db/system_index.cpp b/src/mongo/db/system_index.cpp
index 47433ac4d38..b3b8ed740a6 100644
--- a/src/mongo/db/system_index.cpp
+++ b/src/mongo/db/system_index.cpp
@@ -111,7 +111,7 @@ SharedSemiFuture<ReplIndexBuildState::IndexCatalogStats> generateSystemIndexForE
try {
auto indexSpecStatus = index_key_validate::validateIndexSpec(
- opCtx, spec.toBSON(), ns, serverGlobalParams.featureCompatibility);
+ opCtx, spec.toBSON(), serverGlobalParams.featureCompatibility);
BSONObj indexSpec = fassert(40452, indexSpecStatus);
log() << "No authorization index detected on " << ns
@@ -232,20 +232,16 @@ void createSystemIndexes(OperationContext* opCtx, Collection* collection) {
const NamespaceString& ns = collection->ns();
BSONObj indexSpec;
if (ns == AuthorizationManager::usersCollectionNamespace) {
- indexSpec =
- fassert(40455,
- index_key_validate::validateIndexSpec(opCtx,
- v3SystemUsersIndexSpec.toBSON(),
- ns,
- serverGlobalParams.featureCompatibility));
+ indexSpec = fassert(
+ 40455,
+ index_key_validate::validateIndexSpec(
+ opCtx, v3SystemUsersIndexSpec.toBSON(), serverGlobalParams.featureCompatibility));
} else if (ns == AuthorizationManager::rolesCollectionNamespace) {
- indexSpec =
- fassert(40457,
- index_key_validate::validateIndexSpec(opCtx,
- v3SystemRolesIndexSpec.toBSON(),
- ns,
- serverGlobalParams.featureCompatibility));
+ indexSpec = fassert(
+ 40457,
+ index_key_validate::validateIndexSpec(
+ opCtx, v3SystemRolesIndexSpec.toBSON(), serverGlobalParams.featureCompatibility));
}
if (!indexSpec.isEmpty()) {
opCtx->getServiceContext()->getOpObserver()->onCreateIndex(
diff --git a/src/mongo/dbtests/counttests.cpp b/src/mongo/dbtests/counttests.cpp
index 9f820418793..41ad97c5203 100644
--- a/src/mongo/dbtests/counttests.cpp
+++ b/src/mongo/dbtests/counttests.cpp
@@ -59,7 +59,7 @@ public:
IndexCatalog* indexCatalog = _collection->getIndexCatalog();
auto indexSpec = BSON("v" << static_cast<int>(IndexDescriptor::kLatestIndexVersion)
- << "ns" << ns() << "key" << BSON("a" << 1) << "name"
+ << "key" << BSON("a" << 1) << "name"
<< "a_1");
uassertStatusOK(indexCatalog->createIndexOnEmptyCollection(&_opCtx, indexSpec));
diff --git a/src/mongo/dbtests/dbtests.cpp b/src/mongo/dbtests/dbtests.cpp
index c61f4d390b2..6f33b22ebe8 100644
--- a/src/mongo/dbtests/dbtests.cpp
+++ b/src/mongo/dbtests/dbtests.cpp
@@ -86,7 +86,6 @@ void initWireSpec() {
Status createIndex(OperationContext* opCtx, StringData ns, const BSONObj& keys, bool unique) {
BSONObjBuilder specBuilder;
specBuilder.append("name", DBClientBase::genIndexName(keys));
- specBuilder.append("ns", ns);
specBuilder.append("key", keys);
specBuilder.append("v", static_cast<int>(kIndexVersion));
if (unique) {
diff --git a/src/mongo/dbtests/indexcatalogtests.cpp b/src/mongo/dbtests/indexcatalogtests.cpp
index 9ac94209601..802a200ead9 100644
--- a/src/mongo/dbtests/indexcatalogtests.cpp
+++ b/src/mongo/dbtests/indexcatalogtests.cpp
@@ -143,11 +143,11 @@ public:
dbtests::WriteContextForTests ctx(&opCtx, _nss.ns());
const std::string indexName = "x_1";
- ASSERT_OK(dbtests::createIndexFromSpec(
- &opCtx,
- _nss.ns(),
- BSON("name" << indexName << "ns" << _nss.ns() << "key" << BSON("x" << 1) << "v"
- << static_cast<int>(kIndexVersion) << "expireAfterSeconds" << 5)));
+ ASSERT_OK(dbtests::createIndexFromSpec(&opCtx,
+ _nss.ns(),
+ BSON("name" << indexName << "key" << BSON("x" << 1)
+ << "v" << static_cast<int>(kIndexVersion)
+ << "expireAfterSeconds" << 5)));
const IndexDescriptor* desc = _catalog->findIndexByName(&opCtx, indexName);
ASSERT(desc);
diff --git a/src/mongo/dbtests/indexupdatetests.cpp b/src/mongo/dbtests/indexupdatetests.cpp
index 63ed34e3871..362b34ae44a 100644
--- a/src/mongo/dbtests/indexupdatetests.cpp
+++ b/src/mongo/dbtests/indexupdatetests.cpp
@@ -134,7 +134,7 @@ public:
const BSONObj spec = BSON("name"
<< "a"
- << "ns" << coll->ns().ns() << "key" << BSON("a" << 1) << "v"
+ << "key" << BSON("a" << 1) << "v"
<< static_cast<int>(kIndexVersion) << "unique" << true
<< "background" << background);
@@ -182,7 +182,7 @@ public:
const BSONObj spec = BSON("name"
<< "a"
- << "ns" << coll->ns().ns() << "key" << BSON("a" << 1) << "v"
+ << "key" << BSON("a" << 1) << "v"
<< static_cast<int>(kIndexVersion) << "unique" << true
<< "background" << background);
@@ -226,7 +226,7 @@ public:
}
// Request an interrupt.
getGlobalServiceContext()->setKillAllOperations();
- BSONObj indexInfo = BSON("key" << BSON("a" << 1) << "ns" << _ns << "name"
+ BSONObj indexInfo = BSON("key" << BSON("a" << 1) << "name"
<< "a_1"
<< "v" << static_cast<int>(kIndexVersion));
// The call is interrupted because mayInterrupt == true.
@@ -269,7 +269,7 @@ public:
}
// Request an interrupt.
getGlobalServiceContext()->setKillAllOperations();
- BSONObj indexInfo = BSON("key" << BSON("_id" << 1) << "ns" << _ns << "name"
+ BSONObj indexInfo = BSON("key" << BSON("_id" << 1) << "name"
<< "_id_"
<< "v" << static_cast<int>(kIndexVersion));
ASSERT_TRUE(buildIndexInterrupted(indexInfo));
@@ -317,7 +317,7 @@ public:
ASSERT_OK(createIndex("unittest",
BSON("name"
<< "x"
- << "ns" << _ns << "key" << BSON("x" << 1 << "y" << 1) << "v"
+ << "key" << BSON("x" << 1 << "y" << 1) << "v"
<< static_cast<int>(kIndexVersion))));
}
};
@@ -330,9 +330,8 @@ public:
createIndex("unittest",
BSON("name"
<< "x"
- << "ns" << _ns << "unique" << true << "key"
- << BSON("x" << 1 << "y" << 1) << "v"
- << static_cast<int>(kIndexVersion))));
+ << "unique" << true << "key" << BSON("x" << 1 << "y" << 1)
+ << "v" << static_cast<int>(kIndexVersion))));
}
};
@@ -342,7 +341,7 @@ public:
ASSERT_OK(createIndex("unittest",
BSON("name"
<< "x"
- << "ns" << _ns << "key" << BSON("x" << 1 << "y" << 1) << "v"
+ << "key" << BSON("x" << 1 << "y" << 1) << "v"
<< static_cast<int>(kIndexVersion))));
}
};
@@ -355,7 +354,7 @@ public:
createIndex("unittest",
BSON("name"
<< "x"
- << "ns" << _ns << "key" << BSON("y" << 1 << "x" << 1) << "v"
+ << "key" << BSON("y" << 1 << "x" << 1) << "v"
<< static_cast<int>(kIndexVersion))));
}
};
@@ -369,8 +368,8 @@ public:
ASSERT_OK(createIndex("unittests",
BSON("name"
<< "super"
- << "ns" << _ns << "unique" << 1 << "sparse" << true
- << "expireAfterSeconds" << 3600 << "key"
+ << "unique" << 1 << "sparse" << true << "expireAfterSeconds"
+ << 3600 << "key"
<< BSON("superIdx"
<< "2d")
<< "v" << static_cast<int>(kIndexVersion))));
@@ -387,8 +386,8 @@ public:
createIndex("unittests",
BSON("name"
<< "super2"
- << "ns" << _ns << "expireAfterSeconds" << 3600 << "sparse"
- << true << "unique" << 1 << "key"
+ << "expireAfterSeconds" << 3600 << "sparse" << true
+ << "unique" << 1 << "key"
<< BSON("superIdx"
<< "2d")
<< "v" << static_cast<int>(kIndexVersion))));
@@ -403,8 +402,8 @@ public:
ASSERT_OK(createIndex("unittests",
BSON("name"
<< "super"
- << "ns" << _ns << "expireAfterSeconds" << 3600 << "sparse"
- << true << "unique" << 1 << "key"
+ << "expireAfterSeconds" << 3600 << "sparse" << true << "unique"
+ << 1 << "key"
<< BSON("superIdx"
<< "2d")
<< "v" << static_cast<int>(kIndexVersion))));
@@ -421,7 +420,7 @@ public:
createIndex("unittest",
BSON("name"
<< "super2"
- << "ns" << _ns << "unique" << false << "sparse" << true
+ << "unique" << false << "sparse" << true
<< "expireAfterSeconds" << 3600 << "key"
<< BSON("superIdx"
<< "2d")
@@ -432,16 +431,15 @@ public:
class SameSpecDifferentSparse : public ComplexIndex {
public:
void run() {
- ASSERT_EQUALS(
- ErrorCodes::IndexOptionsConflict,
- createIndex("unittest",
- BSON("name"
- << "super2"
- << "ns" << _ns << "unique" << 1 << "sparse" << false << "background"
- << true << "expireAfterSeconds" << 3600 << "key"
- << BSON("superIdx"
- << "2d")
- << "v" << static_cast<int>(kIndexVersion))));
+ ASSERT_EQUALS(ErrorCodes::IndexOptionsConflict,
+ createIndex("unittest",
+ BSON("name"
+ << "super2"
+ << "unique" << 1 << "sparse" << false << "background" << true
+ << "expireAfterSeconds" << 3600 << "key"
+ << BSON("superIdx"
+ << "2d")
+ << "v" << static_cast<int>(kIndexVersion))));
}
};
@@ -452,8 +450,8 @@ public:
createIndex("unittest",
BSON("name"
<< "super2"
- << "ns" << _ns << "unique" << 1 << "sparse" << true
- << "expireAfterSeconds" << 2400 << "key"
+ << "unique" << 1 << "sparse" << true << "expireAfterSeconds"
+ << 2400 << "key"
<< BSON("superIdx"
<< "2d")
<< "v" << static_cast<int>(kIndexVersion))));
@@ -503,8 +501,8 @@ protected:
BSONObj _createSpec(T storageEngineValue) {
return BSON("name"
<< "super2"
- << "ns" << _ns << "key" << BSON("a" << 1) << "v"
- << static_cast<int>(kIndexVersion) << "storageEngine" << storageEngineValue);
+ << "key" << BSON("a" << 1) << "v" << static_cast<int>(kIndexVersion)
+ << "storageEngine" << storageEngineValue);
}
};
diff --git a/src/mongo/dbtests/multikey_paths_test.cpp b/src/mongo/dbtests/multikey_paths_test.cpp
index 8f0759f69b1..6c72c3e8936 100644
--- a/src/mongo/dbtests/multikey_paths_test.cpp
+++ b/src/mongo/dbtests/multikey_paths_test.cpp
@@ -142,8 +142,7 @@ TEST_F(MultikeyPathsTest, PathsUpdatedOnIndexCreation) {
createIndex(collection,
BSON("name"
<< "a_1_b_1"
- << "ns" << _nss.ns() << "key" << keyPattern << "v"
- << static_cast<int>(kIndexVersion)))
+ << "key" << keyPattern << "v" << static_cast<int>(kIndexVersion)))
.transitional_ignore();
assertMultikeyPaths(collection, keyPattern, {std::set<size_t>{}, {0U}});
@@ -172,8 +171,7 @@ TEST_F(MultikeyPathsTest, PathsUpdatedOnIndexCreationWithMultipleDocuments) {
createIndex(collection,
BSON("name"
<< "a_1_b_1"
- << "ns" << _nss.ns() << "key" << keyPattern << "v"
- << static_cast<int>(kIndexVersion)))
+ << "key" << keyPattern << "v" << static_cast<int>(kIndexVersion)))
.transitional_ignore();
assertMultikeyPaths(collection, keyPattern, {{0U}, {0U}});
@@ -188,8 +186,7 @@ TEST_F(MultikeyPathsTest, PathsUpdatedOnDocumentInsert) {
createIndex(collection,
BSON("name"
<< "a_1_b_1"
- << "ns" << _nss.ns() << "key" << keyPattern << "v"
- << static_cast<int>(kIndexVersion)))
+ << "key" << keyPattern << "v" << static_cast<int>(kIndexVersion)))
.transitional_ignore();
{
@@ -226,8 +223,7 @@ TEST_F(MultikeyPathsTest, PathsUpdatedOnDocumentUpdate) {
createIndex(collection,
BSON("name"
<< "a_1_b_1"
- << "ns" << _nss.ns() << "key" << keyPattern << "v"
- << static_cast<int>(kIndexVersion)))
+ << "key" << keyPattern << "v" << static_cast<int>(kIndexVersion)))
.transitional_ignore();
{
@@ -275,8 +271,7 @@ TEST_F(MultikeyPathsTest, PathsNotUpdatedOnDocumentDelete) {
createIndex(collection,
BSON("name"
<< "a_1_b_1"
- << "ns" << _nss.ns() << "key" << keyPattern << "v"
- << static_cast<int>(kIndexVersion)))
+ << "key" << keyPattern << "v" << static_cast<int>(kIndexVersion)))
.transitional_ignore();
{
@@ -316,16 +311,14 @@ TEST_F(MultikeyPathsTest, PathsUpdatedForMultipleIndexesOnDocumentInsert) {
createIndex(collection,
BSON("name"
<< "a_1_b_1"
- << "ns" << _nss.ns() << "key" << keyPatternAB << "v"
- << static_cast<int>(kIndexVersion)))
+ << "key" << keyPatternAB << "v" << static_cast<int>(kIndexVersion)))
.transitional_ignore();
BSONObj keyPatternAC = BSON("a" << 1 << "c" << 1);
createIndex(collection,
BSON("name"
<< "a_1_c_1"
- << "ns" << _nss.ns() << "key" << keyPatternAC << "v"
- << static_cast<int>(kIndexVersion)))
+ << "key" << keyPatternAC << "v" << static_cast<int>(kIndexVersion)))
.transitional_ignore();
{
WriteUnitOfWork wuow(_opCtx.get());
diff --git a/src/mongo/dbtests/query_stage_count.cpp b/src/mongo/dbtests/query_stage_count.cpp
index 87e66a58918..6444ee4b9ea 100644
--- a/src/mongo/dbtests/query_stage_count.cpp
+++ b/src/mongo/dbtests/query_stage_count.cpp
@@ -75,7 +75,7 @@ public:
->createIndexOnEmptyCollection(&_opCtx,
BSON("key" << BSON("x" << 1) << "name"
<< "x_1"
- << "ns" << ns() << "v" << 1))
+ << "v" << 1))
.status_with_transitional_ignore();
for (int i = 0; i < kDocuments; i++) {
diff --git a/src/mongo/dbtests/query_stage_ixscan.cpp b/src/mongo/dbtests/query_stage_ixscan.cpp
index 3217ebd979b..ca36a6710d7 100644
--- a/src/mongo/dbtests/query_stage_ixscan.cpp
+++ b/src/mongo/dbtests/query_stage_ixscan.cpp
@@ -61,9 +61,8 @@ public:
ASSERT_OK(_coll->getIndexCatalog()->createIndexOnEmptyCollection(
&_opCtx,
- BSON("ns" << ns() << "key" << BSON("x" << 1) << "name"
- << DBClientBase::genIndexName(BSON("x" << 1)) << "v"
- << static_cast<int>(kIndexVersion))));
+ BSON("key" << BSON("x" << 1) << "name" << DBClientBase::genIndexName(BSON("x" << 1))
+ << "v" << static_cast<int>(kIndexVersion))));
wunit.commit();
}
diff --git a/src/mongo/dbtests/querytests.cpp b/src/mongo/dbtests/querytests.cpp
index 6e74f6c1571..c91ab589923 100644
--- a/src/mongo/dbtests/querytests.cpp
+++ b/src/mongo/dbtests/querytests.cpp
@@ -100,7 +100,6 @@ protected:
void addIndex(const IndexSpec& spec) {
BSONObjBuilder builder(spec.toBSON());
builder.append("v", int(IndexDescriptor::kLatestIndexVersion));
- builder.append("ns", ns());
auto specObj = builder.obj();
MultiIndexBlock indexer;
diff --git a/src/mongo/dbtests/rollbacktests.cpp b/src/mongo/dbtests/rollbacktests.cpp
index 317be739e89..fd48e6f46a3 100644
--- a/src/mongo/dbtests/rollbacktests.cpp
+++ b/src/mongo/dbtests/rollbacktests.cpp
@@ -541,8 +541,8 @@ public:
IndexCatalog* catalog = coll->getIndexCatalog();
string idxName = "a";
- BSONObj spec = BSON("ns" << ns << "key" << BSON("a" << 1) << "name" << idxName << "v"
- << static_cast<int>(kIndexVersion));
+ BSONObj spec = BSON("key" << BSON("a" << 1) << "name" << idxName << "v"
+ << static_cast<int>(kIndexVersion));
// END SETUP / START TEST
@@ -582,8 +582,8 @@ public:
IndexCatalog* catalog = coll->getIndexCatalog();
string idxName = "a";
- BSONObj spec = BSON("ns" << ns << "key" << BSON("a" << 1) << "name" << idxName << "v"
- << static_cast<int>(kIndexVersion));
+ BSONObj spec = BSON("key" << BSON("a" << 1) << "name" << idxName << "v"
+ << static_cast<int>(kIndexVersion));
{
WriteUnitOfWork uow(&opCtx);
@@ -635,8 +635,8 @@ public:
IndexCatalog* catalog = coll->getIndexCatalog();
string idxName = "a";
- BSONObj spec = BSON("ns" << ns << "key" << BSON("a" << 1) << "name" << idxName << "v"
- << static_cast<int>(kIndexVersion));
+ BSONObj spec = BSON("key" << BSON("a" << 1) << "name" << idxName << "v"
+ << static_cast<int>(kIndexVersion));
// END SETUP / START TEST
@@ -678,12 +678,12 @@ public:
string idxNameA = "indexA";
string idxNameB = "indexB";
string idxNameC = "indexC";
- BSONObj specA = BSON("ns" << ns << "key" << BSON("a" << 1) << "name" << idxNameA << "v"
- << static_cast<int>(kIndexVersion));
- BSONObj specB = BSON("ns" << ns << "key" << BSON("b" << 1) << "name" << idxNameB << "v"
- << static_cast<int>(kIndexVersion));
- BSONObj specC = BSON("ns" << ns << "key" << BSON("c" << 1) << "name" << idxNameC << "v"
- << static_cast<int>(kIndexVersion));
+ BSONObj specA = BSON("key" << BSON("a" << 1) << "name" << idxNameA << "v"
+ << static_cast<int>(kIndexVersion));
+ BSONObj specB = BSON("key" << BSON("b" << 1) << "name" << idxNameB << "v"
+ << static_cast<int>(kIndexVersion));
+ BSONObj specC = BSON("key" << BSON("c" << 1) << "name" << idxNameC << "v"
+ << static_cast<int>(kIndexVersion));
// END SETUP / START TEST
diff --git a/src/mongo/dbtests/storage_timestamp_tests.cpp b/src/mongo/dbtests/storage_timestamp_tests.cpp
index 60d10e576f3..6e79c1b8ae3 100644
--- a/src/mongo/dbtests/storage_timestamp_tests.cpp
+++ b/src/mongo/dbtests/storage_timestamp_tests.cpp
@@ -261,8 +261,7 @@ public:
auto swIndexInfoObj =
indexer.init(_opCtx,
coll,
- {BSON("v" << 2 << "name" << indexName << "ns" << coll->ns().ns()
- << "key" << indexKey)},
+ {BSON("v" << 2 << "name" << indexName << "key" << indexKey)},
MultiIndexBlock::makeTimestampedIndexOnInitFn(_opCtx, coll));
ASSERT_OK(swIndexInfoObj.getStatus());
indexInfoObj = std::move(swIndexInfoObj.getValue()[0]);
@@ -1260,8 +1259,8 @@ public:
uuid = autoColl.getCollection()->uuid();
}
auto indexName = "a_1";
- auto indexSpec = BSON("name" << indexName << "ns" << nss.ns() << "key" << BSON("a" << 1)
- << "v" << static_cast<int>(kIndexVersion));
+ auto indexSpec = BSON("name" << indexName << "key" << BSON("a" << 1) << "v"
+ << static_cast<int>(kIndexVersion));
ASSERT_OK(dbtests::createIndexFromSpec(_opCtx, nss.ns(), indexSpec));
_coordinatorMock->alwaysAllowWrites(false);
@@ -1329,8 +1328,8 @@ public:
uuid = autoColl.getCollection()->uuid();
}
auto indexName = "a_1";
- auto indexSpec = BSON("name" << indexName << "ns" << nss.ns() << "key" << BSON("a" << 1)
- << "v" << static_cast<int>(kIndexVersion));
+ auto indexSpec = BSON("name" << indexName << "key" << BSON("a" << 1) << "v"
+ << static_cast<int>(kIndexVersion));
ASSERT_OK(dbtests::createIndexFromSpec(_opCtx, nss.ns(), indexSpec));
_coordinatorMock->alwaysAllowWrites(false);
@@ -1357,10 +1356,10 @@ public:
<< "op"
<< "i"
<< "ns" << nss.ns() << "ui" << uuid << "o" << doc2));
- auto indexSpec2 = BSON("createIndexes" << nss.coll() << "ns" << nss.ns() << "v"
- << static_cast<int>(kIndexVersion) << "key"
- << BSON("b" << 1) << "name"
- << "b_1");
+ auto indexSpec2 =
+ BSON("createIndexes" << nss.coll() << "v" << static_cast<int>(kIndexVersion) << "key"
+ << BSON("b" << 1) << "name"
+ << "b_1");
auto createIndexOp = repl::OplogEntry(
BSON("ts" << indexBuildTime.asTimestamp() << "t" << 1LL << "v" << 2 << "op"
<< "c"
@@ -1425,8 +1424,8 @@ public:
AutoGetCollection autoColl(_opCtx, nss, LockMode::MODE_IX);
auto indexName = "a_1";
- auto indexSpec = BSON("name" << indexName << "ns" << nss.ns() << "key" << BSON("a" << 1)
- << "v" << static_cast<int>(kIndexVersion));
+ auto indexSpec = BSON("name" << indexName << "key" << BSON("a" << 1) << "v"
+ << static_cast<int>(kIndexVersion));
ASSERT_OK(dbtests::createIndexFromSpec(_opCtx, nss.ns(), indexSpec));
const LogicalTime pastTime = _clock->reserveTicks(1);
@@ -1454,8 +1453,8 @@ public:
AutoGetCollection autoColl(_opCtx, nss, LockMode::MODE_IX);
auto indexName = "a_1";
- auto indexSpec = BSON("name" << indexName << "ns" << nss.ns() << "key" << BSON("a" << 1)
- << "v" << static_cast<int>(kIndexVersion));
+ auto indexSpec = BSON("name" << indexName << "key" << BSON("a" << 1) << "v"
+ << static_cast<int>(kIndexVersion));
ASSERT_OK(dbtests::createIndexFromSpec(_opCtx, nss.ns(), indexSpec));
const LogicalTime pastTime = _clock->reserveTicks(1);
@@ -1877,7 +1876,7 @@ public:
autoColl.getCollection(),
{BSON("v" << 2 << "unique" << true << "name"
<< "a_1"
- << "ns" << nss.ns() << "key" << BSON("a" << 1))},
+ << "key" << BSON("a" << 1))},
MultiIndexBlock::makeTimestampedIndexOnInitFn(_opCtx, autoColl.getCollection()));
ASSERT_OK(swIndexInfoObj.getStatus());
indexInfoObj = std::move(swIndexInfoObj.getValue()[0]);
@@ -2515,10 +2514,10 @@ public:
origIdents = durableCatalog->getAllIdents(_opCtx);
}
- auto indexSpec = BSON("createIndexes" << nss.coll() << "ns" << nss.ns() << "v"
- << static_cast<int>(kIndexVersion) << "key"
- << BSON("field" << 1) << "name"
- << "field_1");
+ auto indexSpec =
+ BSON("createIndexes" << nss.coll() << "v" << static_cast<int>(kIndexVersion)
+ << "key" << BSON("field" << 1) << "name"
+ << "field_1");
auto createIndexOp = BSON("ts" << startBuildTs << "t" << 1LL << "v" << 2 << "op"
<< "c"
diff --git a/src/mongo/dbtests/validate_tests.cpp b/src/mongo/dbtests/validate_tests.cpp
index 39f48384421..ed805c905f7 100644
--- a/src/mongo/dbtests/validate_tests.cpp
+++ b/src/mongo/dbtests/validate_tests.cpp
@@ -229,14 +229,13 @@ public:
wunit.commit();
}
- auto status =
- dbtests::createIndexFromSpec(&_opCtx,
- coll->ns().ns(),
- BSON("name"
- << "a"
- << "ns" << coll->ns().ns() << "key" << BSON("a" << 1)
- << "v" << static_cast<int>(kIndexVersion)
- << "background" << false));
+ auto status = dbtests::createIndexFromSpec(&_opCtx,
+ coll->ns().ns(),
+ BSON("name"
+ << "a"
+ << "key" << BSON("a" << 1) << "v"
+ << static_cast<int>(kIndexVersion)
+ << "background" << false));
ASSERT_OK(status);
ASSERT_TRUE(checkValid());
@@ -301,14 +300,13 @@ public:
wunit.commit();
}
- auto status =
- dbtests::createIndexFromSpec(&_opCtx,
- coll->ns().ns(),
- BSON("name"
- << "a"
- << "ns" << coll->ns().ns() << "key" << BSON("a" << 1)
- << "v" << static_cast<int>(kIndexVersion)
- << "background" << false));
+ auto status = dbtests::createIndexFromSpec(&_opCtx,
+ coll->ns().ns(),
+ BSON("name"
+ << "a"
+ << "key" << BSON("a" << 1) << "v"
+ << static_cast<int>(kIndexVersion)
+ << "background" << false));
ASSERT_OK(status);
ASSERT_TRUE(checkValid());
@@ -459,8 +457,7 @@ public:
coll->ns().ns(),
BSON("name"
<< "multikey_index"
- << "ns" << coll->ns().ns() << "key"
- << BSON("a.b" << 1) << "v"
+ << "key" << BSON("a.b" << 1) << "v"
<< static_cast<int>(kIndexVersion)
<< "background" << false));
@@ -534,9 +531,9 @@ public:
coll->ns().ns(),
BSON("name"
<< "sparse_index"
- << "ns" << coll->ns().ns() << "key" << BSON("a" << 1)
- << "v" << static_cast<int>(kIndexVersion)
- << "background" << false << "sparse" << true));
+ << "key" << BSON("a" << 1) << "v"
+ << static_cast<int>(kIndexVersion) << "background"
+ << false << "sparse" << true));
ASSERT_OK(status);
ASSERT_TRUE(checkValid());
@@ -601,9 +598,9 @@ public:
coll->ns().ns(),
BSON("name"
<< "partial_index"
- << "ns" << coll->ns().ns() << "key" << BSON("a" << 1)
- << "v" << static_cast<int>(kIndexVersion)
- << "background" << false << "partialFilterExpression"
+ << "key" << BSON("a" << 1) << "v"
+ << static_cast<int>(kIndexVersion) << "background"
+ << false << "partialFilterExpression"
<< BSON("a" << BSON("$gt" << 1))));
ASSERT_OK(status);
@@ -662,7 +659,7 @@ public:
coll->ns().ns(),
BSON("name"
<< "partial_index"
- << "ns" << coll->ns().ns() << "key"
+ << "key"
<< BSON("x"
<< "2dsphere")
<< "v" << static_cast<int>(kIndexVersion)
@@ -675,7 +672,7 @@ public:
coll->ns().ns(),
BSON("name"
<< "partial_index"
- << "ns" << coll->ns().ns() << "key"
+ << "key"
<< BSON("x"
<< "2dsphere")
<< "v" << static_cast<int>(kIndexVersion)
@@ -735,9 +732,8 @@ public:
coll->ns().ns(),
BSON("name"
<< "compound_index_1"
- << "ns" << coll->ns().ns() << "key"
- << BSON("a" << 1 << "b" << -1) << "v"
- << static_cast<int>(kIndexVersion)
+ << "key" << BSON("a" << 1 << "b" << -1)
+ << "v" << static_cast<int>(kIndexVersion)
<< "background" << false));
ASSERT_OK(status);
@@ -745,8 +741,7 @@ public:
coll->ns().ns(),
BSON("name"
<< "compound_index_2"
- << "ns" << coll->ns().ns() << "key"
- << BSON("a" << -1 << "b" << 1) << "v"
+ << "key" << BSON("a" << -1 << "b" << 1) << "v"
<< static_cast<int>(kIndexVersion)
<< "background" << false));
@@ -806,7 +801,7 @@ public:
auto status = dbtests::createIndexFromSpec(
&_opCtx,
coll->ns().ns(),
- BSON("name" << indexName << "ns" << coll->ns().ns() << "key" << BSON("a" << 1) << "v"
+ BSON("name" << indexName << "key" << BSON("a" << 1) << "v"
<< static_cast<int>(kIndexVersion) << "background" << false));
ASSERT_OK(status);
@@ -888,7 +883,7 @@ public:
auto status = dbtests::createIndexFromSpec(
&_opCtx,
coll->ns().ns(),
- BSON("name" << indexName << "ns" << coll->ns().ns() << "key" << BSON("a" << 1) << "v"
+ BSON("name" << indexName << "key" << BSON("a" << 1) << "v"
<< static_cast<int>(kIndexVersion) << "background" << false));
ASSERT_OK(status);
@@ -935,8 +930,8 @@ public:
auto status = dbtests::createIndexFromSpec(
&_opCtx,
coll->ns().ns(),
- BSON("name" << indexName << "ns" << coll->ns().ns() << "key" << indexKey << "v"
- << static_cast<int>(kIndexVersion) << "background" << false));
+ BSON("name" << indexName << "key" << indexKey << "v" << static_cast<int>(kIndexVersion)
+ << "background" << false));
ASSERT_OK(status);
// Insert non-multikey documents.
@@ -1044,8 +1039,8 @@ public:
auto status = dbtests::createIndexFromSpec(
&_opCtx,
coll->ns().ns(),
- BSON("name" << indexName << "ns" << coll->ns().ns() << "key" << indexKey << "v"
- << static_cast<int>(kIndexVersion) << "background" << false));
+ BSON("name" << indexName << "key" << indexKey << "v" << static_cast<int>(kIndexVersion)
+ << "background" << false));
ASSERT_OK(status);
// Insert documents with indexed and not-indexed paths.
@@ -1135,8 +1130,8 @@ public:
auto status = dbtests::createIndexFromSpec(
&_opCtx,
coll->ns().ns(),
- BSON("name" << indexName << "ns" << coll->ns().ns() << "key" << indexKey << "v"
- << static_cast<int>(kIndexVersion) << "background" << false));
+ BSON("name" << indexName << "key" << indexKey << "v" << static_cast<int>(kIndexVersion)
+ << "background" << false));
ASSERT_OK(status);
// Insert documents.
@@ -1222,8 +1217,8 @@ public:
auto status = dbtests::createIndexFromSpec(
&_opCtx,
coll->ns().ns(),
- BSON("name" << indexName << "ns" << coll->ns().ns() << "key" << indexKey << "v"
- << static_cast<int>(kIndexVersion) << "background" << false));
+ BSON("name" << indexName << "key" << indexKey << "v" << static_cast<int>(kIndexVersion)
+ << "background" << false));
ASSERT_OK(status);
// Insert documents.
@@ -1328,8 +1323,8 @@ public:
auto status = dbtests::createIndexFromSpec(
&_opCtx,
coll->ns().ns(),
- BSON("name" << indexName << "ns" << coll->ns().ns() << "key" << indexKey << "v"
- << static_cast<int>(kIndexVersion) << "background" << false));
+ BSON("name" << indexName << "key" << indexKey << "v" << static_cast<int>(kIndexVersion)
+ << "background" << false));
ASSERT_OK(status);
// Insert documents.
diff --git a/src/mongo/dbtests/wildcard_multikey_persistence_test.cpp b/src/mongo/dbtests/wildcard_multikey_persistence_test.cpp
index 8ace89874da..6731153ed88 100644
--- a/src/mongo/dbtests/wildcard_multikey_persistence_test.cpp
+++ b/src/mongo/dbtests/wildcard_multikey_persistence_test.cpp
@@ -181,8 +181,7 @@ protected:
BSONObj key,
BSONObj pathProjection,
bool background) {
- BSONObjBuilder bob =
- std::move(BSONObjBuilder() << "ns" << nss.ns() << "name" << name << "key" << key);
+ BSONObjBuilder bob = std::move(BSONObjBuilder() << "name" << name << "key" << key);
if (!pathProjection.isEmpty())
bob << IndexDescriptor::kPathProjectionFieldName << pathProjection;