Skip to content

Commit a2f8363

Browse files
authored
VIEW import: bugfix for a dependent view case (#14706)
1 parent f9c6964 commit a2f8363

File tree

3 files changed

+100
-3
lines changed

3 files changed

+100
-3
lines changed

ydb/core/tx/schemeshard/schemeshard_import__create.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ struct TSchemeShard::TImport::TTxProgress: public TSchemeShard::TXxport::TTxBase
340340
if (SchemeResult) {
341341
OnSchemeResult(txc, ctx);
342342
} else if (SchemeQueryResult) {
343-
OnSchemeQueryPreparation(txc);
343+
OnSchemeQueryPreparation(txc, ctx);
344344
} else if (AllocateResult) {
345345
OnAllocateResult(txc, ctx);
346346
} else if (ModifyResult) {
@@ -886,7 +886,7 @@ struct TSchemeShard::TImport::TTxProgress: public TSchemeShard::TXxport::TTxBase
886886
}
887887
}
888888

889-
void OnSchemeQueryPreparation(TTransactionContext& txc) {
889+
void OnSchemeQueryPreparation(TTransactionContext& txc, const TActorContext& ctx) {
890890
Y_ABORT_UNLESS(SchemeQueryResult);
891891
const auto& message = *SchemeQueryResult.Get()->Get();
892892
const TString error = std::holds_alternative<TString>(message.Result) ? std::get<TString>(message.Result) : "";
@@ -929,6 +929,8 @@ struct TSchemeShard::TImport::TTxProgress: public TSchemeShard::TXxport::TTxBase
929929
if (AllWaiting(itemStates)) {
930930
// Cancel the import, or we will end up waiting indefinitely.
931931
return CancelAndPersist(db, importInfo, message.ItemIdx, error, "creation query failed");
932+
} else if (AllDoneOrWaiting(itemStates)) {
933+
RetryViewsCreation(importInfo, db, ctx);
932934
}
933935
return;
934936
}

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

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1738,7 +1738,7 @@ value {
17381738

17391739
const std::pair<ui64, ui64> decimal2 = NYql::NDecimal::MakePair(NYql::NDecimal::FromString("32.1", 2, 1));
17401740
const std::pair<ui64, ui64> decimal35 = NYql::NDecimal::MakePair(NYql::NDecimal::FromString("555555555555555.123456789", 35, 10));
1741-
UploadRow(runtime, "/MyRoot/Table", 0, {1}, {2},
1741+
UploadRow(runtime, "/MyRoot/Table", 0, {1}, {2},
17421742
{TCell::Make<std::pair<ui64, ui64>>(decimal2)}, {TCell::Make<std::pair<ui64, ui64>>(decimal35)});
17431743

17441744
TPortManager portManager;
@@ -4964,6 +4964,45 @@ Y_UNIT_TEST_SUITE(TImportWithRebootsTests) {
49644964
);
49654965
}
49664966

4967+
Y_UNIT_TEST(ShouldSucceedOnDependentView) {
4968+
ShouldSucceed(
4969+
{
4970+
{
4971+
"/DependentView",
4972+
{
4973+
EPathTypeView,
4974+
R"(
4975+
-- backup root: "/MyRoot"
4976+
CREATE VIEW IF NOT EXISTS `DependentView` WITH security_invoker = TRUE AS SELECT * FROM `BaseView`;
4977+
)"
4978+
}
4979+
}, {
4980+
"/BaseView",
4981+
{
4982+
EPathTypeView,
4983+
R"(
4984+
-- backup root: "/MyRoot"
4985+
CREATE VIEW IF NOT EXISTS `BaseView` WITH security_invoker = TRUE AS SELECT 1;
4986+
)"
4987+
}
4988+
}
4989+
}, R"(
4990+
ImportFromS3Settings {
4991+
endpoint: "localhost:%d"
4992+
scheme: HTTP
4993+
items {
4994+
source_prefix: "DependentView"
4995+
destination_path: "/MyRoot/DependentView"
4996+
}
4997+
items {
4998+
source_prefix: "BaseView"
4999+
destination_path: "/MyRoot/BaseView"
5000+
}
5001+
}
5002+
)"
5003+
);
5004+
}
5005+
49675006
void CancelShouldSucceed(const THashMap<TString, TTypedScheme>& schemes, TStringBuf importSettings = DefaultImportSettings) {
49685007
TPortManager portManager;
49695008
const ui16 port = portManager.GetPort();
@@ -5112,4 +5151,43 @@ Y_UNIT_TEST_SUITE(TImportWithRebootsTests) {
51125151
)"
51135152
);
51145153
}
5154+
5155+
Y_UNIT_TEST(CancelShouldSucceedOnDependentView) {
5156+
CancelShouldSucceed(
5157+
{
5158+
{
5159+
"/DependentView",
5160+
{
5161+
EPathTypeView,
5162+
R"(
5163+
-- backup root: "/MyRoot"
5164+
CREATE VIEW IF NOT EXISTS `DependentView` WITH security_invoker = TRUE AS SELECT * FROM `BaseView`;
5165+
)"
5166+
}
5167+
}, {
5168+
"/BaseView",
5169+
{
5170+
EPathTypeView,
5171+
R"(
5172+
-- backup root: "/MyRoot"
5173+
CREATE VIEW IF NOT EXISTS `BaseView` WITH security_invoker = TRUE AS SELECT 1;
5174+
)"
5175+
}
5176+
}
5177+
}, R"(
5178+
ImportFromS3Settings {
5179+
endpoint: "localhost:%d"
5180+
scheme: HTTP
5181+
items {
5182+
source_prefix: "DependentView"
5183+
destination_path: "/MyRoot/DependentView"
5184+
}
5185+
items {
5186+
source_prefix: "BaseView"
5187+
destination_path: "/MyRoot/BaseView"
5188+
}
5189+
}
5190+
)"
5191+
);
5192+
}
51155193
}

