aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgritukan <gritukan@yandex-team.com>2023-08-14 00:45:32 +0300
committergritukan <gritukan@yandex-team.com>2023-08-14 01:53:49 +0300
commit05cd5c0fa92fc45a1b631d884667824fa7ee839d (patch)
tree33beecc9cb51e1f1b2f2e8a4084ad40dc7798858
parent4d8efea2976baa47be1d1370b67fd58607e27c26 (diff)
downloadydb-05cd5c0fa92fc45a1b631d884667824fa7ee839d.tar.gz
YT-19686: Make some of the YPath helpers work with vanilla protobuf
-rw-r--r--yt/yt/core/ytree/ypath_client.cpp20
-rw-r--r--yt/yt/core/ytree/ypath_client.h15
2 files changed, 35 insertions, 0 deletions
diff --git a/yt/yt/core/ytree/ypath_client.cpp b/yt/yt/core/ytree/ypath_client.cpp
index 142834c1d3..ceab65ab79 100644
--- a/yt/yt/core/ytree/ypath_client.cpp
+++ b/yt/yt/core/ytree/ypath_client.cpp
@@ -238,6 +238,24 @@ bool TYPathResponse::TryDeserializeBody(TRef /*data*/, std::optional<NCompressio
////////////////////////////////////////////////////////////////////////////////
+#ifdef YT_USE_VANILLA_PROTOBUF
+
+TYPath GetRequestTargetYPath(const NRpc::NProto::TRequestHeader& header)
+{
+ const auto& ypathExt = header.GetExtension(NProto::TYPathHeaderExt::ypath_header_ext);
+ return FromProto<TYPath>(ypathExt.target_path());
+}
+
+TYPath GetOriginalRequestTargetYPath(const NRpc::NProto::TRequestHeader& header)
+{
+ const auto& ypathExt = header.GetExtension(NProto::TYPathHeaderExt::ypath_header_ext);
+ return ypathExt.has_original_target_path()
+ ? FromProto<TYPath>(ypathExt.original_target_path())
+ : FromProto<TYPath>(ypathExt.target_path());
+}
+
+#else
+
const TYPath& GetRequestTargetYPath(const NRpc::NProto::TRequestHeader& header)
{
const auto& ypathExt = header.GetExtension(NProto::TYPathHeaderExt::ypath_header_ext);
@@ -250,6 +268,8 @@ const TYPath& GetOriginalRequestTargetYPath(const NRpc::NProto::TRequestHeader&
return ypathExt.has_original_target_path() ? ypathExt.original_target_path() : ypathExt.target_path();
}
+#endif
+
void SetRequestTargetYPath(NRpc::NProto::TRequestHeader* header, TYPath path)
{
auto* ypathExt = header->MutableExtension(NProto::TYPathHeaderExt::ypath_header_ext);
diff --git a/yt/yt/core/ytree/ypath_client.h b/yt/yt/core/ytree/ypath_client.h
index fbe3d40364..a29633d67b 100644
--- a/yt/yt/core/ytree/ypath_client.h
+++ b/yt/yt/core/ytree/ypath_client.h
@@ -188,8 +188,23 @@ protected:
////////////////////////////////////////////////////////////////////////////////
+// TODO(gritukan): It's not easy to find a proper return type for these functions
+// that is suitable both for vanilla and patched protobufs. In an ideal world,
+// it would be TYPathBuf, but for now it breaks the advantages for CoW of the
+// TString. Rethink it if and when YT will try to use std::string or non-CoW
+// TString everywhere.
+#ifdef YT_USE_VANILLA_PROTOBUF
+
+TYPath GetRequestTargetYPath(const NRpc::NProto::TRequestHeader& header);
+TYPath GetOriginalRequestTargetYPath(const NRpc::NProto::TRequestHeader& header);
+
+#else
+
const TYPath& GetRequestTargetYPath(const NRpc::NProto::TRequestHeader& header);
const TYPath& GetOriginalRequestTargetYPath(const NRpc::NProto::TRequestHeader& header);
+
+#endif
+
void SetRequestTargetYPath(NRpc::NProto::TRequestHeader* header, TYPath path);
bool IsRequestMutating(const NRpc::NProto::TRequestHeader& header);