Skip to content

Fix alter replication config #6348

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
merged 1 commit into from
Jul 5, 2024
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
2 changes: 2 additions & 0 deletions ydb/core/tx/datashard/datashard_user_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ void TUserTable::AlterSchema() {
schema.SetPartitionRangeEnd(Range.To.GetBuffer());
schema.SetPartitionRangeEndIsInclusive(Range.ToInclusive);

ReplicationConfig.Serialize(*schema.MutableReplicationConfig());

schema.SetName(Name);
schema.SetPath(Path);

Expand Down
5 changes: 5 additions & 0 deletions ydb/core/tx/datashard/datashard_user_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,11 @@ struct TUserTable : public TThrRefBase {
bool HasStrongConsistency() const {
return Consistency == NKikimrSchemeOp::TTableReplicationConfig::CONSISTENCY_STRONG;
}

void Serialize(NKikimrSchemeOp::TTableReplicationConfig& proto) const {
proto.SetMode(Mode);
proto.SetConsistency(Consistency);
}
};

struct TStats {
Expand Down
3 changes: 3 additions & 0 deletions ydb/core/tx/datashard/datashard_ut_replication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ Y_UNIT_TEST_SUITE(DataShardReplication) {
ExecSQL(server, sender, "SELECT * FROM `/Root/table-1`");
ExecSQL(server, sender, "INSERT INTO `/Root/table-1` (key, value) VALUES (1, 10);", true,
Ydb::StatusIds::GENERIC_ERROR);

WaitTxNotification(server, sender, AsyncAlterDropReplicationConfig(server, "/Root", "table-1"));
ExecSQL(server, sender, "INSERT INTO `/Root/table-1` (key, value) VALUES (1, 10);");
}

Y_UNIT_TEST(ApplyChangesToReplicatedTable) {
Expand Down
16 changes: 16 additions & 0 deletions ydb/core/tx/datashard/ut_common/datashard_ut_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1730,6 +1730,22 @@ ui64 AsyncAlterDropStream(
return RunSchemeTx(*server->GetRuntime(), std::move(request));
}

ui64 AsyncAlterDropReplicationConfig(
Tests::TServer::TPtr server,
const TString& workingDir,
const TString& tableName)
{
auto request = SchemeTxTemplate(NKikimrSchemeOp::ESchemeOpAlterTable, workingDir);
auto& tx = *request->Record.MutableTransaction()->MutableModifyScheme();
tx.SetInternal(true);

auto& desc = *tx.MutableAlterTable();
desc.SetName(tableName);
desc.MutableReplicationConfig()->SetMode(NKikimrSchemeOp::TTableReplicationConfig::REPLICATION_MODE_NONE);

return RunSchemeTx(*server->GetRuntime(), std::move(request));
}

ui64 AsyncCreateContinuousBackup(
Tests::TServer::TPtr server,
const TString& workingDir,
Expand Down
5 changes: 5 additions & 0 deletions ydb/core/tx/datashard/ut_common/datashard_ut_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,11 @@ ui64 AsyncAlterDropStream(
const TString& tableName,
const TString& streamName);

ui64 AsyncAlterDropReplicationConfig(
Tests::TServer::TPtr server,
const TString& workingDir,
const TString& tableName);

ui64 AsyncCreateContinuousBackup(
Tests::TServer::TPtr server,
const TString& workingDir,
Expand Down
6 changes: 6 additions & 0 deletions ydb/core/tx/schemeshard/schemeshard_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6538,6 +6538,12 @@ TString TSchemeShard::FillAlterTableTxBody(TPathId pathId, TShardIdx shardIdx, T
*patch);
}

if (alterData->TableDescriptionFull.Defined() && alterData->TableDescriptionFull->HasReplicationConfig()) {
proto->MutableReplicationConfig()->CopyFrom(alterData->TableDescriptionFull->GetReplicationConfig());
} else if (tableInfo->HasReplicationConfig()) {
proto->MutableReplicationConfig()->CopyFrom(tableInfo->ReplicationConfig());
}

TString txBody;
Y_PROTOBUF_SUPPRESS_NODISCARD tx.SerializeToString(&txBody);
return txBody;
Expand Down
Loading