Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ydb/core/protos/feature_flags.proto
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,5 @@ message TFeatureFlags {
optional bool SwitchToConfigV1 = 180 [default = false];
optional bool EnableEncryptedExport = 181 [default = false];
optional bool EnableAlterDatabase = 182 [default = false];
optional bool EnableExportAutoDropping = 183 [default = false];
}
13 changes: 11 additions & 2 deletions ydb/core/tx/schemeshard/schemeshard_export__create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,11 @@ struct TSchemeShard::TExport::TTxProgress: public TSchemeShard::TXxport::TTxBase
Self->PersistExportItemState(db, exportInfo, itemIdx);

if (AllOf(exportInfo->Items, &TExportInfo::TItem::IsDone)) {
PrepareAutoDropping(Self, exportInfo, db);
if (!AppData()->FeatureFlags.GetEnableExportAutoDropping()) {
EndExport(exportInfo, EState::Done, db);
} else {
PrepareAutoDropping(Self, exportInfo, db);
}
}
} else if (exportInfo->State == EState::Cancellation) {
item.State = EState::Cancelled;
Expand Down Expand Up @@ -1358,7 +1362,12 @@ struct TSchemeShard::TExport::TTxProgress: public TSchemeShard::TXxport::TTxBase
}
}
if (!itemHasIssues && AllOf(exportInfo->Items, &TExportInfo::TItem::IsDone)) {
PrepareAutoDropping(Self, exportInfo, db);
if (!AppData()->FeatureFlags.GetEnableExportAutoDropping()) {
exportInfo->State = EState::Done;
exportInfo->EndTime = TAppData::TimeProvider->Now();
} else {
PrepareAutoDropping(Self, exportInfo, db);
}
}

