Back to Redis

Rebalance

content/operate/rs/references/rest-api/requests/bdbs/actions/rebalance.md

latest4.3 KB
Original Source
MethodPathDescription
PUT/v1/bdbs/{uid}/actions/rebalanceRebalance database shards

Rebalance database shards {#put-bdbs-actions-rebalance}

sh
PUT /v1/bdbs/{int: uid}/actions/rebalance

Distributes the database's shards across nodes based on the database's shard placement policy. See [Shard placement policy]({{<relref "/operate/rs/databases/memory-performance/shard-placement-policy">}}) for more information about shard placement and available policies.

Required permissions

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

Request {#put-request}

Example HTTP request

sh
PUT /v1/bdbs/1/actions/rebalance

Dry-run example:

sh
PUT /v1/bdbs/1/actions/rebalance?only_failovers=true&dry_run=true

URL parameters

FieldTypeDescription
uidintegerThe unique ID of the database to rebalance.

Query parameters

FieldTypeDescription
dry_runbooleanIf true, returns the blueprint of the rebalanced database without actually changing the database. Default is false.
only_failoversbooleanIf true, only runs failovers and no migrations. Default is false.
max_operationsintegerOptional. The number of operations to do. Only works if only_failovers is true. If not provided, uses the number of the database's primary-replica pairs.

Response {#put-response}

  • If dry_run is false, returns 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.

  • If dry_run is true, returns the balanced shards' blueprint.

    You can rearrange shards according to this blueprint if you use it in the shards_blueprint field of a [rearrange database shards]({{<relref "/operate/rs/references/rest-api/requests/bdbs/actions/optimize_shards_placement#put-bdbs-rearrange-shards">}}) request.

    You should also pass the rebalance shards' cluster-state-id response header as a request header of the rearrange database shards request to make sure the optimized shard placement is relevant for the current cluster state. The cluster will reject the update if its state changed since the optimal shards placement blueprint was generated.

Example response

If dry_run is false:

sh
{
    "action_uid": "21ad01d5-55aa-4ec6-b5c0-44dc95176486"
}

If dry_run is true:

sh
[
  {
    "nodes": [
      {
        "node_uid": "3",
        "role": "master"
      },
      {
        "node_uid": "1",
        "role": "slave"
      }
    ],
    "slot_range": "5461-10922"
  },
  {
    "nodes": [
      {
        "node_uid": "3",
        "role": "master"
      },
      {
        "node_uid": "1",
        "role": "slave"
      }
    ],
    "slot_range": "10923-16383"
  },
  {
    "nodes": [
      {
        "node_uid": "3",
        "role": "master"
      },
      {
        "node_uid": "1",
        "role": "slave"
      }
    ],
    "slot_range": "0-5460"
  }
]

Status codes {#put-status-codes}

CodeDescription
200 OKWhen dry_run is false: The request is accepted and is being processed. When the database is recovered, its status will become active.
When dry_run is true: No error.
400 Bad RequestBad request. Invalid input parameters.
404 Not FoundAttempting to perform an action on a nonexistent database.
406 Not AcceptableNot enough resources in the cluster to host the database.
409 ConflictDatabase is currently busy with another action, recovery is already in progress, or is not in a recoverable state.
500 Internal Server ErrorInternal server error.