Skip to content

Commit 5d3c7d9

Browse files
committed
Add CleanupEC2MetadataClient() (ydb-platform#15266)
1 parent c7df996 commit 5d3c7d9

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
@@ -157,6 +157,7 @@
157157
#include <ydb/core/tx/long_tx_service/public/events.h>
158158
#include <ydb/core/tx/long_tx_service/long_tx_service.h>
159159

160+
#include <ydb/core/util/aws.h>
160161
#include <ydb/core/util/failure_injection.h>
161162
#include <ydb/core/util/memory_tracker.h>
162163
#include <ydb/core/util/sig.h>
@@ -248,32 +249,17 @@
248249

249250
#include <util/system/hostname.h>
250251

251-
#ifndef KIKIMR_DISABLE_S3_OPS
252-
#include <aws/core/Aws.h>
253-
#endif
254-
255-
namespace {
252+
namespace NKikimr::NKikimrServicesInitializers {
256253

257-
#ifndef KIKIMR_DISABLE_S3_OPS
258254
struct TAwsApiGuard {
259255
TAwsApiGuard() {
260-
Aws::InitAPI(Options);
256+
InitAwsAPI();
261257
}
262258

263259
~TAwsApiGuard() {
264-
Aws::ShutdownAPI(Options);
260+
ShutdownAwsAPI();
265261
}
266-
267-
private:
268-
Aws::SDKOptions Options;
269262
};
270-
#endif
271-
272-
}
273-
274-
namespace NKikimr {
275-
276-
namespace NKikimrServicesInitializers {
277263

278264
ui32 TFederatedQueryInitializer::IcPort = 0;
279265

@@ -2832,7 +2818,6 @@ void TGraphServiceInitializer::InitializeServices(NActors::TActorSystemSetup* se
28322818
TActorSetupCmd(NGraph::CreateGraphService(appData->TenantName), TMailboxType::HTSwap, appData->UserPoolId));
28332819
}
28342820

2835-
#ifndef KIKIMR_DISABLE_S3_OPS
28362821
TAwsApiInitializer::TAwsApiInitializer(IGlobalObjectStorage& globalObjects)
28372822
: GlobalObjects(globalObjects)
28382823
{
@@ -2843,7 +2828,5 @@ void TAwsApiInitializer::InitializeServices(NActors::TActorSystemSetup* setup, c
28432828
Y_UNUSED(appData);
28442829
GlobalObjects.AddGlobalObject(std::make_shared<TAwsApiGuard>());
28452830
}
2846-
#endif
28472831

2848-
} // namespace NKikimrServicesInitializers
2849-
} // namespace NKikimr
2832+
} // 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
@@ -631,7 +631,6 @@ class TGraphServiceInitializer : public IKikimrServicesInitializer {
631631
void InitializeServices(NActors::TActorSystemSetup* setup, const NKikimr::TAppData* appData) override;
632632
};
633633

634-
#ifndef KIKIMR_DISABLE_S3_OPS
635634
class TAwsApiInitializer : public IServiceInitializer {
636635
IGlobalObjectStorage& GlobalObjects;
637636

@@ -640,7 +639,6 @@ class TAwsApiInitializer : public IServiceInitializer {
640639

641640
void InitializeServices(NActors::TActorSystemSetup* setup, const NKikimr::TAppData* appData) override;
642641
};
643-
#endif
644642

645643
} // namespace NKikimrServicesInitializers
646644
} // namespace NKikimr

ydb/core/driver_lib/run/run.cpp

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

1748-
#ifndef KIKIMR_DISABLE_S3_OPS
17491748
if (serviceMask.EnableAwsService) {
17501749
sil->AddServiceInitializer(new TAwsApiInitializer(*this));
17511750
}
1752-
#endif
17531751

17541752
return sil;
17551753
}

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
ADDINCL(
144
ydb/public/sdk/cpp
155
)

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-cpp-sdk/client/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
@@ -16,13 +16,13 @@ PEERDIR(
1616
library/cpp/getopt
1717
library/cpp/regex/pcre
1818
library/cpp/svnversion
19-
contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core
2019
ydb/core/testlib/default
2120
ydb/core/tx/columnshard/hooks/abstract
2221
ydb/core/tx/columnshard/hooks/testing
2322
ydb/core/tx/columnshard/test_helper
2423
ydb/services/metadata
2524
ydb/core/tx
25+
ydb/core/util
2626
ydb/public/lib/yson_value
2727
)
2828

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
@@ -18,10 +18,10 @@ IF (NOT OS_WINDOWS)
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
2423
ydb/core/tx/schemeshard/ut_helpers
24+
ydb/core/util
2525
ydb/core/wrappers/ut_helpers
2626
yql/essentials/public/udf/service/exception_policy
2727
)

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <ydb/core/tx/schemeshard/schemeshard_billing_helpers.h>
77
#include <ydb/core/tx/schemeshard/ut_helpers/auditlog_helpers.h>
88
#include <ydb/core/tx/schemeshard/ut_helpers/helpers.h>
9+
#include <ydb/core/util/aws.h>
910
#include <ydb/core/wrappers/s3_wrapper.h>
1011
#include <ydb/core/wrappers/ut_helpers/s3_mock.h>
1112
#include <ydb/public/api/protos/ydb_export.pb.h>
@@ -17,23 +18,19 @@
1718

