Browse Source

YT-20971: Check for actual clock_cluster_tag in generateTimestamp
11502915d95ae90898a9b08a451054aa148accde

osidorkin 11 months ago
parent
commit
5d00501105

+ 16 - 3
yt/yt/client/transaction_client/remote_timestamp_provider.cpp

@@ -87,9 +87,22 @@ private:
         if (clockClusterTag != InvalidCellTag) {
             req->set_clock_cluster_tag(ToProto<int>(clockClusterTag));
         }
-        return req->Invoke().Apply(BIND([] (const TTimestampServiceProxy::TRspGenerateTimestampsPtr& rsp) {
-            return static_cast<TTimestamp>(rsp->timestamp());
-        }));
+        return req->Invoke().Apply(
+            BIND([clockClusterTag] (const TTimestampServiceProxy::TRspGenerateTimestampsPtr& rsp) {
+            auto responseClockClusterTag = rsp->has_clock_cluster_tag()
+                ? FromProto<TCellTag>(rsp->clock_cluster_tag())
+                : InvalidCellTag;
+
+            if (clockClusterTag != InvalidCellTag && responseClockClusterTag != InvalidCellTag &&
+                clockClusterTag != responseClockClusterTag)
+            {
+                THROW_ERROR_EXCEPTION(NRpc::EErrorCode::ClockClusterTagMismatch, "Clock cluster tag mismatch")
+                    << TErrorAttribute("request_clock_cluster_tag", clockClusterTag)
+                    << TErrorAttribute("response_clock_cluster_tag", responseClockClusterTag);
+            }
+
+                return static_cast<TTimestamp>(rsp->timestamp());
+            }));
     }
 };
 

+ 2 - 0
yt/yt/core/rpc/public.h

@@ -185,6 +185,8 @@ YT_DEFINE_ERROR_ENUM(
     ((SslError)                     (static_cast<int>(NBus::EErrorCode::SslError)))
     ((MemoryOverflow)               (120))
     ((GlobalDiscoveryError)         (121)) // Single peer discovery interrupts discovery session.
+    ((UnknownClockClusterTag)       (122))
+    ((ClockClusterTagMismatch)      (123))
 );
 
 DEFINE_ENUM(EMessageFormat,

+ 1 - 0
yt/yt_proto/yt/client/transaction_client/proto/timestamp_service.proto

@@ -11,6 +11,7 @@ message TReqGenerateTimestamps
 message TRspGenerateTimestamps
 {
     required int64 timestamp = 1;
+    optional int32 clock_cluster_tag = 2;
 }
 
 ////////////////////////////////////////////////////////////////////////////////