summaryrefslogtreecommitdiff
path: root/src/mongo/db/storage/kv
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 13:54:54 -0400
commit9ad8cdbded0dc00b17dca8344608920507f60e8d (patch)
treebe05b1cd66df14407434922ccbf9aa88521557d3 /src/mongo/db/storage/kv
parent86b07826cede4cfd33e1a47f10a111b1d96e9758 (diff)
downloadmongo-9ad8cdbded0dc00b17dca8344608920507f60e8d.tar.gz
SERVER-41422 Allow the absence of the 'ns' field from index specs
Diffstat (limited to 'src/mongo/db/storage/kv')
-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
4 files changed, 64 insertions, 12 deletions
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 744dd3818a2..6831af48ff4 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 1485bacf687..afd0cbb68b8 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 54e2f3a54d0..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 =
- std::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);