Skip to content

Commit c157964

Browse files
authored
24-3: Forbid scheme ops on backup table (#9446)
1 parent 75f6b27 commit c157964

5 files changed

+47
-7
lines changed

ydb/core/tx/schemeshard/schemeshard__operation_alter_table.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,10 @@ class TAlterTable: public TSubOperation {
523523
.IsTable()
524524
.NotUnderOperation();
525525

526-
if (!Transaction.GetInternal()) {
527-
checks.NotAsyncReplicaTable();
526+
if (checks && !Transaction.GetInternal()) {
527+
checks
528+
.NotAsyncReplicaTable()
529+
.NotBackupTable();
528530
}
529531

530532
if (!context.IsAllowedPrivateTables) {
@@ -726,6 +728,10 @@ TVector<ISubOperation::TPtr> CreateConsistentAlterTable(TOperationId id, const T
726728
return {CreateAlterTable(id, tx)};
727729
}
728730

731+
if (path.IsBackupTable()) {
732+
return {CreateAlterTable(id, tx)};
733+
}
734+
729735
TPath parent = path.Parent();
730736

731737
if (!parent.IsTableIndex()) {

ydb/core/tx/schemeshard/schemeshard__operation_create_cdc_stream.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ class TNewCdcStream: public TSubOperation {
131131
.IsResolved()
132132
.NotDeleted()
133133
.IsTable()
134+
.NotBackupTable()
134135
.NotAsyncReplicaTable()
135136
.NotUnderDeleting();
136137

ydb/core/tx/schemeshard/schemeshard__operation_create_index.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ class TCreateTableIndex: public TSubOperation {
139139
.NotDeleted()
140140
.NotUnderDeleting()
141141
.IsCommonSensePath()
142-
.IsTable();
142+
.IsTable()
143+
.NotBackupTable();
143144

144145
if (!internal) {
145146
checks.NotAsyncReplicaTable();

ydb/core/tx/schemeshard/schemeshard__operation_create_sequence.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ class TCreateSequence : public TSubOperation {
376376

377377
if (checks) {
378378
if (parentPath->IsTable()) {
379+
checks.NotBackupTable();
379380
// allow immediately inside a normal table
380381
if (parentPath.IsUnderOperation()) {
381382
checks.IsUnderTheSameOperation(OperationId.GetTxId()); // allowed only as part of consistent operations

ydb/core/tx/schemeshard/ut_base/ut_base.cpp

+35-4
Original file line numberDiff line numberDiff line change
@@ -3603,6 +3603,35 @@ Y_UNIT_TEST_SUITE(TSchemeShardTest) {
36033603
NLs::IsBackupTable(true),
36043604
});
36053605

3606+
// cannot alter backup table
3607+
TestAlterTable(runtime, ++txId, "/MyRoot", R"(
3608+
Name: "CopyTable"
3609+
DropColumns { Name: "value" }
3610+
)", {NKikimrScheme::StatusSchemeError});
3611+
3612+
// cannot add cdc stream to backup table
3613+
TestCreateCdcStream(runtime, ++txId, "/MyRoot", R"(
3614+
TableName: "CopyTable"
3615+
StreamDescription {
3616+
Name: "Stream"
3617+
Mode: ECdcStreamModeKeysOnly
3618+
Format: ECdcStreamFormatProto
3619+
}
3620+
)", {NKikimrScheme::StatusSchemeError});
3621+
3622+
// cannot add sequence to backup table
3623+
TestCreateSequence(runtime, ++txId, "/MyRoot/CopyTable", R"(
3624+
Name: "Sequence"
3625+
)", {NKikimrScheme::StatusSchemeError});
3626+
3627+
// cannot add index to backup table
3628+
TestBuildIndex(runtime, ++txId, TTestTxConfig::SchemeShard, "/MyRoot", "/MyRoot/CopyTable", "Index", {"value"});
3629+
env.TestWaitNotification(runtime, txId);
3630+
{
3631+
auto desc = TestGetBuildIndex(runtime, TTestTxConfig::SchemeShard, "/MyRoot", txId);
3632+
UNIT_ASSERT_EQUAL(desc.GetIndexBuild().GetState(), Ydb::Table::IndexBuildState::STATE_REJECTED);
3633+
}
3634+
36063635
// consistent copy table
36073636
TestConsistentCopyTables(runtime, ++txId, "/", R"(
36083637
CopyTableDescriptions {
@@ -3741,16 +3770,18 @@ Y_UNIT_TEST_SUITE(TSchemeShardTest) {
37413770
)", {NKikimrScheme::StatusInvalidParameter});
37423771

37433772
// cannot remove 'IsBackup' property from existent table
3744-
TestAlterTable(runtime, ++txId, "/MyRoot", R"(
3773+
AsyncSend(runtime, TTestTxConfig::SchemeShard, InternalTransaction(AlterTableRequest(++txId, "/MyRoot", R"(
37453774
Name: "CopyTable"
37463775
IsBackup: false
3747-
)", {NKikimrScheme::StatusInvalidParameter});
3776+
)")));
3777+
TestModificationResults(runtime, txId, {NKikimrScheme::StatusInvalidParameter});
37483778

3749-
TestAlterTable(runtime, ++txId, "/MyRoot", R"(
3779+
AsyncSend(runtime, TTestTxConfig::SchemeShard, InternalTransaction(AlterTableRequest(++txId, "/MyRoot", R"(
37503780
Name: "CopyTable"
37513781
IsBackup: false
37523782
DropColumns { Name: "value" }
3753-
)", {NKikimrScheme::StatusInvalidParameter});
3783+
)")));
3784+
TestModificationResults(runtime, txId, {NKikimrScheme::StatusInvalidParameter});
37543785

37553786
// sanity check
37563787

0 commit comments

Comments
 (0)