Primary replica failover
In a cluster with multiple replicas, you can switch the primary replica if needed.
The switchover typically takes less than a minute. During the switchover, the cluster may be unwriteable for a few seconds.
- Open the folder dashboard
. - Navigate to the Yandex StoreDoc service.
- Click the name of your cluster and select the Hosts tab.
- Locate the
PRIMARYhost in the list, click in its row, and select Step down.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.
To perform a primary replica switchover, run this command:
yc managed-mongodb hosts stepdown <current_primary_replica_name> \
--name=<cluster_name>
You can get the primary replica name for the required shard from the cluster’s host list, and the cluster name from the list of clusters in your folder.
-
Get an IAM token for API authentication and place it in an environment variable:
export IAM_TOKEN="<IAM_token>" -
Call the Cluster.StepdownHosts method, e.g., via the following cURL
request:curl \ --request POST \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://mdb.api.cloud.yandex.net/managed-mongodb/v1/clusters/<cluster_ID>:stepdownHosts' \ --data '{ "hostNames": [ "<current_primary_replica_name>" ] }'You can get the cluster ID from the list of clusters in your folder, and the primary replica name for the required shard from the cluster’s host list.
-
Check the server response to make sure your request was successful.
-
Get an IAM token for API authentication and place it in an environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume that the repository contents reside in the
~/cloudapi/directory. -
Call the ClusterService.StepdownHosts method, e.g., via the following gRPCurl
request:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/mongodb/v1/cluster_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>", "host_names": [ "<current_primary_replica_name>" ] }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.mongodb.v1.ClusterService.StepdownHostsYou can get the cluster ID from the list of clusters in your folder, and the primary replica name for the required shard from the cluster’s host list.
-
Check the server response to make sure your request was successful.