summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2016-12-06 15:13:17 -0500
committerBenety Goh <benety@mongodb.com>2016-12-07 10:11:50 -0500
commitb666c293b8dee59b0bb8926afafc6eebf9c7d21c (patch)
tree3bdc6f54dea3aec82cbdad525e8edc2ec1541936 /src/mongo
parent27b1e9a1d61fdd522df5376495859cf9f63725a9 (diff)
downloadmongo-b666c293b8dee59b0bb8926afafc6eebf9c7d21c.tar.gz
SERVER-27301 converted OpObserver into an interface. ServiceContext should always return a valid OpObserver implementation.
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/SConscript12
-rw-r--r--src/mongo/db/catalog/collection.cpp32
-rw-r--r--src/mongo/db/catalog/database.cpp9
-rw-r--r--src/mongo/db/catalog/drop_database.cpp4
-rw-r--r--src/mongo/db/catalog/drop_indexes.cpp5
-rw-r--r--src/mongo/db/cloner.cpp3
-rw-r--r--src/mongo/db/commands/create_indexes.cpp6
-rw-r--r--src/mongo/db/commands/feature_compatibility_version.cpp2
-rw-r--r--src/mongo/db/commands/mr.cpp2
-rw-r--r--src/mongo/db/db.cpp4
-rw-r--r--src/mongo/db/op_observer.h84
-rw-r--r--src/mongo/db/op_observer_impl.cpp (renamed from src/mongo/db/op_observer.cpp)91
-rw-r--r--src/mongo/db/op_observer_impl.h86
-rw-r--r--src/mongo/db/op_observer_noop.cpp80
-rw-r--r--src/mongo/db/op_observer_noop.h86
-rw-r--r--src/mongo/db/service_context_d_test_fixture.cpp3
-rw-r--r--src/mongo/dbtests/SConscript1
-rw-r--r--src/mongo/dbtests/framework.cpp2
-rw-r--r--src/mongo/dbtests/repltests.cpp3
-rw-r--r--src/mongo/s/sharding_mongod_test_fixture.cpp4
20 files changed, 386 insertions, 133 deletions
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript
index ed5c540ab37..7a1fe1d630c 100644
--- a/src/mongo/db/SConscript
+++ b/src/mongo/db/SConscript
@@ -635,7 +635,7 @@ serverOnlyFiles = [
"index_rebuilder.cpp",
"instance.cpp",
"introspect.cpp",
- "op_observer.cpp",
+ "op_observer_impl.cpp",
"operation_context_impl.cpp",
"prefetch.cpp",
"range_deleter_db_env.cpp",
@@ -740,11 +740,21 @@ env.Library(
)
env.Library(
+ target= 'op_observer_noop',
+ source= [
+ 'op_observer_noop.cpp',
+ ],
+ LIBDEPS= [
+ ],
+)
+
+env.Library(
target= 'service_context_d_test_fixture',
source= [
'service_context_d_test_fixture.cpp',
],
LIBDEPS= [
+ 'op_observer_noop',
'$BUILD_DIR/mongo/db/serveronly',
'$BUILD_DIR/mongo/db/storage/storage_options',
'$BUILD_DIR/mongo/unittest/unittest',
diff --git a/src/mongo/db/catalog/collection.cpp b/src/mongo/db/catalog/collection.cpp
index 757077efb56..39bb1870256 100644
--- a/src/mongo/db/catalog/collection.cpp
+++ b/src/mongo/db/catalog/collection.cpp
@@ -417,9 +417,7 @@ Status Collection::insertDocuments(OperationContext* txn,
return status;
invariant(sid == txn->recoveryUnit()->getSnapshotId());
- auto opObserver = getGlobalServiceContext()->getOpObserver();
- if (opObserver)
- opObserver->onInserts(txn, ns(), begin, end, fromMigrate);
+ getGlobalServiceContext()->getOpObserver()->onInserts(txn, ns(), begin, end, fromMigrate);
txn->recoveryUnit()->onCommit([this]() { notifyCappedWaitersIfNeeded(); });
@@ -481,9 +479,8 @@ Status Collection::insertDocument(OperationContext* txn,
vector<BSONObj> docs;
docs.push_back(doc);
- auto opObserver = getGlobalServiceContext()->getOpObserver();
- if (opObserver)
- opObserver->onInserts(txn, ns(), docs.begin(), docs.end());
+ getGlobalServiceContext()->getOpObserver()->onInserts(
+ txn, ns(), docs.begin(), docs.end(), false);
txn->recoveryUnit()->onCommit([this]() { notifyCappedWaitersIfNeeded(); });
@@ -582,10 +579,8 @@ void Collection::deleteDocument(
Snapshotted<BSONObj> doc = docFor(txn, loc);
- CollectionShardingState::DeleteState deleteState;
- auto opObserver = getGlobalServiceContext()->getOpObserver();
- if (opObserver)
- deleteState = opObserver->aboutToDelete(txn, ns(), doc.value());
+ auto deleteState =
+ getGlobalServiceContext()->getOpObserver()->aboutToDelete(txn, ns(), doc.value());
/* check if any cursors point to us. if so, advance them. */
_cursorManager.invalidateDocument(txn, loc, INVALIDATION_DELETION);
@@ -598,8 +593,8 @@ void Collection::deleteDocument(
_recordStore->deleteRecord(txn, loc);
- if (opObserver)
- opObserver->onDelete(txn, ns(), std::move(deleteState), fromMigrate);
+ getGlobalServiceContext()->getOpObserver()->onDelete(
+ txn, ns(), std::move(deleteState), fromMigrate);
}
Counter64 moveCounter;
@@ -723,9 +718,7 @@ StatusWith<RecordId> Collection::updateDocument(OperationContext* txn,
invariant(sid == txn->recoveryUnit()->getSnapshotId());
args->updatedDoc = newDoc;
- auto opObserver = getGlobalServiceContext()->getOpObserver();
- if (opObserver)
- opObserver->onUpdate(txn, *args);
+ getGlobalServiceContext()->getOpObserver()->onUpdate(txn, *args);
return {oldLocation};
}
@@ -770,10 +763,7 @@ StatusWith<RecordId> Collection::_updateDocumentWithMove(OperationContext* txn,
invariant(sid == txn->recoveryUnit()->getSnapshotId());
args->updatedDoc = newDoc;
- auto opObserver = getGlobalServiceContext()->getOpObserver();
- if (opObserver) {
- opObserver->onUpdate(txn, *args);
- }
+ getGlobalServiceContext()->getOpObserver()->onUpdate(txn, *args);
moveCounter.increment();
if (opDebug) {
@@ -819,9 +809,7 @@ StatusWith<RecordData> Collection::updateDocumentWithDamages(
if (newRecStatus.isOK()) {
args->updatedDoc = newRecStatus.getValue().toBson();
- auto opObserver = getGlobalServiceContext()->getOpObserver();
- if (opObserver)
- opObserver->onUpdate(txn, *args);
+ getGlobalServiceContext()->getOpObserver()->onUpdate(txn, *args);
}
return newRecStatus;
}
diff --git a/src/mongo/db/catalog/database.cpp b/src/mongo/db/catalog/database.cpp
index af8070e66c4..7361e1f4f4c 100644
--- a/src/mongo/db/catalog/database.cpp
+++ b/src/mongo/db/catalog/database.cpp
@@ -407,9 +407,7 @@ Status Database::dropCollection(OperationContext* txn, StringData fullns) {
}
}
- auto opObserver = getGlobalServiceContext()->getOpObserver();
- if (opObserver)
- opObserver->onDropCollection(txn, nss);
+ getGlobalServiceContext()->getOpObserver()->onDropCollection(txn, nss);
return Status::OK();
}
@@ -562,9 +560,8 @@ Collection* Database::createCollection(OperationContext* txn,
}
}
- auto opObserver = getGlobalServiceContext()->getOpObserver();
- if (opObserver)
- opObserver->onCreateCollection(txn, nss, options, fullIdIndexSpec);
+ getGlobalServiceContext()->getOpObserver()->onCreateCollection(
+ txn, nss, options, fullIdIndexSpec);
return collection;
}
diff --git a/src/mongo/db/catalog/drop_database.cpp b/src/mongo/db/catalog/drop_database.cpp
index 8b8a992ce5e..c0698f10821 100644
--- a/src/mongo/db/catalog/drop_database.cpp
+++ b/src/mongo/db/catalog/drop_database.cpp
@@ -84,9 +84,7 @@ Status dropDatabase(OperationContext* txn, const std::string& dbName) {
WriteUnitOfWork wunit(txn);
- auto opObserver = getGlobalServiceContext()->getOpObserver();
- if (opObserver)
- opObserver->onDropDatabase(txn, dbName + ".$cmd");
+ getGlobalServiceContext()->getOpObserver()->onDropDatabase(txn, dbName + ".$cmd");
wunit.commit();
}
diff --git a/src/mongo/db/catalog/drop_indexes.cpp b/src/mongo/db/catalog/drop_indexes.cpp
index dfa22b06561..5f252685b77 100644
--- a/src/mongo/db/catalog/drop_indexes.cpp
+++ b/src/mongo/db/catalog/drop_indexes.cpp
@@ -165,9 +165,8 @@ Status dropIndexes(OperationContext* txn,
return status;
}
- auto opObserver = getGlobalServiceContext()->getOpObserver();
- if (opObserver)
- opObserver->onDropIndex(txn, dbName.toString() + ".$cmd", idxDescriptor);
+ getGlobalServiceContext()->getOpObserver()->onDropIndex(
+ txn, dbName.toString() + ".$cmd", idxDescriptor);
wunit.commit();
}
diff --git a/src/mongo/db/cloner.cpp b/src/mongo/db/cloner.cpp
index a23ddd58d8e..6b3184eae4b 100644
--- a/src/mongo/db/cloner.cpp
+++ b/src/mongo/db/cloner.cpp
@@ -424,7 +424,8 @@ void Cloner::copyIndexes(OperationContext* txn,
const string targetSystemIndexesCollectionName = to_collection.getSystemIndexesCollection();
const char* createIndexNs = targetSystemIndexesCollectionName.c_str();
for (auto&& infoObj : indexInfoObjs) {
- getGlobalServiceContext()->getOpObserver()->onCreateIndex(txn, createIndexNs, infoObj);
+ getGlobalServiceContext()->getOpObserver()->onCreateIndex(
+ txn, createIndexNs, infoObj, false);
}
}
wunit.commit();
diff --git a/src/mongo/db/commands/create_indexes.cpp b/src/mongo/db/commands/create_indexes.cpp
index 116a6248cc9..570d95a7bdb 100644
--- a/src/mongo/db/commands/create_indexes.cpp
+++ b/src/mongo/db/commands/create_indexes.cpp
@@ -392,10 +392,8 @@ public:
for (auto&& infoObj : indexInfoObjs) {
std::string systemIndexes = ns.getSystemIndexesCollection();
- auto opObserver = getGlobalServiceContext()->getOpObserver();
- if (opObserver) {
- opObserver->onCreateIndex(txn, systemIndexes, infoObj);
- }
+ getGlobalServiceContext()->getOpObserver()->onCreateIndex(
+ txn, systemIndexes, infoObj, false);
}
wunit.commit();
diff --git a/src/mongo/db/commands/feature_compatibility_version.cpp b/src/mongo/db/commands/feature_compatibility_version.cpp
index 2e38906b685..73988bef0c7 100644
--- a/src/mongo/db/commands/feature_compatibility_version.cpp
+++ b/src/mongo/db/commands/feature_compatibility_version.cpp
@@ -227,7 +227,7 @@ void FeatureCompatibilityVersion::set(OperationContext* txn, StringData version)
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
WriteUnitOfWork wuow(txn);
getGlobalServiceContext()->getOpObserver()->onCreateIndex(
- txn, autoDB.getDb()->getSystemIndexesName(), k32IncompatibleIndexSpec);
+ txn, autoDB.getDb()->getSystemIndexesName(), k32IncompatibleIndexSpec, false);
wuow.commit();
}
MONGO_WRITE_CONFLICT_RETRY_LOOP_END(txn, "FeatureCompatibilityVersion::set", nss.ns());
diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp
index 5c0b45fc6f4..5e5306f5452 100644
--- a/src/mongo/db/commands/mr.cpp
+++ b/src/mongo/db/commands/mr.cpp
@@ -510,7 +510,7 @@ void State::prepTempCollection() {
}
// Log the createIndex operation.
string logNs = nsToDatabase(_config.tempNamespace) + ".system.indexes";
- getGlobalServiceContext()->getOpObserver()->onCreateIndex(_txn, logNs, *it);
+ getGlobalServiceContext()->getOpObserver()->onCreateIndex(_txn, logNs, *it, false);
}
wuow.commit();
}
diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp
index abd2fbf40a4..bd99954befd 100644
--- a/src/mongo/db/db.cpp
+++ b/src/mongo/db/db.cpp
@@ -74,7 +74,7 @@
#include "mongo/db/json.h"
#include "mongo/db/log_process_details.h"
#include "mongo/db/mongod_options.h"
-#include "mongo/db/op_observer.h"
+#include "mongo/db/op_observer_impl.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/query/internal_plans.h"
#include "mongo/db/range_deleter_service.h"
@@ -427,7 +427,7 @@ ExitCode _initAndListen(int listenPort) {
auto globalServiceContext = getGlobalServiceContext();
globalServiceContext->setFastClockSource(FastClockSourceFactory::create(Milliseconds(10)));
- globalServiceContext->setOpObserver(stdx::make_unique<OpObserver>());
+ globalServiceContext->setOpObserver(stdx::make_unique<OpObserverImpl>());
DBDirectClientFactory::get(globalServiceContext)
.registerImplementation([](OperationContext* txn) {
diff --git a/src/mongo/db/op_observer.h b/src/mongo/db/op_observer.h
index e9c6f7d7425..15b63d89c0c 100644
--- a/src/mongo/db/op_observer.h
+++ b/src/mongo/db/op_observer.h
@@ -63,22 +63,22 @@ class OpObserver {
MONGO_DISALLOW_COPYING(OpObserver);
public:
- OpObserver() {}
- ~OpObserver() {}
+ OpObserver() = default;
+ virtual ~OpObserver() = default;
- void onCreateIndex(OperationContext* txn,
- const std::string& ns,
- BSONObj indexDoc,
- bool fromMigrate = false);
- void onInserts(OperationContext* txn,
- const NamespaceString& ns,
- std::vector<BSONObj>::const_iterator begin,
- std::vector<BSONObj>::const_iterator end,
- bool fromMigrate = false);
- void onUpdate(OperationContext* txn, const OplogUpdateEntryArgs& args);
- CollectionShardingState::DeleteState aboutToDelete(OperationContext* txn,
- const NamespaceString& ns,
- const BSONObj& doc);
+ virtual void onCreateIndex(OperationContext* txn,
+ const std::string& ns,
+ BSONObj indexDoc,
+ bool fromMigrate) = 0;
+ virtual void onInserts(OperationContext* txn,
+ const NamespaceString& ns,
+ std::vector<BSONObj>::const_iterator begin,
+ std::vector<BSONObj>::const_iterator end,
+ bool fromMigrate) = 0;
+ virtual void onUpdate(OperationContext* txn, const OplogUpdateEntryArgs& args) = 0;
+ virtual CollectionShardingState::DeleteState aboutToDelete(OperationContext* txn,
+ const NamespaceString& ns,
+ const BSONObj& doc) = 0;
/**
* Handles logging before document is deleted.
*
@@ -88,31 +88,35 @@ public:
* so should be ignored by the user as an internal maintenance operation and not a
* real delete.
*/
- void onDelete(OperationContext* txn,
- const NamespaceString& ns,
- CollectionShardingState::DeleteState deleteState,
- bool fromMigrate);
- void onOpMessage(OperationContext* txn, const BSONObj& msgObj);
- void onCreateCollection(OperationContext* txn,
- const NamespaceString& collectionName,
- const CollectionOptions& options,
- const BSONObj& idIndex);
- void onCollMod(OperationContext* txn, const std::string& dbName, const BSONObj& collModCmd);
- void onDropDatabase(OperationContext* txn, const std::string& dbName);
- void onDropCollection(OperationContext* txn, const NamespaceString& collectionName);
- void onDropIndex(OperationContext* txn,
- const std::string& dbName,
- const BSONObj& idxDescriptor);
- void onRenameCollection(OperationContext* txn,
- const NamespaceString& fromCollection,
- const NamespaceString& toCollection,
- bool dropTarget,
- bool stayTemp);
- void onApplyOps(OperationContext* txn, const std::string& dbName, const BSONObj& applyOpCmd);
- void onEmptyCapped(OperationContext* txn, const NamespaceString& collectionName);
- void onConvertToCapped(OperationContext* txn,
- const NamespaceString& collectionName,
- double size);
+ virtual void onDelete(OperationContext* txn,
+ const NamespaceString& ns,
+ CollectionShardingState::DeleteState deleteState,
+ bool fromMigrate) = 0;
+ virtual void onOpMessage(OperationContext* txn, const BSONObj& msgObj) = 0;
+ virtual void onCreateCollection(OperationContext* txn,
+ const NamespaceString& collectionName,
+ const CollectionOptions& options,
+ const BSONObj& idIndex) = 0;
+ virtual void onCollMod(OperationContext* txn,
+ const std::string& dbName,
+ const BSONObj& collModCmd) = 0;
+ virtual void onDropDatabase(OperationContext* txn, const std::string& dbName) = 0;
+ virtual void onDropCollection(OperationContext* txn, const NamespaceString& collectionName) = 0;
+ virtual void onDropIndex(OperationContext* txn,
+ const std::string& dbName,
+ const BSONObj& idxDescriptor) = 0;
+ virtual void onRenameCollection(OperationContext* txn,
+ const NamespaceString& fromCollection,
+ const NamespaceString& toCollection,
+ bool dropTarget,
+ bool stayTemp) = 0;
+ virtual void onApplyOps(OperationContext* txn,
+ const std::string& dbName,
+ const BSONObj& applyOpCmd) = 0;
+ virtual void onEmptyCapped(OperationContext* txn, const NamespaceString& collectionName) = 0;
+ virtual void onConvertToCapped(OperationContext* txn,
+ const NamespaceString& collectionName,
+ double size) = 0;
};
} // namespace mongo
diff --git a/src/mongo/db/op_observer.cpp b/src/mongo/db/op_observer_impl.cpp
index 99e1fe2f649..e8b796daac2 100644
--- a/src/mongo/db/op_observer.cpp
+++ b/src/mongo/db/op_observer_impl.cpp
@@ -1,5 +1,5 @@
/**
-* Copyright (C) 2008-2014 MongoDB Inc.
+* Copyright (C) 2016 MongoDB Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
@@ -28,7 +28,7 @@
#include "mongo/platform/basic.h"
-#include "mongo/db/op_observer.h"
+#include "mongo/db/op_observer_impl.h"
#include "mongo/db/auth/authorization_manager_global.h"
#include "mongo/db/catalog/collection_options.h"
@@ -45,12 +45,10 @@
namespace mongo {
-using std::vector;
-
-void OpObserver::onCreateIndex(OperationContext* txn,
- const std::string& ns,
- BSONObj indexDoc,
- bool fromMigrate) {
+void OpObserverImpl::onCreateIndex(OperationContext* txn,
+ const std::string& ns,
+ BSONObj indexDoc,
+ bool fromMigrate) {
repl::logOp(txn, "i", ns.c_str(), indexDoc, nullptr, fromMigrate);
AuthorizationManager::get(txn->getServiceContext())
->logOp(txn, "i", ns.c_str(), indexDoc, nullptr);
@@ -63,11 +61,11 @@ void OpObserver::onCreateIndex(OperationContext* txn,
logOpForDbHash(txn, ns.c_str());
}
-void OpObserver::onInserts(OperationContext* txn,
- const NamespaceString& nss,
- vector<BSONObj>::const_iterator begin,
- vector<BSONObj>::const_iterator end,
- bool fromMigrate) {
+void OpObserverImpl::onInserts(OperationContext* txn,
+ const NamespaceString& nss,
+ std::vector<BSONObj>::const_iterator begin,
+ std::vector<BSONObj>::const_iterator end,
+ bool fromMigrate) {
repl::logOps(txn, "i", nss, begin, end, fromMigrate);
auto css = CollectionShardingState::get(txn, nss.ns());
@@ -95,7 +93,7 @@ void OpObserver::onInserts(OperationContext* txn,
}
}
-void OpObserver::onUpdate(OperationContext* txn, const OplogUpdateEntryArgs& args) {
+void OpObserverImpl::onUpdate(OperationContext* txn, const OplogUpdateEntryArgs& args) {
// Do not log a no-op operation; see SERVER-21738
if (args.update.isEmpty()) {
return;
@@ -125,9 +123,9 @@ void OpObserver::onUpdate(OperationContext* txn, const OplogUpdateEntryArgs& arg
}
}
-CollectionShardingState::DeleteState OpObserver::aboutToDelete(OperationContext* txn,
- const NamespaceString& ns,
- const BSONObj& doc) {
+CollectionShardingState::DeleteState OpObserverImpl::aboutToDelete(OperationContext* txn,
+ const NamespaceString& ns,
+ const BSONObj& doc) {
CollectionShardingState::DeleteState deleteState;
BSONElement idElement = doc["_id"];
if (!idElement.eoo()) {
@@ -140,10 +138,10 @@ CollectionShardingState::DeleteState OpObserver::aboutToDelete(OperationContext*
return deleteState;
}
-void OpObserver::onDelete(OperationContext* txn,
- const NamespaceString& ns,
- CollectionShardingState::DeleteState deleteState,
- bool fromMigrate) {
+void OpObserverImpl::onDelete(OperationContext* txn,
+ const NamespaceString& ns,
+ CollectionShardingState::DeleteState deleteState,
+ bool fromMigrate) {
if (deleteState.idDoc.isEmpty())
return;
@@ -168,14 +166,14 @@ void OpObserver::onDelete(OperationContext* txn,
}
}
-void OpObserver::onOpMessage(OperationContext* txn, const BSONObj& msgObj) {
+void OpObserverImpl::onOpMessage(OperationContext* txn, const BSONObj& msgObj) {
repl::logOp(txn, "n", "", msgObj, nullptr, false);
}
-void OpObserver::onCreateCollection(OperationContext* txn,
- const NamespaceString& collectionName,
- const CollectionOptions& options,
- const BSONObj& idIndex) {
+void OpObserverImpl::onCreateCollection(OperationContext* txn,
+ const NamespaceString& collectionName,
+ const CollectionOptions& options,
+ const BSONObj& idIndex) {
std::string dbName = collectionName.db().toString() + ".$cmd";
BSONObjBuilder b;
b.append("create", collectionName.coll().toString());
@@ -202,9 +200,9 @@ void OpObserver::onCreateCollection(OperationContext* txn,
logOpForDbHash(txn, dbName.c_str());
}
-void OpObserver::onCollMod(OperationContext* txn,
- const std::string& dbName,
- const BSONObj& collModCmd) {
+void OpObserverImpl::onCollMod(OperationContext* txn,
+ const std::string& dbName,
+ const BSONObj& collModCmd) {
BSONElement first = collModCmd.firstElement();
std::string coll = first.valuestr();
@@ -217,7 +215,7 @@ void OpObserver::onCollMod(OperationContext* txn,
logOpForDbHash(txn, dbName.c_str());
}
-void OpObserver::onDropDatabase(OperationContext* txn, const std::string& dbName) {
+void OpObserverImpl::onDropDatabase(OperationContext* txn, const std::string& dbName) {
BSONObj cmdObj = BSON("dropDatabase" << 1);
repl::logOp(txn, "c", dbName.c_str(), cmdObj, nullptr, false);
@@ -226,7 +224,8 @@ void OpObserver::onDropDatabase(OperationContext* txn, const std::string& dbName
logOpForDbHash(txn, dbName.c_str());
}
-void OpObserver::onDropCollection(OperationContext* txn, const NamespaceString& collectionName) {
+void OpObserverImpl::onDropCollection(OperationContext* txn,
+ const NamespaceString& collectionName) {
std::string dbName = collectionName.db().toString() + ".$cmd";
BSONObj cmdObj = BSON("drop" << collectionName.coll().toString());
@@ -247,20 +246,20 @@ void OpObserver::onDropCollection(OperationContext* txn, const NamespaceString&
logOpForDbHash(txn, dbName.c_str());
}
-void OpObserver::onDropIndex(OperationContext* txn,
- const std::string& dbName,
- const BSONObj& idxDescriptor) {
+void OpObserverImpl::onDropIndex(OperationContext* txn,
+ const std::string& dbName,
+ const BSONObj& idxDescriptor) {
repl::logOp(txn, "c", dbName.c_str(), idxDescriptor, nullptr, false);
getGlobalAuthorizationManager()->logOp(txn, "c", dbName.c_str(), idxDescriptor, nullptr);
logOpForDbHash(txn, dbName.c_str());
}
-void OpObserver::onRenameCollection(OperationContext* txn,
- const NamespaceString& fromCollection,
- const NamespaceString& toCollection,
- bool dropTarget,
- bool stayTemp) {
+void OpObserverImpl::onRenameCollection(OperationContext* txn,
+ const NamespaceString& fromCollection,
+ const NamespaceString& toCollection,
+ bool dropTarget,
+ bool stayTemp) {
std::string dbName = fromCollection.db().toString() + ".$cmd";
BSONObj cmdObj =
BSON("renameCollection" << fromCollection.ns() << "to" << toCollection.ns() << "stayTemp"
@@ -279,18 +278,18 @@ void OpObserver::onRenameCollection(OperationContext* txn,
logOpForDbHash(txn, dbName.c_str());
}
-void OpObserver::onApplyOps(OperationContext* txn,
- const std::string& dbName,
- const BSONObj& applyOpCmd) {
+void OpObserverImpl::onApplyOps(OperationContext* txn,
+ const std::string& dbName,
+ const BSONObj& applyOpCmd) {
repl::logOp(txn, "c", dbName.c_str(), applyOpCmd, nullptr, false);
getGlobalAuthorizationManager()->logOp(txn, "c", dbName.c_str(), applyOpCmd, nullptr);
logOpForDbHash(txn, dbName.c_str());
}
-void OpObserver::onConvertToCapped(OperationContext* txn,
- const NamespaceString& collectionName,
- double size) {
+void OpObserverImpl::onConvertToCapped(OperationContext* txn,
+ const NamespaceString& collectionName,
+ double size) {
std::string dbName = collectionName.db().toString() + ".$cmd";
BSONObj cmdObj = BSON("convertToCapped" << collectionName.coll() << "size" << size);
@@ -303,7 +302,7 @@ void OpObserver::onConvertToCapped(OperationContext* txn,
logOpForDbHash(txn, dbName.c_str());
}
-void OpObserver::onEmptyCapped(OperationContext* txn, const NamespaceString& collectionName) {
+void OpObserverImpl::onEmptyCapped(OperationContext* txn, const NamespaceString& collectionName) {
std::string dbName = collectionName.db().toString() + ".$cmd";
BSONObj cmdObj = BSON("emptycapped" << collectionName.coll());
diff --git a/src/mongo/db/op_observer_impl.h b/src/mongo/db/op_observer_impl.h
new file mode 100644
index 00000000000..d8ccfbd678d
--- /dev/null
+++ b/src/mongo/db/op_observer_impl.h
@@ -0,0 +1,86 @@
+/**
+ * Copyright 2016 MongoDB Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * 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
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * 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 GNU Affero General 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.
+ */
+
+#pragma once
+
+#include "mongo/db/op_observer.h"
+
+namespace mongo {
+
+class OpObserverImpl : public OpObserver {
+ MONGO_DISALLOW_COPYING(OpObserverImpl);
+
+public:
+ OpObserverImpl() = default;
+ virtual ~OpObserverImpl() = default;
+
+ void onCreateIndex(OperationContext* txn,
+ const std::string& ns,
+ BSONObj indexDoc,
+ bool fromMigrate) override;
+ void onInserts(OperationContext* txn,
+ const NamespaceString& ns,
+ std::vector<BSONObj>::const_iterator begin,
+ std::vector<BSONObj>::const_iterator end,
+ bool fromMigrate) override;
+ void onUpdate(OperationContext* txn, const OplogUpdateEntryArgs& args) override;
+ CollectionShardingState::DeleteState aboutToDelete(OperationContext* txn,
+ const NamespaceString& ns,
+ const BSONObj& doc) override;
+ void onDelete(OperationContext* txn,
+ const NamespaceString& ns,
+ CollectionShardingState::DeleteState deleteState,
+ bool fromMigrate) override;
+ void onOpMessage(OperationContext* txn, const BSONObj& msgObj) override;
+ void onCreateCollection(OperationContext* txn,
+ const NamespaceString& collectionName,
+ const CollectionOptions& options,
+ const BSONObj& idIndex) override;
+ void onCollMod(OperationContext* txn,
+ const std::string& dbName,
+ const BSONObj& collModCmd) override;
+ void onDropDatabase(OperationContext* txn, const std::string& dbName) override;
+ void onDropCollection(OperationContext* txn, const NamespaceString& collectionName) override;
+ void onDropIndex(OperationContext* txn,
+ const std::string& dbName,
+ const BSONObj& idxDescriptor) override;
+ void onRenameCollection(OperationContext* txn,
+ const NamespaceString& fromCollection,
+ const NamespaceString& toCollection,
+ bool dropTarget,
+ bool stayTemp) override;
+ void onApplyOps(OperationContext* txn,
+ const std::string& dbName,
+ const BSONObj& applyOpCmd) override;
+ void onEmptyCapped(OperationContext* txn, const NamespaceString& collectionName);
+ void onConvertToCapped(OperationContext* txn,
+ const NamespaceString& collectionName,
+ double size) override;
+};
+
+} // namespace mongo
diff --git a/src/mongo/db/op_observer_noop.cpp b/src/mongo/db/op_observer_noop.cpp
new file mode 100644
index 00000000000..11243595a42
--- /dev/null
+++ b/src/mongo/db/op_observer_noop.cpp
@@ -0,0 +1,80 @@
+/**
+* Copyright (C) 2016 MongoDB Inc.
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License, version 3,
+* as published by the Free Software Foundation.
+*
+* 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
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*
+* 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 GNU Affero General 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.
+*/
+
+#include "mongo/platform/basic.h"
+
+#include "mongo/db/op_observer_noop.h"
+
+namespace mongo {
+
+void OpObserverNoop::onCreateIndex(OperationContext*, const std::string&, BSONObj, bool) {}
+
+void OpObserverNoop::onInserts(OperationContext*,
+ const NamespaceString&,
+ std::vector<BSONObj>::const_iterator,
+ std::vector<BSONObj>::const_iterator,
+ bool) {}
+
+void OpObserverNoop::onUpdate(OperationContext*, const OplogUpdateEntryArgs&) {}
+
+CollectionShardingState::DeleteState OpObserverNoop::aboutToDelete(OperationContext*,
+ const NamespaceString&,
+ const BSONObj&) {
+ return {};
+}
+
+void OpObserverNoop::onDelete(OperationContext*,
+ const NamespaceString&,
+ CollectionShardingState::DeleteState,
+ bool) {}
+
+void OpObserverNoop::onOpMessage(OperationContext*, const BSONObj&) {}
+
+void OpObserverNoop::onCreateCollection(OperationContext*,
+ const NamespaceString&,
+ const CollectionOptions&,
+ const BSONObj&) {}
+
+void OpObserverNoop::onCollMod(OperationContext*, const std::string&, const BSONObj&) {}
+
+void OpObserverNoop::onDropDatabase(OperationContext*, const std::string&) {}
+
+void OpObserverNoop::onDropCollection(OperationContext*, const NamespaceString&) {}
+
+void OpObserverNoop::onDropIndex(OperationContext*, const std::string&, const BSONObj&) {}
+
+void OpObserverNoop::onRenameCollection(
+ OperationContext*, const NamespaceString&, const NamespaceString&, bool, bool) {}
+
+void OpObserverNoop::onApplyOps(OperationContext*, const std::string&, const BSONObj&) {}
+
+void OpObserverNoop::onConvertToCapped(OperationContext*, const NamespaceString&, double) {}
+
+void OpObserverNoop::onEmptyCapped(OperationContext*, const NamespaceString&) {}
+
+} // namespace mongo
diff --git a/src/mongo/db/op_observer_noop.h b/src/mongo/db/op_observer_noop.h
new file mode 100644
index 00000000000..f9d1e1d9182
--- /dev/null
+++ b/src/mongo/db/op_observer_noop.h
@@ -0,0 +1,86 @@
+/**
+ * Copyright 2016 MongoDB Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * 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
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * 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 GNU Affero General 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.
+ */
+
+#pragma once
+
+#include "mongo/db/op_observer.h"
+
+namespace mongo {
+
+class OpObserverNoop : public OpObserver {
+ MONGO_DISALLOW_COPYING(OpObserverNoop);
+
+public:
+ OpObserverNoop() = default;
+ virtual ~OpObserverNoop() = default;
+
+ void onCreateIndex(OperationContext* txn,
+ const std::string& ns,
+ BSONObj indexDoc,
+ bool fromMigrate) override;
+ void onInserts(OperationContext* txn,
+ const NamespaceString& ns,
+ std::vector<BSONObj>::const_iterator begin,
+ std::vector<BSONObj>::const_iterator end,
+ bool fromMigrate) override;
+ void onUpdate(OperationContext* txn, const OplogUpdateEntryArgs& args) override;
+ CollectionShardingState::DeleteState aboutToDelete(OperationContext* txn,
+ const NamespaceString& ns,
+ const BSONObj& doc) override;
+ void onDelete(OperationContext* txn,
+ const NamespaceString& ns,
+ CollectionShardingState::DeleteState deleteState,
+ bool fromMigrate) override;
+ void onOpMessage(OperationContext* txn, const BSONObj& msgObj) override;
+ void onCreateCollection(OperationContext* txn,
+ const NamespaceString& collectionName,
+ const CollectionOptions& options,
+ const BSONObj& idIndex) override;
+ void onCollMod(OperationContext* txn,
+ const std::string& dbName,
+ const BSONObj& collModCmd) override;
+ void onDropDatabase(OperationContext* txn, const std::string& dbName) override;
+ void onDropCollection(OperationContext* txn, const NamespaceString& collectionName) override;
+ void onDropIndex(OperationContext* txn,
+ const std::string& dbName,
+ const BSONObj& idxDescriptor) override;
+ void onRenameCollection(OperationContext* txn,
+ const NamespaceString& fromCollection,
+ const NamespaceString& toCollection,
+ bool dropTarget,
+ bool stayTemp) override;
+ void onApplyOps(OperationContext* txn,
+ const std::string& dbName,
+ const BSONObj& applyOpCmd) override;
+ void onEmptyCapped(OperationContext* txn, const NamespaceString& collectionName);
+ void onConvertToCapped(OperationContext* txn,
+ const NamespaceString& collectionName,
+ double size) override;
+};
+
+} // namespace mongo
diff --git a/src/mongo/db/service_context_d_test_fixture.cpp b/src/mongo/db/service_context_d_test_fixture.cpp
index 74fc3872d91..268a7cee984 100644
--- a/src/mongo/db/service_context_d_test_fixture.cpp
+++ b/src/mongo/db/service_context_d_test_fixture.cpp
@@ -37,10 +37,12 @@
#include "mongo/db/concurrency/write_conflict_exception.h"
#include "mongo/db/curop.h"
#include "mongo/db/db_raii.h"
+#include "mongo/db/op_observer_noop.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/service_context.h"
#include "mongo/db/service_context_d.h"
#include "mongo/db/storage/storage_options.h"
+#include "mongo/stdx/memory.h"
#include "mongo/unittest/temp_dir.h"
#include "mongo/util/scopeguard.h"
@@ -58,6 +60,7 @@ void ServiceContextMongoDTest::setUp() {
storageGlobalParams.engineSetByUser = true;
checked_cast<ServiceContextMongoD*>(getGlobalServiceContext())->createLockFile();
serviceContext->initializeGlobalStorageEngine();
+ serviceContext->setOpObserver(stdx::make_unique<OpObserverNoop>());
}
}
diff --git a/src/mongo/dbtests/SConscript b/src/mongo/dbtests/SConscript
index dc30106d231..f67d20040d3 100644
--- a/src/mongo/dbtests/SConscript
+++ b/src/mongo/dbtests/SConscript
@@ -22,6 +22,7 @@ env.Library(
'framework_options_init.cpp',
],
LIBDEPS=[
+ '$BUILD_DIR/mongo/db/op_observer_noop',
'$BUILD_DIR/mongo/db/s/sharding',
'$BUILD_DIR/mongo/s/coreshard',
'$BUILD_DIR/mongo/unittest/unittest',
diff --git a/src/mongo/dbtests/framework.cpp b/src/mongo/dbtests/framework.cpp
index 53826e931a0..68537ee5705 100644
--- a/src/mongo/dbtests/framework.cpp
+++ b/src/mongo/dbtests/framework.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/client.h"
#include "mongo/db/concurrency/lock_state.h"
#include "mongo/db/dbdirectclient.h"
+#include "mongo/db/op_observer_noop.h"
#include "mongo/db/s/sharding_state.h"
#include "mongo/db/service_context.h"
#include "mongo/db/service_context_d.h"
@@ -89,6 +90,7 @@ int runDbTests(int argc, char** argv) {
checked_cast<ServiceContextMongoD*>(globalServiceContext)->createLockFile();
globalServiceContext->initializeGlobalStorageEngine();
+ globalServiceContext->setOpObserver(stdx::make_unique<OpObserverNoop>());
int ret = unittest::Suite::run(frameworkGlobalParams.suites,
frameworkGlobalParams.filter,
diff --git a/src/mongo/dbtests/repltests.cpp b/src/mongo/dbtests/repltests.cpp
index b17ff37767c..e547f4aa8a6 100644
--- a/src/mongo/dbtests/repltests.cpp
+++ b/src/mongo/dbtests/repltests.cpp
@@ -41,6 +41,7 @@
#include "mongo/db/db_raii.h"
#include "mongo/db/dbdirectclient.h"
#include "mongo/db/json.h"
+#include "mongo/db/op_observer_impl.h"
#include "mongo/db/ops/update.h"
#include "mongo/db/repl/master_slave.h"
#include "mongo/db/repl/oplog.h"
@@ -77,7 +78,7 @@ public:
replSettings.setMaster(true);
setGlobalReplicationCoordinator(new repl::ReplicationCoordinatorMock(replSettings));
- getGlobalServiceContext()->setOpObserver(stdx::make_unique<OpObserver>());
+ getGlobalServiceContext()->setOpObserver(stdx::make_unique<OpObserverImpl>());
setOplogCollectionName();
createOplog(&_txn);
diff --git a/src/mongo/s/sharding_mongod_test_fixture.cpp b/src/mongo/s/sharding_mongod_test_fixture.cpp
index 3e8c9f013d7..41b6565ffb5 100644
--- a/src/mongo/s/sharding_mongod_test_fixture.cpp
+++ b/src/mongo/s/sharding_mongod_test_fixture.cpp
@@ -40,7 +40,7 @@
#include "mongo/db/commands.h"
#include "mongo/db/db_raii.h"
#include "mongo/db/namespace_string.h"
-#include "mongo/db/op_observer.h"
+#include "mongo/db/op_observer_impl.h"
#include "mongo/db/query/cursor_response.h"
#include "mongo/db/query/query_request.h"
#include "mongo/db/repl/oplog.h"
@@ -124,7 +124,7 @@ void ShardingMongodTestFixture::setUp() {
repl::ReplicationCoordinator::set(serviceContext, std::move(replCoordPtr));
- serviceContext->setOpObserver(stdx::make_unique<OpObserver>());
+ serviceContext->setOpObserver(stdx::make_unique<OpObserverImpl>());
repl::setOplogCollectionName();
repl::createOplog(_opCtx.get());
}