aboutsummaryrefslogtreecommitdiffstats
path: root/yt/cpp/mapreduce/client
diff options
context:
space:
mode:
authorermolovd <ermolovd@yandex-team.com>2024-11-08 10:09:59 +0300
committerermolovd <ermolovd@yandex-team.com>2024-11-08 10:19:56 +0300
commit726d467e9898a4afca4523f30dd420cd2a85b43c (patch)
treec8566ca77ff317dba58313934adfbbfb0306578e /yt/cpp/mapreduce/client
parenta784a2f943d6e15caa6241e2e96d80aac6dbf375 (diff)
downloadydb-726d467e9898a4afca4523f30dd420cd2a85b43c.tar.gz
YT-23262: initialize client with JoblessInitialize if user didn't
commit_hash:439622e771e7b7010609aa9974e9b82dcb0163ca
Diffstat (limited to 'yt/cpp/mapreduce/client')
-rw-r--r--yt/cpp/mapreduce/client/client.cpp10
-rw-r--r--yt/cpp/mapreduce/client/init.cpp14
-rw-r--r--yt/cpp/mapreduce/client/init.h8
3 files changed, 25 insertions, 7 deletions
diff --git a/yt/cpp/mapreduce/client/client.cpp b/yt/cpp/mapreduce/client/client.cpp
index 9dab176bde..43e3864ae2 100644
--- a/yt/cpp/mapreduce/client/client.cpp
+++ b/yt/cpp/mapreduce/client/client.cpp
@@ -6,6 +6,7 @@
#include "file_reader.h"
#include "file_writer.h"
#include "format_hints.h"
+#include "init.h"
#include "lock.h"
#include "operation.h"
#include "retry_transaction.h"
@@ -1433,7 +1434,10 @@ TClientPtr CreateClientImpl(
if (!retryConfigProvider) {
retryConfigProvider = CreateDefaultRetryConfigProvider();
}
- return new NDetail::TClient(context, globalTxId, CreateDefaultClientRetryPolicy(retryConfigProvider, context.Config));
+
+ EnsureInitialized();
+
+ return new TClient(context, globalTxId, CreateDefaultClientRetryPolicy(retryConfigProvider, context.Config));
}
////////////////////////////////////////////////////////////////////////////////
@@ -1442,6 +1446,7 @@ TClientPtr CreateClientImpl(
////////////////////////////////////////////////////////////////////////////////
+
IClientPtr CreateClient(
const TString& serverName,
const TCreateClientOptions& options)
@@ -1455,10 +1460,9 @@ IClientPtr CreateClientFromEnv(const TCreateClientOptions& options)
if (!serverName) {
ythrow yexception() << "YT_PROXY is not set";
}
- return NDetail::CreateClientImpl(serverName, options);
+ return CreateClient(serverName, options);
}
-
////////////////////////////////////////////////////////////////////////////////
} // namespace NYT
diff --git a/yt/cpp/mapreduce/client/init.cpp b/yt/cpp/mapreduce/client/init.cpp
index 44d685d779..ea1f7a5561 100644
--- a/yt/cpp/mapreduce/client/init.cpp
+++ b/yt/cpp/mapreduce/client/init.cpp
@@ -266,12 +266,23 @@ void ExecJob(int argc, const char** argv, const TInitializeOptions& options)
Y_UNREACHABLE();
}
+void EnsureInitialized()
+{
+ if (GetInitStatus() == EInitStatus::NotInitialized) {
+ JoblessInitialize();
+ }
+}
+
} // namespace NDetail
////////////////////////////////////////////////////////////////////////////////
+static TMutex InitializeLock;
+
void JoblessInitialize(const TInitializeOptions& options)
{
+ auto g = Guard(InitializeLock);
+
static const char* fakeArgv[] = {"unknown..."};
NDetail::CommonInitialize(1, fakeArgv);
NDetail::NonJobInitialize(options);
@@ -280,12 +291,15 @@ void JoblessInitialize(const TInitializeOptions& options)
void Initialize(int argc, const char* argv[], const TInitializeOptions& options)
{
+ auto g = Guard(InitializeLock);
+
NDetail::CommonInitialize(argc, argv);
NDetail::ElevateInitStatus(NDetail::EInitStatus::FullInitialization);
const bool isInsideJob = !GetEnv("YT_JOB_ID").empty();
if (isInsideJob) {
+ g.Release();
NDetail::ExecJob(argc, argv, options);
} else {
NDetail::NonJobInitialize(options);
diff --git a/yt/cpp/mapreduce/client/init.h b/yt/cpp/mapreduce/client/init.h
index af2fc80e55..ee879d1a99 100644
--- a/yt/cpp/mapreduce/client/init.h
+++ b/yt/cpp/mapreduce/client/init.h
@@ -2,8 +2,7 @@
#include <yt/cpp/mapreduce/interface/init.h>
-namespace NYT {
-namespace NDetail {
+namespace NYT::NDetail {
////////////////////////////////////////////////////////////////////////////////
@@ -16,7 +15,8 @@ enum class EInitStatus : int
EInitStatus& GetInitStatus();
+void EnsureInitialized();
+
////////////////////////////////////////////////////////////////////////////////
-} // namespace NDetail
-} // namespace NYT
+} // namespace NYT::NDetail