1819
#include <library/cpp/testing/hook/hook.h>
1920

20-
#include <aws/core/Aws.h>
21-
2221
using namespace NSchemeShardUT_Private;
2322
using namespace NKikimr::NWrappers::NTestHelpers;
2423

2524
using TTablesWithAttrs = TVector<std::pair<TString, TMap<TString, TString>>>;
2625

2726
namespace {
2827

29-
Aws::SDKOptions Options;
30-
3128
Y_TEST_HOOK_BEFORE_RUN(InitAwsAPI) {
32-
Aws::InitAPI(Options);
29+
NKikimr::InitAwsAPI();
3330
}
3431

3532
Y_TEST_HOOK_AFTER_RUN(ShutdownAwsAPI) {
36-
Aws::ShutdownAPI(Options);
33+
NKikimr::ShutdownAwsAPI();
3734
}
3835

3936
void Run(TTestBasicRuntime& runtime, TTestEnv& env, const std::variant<TVector<TString>, TTablesWithAttrs>& tablesVar, 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
@@ -18,10 +18,10 @@ IF (NOT OS_WINDOWS)
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
2423
ydb/core/tx/schemeshard/ut_helpers
24+
ydb/core/util
2525
ydb/core/wrappers/ut_helpers
2626
yql/essentials/public/udf/service/exception_policy
2727
)

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,28 +1,25 @@
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 NKikimrSchemeOp;
1211
using namespace NKikimr::NWrappers::NTestHelpers;
1312
using namespace NSchemeShardUT_Private;
1413
using namespace NSchemeShardUT_Private::NExportReboots;
1514

1615
namespace {
1716

18-
Aws::SDKOptions Options;
19-
2017
Y_TEST_HOOK_BEFORE_RUN(InitAwsAPI) {
21-
Aws::InitAPI(Options);
18+
NKikimr::InitAwsAPI();
2219
}
2320

2421
Y_TEST_HOOK_AFTER_RUN(ShutdownAwsAPI) {
25-
Aws::ShutdownAPI(Options);
22+
NKikimr::ShutdownAwsAPI();
2623
}
2724

2825
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ PEERDIR(
1717
library/cpp/getopt
1818
library/cpp/regex/pcre
1919
library/cpp/svnversion
20-
contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core
2120
ydb/core/testlib/default
2221
ydb/core/tx
2322
ydb/core/tx/schemeshard/ut_helpers
23+
ydb/core/util
2424
ydb/core/wrappers/ut_helpers
2525
yql/essentials/public/udf/service/exception_policy
2626
)

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <ydb/core/tx/schemeshard/schemeshard_private.h>
1313
#include <ydb/core/tx/schemeshard/ut_helpers/auditlog_helpers.h>
1414
#include <ydb/core/tx/schemeshard/ut_helpers/helpers.h>
15+
#include <ydb/core/util/aws.h>
1516
#include <ydb/core/wrappers/ut_helpers/s3_mock.h>
1617
#include <ydb/core/ydb_convert/table_description.h>
1718

@@ -21,7 +22,6 @@
2122

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

24-
#include <aws/core/Aws.h>
2525
#include <contrib/libs/double-conversion/double-conversion/ieee.h>
2626
#include <contrib/libs/zstd/include/zstd.h>
2727
#include <library/cpp/string_utils/quote/quote.h>
@@ -44,14 +44,12 @@ using namespace NSchemeShardUT_Private;
4444

4545
namespace {
4646

47-
Aws::SDKOptions Options;
48-
4947
Y_TEST_HOOK_BEFORE_RUN(InitAwsAPI) {
50-
Aws::InitAPI(Options);
48+
NKikimr::InitAwsAPI();
5149
}
5250

5351
Y_TEST_HOOK_AFTER_RUN(ShutdownAwsAPI) {
54-
Aws::ShutdownAPI(Options);
52+
NKikimr::ShutdownAwsAPI();
5553
}
5654

5755
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
@@ -12,11 +12,11 @@ ELSE()
1212
ENDIF()
1313

1414
PEERDIR(
15-
contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core
1615
contrib/libs/double-conversion
1716
library/cpp/string_utils/quote
1817
ydb/core/kqp/ut/common
1918
ydb/core/tx/schemeshard/ut_helpers
19+
ydb/core/util
2020
ydb/core/wrappers/ut_helpers
2121
ydb/core/ydb_convert
2222
yql/essentials/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)