sh.status()

On this page本页内容

Definition定义

sh.status()

When run on a mongos instance, prints a formatted report of the sharding configuration and the information regarding existing chunks in a sharded cluster. mongos实例上运行时,打印分片配置的格式化报告以及有关分片集群中现有块的信息。The default behavior suppresses the detailed chunk information if the total number of chunks is greater than or equal to 20.如果区块总数大于或等于20,则默认行为将禁止显示详细的区块信息。

The sh.status() method has the following parameter:sh.status()方法具有以下参数:

Parameter参数Type类型Description描述
verboseboolean

Optional. 可选。Determines the level of verbosity.确定详细级别。

If true, the method displays:如果为true,则该方法显示:

  • Full details of the chunk distribution across shards even if you have 20 or more chunks, as well as the number of chunks on each shard.即使您有20个或更多块,块在分片上分布的完整详细信息,以及每个分片上的块数。
  • Details of active mongos instances.活动mongos实例的详细信息。

If false, the method displays:如果为false,则该方法显示:

  • Full details of the chunk distribution across shards only if you have less than 20 chunks. 只有当块数少于20时,才能完整地了解块在分片上的分布情况。If you have 20 or more chunks, the method instead returns a too many chunks to print ... message, showing only the number of chunks on each shard.如果您有20个或更多的块,那么该方法会返回一条too many chunks to print ...消息,只显示每个分片上的块数。
  • Only the version and number of active mongos instances.仅显示活动mongos实例的版本和数量

The default verbose value is false.默认的详细值为false

Tip提示
See also: 参阅:

Output Examples输出示例

The Sharding Version section displays information on the config database:Sharding Version部分显示有关config数据库的信息:

--- Sharding Status ---
  sharding version: {
   "_id" : <num>,
   "minCompatibleVersion" : <num>,
   "currentVersion" : <num>,
   "clusterId" : <ObjectId>
}

The Shards section lists information on the shard(s). 分片部分列出了有关分片的信息。For each shard, the section displays the name, host, and the associated tags, if any.对于每个分片,该部分显示名称、主机和关联的标记(如果有)。

shards:
 { "_id" : <shard name1>, "host" : <string>, "tags" : [ <string> ... ], "state" : <num> }
 { "_id" : <shard name2>, "host" : <string>, "tags" : [ <string> ... ], "state" : <num> }
 ...

The Active mongos Instances section displays, by default, information on the version and count of mongos instances that have been active within the last 60 seconds:默认情况下,活动mongos实例部分显示有关在过去60秒内处于活动状态的mongos实例的版本和计数的信息:

active mongoses:
  <version> : <num>

If the method is run with the verbose parameter to true, the Active mongos Instances section displays additional information:如果在verbose参数为true的情况下运行该方法,则活动mongos实例部分将显示其他信息:

active mongoses:
{  "_id" : "<hostname:port>",  "advisoryHostFQDNs" : [ "<name>" ],  "mongoVersion" : <string>,  "ping" : <ISODate>,  "up" : <long>,  "waiting" : <boolean> }

The Autosplit displays information on whether autosplit is enabled:自动拆分显示有关是否启用自动拆分的信息:

autosplit:
  Currently enabled: <yes|no>

The Balancer section lists information about the state of the balancer. 平衡器部分列出了有关平衡器状态的信息。This provides insight into current balancer operation and can be useful when troubleshooting an unbalanced sharded cluster.这提供了对当前平衡器操作的深入了解,在对不平衡的分片集群进行故障排除时非常有用。

balancer:
      Currently enabled:  yes
      Currently running:  yes
      Collections with active migrations:
              config.system.sessions started at Fri May 15 2020 17:38:12 GMT-0400 (EDT)
      Failed balancer rounds in last 5 attempts:  0
      Migration Results for the last 24 hours:
             416 : Success
             1 : Failed with error 'aborted', from shardA to shardB

The Databases section lists information on the database(s). 数据库部分列出了有关数据库的信息。For each database, the section displays the name, whether the database has sharding enabled, and the primary shard for the database.对于每个数据库,该部分显示名称、数据库是否启用了分片以及数据库的主分片

databases:
 { "_id" : <dbname1>, "primary" : <string>, "partitioned" : <boolean>, "version": <document> }
 { "_id" : <dbname2>, "primary" : <string>, "partitioned" : <boolean>, "version": <document> }
 ...

The Sharded Collection section provides information on the sharding details for sharded collection(s). Sharded Collection部分提供了有关分片集合的分片详细信息。For each sharded collection, the section displays the shard key, the number of chunks per shard(s), the distribution of chunks across shards [1], and the tag information, if any, for shard key range(s).对于每个分片集合,该部分显示分片键、每个分片的块数、块在分片上的分布[1],以及分片键范围的标记信息(如果有)。

