summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Wlodarek <gregory.wlodarek@mongodb.com>2019-06-05 23:02:27 -0400
committerGregory Wlodarek <gregory.wlodarek@mongodb.com>2019-06-11 14:00:00 -0400
commit214255bc66e3b713245550d4449de554c8d9b31f (patch)
tree9971bca2bb3f6c0188560cfba1f86903263a07d6
parent6b893a49227f87c6c5580e9c59ca59b28ca75ffb (diff)
downloadmongo-214255bc66e3b713245550d4449de554c8d9b31f.tar.gz
SERVER-41422 Allow the absence of the 'ns' field from index specs
-rw-r--r--jstests/noPassthrough/absent_ns_field_in_index_specs.js75
-rw-r--r--jstests/noPassthrough/characterize_index_builds_on_restart.js36
-rw-r--r--src/mongo/db/catalog/SConscript14
-rw-r--r--src/mongo/db/catalog/disable_index_spec_namespace_generation.idl41
-rw-r--r--src/mongo/db/catalog/index_catalog_impl.cpp27
-rw-r--r--src/mongo/db/catalog/index_key_validate.cpp5
-rw-r--r--src/mongo/db/index/index_descriptor.cpp2
-rw-r--r--src/mongo/db/storage/SConscript3
-rw-r--r--src/mongo/db/storage/biggie/biggie_sorted_impl_test.cpp4
-rw-r--r--src/mongo/db/storage/bson_collection_catalog_entry.cpp11
-rw-r--r--src/mongo/db/storage/kv/SConscript1
-rw-r--r--src/mongo/db/storage/kv/kv_collection_catalog_entry_test.cpp4
-rw-r--r--src/mongo/db/storage/kv/kv_engine_test_harness.cpp64
-rw-r--r--src/mongo/db/storage/kv/kv_storage_engine_test_fixture.h7
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_prefixed_index_test.cpp4
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_standard_index_test.cpp4
16 files changed, 260 insertions, 42 deletions
diff --git a/jstests/noPassthrough/absent_ns_field_in_index_specs.js b/jstests/noPassthrough/absent_ns_field_in_index_specs.js
new file mode 100644
index 00000000000..07477fdd1e4
--- /dev/null
+++ b/jstests/noPassthrough/absent_ns_field_in_index_specs.js
@@ -0,0 +1,75 @@
+/**
+ * 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.
+ *
+ * @tags: [requires_replication, requires_persistence]
+ */
+(function() {
+ 'use strict';
+
+ const dbName = 'test';
+ const collName = 'absent_ns';
+
+ let replSet = new ReplSetTest({name: 'absentNsField', nodes: 2});
+ replSet.startSet();
+ replSet.initiate();
+
+ const primary = replSet.getPrimary();
+ const primaryDB = primary.getDB(dbName);
+ 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}));
+
+ replSet.awaitReplication();
+
+ let specPrimary =
+ assert.commandWorked(primaryDB.runCommand({listIndexes: collName})).cursor.firstBatch[1];
+ 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);
+
+ 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.
+ const options = {dbpath: primary.dbpath, noCleanData: true};
+ let conn = MongoRunner.runMongod(options);
+ assert.neq(null, conn, 'mongod was unable to start up with options: ' + tojson(options));
+
+ 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);
+
+ MongoRunner.stopMongod(conn);
+
+ options.dbpath = secondary.dbpath;
+ conn = MongoRunner.runMongod(options);
+ assert.neq(null, conn, 'mongod was unable to start up with options: ' + tojson(options));
+
+ 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);
+
+ MongoRunner.stopMongod(conn);
+}());
diff --git a/jstests/noPassthrough/characterize_index_builds_on_restart.js b/jstests/noPassthrough/characterize_index_builds_on_restart.js
index 083c2ad1488..37cffa27ae9 100644
--- a/jstests/noPassthrough/characterize_index_builds_on_restart.js
+++ b/jstests/noPassthrough/characterize_index_builds_on_restart.js
@@ -1,6 +1,10 @@
/**
* Characterizes the actions (rebuilds or drops the index) taken upon unfinished indexes when
* restarting mongod from (standalone -> standalone) and (replica set member -> standalone).
+ * Additionally, the primary will use the 'disableIndexSpecNamespaceGeneration' server test
+ * parameter to prevent index specs from having the 'ns' field to test the absence of the 'ns' field
+ * on a replica set with unfinished indexes during restart.
+ *
* @tags: [requires_replication, requires_persistence, requires_majority_read_concern]
*/
(function() {
@@ -42,20 +46,14 @@
}
function startReplSet() {
- let replSet = new ReplSetTest({name: "indexBuilds", nodes: 3, nodeOptions: {syncdelay: 1}});
+ let replSet = new ReplSetTest({name: "indexBuilds", nodes: 2, nodeOptions: {syncdelay: 1}});
let nodes = replSet.nodeList();
// We need an arbiter to ensure that the primary doesn't step down when we restart the
// secondary
replSet.startSet({startClean: true});
- replSet.initiate({
- _id: "indexBuilds",
- members: [
- {_id: 0, host: nodes[0]},
- {_id: 1, host: nodes[1]},
- {_id: 2, host: nodes[2], arbiterOnly: true}
- ]
- });
+ replSet.initiate(
+ {_id: "indexBuilds", members: [{_id: 0, host: nodes[0]}, {_id: 1, host: nodes[1]}]});
replSet.getPrimary().getDB(dbName).dropDatabase();
return replSet;
@@ -81,6 +79,11 @@
assert.commandWorked(secondaryDB.adminCommand(
{configureFailPoint: "leaveIndexBuildUnfinishedForShutdown", mode: "alwaysOn"}));
+ // Do not generate the 'ns' field for index specs on the primary to test the absence of the
+ // field on restart.
+ assert.commandWorked(
+ primaryDB.adminCommand({setParameter: 1, disableIndexSpecNamespaceGeneration: 1}));
+
try {
let res = assert.commandWorked(primaryDB.runCommand({
createIndexes: collName,
@@ -142,6 +145,7 @@
let foundIndexEntry = false;
for (let index = 0; index < collIndexes.length; index++) {
+ assert.eq(true, collIndexes[index].hasOwnProperty('ns'));
if (collIndexes[index].name == indexName) {
foundIndexEntry = true;
break;
@@ -208,9 +212,7 @@
startIndexBuildOnSecondaryAndLeaveUnfinished(primaryDB, /*writeConcern=*/2, secondaryDB);
- let secondaryId = replSet.getNodeId(secondary);
- replSet.stop(secondaryId);
- replSet.remove(secondaryId);
+ replSet.stopSet(/*signal=*/null, /*forRestart=*/true);
let mongod = restartStandalone(secondary);
@@ -220,7 +222,15 @@
checkForIndexRebuild(mongod, fourthIndex, /*shouldExist=*/true);
shutdownStandalone(mongod);
- stopReplSet(replSet);
+
+ mongod = restartStandalone(primary);
+ let specs = mongod.getDB(dbName).getCollection(collName).getIndexes();
+ assert.eq(specs.length, 5);
+ for (let index = 0; index < specs.length; index++) {
+ assert.eq(true, specs[index].hasOwnProperty('ns'));
+ }
+
+ shutdownStandalone(mongod);
}
/* Begin tests */
diff --git a/src/mongo/db/catalog/SConscript b/src/mongo/db/catalog/SConscript
index 11b6f55ebf0..55f96caf927 100644
--- a/src/mongo/db/catalog/SConscript
+++ b/src/mongo/db/catalog/SConscript
@@ -156,6 +156,16 @@ env.CppUnitTest(
)
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",
@@ -170,6 +180,9 @@ 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.CppUnitTest(
@@ -417,6 +430,7 @@ env.Library(
'$BUILD_DIR/mongo/db/views/views_mongod',
],
LIBDEPS_PRIVATE=[
+ '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/disable_index_spec_namespace_generation.idl b/src/mongo/db/catalog/disable_index_spec_namespace_generation.idl
new file mode 100644
index 00000000000..c750956396c
--- /dev/null
+++ b/src/mongo/db/catalog/disable_index_spec_namespace_generation.idl
@@ -0,0 +1,41 @@
+# 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_catalog_impl.cpp b/src/mongo/db/catalog/index_catalog_impl.cpp
index f0cb65285c1..0691f21c5e8 100644
--- a/src/mongo/db/catalog/index_catalog_impl.cpp
+++ b/src/mongo/db/catalog/index_catalog_impl.cpp
@@ -42,6 +42,7 @@
#include "mongo/db/background.h"
#include "mongo/db/catalog/collection.h"
#include "mongo/db/catalog/collection_catalog_entry.h"
+#include "mongo/db/catalog/disable_index_spec_namespace_generation_gen.h"
#include "mongo/db/catalog/index_catalog_entry_impl.h"
#include "mongo/db/catalog/index_key_validate.h"
#include "mongo/db/client.h"
@@ -577,18 +578,22 @@ Status IndexCatalogImpl::_isSpecOk(OperationContext* opCtx, const BSONObj& spec)
if (nss.isOplog())
return Status(ErrorCodes::CannotCreateIndex, "cannot have an index on the oplog");
- const BSONElement specNamespace = spec["ns"];
- if (specNamespace.type() != String)
- return Status(ErrorCodes::CannotCreateIndex,
- "the index spec is missing a \"ns\" string field");
+ // 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
- << "'");
+ 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"];
diff --git a/src/mongo/db/catalog/index_key_validate.cpp b/src/mongo/db/catalog/index_key_validate.cpp
index 52b3193fd09..c9cd4223504 100644
--- a/src/mongo/db/catalog/index_key_validate.cpp
+++ b/src/mongo/db/catalog/index_key_validate.cpp
@@ -40,6 +40,7 @@
#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"
@@ -487,7 +488,9 @@ StatusWith<BSONObj> validateIndexSpec(
if (!hasNamespaceField || !hasVersionField) {
BSONObjBuilder bob;
- if (!hasNamespaceField) {
+ // 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());
diff --git a/src/mongo/db/index/index_descriptor.cpp b/src/mongo/db/index/index_descriptor.cpp
index 96cb26f87ec..edae421b9f6 100644
--- a/src/mongo/db/index/index_descriptor.cpp
+++ b/src/mongo/db/index/index_descriptor.cpp
@@ -107,7 +107,7 @@ IndexDescriptor::IndexDescriptor(Collection* collection,
_keyPattern(infoObj.getObjectField(IndexDescriptor::kKeyPatternFieldName).getOwned()),
_projection(infoObj.getObjectField(IndexDescriptor::kPathProjectionFieldName).getOwned()),
_indexName(infoObj.getStringField(IndexDescriptor::kIndexNameFieldName)),
- _parentNS(infoObj.getStringField(IndexDescriptor::kNamespaceFieldName)),
+ _parentNS(collection->ns()),
_isIdIndex(isIdIndexPattern(_keyPattern)),
_sparse(infoObj[IndexDescriptor::kSparseFieldName].trueValue()),
_unique(_isIdIndex || infoObj[kUniqueFieldName].trueValue()),
diff --git a/src/mongo/db/storage/SConscript b/src/mongo/db/storage/SConscript
index 0d4b18fb23a..b2d7b1bffaa 100644
--- a/src/mongo/db/storage/SConscript
+++ b/src/mongo/db/storage/SConscript
@@ -69,6 +69,9 @@ 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(
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 52c858c694c..5ff7ca7cb75 100644
--- a/src/mongo/db/storage/biggie/biggie_sorted_impl_test.cpp
+++ b/src/mongo/db/storage/biggie/biggie_sorted_impl_test.cpp
@@ -30,6 +30,7 @@
#include "mongo/platform/basic.h"
#include "mongo/base/init.h"
+#include "mongo/db/catalog/collection_mock.h"
#include "mongo/db/index/index_descriptor.h"
#include "mongo/db/storage/biggie/biggie_kv_engine.h"
#include "mongo/db/storage/biggie/biggie_recovery_unit.h"
@@ -69,7 +70,8 @@ public:
spec = spec.addField(partialBSON.firstElement());
}
- IndexDescriptor desc(NULL, "", spec);
+ auto collection = std::make_unique<CollectionMock>(NamespaceString(ns));
+ IndexDescriptor desc(collection.get(), "", spec);
return std::make_unique<SortedDataInterface>(&opCtx, "ident"_sd, &desc);
}
diff --git a/src/mongo/db/storage/bson_collection_catalog_entry.cpp b/src/mongo/db/storage/bson_collection_catalog_entry.cpp
index 9c53499756e..1ff70e21d04 100644
--- a/src/mongo/db/storage/bson_collection_catalog_entry.cpp
+++ b/src/mongo/db/storage/bson_collection_catalog_entry.cpp
@@ -32,6 +32,7 @@
#include <algorithm>
#include <numeric>
+#include "mongo/db/catalog/disable_index_spec_namespace_generation_gen.h"
#include "mongo/db/field_ref.h"
namespace mongo {
@@ -133,7 +134,15 @@ BSONObj BSONCollectionCatalogEntry::getIndexSpec(OperationContext* opCtx,
int offset = md.findIndexOffset(indexName);
invariant(offset >= 0);
- return md.indexes[offset].spec.getOwned();
+
+ 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/SConscript b/src/mongo/db/storage/kv/SConscript
index 45d1e34d760..74b955d1f7b 100644
--- a/src/mongo/db/storage/kv/SConscript
+++ b/src/mongo/db/storage/kv/SConscript
@@ -73,6 +73,7 @@ env.Library(
'kv_engine_timestamps_test.cpp',
],
LIBDEPS=[
+ '$BUILD_DIR/mongo/db/catalog/catalog_impl',
'$BUILD_DIR/mongo/db/service_context',
'$BUILD_DIR/mongo/db/service_context_test_fixture',
'$BUILD_DIR/mongo/db/storage/storage_options',
diff --git a/src/mongo/db/storage/kv/kv_collection_catalog_entry_test.cpp b/src/mongo/db/storage/kv/kv_collection_catalog_entry_test.cpp
index c4eee897176..7d4e035c222 100644
--- a/src/mongo/db/storage/kv/kv_collection_catalog_entry_test.cpp
+++ b/src/mongo/db/storage/kv/kv_collection_catalog_entry_test.cpp
@@ -35,6 +35,7 @@
#include "mongo/db/catalog/collection_catalog.h"
#include "mongo/db/catalog/collection_catalog_entry.h"
+#include "mongo/db/catalog/collection_mock.h"
#include "mongo/db/index/index_descriptor.h"
#include "mongo/db/index/multikey_paths.h"
#include "mongo/db/index_names.h"
@@ -100,8 +101,9 @@ public:
auto opCtx = newOperationContext();
std::string indexName = "idx" + std::to_string(numIndexesCreated);
+ auto collection = std::make_unique<CollectionMock>(_nss);
IndexDescriptor desc(
- nullptr,
+ collection.get(),
indexType,
BSON("v" << 1 << "key" << keyPattern << "name" << indexName << "ns" << _nss.ns()));
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 182eba1cd73..72935625b70 100644
--- a/src/mongo/db/storage/kv/kv_engine_test_harness.cpp
+++ b/src/mongo/db/storage/kv/kv_engine_test_harness.cpp
@@ -29,6 +29,8 @@
#include "mongo/db/storage/kv/kv_engine_test_harness.h"
+#include "mongo/db/catalog/collection_catalog_entry_mock.h"
+#include "mongo/db/catalog/collection_impl.h"
#include "mongo/db/index/index_descriptor.h"
#include "mongo/db/operation_context_noop.h"
#include "mongo/db/storage/kv/kv_catalog.h"
@@ -142,17 +144,40 @@ TEST(KVEngineTestHarness, Restart1) {
TEST(KVEngineTestHarness, SimpleSorted1) {
+ setGlobalServiceContext(ServiceContext::make());
unique_ptr<KVHarnessHelper> helper(KVHarnessHelper::create());
KVEngine* engine = helper->getEngine();
ASSERT(engine);
string ident = "abc";
- IndexDescriptor desc(nullptr,
- "",
- BSON("v" << static_cast<int>(IndexDescriptor::kLatestIndexVersion) << "ns"
- << "mydb.mycoll"
- << "key"
- << BSON("a" << 1)));
+ string ns = "mydb.mycoll";
+
+ unique_ptr<RecordStore> rs;
+ {
+ MyOperationContext opCtx(engine);
+ WriteUnitOfWork uow(&opCtx);
+ ASSERT_OK(engine->createRecordStore(&opCtx, "catalog", "catalog", CollectionOptions()));
+ rs = engine->getRecordStore(&opCtx, "catalog", "catalog", CollectionOptions());
+ uow.commit();
+ }
+
+
+ unique_ptr<CollectionCatalogEntryMock> catalogEntry =
+ std::make_unique<CollectionCatalogEntryMock>(ns);
+ unique_ptr<CollectionImpl> collection;
+ {
+ MyOperationContext opCtx(engine);
+ WriteUnitOfWork uow(&opCtx);
+ collection =
+ std::make_unique<CollectionImpl>(&opCtx, ns, UUID::gen(), catalogEntry.get(), rs.get());
+ uow.commit();
+ }
+
+ IndexDescriptor desc(
+ collection.get(),
+ "",
+ BSON("v" << static_cast<int>(IndexDescriptor::kLatestIndexVersion) << "ns" << ns << "key"
+ << BSON("a" << 1)));
unique_ptr<SortedDataInterface> sorted;
{
MyOperationContext opCtx(engine);
@@ -660,17 +685,40 @@ TEST_F(KVCatalogTest, BackupImplemented) {
}
DEATH_TEST_F(KVCatalogTest, TerminateOnNonNumericIndexVersion, "Fatal Assertion 50942") {
+ setGlobalServiceContext(ServiceContext::make());
unique_ptr<KVHarnessHelper> helper(KVHarnessHelper::create());
KVEngine* engine = helper->getEngine();
ASSERT(engine);
string ident = "abc";
- IndexDescriptor desc(nullptr,
+ string ns = "mydb.mycoll";
+
+ unique_ptr<RecordStore> rs;
+ {
+ MyOperationContext opCtx(engine);
+ WriteUnitOfWork uow(&opCtx);
+ ASSERT_OK(engine->createRecordStore(&opCtx, "catalog", "catalog", CollectionOptions()));
+ rs = engine->getRecordStore(&opCtx, "catalog", "catalog", CollectionOptions());
+ uow.commit();
+ }
+
+ unique_ptr<CollectionCatalogEntryMock> catalogEntry =
+ std::make_unique<CollectionCatalogEntryMock>(ns);
+ unique_ptr<CollectionImpl> collection;
+ {
+ MyOperationContext opCtx(engine);
+ WriteUnitOfWork uow(&opCtx);
+ collection =
+ std::make_unique<CollectionImpl>(&opCtx, ns, UUID::gen(), catalogEntry.get(), rs.get());
+ uow.commit();
+ }
+
+ IndexDescriptor desc(collection.get(),
"",
BSON("v"
<< "1"
<< "ns"
- << "mydb.mycoll"
+ << ns
<< "key"
<< BSON("a" << 1)));
unique_ptr<SortedDataInterface> sorted;
diff --git a/src/mongo/db/storage/kv/kv_storage_engine_test_fixture.h b/src/mongo/db/storage/kv/kv_storage_engine_test_fixture.h
index 2b704e7b4e5..29cf88e7a84 100644
--- a/src/mongo/db/storage/kv/kv_storage_engine_test_fixture.h
+++ b/src/mongo/db/storage/kv/kv_storage_engine_test_fixture.h
@@ -30,6 +30,7 @@
#pragma once
#include "mongo/db/catalog/collection_catalog.h"
+#include "mongo/db/catalog/collection_mock.h"
#include "mongo/db/catalog_raii.h"
#include "mongo/db/service_context_d_test_fixture.h"
#include "mongo/db/storage/kv/kv_catalog.h"
@@ -122,7 +123,6 @@ public:
NamespaceString collNs,
std::string key,
bool isBackgroundSecondaryBuild) {
- Collection* coll = nullptr;
BSONObjBuilder builder;
{
BSONObjBuilder keyObj;
@@ -130,8 +130,9 @@ public:
}
BSONObj spec = builder.append("name", key).append("ns", collNs.ns()).append("v", 2).done();
- auto descriptor =
- stdx::make_unique<IndexDescriptor>(coll, IndexNames::findPluginName(spec), spec);
+ auto collection = std::make_unique<CollectionMock>(collNs);
+ auto descriptor = std::make_unique<IndexDescriptor>(
+ collection.get(), IndexNames::findPluginName(spec), spec);
CollectionCatalogEntry* cce =
CollectionCatalog::get(opCtx).lookupCollectionCatalogEntryByNamespace(collNs);
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 3becc730727..98d91659b4e 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_prefixed_index_test.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_prefixed_index_test.cpp
@@ -33,6 +33,7 @@
#include "mongo/base/init.h"
#include "mongo/bson/bsonobjbuilder.h"
+#include "mongo/db/catalog/collection_mock.h"
#include "mongo/db/catalog/index_catalog_entry.h"
#include "mongo/db/index/index_descriptor.h"
#include "mongo/db/json.h"
@@ -90,7 +91,8 @@ public:
spec = spec.addField(partialBSON.firstElement());
}
- IndexDescriptor desc(NULL, "", spec);
+ auto collection = std::make_unique<CollectionMock>(NamespaceString(ns));
+ IndexDescriptor desc(collection.get(), "", spec);
KVPrefix prefix = KVPrefix::generateNextPrefix();
StatusWith<std::string> result = WiredTigerIndex::generateCreateString(
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 9407ff2dedc..77ce7b9f222 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_standard_index_test.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_standard_index_test.cpp
@@ -33,6 +33,7 @@
#include "mongo/base/init.h"
#include "mongo/bson/bsonobjbuilder.h"
+#include "mongo/db/catalog/collection_mock.h"
#include "mongo/db/catalog/index_catalog_entry.h"
#include "mongo/db/index/index_descriptor.h"
#include "mongo/db/json.h"
@@ -90,7 +91,8 @@ public:
spec = spec.addField(partialBSON.firstElement());
}
- IndexDescriptor desc(NULL, "", spec);
+ auto collection = std::make_unique<CollectionMock>(NamespaceString(ns));
+ IndexDescriptor desc(collection.get(), "", spec);
KVPrefix prefix = KVPrefix::kNotPrefixed;
StatusWith<std::string> result = WiredTigerIndex::generateCreateString(