summaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorAntonin Kral <a.kral@bobek.cz>2010-12-10 13:05:34 +0100
committerAntonin Kral <a.kral@bobek.cz>2010-12-10 13:05:34 +0100
commited4a804c027562e1bf6a0f45dae7326198c29f8e (patch)
tree9d04736132d5421497a80619e30d4c2e03e76728 /shell
parente598e7ada36302f35a0da8ae0c63c34b51b6a720 (diff)
downloadmongodb-ed4a804c027562e1bf6a0f45dae7326198c29f8e.tar.gz
Imported Upstream version 1.6.5
Diffstat (limited to 'shell')
-rw-r--r--shell/mongo_vstudio.cpp37
-rw-r--r--shell/servers.js18
-rw-r--r--shell/shell_utils.cpp4
-rw-r--r--shell/utils.js28
4 files changed, 72 insertions, 15 deletions
diff --git a/shell/mongo_vstudio.cpp b/shell/mongo_vstudio.cpp
index 8b23ef1..c1a224d 100644
--- a/shell/mongo_vstudio.cpp
+++ b/shell/mongo_vstudio.cpp
@@ -654,11 +654,13 @@ const char * jsconcatcode =
"print(\"\\trs.status() { replSetGetStatus : 1 } checks repl set status\");\n"
"print(\"\\trs.initiate() { replSetInitiate : null } initiates set with default settings\");\n"
"print(\"\\trs.initiate(cfg) { replSetInitiate : cfg } initiates set with configuration cfg\");\n"
+ "print(\"\\trs.conf() get the current configuration object from local.system.replset\");\n"
+ "print(\"\\trs.reconfig(cfg) updates the configuration of a running replica set with cfg\");\n"
"print(\"\\trs.add(hostportstr) add a new member to the set with default attributes\");\n"
"print(\"\\trs.add(membercfgobj) add a new member to the set with extra attributes\");\n"
"print(\"\\trs.addArb(hostportstr) add a new member which is arbiterOnly:true\");\n"
"print(\"\\trs.stepDown() step down as primary (momentarily)\");\n"
- "print(\"\\trs.conf() return configuration from local.system.replset\");\n"
+ "print(\"\\trs.remove(hostportstr) remove a host from the replica set\");\n"
"print(\"\\trs.slaveOk() shorthand for db.getMongo().setSlaveOk()\");\n"
"print();\n"
"print(\"\\tdb.isMaster() check who is primary\");\n"
@@ -668,6 +670,9 @@ const char * jsconcatcode =
"rs.status = function () { return db._adminCommand(\"replSetGetStatus\"); }\n"
"rs.isMaster = function () { return db.isMaster(); }\n"
"rs.initiate = function (c) { return db._adminCommand({ replSetInitiate: c }); }\n"
+ "rs.reconfig = function(cfg) {\n"
+ "cfg.version = rs.conf().version + 1;\n"
+ "return db._adminCommand({ replSetReconfig: cfg });}\n"
"rs.add = function (hostport, arb) {\n"
"var cfg = hostport;\n"
"var local = db.getSisterDB(\"local\");\n"
@@ -687,6 +692,18 @@ const char * jsconcatcode =
"rs.stepDown = function () { return db._adminCommand({ replSetStepDown:true}); }\n"
"rs.addArb = function (hn) { return this.add(hn, true); }\n"
"rs.conf = function () { return db.getSisterDB(\"local\").system.replset.findOne(); }\n"
+ "rs.remove = function (hn) {\n"
+ "var local = db.getSisterDB(\"local\");\n"
+ "assert(local.system.replset.count() <= 1, \"error: local.system.replset has unexpected contents\");\n"
+ "var c = local.system.replset.findOne();\n"
+ "assert(c, \"no config object retrievable from local.system.replset\");\n"
+ "c.version++;\n"
+ "for (var i in c.members) {\n"
+ "if (c.members[i].host == hn) {\n"
+ "c.members.splice(i, 1);\n"
+ "return db._adminCommand({ replSetReconfig : c});}}\n"
+ "return \"error: couldn't find \"+hn+\" in \"+tojson(c.members);\n"
+ "};\n"
"help = shellHelper.help = function (x) {\n"
"if (x == \"connect\") {\n"
"print(\"\\nNormally one specifies the server on the mongo shell command line. Run mongo --help to see those options.\");\n"
@@ -1372,7 +1389,17 @@ const char * jsconcatcode =
"var e = n.next();\n"
"if (!verbose) {\n"
"delete e.allPlans;\n"
- "delete e.oldPlan;}\n"
+ "delete e.oldPlan;\n"
+ "if (e.shards){\n"
+ "for (var key in e.shards){\n"
+ "var s = e.shards[key];\n"
+ "if(s.length === undefined){\n"
+ "delete s.allPlans;\n"
+ "delete s.oldPlan;\n"
+ "} else {\n"
+ "for (var i=0; i < s.length; i++){\n"
+ "delete s[i].allPlans;\n"
+ "delete s[i].oldPlan;}}}}}\n"
"return e;}\n"
"DBQuery.prototype.snapshot = function(){\n"
"this._ensureSpecial();\n"
@@ -1452,6 +1479,8 @@ const char * jsconcatcode =
"return __magicNoPrint;}\n"
"DBCollection.prototype.getFullName = function(){\n"
"return this._fullName;}\n"
+ "DBCollection.prototype.getMongo = function(){\n"
+ "return this._db.getMongo();}\n"
"DBCollection.prototype.getDB = function(){\n"
"return this._db;}\n"
"DBCollection.prototype._dbCommand = function( cmd , params ){\n"
@@ -1516,8 +1545,8 @@ const char * jsconcatcode =
"obj[key] = tmp[key];}}\n"
"this._mongo.insert( this._fullName , obj );\n"
"this._lastID = obj._id;}\n"
- "DBCollection.prototype.remove = function( t ){\n"
- "this._mongo.remove( this._fullName , this._massageObject( t ) );}\n"
+ "DBCollection.prototype.remove = function( t , justOne ){\n"
+ "this._mongo.remove( this._fullName , this._massageObject( t ) , justOne ? true : false );}\n"
"DBCollection.prototype.update = function( query , obj , upsert , multi ){\n"
"assert( query , \"need a query\" );\n"
"assert( obj , \"need an object\" );\n"
diff --git a/shell/servers.js b/shell/servers.js
index eb548ea..1b58c81 100644
--- a/shell/servers.js
+++ b/shell/servers.js
@@ -457,13 +457,15 @@ printShardingStatus = function( configDB ){
if (db.partitioned){
configDB.collections.find( { _id : new RegExp( "^" + db._id + "\." ) } ).sort( { _id : 1 } ).forEach(
function( coll ){
- output("\t\t" + coll._id + " chunks:");
- configDB.chunks.find( { "ns" : coll._id } ).sort( { min : 1 } ).forEach(
- function(chunk){
- output( "\t\t\t" + tojson( chunk.min ) + " -->> " + tojson( chunk.max ) +
- " on : " + chunk.shard + " " + tojson( chunk.lastmod ) );
- }
- );
+ if ( coll.dropped == false ){
+ output("\t\t" + coll._id + " chunks:");
+ configDB.chunks.find( { "ns" : coll._id } ).sort( { min : 1 } ).forEach(
+ function(chunk){
+ output( "\t\t\t" + tojson( chunk.min ) + " -->> " + tojson( chunk.max ) +
+ " on : " + chunk.shard + " " + tojson( chunk.lastmod ) );
+ }
+ );
+ }
}
)
}
@@ -1314,7 +1316,7 @@ ReplSetTest.prototype.awaitReplication = function() {
var entry = log.find({}).sort({'$natural': -1}).limit(1).next();
printjson( entry );
var ts = entry['ts'];
- print("TS for " + slave + " is " + ts + " and latest is " + latest);
+ print("TS for " + slave + " is " + ts.t + " and latest is " + latest.t);
print("Oplog size for " + slave + " is " + log.count());
synced = (synced && friendlyEqual(latest,ts))
}
diff --git a/shell/shell_utils.cpp b/shell/shell_utils.cpp
index 5260015..b6a67e2 100644
--- a/shell/shell_utils.cpp
+++ b/shell/shell_utils.cpp
@@ -706,8 +706,8 @@ namespace mongo {
kill_wrapper( pid, signal, port );
int i = 0;
- for( ; i < 65; ++i ) {
- if ( i == 5 ) {
+ for( ; i < 130; ++i ) {
+ if ( i == 30 ) {
char now[64];
time_t_to_String(time(0), now);
now[ 20 ] = 0;
diff --git a/shell/utils.js b/shell/utils.js
index de26403..71f3fbd 100644
--- a/shell/utils.js
+++ b/shell/utils.js
@@ -1052,11 +1052,13 @@ rs.help = function () {
print("\trs.status() { replSetGetStatus : 1 } checks repl set status");
print("\trs.initiate() { replSetInitiate : null } initiates set with default settings");
print("\trs.initiate(cfg) { replSetInitiate : cfg } initiates set with configuration cfg");
+ print("\trs.conf() get the current configuration object from local.system.replset");
+ print("\trs.reconfig(cfg) updates the configuration of a running replica set with cfg");
print("\trs.add(hostportstr) add a new member to the set with default attributes");
print("\trs.add(membercfgobj) add a new member to the set with extra attributes");
print("\trs.addArb(hostportstr) add a new member which is arbiterOnly:true");
print("\trs.stepDown() step down as primary (momentarily)");
- print("\trs.conf() return configuration from local.system.replset");
+ print("\trs.remove(hostportstr) remove a host from the replica set");
print("\trs.slaveOk() shorthand for db.getMongo().setSlaveOk()");
print();
print("\tdb.isMaster() check who is primary");
@@ -1067,6 +1069,11 @@ rs.slaveOk = function () { return db.getMongo().setSlaveOk(); }
rs.status = function () { return db._adminCommand("replSetGetStatus"); }
rs.isMaster = function () { return db.isMaster(); }
rs.initiate = function (c) { return db._adminCommand({ replSetInitiate: c }); }
+rs.reconfig = function(cfg) {
+ cfg.version = rs.conf().version + 1;
+
+ return db._adminCommand({ replSetReconfig: cfg });
+}
rs.add = function (hostport, arb) {
var cfg = hostport;
@@ -1074,7 +1081,9 @@ rs.add = function (hostport, arb) {
assert(local.system.replset.count() <= 1, "error: local.system.replset has unexpected contents");
var c = local.system.replset.findOne();
assert(c, "no config object retrievable from local.system.replset");
+
c.version++;
+
var max = 0;
for (var i in c.members)
if (c.members[i]._id > max) max = c.members[i]._id;
@@ -1090,6 +1099,23 @@ rs.stepDown = function () { return db._adminCommand({ replSetStepDown:true}); }
rs.addArb = function (hn) { return this.add(hn, true); }
rs.conf = function () { return db.getSisterDB("local").system.replset.findOne(); }
+rs.remove = function (hn) {
+ var local = db.getSisterDB("local");
+ assert(local.system.replset.count() <= 1, "error: local.system.replset has unexpected contents");
+ var c = local.system.replset.findOne();
+ assert(c, "no config object retrievable from local.system.replset");
+ c.version++;
+
+ for (var i in c.members) {
+ if (c.members[i].host == hn) {
+ c.members.splice(i, 1);
+ return db._adminCommand({ replSetReconfig : c});
+ }
+ }
+
+ return "error: couldn't find "+hn+" in "+tojson(c.members);
+};
+
help = shellHelper.help = function (x) {
if (x == "connect") {
print("\nNormally one specifies the server on the mongo shell command line. Run mongo --help to see those options.");