<dbname>.<collection>
   shard key: { <shard key> : <1 or hashed> }
   unique: <boolean>
   balancing: <boolean>
   chunks:
      <shard name1> <number of chunks>
      <shard name2> <number of chunks>
      ...
   { <shard key>: <min range1> } -->> { <shard key> : <max range1> } on : <shard name> <last modified timestamp>
   { <shard key>: <min range2> } -->> { <shard key> : <max range2> } on : <shard name> <last modified timestamp>
   ...
   tag: <tag1>  { <shard key> : <min range1> } -->> { <shard key> : <max range1> }
   ...

Output Fields输出字段

Sharding Version分片版本

sh.status.sharding-version._id

The _id is an identifier for the version details._id是版本详细信息的标识符。

sh.status.sharding-version.minCompatibleVersion

The minCompatibleVersion is the minimum compatible version of the config server.minCompatibleVersion是配置服务器的最低兼容版本。

sh.status.sharding-version.currentVersion

The currentVersion is the current version of the config server.currentVersion是配置服务器的当前版本。

sh.status.sharding-version.clusterId

The clusterId is the identification for the sharded cluster.clusterId是分片集群的标识。

Active mongos Instances活动mongos实例

sh.status.active-mongoses

If verbose is false, sh.status.active-mongoses lists the version and count of the active mongos instances. 如果verbosefalsesh.status.active-mongoses将列出活动mongos实例的版本和计数。Active mongos instances are mongos instances that have been pinged within the last 60 seconds.活动mongos实例是在过去60秒内ping的mongos示例。

If verbose is true, sh.status.active-mongoses returns a document for each active mongos instance containing the following fields:如果verbosetruesh.status.active-mongoses将为每个活动mongos实例返回一个包含以下字段的文档:

Field字段Data TypeDescription描述
_idStringThe hostname and port where the mongos is running. mongos运行的主机名和端口。The _id is formatted as <hostname>:<port>._id的格式为<hostname>:<port>
advisoryHostFQDNsArray of stringsArray of the mongos's fully qualified domain names (FQDNs).mongos的完全限定域名(FQDN)数组。
createdDate

When the mongos was started.当蒙古人开始的时候。

New in version 5.2.在版本5.2中新增

mongoVersionStringVersion of MongoDB that the mongos is running.mongos正在运行的MongoDB版本。
pingDatemongos instances send pings to the config server every 30 seconds. mongos实例每30秒向配置服务器发送一次ping。This field indicates the last ping time.此字段指示上次ping时间。
upNumberLongNumber of seconds the mongos has been up as of the last ping.截至上次ping,mongos已上升的秒数。
waitingBooleanAs of MongoDB 3.4, this field is always true and is only present for backward compatibility.从MongoDB 3.4开始,此字段始终为true,仅用于向后兼容。
active mongoses:
{
   "_id" : "<hostname:port>",
   "advisoryHostFQDNs" : [ "<name>" ],
   "created" : <ISODate>,
   "mongoVersion" : <string>,
   "ping" : <ISODate>,
   "up" : <long>,
   "waiting" : <boolean>
}
...

Autosplit自动拆分

sh.status.autosplit

sh.status.autosplit indicates whether autosplit is currently enabled.指示当前是否启用了自动拆分。

Note注意

Starting in MongoDB 4.2:从MongoDB 4.2开始:

The mongo methods sh.enableBalancing(namespace) and sh.disableBalancing(namespace) have no affect on the auto-splitting.mongo方法sh.enableBalancing(namespace)sh.disableBalancing(namespace)对自动拆分没有影响。

Shards分片

sh.status.shards._id

The _id displays the name of the shard._id显示分片的名称。

sh.status.shards.host

The host displays the host location of the shard.host显示分片的主机位置。

sh.status.shards.tags

The tags displays all the tags for the shard. The field only displays if the shard has tags.tags显示分片的所有标记。该字段仅在分片具有标记时显示。

sh.status.shards.state

The state displays:state显示:

  • 0 if the shard is not shard aware.如果分片不可识别分片。
  • 1 if the shard is shard aware.如果分片是分片感知的。

Balancer平衡器

Note注意

Starting in MongoDB 4.2:从MongoDB 4.2开始:

The mongo methods sh.enableBalancing(namespace) and sh.disableBalancing(namespace) have no affect on the auto-splitting.mongo方法sh.enableBalancing(namespace)sh.disableBalancing(namespace)对自动拆分没有影响。

sh.status.balancer.currently-enabled

