summaryrefslogtreecommitdiff
path: root/src/mongo/db/session.h
diff options
context:
space:
mode:
authorJudah Schvimer <judah@mongodb.com>2018-08-07 13:42:19 -0400
committerJudah Schvimer <judah@mongodb.com>2018-08-07 13:42:19 -0400
commit0ed9472dc8c2f85e957052f01336b1247c7a6e75 (patch)
treeda761a08d90ca13f535a443447ff790910e34702 /src/mongo/db/session.h
parent3ff467eb73c0db1022ba4e1c182bedf65f183a3b (diff)
downloadmongo-0ed9472dc8c2f85e957052f01336b1247c7a6e75.tar.gz
SERVER-35798 preallocate prepare timestamp
Diffstat (limited to 'src/mongo/db/session.h')
-rw-r--r--src/mongo/db/session.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/mongo/db/session.h b/src/mongo/db/session.h
index 6faa0f28b5f..21fa7b9deb5 100644
--- a/src/mongo/db/session.h
+++ b/src/mongo/db/session.h
@@ -36,6 +36,7 @@
#include "mongo/db/logical_session_id.h"
#include "mongo/db/multi_key_path_tracker.h"
#include "mongo/db/operation_context.h"
+#include "mongo/db/repl/oplog.h"
#include "mongo/db/repl/oplog_entry.h"
#include "mongo/db/repl/read_concern_args.h"
#include "mongo/db/session_txn_record_gen.h"
@@ -483,6 +484,36 @@ private:
const repl::OpTime& lastStmtIdWriteTs);
/**
+ * Reserves a slot in the oplog with an open storage-transaction while it is alive. Reserves the
+ * slot at construction. Aborts the storage-transaction and releases the oplog slot at
+ * destruction.
+ */
+ class OplogSlotReserver {
+ public:
+ OplogSlotReserver(OperationContext* opCtx);
+
+ ~OplogSlotReserver();
+
+ // Rule of 5: because we have a class-defined destructor, we need to explictly specify
+ // the move operator and move assignment operator.
+ OplogSlotReserver(OplogSlotReserver&&) = default;
+ OplogSlotReserver& operator=(OplogSlotReserver&&) = default;
+
+ /**
+ * Returns the oplog slot reserved at construction.
+ */
+ OplogSlot getReservedOplogSlot() const {
+ invariant(!_oplogSlot.opTime.isNull());
+ return _oplogSlot;
+ }
+
+ private:
+ std::unique_ptr<Locker> _locker;
+ std::unique_ptr<RecoveryUnit> _recoveryUnit;
+ OplogSlot _oplogSlot;
+ };
+
+ /**
* Indicates the state of the current multi-document transaction, if any. If the transaction is
* in any state but kInProgress, no more operations can be collected. Once the transaction is in
* kPrepared, the transaction is not allowed to abort outside of an 'abortTransaction' command.