aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniil Demin <deminds@ydb.tech>2025-02-17 21:25:50 +0300
committerGitHub <noreply@github.com>2025-02-17 21:25:50 +0300
commita2f83637b9287a1ee6bfdfd696e2a70d29cfac80 (patch)
tree570ef6dde875a3ceecf344eac7b6c2331700e116
parentf9c69643a8e241858b558435b88f02fcf7c79daf (diff)
downloadydb-a2f83637b9287a1ee6bfdfd696e2a70d29cfac80.tar.gz
VIEW import: bugfix for a dependent view case (#14706)
-rw-r--r--ydb/core/tx/schemeshard/schemeshard_import__create.cpp6
-rw-r--r--ydb/core/tx/schemeshard/ut_restore/ut_restore.cpp80
-rw-r--r--ydb/services/ydb/backup_ut/ydb_backup_ut.cpp17
3 files changed, 100 insertions, 3 deletions
diff --git a/ydb/core/tx/schemeshard/schemeshard_import__create.cpp b/ydb/core/tx/schemeshard/schemeshard_import__create.cpp
index f434d4983a..a90bd50a05 100644
--- a/ydb/core/tx/schemeshard/schemeshard_import__create.cpp
+++ b/ydb/core/tx/schemeshard/schemeshard_import__create.cpp
@@ -340,7 +340,7 @@ struct TSchemeShard::TImport::TTxProgress: public TSchemeShard::TXxport::TTxBase
if (SchemeResult) {
OnSchemeResult(txc, ctx);
} else if (SchemeQueryResult) {
- OnSchemeQueryPreparation(txc);
+ OnSchemeQueryPreparation(txc, ctx);
} else if (AllocateResult) {
OnAllocateResult(txc, ctx);
} else if (ModifyResult) {
@@ -886,7 +886,7 @@ private:
}
}
- void OnSchemeQueryPreparation(TTransactionContext& txc) {
+ void OnSchemeQueryPreparation(TTransactionContext& txc, const TActorContext& ctx) {
Y_ABORT_UNLESS(SchemeQueryResult);
const auto& message = *SchemeQueryResult.Get()->Get();
const TString error = std::holds_alternative<TString>(message.Result) ? std::get<TString>(message.Result) : "";
@@ -929,6 +929,8 @@ private:
if (AllWaiting(itemStates)) {
// Cancel the import, or we will end up waiting indefinitely.
return CancelAndPersist(db, importInfo, message.ItemIdx, error, "creation query failed");
+ } else if (AllDoneOrWaiting(itemStates)) {
+ RetryViewsCreation(importInfo, db, ctx);
}
return;
}
diff --git a/ydb/core/tx/schemeshard/ut_restore/ut_restore.cpp b/ydb/core/tx/schemeshard/ut_restore/ut_restore.cpp
index a47d68cfef..4c701b30ba 100644
--- a/ydb/core/tx/schemeshard/ut_restore/ut_restore.cpp
+++ b/ydb/core/tx/schemeshard/ut_restore/ut_restore.cpp
@@ -1738,7 +1738,7 @@ value {
const std::pair<ui64, ui64> decimal2 = NYql::NDecimal::MakePair(NYql::NDecimal::FromString("32.1", 2, 1));
const std::pair<ui64, ui64> decimal35 = NYql::NDecimal::MakePair(NYql::NDecimal::FromString("555555555555555.123456789", 35, 10));
- UploadRow(runtime, "/MyRoot/Table", 0, {1}, {2},
+ UploadRow(runtime, "/MyRoot/Table", 0, {1}, {2},
{TCell::Make<std::pair<ui64, ui64>>(decimal2)}, {TCell::Make<std::pair<ui64, ui64>>(decimal35)});
TPortManager portManager;
@@ -4964,6 +4964,45 @@ Y_UNIT_TEST_SUITE(TImportWithRebootsTests) {
);
}
+ Y_UNIT_TEST(ShouldSucceedOnDependentView) {
+ ShouldSucceed(
+ {
+ {
+ "/DependentView",
+ {
+ EPathTypeView,
+ R"(
+ -- backup root: "/MyRoot"
+ CREATE VIEW IF NOT EXISTS `DependentView` WITH security_invoker = TRUE AS SELECT * FROM `BaseView`;
+ )"
+ }
+ }, {
+ "/BaseView",
+ {
+ EPathTypeView,
+ R"(
+ -- backup root: "/MyRoot"
+ CREATE VIEW IF NOT EXISTS `BaseView` WITH security_invoker = TRUE AS SELECT 1;
+ )"
+ }
+ }
+ }, R"(
+ ImportFromS3Settings {
+ endpoint: "localhost:%d"
+ scheme: HTTP
+ items {
+ source_prefix: "DependentView"
+ destination_path: "/MyRoot/DependentView"
+ }
+ items {
+ source_prefix: "BaseView"
+ destination_path: "/MyRoot/BaseView"
+ }
+ }
+ )"
+ );
+ }
+
void CancelShouldSucceed(const THashMap<TString, TTypedScheme>& schemes, TStringBuf importSettings = DefaultImportSettings) {
TPortManager portManager;
const ui16 port = portManager.GetPort();
@@ -5112,4 +5151,43 @@ Y_UNIT_TEST_SUITE(TImportWithRebootsTests) {
)"
);
}
+
+ Y_UNIT_TEST(CancelShouldSucceedOnDependentView) {
+ CancelShouldSucceed(
+ {
+ {
+ "/DependentView",
+ {
+ EPathTypeView,
+ R"(
+ -- backup root: "/MyRoot"
+ CREATE VIEW IF NOT EXISTS `DependentView` WITH security_invoker = TRUE AS SELECT * FROM `BaseView`;
+ )"
+ }
+ }, {
+ "/BaseView",
+ {
+ EPathTypeView,
+ R"(
+ -- backup root: "/MyRoot"
+ CREATE VIEW IF NOT EXISTS `BaseView` WITH security_invoker = TRUE AS SELECT 1;
+ )"
+ }
+ }
+ }, R"(
+ ImportFromS3Settings {
+ endpoint: "localhost:%d"
+ scheme: HTTP
+ items {
+ source_prefix: "DependentView"
+ destination_path: "/MyRoot/DependentView"
+ }
+ items {
+ source_prefix: "BaseView"
+ destination_path: "/MyRoot/BaseView"
+ }
+ }
+ )"
+ );
+ }
}
diff --git a/ydb/services/ydb/backup_ut/ydb_backup_ut.cpp b/ydb/services/ydb/backup_ut/ydb_backup_ut.cpp
index ba54f5c725..105c76f0c5 100644
--- a/ydb/services/ydb/backup_ut/ydb_backup_ut.cpp
+++ b/ydb/services/ydb/backup_ut/ydb_backup_ut.cpp
@@ -1704,6 +1704,8 @@ Y_UNIT_TEST_SUITE(BackupRestoreS3) {
auto& runtime = *Server.GetRuntime();
runtime.SetLogPriority(NKikimrServices::TX_PROXY, NLog::EPriority::PRI_DEBUG);
+ runtime.SetLogPriority(NKikimrServices::EXPORT, NLog::EPriority::PRI_DEBUG);
+ runtime.SetLogPriority(NKikimrServices::IMPORT, NLog::EPriority::PRI_DEBUG);
runtime.GetAppData().DataShardExportFactory = &DataShardExportFactory;
runtime.GetAppData().FeatureFlags.SetEnableViews(true);
runtime.GetAppData().FeatureFlags.SetEnableViewExport(true);
@@ -2015,6 +2017,21 @@ Y_UNIT_TEST_SUITE(BackupRestoreS3) {
);
}
+ Y_UNIT_TEST(RestoreViewDependentOnAnotherView) {
+ TS3TestEnv testEnv;
+ constexpr const char* baseView = "/Root/baseView";
+ constexpr const char* dependentView = "/Root/dependentView";
+
+ TestViewDependentOnAnotherViewIsRestored(
+ baseView,
+ dependentView,
+ testEnv.GetQuerySession(),
+ CreateBackupLambda(testEnv.GetDriver(), testEnv.GetS3Port()),
+ CreateRestoreLambda(testEnv.GetDriver(), testEnv.GetS3Port(), { "baseView", "dependentView" })
+ );
+ }
+
+
// TO DO: test view restoration to a different database
void TestTableBackupRestore() {