summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2019-01-24 11:40:43 -0500
committerBenety Goh <benety@mongodb.com>2019-01-24 11:40:43 -0500
commit7106a8ed5f278c81e10b94a3501b8d3992b4a97e (patch)
tree484fb0efacaaad8368a5cdb1290215bc38836779 /src
parent731bc64f8dbbee1def448b10feca305887bdc180 (diff)
downloadmongo-7106a8ed5f278c81e10b94a3501b8d3992b4a97e.tar.gz
SERVER-37643 fix dbtests to avoid creating indexes using DBClient while holding locks
Diffstat (limited to 'src')
-rw-r--r--src/mongo/dbtests/counttests.cpp17
-rw-r--r--src/mongo/dbtests/querytests.cpp24
-rw-r--r--src/mongo/dbtests/storage_timestamp_tests.cpp27
3 files changed, 51 insertions, 17 deletions
diff --git a/src/mongo/dbtests/counttests.cpp b/src/mongo/dbtests/counttests.cpp
index a591320a4d4..1781617fc19 100644
--- a/src/mongo/dbtests/counttests.cpp
+++ b/src/mongo/dbtests/counttests.cpp
@@ -31,12 +31,13 @@
#include "mongo/platform/basic.h"
#include "mongo/db/catalog/collection.h"
+#include "mongo/db/catalog/index_catalog.h"
#include "mongo/db/client.h"
#include "mongo/db/db_raii.h"
#include "mongo/db/dbdirectclient.h"
+#include "mongo/db/index/index_descriptor.h"
#include "mongo/db/json.h"
#include "mongo/dbtests/dbtests.h"
-#include "mongo/stdx/thread.h"
namespace CountTests {
@@ -50,16 +51,24 @@ public:
{
WriteUnitOfWork wunit(&_opCtx);
+
_collection = _database->getCollection(&_opCtx, ns());
if (_collection) {
_database->dropCollection(&_opCtx, ns()).transitional_ignore();
}
_collection = _database->createCollection(&_opCtx, ns());
+
+ IndexCatalog* indexCatalog = _collection->getIndexCatalog();
+ auto indexSpec =
+ BSON("v" << static_cast<int>(IndexDescriptor::kLatestIndexVersion) << "ns" << ns()
+ << "key"
+ << BSON("a" << 1)
+ << "name"
+ << "a_1");
+ uassertStatusOK(indexCatalog->createIndexOnEmptyCollection(&_opCtx, indexSpec));
+
wunit.commit();
}
-
- DBDirectClient client(&_opCtx);
- client.createIndex(ns(), IndexSpec().addKey("a").unique(false));
}
~Base() {
diff --git a/src/mongo/dbtests/querytests.cpp b/src/mongo/dbtests/querytests.cpp
index 1c74a747090..5b37ac26582 100644
--- a/src/mongo/dbtests/querytests.cpp
+++ b/src/mongo/dbtests/querytests.cpp
@@ -35,6 +35,7 @@
#include "mongo/client/dbclient_cursor.h"
#include "mongo/db/catalog/collection.h"
+#include "mongo/db/catalog/multi_index_block.h"
#include "mongo/db/client.h"
#include "mongo/db/clientcursor.h"
#include "mongo/db/cursor_manager.h"
@@ -42,6 +43,7 @@
#include "mongo/db/dbdirectclient.h"
#include "mongo/db/dbhelpers.h"
#include "mongo/db/exec/queued_data_stage.h"
+#include "mongo/db/index/index_descriptor.h"
#include "mongo/db/json.h"
#include "mongo/db/lasterror.h"
#include "mongo/db/logical_clock.h"
@@ -93,9 +95,25 @@ protected:
}
void addIndex(const IndexSpec& spec) {
- DBDirectClient client(&_opCtx);
- client.createIndex(ns(), spec);
- client.getLastError();
+ BSONObjBuilder builder(spec.toBSON());
+ builder.append("v", int(IndexDescriptor::kLatestIndexVersion));
+ builder.append("ns", ns());
+ auto specObj = builder.obj();
+
+ MultiIndexBlock indexer(&_opCtx, _collection);
+ {
+ WriteUnitOfWork wunit(&_opCtx);
+ uassertStatusOK(indexer.init(specObj));
+ wunit.commit();
+ }
+ uassertStatusOK(indexer.insertAllDocumentsInCollection());
+ uassertStatusOK(indexer.drainBackgroundWrites());
+ uassertStatusOK(indexer.checkConstraints());
+ {
+ WriteUnitOfWork wunit(&_opCtx);
+ uassertStatusOK(indexer.commit());
+ wunit.commit();
+ }
}
void insert(const char* s) {
diff --git a/src/mongo/dbtests/storage_timestamp_tests.cpp b/src/mongo/dbtests/storage_timestamp_tests.cpp
index 6a1c9877a4a..a26150058d4 100644
--- a/src/mongo/dbtests/storage_timestamp_tests.cpp
+++ b/src/mongo/dbtests/storage_timestamp_tests.cpp
@@ -1886,10 +1886,12 @@ public:
NamespaceString nss("unittests.timestampMultiIndexBuilds");
reset(nss);
- AutoGetCollection autoColl(_opCtx, nss, LockMode::MODE_X, LockMode::MODE_X);
-
- const LogicalTime insertTimestamp = _clock->reserveTicks(1);
+ std::vector<std::string> origIdents;
{
+ AutoGetCollection autoColl(_opCtx, nss, LockMode::MODE_X, LockMode::MODE_X);
+
+ const LogicalTime insertTimestamp = _clock->reserveTicks(1);
+
WriteUnitOfWork wuow(_opCtx);
insertDocument(autoColl.getCollection(),
InsertStatement(BSON("_id" << 0 << "a" << 1 << "b" << 2 << "c" << 3),
@@ -1897,11 +1899,11 @@ public:
presentTerm));
wuow.commit();
ASSERT_EQ(1, itCount(autoColl.getCollection()));
- }
- // Save the pre-state idents so we can capture the specific ident related to index
- // creation.
- std::vector<std::string> origIdents = kvCatalog->getAllIdents(_opCtx);
+ // Save the pre-state idents so we can capture the specific ident related to index
+ // creation.
+ origIdents = kvCatalog->getAllIdents(_opCtx);
+ }
DBDirectClient client(_opCtx);
{
@@ -1932,6 +1934,8 @@ public:
const auto indexBComplete =
Timestamp(indexAComplete.getSecs(), indexAComplete.getInc() + 1);
+ AutoGetCollection autoColl(_opCtx, nss, LockMode::MODE_S);
+
// The idents are created and persisted with the "ready: false" write. There should be two
// new index idents visible at this time.
const std::vector<std::string> indexes =
@@ -1967,10 +1971,11 @@ public:
NamespaceString nss("unittests.timestampMultiIndexBuildsDuringRename");
reset(nss);
- AutoGetCollection autoColl(_opCtx, nss, LockMode::MODE_X, LockMode::MODE_X);
-
- const LogicalTime insertTimestamp = _clock->reserveTicks(1);
{
+ AutoGetCollection autoColl(_opCtx, nss, LockMode::MODE_X, LockMode::MODE_X);
+
+ const LogicalTime insertTimestamp = _clock->reserveTicks(1);
+
WriteUnitOfWork wuow(_opCtx);
insertDocument(autoColl.getCollection(),
InsertStatement(BSON("_id" << 0 << "a" << 1 << "b" << 2 << "c" << 3),
@@ -1994,6 +1999,8 @@ public:
client.createIndexes(nss.ns(), indexes);
}
+ AutoGetCollection autoColl(_opCtx, nss, LockMode::MODE_X, LockMode::MODE_X);
+
NamespaceString renamedNss("unittestsRename.timestampMultiIndexBuildsDuringRename");
reset(renamedNss);