diff options
author | Matthew Russotto <matthew.russotto@10gen.com> | 2018-02-12 10:08:44 -0500 |
---|---|---|
committer | Matthew Russotto <matthew.russotto@10gen.com> | 2018-02-13 14:00:58 -0500 |
commit | 0f4b9e146be4cf9b612e34c500d91b4fdb91b07a (patch) | |
tree | e785b82c76e11f27421f6adc747f191f1b39e50a /src/mongo/db | |
parent | a4321b24021f6c1ec376c1c3b79f59732a3463e4 (diff) | |
download | mongo-0f4b9e146be4cf9b612e34c500d91b4fdb91b07a.tar.gz |
SERVER-33058 Add onTransactionCommit and onTransactionAbort opObservers
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/catalog/uuid_catalog.h | 2 | ||||
-rw-r--r-- | src/mongo/db/op_observer.h | 11 | ||||
-rw-r--r-- | src/mongo/db/op_observer_impl.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/op_observer_impl.h | 2 | ||||
-rw-r--r-- | src/mongo/db/op_observer_noop.h | 2 | ||||
-rw-r--r-- | src/mongo/db/op_observer_registry.h | 10 |
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; |