Database Manual / Sharding / Zones / Manage

Update an Existing Shard Zone更新现有分片区域

After you specify a range of values for a shard zone, you can update the shard zone range if your application's requirements change.为分片区域指定一个值范围后,如果应用程序的要求发生变化,您可以更新分片区域范围。

To update an existing shard zone, perform these steps:要更新现有的分片区域,请执行以下步骤:

  1. Stop the balancer.停止平衡器
  2. Remove the old range from the zone.从区域中删除旧范围。
  3. Update the zone's range.更新区域的范围。
  4. Restart the balancer.重新启动平衡器。

About this Task关于此任务

  • Zone ranges are inclusive of the lower boundary and exclusive of the upper boundary.区域范围包括下边界,不包括上边界。
  • After you modify a zone, the balancer must migrate chunks to the appropriate zones based on the new range of values. Until balancing completes, some chunks may reside on the wrong shard given the configured zones for the sharded cluster.修改区域后,平衡器必须根据新的值范围将块迁移到适当的区域。在平衡完成之前,根据分片集群的配置区域,一些块可能会驻留在错误的分片上。

Before you Begin开始之前

To complete this tutorial, you must deploy a sharded cluster with a sharded collection and create a zone to modify.要完成本教程,您必须部署一个具有分片集合的分片集群,并创建一个要修改的区域。

This example uses a sharded collection named users in the records database, sharded by the zipcode field.此示例使用records数据库中名为users的分片集合,由zipcode字段分片。

1

Add a shard to a zone called NYC将一个分片添加到名为NYC的区域

sh.addShardToZone(<shard name>, "NYC")
2

Specify a range of zipcode values for the NYC zone为NYC区域指定一系列邮政编码值

sh.updateZoneKeyRange("records.users", { zipcode: "10001" }, { zipcode: "10281" }, "NYC" )

Steps步骤

The following procedure modifies the range of zipcode values for the NYC zone to be 11201 through 11240.以下过程将NYC区域的zipcode范围修改为1120111240

1

Stop the balancer停止平衡器

sh.stopBalancer()
2

Remove the current NYC range from the zone从区域中删除当前NYC范围

sh.removeRangeFromZone("records.user", { zipcode: "10001" }, { zipcode: "10281" } )
3

Update the zone key range for the NYC zone更新纽约市区域的区域键范围

sh.updateZoneKeyRange("records.users", { zipcode: "11201" }, { zipcode: "11240" }, "NYC" )
4

Restart the balancer重新启动平衡器

sh.startBalancer()

Learn More了解更多