shardingState

On this page本页内容

shardingState

shardingState is an admin command that reports if mongod is a member of a sharded cluster.shardingState是一个管理命令,用于报告mongod是否是分片集群的成员。

shardingState has the following prototype form:具有以下原型形式:

{ shardingState: 1 }

To run the command, you must run against the admin database. 要运行该命令,必须针对admin数据库运行。See db.adminCommand().请参阅db.adminCommand()

Behavior行为

For shardingState to detect that a mongod is a member of a sharded cluster, the mongod must satisfy the following conditions:为了使shardingState检测到mongod是分片集群的成员,mongod必须满足以下条件:

  1. the mongod is a primary member of a replica set, andmongod是副本集的主要成员,并且
  2. the mongod instance is a member of a sharded cluster.mongod实例是分片集群的成员。

If shardingState detects that a mongod is a member of a sharded cluster, shardingState returns a document that resembles the following prototype:如果shardingState检测到mongod是分片集群的成员,shardingState将返回一个类似于以下原型的文档:

{
  "enabled" : true,
  "configServer" : "<configdb-string>",
  "shardName" : "<string>",
  "shardHost" : "string:",
  "versions" : {
       "<database>.<collection>" : Timestamp(<...>),
       "<database>.<collection>" : Timestamp(<...>)
  },
  "ok" : 1,
  "$clusterTime" : {
     "clusterTime" : Timestamp(1510716515, 1),
     "signature" : {
        "hash" : BinData(0,"B2ViX7XLzFLS5Fl9XEuFXbwKIM4="),
        "keyId" : NumberLong("6488045157173166092")
     }
  },
  "operationTime" : Timestamp(1510716515, 1)
}

Otherwise, shardingState will return the following document:否则,shardingState将返回以下文档:

{
  "enabled" : false,
  "ok" : 1,
  "$clusterTime" : {
     "clusterTime" : Timestamp(1510716515, 1),
     "signature" : {
        "hash" : BinData(0,"B2ViX7XLzFLS5Fl9XEuFXbwKIM4="),
        "keyId" : NumberLong("6488045157173166092")
     }
  },
  "operationTime" : Timestamp(1510716515, 1)
}

The response from shardingState when used with a config server is:配置服务器一起使用时,shardingState的响应为:

{
   "enabled" : false,
   "ok" : 1,
   "operationTime" : Timestamp(1510767613, 1),
   "$gleStats" : {
      "lastOpTime" : Timestamp(0, 0),
      "electionId" : ObjectId("7fffffff0000000000000001")
   },
   "$clusterTime" : {
      "clusterTime" : Timestamp(1510767613, 1),
      "signature" : {
         "hash" : BinData(0,"IwBZ4SZjIMI5NdM62NObV/R31GM="),
         "keyId" : NumberLong("6488693018630029321")
      }
   }
}
Note注意

mongos instances do not provide the shardingState.mongos实例不提供shardingState

Warning警告

This command obtains a write lock on the affected database and will block other operations until it has completed; however, the operation is typically short lived.该命令在受影响的数据库上获得写锁,并将阻止其他操作,直到其完成;然而,该操作通常寿命很短。

←  shardCollectionsplit →