summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl/split_prepare_session_manager.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/repl/split_prepare_session_manager.h')
-rw-r--r--src/mongo/db/repl/split_prepare_session_manager.h39
1 files changed, 34 insertions, 5 deletions
diff --git a/src/mongo/db/repl/split_prepare_session_manager.h b/src/mongo/db/repl/split_prepare_session_manager.h
index 6a53763e73b..7732ff8853e 100644
--- a/src/mongo/db/repl/split_prepare_session_manager.h
+++ b/src/mongo/db/repl/split_prepare_session_manager.h
@@ -39,6 +39,19 @@ namespace repl {
using PooledSession = InternalSessionPool::Session;
/**
+ * This struct contains information for a split session, including the split
+ * session itself and the id of the requester who wants to acquire the split
+ * session, which is usually a writer thread from the oplog applier.
+ */
+struct SplitSessionInfo {
+ PooledSession session;
+ uint32_t requesterId;
+
+ SplitSessionInfo(PooledSession&& sess, uint32_t reqId)
+ : session(std::move(sess)), requesterId(reqId) {}
+};
+
+/**
* This class manages the sessions for split prepared transactions.
*
* Prepared transactions are split and applied in parallel on secondaries, and this class is
@@ -57,22 +70,35 @@ public:
/**
* Creates split sessions for the given top-level session and track the mapping.
*
+ * The txnNumber is the txnNumber of the top-level session that needs to be split. It
+ * servers as a sanity check: onces a session is split, it can not be split again for
+ * another txnNumber until it releases the existing split sessions.
+ *
+ * The requesterIds is a sorted list of requesters (usually writer threads from the
+ * oplog applier), each of whom wants to acquire a split session.
+ *
* Asserts if the given session is already split.
*/
- const std::vector<PooledSession>& splitSession(const LogicalSessionId& sessionId,
- TxnNumber txnNumber,
- uint32_t numSplits);
+ const std::vector<SplitSessionInfo>& splitSession(const LogicalSessionId& sessionId,
+ TxnNumber txnNumber,
+ const std::vector<uint32_t>& requesterIds);
/**
* Returns a vector of split sessions for the given top-level session, or nothing if
* the given session has not been split.
+ *
+ * The txnNumber servers a sanity check to make sure it is the same as the one being
+ * used for splitSession().
*/
- boost::optional<const std::vector<PooledSession>&> getSplitSessions(
+ boost::optional<const std::vector<SplitSessionInfo>&> getSplitSessions(
const LogicalSessionId& sessionId, TxnNumber txnNumber) const;
/**
* Returns true if the given session has been split, or false otherwise. This can be
* used as an alternative to getSplitSessionIds() when the result is not needed.
+ *
+ * The txnNumber servers a sanity check to make sure it is the same as the one being
+ * used for splitSession().
*/
bool isSessionSplit(const LogicalSessionId& sessionId, TxnNumber txnNumber) const;
@@ -80,6 +106,9 @@ public:
* Releases all the split sessions of the give top-level session into the session pool
* and stops tracking their mapping.
*
+ * The txnNumber servers a sanity check to make sure it is the same as the one being
+ * used for splitSession().
+ *
* Asserts if the given session is not split.
*/
void releaseSplitSessions(const LogicalSessionId& sessionId, TxnNumber txnNumber);
@@ -92,7 +121,7 @@ private:
InternalSessionPool* _sessionPool;
// A map to track top-level sessions and their splits.
- LogicalSessionIdMap<std::pair<TxnNumber, std::vector<PooledSession>>> _splitSessionMap;
+ LogicalSessionIdMap<std::pair<TxnNumber, std::vector<SplitSessionInfo>>> _splitSessionMap;
};
} // namespace repl