Skip to content

feat: ALTER TABLE SET (REPLICATION_MODE) for the manual switchover fence - #59248

Closed
Enjection wants to merge 4 commits into
ydb-platform:mainfrom
Enjection:feat/manual-replication-switchover-no-legacy
Closed

Enjection wants to merge 4 commits into
ydb-platform:mainfrom
Enjection:feat/manual-replication-switchover-no-legacy

Conversation

@Enjection

Copy link
Copy Markdown
Member

Changelog entry

Everything from #59171, and additionally: 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 and back, for a cluster administrator. It is the write fence of a manual replication switchover, which no longer needs the legacy ydbd db schema exec service.

Description for reviewers

Stacked on #59171 (same three commits) with one commit on top. Review that PR first; this one only replaces how the switchover fences writes.

Why. A switchover demotes the old primary's tables to read-only replicas in place. SchemeShard already does exactly that, but only for an Internal ModifyScheme (schemeshard_info_types.cpp rejects replica mode from a plain alter), and the only client that forwards a raw ModifyScheme is the legacy MsgBus SchemeOperation call. So #59171's tool needs the legacy gRPC service enabled on a node of each cluster. This PR gives the operation a supported door.

What the statement does. ALTER TABLE t SET (REPLICATION_MODE = READ_ONLY) sets ReplicationConfig { Mode: READ_ONLY, ConsistencyLevel: ROW, ImportState: IMPORTED } on the table and, in the same operation, on the implementation tables of its synchronous and unique indexes, which are independent replication targets. NONE reverses it. IMPORTED is what the replication's attach path requires of a table it did not create, and the consistency level has to be the one that replication's own configuration asks for, or its CheckReplicationConfig refuses the table (dst_creator.cpp) — hence REPLICATION_CONSISTENCY_LEVEL = GLOBAL for a globally consistent one; ROW is the default, and the setting is rejected without REPLICATION_MODE.

Authorization. A new TModifyScheme.AllowReplicationModeChange replaces the Internal flag for this path, and SchemeShard honours it only for a real cluster administrator: IsAdministrator(...) && !AdministrationAllowedSIDs.empty(), the same rule the index-implementation-table alter already uses, so "all users are admins by default" does not grant it. A non-administrator gets StatusAccessDenied with a message naming the requirement. The flag is not reachable from the public AlterTableRequest, which has no replication field; KQP builds the scheme transaction for this one setting.

Where it is plumbed. Translator (both settings in the ALTER TABLE ... SET allow-list, create-time and RESET rejected), KQP type annotation and exec (READ_ONLY/NONE, anything else is an error), gateway (builds the TModifyScheme directly, like the local bloom filter index does), alter-kind classifier, SchemeShard (the admin gate plus propagation into index implementation tables).

Tool. fence, rollback and the promote fallback now issue the statement; the stale index changefeed is dropped through the Table API addressed by the index path, as the replication controller itself does. ydbd is left only for a read-only db schema describe. A --token option (or YDB_TOKEN) carries the administrator token to both clusters and to the CLI.

Tests: 5 parser cases in SqlParsingOnly, and KqpScheme::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. The tool's rehearsal was run end to end on a sandbox cluster pair with an administrator SID.

The switchover fences writes by demoting the old primary's tables to
read-only replicas in place. Only an Internal ModifyScheme could do that,
and the only client that forwards one is the legacy MsgBus SchemeOperation
service, so the tool needed `ydbd db schema exec`.

ALTER TABLE <t> SET (REPLICATION_MODE = READ_ONLY | NONE,
REPLICATION_CONSISTENCY_LEVEL = ROW | GLOBAL) replaces it. A new
TModifyScheme.AllowReplicationModeChange stands in for Internal on this
path and SchemeShard honours it only for a real cluster administrator, the
same rule index implementation table alters already use. The demote also
sets ImportState = IMPORTED and the consistency level, both of which the
replication's attach path requires of a table it did not create, and
applies to the implementation tables of synchronous and unique indexes.
@github-actions

Copy link
Copy Markdown
Contributor

🔴 Unable to merge your PR into the base branch. Please rebase or merge it with the base branch.

@Enjection

Copy link
Copy Markdown
Member Author

Superseded. Its two halves have gone separate ways:

This branch is also on a stale base and still carries the CASCADE change that was withdrawn in #59278. Closing.

@Enjection Enjection closed this Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant