|
| 1 | +.. _sharding-update-existing-zone: |
| 2 | + |
| 3 | +============================= |
| 4 | +Update an Existing Shard Zone |
| 5 | +============================= |
| 6 | + |
| 7 | +.. contents:: On this page |
| 8 | + :local: |
| 9 | + :backlinks: none |
| 10 | + :depth: 2 |
| 11 | + :class: singlecol |
| 12 | + |
| 13 | +.. facet:: |
| 14 | + :name: genre |
| 15 | + :values: tutorial |
| 16 | + |
| 17 | +After you specify a range of values for a shard zone, you can update the |
| 18 | +shard zone range if your application's requirements change. |
| 19 | + |
| 20 | +To update an existing shard zone, perform these steps: |
| 21 | + |
| 22 | +#. Stop the :term:`balancer`. |
| 23 | + |
| 24 | +#. Remove the old range from the zone. |
| 25 | + |
| 26 | +#. Update the zone's range. |
| 27 | + |
| 28 | +#. Restart the balancer. |
| 29 | + |
| 30 | +About this Task |
| 31 | +--------------- |
| 32 | + |
| 33 | +- Zone ranges are inclusive of the lower boundary and exclusive of the |
| 34 | + upper boundary. |
| 35 | + |
| 36 | +- After you modify a zone, the balancer must migrate chunks to the |
| 37 | + appropriate zones based on the new range of values. Until balancing |
| 38 | + completes, some chunks may reside on the wrong shard given the |
| 39 | + configured zones for the sharded cluster. |
| 40 | + |
| 41 | +Before you Begin |
| 42 | +---------------- |
| 43 | + |
| 44 | +To complete this tutorial, you must :ref:`deploy a sharded cluster |
| 45 | +<sharding-procedure-setup>` with a sharded collection and create a zone |
| 46 | +to modify. |
| 47 | + |
| 48 | +This example uses a sharded collection named ``users`` in the |
| 49 | +``records`` database, sharded by the ``zipcode`` field. |
| 50 | + |
| 51 | +.. procedure:: |
| 52 | + :style: normal |
| 53 | + |
| 54 | + .. step:: Add a shard to a zone called NYC |
| 55 | + |
| 56 | + .. code-block:: none |
| 57 | + |
| 58 | + sh.addShardToZone(<shard name>, "NYC") |
| 59 | + |
| 60 | + .. step:: Specify a range of zipcode values for the NYC zone |
| 61 | + |
| 62 | + .. code-block:: javascript |
| 63 | + |
| 64 | + sh.updateZoneKeyRange("records.users", { zipcode: "10001" }, { zipcode: "10281" }, "NYC" ) |
| 65 | + |
| 66 | +Steps |
| 67 | +----- |
| 68 | + |
| 69 | +The following procedure modifies the range of ``zipcode`` values for the |
| 70 | +``NYC`` zone to be ``11201`` through ``11240``. |
| 71 | + |
| 72 | +.. procedure:: |
| 73 | + :style: normal |
| 74 | + |
| 75 | + .. step:: Stop the balancer |
| 76 | + |
| 77 | + .. code-block:: javascript |
| 78 | + |
| 79 | + sh.stopBalancer() |
| 80 | + |
| 81 | + .. step:: Remove the current NYC range from the zone |
| 82 | + |
| 83 | + .. code-block:: javascript |
| 84 | + |
| 85 | + sh.removeRangeFromZone("records.user", { zipcode: "10001" }, { zipcode: "10281" } ) |
| 86 | + |
| 87 | + .. step:: Update the zone key range for the NYC zone |
| 88 | + |
| 89 | + .. code-block:: javascript |
| 90 | + |
| 91 | + sh.updateZoneKeyRange("records.users", { zipcode: "11201" }, { zipcode: "11240" }, "NYC" ) |
| 92 | + |
| 93 | + .. step:: Restart the balancer |
| 94 | + |
| 95 | + .. code-block:: javascript |
| 96 | + |
| 97 | + sh.startBalancer() |
| 98 | + |
| 99 | +Learn More |
| 100 | +---------- |
| 101 | + |
| 102 | +- :method:`sh.removeRangeFromZone()` |
| 103 | + |
| 104 | +- :method:`sh.updateZoneKeyRange()` |
| 105 | + |
| 106 | +- :ref:`workload-isolation` |
0 commit comments