Back to Redis

Failover

content/operate/rs/references/rest-api/requests/shards/actions/failover.md

latest6.7 KB
Original Source
MethodPathDescription
POST/v1/shards/actions/failoverFail over multiple shards
POST/v1/shards/{uid}/actions/failoverFail over a specific shard

Fail over multiple shards {#post-multi-shards}

POST /v1/shards/actions/failover

Performs failover on the primary shards specified by shard_uids in the request body, and promotes their replicas to primary shards. This request is asynchronous.

The cluster automatically manages failover to ensure high availability. Use this failover REST API request only for testing and planned maintenance.

Required permissions

Permission nameRoles
[failover_shard]({{< relref "/operate/rs/references/rest-api/permissions#failover_shard" >}})admin
cluster_member
db_member

Request {#post-multi-request}

Example HTTP request

POST /v1/shards/actions/failover

Example JSON body

json
{
    "shard_uids": ["2","4","6"]
}

Request headers

KeyValueDescription
Hostcnm.cluster.fqdnDomain name
Acceptapplication/jsonAccepted media type

Request body {#post-multi-request-body}

The request body is a JSON object that can contain the following fields:

FieldTypeDescription
shard_uidsarray of stringsList of primary shard UIDs to fail over. The shards must belong to the same database.
dead_uidsarray of stringsPrimary shards to avoid stopping. Optional.
dead_nodesarray of stringsNodes that should not be drained or used for promoted replica shards. Optional.
dry_runbooleanDetermines whether the failover is actually done. If true, will just do a dry run. If the dry run succeeds, the request returns a 200 OK status code. Otherwise, it returns a JSON object with an error code and description. Optional.
force_rebindbooleanRebind after promotion. Optional.
redis_version_upgradestringNew version of the promoted primary shards. Optional.

Response {#post-multi-response}

Returns a JSON object with an action_uid. You can track the action's progress with a [GET /v1/actions/<action_uid>]({{<relref "/operate/rs/references/rest-api/requests/actions#get-action">}}) request.

Example JSON body

json
{
    "action_uid": "e5e24ddf-a456-4a7e-ad53-4463cd44880e",
    "description": "Failover was triggered"
}

Status codes {#post-multi-status-codes}

CodeDescription
200 OKNo error.
400 Bad RequestShard is a replica or the specified failover shards are not in the same database.
404 Not FoundA list of shard UIDs is required and not given, or a specified shard does not exist.
409 ConflictDatabase is currently busy.

Error codes {#put-multi-error-codes}

When errors are reported, the server may return a JSON object with error_code and message field that provide additional information. The following are possible error_code values:

CodeDescription
db_busyDatabase is currently busy.
failover_shards_different_bdbAll failover shards should be in the same database.
shard_is_slaveShard is a replica.
shard_not_existShard does not exist.
shard_uids_requiredList of shard UIDs is required and not given.

Fail over shard {#post-shard}

POST /v1/shards/{int: uid}/actions/failover

Performs failover on the primary shard with the specified shard_uid, and promotes its replica shard to a primary shard. This request is asynchronous.

The cluster automatically manages failover to ensure high availability. Use this failover REST API request only for testing and planned maintenance.

Required permissions

Permission nameRoles
[failover_shard]({{< relref "/operate/rs/references/rest-api/permissions#failover_shard" >}})admin
cluster_member
db_member

Request {#post-request}

Example HTTP request

POST /v1/shards/1/actions/failover

Example JSON body

json
{
    "force_rebind": true
}

Request headers

KeyValueDescription
Hostcnm.cluster.fqdnDomain name
Acceptapplication/jsonAccepted media type

URL parameters

FieldTypeDescription
uidintegerThe unique ID of the shard to fail over.

Request body {#post-request-body}

The request body is a JSON object that can contain the following fields:

FieldTypeDescription
dead_uidstringPrimary shard to avoid stopping. Optional.
dead_nodesarray of stringsNodes that should not be drained or used for promoted replica shards. Optional.
dry_runbooleanDetermines whether the failover is actually done. If true, will just do a dry run. If the dry run succeeds, the request returns a 200 OK status code. Otherwise, it returns a JSON object with an error code and description. Optional.
force_rebindbooleanRebind after promotion. Optional.
redis_version_upgradestringNew version of the promoted primary shards. Optional.

Response {#post-response}

Returns a JSON object with an action_uid. You can track the action's progress with a [GET /v1/actions/<action_uid>]({{<relref "/operate/rs/references/rest-api/requests/actions#get-action">}}) request.

Example JSON body

json
{
    "action_uid": "e5e24ddf-a456-4a7e-ad53-4463cd44880e",
    "description": "Failover was triggered"
}

Status codes {#post-status-codes}

CodeDescription
200 OKNo error.
400 Bad RequestShard is a replica.
404 Not FoundSpecified shard does not exist.
409 ConflictDatabase is currently busy.

Error codes {#put-error-codes}

When errors are reported, the server may return a JSON object with error_code and message field that provide additional information. The following are possible error_code values:

CodeDescription
db_busyDatabase is currently busy.
shard_is_slaveShard is a replica.
shard_not_existShard does not exist.