Skip to content

Commit

Permalink
Fix memory leak issue with AWS API usage (#6160)
Browse files Browse the repository at this point in the history
  • Loading branch information
jepett0 authored Aug 7, 2024
1 parent cb6f3c8 commit ff0fd33
Show file tree
Hide file tree
Showing 25 changed files with 664 additions and 316 deletions.
30 changes: 30 additions & 0 deletions ydb/core/driver_lib/run/kikimr_services_initializers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,25 @@

#include <util/system/hostname.h>

#include <aws/core/Aws.h>

namespace {

struct TAwsApiGuard {
TAwsApiGuard() {
Aws::InitAPI(Options);
}

~TAwsApiGuard() {
Aws::ShutdownAPI(Options);
}

private:
Aws::SDKOptions Options;
};

}

namespace NKikimr {

namespace NKikimrServicesInitializers {
Expand Down Expand Up @@ -2810,5 +2829,16 @@ void TGraphServiceInitializer::InitializeServices(NActors::TActorSystemSetup* se
TActorSetupCmd(NGraph::CreateGraphService(appData->TenantName), TMailboxType::HTSwap, appData->UserPoolId));
}

TAwsApiInitializer::TAwsApiInitializer(IGlobalObjectStorage& globalObjects)
: GlobalObjects(globalObjects)
{
}

void TAwsApiInitializer::InitializeServices(NActors::TActorSystemSetup* setup, const NKikimr::TAppData* appData) {
Y_UNUSED(setup);
Y_UNUSED(appData);
GlobalObjects.AddGlobalObject(std::make_shared<TAwsApiGuard>());
}

} // namespace NKikimrServicesInitializers
} // namespace NKikimr
9 changes: 9 additions & 0 deletions ydb/core/driver_lib/run/kikimr_services_initializers.h
Original file line number Diff line number Diff line change
Expand Up @@ -619,5 +619,14 @@ class TGraphServiceInitializer : public IKikimrServicesInitializer {
void InitializeServices(NActors::TActorSystemSetup* setup, const NKikimr::TAppData* appData) override;
};

class TAwsApiInitializer : public IServiceInitializer {
IGlobalObjectStorage& GlobalObjects;

public:
TAwsApiInitializer(IGlobalObjectStorage& globalObjects);

void InitializeServices(NActors::TActorSystemSetup* setup, const NKikimr::TAppData* appData) override;
};

} // namespace NKikimrServicesInitializers
} // namespace NKikimr
2 changes: 2 additions & 0 deletions ydb/core/driver_lib/run/run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,8 @@ TIntrusivePtr<TServiceInitializersList> TKikimrRunner::CreateServiceInitializers
sil->AddServiceInitializer(new TGraphServiceInitializer(runConfig));
}

sil->AddServiceInitializer(new TAwsApiInitializer(*this));

return sil;
}

Expand Down
1 change: 1 addition & 0 deletions ydb/core/driver_lib/run/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ SRCS(
)

