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.

mongosh에서 이 명령을 sh.updateZoneKeyRange() 헬퍼 메서드를 통해서도 실행할 수 있습니다.

헬퍼 메서드는 mongosh 사용자에게 편리하지만 데이터베이스 명령과 동일한 수준의 정보를 반환하지 못할 수 있습니다. 편의가 필요하지 않거나 추가 리턴 필드가 필요한 경우 데이터베이스 명령을 사용합니다.

updateZoneKeyRange를 실행하려면 db.runCommand( { <command> } ) 메서드를 사용합니다.

You must run addShardToZone on the admin database.

이 명령은 다음 환경에서 호스팅되는 배포에서 사용할 수 있습니다.

  • MongoDB Atlas: 클라우드에서의 MongoDB 배포를 위한 완전 관리형 서비스

중요

이 명령은 서버리스 인스턴스에서는 지원되지 않습니다. 자세한 내용은 지원되지 않는 명령을 참조하세요.

명령은 다음과 같은 구문을 가집니다:

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

이 명령은 다음 필드를 사용합니다.

Parameter
유형
설명

updateZoneKeyRange

문자열

The namespace of the collection to associate with the range.

The collection must be sharded for the command to succeed.

min

문서

샤드 키 값 범위의 포괄적 하한입니다.

샤드 키의 각 필드를 <fieldname> : <value> 형식으로 지정합니다. 값은 샤드 키와 동일한 BSON 유형이어야 합니다.

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

max

문서

샤드 키 값 범위의 배타적 상한입니다.

샤드 키의 각 필드를 <fieldname> : <value> 형식으로 지정합니다. 값은 샤드 키와 동일한 BSON 유형이어야 합니다.

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

zone

문자열

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 의 새 범위를 만들 수 없습니다.

구역은 여러 범위의 데이터와 연결될 수 있지만 범위는 최대 단일 구역과 연결될 수 있습니다.

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). 버전 4 부터.0.3, 비어 있거나 존재하지 않는 컬렉션에 구역 및 구역 범위를 생성하면 MongoDB가 컬렉션을 샤딩할 때 초기 청크 생성 및 배포 프로세스를 최적화할 수 있습니다. 이 최적화된 프로세스는 샤딩 후 구역을 생성하는 것보다 적은 밸런서 오버헤드로 구역 샤딩을 더 빠르게 설정할 수 있도록 지원합니다. 밸런서 는 최적화된 초기 청크 생성 및 배포 후 모든 청크 관리를 수행합니다.

초기 청크 배포를 위한 구역 및 구역 범위를 정의하는 예 는 비어 있거나 존재하지 않는 collection에 대한 구역 및 구역 범위 사전 정의를 참조하세요.

MongoDB는 복합 해시 인덱스 에서 컬렉션 샤딩을 지원합니다. MongoDB는 복합 해시 샤드 키에서 비어 있거나 존재하지 않는 컬렉션을 샤딩할 때 최적화된 초기 청크 생성 및 배포를 수행할 수 있습니다.

해시된 필드가 샤드 키의 접두사(즉, 샤드 키의 첫 번째 필드)인 경우, MongoDB가 초기 청크 생성 및 배포를 수행하려면 다음 사항이 모두 충족되어야 합니다.

해시 된 필드 가 샤드 키 의 접두사가 아닌 경우(즉, 샤드 키 에 해시되지 않은 선행 필드가 하나 이상 있는 경우) MongoDB 가 초기 청크 생성 및 배포를 수행하려면 다음 사항이 모두 충족되어야 합니다.

  • 컬렉션에는 고유한 접두사 필드 값의 각 조합에 대해 하나의 구역 범위가 있습니다(예: 해시된 필드 앞에 오는 모든 필드).

  • 각 구역 범위 의 하한에 대해 해시 필드 와 모든 후속 필드에 대해 MinKey 를 지정합니다.

  • 각 구역 범위에 대해 하나 이상의 상한 접두사 필드는 하한 접두사 필드와 달라야 합니다 .

  • 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.

범위와 구역 간의 연결을 제거하면 제약 조건이 제거되어 청크가 해당 구역 내부의 샤드 범위에 포함되도록 유지됩니다. 다음 밸런서 라운드에서 밸런서는 이전에 해당 구역에 포함된 청크를 마이그레이션할 수 있습니다.

샤드 cluster에서 마이그레이션이 작동하는 방식에 대한 자세한 내용은 샤드 cluster 밸런서 설명서를 참조하세요.

구역 범위는 항상 하한 경계를 포함하고 상한 경계를 제외합니다.

컬렉션을 제거하면 관련된 영역/태그 범위가 삭제됩니다.

이전 버전에서는 MongoDB가 삭제된 컬렉션에 대한 태그 연결을 제거하지 않았으며, 나중에 같은 이름으로 새 컬렉션을 만들면 이전 태그 연결이 새 컬렉션에 적용됩니다.

authentication 으로 실행되는 샤드 클러스터의 경우 다음 중 하나를 사용하여 인증해야 합니다.

  • config 데이터베이스의 다양한 컬렉션에 대해 지정된 작업이 포함된 권한을 가진 사용자입니다.

    또는,

  • 클러스터 리소스에 대한 가 enableSharding 포함된 권한을 가진 사용자입니다.

clusterAdmin 또는 clusterManager 기본 제공 역할에는 updateZoneKeyRange 발급에 적합한 권한이 있습니다. 자세한 내용은 역할 기반 액세스 제어 에 대한 설명서 페이지를 참조하세요.

샤드 키가 { a : 1 } 인 샤드 컬렉션 exampledb.collection 이 주어지면 다음 작업은 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 는 대상 범위의 경계와 정확히 일치해야 합니다. 다음 작업은 이전에 생성된 범위를 제거하려고 시도하지만 { a : 0 }min 바운드로 지정합니다.

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"
}
)