From 0a5b8a92ed440f9dbc35d8e3d22cde43fab164f6 Mon Sep 17 00:00:00 2001 From: Geert Bosch Date: Tue, 22 Oct 2019 21:05:20 +0000 Subject: SERVER-44101 Add a KeyString::Value::hash method and use it in validation --- src/mongo/db/catalog/index_consistency.cpp | 6 +----- src/mongo/db/storage/key_string.h | 7 +++++++ 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/mongo/db/catalog/index_consistency.cpp b/src/mongo/db/catalog/index_consistency.cpp index a9999d0b5ba..83d9d45f19b 100644 --- a/src/mongo/db/catalog/index_consistency.cpp +++ b/src/mongo/db/catalog/index_consistency.cpp @@ -307,10 +307,6 @@ BSONObj IndexConsistency::_generateInfo(const IndexInfo& indexInfo, uint32_t IndexConsistency::_hashKeyString(const KeyString::Value& ks, uint32_t indexNameHash) const { - using namespace absl::hash_internal; - uint64_t hash = indexNameHash; - hash = CityHash64WithSeed(ks.getTypeBits().getBuffer(), ks.getTypeBits().getSize(), hash); - hash = CityHash64WithSeed(ks.getBuffer(), ks.getSize(), hash); - return hash % kNumHashBuckets; + return ks.hash(indexNameHash) % kNumHashBuckets; } } // namespace mongo diff --git a/src/mongo/db/storage/key_string.h b/src/mongo/db/storage/key_string.h index 74fb80406e3..5b8d77a11f4 100644 --- a/src/mongo/db/storage/key_string.h +++ b/src/mongo/db/storage/key_string.h @@ -31,6 +31,8 @@ #include +#include + #include "mongo/base/static_assert.h" #include "mongo/bson/bsonelement_comparator_interface.h" #include "mongo/bson/bsonmisc.h" @@ -342,6 +344,11 @@ public: return TypeBits::fromBuffer(_version, &reader); } + // Compute hash over key + uint64_t hash(uint64_t seed = 0) const { + return absl::hash_internal::CityHash64WithSeed(_buffer.get(), _bufSize, seed); + } + /** * Returns a hex encoding of this key. */ -- cgit v1.2.1