currently-enabled indicates if the balancer is currently enabled on the sharded cluster.指示当前是否在分片群集上启用了平衡器

sh.status.balancer.currently-running

currently-running indicates whether the balancer is currently running, and therefore currently balancing the cluster.指示平衡器当前是否正在运行,因此当前是否正在平衡群集。

sh.status.balancer.collections-with-active-migrations

collections-with-active-migrations lists the names of any collections with active migrations, and specifies when the migration began. 列出具有活动迁移的所有集合的名称,并指定迁移开始的时间。If there are no active migrations, this field will not appear in the sh.status() output.如果没有活动迁移,则sh.status()输出中将不会显示此字段。

sh.status.balancer.failed-balancer-rounds-in-last-5-attempts

failed-balancer-rounds-in-last-5-attempts displays the number of balancer rounds that failed, from among the last five attempted rounds. 显示最近五次尝试轮次中失败的平衡器轮次数。A balancer round will fail when a chunk migration fails.当块迁移失败时,平衡轮将失败。

sh.status.balancer.last-reported-error

last-reported-error lists the most recent balancer error message. 列出了最新的平衡器错误消息。If there have been no errors, this field will not appear in the sh.status() output.如果没有错误,该字段将不会出现在sh.status()输出中。

sh.status.balancer.time-of-reported-error

time-of-reported-error provides the date and time of the most recently-reported error.提供最近报告的错误的日期和时间。

sh.status.balancer.migration-results-for-the-last-24-hours

migration-results-for-the-last-24-hours displays the number of migrations in the last 24 hours, and the error messages from failed migrations . 显示最近24小时内的迁移数,以及失败迁移的错误消息。If there have been no recent migrations, migration-results-for-the-last-24-hours displays No recent migrations.如果最近没有迁移,则最近24小时的迁移结果将显示No recent migrations

migration-results-for-the-last-24-hours includes all migrations, including those not initiated by the balancer.包括所有迁移,包括那些不是由平衡器启动的迁移。

Databases数据库

sh.status.databases._id

The _id displays the name of the database._id显示数据库的名称。

sh.status.databases.partitioned

The partitioned displays whether the database has sharding enabled. partitioned显示数据库是否启用了分片。If true, the database has sharding enabled.如果为true,则数据库已启用分片。

sh.status.databases.primary

The primary displays the primary shard for the database.primary显示数据库的主分片

sh.status.databases.version

New in version 4.0.在版本4.0中新增 Only available for featureCompatibilityVersion4.0 or greater.仅适用于featureCompatibilityVersion4.0或更高版本。

The version displays the version information for the database:version显示数据库的版本信息:

{  "uuid" : UUID("cc250b66-8638-49f7-a2e8-c6f1220b9d7a"),  "lastMod" : 1 }

where:

  • uuid is the database identifier.是数据库标识符。
  • lastMod is the database version.是数据库版本。

Sharded Collection分片集合

sh.status.databases.<collection>.shard-key

The shard-key displays the shard key specification document.shard-key显示分片键规范文档。

sh.status.databases.<collection>.unique

The unique displays whether MongoDB enforces uniqueness on the shard key values (i.e. whether the underlying shard key index is unique).显示MongoDB是否强制分片键值的唯一性(即底层分片键值索引是否唯一)。

sh.status.databases.<collection>.balancing

The balancing displays whether balancing is enabled (true) or disabled (false) for the collection.balancing显示集合的平衡是启用(true)还是禁用(false)。

sh.status.databases.<collection>.chunks

The chunks lists all the shards and the number of chunks that reside on each shard.chunks列出了所有分片以及每个分片上的块数。

sh.status.databases.<collection>.chunk-details

The chunk-details lists the details of the chunks chunk-details列出了区块的详细信息[1]:

  • The range of shard key values that define the chunk,定义块的分片键值的范围,
  • The shard where the chunk resides, and区块所在的分片,以及
  • The last modified timestamp for the chunk.块的上次修改时间戳。
sh.status.databases.<collection>.tag

The tag lists the details of the tags associated with a range of shard key values.tag列出了与一系列shard键值关联的标记的详细信息。

Tip提示
See also: 参阅:
[1](1, 2) The sharded collection section, by default, displays the chunk information if the total number of chunks is less than 20. 默认情况下,如果区块总数小于20,则分片集合部分将显示区块信息。To display the information when you have 20 or more chunks, call the sh.status() methods with the verbose parameter set to true, i.e. sh.status(true).要在有20个或更多块时显示信息,请调用sh.status()方法,并将verbose参数设置为true,即sh.status(true)
←  sh.startBalancer()sh.stopBalancer() →