DB 中是否有 sh.enableSharding() 尚未执行的主分片?
Is there a primary shard in DBs in which sh.enableSharding() has not been yet executed?
MongoDB 分片集群使用 "primary shard" 将集合数据保存在已启用分片的数据库中(使用 sh.enableSharding()
)但集合本身尚未启用(使用sh.shardCollection()
)。 mongos
进程自动选择主分片,除非用户将其明确声明为 sh.enableSharding()
的参数
但是,在 sh.enableSharding()
尚未 的数据库中会发生什么?这些案例有一些 "global primary" 吗?我怎么知道是哪一个? sh.status()
不显示有关它的信息...
我正在使用 MongoDB 4.2 版本。
谢谢!
文档说:
The mongos selects the primary shard when creating a new database by picking the shard in the cluster that has the least amount of data.
如果在已存在的数据库上调用 enableSharding
,上述引用将定义数据库在启用分片之前的位置。
sh.status()
显示数据库存储位置:
MongoDB Enterprise mongos> use foo
switched to db foo
MongoDB Enterprise mongos> db.foo.insert({a:1})
WriteResult({ "nInserted" : 1 })
MongoDB Enterprise mongos> sh.status()
--- Sharding Status ---
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
"clusterId" : ObjectId("5eade78756d7ba8d40fc4317")
}
shards:
{ "_id" : "shard01", "host" : "shard01/localhost:14442,localhost:14443", "state" : 1 }
{ "_id" : "shard02", "host" : "shard02/localhost:14444,localhost:14445", "state" : 1 }
active mongoses:
"4.3.6" : 2
autosplit:
Currently enabled: yes
balancer:
Currently enabled: yes
Currently running: no
Failed balancer rounds in last 5 attempts: 0
Migration Results for the last 24 hours:
No recent migrations
databases:
{ "_id" : "config", "primary" : "config", "partitioned" : true }
{ "_id" : "foo", "primary" : "shard02", "partitioned" : false, "version" : { "uuid" : UUID("ff618243-f4b9-4607-8f79-3075d14d737d"), "lastMod" : 1 } }
{ "_id" : "test", "primary" : "shard01", "partitioned" : false, "version" : { "uuid" : UUID("4d76cf84-4697-4e8c-82f8-a0cfad87be80"), "lastMod" : 1 } }
foo
不分区存储在shard02.
如果在尚不存在的数据库上调用enableSharding
,则创建数据库并指定主分片,指定的分片用作主分片。测试码here.
MongoDB 分片集群使用 "primary shard" 将集合数据保存在已启用分片的数据库中(使用 sh.enableSharding()
)但集合本身尚未启用(使用sh.shardCollection()
)。 mongos
进程自动选择主分片,除非用户将其明确声明为 sh.enableSharding()
但是,在 sh.enableSharding()
尚未 的数据库中会发生什么?这些案例有一些 "global primary" 吗?我怎么知道是哪一个? sh.status()
不显示有关它的信息...
我正在使用 MongoDB 4.2 版本。
谢谢!
文档说:
The mongos selects the primary shard when creating a new database by picking the shard in the cluster that has the least amount of data.
如果在已存在的数据库上调用 enableSharding
,上述引用将定义数据库在启用分片之前的位置。
sh.status()
显示数据库存储位置:
MongoDB Enterprise mongos> use foo
switched to db foo
MongoDB Enterprise mongos> db.foo.insert({a:1})
WriteResult({ "nInserted" : 1 })
MongoDB Enterprise mongos> sh.status()
--- Sharding Status ---
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
"clusterId" : ObjectId("5eade78756d7ba8d40fc4317")
}
shards:
{ "_id" : "shard01", "host" : "shard01/localhost:14442,localhost:14443", "state" : 1 }
{ "_id" : "shard02", "host" : "shard02/localhost:14444,localhost:14445", "state" : 1 }
active mongoses:
"4.3.6" : 2
autosplit:
Currently enabled: yes
balancer:
Currently enabled: yes
Currently running: no
Failed balancer rounds in last 5 attempts: 0
Migration Results for the last 24 hours:
No recent migrations
databases:
{ "_id" : "config", "primary" : "config", "partitioned" : true }
{ "_id" : "foo", "primary" : "shard02", "partitioned" : false, "version" : { "uuid" : UUID("ff618243-f4b9-4607-8f79-3075d14d737d"), "lastMod" : 1 } }
{ "_id" : "test", "primary" : "shard01", "partitioned" : false, "version" : { "uuid" : UUID("4d76cf84-4697-4e8c-82f8-a0cfad87be80"), "lastMod" : 1 } }
foo
不分区存储在shard02.
如果在尚不存在的数据库上调用enableSharding
,则创建数据库并指定主分片,指定的分片用作主分片。测试码here.