PEERDIR(
contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core
contrib/libs/protobuf
ydb/library/actors/core
ydb/library/actors/dnsresolver
Expand Down
13 changes: 13 additions & 0 deletions ydb/core/tx/columnshard/ut_schema/ut_columnshard_schema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

#include <util/system/hostname.h>
#include <library/cpp/deprecated/atomic/atomic.h>
#include <library/cpp/testing/hook/hook.h>

#include <aws/core/Aws.h>

namespace NKikimr {

Expand All @@ -32,6 +35,16 @@ enum class EInitialEviction {

namespace {

Aws::SDKOptions Options;

Y_TEST_HOOK_BEFORE_RUN(InitAwsAPI) {
Aws::InitAPI(Options);
}

Y_TEST_HOOK_AFTER_RUN(ShutdownAwsAPI) {
Aws::ShutdownAPI(Options);
}

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

Expand Down
1 change: 1 addition & 0 deletions ydb/core/tx/columnshard/ut_schema/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ PEERDIR(
library/cpp/getopt
library/cpp/regex/pcre
library/cpp/svnversion
contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core
ydb/core/testlib/default
ydb/core/tx/columnshard/hooks/abstract
ydb/core/tx/columnshard/hooks/testing
Expand Down
1 change: 1 addition & 0 deletions ydb/core/tx/datashard/import_s3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <ydb/core/tablet/resource_broker.h>
#include <ydb/core/wrappers/s3_wrapper.h>
#include <ydb/core/wrappers/s3_storage.h>
#include <ydb/core/wrappers/s3_storage_config.h>
#include <ydb/core/io_formats/ydb_dump/csv_ydb_dump.h>
#include <ydb/public/lib/scheme_types/scheme_type_id.h>

Expand Down
18 changes: 18 additions & 0 deletions ydb/core/tx/schemeshard/ut_backup/ut_backup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,27 @@
#include <util/string/cast.h>
#include <util/string/printf.h>

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

#include <aws/core/Aws.h>

using namespace NSchemeShardUT_Private;
using namespace NKikimr::NWrappers::NTestHelpers;

namespace {

Aws::SDKOptions Options;

Y_TEST_HOOK_BEFORE_RUN(InitAwsAPI) {
Aws::InitAPI(Options);
}

Y_TEST_HOOK_AFTER_RUN(ShutdownAwsAPI) {
Aws::ShutdownAPI(Options);
}

}

Y_UNIT_TEST_SUITE(TBackupTests) {
using TFillFn = std::function<void(TTestBasicRuntime&)>;

Expand Down
1 change: 1 addition & 0 deletions ydb/core/tx/schemeshard/ut_backup/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ IF (NOT OS_WINDOWS)
library/cpp/getopt
library/cpp/regex/pcre
library/cpp/svnversion
contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core
ydb/core/testlib/default
ydb/core/tx
ydb/core/tx/schemeshard/ut_helpers
Expand Down
18 changes: 16 additions & 2 deletions ydb/core/tx/schemeshard/ut_export/ut_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,27 @@
#include <util/string/printf.h>
#include <util/system/env.h>

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

#include <aws/core/Aws.h>

using namespace NSchemeShardUT_Private;
using namespace NKikimr::NWrappers::NTestHelpers;

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

namespace {

Aws::SDKOptions Options;

Y_TEST_HOOK_BEFORE_RUN(InitAwsAPI) {
Aws::InitAPI(Options);
}

Y_TEST_HOOK_AFTER_RUN(ShutdownAwsAPI) {
Aws::ShutdownAPI(Options);
}

void Run(TTestBasicRuntime& runtime, TTestEnv& env, const std::variant<TVector<TString>, TTablesWithAttrs>& tablesVar, const TString& request,
Ydb::StatusIds::StatusCode expectedStatus = Ydb::StatusIds::SUCCESS,
const TString& dbName = "/MyRoot", bool serverless = false, const TString& userSID = "") {
Expand Down Expand Up @@ -1809,7 +1823,7 @@ partitioning_settings {
return ev->Get<TEvSchemeShard::TEvModifySchemeTransaction>()->Record
.GetTransaction(0).GetOperationType() == NKikimrSchemeOp::ESchemeOpBackup;
};

THolder<IEventHandle> delayed;
auto prevObserver = runtime.SetObserverFunc([&](TAutoPtr<IEventHandle>& ev) {
if (delayFunc(ev)) {
Expand Down Expand Up @@ -1976,7 +1990,7 @@ partitioning_settings {
min_partitions_count: 10
)"));
}

Y_UNIT_TEST(UserSID) {
TTestBasicRuntime runtime;
TTestEnv env(runtime);
Expand Down
1 change: 1 addition & 0 deletions ydb/core/tx/schemeshard/ut_export/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ IF (NOT OS_WINDOWS)
library/cpp/getopt
library/cpp/regex/pcre
library/cpp/svnversion
contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core
ydb/core/testlib/default
ydb/core/tx
ydb/core/tx/schemeshard/ut_helpers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,28 @@

#include <util/string/printf.h>

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

#include <aws/core/Aws.h>

using namespace NSchemeShardUT_Private;
using namespace NSchemeShardUT_Private::NExportReboots;
using namespace NKikimr::NWrappers::NTestHelpers;

namespace {

Aws::SDKOptions Options;

Y_TEST_HOOK_BEFORE_RUN(InitAwsAPI) {
Aws::InitAPI(Options);
}

Y_TEST_HOOK_AFTER_RUN(ShutdownAwsAPI) {
Aws::ShutdownAPI(Options);
}

}

Y_UNIT_TEST_SUITE(TExportToS3WithRebootsTests) {
using TUnderlying = std::function<void(const TVector<TString>&, const TString&, TTestWithReboots&)>;

Expand Down
1 change: 1 addition & 0 deletions ydb/core/tx/schemeshard/ut_export_reboots_s3/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ PEERDIR(
library/cpp/getopt
library/cpp/regex/pcre
library/cpp/svnversion
contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core
ydb/core/testlib/default
ydb/core/tx
ydb/core/tx/schemeshard/ut_helpers
Expand Down
13 changes: 12 additions & 1 deletion ydb/core/tx/schemeshard/ut_restore/ut_restore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@

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

#include <aws/core/Aws.h>
#include <contrib/libs/zstd/include/zstd.h>
#include <library/cpp/string_utils/quote/quote.h>
#include <library/cpp/testing/hook/hook.h>

#include <util/datetime/base.h>
#include <util/generic/size_literals.h>
Expand All @@ -37,6 +39,16 @@ using namespace NKikimr::NWrappers::NTestHelpers;

namespace {

Aws::SDKOptions Options;

Y_TEST_HOOK_BEFORE_RUN(InitAwsAPI) {
Aws::InitAPI(Options);
}

Y_TEST_HOOK_AFTER_RUN(ShutdownAwsAPI) {
Aws::ShutdownAPI(Options);
}

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

TString GenerateScheme(const NKikimrSchemeOp::TPathDescription& pathDesc) {
Expand Down Expand Up @@ -316,7 +328,6 @@ namespace {
runtime.SetObserverFunc(prevObserver);
}


} // anonymous

Y_UNIT_TEST_SUITE(TRestoreTests) {
Expand Down
1 change: 1 addition & 0 deletions ydb/core/tx/schemeshard/ut_restore/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ELSE()
ENDIF()

PEERDIR(
contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core
contrib/libs/double-conversion
library/cpp/string_utils/quote
ydb/core/kqp/ut/common
Expand Down
3 changes: 1 addition & 2 deletions ydb/core/wrappers/s3_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#ifndef KIKIMR_DISABLE_S3_OPS

#include "abstract.h"
#include "s3_storage_config.h"

#include <ydb/core/protos/flat_scheme_op.pb.h>
#include <ydb/core/wrappers/events/common.h>
Expand Down Expand Up @@ -32,7 +31,7 @@

namespace NKikimr::NWrappers::NExternalStorage {

class TS3ExternalStorage: public IExternalStorageOperator, TS3User {
class TS3ExternalStorage: public IExternalStorageOperator {
private:
THolder<Aws::S3::S3Client> Client;
const Aws::Client::ClientConfiguration Config;
Expand Down
Loading

0 comments on commit ff0fd33

Please sign in to comment.