summaryrefslogtreecommitdiff
path: root/src/mongo/shell/shardingtest.js
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2016-06-29 11:13:09 -0400
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2016-06-29 15:00:16 -0400
commit7f736859d32f9237aa382a676644082a9f66a45d (patch)
treec083e482de7f58f30ff854fcc76d5525c85f3eaa /src/mongo/shell/shardingtest.js
parentb65ddcd7868eecdec66255cae14596c479e5d316 (diff)
downloadmongo-7f736859d32f9237aa382a676644082a9f66a45d.tar.gz
SERVER-24720/SERVER-24782 Move serverStatus.balancer to a balancerStatus command
This change gets rid of the serverStatus.balancer section and moves its functionality to a new balancer command called 'balancerStatus'. In addition it gets rid of the 'controlBalancer' command and splits it into two commands - balancerStart and balancerStop.
Diffstat (limited to 'src/mongo/shell/shardingtest.js')
-rw-r--r--src/mongo/shell/shardingtest.js62
1 files changed, 10 insertions, 52 deletions
diff --git a/src/mongo/shell/shardingtest.js b/src/mongo/shell/shardingtest.js
index e4a6ffbf232..1d2586eb25f 100644
--- a/src/mongo/shell/shardingtest.js
+++ b/src/mongo/shell/shardingtest.js
@@ -562,26 +562,21 @@ var ShardingTest = function(params) {
/**
* Waits up to the specified timeout (with a default of 60s) for the balancer to execute one
- * round.
+ * round. If no round has been executed, throws an error.
+ *
+ * The mongosConnection parameter is optional and allows callers to specify a connection
+ * different than the first mongos instance in the list.
*/
- this.awaitBalancerRound = function(timeoutMs) {
+ this.awaitBalancerRound = function(timeoutMs, mongosConnection) {
timeoutMs = timeoutMs || 60000;
+ mongosConnection = mongosConnection || self.s0;
// Get the balancer section from the server status of the config server primary
function getBalancerStatus() {
- var csrsPrimary = self.configRS.getPrimary();
- var serverStatus = csrsPrimary.adminCommand({serverStatus: 1, sharding: 1});
- if (!serverStatus) {
- throw Error('Unable to run serverStatus on "' + csrsPrimary + '"');
- }
-
- var balancerStatus = serverStatus.sharding.balancer;
- if (!balancerStatus) {
- throw Error('Host "' + csrsPrimary + '" does not have the balancer component');
- }
-
- if (balancerStatus.state !== 'running') {
- throw Error('Balancer is stopped');
+ var balancerStatus =
+ assert.commandWorked(mongosConnection.adminCommand({balancerStatus: 1}));
+ if (balancerStatus.mode !== 'full') {
+ throw Error('Balancer is not enabled');
}
return balancerStatus;
@@ -708,43 +703,6 @@ var ShardingTest = function(params) {
};
/**
- * Returns true after the balancer has completed a balancing round.
- *
- * Checks that three pings were sent to config.mongos. The balancer writes a ping
- * at the start and end of a balancing round. If the balancer is in the middle of
- * a round, there could be three pings before the first full balancing round
- * completes: end ping of a round, and start and end pings of the following round.
- */
- this.waitForBalancerRound = function() {
- if (typeof db == "undefined") {
- db = undefined;
- }
- var oldDB = db;
- db = this.config;
-
- var getPings = function() {
- return sh._getConfigDB().mongos.find().toArray();
- };
-
- try {
- // If sh.waitForPingChange returns a non-empty array, config.mongos
- // was not successfully updated and no balancer round was reported.
- for (var i = 0; i < 3; ++i) {
- if (sh.waitForPingChange(getPings()).length != 0) {
- return false;
- }
- }
-
- db = oldDB;
- return true;
- } catch (e) {
- print("Error running waitForPingChange: " + tojson(e));
- db = oldDB;
- return false;
- }
- };
-
- /**
* Kills the mongos with index n.
*/
this.stopMongos = function(n, opts) {