-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RS: Add rebalance database shards REST API reference #733
Open
rrelledge
wants to merge
1
commit into
release-rs-fuya-fuya
Choose a base branch
from
DOC-4191
base: release-rs-fuya-fuya
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
content/operate/rs/references/rest-api/requests/bdbs/actions/rebalance.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
--- | ||
Title: Rebalance database requests | ||
alwaysopen: false | ||
categories: | ||
- docs | ||
- operate | ||
- rs | ||
description: REST API requests to rebalance database shards | ||
headerRange: '[1-2]' | ||
linkTitle: rebalance | ||
weight: $weight | ||
--- | ||
|
||
| Method | Path | Description | | ||
|--------|------|-------------| | ||
| [PUT](#put-bdbs-actions-rebalance) | `/v1/bdbs/{uid}/actions/rebalance` | Rebalance 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 name | Roles | | ||
|-----------------|-------| | ||
| [view_bdb_info]({{< relref "/operate/rs/references/rest-api/permissions#view_bdb_info" >}}) | admin<br />cluster_member<br />cluster_viewer<br />db_member<br />db_viewer | | ||
|
||
### Request {#put-request} | ||
|
||
#### Example HTTP request | ||
|
||
```sh | ||
PUT /bdbs/1/actions/rebalance | ||
``` | ||
|
||
Dry-run example: | ||
|
||
```sh | ||
PUT /bdbs/1/actions/rebalance?only_failovers=true&dry_run=true | ||
``` | ||
|
||
#### URL parameters | ||
|
||
| Field | Type | Description | | ||
|-------|------|-------------| | ||
| uid | integer | The unique ID of the database to rebalance. | | ||
|
||
#### Query parameters | ||
|
||
| Field | Type | Description | | ||
|-------|------|-------------| | ||
| dry_run | boolean | If true, returns the blueprint of the rebalanced database without actually changing the database. Default is false. | | ||
| only_failovers | boolean | If true, only runs failovers and no migrations. Default is false. | | ||
| max_operations | integer | Optional. 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} | ||
|
||
| Code | Description | | ||
|------|-------------| | ||
| [200 OK](https://www.rfc-editor.org/rfc/rfc9110.html#name-200-ok) | When `dry_run` is false: The request is accepted and is being processed. When the database is recovered, its status will become active.<br />When `dry_run` is true: No error. | | ||
| [400 Bad Request](https://www.rfc-editor.org/rfc/rfc9110.html#name-400-bad-request) | Bad request. Invalid input parameters. | | ||
| [404 Not Found](https://www.rfc-editor.org/rfc/rfc9110.html#name-404-not-found) | Attempting to perform an action on a nonexistent database. | | ||
| [406 Not Acceptable](https://www.rfc-editor.org/rfc/rfc9110.html#name-406-not-acceptable) | Not enough resources in the cluster to host the database. | | ||
| [409 Conflict](https://www.rfc-editor.org/rfc/rfc9110.html#name-409-conflict) | Database is currently busy with another action, recovery is already in progress, or is not in a recoverable state. | | ||
| [500 Internal Server Error](https://www.rfc-editor.org/rfc/rfc9110.html#name-500-internal-server-error) | Internal server error. | |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is right, but just in case: