aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorermolovd <ermolovd@yandex-team.com>2025-02-19 12:57:38 +0300
committerermolovd <ermolovd@yandex-team.com>2025-02-19 13:19:53 +0300
commitdbc58e8a3b624feb7bccd730530e520da549e859 (patch)
treebece6558f94e28a8d95cce5b413c2e39c37a28d0
parent209a37d035f1d8ea98e913ccbc07762ec479eab2 (diff)
downloadydb-dbc58e8a3b624feb7bccd730530e520da549e859.tar.gz
YT-21081: fix temp tables for case when client is created with GlobalTx
commit_hash:c49256f38de62e8d05359c16a70ea6b88220a9ba
-rw-r--r--yt/cpp/mapreduce/client/client.cpp24
-rw-r--r--yt/cpp/mapreduce/client/client.h6
-rw-r--r--yt/cpp/mapreduce/interface/client.h11
-rw-r--r--yt/cpp/mapreduce/interface/temp.cpp2
4 files changed, 33 insertions, 10 deletions
diff --git a/yt/cpp/mapreduce/client/client.cpp b/yt/cpp/mapreduce/client/client.cpp
index 004bfaf2d8..6e58903308 100644
--- a/yt/cpp/mapreduce/client/client.cpp
+++ b/yt/cpp/mapreduce/client/client.cpp
@@ -936,11 +936,6 @@ TBatchRequestPtr TClientBase::CreateBatchRequest()
return MakeIntrusive<TBatchRequest>(TransactionId_, GetParentClientImpl());
}
-IClientPtr TClientBase::GetParentClient()
-{
- return GetParentClientImpl();
-}
-
IRawClientPtr TClientBase::GetRawClient() const
{
return RawClient_;
@@ -1056,6 +1051,11 @@ ITransactionPingerPtr TTransaction::GetTransactionPinger()
return TransactionPinger_;
}
+IClientPtr TTransaction::GetParentClient(bool ignoreGlobalTx)
+{
+ return GetParentClientImpl()->GetParentClient(ignoreGlobalTx);
+}
+
TClientPtr TTransaction::GetParentClientImpl()
{
return ParentClient_;
@@ -1489,6 +1489,20 @@ TClientPtr TClient::GetParentClientImpl()
return this;
}
+IClientPtr TClient::GetParentClient(bool ignoreGlobalTx)
+{
+ if (!TransactionId_.IsEmpty() && ignoreGlobalTx) {
+ return MakeIntrusive<TClient>(
+ RawClient_,
+ Context_,
+ TTransactionId(),
+ ClientRetryPolicy_
+ );
+ } else {
+ return this;
+ }
+}
+
void TClient::CheckShutdown() const
{
if (Shutdown_) {
diff --git a/yt/cpp/mapreduce/client/client.h b/yt/cpp/mapreduce/client/client.h
index 769dfe2312..9cd650bd2d 100644
--- a/yt/cpp/mapreduce/client/client.h
+++ b/yt/cpp/mapreduce/client/client.h
@@ -222,8 +222,6 @@ public:
TBatchRequestPtr CreateBatchRequest() override;
- IClientPtr GetParentClient() override;
-
IRawClientPtr GetRawClient() const;
const TClientContext& GetContext() const;
@@ -328,6 +326,8 @@ public:
ITransactionPingerPtr GetTransactionPinger() override;
+ IClientPtr GetParentClient(bool ignoreGlobalTx) override;
+
protected:
TClientPtr GetParentClientImpl() override;
@@ -488,6 +488,8 @@ public:
ITransactionPingerPtr GetTransactionPinger() override;
+ IClientPtr GetParentClient(bool ignoreGlobalTx) override;
+
// Helper methods
TYtPoller& GetYtPoller();
diff --git a/yt/cpp/mapreduce/interface/client.h b/yt/cpp/mapreduce/interface/client.h
index 8270eec55d..3d4bc6ac1b 100644
--- a/yt/cpp/mapreduce/interface/client.h
+++ b/yt/cpp/mapreduce/interface/client.h
@@ -165,8 +165,15 @@ public:
/// @see [YT doc](https://ytsaurus.tech/docs/en/api/commands.html#execute_batch)
virtual TBatchRequestPtr CreateBatchRequest() = 0;
- /// @brief Get root client outside of all transactions.
- virtual IClientPtr GetParentClient() = 0;
+ ///
+ /// @brief Get root client.
+ ///
+ /// @param ignoreGlobalTx root client could be created already attached to some global transaction, @ref NYT::TConfig::GlobalTx.
+ /// when ignoreGlobalTx = false original client (attached to GlobalTx) is returned
+ /// when ignoreGlobalTx = true, returned client is not attached to any transaction.
+ ///
+ /// TODO: rename to GetRootClient()
+ virtual IClientPtr GetParentClient(bool ignoreGlobalTx = false) = 0;
};
////////////////////////////////////////////////////////////////////////////////
diff --git a/yt/cpp/mapreduce/interface/temp.cpp b/yt/cpp/mapreduce/interface/temp.cpp
index 04250d12a6..2a3bf0f0bb 100644
--- a/yt/cpp/mapreduce/interface/temp.cpp
+++ b/yt/cpp/mapreduce/interface/temp.cpp
@@ -133,7 +133,7 @@ TYPath CreateTempTable(
// we retry attempt if it was failed with path resolution error.
const int maxAttempts = 3;
for (int i = 0; i < maxAttempts; ++i) {
- client->GetParentClient()->Create(resultDirectory, NT_MAP, TCreateOptions().Recursive(true).IgnoreExisting(true));
+ client->GetParentClient(/*ignoreGlobalTx=*/ true)->Create(resultDirectory, NT_MAP, TCreateOptions().Recursive(true).IgnoreExisting(true));
try {
client->Create(result, NT_TABLE, options);