Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-19076

printShardingStatus/sh.status should pass a decent indent to tojson() for shard keys

    • Minor Change
    • v3.4, v3.2

      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)
      

            Assignee:
            kevin.pulo@mongodb.com Kevin Pulo
            Reporter:
            kevin.pulo@mongodb.com Kevin Pulo
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: