Skip to content

Commit 70cc46e

Browse files
committed
Add CleanupEC2MetadataClient() (ydb-platform#15266)
1 parent 0a25dc5 commit 70cc46e

File tree

21 files changed

+93
-84
lines changed

21 files changed

+93
-84
lines changed

ydb/core/driver_lib/run/kikimr_services_initializers.cpp

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@
155155
#include <ydb/core/tx/long_tx_service/public/events.h>
156156
#include <ydb/core/tx/long_tx_service/long_tx_service.h>
157157

158+
#include <ydb/core/util/aws.h>
158159
#include <ydb/core/util/failure_injection.h>
159160
#include <ydb/core/util/memory_tracker.h>
160161
#include <ydb/core/util/sig.h>
@@ -244,32 +245,17 @@
244245

245246
#include <util/system/hostname.h>
246247

247-
#ifndef KIKIMR_DISABLE_S3_OPS
248-
#include <aws/core/Aws.h>
249-
#endif
250-
251-
namespace {
248+
namespace NKikimr::NKikimrServicesInitializers {
252249

253-
#ifndef KIKIMR_DISABLE_S3_OPS
254250
struct TAwsApiGuard {
255251
TAwsApiGuard() {
256-
Aws::InitAPI(Options);
252+
InitAwsAPI();
257253
}
258254

259255
~TAwsApiGuard() {
260-
Aws::ShutdownAPI(Options);
256+
ShutdownAwsAPI();
261257
}
262-
263-
private:
264-
Aws::SDKOptions Options;
265258
};
266-
#endif
267-
268-
}
269-
270-
namespace NKikimr {
271-
272-
namespace NKikimrServicesInitializers {
273259

274260
ui32 TFederatedQueryInitializer::IcPort = 0;
275261

@@ -2884,7 +2870,6 @@ void TGraphServiceInitializer::InitializeServices(NActors::TActorSystemSetup* se
28842870
TActorSetupCmd(NGraph::CreateGraphService(appData->TenantName), TMailboxType::HTSwap, appData->UserPoolId));
28852871
}
28862872

2887-
#ifndef KIKIMR_DISABLE_S3_OPS
28882873
TAwsApiInitializer::TAwsApiInitializer(IGlobalObjectStorage& globalObjects)
28892874
: GlobalObjects(globalObjects)
28902875
{
@@ -2895,7 +2880,5 @@ void TAwsApiInitializer::InitializeServices(NActors::TActorSystemSetup* setup, c
28952880
Y_UNUSED(appData);
28962881
GlobalObjects.AddGlobalObject(std::make_shared<TAwsApiGuard>());
28972882
}
2898-
#endif
28992883

2900-
} // namespace NKikimrServicesInitializers
2901-
} // namespace NKikimr
2884+
} // namespace NKikimr::NKikimrServicesInitializers

ydb/core/driver_lib/run/kikimr_services_initializers.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,6 @@ class TGraphServiceInitializer : public IKikimrServicesInitializer {
618618
void InitializeServices(NActors::TActorSystemSetup* setup, const NKikimr::TAppData* appData) override;
619619
};
620620

621-
#ifndef KIKIMR_DISABLE_S3_OPS
622621
class TAwsApiInitializer : public IServiceInitializer {
623622
IGlobalObjectStorage& GlobalObjects;
624623

@@ -627,7 +626,6 @@ class TAwsApiInitializer : public IServiceInitializer {
627626

628627
void InitializeServices(NActors::TActorSystemSetup* setup, const NKikimr::TAppData* appData) override;
629628
};
630-
#endif
631629

632630
} // namespace NKikimrServicesInitializers
633631
} // namespace NKikimr

ydb/core/driver_lib/run/run.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,11 +1685,9 @@ TIntrusivePtr<TServiceInitializersList> TKikimrRunner::CreateServiceInitializers
16851685
sil->AddServiceInitializer(new TGraphServiceInitializer(runConfig));
16861686
}
16871687

