diff options
| author | babenko <[email protected]> | 2024-10-27 11:04:42 +0300 |
|---|---|---|
| committer | babenko <[email protected]> | 2024-10-27 11:18:41 +0300 |
| commit | d9ee431eba4f735c4b0a12d49fb3159e19990ede (patch) | |
| tree | 35d3f26fa019fb081567b8c83438d5edf2cfafad | |
| parent | 1529383373617c6d14ad4972afdc46a5eb35f954 (diff) | |
Make NHydra::TRevision a strong typedef
commit_hash:a99d3da5a670d4c59ea821a95f57d1ffb2097daa
| -rw-r--r-- | yt/yt/client/api/rpc_proxy/file_reader.cpp | 5 | ||||
| -rw-r--r-- | yt/yt/client/api/rpc_proxy/helpers.cpp | 6 | ||||
| -rw-r--r-- | yt/yt/client/hydra/public.h | 6 | ||||
| -rw-r--r-- | yt/yt/client/hydra/version.cpp | 18 | ||||
| -rw-r--r-- | yt/yt/client/hydra/version.h | 2 | ||||
| -rw-r--r-- | yt/yt/client/object_client/helpers-inl.h | 7 | ||||
| -rw-r--r-- | yt/yt/client/object_client/helpers.h | 5 |
7 files changed, 32 insertions, 17 deletions
diff --git a/yt/yt/client/api/rpc_proxy/file_reader.cpp b/yt/yt/client/api/rpc_proxy/file_reader.cpp index 24c55ff5217..c3e928f4fd2 100644 --- a/yt/yt/client/api/rpc_proxy/file_reader.cpp +++ b/yt/yt/client/api/rpc_proxy/file_reader.cpp @@ -60,7 +60,10 @@ TFuture<IFileReaderPtr> CreateFileReader( THROW_ERROR_EXCEPTION("Failed to deserialize file stream header"); } - return New<TFileReader>(inputStream, FromProto<TObjectId>(meta.id()), meta.revision()); + return New<TFileReader>( + inputStream, + FromProto<TObjectId>(meta.id()), + FromProto<NHydra::TRevision>(meta.revision())); })).As<IFileReaderPtr>(); })); } diff --git a/yt/yt/client/api/rpc_proxy/helpers.cpp b/yt/yt/client/api/rpc_proxy/helpers.cpp index f27134a912a..44c240da548 100644 --- a/yt/yt/client/api/rpc_proxy/helpers.cpp +++ b/yt/yt/client/api/rpc_proxy/helpers.cpp @@ -81,7 +81,7 @@ void ToProto( for (const auto& item : options.PrerequisiteRevisions) { auto* protoItem = proto->add_revisions(); protoItem->set_path(item->Path); - protoItem->set_revision(item->Revision); + protoItem->set_revision(ToProto(item->Revision)); } } @@ -599,7 +599,7 @@ void FromProto(NTableClient::TTableSchemaPtr* schema, const NProto::TTableSchema void ToProto(NProto::TTabletInfo* protoTabletInfo, const NTabletClient::TTabletInfo& tabletInfo) { ToProto(protoTabletInfo->mutable_tablet_id(), tabletInfo.TabletId); - protoTabletInfo->set_mount_revision(tabletInfo.MountRevision); + protoTabletInfo->set_mount_revision(ToProto(tabletInfo.MountRevision)); protoTabletInfo->set_state(static_cast<i32>(tabletInfo.State)); ToProto(protoTabletInfo->mutable_pivot_key(), tabletInfo.PivotKey); if (tabletInfo.CellId) { @@ -611,7 +611,7 @@ void FromProto(NTabletClient::TTabletInfo* tabletInfo, const NProto::TTabletInfo { tabletInfo->TabletId = FromProto<TTabletId>(protoTabletInfo.tablet_id()); - tabletInfo->MountRevision = protoTabletInfo.mount_revision(); + tabletInfo->MountRevision = FromProto<NHydra::TRevision>(protoTabletInfo.mount_revision()); tabletInfo->State = CheckedEnumCast<ETabletState>(protoTabletInfo.state()); tabletInfo->PivotKey = FromProto<NTableClient::TLegacyOwningKey>(protoTabletInfo.pivot_key()); if (protoTabletInfo.has_cell_id()) { diff --git a/yt/yt/client/hydra/public.h b/yt/yt/client/hydra/public.h index c2bdbf94cd9..c3a9b358b8e 100644 --- a/yt/yt/client/hydra/public.h +++ b/yt/yt/client/hydra/public.h @@ -6,6 +6,8 @@ #include <yt/yt/core/rpc/public.h> +#include <library/cpp/yt/misc/strong_typedef.h> + namespace NYT::NHydra { //////////////////////////////////////////////////////////////////////////////// @@ -41,8 +43,8 @@ DEFINE_ENUM(EPeerKind, ((LeaderOrFollower) (2)) ); -using TRevision = ui64; -constexpr TRevision NullRevision = 0; +YT_DEFINE_STRONG_TYPEDEF(TRevision, ui64); +constexpr auto NullRevision = TRevision(); struct TVersion; struct TReachableState; diff --git a/yt/yt/client/hydra/version.cpp b/yt/yt/client/hydra/version.cpp index 782ece82e54..6f55b6b56e1 100644 --- a/yt/yt/client/hydra/version.cpp +++ b/yt/yt/client/hydra/version.cpp @@ -58,22 +58,22 @@ TVersion::TVersion(int segmentId, int recordId) noexcept , RecordId(recordId) { } -std::strong_ordering TVersion::operator <=> (const TVersion& other) const -{ - if (SegmentId != other.SegmentId) { - return SegmentId <=> other.SegmentId; - } - return RecordId <=> other.RecordId; -} +// std::strong_ordering TVersion::operator <=> (const TVersion& other) const +// { +// if (SegmentId != other.SegmentId) { +// return SegmentId <=> other.SegmentId; +// } +// return RecordId <=> other.RecordId; +// } TRevision TVersion::ToRevision() const { - return (static_cast<TRevision>(SegmentId) << 32) | static_cast<TRevision>(RecordId); + return TRevision((static_cast<ui64>(SegmentId) << 32) | static_cast<ui64>(RecordId)); } TVersion TVersion::FromRevision(TRevision revision) { - return TVersion(revision >> 32, revision & 0xffffffff); + return TVersion(revision.Underlying() >> 32, revision.Underlying() & 0xffffffff); } TVersion TVersion::Advance(int delta) const diff --git a/yt/yt/client/hydra/version.h b/yt/yt/client/hydra/version.h index 79e60dff446..c6dd8ef65bd 100644 --- a/yt/yt/client/hydra/version.h +++ b/yt/yt/client/hydra/version.h @@ -58,7 +58,7 @@ struct TVersion TVersion() = default; TVersion(int segmentId, int recordId) noexcept; - std::strong_ordering operator <=> (const TVersion& other) const; + std::strong_ordering operator <=> (const TVersion& other) const = default; bool operator == (const TVersion& other) const = default; TRevision ToRevision() const; diff --git a/yt/yt/client/object_client/helpers-inl.h b/yt/yt/client/object_client/helpers-inl.h index 9d487edb19c..000d5b1710f 100644 --- a/yt/yt/client/object_client/helpers-inl.h +++ b/yt/yt/client/object_client/helpers-inl.h @@ -29,6 +29,11 @@ inline ui64 CounterFromId(TObjectId id) return result; } +inline NHydra::TRevision RevisionFromId(TObjectId id) +{ + return NHydra::TRevision(CounterFromId(id)); +} + inline ui32 EntropyFromId(TObjectId id) { return id.Parts32[0]; @@ -37,7 +42,7 @@ inline ui32 EntropyFromId(TObjectId id) inline NHydra::TVersion VersionFromId(TObjectId id) { YT_ASSERT(!IsSequoiaId(id)); - return NHydra::TVersion::FromRevision(CounterFromId(id)); + return NHydra::TVersion::FromRevision(RevisionFromId(id)); } inline NTransactionClient::TTimestamp TimestampFromId(TObjectId id) diff --git a/yt/yt/client/object_client/helpers.h b/yt/yt/client/object_client/helpers.h index 1c668033c9c..8ff3066b258 100644 --- a/yt/yt/client/object_client/helpers.h +++ b/yt/yt/client/object_client/helpers.h @@ -8,6 +8,8 @@ #include <yt/yt/client/ypath/public.h> +#include <yt/yt/client/hydra/public.h> + #include <yt/yt/core/rpc/public.h> namespace NYT::NObjectClient { @@ -98,6 +100,9 @@ TCellTag CellTagFromId(TObjectId id); //! Extracts the counter component from #id. ui64 CounterFromId(TObjectId id); +//! Extracts Hydra revision from #id. +NHydra::TRevision RevisionFromId(TObjectId id); + //! Extracts the entropy component from #id. ui32 EntropyFromId(TObjectId id); |
