[SERVER-13985] printShardingStatus uses group/JS Created: 19/May/14  Updated: 11/Jul/16  Resolved: 27/May/14

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 2.6.1
Fix Version/s: 2.6.12, 2.7.2

Type: Bug Priority: Minor - P4
Reporter: Asya Kamsky Assignee: Ramon Fernandez Marina
Resolution: Done Votes: 1
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Duplicate
duplicates SERVER-6348 Create ChunkStats command to replace ... Closed
is duplicated by SERVER-20251 sh.status() returns incomplete result. Closed
Related
is related to SERVER-14968 sh.status(): order shards for sharded... Closed
Backwards Compatibility: Major Change
Operating System: ALL
Backport Completed:
Sprint: Server 2.7.1, Server 2.7.2
Participants:
Linked BF Score: 0

 Description   

sh.status() aka printShardingStatus still uses the old MR/group command

res = configDB.chunks.group( { cond : { ns : coll._id } , key : { shard : 1 },
     reduce : function( doc , out ){ out.nChunks++; } , initial : { nChunks : 0 } } );

with aggregation readily available without JS, there is no reason to leave this using group and being broken for users who turn off server side scripting for security reasons.



 Comments   
Comment by Githook User [ 02/Sep/15 ]

Author:

{u'username': u'Zarkantho', u'name': u'Shaun Verch', u'email': u'shaun.verch@mongodb.com'}

Message: SERVER-13985 Remove old v3 to v4 config metadata upgrade jstests

(cherry picked from commit 6511fae500f5d3c3205499d0b48c842c199222f4)
Branch: v2.6
https://github.com/mongodb/mongo/commit/e748e49c88b0ea282770e3ddd46a7e3c3d96dd30

Comment by Githook User [ 02/Sep/15 ]

Author:

{u'username': u'Zarkantho', u'name': u'Shaun Verch', u'email': u'shaun.verch@mongodb.com'}

Message: SERVER-13985 Remove server side js usage from printShardingStatus

(cherry picked from commit df9cb2c79f98f5ab5471a95b36e7689600d686d2)
Branch: v2.6
https://github.com/mongodb/mongo/commit/61730dca01746a5eb7faada07fa16bbe52460157

Comment by Shaun Verch [ 28/May/14 ]

Confirmed the new shell works with both versions when they have "--noscripting" on.

MongoDB shell version: 2.7.2-pre-
connecting to: test
mongos> db.version()
2.2.7
mongos> printShardingStatus()
--- Sharding Status ---
  sharding version: { "_id" : 1, "version" : 3 }
  shards:
	{  "_id" : "shard0000",  "host" : "sv.local:27018" }
	{  "_id" : "shard0001",  "host" : "sv.local:27019" }
  databases:
	{  "_id" : "admin",  "partitioned" : false,  "primary" : "config" }
	{  "_id" : "test",  "partitioned" : true,  "primary" : "shard0000" }
		test.test
			shard key: { "x" : 1 }
			chunks:
				shard0000	1
			{ "x" : { "$minKey" : 1 } } -->> { "x" : { "$maxKey" : 1 } } on : shard0000 Timestamp(1, 0)
 
mongos> exit
bye
$ ./mongo
MongoDB shell version: 2.7.2-pre-
connecting to: test
mongos> db.version()
2.4.10
mongos> printShardingStatus()
--- Sharding Status ---
  sharding version: {
	"_id" : 1,
	"version" : 3,
	"minCompatibleVersion" : 3,
	"currentVersion" : 4,
	"clusterId" : ObjectId("5385fde5a29d164c53982847")
}
  shards:
	{  "_id" : "shard0000",  "host" : "sv.local:27018" }
	{  "_id" : "shard0001",  "host" : "sv.local:27019" }
  databases:
	{  "_id" : "admin",  "partitioned" : false,  "primary" : "config" }
	{  "_id" : "test",  "partitioned" : true,  "primary" : "shard0000" }
		test.test
			shard key: { "x" : 1 }
			chunks:
				shard0000	1
			{ "x" : { "$minKey" : 1 } } -->> { "x" : { "$maxKey" : 1 } } on : shard0000 Timestamp(1, 0)
 
mongos>

Comment by Githook User [ 28/May/14 ]

Author:

{u'name': u'Shaun Verch', u'email': u'shaun.verch@mongodb.com'}

Message: SERVER-13985 Remove old v3 to v4 config metadata upgrade jstests
Branch: master
https://github.com/mongodb/mongo/commit/6511fae500f5d3c3205499d0b48c842c199222f4

Comment by Scott Hernandez (Inactive) [ 27/May/14 ]

Note, this will not work against a server without aggregation support, like pre-2.2. We could add fallback support if the command is not found.

Comment by Githook User [ 27/May/14 ]

Author:

{u'name': u'Shaun Verch', u'email': u'shaun.verch@mongodb.com'}

Message: SERVER-13985 Remove server side js usage from printShardingStatus
Branch: master
https://github.com/mongodb/mongo/commit/df9cb2c79f98f5ab5471a95b36e7689600d686d2

Comment by Asya Kamsky [ 19/May/14 ]

Here's the change:

diff --git a/src/mongo/shell/shardingtest.js b/src/mongo/shell/shardingtest.js
index d3e9824..603f553 100644
--- a/src/mongo/shell/shardingtest.js
+++ b/src/mongo/shell/shardingtest.js
@@ -671,8 +671,8 @@ printShardingStatus = function( configDB , verbose ){
                             output( "\t\t\tshard key: " + tojson(coll.key) );
                             output( "\t\t\tchunks:" );
 
-                            res = configDB.chunks.group( { cond : { ns : coll._id } , key : { shard : 1 },
-                                reduce : function( doc , out ){ out.nChunks++; } , initial : { nChunks : 0 } } );
+                            res = configDB.chunks.aggregate( {$match:{ ns : coll._id } } , {$group:{_id:"$shard", cnt:{$sum:1}}},
+                                {$project:{_id:0,shard:"$_id",nChunks:"$cnt"}},{$sort:{shard:1}}).toArray();
                             var totalChunks = 0;
                             res.forEach( function(z){
                                 totalChunks += z.nChunks;

I tested it. Should I make/attach it as a pull request?

Comment by Asya Kamsky [ 19/May/14 ]

Looks like it's 100% equivalent to doing aggregation:

db.chunks.aggregate({$match:{ns: coll._id}},{$group:{_id:"$shard",cnt:{$sum:1}}},{$project:{_id:0,shard:"$_id",nChunks:"$cnt"}}).toArray()

in 2.6 anyway.

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