switchmode
Changes the read-write or read-only mode of one or more replication units (RUs) in a shardgroup.
Syntax
switchmode [-ru ru_id]
-shardgroup shardgroup_name
[-force]
Options
Table 115 GDSCTL switchmode Options
| Option | Description |
|---|---|
-force |
Allow a transition to read-write mode to continue if switching the current writer to read-only mode fails. This option also relaxes some replication unit state checks. |
-ru ru_id |
Specify the replication unit to switch. If omitted, switch all replication units in the target shardgroup. |
-shardgroup shardgroup_name |
Specify the shardgroup containing the replication units whose modes are to be switched. This option is required. |
Usage Notes
Use this command to change write ownership in a cross-region Raft replication configuration. The command switches the current mode of each selected replication unit. When the selected replication units are read-write, GDSCTL creates a background task for each unit to change it to read-only mode.
When the target replication units are read-only, background tasks change the current writer in another shardgroup in the same shardspace to read-only mode, if one exists, and then change the target replication units to read-write mode. Without -force, the target transition depends on successful completion of the task that changes the current writer to read-only mode. The -force option allows the target transition to proceed if that task fails. Before using -force, account for application access to the former writer and transactions that have not reached the target.
If -ru is omitted, all replication units in the target shardgroup must have the same current mode. The command is rejected if the selected replication units have mixed modes. GDSCTL also validates that their leaders are running and that their states allow the requested transition. If validation fails for any selected replication unit, the request is rejected.
Tasks can remain pending or fail independently. A task failure does not cancel other tasks. Use config task to monitor tasks and alter task to manage them. Before retrying, check the current modes because the command can switch them in either direction.
Use switchover ru to change the leader within a replication unit. Use switchmode to change the write mode across shardgroups.
Examples
The following examples are alternative operations. Both use shardgroup DBS2 as the target and assume that the selected replication units are initially read-only and that the current writer is available.
Switch replication unit 1 in shardgroup DBS2 to read-write mode:
GDSCTL> switchmode -ru 1 -shardgroup dbs2
Alternatively, switch all replication units in shardgroup DBS2 to read-write mode:
GDSCTL> switchmode -shardgroup dbs2
Monitor the generated tasks and verify the resulting replication unit modes. Confirm that the required tasks have completed and that the intended replication units are read-write before directing application writes to the new writer:
GDSCTL> config task
GDSCTL> status ru