diff options
author | babenko <babenko@yandex-team.com> | 2024-04-24 00:11:24 +0300 |
---|---|---|
committer | babenko <babenko@yandex-team.com> | 2024-04-24 00:20:54 +0300 |
commit | 0add7c67fec9cfc75d74ebf9dfba10202cc65360 (patch) | |
tree | 9c077073f91d5cbdd096d3390f4317f53c5ab465 | |
parent | 42c37f6650d9387d20dc37cba3fbddd523075166 (diff) | |
download | ydb-0add7c67fec9cfc75d74ebf9dfba10202cc65360.tar.gz |
Make hashcodes produced by TDirectObjectIdHash truely 64 bit
2de4b05f986a03156d6a56a6e660777764fcc52f
-rw-r--r-- | yt/yt/client/chaos_client/helpers.cpp | 8 | ||||
-rw-r--r-- | yt/yt/client/object_client/helpers-inl.h | 27 | ||||
-rw-r--r-- | yt/yt/client/object_client/helpers.h | 20 | ||||
-rw-r--r-- | yt/yt/client/object_client/public.h | 4 |
4 files changed, 29 insertions, 30 deletions
diff --git a/yt/yt/client/chaos_client/helpers.cpp b/yt/yt/client/chaos_client/helpers.cpp index 377011c913..8f7a289c34 100644 --- a/yt/yt/client/chaos_client/helpers.cpp +++ b/yt/yt/client/chaos_client/helpers.cpp @@ -18,7 +18,7 @@ TReplicationCardId MakeReplicationCardId(TObjectId randomId) EObjectType::ReplicationCard, CellTagFromId(randomId), CounterFromId(randomId), - HashFromId(randomId) & 0xffff0000); + EntropyFromId(randomId) & 0xffff0000); } TReplicaId MakeReplicaId(TReplicationCardId replicationCardId, TReplicaIdIndex index) @@ -27,7 +27,7 @@ TReplicaId MakeReplicaId(TReplicationCardId replicationCardId, TReplicaIdIndex i EObjectType::ChaosTableReplica, CellTagFromId(replicationCardId), CounterFromId(replicationCardId), - HashFromId(replicationCardId) | index); + EntropyFromId(replicationCardId) | index); } TReplicationCardId ReplicationCardIdFromReplicaId(TReplicaId replicaId) @@ -36,7 +36,7 @@ TReplicationCardId ReplicationCardIdFromReplicaId(TReplicaId replicaId) EObjectType::ReplicationCard, CellTagFromId(replicaId), CounterFromId(replicaId), - HashFromId(replicaId) & 0xffff0000); + EntropyFromId(replicaId) & 0xffff0000); } TReplicationCardId ReplicationCardIdFromUpstreamReplicaIdOrNull(TReplicaId upstreamReplicaId) @@ -52,7 +52,7 @@ TReplicationCardId MakeReplicationCardCollocationId(TObjectId randomId) EObjectType::ReplicationCardCollocation, CellTagFromId(randomId), CounterFromId(randomId), - HashFromId(randomId) & 0xffff0000); + EntropyFromId(randomId) & 0xffff0000); } TCellTag GetSiblingChaosCellTag(TCellTag cellTag) diff --git a/yt/yt/client/object_client/helpers-inl.h b/yt/yt/client/object_client/helpers-inl.h index 9297fec91d..1aaa08b251 100644 --- a/yt/yt/client/object_client/helpers-inl.h +++ b/yt/yt/client/object_client/helpers-inl.h @@ -29,7 +29,7 @@ inline ui64 CounterFromId(TObjectId id) return result; } -inline ui32 HashFromId(TObjectId id) +inline ui32 EntropyFromId(TObjectId id) { return id.Parts32[0]; } @@ -62,10 +62,10 @@ inline TObjectId MakeId( EObjectType type, TCellTag cellTag, ui64 counter, - ui32 hash) + ui32 entropy) { return TObjectId( - hash, + entropy, (static_cast<ui32>(cellTag.Underlying()) << 16) | static_cast<ui32>(type), counter & 0xffffffff, counter >> 32); @@ -97,10 +97,10 @@ inline TObjectId MakeRegularId( EObjectType type, TCellTag cellTag, NHydra::TVersion version, - ui32 hash) + ui32 entropy) { return TObjectId( - hash, + entropy, (static_cast<ui32>(cellTag.Underlying()) << 16) | static_cast<ui32>(type), version.RecordId, version.SegmentId); @@ -110,14 +110,14 @@ inline TObjectId MakeSequoiaId( EObjectType type, TCellTag cellTag, NTransactionClient::TTimestamp timestamp, - ui32 hash) + ui32 entropy) { YT_ASSERT(!(timestamp & SequoiaCounterMask)); return MakeId( type, cellTag, timestamp | SequoiaCounterMask, - hash); + entropy); } inline TObjectId MakeWellKnownId( @@ -163,22 +163,21 @@ inline TObjectId ReplaceCellTagInId( template <int ShardCount> inline int GetShardIndex(TObjectId id) { - static_assert(IsPowerOf2(ShardCount), "Number of shards must be a power of 2"); - return TDirectObjectIdHash()(id) & (ShardCount - 1); + return EntropyFromId(id) % static_cast<ui32>(ShardCount); } //////////////////////////////////////////////////////////////////////////////// -Y_FORCE_INLINE size_t TDirectObjectIdHash::operator()(TObjectId id) const +Y_FORCE_INLINE size_t TObjectIdEntropyHash::operator()(TObjectId id) const { - return id.Parts32[0]; + return (static_cast<size_t>(id.Parts32[0]) | (static_cast<size_t>(id.Parts32[0]) << 32)) ^ id.Parts64[1]; } -Y_FORCE_INLINE size_t TDirectVersionedObjectIdHash::operator()(const TVersionedObjectId& id) const +Y_FORCE_INLINE size_t TVersionedObjectIdEntropyHash::operator()(const TVersionedObjectId& id) const { return - TDirectObjectIdHash()(id.TransactionId) * 497 + - TDirectObjectIdHash()(id.ObjectId); + TObjectIdEntropyHash()(id.TransactionId) * 497 + + TObjectIdEntropyHash()(id.ObjectId); } //////////////////////////////////////////////////////////////////////////////// diff --git a/yt/yt/client/object_client/helpers.h b/yt/yt/client/object_client/helpers.h index a258269afe..d172d8b45c 100644 --- a/yt/yt/client/object_client/helpers.h +++ b/yt/yt/client/object_client/helpers.h @@ -84,8 +84,8 @@ TCellTag CellTagFromId(TObjectId id); //! Extracts the counter component from #id. ui64 CounterFromId(TObjectId id); -//! Extracts the hash component from #id. -ui32 HashFromId(TObjectId id); +//! Extracts the entropy component from #id. +ui32 EntropyFromId(TObjectId id); //! Extracts Hydra revision from #id for non-Sequoia objects. NHydra::TVersion VersionFromId(TObjectId id); @@ -110,7 +110,7 @@ TObjectId MakeId( EObjectType type, TCellTag cellTag, ui64 counter, - ui32 hash); + ui32 entropy); //! Creates a random id with given type and cell tag. TObjectId MakeRandomId( @@ -134,14 +134,14 @@ TObjectId MakeRegularId( EObjectType type, TCellTag cellTag, NHydra::TVersion version, - ui32 hash); + ui32 entropy); //! Constructs the id for a regular Sequoia object. TObjectId MakeSequoiaId( EObjectType type, TCellTag cellTag, NTransactionClient::TTimestamp timestamp, - ui32 hash); + ui32 entropy); //! Constructs the id corresponding to well-known (usually singleton) entities. /* @@ -178,15 +178,15 @@ bool IsGlobalCellId(TCellId cellId); //////////////////////////////////////////////////////////////////////////////// -//! Relies on first 32 bits of object id to be pseudo-random, -//! cf. TObjectManager::GenerateId. -struct TDirectObjectIdHash +//! Relies on first 32 bits of object id ("entropy") to be pseudo-random, +//! cf. MakeRegularId. +struct TObjectIdEntropyHash { size_t operator()(TObjectId id) const; }; -//! Cf. TDirectObjectIdHash -struct TDirectVersionedObjectIdHash +//! Cf. TObjectIdEntropyHash +struct TVersionedObjectIdEntropyHash { size_t operator()(const TVersionedObjectId& id) const; }; diff --git a/yt/yt/client/object_client/public.h b/yt/yt/client/object_client/public.h index 28536c9516..bdb18fa02d 100644 --- a/yt/yt/client/object_client/public.h +++ b/yt/yt/client/object_client/public.h @@ -409,8 +409,8 @@ bool operator < (const TVersionedObjectId& lhs, const TVersionedObjectId& rhs); class TObjectServiceProxy; -struct TDirectObjectIdHash; -struct TDirectVersionedObjectIdHash; +struct TObjectIdEntropyHash; +struct TVersionedObjectIdEntropyHash; //////////////////////////////////////////////////////////////////////////////// |