summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdityavardhan Agrawal <aa729@cornell.edu>2022-09-07 15:16:35 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-09-07 16:44:56 +0000
commita40f6505e1a1ac8f886cb5946ca00e60ac4d3c41 (patch)
treef337df8e2d6ff6de0c981908f6644b1188782568 /src
parent44c8b34f1d6d01d67e454fb2d0073d7e07cd652a (diff)
downloadmongo-a40f6505e1a1ac8f886cb5946ca00e60ac4d3c41.tar.gz
SERVER-68837: removed the double hashing in AbslHashValue for TenantId
Diffstat (limited to 'src')
-rw-r--r--src/mongo/bson/oid.h27
-rw-r--r--src/mongo/bson/oid_test.cpp7
-rw-r--r--src/mongo/db/tenant_id.h2
3 files changed, 26 insertions, 10 deletions
diff --git a/src/mongo/bson/oid.h b/src/mongo/bson/oid.h
index afe716e5b17..3ff6a0e12ab 100644
--- a/src/mongo/bson/oid.h
+++ b/src/mongo/bson/oid.h
@@ -72,15 +72,6 @@ class SecureRandom;
*/
class OID {
public:
- /**
- * Functor compatible with std::hash for std::unordered_{map,set}
- * Warning: The hash function is subject to change. Do not use in cases where hashes need
- * to be consistent across versions.
- */
- struct Hasher {
- size_t operator()(const OID& oid) const;
- };
-
OID() : _data() {}
enum { kOIDSize = 12, kTimestampSize = 4, kInstanceUniqueSize = 5, kIncrementSize = 3 };
@@ -180,11 +171,29 @@ public:
}
/**
+ * Functor compatible with std::hash for std::unordered_{map,set}
+ * Warning: The hash function is subject to change. Do not use in cases where hashes need
+ * to be consistent across versions.
+ */
+ struct Hasher {
+ size_t operator()(const OID& oid) const;
+ };
+
+ /**
* this is not consistent
* do not store on disk
*/
void hash_combine(size_t& seed) const;
+ /**
+ * Hash function compatible with absl::Hash for absl::unordered_{map,set}
+ */
+ template <typename H>
+ friend H AbslHashValue(H h, const OID& oid) {
+ const auto& d = oid._data;
+ return H::combine(std::move(h), std::string_view(d, sizeof(d)));
+ }
+
/** call this after a fork to update the process id */
static void justForked();
diff --git a/src/mongo/bson/oid_test.cpp b/src/mongo/bson/oid_test.cpp
index a33db2d90b1..5a34e6af7c1 100644
--- a/src/mongo/bson/oid_test.cpp
+++ b/src/mongo/bson/oid_test.cpp
@@ -166,4 +166,11 @@ TEST(Basic, FromTerm) {
ASSERT_OK(mongo::NumberParser::strToAny()(oidTail, &oidTailInt));
ASSERT_EQUALS(term, oidTailInt);
}
+
+TEST(Basic, AbslHash) {
+ OID o1 = OID::gen();
+ OID o2 = o1;
+ ASSERT_EQUALS(absl::Hash<OID>{}(o1), absl::Hash<OID>{}(o2));
+}
+
} // namespace
diff --git a/src/mongo/db/tenant_id.h b/src/mongo/db/tenant_id.h
index dc9b46705c3..c3eedb66053 100644
--- a/src/mongo/db/tenant_id.h
+++ b/src/mongo/db/tenant_id.h
@@ -89,7 +89,7 @@ public:
*/
template <typename H>
friend H AbslHashValue(H h, const TenantId& tenantId) {
- return H::combine(std::move(h), tenantId.hash());
+ return H::combine(std::move(h), tenantId._oid);
}
/**