停止取消分片集合
您可以使用以下方式停止取消分片分片集合:abortUnshardCollection
命令。
关于此任务
要停止正在进行的 unshardCollection
操作,运行 abortUnshardCollection
命令。
注意
解分片是一个写密集型过程,可能会导致操作日志(oplog)的速率增加。您可能需要
设置固定的oplog大小以防止oplog无界增长。
增加oplog大小以最小化一个或多个二级节点变旧的几率。
有关更多详细信息,请参阅副本集oplog 文档。
兼容性
您可以在以下环境中执行此任务
MongoDB Atlas:云中MongoDB部署的全托管服务
注意
此任务在Atlas共享层或Atlas无服务器上不可用。
MongoDB Enterprise:基于订阅的自托管MongoDB版本
MongoDB Community:源代码可用的、免费使用且自托管的MongoDB版本
限制
abortUnshardCollection
只能在分片集群上运行。abortUnshardCollection
只能操作分片集合。abortUnshardCollection
每次只能操作一个集合。在
abortUnshardCollection
完成之前,您无法进行拓扑更改,例如添加或删除分片或在不同配置服务器之间转换。在
abortUnshardCollection
进行中时,您不能在正在解分片的集合上运行以下操作在
unshardCollection
进行中时,您不能在集群上运行以下操作在
abortUnshardCollection
进行中时发生的索引构建可能会静默失败。在
abortUnshardCollection
进行中时,请不要创建索引。如果存在正在进行的索引构建,请不要调用
abortUnshardCollection
。
访问控制
如果您的部署启用了 访问控制,则 enableSharding
角色授予您运行 abortUnshardCollection
命令的权限。
步骤
停止集合的分片
要停止集合的分片,运行 abortUnshardCollection
命令。以下示例停止了 sales
数据库中 us_accounts
的 unshardCollection
操作
db.adminCommand( { abortUnshardCollection: "sales.us_accounts", } )
确认分片操作已停止
要确认 unshardCollection
操作已停止,使用 sh.status()
方法
sh.status()
以下示例输出显示集合已分片,其原始分片键如下:
collections: { 'sales.us_accounts': { shardKey: { account_number: 1 }, unique: false, balancing: true, chunkMetadata: [ { shard: 'shard-0', nChunks: 1 }, { shard: 'shard-1', nChunks: 1 } ], chunks: [ { min: { _id: MinKey() }, max: { _id: Long('0') }, 'on shard': 'shard-0', 'last modified': Timestamp({ t: 1, i: 0 }) }, { min: { _id: Long('0') }, max: { _id: MaxKey() }, 'on shard': 'shard-1', 'last modified': Timestamp({ t: 1, i: 1 }) } ], ... } ... }