summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeert Bosch <geert.bosch@mongodb.com>2019-10-22 21:05:20 +0000
committerevergreen <evergreen@mongodb.com>2019-10-22 21:05:20 +0000
commit0a5b8a92ed440f9dbc35d8e3d22cde43fab164f6 (patch)
treeb977e70a4e929ed8fbfe2c1136d2d2d481063aaa
parent604cc100d1e12422aa3243385bc994651e0e19d2 (diff)
downloadmongo-0a5b8a92ed440f9dbc35d8e3d22cde43fab164f6.tar.gz
SERVER-44101 Add a KeyString::Value::hash method and use it in validation
-rw-r--r--src/mongo/db/catalog/index_consistency.cpp6
-rw-r--r--src/mongo/db/storage/key_string.h7
2 files changed, 8 insertions, 5 deletions
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 <limits>
+#include <absl/hash/hash.h>
+
#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.
*/