清除巨型标志

在本页面

如果 MongoDB 无法拆分超过指定的块大小的块,则 MongoDB 将该块标记为jumbo

如果块大小不再超过指定的块大小,则当mongos重写块元数据时,MongoDB 会清除该块的jumbo标志。

如果需要手动清除该标志,则以下过程概述了手动清除jumbo标志的步骤。

Procedures

Divisible Chunks

从块中清除jumbo标志的首选方法是尝试拆分块。如果块是可分割的,则 MongoDB 在成功拆分块后会删除该标志。

连接到 mongos。

mongoShell 连接到mongos

找到巨型块。

运行sh.status(true)以找到标记为jumbo的块。

sh.status(true)

例如,sh.status(true)的以下输出显示,分片键范围为{ "x" : 2 } -->> { "x" : 4 }的块为jumbo

--- Sharding Status ---
  sharding version: {
     ...
  }
  shards:
     ...
  databases:
     ...
        test.foo
           shard key: { "x" : 1 }
        chunks:
             shard-b  2
             shard-a  2
        { "x" : { "$minKey" : 1 } } -->> { "x" : 1 } on : shard-b Timestamp(2, 0)
        { "x" : 1 } -->> { "x" : 2 } on : shard-a Timestamp(3, 1)
        { "x" : 2 } -->> { "x" : 4 } on : shard-a Timestamp(2, 2) jumbo
        { "x" : 4 } -->> { "x" : { "$maxKey" : 1 } } on : shard-b Timestamp(3, 0)

拆分大块。

使用sh.splitAt()sh.splitFind()拆分jumbo块。

sh.splitAt( "test.foo", { x: 3 })

成功拆分块后,MongoDB 将删除jumbo标志。

Indivisible Chunks

在某些情况下,MongoDB 无法拆分不再长的jumbo块,例如具有单个分片键值范围的块,并且清除标记的首选方法也不适用。在这种情况下,可以使用以下步骤清除标志。

Important

仅在preferred method不适用时才使用此方法。

在修改config database之前,总是备份配置数据库。

如果您为仍超过块大小的块清除了jumbo标志,则当 MongoDB 尝试移动该块时,MongoDB 将把该块重新标记为jumbo

停止平衡器。

遵循禁用平衡器中概述的步骤,暂时禁用集群平衡器进程。

创建配置数据库的备份。

对配置服务器使用mongodump来创建config数据库的备份。例如:

mongodump --db config --port <config server port> --out <output file>

连接到 mongos。

mongoShell 连接到mongos

找到巨型块。

运行sh.status(true)以找到标记为jumbo的块。

sh.status(true)

例如,sh.status(true)的以下输出显示,分片键范围为{ "x" : 2 } -->> { "x" : 3 }的块为jumbo

--- Sharding Status ---
  sharding version: {
     ...
  }
  shards:
     ...
  databases:
     ...
        test.foo
           shard key: { "x" : 1 }
        chunks:
             shard-b  2
             shard-a  2
        { "x" : { "$minKey" : 1 } } -->> { "x" : 1 } on : shard-b Timestamp(2, 0)
        { "x" : 1 } -->> { "x" : 2 } on : shard-a Timestamp(3, 1)
        { "x" : 2 } -->> { "x" : 3 } on : shard-a Timestamp(2, 2) jumbo
        { "x" : 3 } -->> { "x" : { "$maxKey" : 1 } } on : shard-b Timestamp(3, 0)

更新块集合。

config数据库的chunks集合中,取消设置块的jumbo标志。例如,

db.getSiblingDB("config").chunks.update(
   { ns: "test.foo", min: { x: 2 }, jumbo: true },
   { $unset: { jumbo: "" } }
)

清除缓存的路由信息。

chunks集合中清除掉巨型标志之后,更新集群路由元数据缓存。

从 MongoDB 3.6.11 开始,您必须刷新名称空间的 config server primary 上的缓存。这会通知平衡器巨型标志清除。

在早期版本(MongoDB 3.4 系列,MongoDB 3.6.0-3.6.10)中,您必须退出配置服务器主服务器。

db.adminCommand( { flushRouterConfig:  "test.foo" } )
首页