Self->PersistExportItemState(db, exportInfo, itemIdx);
Expand Down
71 changes: 65 additions & 6 deletions ydb/core/tx/schemeshard/ut_export/ut_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace {
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 = "", const TString& peerName = "",
const TVector<TString>& cdcStreams = {}) {
const TVector<TString>& cdcStreams = {}, bool checkAutoDropping = false) {

TTablesWithAttrs tables;

Expand Down Expand Up @@ -150,6 +150,40 @@ namespace {
const ui64 exportId = txId;
TestGetExport(runtime, schemeshardId, exportId, dbName, expectedStatus);

if (!runtime.GetAppData().FeatureFlags.GetEnableExportAutoDropping() && checkAutoDropping) {
auto desc = DescribePath(runtime, "/MyRoot");
Cerr << "desc: " << desc.GetPathDescription().ChildrenSize()<< Endl;
UNIT_ASSERT(desc.GetPathDescription().ChildrenSize() > 1);

bool foundExportDir = false;
bool foundOriginalTable = false;

for (size_t i = 0; i < desc.GetPathDescription().ChildrenSize(); ++i) {
const auto& child = desc.GetPathDescription().GetChildren(i);
const auto& name = child.GetName();

if (name.StartsWith("Table")) {
foundOriginalTable = true;
} else if (name.StartsWith("export-")) {
foundExportDir = true;
auto exportDirDesc = DescribePath(runtime, "/MyRoot/" + name);
UNIT_ASSERT(exportDirDesc.GetPathDescription().ChildrenSize() >= 1);
UNIT_ASSERT_EQUAL(exportDirDesc.GetPathDescription().GetChildren(0).GetName(), "0");
}
}

UNIT_ASSERT(foundExportDir);
UNIT_ASSERT(foundOriginalTable);
} else if (checkAutoDropping) {
auto desc = DescribePath(runtime, "/MyRoot");
Cerr << "desc: " << desc.GetPathDescription().ChildrenSize()<< Endl;
for (size_t i = 0; i < desc.GetPathDescription().ChildrenSize(); ++i) {
const auto& child = desc.GetPathDescription().GetChildren(i);
const auto& name = child.GetName();
UNIT_ASSERT(!name.StartsWith("export-"));
}
}

TestForgetExport(runtime, schemeshardId, ++txId, dbName, exportId);
env.TestWaitNotification(runtime, exportId, schemeshardId);

Expand Down Expand Up @@ -1201,6 +1235,7 @@ partitioning_settings {
ui64 txId = 100;

THashSet<ui64> statsCollected;
Runtime().GetAppData().FeatureFlags.SetEnableExportAutoDropping(true);
Runtime().SetObserverFunc([&](TAutoPtr<IEventHandle>& ev) {
if (ev->GetTypeRewrite() == TEvDataShard::EvPeriodicTableStats) {
statsCollected.insert(ev->Get<TEvDataShard::TEvPeriodicTableStats>()->Record.GetDatashardId());
Expand Down Expand Up @@ -1286,7 +1321,7 @@ partitioning_settings {
Y_UNIT_TEST(CheckItemProgress) {
Env(); // Init test env
ui64 txId = 100;

Runtime().GetAppData().FeatureFlags.SetEnableExportAutoDropping(true);
TBlockEvents<NKikimr::NWrappers::NExternalStorage::TEvPutObjectRequest> blockPartition01(Runtime(), [](auto&& ev) {
return ev->Get()->Request.GetKey() == "/data_01.csv";
});
Expand Down Expand Up @@ -2773,17 +2808,41 @@ attributes {
}
)", S3Port());

Env();
Runtime().GetAppData().FeatureFlags.SetEnableExportAutoDropping(true);

Run(Runtime(), Env(), TVector<TString>{
R"(
Name: "Table"
Columns { Name: "key" Type: "Utf8" }
Columns { Name: "value" Type: "Utf8" }
KeyColumnNames: ["key"]
)",
}, request, Ydb::StatusIds::SUCCESS, "/MyRoot");
}, request, Ydb::StatusIds::SUCCESS, "/MyRoot", false, "", "", {}, true);
}

Y_UNIT_TEST(DisableAutoDropping) {
auto request = Sprintf(R"(
ExportToS3Settings {
endpoint: "localhost:%d"
scheme: HTTP
items {
source_path: "/MyRoot/Table"
destination_prefix: ""
}
}
)", S3Port());

Env();
Runtime().GetAppData().FeatureFlags.SetEnableExportAutoDropping(false);

auto desc = DescribePath(Runtime(), "/MyRoot");
UNIT_ASSERT_EQUAL(desc.GetPathDescription().ChildrenSize(), 1);
UNIT_ASSERT_EQUAL(desc.GetPathDescription().GetChildren(0).GetName(), "Table");
Run(Runtime(), Env(), TVector<TString>{
R"(
Name: "Table"
Columns { Name: "key" Type: "Utf8" }
Columns { Name: "value" Type: "Utf8" }
KeyColumnNames: ["key"]
)",
}, request, Ydb::StatusIds::SUCCESS, "/MyRoot", false, "", "", {}, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ Y_UNIT_TEST_SUITE(TExportToS3WithRebootsTests) {

t.Run([&](TTestActorRuntime& runtime, bool& activeZone) {
runtime.SetLogPriority(NKikimrServices::EXPORT, NActors::NLog::PRI_TRACE);
runtime.GetAppData().FeatureFlags.SetEnableExportAutoDropping(true);
{
TInactiveZone inactive(activeZone);
CreateSchemeObjects(t, runtime, {
Expand All @@ -620,4 +621,41 @@ Y_UNIT_TEST_SUITE(TExportToS3WithRebootsTests) {
}
});
}

Y_UNIT_TEST(ShouldDisableAutoDropping) {
TPortManager portManager;
const ui16 port = portManager.GetPort();

TTestWithReboots t;
TS3Mock s3Mock({}, TS3Mock::TSettings(port));
UNIT_ASSERT(s3Mock.Start());

t.Run([&](TTestActorRuntime& runtime, bool& activeZone) {
runtime.SetLogPriority(NKikimrServices::EXPORT, NActors::NLog::PRI_TRACE);
runtime.GetAppData().FeatureFlags.SetEnableExportAutoDropping(false);
{
TInactiveZone inactive(activeZone);
CreateSchemeObjects(t, runtime, {
TTestData::Table()
});

TestExport(runtime, ++t.TxId, "/MyRoot", Sprintf(TTestData::Request().data(), port));
}

const ui64 exportId = t.TxId;
t.TestEnv->TestWaitNotification(runtime, exportId);

{
TInactiveZone inactive(activeZone);
TestGetExport(runtime, exportId, "/MyRoot");
TestRmDir(runtime, ++t.TxId, "/MyRoot", "DirA");
auto desc = DescribePath(runtime, "/MyRoot");
UNIT_ASSERT_EQUAL(desc.GetPathDescription().ChildrenSize(), 2);
const auto namesVector = {desc.GetPathDescription().GetChildren(0).GetName(),
desc.GetPathDescription().GetChildren(1).GetName()};
UNIT_ASSERT(IsIn(namesVector, "Table"));
UNIT_ASSERT(IsIn(namesVector, "export-1003"));
}
});
}
}
Loading