summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordwight <dwight@10gen.com>2010-11-23 04:16:04 -0500
committerdwight <dwight@10gen.com>2010-11-23 04:16:04 -0500
commitf6a923ca3f54b141b984be622da196ec6ea52b09 (patch)
treecc0bf78399b0134f23a36722c45ba22221bf8ec8
parent95517ebb6850029455a5a3caea953f805e7c9ddc (diff)
downloadmongo-f6a923ca3f54b141b984be622da196ec6ea52b09.tar.gz
show repl state in shell prompt. needs more work
-rw-r--r--client/dbclient.h4
-rw-r--r--jstests/rs/rs_basic.js86
-rw-r--r--scripting/engine_spidermonkey.cpp1
-rw-r--r--scripting/sm_db.cpp3
-rw-r--r--shell/collection.js6
-rw-r--r--shell/dbshell.cpp37
-rw-r--r--shell/mongo_vstudio.cpp24
-rw-r--r--shell/shell_utils.cpp2
8 files changed, 104 insertions, 59 deletions
diff --git a/client/dbclient.h b/client/dbclient.h
index 76eff17e5dd..ca93a7684b8 100644
--- a/client/dbclient.h
+++ b/client/dbclient.h
@@ -564,8 +564,8 @@ namespace mongo {
*/
bool eval(const string &dbname, const string &jscode, BSONObj& info, BSONElement& retValue, BSONObj *args = 0);
- /**
-
+ /** validate a collection, checking for errors and reporting back statistics.
+ this operation is slow and blocking.
*/
bool validate( const string &ns , bool scandata=true ){
BSONObj cmd = BSON( "validate" << nsGetCollection( ns ) << "scandata" << scandata );
diff --git a/jstests/rs/rs_basic.js b/jstests/rs/rs_basic.js
index 08de68964b0..27e00348736 100644
--- a/jstests/rs/rs_basic.js
+++ b/jstests/rs/rs_basic.js
@@ -1,51 +1,51 @@
// rs_basic.js
-load("../../jstests/rs/test_framework.js");
-
-function go() {
- assert(__nextPort == 27000, "_nextPort==27000");
-
- a = null;
- try {init
- a = new Mongo("localhost:27000");
- print("using already open mongod on port 27000 -- presume you are debugging or something. should start empty.");
- __nextPort++;
- }
- catch (e) {
- a = rs_mongod();
- }
-
+load("../../jstests/rs/test_framework.js");
+
+function go() {
+ assert(__nextPort == 27000, "_nextPort==27000");
+
+ a = null;
+ try {init
+ a = new Mongo("localhost:27000");
+ print("using already open mongod on port 27000 -- presume you are debugging or something. should start empty.");
+ __nextPort++;
+ }
+ catch (e) {
+ a = rs_mongod();
+ }
+
b = rs_mongod();
- x = a.getDB("admin");
- y = b.getDB("admin");
- memb = [];
- memb[0] = x;
- memb[1] = y;
-
- print("rs_basic.js go(): started 2 servers");
-
- cfg = { _id: 'asdf', members: [] };
- var hn = hostname();
- cfg.members[0] = { _id: 0, host: hn + ":27000" };
- cfg.members[1] = { _id: 1, host: hn + ":27001" };
-
+ x = a.getDB("admin");
+ y = b.getDB("admin");
+ memb = [];
+ memb[0] = x;
+ memb[1] = y;
+
+ print("rs_basic.js go(): started 2 servers");
+
+ cfg = { _id: 'asdf', members: [] };
+ var hn = hostname();
+ cfg.members[0] = { _id: 0, host: hn + ":27000" };
+ cfg.members[1] = { _id: 1, host: hn + ":27001" };
+
print("cfg=" + tojson(cfg));
-}
-
-function init(server) {
- var i = server;
- //i = Random.randInt(2); // a random member of the set
- var m = memb[i];
- assert(!m.ismaster(), "not ismaster");
- var res = m.runCommand({ replSetInitiate: cfg });
- return res;
-}
-
-_path = '../../db/Debug/';
-print("_path var set to " + _path);
-
-print("go() to run");
+}
+
+function init(server) {
+ var i = server;
+ //i = Random.randInt(2); // a random member of the set
+ var m = memb[i];
+ assert(!m.ismaster(), "not ismaster");
+ var res = m.runCommand({ replSetInitiate: cfg });
+ return res;
+}
+
+_path = '../../db/Debug/';
+print("_path var set to " + _path);
+
+print("go() to run");
print("init() to initiate");
diff --git a/scripting/engine_spidermonkey.cpp b/scripting/engine_spidermonkey.cpp
index fd3094a4c43..bdd9aca10a9 100644
--- a/scripting/engine_spidermonkey.cpp
+++ b/scripting/engine_spidermonkey.cpp
@@ -1392,7 +1392,6 @@ namespace mongo {
return _interrupt( cx );
}
-
void installInterrupt( int timeoutMs ) {
if ( timeoutMs != 0 || ScriptEngine::haveCheckInterruptCallback() ) {
TimeoutSpec *spec = new TimeoutSpec;
diff --git a/scripting/sm_db.cpp b/scripting/sm_db.cpp
index fa9287309d9..842e3059b5f 100644
--- a/scripting/sm_db.cpp
+++ b/scripting/sm_db.cpp
@@ -301,8 +301,7 @@ namespace mongo {
DBClientWithCommands * conn = getConnection( cx, obj );
uassert( 10248 , "no connection!" , conn );
-
-
+
string ns = c.toString( argv[0] );
BSONObj o = c.toObject( argv[1] );
diff --git a/shell/collection.js b/shell/collection.js
index db755766b8a..f4bf89e4048 100644
--- a/shell/collection.js
+++ b/shell/collection.js
@@ -37,10 +37,10 @@ DBCollection.prototype.help = function () {
print("\tdb." + shortName + ".drop() drop the collection");
print("\tdb." + shortName + ".dropIndex(name)");
print("\tdb." + shortName + ".dropIndexes()");
- print("\tdb." + shortName + ".ensureIndex(keypattern,options) - options should be an object with these possible fields: name, unique, dropDups");
+ print("\tdb." + shortName + ".ensureIndex(keypattern[,options]) - options is an object with these possible fields: name, unique, dropDups");
print("\tdb." + shortName + ".reIndex()");
- print("\tdb." + shortName + ".find( [query] , [fields]) - first parameter is an optional query filter. second parameter is optional set of fields to return.");
- print("\t e.g. db." + shortName + ".find( { x : 77 } , { name : 1 , x : 1 } )");
+ print("\tdb." + shortName + ".find([query],[fields]) - query is an optional query filter. fields is optional set of fields to return.");
+ print("\t e.g. db." + shortName + ".find( {x:77} , {name:1, x:1} )");
print("\tdb." + shortName + ".find(...).count()");
print("\tdb." + shortName + ".find(...).limit(n)");
print("\tdb." + shortName + ".find(...).skip(n)");
diff --git a/shell/dbshell.cpp b/shell/dbshell.cpp
index cacec0ef58c..30aa0b7994e 100644
--- a/shell/dbshell.cpp
+++ b/shell/dbshell.cpp
@@ -39,6 +39,7 @@ jmp_buf jbuf;
#include "../util/password.h"
#include "../util/version.h"
#include "../util/goodies.h"
+#include "../db/repl/rs_member.h"
using namespace std;
using namespace boost::filesystem;
@@ -223,6 +224,7 @@ void quitNicely( int sig ){
#endif
char * shellReadline( const char * prompt , int handlesigint = 0 ){
+
atPrompt = true;
#ifdef USE_READLINE
@@ -432,6 +434,35 @@ bool fileExists( string file ){
namespace mongo {
extern bool isShell;
+ extern DBClientWithCommands *latestConn;
+}
+
+string stateToString(MemberState s) {
+ if( s.s == MemberState::RS_STARTUP ) return "STARTUP";
+ if( s.s == MemberState::RS_PRIMARY ) return "PRIMARY";
+ if( s.s == MemberState::RS_SECONDARY ) return "SECONDARY";
+ if( s.s == MemberState::RS_RECOVERING ) return "RECOVERING";
+ if( s.s == MemberState::RS_FATAL ) return "FATAL";
+ if( s.s == MemberState::RS_STARTUP2 ) return "STARTUP2";
+ if( s.s == MemberState::RS_ARBITER ) return "ARBITER";
+ if( s.s == MemberState::RS_DOWN ) return "DOWN";
+ if( s.s == MemberState::RS_ROLLBACK ) return "ROLLBACK";
+ return "";
+}
+void sayReplSetMemberState() {
+ try {
+ if( latestConn ) {
+ BSONObj info;
+ if( latestConn->simpleCommand("admin", &info, "replSetGetStatus") ) {
+ stringstream ss;
+ ss << info["set"].String() << ':';
+ int s = info["myState"].Number();
+ MemberState ms(s);
+ ss << stateToString(ms);
+ cout << ss.str();
+ }
+ }
+ } catch(...) { }
}
int _main(int argc, char* argv[]) {
@@ -637,6 +668,11 @@ int _main(int argc, char* argv[]) {
while ( 1 ){
inMultiLine = 0;
gotInterrupted = 0;
+// shellMainScope->localConnect;
+ //DBClientWithCommands *c = getConnection( JSContext *cx, JSObject *obj );
+
+ sayReplSetMemberState();
+
char * line = shellReadline( "> " );
if ( line ){
@@ -700,7 +736,6 @@ int _main(int argc, char* argv[]) {
}
}
-
shellHistoryAdd( line );
}
diff --git a/shell/mongo_vstudio.cpp b/shell/mongo_vstudio.cpp
index d3b0143d56c..3019a2d02e8 100644
--- a/shell/mongo_vstudio.cpp
+++ b/shell/mongo_vstudio.cpp
@@ -1384,7 +1384,7 @@ const StringData _jscode_raw_utils =
"print(\" [, scope : <object where fields go into javascript global scope >]\");\n"
"print(\" [, verbose : true]}\\n\");\n"
"return;\n"
-"} if (x == \"connect\") {\n"
+"} else if (x == \"connect\") {\n"
"print(\"\\nNormally one specifies the server on the mongo shell command line. Run mongo --help to see those options.\");\n"
"print(\"Additional connections may be opened:\\n\");\n"
"print(\" var x = new Mongo('host[:port]');\");\n"
@@ -1394,16 +1394,22 @@ const StringData _jscode_raw_utils =
"print(\"\\nNote: the REPL prompt only auto-reports getLastError() for the shell command line connection.\\n\");\n"
"return;\n"
"}\n"
-"if (x == \"misc\") {\n"
+"else if (x == \"misc\") {\n"
"print(\"\\tb = new BinData(subtype,base64str) create a BSON BinData value\");\n"
"print(\"\\tb.subtype() the BinData subtype (0..255)\");\n"
"print(\"\\tb.length() length of the BinData data in bytes\");\n"
"print(\"\\tb.hex() the data as a hex encoded string\");\n"
"print(\"\\tb.base64() the data as a base 64 encoded string\");\n"
"print(\"\\tb.toString()\");\n"
+"print();\n"
+"print(\"\\to = new ObjectId() create a new ObjectId\");\n"
+"print(\"\\to.getTimestamp() return timestamp derived from first 32 bits of the OID\");\n"
+"print(\"\\to.isObjectId()\");\n"
+"print(\"\\to.toString()\");\n"
+"print(\"\\to.equals(otherid)\");\n"
"return;\n"
"}\n"
-"if (x == \"admin\") {\n"
+"else if (x == \"admin\") {\n"
"print(\"\\tls([path]) list files\");\n"
"print(\"\\tpwd() returns current directory\");\n"
"print(\"\\tlistFiles([path]) returns file list\");\n"
@@ -1416,7 +1422,7 @@ const StringData _jscode_raw_utils =
"print(\"\\tgetMemInfo() diagnostic\");\n"
"return;\n"
"}\n"
-"if (x == \"test\") {\n"
+"else if (x == \"test\") {\n"
"print(\"\\tstartMongodEmpty(args) DELETES DATA DIR and then starts mongod\");\n"
"print(\"\\t returns a connection to the new server\");\n"
"print(\"\\tstartMongodTest() DELETES DATA DIR\");\n"
@@ -1426,6 +1432,7 @@ const StringData _jscode_raw_utils =
"print(\"\\t returns a connection to the new server\");\n"
"return;\n"
"}\n"
+"else if (x == \"\") {\n"
"print(\"\\t\" + \"db.help() help on db methods\");\n"
"print(\"\\t\" + \"db.mycoll.help() help on collection methods\");\n"
"print(\"\\t\" + \"rs.help() help on replica set methods\");\n"
@@ -1445,6 +1452,9 @@ const StringData _jscode_raw_utils =
"print(\"\\t\" + \"DBQuery.shellBatchSize = x set default number of items to display on shell\");\n"
"print(\"\\t\" + \"exit quit the mongo shell\");\n"
"}\n"
+"else\n"
+"print(\"unknown help option\");\n"
+"}\n"
;
extern const JSFile utils;
const JSFile utils = { "shell/utils.js" , _jscode_raw_utils };
@@ -2754,10 +2764,10 @@ const StringData _jscode_raw_collection =
"print(\"\\tdb.\" + shortName + \".drop() drop the collection\");\n"
"print(\"\\tdb.\" + shortName + \".dropIndex(name)\");\n"
"print(\"\\tdb.\" + shortName + \".dropIndexes()\");\n"
-"print(\"\\tdb.\" + shortName + \".ensureIndex(keypattern,options) - options should be an object with these possible fields: name, unique, dropDups\");\n"
+"print(\"\\tdb.\" + shortName + \".ensureIndex(keypattern[,options]) - options is an object with these possible fields: name, unique, dropDups\");\n"
"print(\"\\tdb.\" + shortName + \".reIndex()\");\n"
-"print(\"\\tdb.\" + shortName + \".find( [query] , [fields]) - first parameter is an optional query filter. second parameter is optional set of fields to return.\");\n"
-"print(\"\\t e.g. db.\" + shortName + \".find( { x : 77 } , { name : 1 , x : 1 } )\");\n"
+"print(\"\\tdb.\" + shortName + \".find([query],[fields]) - query is an optional query filter. fields is optional set of fields to return.\");\n"
+"print(\"\\t e.g. db.\" + shortName + \".find( {x:77} , {name:1, x:1} )\");\n"
"print(\"\\tdb.\" + shortName + \".find(...).count()\");\n"
"print(\"\\tdb.\" + shortName + \".find(...).limit(n)\");\n"
"print(\"\\tdb.\" + shortName + \".find(...).skip(n)\");\n"
diff --git a/shell/shell_utils.cpp b/shell/shell_utils.cpp
index badb1c17835..744bd29d04f 100644
--- a/shell/shell_utils.cpp
+++ b/shell/shell_utils.cpp
@@ -50,6 +50,7 @@
namespace mongo {
+ DBClientWithCommands *latestConn = 0;
extern bool dbexitCalled;
#ifdef _WIN32
@@ -903,6 +904,7 @@ namespace mongo {
mongo::mutex _allMyUrisMutex("_allMyUrisMutex");
bool _nokillop = false;
void onConnect( DBClientWithCommands &c ) {
+ latestConn = &c;
if ( _nokillop ) {
return;
}