Repository navigation
Conversation
ALTER TABLE <t> SET (REPLICATION_MODE = READ_ONLY | NONE, REPLICATION_CONSISTENCY_LEVEL = ROW | GLOBAL) turns an existing table into a read-only async-replication replica in place, and back. SchemeShard could already do it, but only for an Internal ModifyScheme, and the only client that forwards a raw one is the legacy MsgBus SchemeOperation call. READ_ONLY also sets ImportState = IMPORTED and the consistency level, which is what the replication's attach path requires of a table it did not create (dst_creator.cpp), and applies to the implementation tables of the table's synchronous and unique indexes, each an independent replication target. A new TModifyScheme.AllowReplicationModeChange stands in for Internal on this path, and SchemeShard honours it only for a real cluster administrator -- IsAdministrator() with a non-empty AdministrationAllowedSIDs, the rule index implementation table alters already use -- because the demote bypasses every protection a replica table has.
✅ Documentation buildRevision built successfully |
|
⚪ ⚪
🟢
*please be aware that the difference is based on comparing your commit and the last completed build from the post-commit, check comparation |
|
Superseded by #59328, which exposes the same capability as The replication performs the demote itself, so the mode, consistency level and Closing in favour of that PR. Keeping this branch around in case the standalone primitive turns out to be wanted for repair paths. |
Changelog entry
ALTER TABLE <table> SET (REPLICATION_MODE = READ_ONLY | NONE, REPLICATION_CONSISTENCY_LEVEL = ROW | GLOBAL)turns an existing table into a read-only async-replication replica in place, and back. Admitted from a cluster administrator only.Description for reviewers
SchemeShard can already demote a table to a replica, but only for an
InternalModifyScheme, and the only client that forwards a raw one is the legacy MsgBusSchemeOperationcall. This gives the operation a supported door; it is what a manual replication switchover uses to fence writes on the old primary without copying the data again.READ_ONLYsetsReplicationConfig { Mode: READ_ONLY, ConsistencyLevel, ImportState: IMPORTED }on the table and, in the same operation, on the implementation tables of its synchronous and unique indexes, each an independent replication target.IMPORTEDand a matching consistency level are what the replication's attach path requires of a table it did not create (dst_creator.cpp):ROWis the default,GLOBALis for a globally consistent replication, and the setting is rejected withoutREPLICATION_MODE.NONEreverses the demote.Authorization: a new
TModifyScheme.AllowReplicationModeChangestands in forInternalon this path, and SchemeShard honours it only for a real cluster administrator —IsAdministrator()with a non-emptyAdministrationAllowedSIDs, the rule index implementation table alters already use — so "all users are admins by default" does not grant it. The flag is not reachable from the publicAlterTableRequest, which has no replication field; KQP builds the scheme transaction for these two settings.Tests: 5 parser cases in
SqlParsingOnly, andKqpScheme::AlterTableReplicationMode— administrator succeeds, non-administrator is denied, unknown values rejected, base and index implementation tables demoted with the right consistency level, writes rejected and reads served, back to writable.