diff options
author | Jason Zhang <jason.zhang@mongodb.com> | 2022-04-05 15:07:28 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-04-05 16:39:55 +0000 |
commit | 7d0634a03461f22ef0c0461a011bde9425f00a3b (patch) | |
tree | 46145550063993ff174e60482ae01363c8eebb10 | |
parent | 15bf8f14132712c419a7de16c12396abf40c51df (diff) | |
download | mongo-7d0634a03461f22ef0c0461a011bde9425f00a3b.tar.gz |
SERVER-65235 Make LogicalSessionIdHasher has on txnUUID if it exists
-rw-r--r-- | src/mongo/db/logical_session_id.h | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/mongo/db/logical_session_id.h b/src/mongo/db/logical_session_id.h index 48324b2aa01..ec0d331bce6 100644 --- a/src/mongo/db/logical_session_id.h +++ b/src/mongo/db/logical_session_id.h @@ -29,6 +29,7 @@ #pragma once +#include <boost/functional/hash.hpp> #include <string> #include "mongo/base/status_with.h" @@ -60,8 +61,8 @@ constexpr Minutes kLogicalSessionDefaultTimeout = Minutes(kLocalLogicalSessionTimeoutMinutesDefault); inline bool operator==(const LogicalSessionId& lhs, const LogicalSessionId& rhs) { - return (lhs.getId() == rhs.getId()) && (lhs.getUid() == rhs.getUid()) && - (lhs.getTxnNumber() == rhs.getTxnNumber()) && (lhs.getTxnUUID() == rhs.getTxnUUID()); + return (lhs.getId() == rhs.getId()) && (lhs.getTxnNumber() == rhs.getTxnNumber()) && + (lhs.getTxnUUID() == rhs.getTxnUUID()) && (lhs.getUid() == rhs.getUid()); } inline bool operator!=(const LogicalSessionId& lhs, const LogicalSessionId& rhs) { @@ -89,6 +90,15 @@ LogicalSessionRecord makeLogicalSessionRecordForTest(); struct LogicalSessionIdHash { std::size_t operator()(const LogicalSessionId& lsid) const { + // Due to internal sessions having the same _id, we want to hash by its txnUUID and + // txnNumber to discourage hash key collision. + if (auto txnUUID = lsid.getTxnUUID()) { + auto hash = _hasher(*txnUUID); + if (lsid.getTxnNumber()) { + boost::hash_combine(hash, *lsid.getTxnNumber()); + } + return hash; + } return _hasher(lsid.getId()); } @@ -98,7 +108,7 @@ private: struct LogicalSessionRecordHash { std::size_t operator()(const LogicalSessionRecord& lsid) const { - return _hasher(lsid.getId().getId()); + return LogicalSessionIdHash{}(lsid.getId()); } private: |