Skip to content

24-3: Forbid scheme ops on backup table #9446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
10 changes: 8 additions & 2 deletions ydb/core/tx/schemeshard/schemeshard__operation_alter_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,10 @@ class TAlterTable: public TSubOperation {
.IsTable()
.NotUnderOperation();

if (!Transaction.GetInternal()) {
checks.NotAsyncReplicaTable();
if (checks && !Transaction.GetInternal()) {
checks
.NotAsyncReplicaTable()
.NotBackupTable();
}

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

if (path.IsBackupTable()) {
return {CreateAlterTable(id, tx)};
}

TPath parent = path.Parent();

if (!parent.IsTableIndex()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class TNewCdcStream: public TSubOperation {
.IsResolved()
.NotDeleted()
.IsTable()
.NotBackupTable()
.NotAsyncReplicaTable()
.NotUnderDeleting();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ class TCreateTableIndex: public TSubOperation {
.NotDeleted()
.NotUnderDeleting()
.IsCommonSensePath()
.IsTable();
.IsTable()
.NotBackupTable();

if (!internal) {
checks.NotAsyncReplicaTable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ class TCreateSequence : public TSubOperation {

if (checks) {
if (parentPath->IsTable()) {
checks.NotBackupTable();
// allow immediately inside a normal table
if (parentPath.IsUnderOperation()) {
checks.IsUnderTheSameOperation(OperationId.GetTxId()); // allowed only as part of consistent operations
Expand Down
39 changes: 35 additions & 4 deletions ydb/core/tx/schemeshard/ut_base/ut_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3603,6 +3603,35 @@ Y_UNIT_TEST_SUITE(TSchemeShardTest) {
NLs::IsBackupTable(true),
});

// cannot alter backup table
TestAlterTable(runtime, ++txId, "/MyRoot", R"(
Name: "CopyTable"
DropColumns { Name: "value" }
)", {NKikimrScheme::StatusSchemeError});

// cannot add cdc stream to backup table
TestCreateCdcStream(runtime, ++txId, "/MyRoot", R"(
TableName: "CopyTable"
StreamDescription {
Name: "Stream"
Mode: ECdcStreamModeKeysOnly
Format: ECdcStreamFormatProto
}
)", {NKikimrScheme::StatusSchemeError});

// cannot add sequence to backup table
TestCreateSequence(runtime, ++txId, "/MyRoot/CopyTable", R"(
Name: "Sequence"
)", {NKikimrScheme::StatusSchemeError});

// cannot add index to backup table
TestBuildIndex(runtime, ++txId, TTestTxConfig::SchemeShard, "/MyRoot", "/MyRoot/CopyTable", "Index", {"value"});
env.TestWaitNotification(runtime, txId);
{
auto desc = TestGetBuildIndex(runtime, TTestTxConfig::SchemeShard, "/MyRoot", txId);
UNIT_ASSERT_EQUAL(desc.GetIndexBuild().GetState(), Ydb::Table::IndexBuildState::STATE_REJECTED);
}

// consistent copy table
TestConsistentCopyTables(runtime, ++txId, "/", R"(
CopyTableDescriptions {
Expand Down Expand Up @@ -3741,16 +3770,18 @@ Y_UNIT_TEST_SUITE(TSchemeShardTest) {
)", {NKikimrScheme::StatusInvalidParameter});

// cannot remove 'IsBackup' property from existent table
TestAlterTable(runtime, ++txId, "/MyRoot", R"(
AsyncSend(runtime, TTestTxConfig::SchemeShard, InternalTransaction(AlterTableRequest(++txId, "/MyRoot", R"(
Name: "CopyTable"
IsBackup: false
)", {NKikimrScheme::StatusInvalidParameter});
)")));
TestModificationResults(runtime, txId, {NKikimrScheme::StatusInvalidParameter});

TestAlterTable(runtime, ++txId, "/MyRoot", R"(
AsyncSend(runtime, TTestTxConfig::SchemeShard, InternalTransaction(AlterTableRequest(++txId, "/MyRoot", R"(
Name: "CopyTable"
IsBackup: false
DropColumns { Name: "value" }
)", {NKikimrScheme::StatusInvalidParameter});
)")));
TestModificationResults(runtime, txId, {NKikimrScheme::StatusInvalidParameter});

// sanity check

Expand Down
Loading