How to Automatically Rebalance Shards when a New Node is Added?

Last updated 18, Apr 2024

Question

Is there any rladmin command or procedure to re-balance a database when a node is added to a cluster? While it is possible to migrate specific shards, is there some routine similar to the sparse policy when a clustered database is deployed?

Answer

Optimized distribution of the shards across the nodes, can be achieved using the REST API. The procedure to follow is:

  1. Enable sparse placement policy on the database
  2. Use the following commands to generate the blueprint
curl -l -k -u "<ADMIN_USERNAME>:<ADMIN_PASSWORD>" -X GET -H 'Content-type: application/json' "https://127.0.0.1:9443/v1/bdbs/10/actions/optimize_shards_placement"
Copy code

This will indicate the optimal placement of the shards in the nodes. Check rladmin and see if this differs from what you currently have. This blueprint can be applied to a database using the REST API bdbs endpoint. You will need to get the cluster-state-id header from the GET request and resubmit that in the header of this PUT request with the blueprint array as the value of shards_blueprint.

curl -l -k -u "<ADMIN_USERNAME>:<ADMIN_PASSWORD>" -X PUT -H 'Content-type: application/json' -d '{"shards_blueprint": XXX}' https://127.0.0.01:9443/v1/bdbs/10
Copy code

Where the XXX is the output of the previous GET command

References

Refer to "Optimize shards placement database action requests"