summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorMatthew Russotto <matthew.russotto@10gen.com>2018-02-12 10:08:44 -0500
committerMatthew Russotto <matthew.russotto@10gen.com>2018-02-13 14:00:58 -0500
commit0f4b9e146be4cf9b612e34c500d91b4fdb91b07a (patch)
treee785b82c76e11f27421f6adc747f191f1b39e50a /src/mongo
parenta4321b24021f6c1ec376c1c3b79f59732a3463e4 (diff)
downloadmongo-0f4b9e146be4cf9b612e34c500d91b4fdb91b07a.tar.gz
SERVER-33058 Add onTransactionCommit and onTransactionAbort opObservers
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/catalog/uuid_catalog.h2
-rw-r--r--src/mongo/db/op_observer.h11
-rw-r--r--src/mongo/db/op_observer_impl.cpp8
-rw-r--r--src/mongo/db/op_observer_impl.h2
-rw-r--r--src/mongo/db/op_observer_noop.h2
-rw-r--r--src/mongo/db/op_observer_registry.h10
6 files changed, 35 insertions, 0 deletions
diff --git a/src/mongo/db/catalog/uuid_catalog.h b/src/mongo/db/catalog/uuid_catalog.h
index b4486f89aa2..4ec6efb10be 100644
--- a/src/mongo/db/catalog/uuid_catalog.h
+++ b/src/mongo/db/catalog/uuid_catalog.h
@@ -102,6 +102,8 @@ public:
void onEmptyCapped(OperationContext* opCtx,
const NamespaceString& collectionName,
OptionalCollectionUUID uuid) override {}
+ void onTransactionCommit(OperationContext* opCtx) override {}
+ void onTransactionAbort(OperationContext* opCtx) override {}
};
/**
diff --git a/src/mongo/db/op_observer.h b/src/mongo/db/op_observer.h
index 6ce3ea26fd5..7cbfbcc09b6 100644
--- a/src/mongo/db/op_observer.h
+++ b/src/mongo/db/op_observer.h
@@ -221,6 +221,17 @@ public:
virtual void onEmptyCapped(OperationContext* opCtx,
const NamespaceString& collectionName,
OptionalCollectionUUID uuid) = 0;
+ /**
+ * The onTransactionCommit method is called on the commit of an atomic transaction, before the
+ * RecoveryUnit onCommit() is called. It must not be called when no transaction is active.
+ */
+ virtual void onTransactionCommit(OperationContext* opCtx) = 0;
+
+ /**
+ * The onTransactionAbort method is called when an atomic transaction aborts, before the
+ * RecoveryUnit onRollback() is called. It must not be called when no transaction is active.
+ */
+ virtual void onTransactionAbort(OperationContext* opCtx) = 0;
};
} // namespace mongo
diff --git a/src/mongo/db/op_observer_impl.cpp b/src/mongo/db/op_observer_impl.cpp
index 4323e783738..5977916570d 100644
--- a/src/mongo/db/op_observer_impl.cpp
+++ b/src/mongo/db/op_observer_impl.cpp
@@ -774,4 +774,12 @@ void OpObserverImpl::onEmptyCapped(OperationContext* opCtx,
->logOp(opCtx, "c", cmdNss, cmdObj, nullptr);
}
+void OpObserverImpl::onTransactionCommit(OperationContext* opCtx) {
+ invariant(opCtx->getTxnNumber());
+}
+
+void OpObserverImpl::onTransactionAbort(OperationContext* opCtx) {
+ invariant(opCtx->getTxnNumber());
+}
+
} // namespace mongo
diff --git a/src/mongo/db/op_observer_impl.h b/src/mongo/db/op_observer_impl.h
index 1d26d54a411..5fd71850008 100644
--- a/src/mongo/db/op_observer_impl.h
+++ b/src/mongo/db/op_observer_impl.h
@@ -98,6 +98,8 @@ public:
void onEmptyCapped(OperationContext* opCtx,
const NamespaceString& collectionName,
OptionalCollectionUUID uuid);
+ void onTransactionCommit(OperationContext* opCtx) override;
+ void onTransactionAbort(OperationContext* opCtx) override;
};
} // namespace mongo
diff --git a/src/mongo/db/op_observer_noop.h b/src/mongo/db/op_observer_noop.h
index 12aa572c231..8f59107d034 100644
--- a/src/mongo/db/op_observer_noop.h
+++ b/src/mongo/db/op_observer_noop.h
@@ -97,6 +97,8 @@ public:
void onEmptyCapped(OperationContext* opCtx,
const NamespaceString& collectionName,
OptionalCollectionUUID uuid) override {}
+ void onTransactionCommit(OperationContext* opCtx) override{};
+ void onTransactionAbort(OperationContext* opCtx) override{};
};
} // namespace mongo
diff --git a/src/mongo/db/op_observer_registry.h b/src/mongo/db/op_observer_registry.h
index f9d5c9bb860..e08477610a3 100644
--- a/src/mongo/db/op_observer_registry.h
+++ b/src/mongo/db/op_observer_registry.h
@@ -173,6 +173,16 @@ public:
o->onEmptyCapped(opCtx, collectionName, uuid);
}
+ void onTransactionCommit(OperationContext* opCtx) override {
+ for (auto& o : _observers)
+ o->onTransactionCommit(opCtx);
+ }
+
+ void onTransactionAbort(OperationContext* opCtx) override {
+ for (auto& o : _observers)
+ o->onTransactionAbort(opCtx);
+ }
+
private:
repl::OpTime _forEachObserver(stdx::function<repl::OpTime(OpObserver&)> f) {
repl::OpTime opTime;