summaryrefslogtreecommitdiff
path: root/jstests/sharding/autosplit_with_balancer.js
diff options
context:
space:
mode:
authorclang-format-7.0.1 <adam.martin@10gen.com>2019-07-26 18:20:35 -0400
committerADAM David Alan Martin <adam.martin@10gen.com>2019-07-27 11:02:23 -0400
commit134a4083953270e8a11430395357fb70a29047ad (patch)
treedd428e1230e31d92b20b393dfdc17ffe7fa79cb6 /jstests/sharding/autosplit_with_balancer.js
parent1e46b5049003f427047e723ea5fab15b5a9253ca (diff)
downloadmongo-134a4083953270e8a11430395357fb70a29047ad.tar.gz
SERVER-41772 Apply clang-format 7.0.1 to the codebase
Diffstat (limited to 'jstests/sharding/autosplit_with_balancer.js')
-rw-r--r--jstests/sharding/autosplit_with_balancer.js270
1 files changed, 135 insertions, 135 deletions
diff --git a/jstests/sharding/autosplit_with_balancer.js b/jstests/sharding/autosplit_with_balancer.js
index 8720790596f..0372ca09b9a 100644
--- a/jstests/sharding/autosplit_with_balancer.js
+++ b/jstests/sharding/autosplit_with_balancer.js
@@ -1,166 +1,166 @@
(function() {
- 'use strict';
+'use strict';
- var s = new ShardingTest({shards: 2, mongos: 2, other: {enableAutoSplit: true}});
+var s = new ShardingTest({shards: 2, mongos: 2, other: {enableAutoSplit: true}});
- s.adminCommand({enablesharding: "test"});
- s.ensurePrimaryShard('test', s.shard1.shardName);
- s.adminCommand({shardcollection: "test.foo", key: {num: 1}});
+s.adminCommand({enablesharding: "test"});
+s.ensurePrimaryShard('test', s.shard1.shardName);
+s.adminCommand({shardcollection: "test.foo", key: {num: 1}});
- var bigString = "";
- while (bigString.length < 1024 * 50) {
- bigString += "asocsancdnsjfnsdnfsjdhfasdfasdfasdfnsadofnsadlkfnsaldknfsad";
- }
+var bigString = "";
+while (bigString.length < 1024 * 50) {
+ bigString += "asocsancdnsjfnsdnfsjdhfasdfasdfasdfnsadofnsadlkfnsaldknfsad";
+}
- var db = s.getDB("test");
- var coll = db.foo;
+var db = s.getDB("test");
+var coll = db.foo;
- var i = 0;
- for (var j = 0; j < 30; j++) {
- print("j:" + j + " : " + Date.timeFunc(function() {
- var bulk = coll.initializeUnorderedBulkOp();
- for (var k = 0; k < 100; k++) {
- bulk.insert({num: i, s: bigString});
- i++;
- }
- assert.writeOK(bulk.execute());
- }));
- }
+var i = 0;
+for (var j = 0; j < 30; j++) {
+ print("j:" + j + " : " + Date.timeFunc(function() {
+ var bulk = coll.initializeUnorderedBulkOp();
+ for (var k = 0; k < 100; k++) {
+ bulk.insert({num: i, s: bigString});
+ i++;
+ }
+ assert.writeOK(bulk.execute());
+ }));
+}
- s.startBalancer();
+s.startBalancer();
- let confirmBalancerSettings = function(expectedBalancerOn, expectedAutoSplitOn) {
- let configSettings = s.s.getDB('config').settings;
+let confirmBalancerSettings = function(expectedBalancerOn, expectedAutoSplitOn) {
+ let configSettings = s.s.getDB('config').settings;
- let balancerSettings = configSettings.findOne({_id: 'balancer'});
- assert.neq(null, balancerSettings);
- assert.eq(expectedBalancerOn, !balancerSettings.stopped);
- assert.eq(expectedBalancerOn, balancerSettings.mode == 'full');
+ let balancerSettings = configSettings.findOne({_id: 'balancer'});
+ assert.neq(null, balancerSettings);
+ assert.eq(expectedBalancerOn, !balancerSettings.stopped);
+ assert.eq(expectedBalancerOn, balancerSettings.mode == 'full');
- let autoSplitSettings = configSettings.findOne({_id: 'autosplit'});
- assert.neq(null, autoSplitSettings);
- assert.eq(expectedAutoSplitOn, autoSplitSettings.enabled);
- };
+ let autoSplitSettings = configSettings.findOne({_id: 'autosplit'});
+ assert.neq(null, autoSplitSettings);
+ assert.eq(expectedAutoSplitOn, autoSplitSettings.enabled);
+};
- confirmBalancerSettings(true, true);
+confirmBalancerSettings(true, true);
- assert.eq(i, j * 100, "setup");
+assert.eq(i, j * 100, "setup");
- // Until SERVER-9715 is fixed, the sync command must be run on a diff connection
- new Mongo(s.s.host).adminCommand("connpoolsync");
+// Until SERVER-9715 is fixed, the sync command must be run on a diff connection
+new Mongo(s.s.host).adminCommand("connpoolsync");
- print("done inserting data");
+print("done inserting data");
- print("datasize: " +
- tojson(s.getPrimaryShard("test").getDB("admin").runCommand({datasize: "test.foo"})));
- s.printChunks();
+print("datasize: " +
+ tojson(s.getPrimaryShard("test").getDB("admin").runCommand({datasize: "test.foo"})));
+s.printChunks();
- var counta, countb;
+var counta, countb;
- function doCountsGlobal() {
- counta = s._connections[0].getDB("test").foo.count();
- countb = s._connections[1].getDB("test").foo.count();
- return counta + countb;
- }
+function doCountsGlobal() {
+ counta = s._connections[0].getDB("test").foo.count();
+ countb = s._connections[1].getDB("test").foo.count();
+ return counta + countb;
+}
- // Wait for the chunks to distribute
- assert.soon(function() {
- doCountsGlobal();
- print("Counts: " + counta + countb);
+// Wait for the chunks to distribute
+assert.soon(function() {
+ doCountsGlobal();
+ print("Counts: " + counta + countb);
- return counta > 0 && countb > 0;
- });
+ return counta > 0 && countb > 0;
+});
- print("checkpoint B");
+print("checkpoint B");
- var missing = [];
+var missing = [];
- for (i = 0; i < j * 100; i++) {
- var x = coll.findOne({num: i});
+for (i = 0; i < j * 100; i++) {
+ var x = coll.findOne({num: i});
+ if (!x) {
+ missing.push(i);
+ print("can't find: " + i);
+ sleep(5000);
+ x = coll.findOne({num: i});
if (!x) {
- missing.push(i);
- print("can't find: " + i);
- sleep(5000);
- x = coll.findOne({num: i});
- if (!x) {
- print("still can't find: " + i);
-
- for (var zzz = 0; zzz < s._connections.length; zzz++) {
- if (s._connections[zzz].getDB("test").foo.findOne({num: i})) {
- print("found on wrong server: " + s._connections[zzz]);
- }
+ print("still can't find: " + i);
+
+ for (var zzz = 0; zzz < s._connections.length; zzz++) {
+ if (s._connections[zzz].getDB("test").foo.findOne({num: i})) {
+ print("found on wrong server: " + s._connections[zzz]);
}
}
}
}
-
- s.printChangeLog();
-
- print("missing: " + tojson(missing));
- assert.soon(function(z) {
- return doCountsGlobal() == j * 100;
- }, "from each a:" + counta + " b:" + countb + " i:" + i);
- print("checkpoint B.a");
- s.printChunks();
- assert.eq(j * 100, coll.find().limit(100000000).itcount(), "itcount A");
- assert.eq(j * 100, counta + countb, "from each 2 a:" + counta + " b:" + countb + " i:" + i);
- assert(missing.length == 0, "missing : " + tojson(missing));
-
- print("checkpoint C");
-
- assert(Array.unique(s.config.chunks.find({ns: 'test.foo'}).toArray().map(function(z) {
- return z.shard;
- })).length == 2,
- "should be using both servers");
-
- for (i = 0; i < 100; i++) {
- cursor = coll.find().batchSize(5);
- cursor.next();
- cursor.close();
- }
-
- print("checkpoint D");
-
- // Test non-sharded cursors
- db = s.getDB("test2");
- var t = db.foobar;
- for (i = 0; i < 100; i++)
- t.save({_id: i});
- for (i = 0; i < 100; i++) {
- var cursor = t.find().batchSize(2);
- cursor.next();
- assert.lt(0, db.serverStatus().metrics.cursor.open.total, "cursor1");
- cursor.close();
- }
-
- assert.eq(0, db.serverStatus().metrics.cursor.open.total, "cursor2");
-
- // Stop the balancer, otherwise it may grab some connections from the pool for itself
- s.stopBalancer();
-
- confirmBalancerSettings(false, false);
-
- print("checkpoint E");
-
- assert(t.findOne(), "check close 0");
-
- for (i = 0; i < 20; i++) {
- var conn = new Mongo(db.getMongo().host);
- var temp2 = conn.getDB("test2").foobar;
- assert.eq(conn._fullNameSpace, t._fullNameSpace, "check close 1");
- assert(temp2.findOne(), "check close 2");
- conn.close();
- }
-
- print("checkpoint F");
-
- assert.throws(function() {
- s.getDB("test").foo.find().sort({s: 1}).forEach(function(x) {
- printjsononeline(x.substring(0, x.length > 30 ? 30 : x.length));
- });
+}
+
+s.printChangeLog();
+
+print("missing: " + tojson(missing));
+assert.soon(function(z) {
+ return doCountsGlobal() == j * 100;
+}, "from each a:" + counta + " b:" + countb + " i:" + i);
+print("checkpoint B.a");
+s.printChunks();
+assert.eq(j * 100, coll.find().limit(100000000).itcount(), "itcount A");
+assert.eq(j * 100, counta + countb, "from each 2 a:" + counta + " b:" + countb + " i:" + i);
+assert(missing.length == 0, "missing : " + tojson(missing));
+
+print("checkpoint C");
+
+assert(Array.unique(s.config.chunks.find({ns: 'test.foo'}).toArray().map(function(z) {
+ return z.shard;
+ })).length == 2,
+ "should be using both servers");
+
+for (i = 0; i < 100; i++) {
+ cursor = coll.find().batchSize(5);
+ cursor.next();
+ cursor.close();
+}
+
+print("checkpoint D");
+
+// Test non-sharded cursors
+db = s.getDB("test2");
+var t = db.foobar;
+for (i = 0; i < 100; i++)
+ t.save({_id: i});
+for (i = 0; i < 100; i++) {
+ var cursor = t.find().batchSize(2);
+ cursor.next();
+ assert.lt(0, db.serverStatus().metrics.cursor.open.total, "cursor1");
+ cursor.close();
+}
+
+assert.eq(0, db.serverStatus().metrics.cursor.open.total, "cursor2");
+
+// Stop the balancer, otherwise it may grab some connections from the pool for itself
+s.stopBalancer();
+
+confirmBalancerSettings(false, false);
+
+print("checkpoint E");
+
+assert(t.findOne(), "check close 0");
+
+for (i = 0; i < 20; i++) {
+ var conn = new Mongo(db.getMongo().host);
+ var temp2 = conn.getDB("test2").foobar;
+ assert.eq(conn._fullNameSpace, t._fullNameSpace, "check close 1");
+ assert(temp2.findOne(), "check close 2");
+ conn.close();
+}
+
+print("checkpoint F");
+
+assert.throws(function() {
+ s.getDB("test").foo.find().sort({s: 1}).forEach(function(x) {
+ printjsononeline(x.substring(0, x.length > 30 ? 30 : x.length));
});
+});
- print("checkpoint G");
+print("checkpoint G");
- s.stop();
+s.stop();
})();