Skip to content

Commit dbc58e8

Browse files
author
ermolovd
committed
YT-21081: fix temp tables for case when client is created with GlobalTx
commit_hash:c49256f38de62e8d05359c16a70ea6b88220a9ba
1 parent 209a37d commit dbc58e8

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed

yt/cpp/mapreduce/client/client.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -936,11 +936,6 @@ TBatchRequestPtr TClientBase::CreateBatchRequest()
936936
return MakeIntrusive<TBatchRequest>(TransactionId_, GetParentClientImpl());
937937
}
938938

939-
IClientPtr TClientBase::GetParentClient()
940-
{
941-
return GetParentClientImpl();
942-
}
943-
944939
IRawClientPtr TClientBase::GetRawClient() const
945940
{
946941
return RawClient_;
@@ -1056,6 +1051,11 @@ ITransactionPingerPtr TTransaction::GetTransactionPinger()
10561051
return TransactionPinger_;
10571052
}
10581053

1054+
IClientPtr TTransaction::GetParentClient(bool ignoreGlobalTx)
1055+
{
1056+
return GetParentClientImpl()->GetParentClient(ignoreGlobalTx);
1057+
}
1058+
10591059
TClientPtr TTransaction::GetParentClientImpl()
10601060
{
10611061
return ParentClient_;
@@ -1489,6 +1489,20 @@ TClientPtr TClient::GetParentClientImpl()
14891489
return this;
14901490
}
14911491

1492+
IClientPtr TClient::GetParentClient(bool ignoreGlobalTx)
1493+
{
1494+
if (!TransactionId_.IsEmpty() && ignoreGlobalTx) {
1495+
return MakeIntrusive<TClient>(
1496+
RawClient_,
1497+
Context_,
1498+
TTransactionId(),
1499+
ClientRetryPolicy_
1500+
);
1501+
} else {
1502+
return this;
1503+
}
1504+
}
1505+
14921506
void TClient::CheckShutdown() const
14931507
{
14941508
if (Shutdown_) {

yt/cpp/mapreduce/client/client.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,6 @@ class TClientBase
222222

223223
TBatchRequestPtr CreateBatchRequest() override;
224224

225-
IClientPtr GetParentClient() override;
226-
227225
IRawClientPtr GetRawClient() const;
228226

229227
const TClientContext& GetContext() const;
@@ -328,6 +326,8 @@ class TTransaction
328326

329327
ITransactionPingerPtr GetTransactionPinger() override;
330328

329+
IClientPtr GetParentClient(bool ignoreGlobalTx) override;
330+
331331
protected:
332332
TClientPtr GetParentClientImpl() override;
333333

@@ -488,6 +488,8 @@ class TClient
488488

489489
ITransactionPingerPtr GetTransactionPinger() override;
490490

491+
IClientPtr GetParentClient(bool ignoreGlobalTx) override;
492+
491493
// Helper methods
492494
TYtPoller& GetYtPoller();
493495

yt/cpp/mapreduce/interface/client.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,15 @@ class IClientBase
165165
/// @see [YT doc](https://ytsaurus.tech/docs/en/api/commands.html#execute_batch)
166166
virtual TBatchRequestPtr CreateBatchRequest() = 0;
167167

168-
/// @brief Get root client outside of all transactions.
169-
virtual IClientPtr GetParentClient() = 0;
168+
///
169+
/// @brief Get root client.
170+
///
171+
/// @param ignoreGlobalTx root client could be created already attached to some global transaction, @ref NYT::TConfig::GlobalTx.
172+
/// when ignoreGlobalTx = false original client (attached to GlobalTx) is returned
173+
/// when ignoreGlobalTx = true, returned client is not attached to any transaction.
174+
///
175+
/// TODO: rename to GetRootClient()
176+
virtual IClientPtr GetParentClient(bool ignoreGlobalTx = false) = 0;
170177
};
171178

172179
////////////////////////////////////////////////////////////////////////////////

yt/cpp/mapreduce/interface/temp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ TYPath CreateTempTable(
133133
// we retry attempt if it was failed with path resolution error.
134134
const int maxAttempts = 3;
135135
for (int i = 0; i < maxAttempts; ++i) {
136-
client->GetParentClient()->Create(resultDirectory, NT_MAP, TCreateOptions().Recursive(true).IgnoreExisting(true));
136+
client->GetParentClient(/*ignoreGlobalTx=*/ true)->Create(resultDirectory, NT_MAP, TCreateOptions().Recursive(true).IgnoreExisting(true));
137137

138138
try {
139139
client->Create(result, NT_TABLE, options);

0 commit comments

Comments
 (0)