Skip to content

Add enable/disable balancing collections #1879

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/reference/method/sh.enableBalancing-param.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ object:
field:
optional: false
type: param
name: collection
name: namespace
type: string
position: 1
description: |
Expand Down
4 changes: 2 additions & 2 deletions source/reference/method/sh.enableBalancing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ sh.enableBalancing()
Description
-----------

.. method:: sh.enableBalancing(collection)
.. method:: sh.enableBalancing(namespace)

Enables the balancer for the specified sharded collection.
Enables the balancer for the specified namespace of the sharded collection.

The :method:`sh.enableBalancing()` method has the following parameter:

Expand Down
80 changes: 80 additions & 0 deletions source/tutorial/manage-sharded-cluster-balancer.txt
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,83 @@ is active:

When the backup procedure is complete you can reactivate
the balancer process.

Disable Balancing on a Collection
---------------------------------

You can disable balancing for a specific collection with the
:method:`sh.disableBalancing()` method. You may want to disable the
balancer for a specific collection to support maintenance operations or
atypical workloads, for example, during data ingestions or data exports.

When you disable balancing on a collection, MongoDB will not interrupt in
progress migrations.

To disable balancing on a collection, issue the following from the
:program:`mongo` shell with the full namespace:

.. code-block:: javascript

sh.disableBalancing(<namespace>)

For example:

.. code-block:: javascript

sh.disableBalancing("students.grades")

Enable Balancing on a Collection
--------------------------------

You can enable balancing for a specific collection with the
:method:`sh.enableBalancing()` method.

When you enable balancing for a collection, MongoDB will not *immediately*
begin balancing data. However, if the data in your sharded collection is
not balanced, MongoDB will be able to begin distributing the data more
evenly.

To enable balancing on a collection, issue the following from the
:program:`mongo` shell with the full namespace:

.. code-block:: javascript

sh.enableBalancing(<namespace>)

For example:

.. code-block:: javascript

sh.enableBalancing("students.grades")

Confirm Balancing is Enabled or Disabled
----------------------------------------

To confirm balancing for a collection is enabled or disabled, type this
command on a :program:`mongos` to check the status of your collection
``<namespace>`` in the ``collections`` collection in the
``config`` database:

.. code-block:: javascript

db.getSiblingDB("config").collections.findOne({_id : <namespace>}).noBalance;

For example:

.. code-block:: javascript

db.getSiblingDB("config").collections.findOne({_id : "students.grades"}).noBalance;

This command will return a null error, true, false, or no output:

- A null error indicates the collection name is incorrect.

- If the result is true, balancing is disabled.

- If the result is false, balancing is enabled currently but has been
disabled in the past for the collection. Balancing of this collection
will begin the next time the balancer runs.

- If this command returns no output, balancing is enabled currently and
has never been disabled in the past for this collection. Balancing of
this collection will begin the next time the balancer runs.