Start Defragmenting a Sharded Collection开始对分片集合进行分片整理
On this page本页内容
To start defragmenting a sharded collection, use the 要开始对已分片化的集合进行分片整理,请使用configureCollectionBalancing
command with the defragmentCollection
option set to true
.configureCollectionBalancing
命令,并将defragmentCollection
选项设置为true
。
About this Task任务介绍
Fragmentation is where a sharded collection's data is broken up into an unnecessarily large number of small chunks. 分片化是指将分片化集合的数据分解为不必要的大量小块。This can increase operation times of CRUD operations run on that collection. 这可能会增加在该集合上运行的CRUD操作的操作时间。Defragmentation reduces the number of chunks by merging smaller chunks into larger ones, resulting in lower CRUD operation times.分片整理通过将较小的块合并为较大的块来减少块的数量,从而降低CRUD操作时间。
If CRUD operation times are acceptable, you don't need to defragment collections.如果CRUD操作时间可以接受,则不需要对集合进行分片整理。
The following table summarizes defragmentation information for various MongoDB versions.下表总结了各种MongoDB版本的分片整理信息。
MongoDB Version | |
---|---|
The procedure in this task uses an example sharded collection named 此任务中的过程在名为ordersShardedCollection
in a database named test
.test
的数据库中使用了一个名为ordersShardedCollection
的示例分片集合。
You can use your own sharded collection and database in the procedure.您可以在过程中使用自己的分片集合和数据库。
Before you Begin开始之前
Connect to 连接到mongos
.mongos
。
Procedure过程
Ensure defragmentation started确保分片整理已启动
Ensure 确保命令输出中ok
is 1
in the command output, which indicates the command execution was successful:ok
为1
,这表示命令执行成功:
{
ok: 1,
'$clusterTime': {
clusterTime: Timestamp({ t: 1677616966, i: 8 }),
signature: {
hash: Binary(Buffer.from("0000000000000000000000000000000000000000", "hex"), 0),
keyId: Long("0")
}
},
operationTime: Timestamp({ t: 1677616966, i: 8 })
}
Next Steps下一步
You can monitor the collection's defragmentation progress. 您可以监视集合的分片整理进度。For details, see Monitor Defragmentation of a Sharded Collection.有关详细信息,请参阅监视分片集合的分片整理。
Learn More了解更多信息
Print shard status, see打印分片状态,请参阅db.printShardingStatus()
Retrieve shard status details, see检索分片状态详细信息,请参阅sh.status()
View shard status collection fields, see查看分片状态集合字段,请参阅Sharded CollectionSee active mongos instances, see查看活动mongos
实例,请参阅Activemongos
InstancesMonitor shards using MongoDB Atlas, see使用MongoDB Atlas监控分片,请参阅Review Sharded Clusters