Docs Menu

$shardedDataDistribution (집계)

$shardedDataDistribution

버전 6.0.3에 추가되었습니다.

샤드 컬렉션의 데이터 분포에 대한 정보를 반환합니다.

참고

이 집계 단계는 mongos에서만 사용할 수 있습니다.

이 집계 단계는 admin 데이터베이스에서 실행해야 합니다. 사용자에게 shardedDataDistribution 권한 조치가 있어야 합니다.

shardedDataDistribution 단계에는 다음과 같은 구문이 있습니다.

db.aggregate( [
{ $shardedDataDistribution: { } }
] )

$shardedDataDistribution 단계는 데이터베이스 의 각 샤딩된 컬렉션 에 대한 문서 배열 을 출력합니다. 이러한 문서에는 다음 필드가 포함되어 있습니다.

필드 이름
데이터 유형
설명

ns

문자열

샤드된 컬렉션의 네임스페이스입니다.

shards

배열

컬렉션의 샤드와 각 샤드에 대한 데이터 배포 정보입니다.

shards.numOrphanedDocs

integer

샤드 내 고아 문서 수입니다.

shards.numOwnedDocuments

integer

샤드가 소유한 문서 수입니다.

shards.ownedSizeBytes

integer

압축 해제 시 샤드 가 소유한 문서의 크기(단위: 바이트)입니다.

shards.orphanedSizeBytes

integer

압축을 하지 않았을 때 샤드 에 있는 고아 문서의 크기(단위: 바이트)입니다.

Wired Tiger 스토리지 엔진 을 사용하여 mongod 를 비정상적으로 종료한 후 에서 보고한 크기 및 개수 통계가 $shardedDataDistribution 부정확할 수 있습니다.

편차의 정도는 마지막 체크포인트와 비정상 종료 사이에 수행된 삽입, 업데이트 또는 삭제 작업의 수에 따라 달라집니다. 체크포인트는 보통 60초마다 발생합니다. 그러나mongod 기본값이 아닌 --syncdelay 설정으로 실행되는 인스턴스는 체크포인트가 다소 빈번하게 발생할 수 있습니다.

mongod의 각 컬렉션에서 validate를 실행하여 비정상 종료 후 통계를 복원합니다.

비정상 종료 후

샤딩된 데이터 배포 지표를 모두 반환하려면 다음을 실행합니다.

db.aggregate([
{ $shardedDataDistribution: { } }
])

출력 예시:

[
{
"ns": "test.names",
"shards": [
{
"shardName": "shard-1",
"numOrphanedDocs": 0,
"numOwnedDocuments": 6,
"ownedSizeBytes": 366,
"orphanedSizeBytes": 0
},
{
"shardName": "shard-2",
"numOrphanedDocs": 0,
"numOwnedDocuments": 6,
"ownedSizeBytes": 366,
"orphanedSizeBytes": 0
}
]
}
]

특정 샤드에 대해 샤딩된 데이터 분포 지표를 반환하려면 다음을 실행합니다.

db.aggregate([
{ $shardedDataDistribution: { } },
{ $match: { "shards.shardName": "<name of the shard>" } }
])

네임스페이스에 대한 샤딩된 데이터 분포 데이터를 반환하려면 다음을 실행합니다.

db.aggregate([
{ $shardedDataDistribution: { } },
{ $match: { "ns": "<database>.<collection>" } }
])

MongoDB 6.0.3부터 $shardedDataDistribution 단계를 사용하여 집계를 실행하해 고아 문서가 남아 있지 않은지 확인할 수 있습니다.

db.aggregate([
{ $shardedDataDistribution: { } },
{ $match: { "ns": "<database>.<collection>" } }
])

$shardedDataDistribution 의 출력은 다음과 유사합니다.

[
{
"ns": "test.names",
"shards": [
{
"shardName": "shard-1",
"numOrphanedDocs": 0,
"numOwnedDocuments": 6,
"ownedSizeBytes": 366,
"orphanedSizeBytes": 0
},
{
"shardName": "shard-2",
"numOrphanedDocs": 0,
"numOwnedDocuments": 6,
"ownedSizeBytes": 366,
"orphanedSizeBytes": 0
}
]
}
]

클러스터의 각 샤드에 대해 "numOrphanedDocs"0 인지 확인합니다.