ydb/services/ydb/backup_ut/ydb_backup_ut.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,6 +1704,8 @@ Y_UNIT_TEST_SUITE(BackupRestoreS3) {
17041704

17051705
auto& runtime = *Server.GetRuntime();
17061706
runtime.SetLogPriority(NKikimrServices::TX_PROXY, NLog::EPriority::PRI_DEBUG);
1707+
runtime.SetLogPriority(NKikimrServices::EXPORT, NLog::EPriority::PRI_DEBUG);
1708+
runtime.SetLogPriority(NKikimrServices::IMPORT, NLog::EPriority::PRI_DEBUG);
17071709
runtime.GetAppData().DataShardExportFactory = &DataShardExportFactory;
17081710
runtime.GetAppData().FeatureFlags.SetEnableViews(true);
17091711
runtime.GetAppData().FeatureFlags.SetEnableViewExport(true);
@@ -2015,6 +2017,21 @@ Y_UNIT_TEST_SUITE(BackupRestoreS3) {
20152017
);
20162018
}
20172019

2020+
Y_UNIT_TEST(RestoreViewDependentOnAnotherView) {
2021+
TS3TestEnv testEnv;
2022+
constexpr const char* baseView = "/Root/baseView";
2023+
constexpr const char* dependentView = "/Root/dependentView";
2024+
2025+
TestViewDependentOnAnotherViewIsRestored(
2026+
baseView,
2027+
dependentView,
2028+
testEnv.GetQuerySession(),
2029+
CreateBackupLambda(testEnv.GetDriver(), testEnv.GetS3Port()),
2030+
CreateRestoreLambda(testEnv.GetDriver(), testEnv.GetS3Port(), { "baseView", "dependentView" })
2031+
);
2032+
}
2033+
2034+
20182035
// TO DO: test view restoration to a different database
20192036

20202037
void TestTableBackupRestore() {

0 commit comments

Comments
 (0)