summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/db/auth/authz_session_external_state_d.cpp1
-rw-r--r--src/mongo/db/catalog/database_impl.cpp3
-rw-r--r--src/mongo/db/cloner.cpp2
-rw-r--r--src/mongo/db/dbhelpers.cpp28
-rw-r--r--src/mongo/db/dbhelpers.h18
-rw-r--r--src/mongo/db/repl/sync_tail.cpp1
-rw-r--r--src/mongo/db/restapi.cpp6
-rw-r--r--src/mongo/db/service_context.cpp13
-rw-r--r--src/mongo/dbtests/counttests.cpp26
-rw-r--r--src/mongo/dbtests/indexcatalogtests.cpp1
-rw-r--r--src/mongo/dbtests/indexupdatetests.cpp26
-rw-r--r--src/mongo/dbtests/querytests.cpp24
-rw-r--r--src/mongo/dbtests/validate_tests.cpp1
13 files changed, 30 insertions, 120 deletions
diff --git a/src/mongo/db/auth/authz_session_external_state_d.cpp b/src/mongo/db/auth/authz_session_external_state_d.cpp
index 2ea9386341e..77f0f0df856 100644
--- a/src/mongo/db/auth/authz_session_external_state_d.cpp
+++ b/src/mongo/db/auth/authz_session_external_state_d.cpp
@@ -32,7 +32,6 @@
#include "mongo/client/dbclientinterface.h"
#include "mongo/db/auth/authorization_manager.h"
#include "mongo/db/client.h"
-#include "mongo/db/dbhelpers.h"
#include "mongo/db/jsobj.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/repl/replication_coordinator_global.h"
diff --git a/src/mongo/db/catalog/database_impl.cpp b/src/mongo/db/catalog/database_impl.cpp
index 32ee8cfe279..0c0ff62429e 100644
--- a/src/mongo/db/catalog/database_impl.cpp
+++ b/src/mongo/db/catalog/database_impl.cpp
@@ -48,7 +48,7 @@
#include "mongo/db/clientcursor.h"
#include "mongo/db/concurrency/d_concurrency.h"
#include "mongo/db/concurrency/write_conflict_exception.h"
-#include "mongo/db/dbhelpers.h"
+#include "mongo/db/curop.h"
#include "mongo/db/index/index_access_method.h"
#include "mongo/db/introspect.h"
#include "mongo/db/op_observer.h"
@@ -58,7 +58,6 @@
#include "mongo/db/server_options.h"
#include "mongo/db/server_parameters.h"
#include "mongo/db/service_context.h"
-#include "mongo/db/service_context_d.h"
#include "mongo/db/stats/top.h"
#include "mongo/db/storage/recovery_unit.h"
#include "mongo/db/storage/storage_engine.h"
diff --git a/src/mongo/db/cloner.cpp b/src/mongo/db/cloner.cpp
index 01d03fbc7bf..463324ccbcc 100644
--- a/src/mongo/db/cloner.cpp
+++ b/src/mongo/db/cloner.cpp
@@ -50,8 +50,8 @@
#include "mongo/db/commands/list_collections_filter.h"
#include "mongo/db/commands/rename_collection.h"
#include "mongo/db/concurrency/write_conflict_exception.h"
+#include "mongo/db/curop.h"
#include "mongo/db/dbdirectclient.h"
-#include "mongo/db/dbhelpers.h"
#include "mongo/db/index/index_descriptor.h"
#include "mongo/db/index_builder.h"
#include "mongo/db/jsobj.h"
diff --git a/src/mongo/db/dbhelpers.cpp b/src/mongo/db/dbhelpers.cpp
index c247d31a6d1..9eec07c3fea 100644
--- a/src/mongo/db/dbhelpers.cpp
+++ b/src/mongo/db/dbhelpers.cpp
@@ -83,34 +83,6 @@ using std::stringstream;
using logger::LogComponent;
-void Helpers::ensureIndex(OperationContext* opCtx,
- Collection* collection,
- BSONObj keyPattern,
- IndexDescriptor::IndexVersion indexVersion,
- bool unique,
- const char* name) {
- BSONObjBuilder b;
- b.append("name", name);
- b.append("ns", collection->ns().ns());
- b.append("key", keyPattern);
- b.append("v", static_cast<int>(indexVersion));
- b.appendBool("unique", unique);
- BSONObj o = b.done();
-
- MultiIndexBlock indexer(opCtx, collection);
-
- Status status = indexer.init(o).getStatus();
- if (status.code() == ErrorCodes::IndexAlreadyExists)
- return;
- uassertStatusOK(status);
-
- uassertStatusOK(indexer.insertAllDocumentsInCollection());
-
- WriteUnitOfWork wunit(opCtx);
- indexer.commit();
- wunit.commit();
-}
-
/* fetch a single object from collection ns that matches query
set your db SavedContext first
*/
diff --git a/src/mongo/db/dbhelpers.h b/src/mongo/db/dbhelpers.h
index d143c418dbf..bcba05a7b04 100644
--- a/src/mongo/db/dbhelpers.h
+++ b/src/mongo/db/dbhelpers.h
@@ -32,7 +32,6 @@
#include <memory>
#include "mongo/db/db.h"
-#include "mongo/db/index/index_descriptor.h"
#include "mongo/db/record_id.h"
#include "mongo/db/storage/data_protector.h"
@@ -54,23 +53,6 @@ struct WriteConcernOptions;
struct Helpers {
class RemoveSaver;
- /* ensure the specified index exists.
-
- @param keyPattern key pattern, e.g., { ts : 1 }
- @param name index name, e.g., "name_1"
-
- This method can be a little (not much) cpu-slow, so you may wish to use
- OCCASIONALLY ensureIndex(...);
-
- Note: does nothing if collection does not yet exist.
- */
- static void ensureIndex(OperationContext* opCtx,
- Collection* collection,
- BSONObj keyPattern,
- IndexDescriptor::IndexVersion indexVersion,
- bool unique,
- const char* name);
-
/* fetch a single object from collection ns that matches query.
set your db SavedContext first.
diff --git a/src/mongo/db/repl/sync_tail.cpp b/src/mongo/db/repl/sync_tail.cpp
index 105f40bcd5a..a650721be2c 100644
--- a/src/mongo/db/repl/sync_tail.cpp
+++ b/src/mongo/db/repl/sync_tail.cpp
@@ -51,7 +51,6 @@
#include "mongo/db/concurrency/write_conflict_exception.h"
#include "mongo/db/curop.h"
#include "mongo/db/db_raii.h"
-#include "mongo/db/dbhelpers.h"
#include "mongo/db/namespace_string.h"
#include "mongo/db/prefetch.h"
#include "mongo/db/query/query_knobs.h"
diff --git a/src/mongo/db/restapi.cpp b/src/mongo/db/restapi.cpp
index 1869858f223..393a6085529 100644
--- a/src/mongo/db/restapi.cpp
+++ b/src/mongo/db/restapi.cpp
@@ -42,7 +42,6 @@
#include "mongo/db/clientcursor.h"
#include "mongo/db/concurrency/d_concurrency.h"
#include "mongo/db/dbdirectclient.h"
-#include "mongo/db/dbhelpers.h"
#include "mongo/db/dbwebserver.h"
#include "mongo/db/repl/master_slave.h"
#include "mongo/db/repl/replication_coordinator_global.h"
@@ -53,12 +52,9 @@
namespace mongo {
-bool getInitialSyncCompleted();
-
using std::unique_ptr;
using std::string;
using std::stringstream;
-using std::endl;
using std::vector;
using namespace html;
@@ -124,7 +120,7 @@ public:
responseCode = 400;
headers.push_back("X_err: bad request");
ss << "don't know how to handle a [" << method << "]";
- log() << "don't know how to handle a [" << method << "]" << endl;
+ log() << "don't know how to handle a [" << method << "]";
}
if (html)
diff --git a/src/mongo/db/service_context.cpp b/src/mongo/db/service_context.cpp
index 1509fca8367..de50199c149 100644
--- a/src/mongo/db/service_context.cpp
+++ b/src/mongo/db/service_context.cpp
@@ -293,7 +293,20 @@ void appendStorageEngineList(BSONObjBuilder* result) {
void ServiceContext::setKillAllOperations() {
stdx::lock_guard<stdx::mutex> clientLock(_mutex);
+
+ // Ensure that all newly created operation contexts will immediately be in the interrupted state
_globalKill.store(true);
+
+ // Interrupt all active operations
+ for (auto&& client : _clients) {
+ stdx::lock_guard<Client> lk(*client);
+ auto opCtxToKill = client->getOperationContext();
+ if (opCtxToKill) {
+ killOperation(opCtxToKill, ErrorCodes::InterruptedAtShutdown);
+ }
+ }
+
+ // Notify any listeners who need to reach to the server shutting down
for (const auto listener : _killOpListeners) {
try {
listener->interruptAll();
diff --git a/src/mongo/dbtests/counttests.cpp b/src/mongo/dbtests/counttests.cpp
index 72eef6f6097..2ae6da87932 100644
--- a/src/mongo/dbtests/counttests.cpp
+++ b/src/mongo/dbtests/counttests.cpp
@@ -1,5 +1,3 @@
-// counttests.cpp : count.{h,cpp} unit tests.
-
/**
* Copyright (C) 2008 10gen Inc.
*
@@ -35,19 +33,12 @@
#include "mongo/db/db.h"
#include "mongo/db/db_raii.h"
#include "mongo/db/dbdirectclient.h"
-#include "mongo/db/dbhelpers.h"
-#include "mongo/db/index/index_descriptor.h"
#include "mongo/db/json.h"
-#include "mongo/stdx/thread.h"
-
#include "mongo/dbtests/dbtests.h"
+#include "mongo/stdx/thread.h"
namespace CountTests {
-namespace {
-const auto kIndexVersion = IndexDescriptor::IndexVersion::kV2;
-} // namespace
-
class Base {
public:
Base()
@@ -66,8 +57,10 @@ public:
wunit.commit();
}
- addIndex(fromjson("{\"a\":1}"));
+ DBDirectClient client(&_opCtx);
+ client.createIndex(ns(), IndexSpec().addKey("a").unique(false));
}
+
~Base() {
try {
WriteUnitOfWork wunit(&_opCtx);
@@ -83,15 +76,6 @@ protected:
return "unittests.counttests";
}
- void addIndex(const BSONObj& key) {
- Helpers::ensureIndex(&_opCtx,
- _collection,
- key,
- kIndexVersion,
- /*unique=*/false,
- /*name=*/key.firstElementFieldName());
- }
-
void insert(const char* s) {
WriteUnitOfWork wunit(&_opCtx);
const BSONObj o = fromjson(s);
@@ -110,7 +94,6 @@ protected:
wunit.commit();
}
-
const ServiceContext::UniqueOperationContext _opCtxPtr = cc().makeOperationContext();
OperationContext& _opCtx = *_opCtxPtr;
Lock::DBLock _lk;
@@ -162,7 +145,6 @@ public:
}
};
-
class All : public Suite {
public:
All() : Suite("count") {}
diff --git a/src/mongo/dbtests/indexcatalogtests.cpp b/src/mongo/dbtests/indexcatalogtests.cpp
index a30fa5cc82f..04bce2a1b38 100644
--- a/src/mongo/dbtests/indexcatalogtests.cpp
+++ b/src/mongo/dbtests/indexcatalogtests.cpp
@@ -24,7 +24,6 @@
#include "mongo/db/client.h"
#include "mongo/db/db.h"
#include "mongo/db/db_raii.h"
-#include "mongo/db/dbhelpers.h"
#include "mongo/db/index/index_descriptor.h"
#include "mongo/dbtests/dbtests.h"
diff --git a/src/mongo/dbtests/indexupdatetests.cpp b/src/mongo/dbtests/indexupdatetests.cpp
index f0ab83fb9f0..4cc101e0dac 100644
--- a/src/mongo/dbtests/indexupdatetests.cpp
+++ b/src/mongo/dbtests/indexupdatetests.cpp
@@ -38,7 +38,6 @@
#include "mongo/db/client.h"
#include "mongo/db/db_raii.h"
#include "mongo/db/dbdirectclient.h"
-#include "mongo/db/dbhelpers.h"
#include "mongo/db/index/index_descriptor.h"
#include "mongo/db/service_context.h"
#include "mongo/db/service_context_d.h"
@@ -46,8 +45,6 @@
namespace IndexUpdateTests {
-using std::unique_ptr;
-
namespace {
const auto kIndexVersion = IndexDescriptor::IndexVersion::kV2;
} // namespace
@@ -416,28 +413,6 @@ public:
}
};
-/** Helpers::ensureIndex() is not interrupted. */
-class HelpersEnsureIndexInterruptDisallowed : public IndexBuildBase {
-public:
- void run() {
- // Insert some documents.
- int32_t nDocs = 1000;
- for (int32_t i = 0; i < nDocs; ++i) {
- _client.insert(_ns, BSON("a" << i));
- }
- // Start with just _id
- ASSERT_EQUALS(1U, _client.getIndexSpecs(_ns).size());
- // Request an interrupt.
- getGlobalServiceContext()->setKillAllOperations();
- // The call is not interrupted.
- Helpers::ensureIndex(&_opCtx, collection(), BSON("a" << 1), kIndexVersion, false, "a_1");
- // only want to interrupt the index build
- getGlobalServiceContext()->unsetKillAllOperations();
- // The new index is listed in getIndexSpecs because the index build completed.
- ASSERT_EQUALS(2U, _client.getIndexSpecs(_ns).size());
- }
-};
-
Status IndexBuildBase::createIndex(const std::string& dbname, const BSONObj& indexSpec) {
MultiIndexBlock indexer(&_opCtx, collection());
Status status = indexer.init(indexSpec).getStatus();
@@ -834,7 +809,6 @@ public:
add<InsertBuildIndexInterruptDisallowed>();
add<InsertBuildIdIndexInterrupt>();
add<InsertBuildIdIndexInterruptDisallowed>();
- add<HelpersEnsureIndexInterruptDisallowed>();
add<SameSpecDifferentOption>();
add<SameSpecSameOptions>();
add<DifferentSpecSameName>();
diff --git a/src/mongo/dbtests/querytests.cpp b/src/mongo/dbtests/querytests.cpp
index 6894117ce4c..e68d41bfcd8 100644
--- a/src/mongo/dbtests/querytests.cpp
+++ b/src/mongo/dbtests/querytests.cpp
@@ -1,5 +1,3 @@
-// querytests.cpp : query.{h,cpp} unit tests.
-
/**
* Copyright (C) 2008 10gen Inc.
*
@@ -41,7 +39,6 @@
#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"
@@ -61,10 +58,6 @@ using std::endl;
using std::string;
using std::vector;
-namespace {
-const auto kIndexVersion = IndexDescriptor::IndexVersion::kV2;
-} // namespace
-
class Base {
public:
Base() : _lk(&_opCtx), _context(&_opCtx, ns()) {
@@ -79,7 +72,7 @@ public:
wunit.commit();
}
- addIndex(fromjson("{\"a\":1}"));
+ addIndex(IndexSpec().addKey("a").unique(false));
}
~Base() {
@@ -97,9 +90,10 @@ protected:
return "unittests.querytests";
}
- void addIndex(const BSONObj& key) {
- Helpers::ensureIndex(
- &_opCtx, _collection, key, kIndexVersion, false, key.firstElementFieldName());
+ void addIndex(const IndexSpec& spec) {
+ DBDirectClient client(&_opCtx);
+ client.createIndex(ns(), spec);
+ client.getLastError();
}
void insert(const char* s) {
@@ -135,8 +129,9 @@ protected:
class FindOneOr : public Base {
public:
void run() {
- addIndex(BSON("b" << 1));
- addIndex(BSON("c" << 1));
+ addIndex(IndexSpec().addKey("b").unique(false));
+ addIndex(IndexSpec().addKey("c").unique(false));
+
insert(BSON("b" << 2 << "_id" << 0));
insert(BSON("c" << 3 << "_id" << 1));
BSONObj query = fromjson("{$or:[{b:2},{c:3}]}");
@@ -173,7 +168,8 @@ public:
// Check findOne() returning location, requiring indexed scan without index.
ASSERT_THROWS(Helpers::findOne(&_opCtx, _collection, query, true), MsgAssertionException);
- addIndex(BSON("b" << 1));
+ addIndex(IndexSpec().addKey("b").unique(false));
+
// Check findOne() returning object, requiring indexed scan with index.
ASSERT(Helpers::findOne(&_opCtx, _collection, query, ret, true));
// Check findOne() returning location, requiring indexed scan with index.
diff --git a/src/mongo/dbtests/validate_tests.cpp b/src/mongo/dbtests/validate_tests.cpp
index 9b949ec3b93..3bd85e9925f 100644
--- a/src/mongo/dbtests/validate_tests.cpp
+++ b/src/mongo/dbtests/validate_tests.cpp
@@ -36,7 +36,6 @@
#include "mongo/db/client.h"
#include "mongo/db/db_raii.h"
#include "mongo/db/dbdirectclient.h"
-#include "mongo/db/dbhelpers.h"
#include "mongo/db/index/index_descriptor.h"
#include "mongo/db/service_context.h"
#include "mongo/db/service_context_d.h"