[SERVER-19076] printShardingStatus/sh.status should pass a decent indent to tojson() for shard keys Created: 23/Jun/15  Updated: 12/Oct/17  Resolved: 21/Sep/17

Status: Closed
Project: Core Server
Component/s: Sharding, Shell
Affects Version/s: None
Fix Version/s: 3.2.18, 3.4.10, 3.6.0-rc0

Type: Improvement Priority: Major - P3
Reporter: Kevin Pulo Assignee: Kevin Pulo
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Backwards Compatibility: Minor Change
Backport Requested:
v3.4, v3.2
Participants:

 Description   

When shard keys are long enough, they aren't output on a single line by sh.status(), e.g.:

> sh.status()
--- Sharding Status ---
  sharding version: {
        "_id" : 1,
        "minCompatibleVersion" : 5,
        "currentVersion" : 6,
        "clusterId" : ObjectId("5588bac0938487f72c20f9c1")
}
  shards:
        {  "_id" : "shard01",  "host" : "genique:11112" }
  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" : "admin",  "partitioned" : false,  "primary" : "config" }
        {  "_id" : "test",  "partitioned" : true,  "primary" : "shard01" }
                test.test
                        shard key: {
        "longFieldName1" : 1,
        "longFieldName2" : 1,
        "longFieldName3" : 1,
        "longFieldName4" : 1
}
                        chunks:
                                shard01 2
                        {
        "longFieldName1" : { "$minKey" : 1 },
        "longFieldName2" : { "$minKey" : 1 },
        "longFieldName3" : { "$minKey" : 1 },
        "longFieldName4" : { "$minKey" : 1 }
} -->> {
        "longFieldName1" : 1,
        "longFieldName2" : 1,
        "longFieldName3" : 1,
        "longFieldName4" : 1
} on : shard01 Timestamp(1, 1)
                        {
        "longFieldName1" : 1,
        "longFieldName2" : 1,
        "longFieldName3" : 1,
        "longFieldName4" : 1
} -->> {
        "longFieldName1" : { "$maxKey" : 1 },
        "longFieldName2" : { "$maxKey" : 1 },
        "longFieldName3" : { "$maxKey" : 1 },
        "longFieldName4" : { "$maxKey" : 1 }
} on : shard01 Timestamp(1, 2)

This is because tojson() is used, rather than tojsononeline(). Outputting with tojsononeline() would make for very long lines, which would not be good, but as it stands the current output can be extremely difficult to read.

The best solution would be to pass an appropriate indent value to tojson(), so that the indenting is preserved if multiple lines are needed. This would give output like:

  databases:
        {  "_id" : "admin",  "partitioned" : false,  "primary" : "config" }
        {  "_id" : "test",  "partitioned" : true,  "primary" : "shard01" }
                test.test
                        shard key: {
                                           "longFieldName1" : 1,
                                           "longFieldName2" : 1,
                                           "longFieldName3" : 1,
                                           "longFieldName4" : 1
                                   }
                        chunks:
                                shard01 2
                        {
                                "longFieldName1" : { "$minKey" : 1 },
                                "longFieldName2" : { "$minKey" : 1 },
                                "longFieldName3" : { "$minKey" : 1 },
                                "longFieldName4" : { "$minKey" : 1 }
                        } -->> {
                                "longFieldName1" : 1,
                                "longFieldName2" : 1,
                                "longFieldName3" : 1,
                                "longFieldName4" : 1
                        } on : shard01 Timestamp(1, 1)
                        {
                                "longFieldName1" : 1,
                                "longFieldName2" : 1,
                                "longFieldName3" : 1,
                                "longFieldName4" : 1
                        } -->> {
                                "longFieldName1" : { "$maxKey" : 1 },
                                "longFieldName2" : { "$maxKey" : 1 },
                                "longFieldName3" : { "$maxKey" : 1 },
                                "longFieldName4" : { "$maxKey" : 1 }
                        } on : shard01 Timestamp(1, 2)



 Comments   
Comment by Githook User [ 04/Oct/17 ]

Author:

{'email': 'kevin.pulo@mongodb.com', 'name': 'Kevin Pulo', 'username': 'devkev'}

Message: SERVER-19076 handle multiline shard keys in sh.status()

(cherry picked from commit a18d0f0c5754c750b44ba05ad7cc26b1f8054625)
Branch: v3.2
https://github.com/mongodb/mongo/commit/cfd5d0743fa00409b5208f1ee2d14dfbdc269ea4

Comment by Githook User [ 04/Oct/17 ]

Author:

{'email': 'kevin.pulo@mongodb.com', 'name': 'Kevin Pulo', 'username': 'devkev'}

Message: SERVER-19076 handle multiline shard keys in sh.status()

(cherry picked from commit 18645e165e5f23e899b32cb5ebe45e9750dd3a97)

Switch back to calling sh.isBalancerRunning() from printShardingStatus(), because it has the correct behaviour for this version.
Branch: v3.4
https://github.com/mongodb/mongo/commit/a18d0f0c5754c750b44ba05ad7cc26b1f8054625

Comment by Githook User [ 21/Sep/17 ]

Author:

{'email': 'kevin.pulo@mongodb.com', 'name': 'Kevin Pulo', 'username': 'devkev'}

Message: SERVER-19076 handle multiline shard keys in sh.status()
Branch: master
https://github.com/mongodb/mongo/commit/18645e165e5f23e899b32cb5ebe45e9750dd3a97

Generated at Thu Feb 08 03:49:45 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.