1688-
#ifndef KIKIMR_DISABLE_S3_OPS
16891688
if (serviceMask.EnableAwsService) {
16901689
sil->AddServiceInitializer(new TAwsApiInitializer(*this));
16911690
}
1692-
#endif
16931691

16941692
return sil;
16951693
}

ydb/core/driver_lib/run/ya.make

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
LIBRARY(run)
22

3-
IF (OS_WINDOWS)
4-
CFLAGS(
5-
-DKIKIMR_DISABLE_S3_OPS
6-
)
7-
ELSE()
8-
PEERDIR(
9-
contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core
10-
)
11-
ENDIF()
12-
133
SRCS(
144
auto_config_initializer.cpp
155
config.cpp

ydb/core/tx/columnshard/ut_schema/ut_columnshard_schema.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <ydb/core/tx/columnshard/blobs_reader/actor.h>
1212
#include <ydb/core/tx/columnshard/test_helper/controllers.h>
1313
#include <ydb/core/tx/columnshard/engines/changes/ttl.h>
14+
#include <ydb/core/util/aws.h>
1415
#include <ydb/public/sdk/cpp/client/ydb_table/table.h>
1516

1617
#include <ydb/library/actors/core/av_bootstrapped.h>
@@ -19,8 +20,6 @@
1920
#include <library/cpp/deprecated/atomic/atomic.h>
2021
#include <library/cpp/testing/hook/hook.h>
2122

22-
#include <aws/core/Aws.h>
23-
2423
namespace NKikimr {
2524

2625
using namespace NTxUT;
@@ -35,14 +34,12 @@ enum class EInitialEviction {
3534

3635
namespace {
3736

38-
Aws::SDKOptions Options;
39-
4037
Y_TEST_HOOK_BEFORE_RUN(InitAwsAPI) {
41-
Aws::InitAPI(Options);
38+
NKikimr::InitAwsAPI();
4239
}
4340

4441
Y_TEST_HOOK_AFTER_RUN(ShutdownAwsAPI) {
45-
Aws::ShutdownAPI(Options);
42+
NKikimr::ShutdownAwsAPI();
4643
}
4744

4845
static const std::vector<NArrow::NTest::TTestColumn> testYdbSchema = TTestSchema::YdbSchema();

ydb/core/tx/columnshard/ut_schema/ya.make

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ PEERDIR(
1818
library/cpp/getopt
1919
library/cpp/regex/pcre
2020
library/cpp/svnversion
21-
contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core
2221
ydb/core/testlib/default
2322
ydb/core/tx/columnshard/hooks/abstract
2423
ydb/core/tx/columnshard/hooks/testing
2524
ydb/core/tx/columnshard/test_helper
2625
ydb/services/metadata
2726
ydb/core/tx
27+
ydb/core/util
2828
ydb/public/lib/yson_value
2929
)
3030

ydb/core/tx/schemeshard/ut_backup/ut_backup.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "ut_helpers/ut_backup_restore_common.h"
22

33
#include <ydb/core/tx/schemeshard/ut_helpers/helpers.h>
4+
#include <ydb/core/util/aws.h>
45
#include <ydb/core/wrappers/ut_helpers/s3_mock.h>
56
#include <ydb/core/wrappers/s3_wrapper.h>
67

@@ -9,21 +10,17 @@
910

1011
#include <library/cpp/testing/hook/hook.h>
1112

12-
#include <aws/core/Aws.h>
13-
1413
using namespace NSchemeShardUT_Private;
1514
using namespace NKikimr::NWrappers::NTestHelpers;
1615

1716
namespace {
1817

19-
Aws::SDKOptions Options;
20-
2118
Y_TEST_HOOK_BEFORE_RUN(InitAwsAPI) {
22-
Aws::InitAPI(Options);
19+
NKikimr::InitAwsAPI();
2320
}
2421

2522
Y_TEST_HOOK_AFTER_RUN(ShutdownAwsAPI) {
26-
Aws::ShutdownAPI(Options);
23+
NKikimr::ShutdownAwsAPI();
2724
}
2825

2926
}

ydb/core/tx/schemeshard/ut_backup/ya.make

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ IF (NOT OS_WINDOWS)
2020
library/cpp/getopt
2121
library/cpp/regex/pcre
2222
library/cpp/svnversion
23-
contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core
2423
ydb/core/testlib/default
2524
ydb/core/tx
2625
ydb/core/tx/schemeshard/ut_helpers
26+
ydb/core/util
2727
ydb/core/wrappers/ut_helpers
2828
ydb/library/yql/public/udf/service/exception_policy
2929
)

ydb/core/tx/schemeshard/ut_export/ut_export.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <ydb/core/tx/schemeshard/ut_helpers/auditlog_helpers.h>
44
#include <ydb/core/tx/schemeshard/schemeshard_billing_helpers.h>
55
#include <ydb/core/tx/datashard/datashard.h>
6+
#include <ydb/core/util/aws.h>
67
#include <ydb/core/wrappers/ut_helpers/s3_mock.h>
78
#include <ydb/core/wrappers/s3_wrapper.h>
89
#include <ydb/core/metering/metering.h>
@@ -15,21 +16,17 @@
1516

1617
#include <library/cpp/testing/hook/hook.h>
1718

18-
#include <aws/core/Aws.h>
19-
2019
using namespace NSchemeShardUT_Private;
2120
using namespace NKikimr::NWrappers::NTestHelpers;
2221

2322
namespace {
2423

25-
Aws::SDKOptions Options;
26-
2724
Y_TEST_HOOK_BEFORE_RUN(InitAwsAPI) {
28-
Aws::InitAPI(Options);
25+
NKikimr::InitAwsAPI();
2926
}
3027

3128
Y_TEST_HOOK_AFTER_RUN(ShutdownAwsAPI) {
32-
Aws::ShutdownAPI(Options);
29+
NKikimr::ShutdownAwsAPI();
3330
}
3431

3532
void Run(TTestBasicRuntime& runtime, TTestEnv& env, const TVector<TString>& tables, const TString& request,

ydb/core/tx/schemeshard/ut_export/ya.make

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ IF (NOT OS_WINDOWS)
2020
library/cpp/getopt
2121
library/cpp/regex/pcre
2222
library/cpp/svnversion
23-
contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core
2423
ydb/core/testlib/default
2524
ydb/core/tx
2625
ydb/core/tx/schemeshard/ut_helpers
26+
ydb/core/util
2727
ydb/core/wrappers/ut_helpers
2828
ydb/library/yql/public/udf/service/exception_policy
2929
)

ydb/core/tx/schemeshard/ut_export_reboots_s3/ut_export_reboots_s3.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
#include <ydb/core/tx/schemeshard/ut_helpers/export_reboots_common.h>
22
#include <ydb/core/tx/schemeshard/ut_helpers/helpers.h>
3+
#include <ydb/core/util/aws.h>
34
#include <ydb/core/wrappers/ut_helpers/s3_mock.h>
45

56
#include <util/string/printf.h>
67

78
#include <library/cpp/testing/hook/hook.h>
89

9-
#include <aws/core/Aws.h>
10-
1110
using namespace NSchemeShardUT_Private;
1211
using namespace NSchemeShardUT_Private::NExportReboots;
1312
using namespace NKikimr::NWrappers::NTestHelpers;
1413

1514
namespace {
1615

17-
Aws::SDKOptions Options;
18-
1916
Y_TEST_HOOK_BEFORE_RUN(InitAwsAPI) {
20-
Aws::InitAPI(Options);
17+
NKikimr::InitAwsAPI();
2118
}
2219

2320
Y_TEST_HOOK_AFTER_RUN(ShutdownAwsAPI) {
24-
Aws::ShutdownAPI(Options);
21+
NKikimr::ShutdownAwsAPI();
2522
}
2623

2724
}

ydb/core/tx/schemeshard/ut_export_reboots_s3/ya.make

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ PEERDIR(
1919
library/cpp/getopt
2020
library/cpp/regex/pcre
2121
library/cpp/svnversion
22-
contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core
2322
ydb/core/testlib/default
2423
ydb/core/tx
2524
ydb/core/tx/schemeshard/ut_helpers
25+
ydb/core/util
2626
ydb/core/wrappers/ut_helpers
2727
ydb/library/yql/public/udf/service/exception_policy
2828
)

ydb/core/tx/schemeshard/ut_restore/ut_restore.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <ydb/core/tx/schemeshard/schemeshard_private.h>
1212
#include <ydb/core/tx/schemeshard/schemeshard_billing_helpers.h>
1313
#include <ydb/core/tx/datashard/datashard.h>
14+
#include <ydb/core/util/aws.h>
1415
#include <ydb/core/wrappers/ut_helpers/s3_mock.h>
1516
#include <ydb/core/metering/metering.h>
1617
#include <ydb/core/ydb_convert/table_description.h>
@@ -22,7 +23,6 @@
2223

2324
#include <ydb/public/api/protos/ydb_import.pb.h>
2425

25-
#include <aws/core/Aws.h>
2626
#include <contrib/libs/zstd/include/zstd.h>
2727
#include <library/cpp/string_utils/quote/quote.h>
2828
#include <library/cpp/testing/hook/hook.h>
@@ -41,14 +41,12 @@ using namespace NKikimr::NWrappers::NTestHelpers;
4141

4242
namespace {
4343

44-
Aws::SDKOptions Options;
45-
4644
Y_TEST_HOOK_BEFORE_RUN(InitAwsAPI) {
47-
Aws::InitAPI(Options);
45+
NKikimr::InitAwsAPI();
4846
}
4947

5048
Y_TEST_HOOK_AFTER_RUN(ShutdownAwsAPI) {
51-
Aws::ShutdownAPI(Options);
49+
NKikimr::ShutdownAwsAPI();
5250
}
5351

5452
const TString EmptyYsonStr = R"([[[[];%false]]])";

ydb/core/tx/schemeshard/ut_restore/ya.make

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ ELSE()
1414
ENDIF()
1515

1616
PEERDIR(
17-
contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core
1817
contrib/libs/double-conversion
1918
library/cpp/string_utils/quote
2019
ydb/core/kqp/ut/common
2120
ydb/core/tx/schemeshard/ut_helpers
21+
ydb/core/util
2222
ydb/core/wrappers/ut_helpers
2323
ydb/core/ydb_convert
2424
ydb/library/yql/sql/pg

ydb/core/util/aws.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include "aws.h"
2+
3+
#ifndef KIKIMR_DISABLE_S3_OPS
4+
5+
#include <contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/include/aws/core/internal/AWSHttpResourceClient.h>
6+
#include <contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/include/aws/core/Aws.h>
7+
#include <contrib/libs/curl/include/curl/curl.h>
8+
9+
Aws::SDKOptions MakeDefaultOptions() {
10+
static Aws::SDKOptions options;
11+
options.httpOptions.initAndCleanupCurl = false;
12+
return options;
13+
}
14+
15+
namespace NKikimr {
16+
17+
void InitAwsAPI() {
18+
curl_global_init(CURL_GLOBAL_ALL);
19+
Aws::InitAPI(MakeDefaultOptions());
20+
Aws::Internal::CleanupEC2MetadataClient(); // speeds up config construction
21+
}
22+
23+
void ShutdownAwsAPI() {
24+
Aws::ShutdownAPI(MakeDefaultOptions());
25+
curl_global_cleanup();
26+
}
27+
28+
} // NKikimr
29+
30+
#else
31+
32+
namespace NKikimr {
33+
34+
void InitAwsAPI() {}
35+
void ShutdownAwsAPI() {}
36+
37+
} // NKikimr
38+
39+
#endif

ydb/core/util/aws.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#pragma once
2+
3+
namespace NKikimr {
4+
5+
void InitAwsAPI();
6+
void ShutdownAwsAPI();
7+
8+
}

0 commit comments

Comments
 (0)