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 helperssh.updateZoneKeyRange()
andsh.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 | タイプ | 説明 |
---|---|---|
| string | The namespace of the collection to associate with the range. The collection must be sharded for the command to succeed. |
| ドキュメント | シャードキー値の範囲の包括的下限。 シャードキーの各フィールドを To use hashed sharding, the field value of |
| ドキュメント | シャードキー値の範囲の排他的上限。 シャードキーの各フィールドを To use hashed sharding, the field value of |
| string | The name of the zone to associate with the range bounded by the
If the value does not match an existing zone, the command fails. Specify |
動作
If no zone range matches the minimum and maximum bounds passed to
updateZoneKeyRange
, nothing is removed.
updateZoneKeyRange
インスタンスに接続されている場合にのみmongos
を発行します。
mongosh
provides two helper methods:
sh.updateZoneKeyRange()
for adding a range of shard key values to a zone.sh.removeRangeFromZone()
for removing a range of shard key values from a zone.
シャーディングされたコレクションの既存の範囲と下限と上限が重複するシャードキー値の範囲は作成できません。 たとえば、 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" } )
次の操作では、 null
をzone
フィールドに渡すことで、以前に作成した範囲が削除されます。
admin = db.getSiblingDB("admin") admin.runCommand( { updateZoneKeyRange : "exampledb.collection", min : { a : 1 }, max : { a : 10 }, zone : null } )
min
とmax
は、ターゲット範囲の境界と完全に一致する必要があります。 次の操作は、以前に作成した範囲を削除しようとしますが、 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" } )