How Do I Manage the Balancer?
Scenarios
- Enable the balancer during off-peak hours.
- Disable the balancer during peak hours.
- Schedule a balancing window so that the balancer can work during off-peak hours.
Constraints
- The balancer applies only to cluster instances.
- DDS enables the balancer by default.
Procedure
- Connect to a cluster instance using Mongo Shell.
- After connecting to a dds mongos node, run the following command to switch to the config database:
use config
- Run the following command to enable the balancer:
sh.setBalancerState(true)
- Connect to a cluster instance using Mongo Shell.
- After connecting to a dds mongos node, run the following command to switch to the config database:
use config
- Run the following command to check the status of the balancer:
while( sh.isBalancerRunning() ) { print("waiting..."); sleep(500); }- If the command output is empty, the balancer is not executing any task. In this case, you can proceed to disable the balancer.
- If the command output is waiting, the balancer is migrating chunks. In this case, you cannot disable the balancer. Otherwise, data may become inconsistent.
- If the command output in 3 is empty, run the following command to disable the balancer:
sh.stopBalancer()
To prevent chunk migration from affecting your businesses, you can perform the following operations to schedule a balancing window.
Before scheduling a balancing window, ensure that the balancer is enabled by referring to Enabling the Balancer.
- Connect to a cluster instance using Mongo Shell.
- After connecting to a dds mongos node, run the following command to switch to the config database:
use config
- Run the following commands to schedule a balancing window:
db.adminCommand({"setBalancerActiveWindow": 1, start : "<start-time>", stop : "<stop-time>"})
- <start-time>: indicates the beginning of the balancing window. Specify the time in the HH:MM format (UTC time). For HH values, use hour values ranging from 00 to 23. For MM value, use minute values ranging from 00 to 59.
- <stop-time>: indicates the end of the balancing window. Specify the time in the HH:MM format (UTC time). For HH values, use hour values ranging from 00 to 23. For MM value, use minute values ranging from 00 to 59.
- If the error message "CommandNotFound" is displayed when you run the setBalancerActiveWindow command as user rwuser to schedule a balancing window, the minor version is too low. In this case, upgrade the minor version of the instance and try again. Alternatively, submit a service ticket.
You can run the sh.status() command to check a balancing window schedule. The following command output in Figure 1 shows that the balancing window is 22:00 to 24:00.
If you have set the balancing window and wish to remove the schedule so that the balancer is always running, run the following command:
db.adminCommand({ 'unsetBalancerActiveWindow' : 1 }) Related APIs
| API | Description |
|---|---|
| Queries the balancer setting of a cluster instance. | |
| Configures the balancer of a cluster instance. | |
| Sets the active window for the balancer of a cluster instance. |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot
