Docs Menu

updateZoneKeyRange

updateZoneKeyRange

The updateZoneKeyRange administrative command can either create or remove the association between a range of shard key values and a ゾーン.

You can run updateZoneKeyRange database command and its helpers sh.updateZoneKeyRange() and sh.addTagRange() on an unsharded collection or a non-existing collection.

Tip

mongoshでは、このコマンドはsh.updateZoneKeyRange()ヘルパー メソッドを通じて実行することもできます。

ヘルパー メソッドはmongoshユーザーには便利ですが、データベースコマンドと同じレベルの情報は返されない可能性があります。 便宜上必要ない場合、または追加の戻りフィールドが必要な場合は、 データベースコマンドを使用します。

updateZoneKeyRange を実行するには、db.runCommand( { <command> } ) メソッドを使用します。

You must run addShardToZone on the admin database.

このコマンドは、次の環境でホストされている配置で使用できます。

  • MongoDB Atlas はクラウドでの MongoDB 配置のためのフルマネージド サービスです

重要

このコマンドはサーバーレスインスタンスではサポートされていません。 詳細については、「サポートされていないコマンド 」を参照してください。

  • MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン

  • MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン

このコマンドの構文は、次のとおりです。

db.adminCommand(
{
updateZoneKeyRange: <string>,
min: <document>,
max: <document>,
zone: <string> | <null>
}
)

このコマンドは、次のフィールドを使用します。

Parameter
タイプ
説明

updateZoneKeyRange

string

The namespace of the collection to associate with the range.

The collection must be sharded for the command to succeed.

min

ドキュメント

シャードキー値の範囲の包括的下限。

シャードキーの各フィールドを<fieldname> : <value>の形式で指定します。 値は、シャードキーと同じ BSON type である必要があります。

To use hashed sharding, the field value of min needs to be of type NumberLong.

max

ドキュメント

シャードキー値の範囲の排他的上限。

シャードキーの各フィールドを<fieldname> : <value>の形式で指定します。 値は、シャードキーと同じ BSON type である必要があります。

To use hashed sharding, the field value of max needs to be of type NumberLong.

zone

string

The name of the zone to associate with the range bounded by the min and max.

If the value does not match an existing zone, the command fails.

Specify null to remove the association between the range with lower bounds of min and upper bound of max and the updateZoneKeyRange collection. The values of min and max must match exactly the target range.

If no zone range matches the minimum and maximum bounds passed to updateZoneKeyRange, nothing is removed.

updateZoneKeyRangeインスタンスに接続されている場合にのみmongos を発行します。

mongosh provides two helper methods:

シャーディングされたコレクションの既存の範囲と下限と上限が重複するシャードキー値の範囲は作成できません。 たとえば、 1から10の既存の範囲がある場合、 5から20の新しい範囲は作成できません。新しい範囲は既存の範囲と重複するためです。

ゾーンには複数のデータ範囲を関連付けることができますが、範囲は最大で 1 つのゾーンに関連付けることができます。

When removing the association between a range and a zone, updateZoneKeyRange does not remove the zone. Use the removeShardFromZone command to remove the association between a zone and a shard.

シャーディングされたクラスター内のゾーンの詳細については、ゾーンのマニュアル ページを参照してください。

空のコレクションまたは存在しないコレクションで ゾーンシャーディングupdateZoneKeyRange を実行することを検討している場合は、コレクションをシャーディングする 前に 、 を使用してゾーンとゾーン範囲を作成します( 以降4.0.2 )。Starting in version 4.0.3, 空のコレクションまたは存在しないコレクションにゾーンとゾーン範囲を作成することで、MongoDB はコレクションをシャーディングするときに初期チャンクの作成と分散プロセスを最適化できます。 この最適化されたプロセスにより、シャーディング後にゾーンを作成するよりもバランサーのオーバーヘッドが少なく、ゾーンシャーディングの迅速なセットアップがサポートされます。 バランサーは、最適化された最初のチャンク作成と分散後に、すべてのチャンク管理を実行します。

最初のチャンク分散のゾーンとゾーン範囲の定義の例については、「空または存在しないコレクションのゾーンとゾーン範囲の事前定義 」を参照してください。

MongoDB は、ハッシュされた複合インデックスでのコレクションのシャーディングをサポートしています。 MongoDB は、空のコレクションまたは存在しないコレクションを 複合ハッシュされたシャードキー でシャーディングするときに、最適化された初期チャンクの作成と分散を実行できます。

ハッシュされたフィールドがシャードキーのプレフィックス(つまり、シャードキーの最初のフィールド)である場合、MongoDB が初期チャンクの作成と分散を実行するには、次のすべてが当てはまる必要があります。

  • コレクションには単一のゾーン範囲があり、すべての下限フィールドにはMinKey 、すべての上限フィールドにはMaxKeyが含まれます。

  • sh.shardCollection()presplitHashedZones: trueオプションを指定します。

ハッシュされたフィールドがシャードキーのプレフィックスではない場合(つまり、シャードキーにハッシュされていない先頭フィールドが 1 つ以上ある場合)、MongoDB が初期チャンクの作成と分散を実行するには、次のすべてが当てはまる必要があります。

  • コレクションには、個別のプレフィックスフィールド値の組み合わせごとに 1 つのゾーン範囲があります(つまり ハッシュされたフィールドに先行するすべてのフィールド)。

  • 各ゾーン範囲の下限について、ハッシュされたフィールドとそれ以降のすべてのフィールドにMinKeyを指定します。

  • 各ゾーン範囲について、少なくとも 1 つの上限プレフィックス フィールドがその下限のカウンター と 異なる必要があります。

  • sh.shardCollection()presplitHashedZones: trueオプションを指定します。

複合ハッシュされたシャードキーでの初期チャンク分散のためのゾーンとゾーン範囲の定義のより詳細な例については、「空または存在しないコレクションのゾーンとゾーン範囲の事前定義 」を参照してください。

After successfully running updateZoneKeyRange, there may be chunk migrations during the next balancer round.

After adding a range to a zone, the バランサー must first run in order to migrate any chunks whose ranges are covered by the zone to shards inside of that zone. Until balancing completes, some chunks may reside on the wrong shard given the configured zones for the sharded cluster.

範囲とゾーンの間の関連付けを削除すると、そのゾーン内のシャードで範囲によってカバーされるチャンクを維持する制約が削除されます。 次のバランサー ラウンド中に、バランサーは以前に ゾーンによってカバーされていたチャンクを移行する場合があります。

シャーディングされたクラスターで移行がどのように機能するかについて詳しくは、 シャーディングされたクラスター バランサーのドキュメントを参照してください。

ゾーン範囲は、常に下限を含み、上限を含まない範囲です。

コレクションを削除すると、それに関連付けられたゾーンやタグの範囲も削除されます。

以前のバージョンでは、MongoDB は削除されたコレクションのタグ関連付けを削除せず、後で同じ名前で新しいコレクションを作成すると、古いタグの関連付けが新しいコレクションに適用されます。

認証 を使用して実行されているシャーディングされたクラスターの場合は、次のいずれかとして認証する必要があります。

  • configデータベース内のさまざまなコレクションに対して指定されたアクションを含む特権を持つユーザー:

    または、あるいは、

  • クラスター リソースでenableSharding を含む 権限 を持つユーザー。

clusterAdminまたはclusterManagerの組み込みロールには、 updateZoneKeyRangeを発行するための適切な権限があります。 詳細については、ロールベースのアクセス制御に関するドキュメントページを参照してください。

シャーディングされたコレクションexampledb.collectionとシャードキーが{ a : 1 }の場合、次の操作を実行すると、 alphaゾーンに下限が1で上限が10の範囲が作成されます。

admin = db.getSiblingDB("admin")
admin.runCommand(
{
updateZoneKeyRange : "exampledb.collection",
min : { a : 1 },
max : { a : 10 },
zone : "alpha"
}
)

次の操作では、 nullzoneフィールドに渡すことで、以前に作成した範囲が削除されます。

admin = db.getSiblingDB("admin")
admin.runCommand(
{
updateZoneKeyRange : "exampledb.collection",
min : { a : 1 },
max : { a : 10 },
zone : null
}
)

minmaxは、ターゲット範囲の境界と完全に一致する必要があります。 次の操作は、以前に作成した範囲を削除しようとしますが、 minの限界として{ a : 0 }を指定します。

admin = db.getSiblingDB("admin")
admin.runCommand(
{
updateZoneKeyRange : "exampledb.collection",
min : { a : 0 },
max : { a : 10 },
zone : null
}
)

While the range of { a : 0 } and { a : 10 } encompasses the existing range, it is not an exact match and therefore updateZoneKeyRange does not remove anything.

Given a sharded collection exampledb.collection with a shard key of { a : 1, b : 1 }, the following operation creates a range covering the lower bound of { a: 1, b : 1 } and an upper bound of { a : 10, b : 10} and associates it with the alpha zone:

admin = db.getSiblingDB("admin")
admin.runCommand(
{
updateZoneKeyRange : "exampledb.collection",
min : { a : 1, b : 1 },
max : { a : 10, b : 10 },
zone : "alpha"
}
)