summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;