summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorDwight <dmerriman@gmail.com>2010-04-23 15:50:49 -0400
committerDwight <dmerriman@gmail.com>2010-04-23 15:50:49 -0400
commit837fd2cd86362410da83f3d188162545e100d94d (patch)
tree0dab1098258ff4bb907af4720dc64a2ef76c5cc7 /db
parente7e41410dc4dacc266ab1e1c644727ec44c6a5b8 (diff)
downloadmongo-837fd2cd86362410da83f3d188162545e100d94d.tar.gz
/_commands in the http interface
Diffstat (limited to 'db')
-rw-r--r--db/client.cpp4
-rw-r--r--db/clientcursor.cpp4
-rw-r--r--db/cloner.cpp30
-rw-r--r--db/cmdline.cpp4
-rw-r--r--db/commands.cpp70
-rw-r--r--db/commands.h14
-rw-r--r--db/dbcommands.cpp207
-rw-r--r--db/dbcommands_admin.cpp34
-rw-r--r--db/dbeval.cpp9
-rw-r--r--db/dbwebserver.cpp40
-rw-r--r--db/index_geo2d.cpp8
-rw-r--r--db/mr.cpp8
-rw-r--r--db/oplog.cpp4
-rw-r--r--db/repl.cpp28
-rw-r--r--db/repl/health.cpp4
-rw-r--r--db/repl/replset_commands.cpp13
-rw-r--r--db/security_commands.cpp12
-rw-r--r--db/stats/top.cpp4
18 files changed, 315 insertions, 182 deletions
diff --git a/db/client.cpp b/db/client.cpp
index dbfcbd02aae..9d52fe0972c 100644
--- a/db/client.cpp
+++ b/db/client.cpp
@@ -264,8 +264,8 @@ namespace mongo {
class HandshakeCmd : public Command {
public:
HandshakeCmd() : Command( "handshake" ){}
- virtual LockType locktype(){ return NONE; }
- virtual bool slaveOk(){ return true; }
+ virtual LockType locktype() const { return NONE; }
+ virtual bool slaveOk() const { return true; }
virtual bool adminOnly(){ return false; }
virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
Client& c = cc();
diff --git a/db/clientcursor.cpp b/db/clientcursor.cpp
index d57b04c36f9..9116f03da14 100644
--- a/db/clientcursor.cpp
+++ b/db/clientcursor.cpp
@@ -285,11 +285,11 @@ namespace mongo {
class CmdCursorInfo : public Command {
public:
CmdCursorInfo() : Command( "cursorInfo", true ) {}
- virtual bool slaveOk() { return true; }
+ virtual bool slaveOk() const { return true; }
virtual void help( stringstream& help ) const {
help << " example: { cursorInfo : 1 }";
}
- virtual LockType locktype(){ return NONE; }
+ virtual LockType locktype() const { return NONE; }
bool run(const char *dbname, BSONObj& jsobj, string& errmsg, BSONObjBuilder& result, bool fromRepl ){
recursive_scoped_lock lock(ClientCursor::ccmutex);
result.append("byLocation_size", unsigned( ClientCursor::byLoc.size() ) );
diff --git a/db/cloner.cpp b/db/cloner.cpp
index d300721a2df..6c976555d18 100644
--- a/db/cloner.cpp
+++ b/db/cloner.cpp
@@ -413,13 +413,13 @@ namespace mongo {
*/
class CmdClone : public Command {
public:
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return false;
}
- virtual LockType locktype(){ return WRITE; }
+ virtual LockType locktype() const { return WRITE; }
virtual void help( stringstream &help ) const {
help << "clone this database from an instance of the db on another host\n";
- help << "example: { clone : \"host13\" }";
+ help << "{ clone : \"host13\" }";
}
CmdClone() : Command("clone") { }
virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
@@ -436,10 +436,10 @@ namespace mongo {
class CmdCloneCollection : public Command {
public:
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return false;
}
- virtual LockType locktype(){ return WRITE; }
+ virtual LockType locktype() const { return WRITE; }
CmdCloneCollection() : Command("cloneCollection") { }
virtual void help( stringstream &help ) const {
help << " example: { cloneCollection: <collection ns>, from: <hostname>, query: <query> }";
@@ -480,10 +480,10 @@ namespace mongo {
class CmdStartCloneCollection : public Command {
public:
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return false;
}
- virtual LockType locktype(){ return WRITE; }
+ virtual LockType locktype() const { return WRITE; }
CmdStartCloneCollection() : Command("startCloneCollection") { }
virtual void help( stringstream &help ) const {
help << " example: { startCloneCollection: <collection ns>, from: <hostname>, query: <query> }";
@@ -534,10 +534,10 @@ namespace mongo {
class CmdFinishCloneCollection : public Command {
public:
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return false;
}
- virtual LockType locktype(){ return WRITE; }
+ virtual LockType locktype() const { return WRITE; }
CmdFinishCloneCollection() : Command("finishCloneCollection") { }
virtual void help( stringstream &help ) const {
help << " example: { finishCloneCollection: <finishToken> }";
@@ -587,10 +587,10 @@ namespace mongo {
virtual bool adminOnly() {
return true;
}
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return false;
}
- virtual LockType locktype(){ return WRITE; }
+ virtual LockType locktype() const { return WRITE; }
virtual void help( stringstream &help ) const {
help << "get a nonce for subsequent copy db request from secure server\n";
help << "usage: {copydbgetnonce: 1, fromhost: <hostname>}";
@@ -628,10 +628,10 @@ namespace mongo {
virtual bool adminOnly() {
return true;
}
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return false;
}
- virtual LockType locktype(){ return WRITE; }
+ virtual LockType locktype() const { return WRITE; }
virtual void help( stringstream &help ) const {
help << "copy a database from another host to this host\n";
help << "usage: {copydb: 1, fromhost: <hostname>, fromdb: <db>, todb: <db>[, username: <username>, nonce: <nonce>, key: <key>]}";
@@ -678,10 +678,10 @@ namespace mongo {
virtual bool adminOnly() {
return true;
}
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return false;
}
- virtual LockType locktype(){ return WRITE; }
+ virtual LockType locktype() const { return WRITE; }
virtual bool logTheOp() {
return true; // can't log steps when doing fast rename within a db, so always log the op rather than individual steps comprising it.
}
diff --git a/db/cmdline.cpp b/db/cmdline.cpp
index 2d15279fb29..ca673f33b12 100644
--- a/db/cmdline.cpp
+++ b/db/cmdline.cpp
@@ -148,9 +148,9 @@ namespace mongo {
class CmdGetCmdLineOpts : Command{
public:
CmdGetCmdLineOpts(): Command("getCmdLineOpts") {}
- virtual LockType locktype() { return NONE; }
+ virtual LockType locktype() const { return NONE; }
virtual bool adminOnly() { return true; }
- virtual bool slaveOk() { return true; }
+ virtual bool slaveOk() const { return true; }
virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl){
result.append("argv", argvArray);
diff --git a/db/commands.cpp b/db/commands.cpp
index 520a79c13bb..5d17bb09938 100644
--- a/db/commands.cpp
+++ b/db/commands.cpp
@@ -25,24 +25,88 @@
namespace mongo {
+ map<string,Command*> * Command::_commandsByBestName;
map<string,Command*> * Command::_webCommands;
map<string,Command*> * Command::_commands;
- Command::Command(const char *_name, bool web) : name(_name) {
+ void Command::htmlHelp(stringstream& ss) const {
+ string helpStr;
+ {
+ stringstream h;
+ help(h);
+ helpStr = h.str();
+ }
+ ss << "\n<tr><td>";
+ bool web = _webCommands->count(name) != 0;
+ if( web ) ss << "<a href=\"/" << name << "?text\">";
+ ss << name;
+ if( web ) ss << "</a>";
+ ss << "</td>\n";
+ ss << "<td>";
+ int l = locktype();
+ //if( l == NONE ) ss << "N ";
+ if( l == READ ) ss << "R ";
+ else if( l == WRITE ) ss << "W ";
+ if( slaveOk() )
+ ss << "S ";
+ ss << "</td>";
+ ss << "<td>";
+ if( helpStr != "no help defined" ) {
+ const char *p = helpStr.c_str();
+ while( *p ) {
+ if( *p == '{' )
+ ss << "<code>";
+ else if( *p == '}' ) {
+ ss << "}</code>";
+ p++;
+ continue;
+ }
+ if( strncmp(p, "http:", 5) == 0 ) {
+ ss << "<a href=\"";
+ const char *q = p;
+ while( *q && *q != ' ' && *q != '\n' )
+ ss << *q++;
+ ss << "\">";
+ q = p;
+ if( startsWith(q, "http://www.mongodb.org/display/") )
+ q += 31;
+ while( *q && *q != ' ' && *q != '\n' ) {
+ ss << (*q == '+' ? ' ' : *q);
+ q++;
+ }
+ ss << "</a>";
+ p = q;
+ continue;
+ }
+ if( *p == '\n' ) ss << "<br>";
+ else ss << *p;
+ p++;
+ }
+ }
+ ss << "</td>";
+ ss << "</tr>\n";
+ }
+
+ Command::Command(const char *_name, bool web, const char *oldName) : name(_name) {
// register ourself.
- if ( _commands == 0 ) {
+ if ( _commands == 0 )
_commands = new map<string,Command*>;
- }
+ if( _commandsByBestName == 0 )
+ _commandsByBestName = new map<string,Command*>;
Command*& c = (*_commands)[name];
if ( c )
log() << "warning: 2 commands with name: " << _name << endl;
c = this;
+ (*_commandsByBestName)[name] = this;
if( web ) {
if( _webCommands == 0 )
_webCommands = new map<string,Command*>;
(*_webCommands)[name] = this;
}
+
+ if( oldName )
+ (*_commands)[oldName] = this;
}
void Command::help( stringstream& help ) const {
diff --git a/db/commands.h b/db/commands.h
index f3482481b48..bf70a348a1f 100644
--- a/db/commands.h
+++ b/db/commands.h
@@ -52,13 +52,15 @@ namespace mongo {
if NONE, can't use Client::Context setup
use with caution
*/
- virtual LockType locktype() = 0;
+ virtual LockType locktype() const = 0;
/* Return true if only the admin ns has privileges to run this command. */
virtual bool adminOnly() {
return false;
}
+ void htmlHelp(stringstream&) const;
+
/* Like adminOnly, but even stricter: we must either be authenticated for admin db,
or, if running without auth, on the local interface.
@@ -69,7 +71,7 @@ namespace mongo {
/* Return true if slaves of a replication pair are allowed to execute the command
(the command directly from a client -- if fromRepl, always allowed).
*/
- virtual bool slaveOk() = 0;
+ virtual bool slaveOk() const = 0;
/* Return true if the client force a command to be run on a slave by
turning on the 'slaveok' option in the command query.
@@ -94,8 +96,10 @@ namespace mongo {
*/
virtual bool requiresAuth() { return true; }
- /** @param webUI expose the command in the web ui as localhost:28017/<name> */
- Command(const char *_name, bool webUI = false);
+ /** @param webUI expose the command in the web ui as localhost:28017/<name>
+ @param oldName an optional old, deprecated name for the command
+ */
+ Command(const char *_name, bool webUI = false, const char *oldName = 0);
virtual ~Command() {}
@@ -109,9 +113,11 @@ namespace mongo {
}
static map<string,Command*> * _commands;
+ static map<string,Command*> * _commandsByBestName;
static map<string,Command*> * _webCommands;
public:
+ static const map<string,Command*>* commandsByBestName() { return _commandsByBestName; }
static const map<string,Command*>* webCommands() { return _webCommands; }
static bool runAgainstRegistered(const char *ns, BSONObj& jsobj, BSONObjBuilder& anObjBuilder);
static LockType locktype( const string& name );
diff --git a/db/dbcommands.cpp b/db/dbcommands.cpp
index bbd15021e55..59dffe9c2b4 100644
--- a/db/dbcommands.cpp
+++ b/db/dbcommands.cpp
@@ -53,10 +53,10 @@ namespace mongo {
virtual bool logTheOp() {
return false;
}
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return true;
}
- virtual LockType locktype(){ return NONE; }
+ virtual LockType locktype() const { return NONE; }
virtual void help( stringstream& help ) const {
help << "shutdown the database. must be ran against admin db and either (1) ran from localhost or (2) authenticated.\n";
}
@@ -78,12 +78,12 @@ namespace mongo {
*/
class CmdResetError : public Command {
public:
- virtual LockType locktype(){ return NONE; }
+ virtual LockType locktype() const { return NONE; }
virtual bool requiresAuth() { return false; }
virtual bool logTheOp() {
return false;
}
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return true;
}
virtual void help( stringstream& help ) const {
@@ -101,16 +101,16 @@ namespace mongo {
/* for diagnostic / testing purposes. */
class CmdSleep : public Command {
public:
- virtual LockType locktype(){ return READ; }
+ virtual LockType locktype() const { return READ; }
virtual bool adminOnly() { return true; }
virtual bool logTheOp() {
return false;
}
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return true;
}
virtual void help( stringstream& help ) const {
- help << "internal / make db block for 100 seconds";
+ help << "internal testing command. Makes db block (in a read lock) for 100 seconds";
}
CmdSleep() : Command("sleep") {}
bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
@@ -121,16 +121,16 @@ namespace mongo {
class CmdGetLastError : public Command {
public:
- virtual LockType locktype(){ return NONE; }
+ virtual LockType locktype() const { return NONE; }
virtual bool requiresAuth() { return false; }
virtual bool logTheOp() {
return false;
}
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return true;
}
virtual void help( stringstream& help ) const {
- help << "return error status of the last operation";
+ help << "return error status of the last operation on this connection";
}
CmdGetLastError() : Command("getlasterror") {}
bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
@@ -182,13 +182,16 @@ namespace mongo {
/* for testing purposes only */
class CmdForceError : public Command {
public:
+ virtual void help( stringstream& help ) const {
+ help << "for testing purposes only. forces a user assertion exception";
+ }
virtual bool logTheOp() {
return false;
}
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return true;
}
- virtual LockType locktype(){ return NONE; }
+ virtual LockType locktype() const { return NONE; }
CmdForceError() : Command("forceerror") {}
bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
uassert( 10038 , "forced error", false);
@@ -198,7 +201,7 @@ namespace mongo {
class CmdGetPrevError : public Command {
public:
- virtual LockType locktype(){ return NONE; }
+ virtual LockType locktype() const { return NONE; }
virtual bool requiresAuth() { return false; }
virtual bool logTheOp() {
return false;
@@ -206,7 +209,7 @@ namespace mongo {
virtual void help( stringstream& help ) const {
help << "check for errors since last reseterror commandcal";
}
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return true;
}
CmdGetPrevError() : Command("getpreverror") {}
@@ -230,10 +233,10 @@ namespace mongo {
virtual void help( stringstream& help ) const {
help << "convert to id based errors rather than connection based";
}
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return true;
}
- virtual LockType locktype(){ return NONE; }
+ virtual LockType locktype() const { return NONE; }
CmdSwitchToClientErrors() : Command("switchtoclienterrors") {}
bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
if ( lastError.getID() ){
@@ -255,10 +258,10 @@ namespace mongo {
virtual void help( stringstream& help ) const {
help << "drop (delete) this database";
}
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return false;
}
- virtual LockType locktype(){ return WRITE; }
+ virtual LockType locktype() const { return WRITE; }
CmdDropDatabase() : Command("dropDatabase") {}
bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
BSONElement e = cmdObj.getField(name);
@@ -277,13 +280,13 @@ namespace mongo {
virtual bool logTheOp() {
return false;
}
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return true;
}
virtual void help( stringstream& help ) const {
help << "repair database. also compacts. note: slow.";
}
- virtual LockType locktype(){ return WRITE; }
+ virtual LockType locktype() const { return WRITE; }
CmdRepairDatabase() : Command("repairDatabase") {}
bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
BSONElement e = cmdObj.getField(name);
@@ -305,13 +308,16 @@ namespace mongo {
*/
class CmdProfile : public Command {
public:
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return true;
}
virtual void help( stringstream& help ) const {
- help << "enable or disable performance profiling";
+ help << "enable or disable performance profiling\n";
+ help << "{ profile : <n> }\n";
+ help << "0=off 1=log slow ops 2=log all\n";
+ help << "http://www.mongodb.org/display/DOCS/Database+Profiler";
}
- virtual LockType locktype(){ return WRITE; }
+ virtual LockType locktype() const { return WRITE; }
CmdProfile() : Command("profile") {}
bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
BSONElement e = cmdObj.getField(name);
@@ -334,14 +340,18 @@ namespace mongo {
class CmdServerStatus : public Command {
public:
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return true;
}
CmdServerStatus() : Command("serverStatus", true) {
started = time(0);
}
- virtual LockType locktype(){ return NONE; }
+ virtual LockType locktype() const { return NONE; }
+
+ virtual void help( stringstream& help ) const {
+ help << "returns lots of administrative server statistics";
+ }
bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
@@ -443,14 +453,14 @@ namespace mongo {
/* just to check if the db has asserted */
class CmdAssertInfo : public Command {
public:
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return true;
}
virtual void help( stringstream& help ) const {
help << "check if any asserts have occurred on the server";
}
- virtual LockType locktype(){ return WRITE; }
- CmdAssertInfo() : Command("assertinfo",true) {}
+ virtual LockType locktype() const { return WRITE; }
+ CmdAssertInfo() : Command("assertInfo",true,"assertinfo") {}
bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
result.appendBool("dbasserted", lastAssert[0].isSet() || lastAssert[1].isSet() || lastAssert[2].isSet());
result.appendBool("asserted", lastAssert[0].isSet() || lastAssert[1].isSet() || lastAssert[2].isSet() || lastAssert[3].isSet());
@@ -464,10 +474,11 @@ namespace mongo {
class CmdGetOpTime : public Command {
public:
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return true;
}
- virtual LockType locktype(){ return NONE; }
+ virtual void help( stringstream& help ) const { help << "internal"; }
+ virtual LockType locktype() const { return NONE; }
CmdGetOpTime() : Command("getoptime") { }
bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
writelock l( "" );
@@ -489,14 +500,14 @@ namespace mongo {
class CmdDiagLogging : public Command {
public:
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return true;
}
CmdDiagLogging() : Command("diagLogging") { }
bool adminOnly() {
return true;
}
- virtual LockType locktype(){ return WRITE; }
+ virtual LockType locktype() const { return WRITE; }
bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool) {
int was = _diaglog.setLevel( cmdObj.firstElement().numberInt() );
stringstream ss;
@@ -611,13 +622,14 @@ namespace mongo {
virtual bool logTheOp() {
return true;
}
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return false;
}
virtual bool adminOnly() {
return false;
}
- virtual LockType locktype(){ return WRITE; }
+ virtual void help( stringstream& help ) const { help << "drop a collection\n{drop : <collectionName>}"; }
+ virtual LockType locktype() const { return WRITE; }
virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool) {
string nsToDrop = cc().database()->name + '.' + cmdObj.getField(name).valuestr();
NamespaceDetails *d = nsdetails(nsToDrop.c_str());
@@ -636,12 +648,12 @@ namespace mongo {
/* select count(*) */
class CmdCount : public Command {
public:
- virtual LockType locktype(){ return READ; }
+ virtual LockType locktype() const { return READ; }
CmdCount() : Command("count") { }
virtual bool logTheOp() {
return false;
}
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
// ok on --slave setups, not ok for nonmaster of a repl pair (unless override)
return replSettings.slave == SimpleSlave;
}
@@ -651,6 +663,7 @@ namespace mongo {
virtual bool adminOnly() {
return false;
}
+ virtual void help( stringstream& help ) const { help << "count objects in collection"; }
virtual bool run(const char *_ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool) {
string ns = cc().database()->name + '.' + cmdObj.getField(name).valuestr();
string err;
@@ -679,13 +692,13 @@ namespace mongo {
virtual bool logTheOp() {
return false;
}
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return false;
}
virtual bool adminOnly() {
return false;
}
- virtual LockType locktype(){ return WRITE; }
+ virtual LockType locktype() const { return WRITE; }
virtual void help( stringstream& help ) const {
help << "create a collection";
}
@@ -705,14 +718,14 @@ namespace mongo {
virtual bool logTheOp() {
return true;
}
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return false;
}
- virtual LockType locktype(){ return WRITE; }
+ virtual LockType locktype() const { return WRITE; }
virtual void help( stringstream& help ) const {
help << "drop indexes for a collection";
}
- CmdDropIndexes(const char *cmdname = "dropIndexes") : Command(cmdname) { }
+ CmdDropIndexes(const char *cmdname = "dropIndexes") : Command(cmdname, false, "deleteIndexes") { }
bool run(const char *ns, BSONObj& jsobj, string& errmsg, BSONObjBuilder& anObjBuilder, bool /*fromRepl*/) {
BSONElement e = jsobj.getField(name.c_str());
string toDeleteNs = cc().database()->name + '.' + e.valuestr();
@@ -748,20 +761,16 @@ namespace mongo {
}
}
} cmdDropIndexes;
- class CmdDeleteIndexes : public CmdDropIndexes {
- public:
- CmdDeleteIndexes() : CmdDropIndexes("deleteIndexes") { }
- } cmdDeleteIndexes;
class CmdReIndex : public Command {
public:
virtual bool logTheOp() {
return true;
}
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return false;
}
- virtual LockType locktype(){ return WRITE; }
+ virtual LockType locktype() const { return WRITE; }
virtual void help( stringstream& help ) const {
help << "re-index a collection";
}
@@ -814,7 +823,7 @@ namespace mongo {
virtual bool logTheOp() {
return false;
}
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return true;
}
virtual bool slaveOverrideOk() {
@@ -823,7 +832,8 @@ namespace mongo {
virtual bool adminOnly() {
return true;
}
- virtual LockType locktype(){ return WRITE; }
+ virtual LockType locktype() const { return WRITE; }
+ virtual void help( stringstream& help ) const { help << "list databases on this server"; }
CmdListDatabases() : Command("listDatabases") {}
bool run(const char *ns, BSONObj& jsobj, string& errmsg, BSONObjBuilder& result, bool /*fromRepl*/) {
vector< string > dbNames;
@@ -873,9 +883,11 @@ namespace mongo {
*/
class CmdCloseAllDatabases : public Command {
public:
+ virtual void help( stringstream& help ) const { help << "Close all database files.\nA new request will cause an immediate reopening; thus, this is mostly for testing purposes."; }
virtual bool adminOnly() { return true; }
- virtual bool slaveOk() { return false; }
- virtual LockType locktype(){ return WRITE; }
+ virtual bool slaveOk() const { return false; }
+ virtual LockType locktype() const { return WRITE; }
+
CmdCloseAllDatabases() : Command( "closeAllDatabases" ) {}
bool run(const char *ns, BSONObj& jsobj, string& errmsg, BSONObjBuilder& result, bool /*fromRepl*/) {
return dbHolder.closeAll( dbpath , result, false );
@@ -885,13 +897,13 @@ namespace mongo {
class CmdFileMD5 : public Command {
public:
CmdFileMD5() : Command( "filemd5" ){}
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return true;
}
virtual void help( stringstream& help ) const {
help << " example: { filemd5 : ObjectId(aaaaaaa) , root : \"fs\" }";
}
- virtual LockType locktype(){ return READ; }
+ virtual LockType locktype() const { return READ; }
bool run(const char *dbname, BSONObj& jsobj, string& errmsg, BSONObjBuilder& result, bool fromRepl ){
static DBDirectClient db;
@@ -950,10 +962,10 @@ namespace mongo {
class CmdMedianKey : public Command {
public:
CmdMedianKey() : Command( "medianKey" ) {}
- virtual bool slaveOk() { return true; }
- virtual LockType locktype(){ return READ; }
+ virtual bool slaveOk() const { return true; }
+ virtual LockType locktype() const { return READ; }
virtual void help( stringstream &help ) const {
- help << " example: { medianKey:\"blog.posts\", keyPattern:{x:1}, min:{x:10}, max:{x:55} }\n"
+ help << "internal.\nexample: { medianKey:\"blog.posts\", keyPattern:{x:1}, min:{x:10}, max:{x:55} }\n"
"NOTE: This command may take awhile to run";
}
bool run(const char *dbname, BSONObj& jsobj, string& errmsg, BSONObjBuilder& result, bool fromRepl ){
@@ -993,12 +1005,12 @@ namespace mongo {
class CmdDatasize : public Command {
public:
- CmdDatasize() : Command( "datasize" ) {}
- virtual bool slaveOk() { return true; }
- virtual LockType locktype(){ return READ; }
+ CmdDatasize() : Command( "dataSize", false, "datasize" ) {}
+ virtual bool slaveOk() const { return true; }
+ virtual LockType locktype() const { return READ; }
virtual void help( stringstream &help ) const {
help <<
- "\ndetermine data size for a set of data in a certain range"
+ "determine data size for a set of data in a certain range"
"\nexample: { datasize:\"blog.posts\", keyPattern:{x:1}, min:{x:10}, max:{x:55} }"
"\nkeyPattern, min, and max parameters are optional."
"\nnot: This command may take a while to run";
@@ -1078,8 +1090,8 @@ namespace mongo {
class CollectionStats : public Command {
public:
CollectionStats() : Command( "collstats" ) {}
- virtual bool slaveOk() { return true; }
- virtual LockType locktype(){ return READ; }
+ virtual bool slaveOk() const { return true; }
+ virtual LockType locktype() const { return READ; }
virtual void help( stringstream &help ) const {
help << " example: { collstats:\"blog.posts\" } ";
}
@@ -1125,12 +1137,11 @@ namespace mongo {
}
} cmdCollectionStatis;
-
class DBStats : public Command {
public:
DBStats() : Command( "dbstats" ) {}
- virtual bool slaveOk() { return true; }
- virtual LockType locktype(){ return READ; }
+ virtual bool slaveOk() const { return true; }
+ virtual LockType locktype() const { return READ; }
virtual void help( stringstream &help ) const {
help << " example: { dbstats:1 } ";
}
@@ -1185,12 +1196,13 @@ namespace mongo {
class CmdBuildInfo : public Command {
public:
- CmdBuildInfo() : Command( "buildinfo" ) {}
- virtual bool slaveOk() { return true; }
+ CmdBuildInfo() : Command( "buildInfo", true, "buildinfo" ) {}
+ virtual bool slaveOk() const { return true; }
virtual bool adminOnly() { return true; }
- virtual LockType locktype(){ return NONE; }
+ virtual LockType locktype() const { return NONE; }
virtual void help( stringstream &help ) const {
- help << "example: { buildinfo:1 }";
+ help << "get version #, etc.\n";
+ help << "{ buildinfo:1 }";
}
bool run(const char *dbname, BSONObj& jsobj, string& errmsg, BSONObjBuilder& result, bool fromRepl ){
result << "version" << versionString << "gitVersion" << gitVersion() << "sysInfo" << sysInfo();
@@ -1203,10 +1215,10 @@ namespace mongo {
class CmdCloneCollectionAsCapped : public Command {
public:
CmdCloneCollectionAsCapped() : Command( "cloneCollectionAsCapped" ) {}
- virtual bool slaveOk() { return false; }
- virtual LockType locktype(){ return WRITE; }
+ virtual bool slaveOk() const { return false; }
+ virtual LockType locktype() const { return WRITE; }
virtual void help( stringstream &help ) const {
- help << "example: { cloneCollectionAsCapped:<fromName>, toCollection:<toName>, size:<sizeInBytes> }";
+ help << "{ cloneCollectionAsCapped:<fromName>, toCollection:<toName>, size:<sizeInBytes> }";
}
bool run(const char *dbname, BSONObj& jsobj, string& errmsg, BSONObjBuilder& result, bool fromRepl ){
string from = jsobj.getStringField( "cloneCollectionAsCapped" );
@@ -1268,10 +1280,10 @@ namespace mongo {
class CmdConvertToCapped : public Command {
public:
CmdConvertToCapped() : Command( "convertToCapped" ) {}
- virtual bool slaveOk() { return false; }
- virtual LockType locktype(){ return WRITE; }
+ virtual bool slaveOk() const { return false; }
+ virtual LockType locktype() const { return WRITE; }
virtual void help( stringstream &help ) const {
- help << "example: { convertToCapped:<fromCollectionName>, size:<sizeInBytes> }";
+ help << "{ convertToCapped:<fromCollectionName>, size:<sizeInBytes> }";
}
bool run(const char *dbname, BSONObj& jsobj, string& errmsg, BSONObjBuilder& result, bool fromRepl ){
BackgroundOperation::assertNoBgOpInProgForDb(dbname);
@@ -1317,8 +1329,8 @@ namespace mongo {
class GroupCommand : public Command {
public:
GroupCommand() : Command("group"){}
- virtual LockType locktype(){ return READ; }
- virtual bool slaveOk() { return true; }
+ virtual LockType locktype() const { return READ; }
+ virtual bool slaveOk() const { return true; }
virtual void help( stringstream &help ) const {
help << "see http://www.mongodb.org/display/DOCS/Aggregation";
}
@@ -1500,8 +1512,8 @@ namespace mongo {
class DistinctCommand : public Command {
public:
DistinctCommand() : Command("distinct"){}
- virtual bool slaveOk() { return true; }
- virtual LockType locktype(){ return READ; }
+ virtual bool slaveOk() const { return true; }
+ virtual LockType locktype() const { return READ; }
virtual void help( stringstream &help ) const {
help << "{ distinct : 'collection name' , key : 'a.b' }";
}
@@ -1549,20 +1561,22 @@ namespace mongo {
/* Find and Modify an object returning either the old (default) or new value*/
class CmdFindAndModify : public Command {
public:
- /* {findandmodify: "collection", query: {processed:false}, update: {$set: {processed:true}}, new: true}
- * {findandmodify: "collection", query: {processed:false}, remove: true, sort: {priority:-1}}
- *
- * either update or remove is required, all other fields have default values
- * output is in the "value" field
- */
+ virtual void help( stringstream &help ) const {
+ help <<
+ "{ findandmodify: \"collection\", query: {processed:false}, update: {$set: {processed:true}}, new: true}\n"
+ "{ findandmodify: \"collection\", query: {processed:false}, remove: true, sort: {priority:-1}}\n"
+ "Either update or remove is required, all other fields have default values.\n"
+ "Output is in the \"value\" field\n";
+ }
+
CmdFindAndModify() : Command("findandmodify") { }
virtual bool logTheOp() {
return false; // the modification will be logged directly
}
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return false;
}
- virtual LockType locktype(){ return WRITE; }
+ virtual LockType locktype() const { return WRITE; }
virtual bool run(const char *dbname, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool) {
static DBDirectClient db;
@@ -1609,10 +1623,10 @@ namespace mongo {
virtual bool logTheOp() {
return false; // the modification will be logged directly
}
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return true;
}
- virtual LockType locktype(){ return NONE; }
+ virtual LockType locktype() const { return NONE; }
virtual bool requiresAuth() {
return false;
}
@@ -1633,15 +1647,15 @@ namespace mongo {
virtual bool logTheOp() {
return true;
}
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return false;
}
- virtual LockType locktype() { return WRITE; }
+ virtual LockType locktype() const { return WRITE; }
virtual bool requiresAuth() {
return true;
}
virtual void help( stringstream &help ) const {
- help << "[for testing only]";
+ help << "internal. for testing only.";
}
virtual bool run(const char *dbname, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool) {
string coll = cmdObj[ "godinsert" ].valuestrsafe();
@@ -1656,8 +1670,8 @@ namespace mongo {
class DBHashCmd : public Command {
public:
DBHashCmd() : Command( "dbhash" ){}
- virtual bool slaveOk() { return true; }
- virtual LockType locktype() { return READ; }
+ virtual bool slaveOk() const { return true; }
+ virtual LockType locktype() const { return READ; }
virtual bool run(const char * badns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool){
string dbname = nsToDatabase( badns );
@@ -1742,8 +1756,9 @@ namespace mongo {
class PingCommand : public Command {
public:
PingCommand() : Command( "ping" ){}
- virtual bool slaveOk() { return true; }
- virtual LockType locktype() { return NONE; }
+ virtual bool slaveOk() const { return true; }
+ virtual void help( stringstream &help ) const { help << "a way to check that the server is alive. responds immediately even if server is in a db lock."; }
+ virtual LockType locktype() const { return NONE; }
virtual bool requiresAuth() { return false; }
virtual bool run(const char * badns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool){
// IMPORTANT: Don't put anything in here that might lock db - including authentication
diff --git a/db/dbcommands_admin.cpp b/db/dbcommands_admin.cpp
index 9a12cef5c5a..736d0be60e1 100644
--- a/db/dbcommands_admin.cpp
+++ b/db/dbcommands_admin.cpp
@@ -39,9 +39,9 @@ namespace mongo {
public:
FeaturesCmd() : Command( "features", true ){}
- virtual bool slaveOk(){ return true; }
+ virtual bool slaveOk() const { return true; }
virtual bool readOnly(){ return true; }
- virtual LockType locktype(){ return READ; }
+ virtual LockType locktype() const { return READ; }
virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl){
result.append( "readlock" , readLockSupported() );
if ( globalScriptEngine ){
@@ -58,9 +58,11 @@ namespace mongo {
public:
CleanCmd() : Command( "clean" ){}
- virtual bool slaveOk(){ return true; }
- virtual LockType locktype(){ return WRITE; }
+ virtual bool slaveOk() const { return true; }
+ virtual LockType locktype() const { return WRITE; }
+ virtual void help(stringstream& h) const { h << "internal"; }
+
bool run(const char *nsRaw, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl ){
string dropns = cc().database()->name + "." + cmdObj.firstElement().valuestrsafe();
@@ -87,11 +89,13 @@ namespace mongo {
public:
ValidateCmd() : Command( "validate" ){}
- virtual bool slaveOk(){
+ virtual bool slaveOk() const {
return true;
}
- virtual LockType locktype(){ return WRITE; }
+ virtual void help(stringstream& h) const { h << "Validate contents of a namespace by scanning its data structures for correctness. Slow."; }
+
+ virtual LockType locktype() const { return READ; }
//{ validate: "collectionnamewithoutthedbpart" [, scandata: <bool>] } */
bool run(const char *nsRaw, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl ){
@@ -281,7 +285,7 @@ namespace mongo {
public:
UnlockCommand() : Command( "unlock" ) { }
virtual bool readOnly() { return true; }
- virtual bool slaveOk(){ return true; }
+ virtual bool slaveOk() const { return true; }
virtual bool adminOnly(){ return true; }
virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
if( lockedForWriting ) {
@@ -337,13 +341,14 @@ namespace mongo {
};
public:
FSyncCommand() : Command( "fsync" ){}
- virtual LockType locktype(){ return WRITE; }
- virtual bool slaveOk(){ return true; }
+ virtual LockType locktype() const { return WRITE; }
+ virtual bool slaveOk() const { return true; }
virtual bool adminOnly(){ return true; }
/*virtual bool localHostOnlyIfNoAuth(const BSONObj& cmdObj) {
string x = cmdObj["exec"].valuestrsafe();
return !x.empty();
}*/
+ virtual void help(stringstream& h) const { h << "http://www.mongodb.org/display/DOCS/fsync+Command"; }
virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
/* async means do an fsync, but return immediately */
bool sync = ! cmdObj["async"].trueValue();
@@ -380,8 +385,8 @@ namespace mongo {
class LogRotateCmd : public Command {
public:
LogRotateCmd() : Command( "logRotate" ){}
- virtual LockType locktype(){ return NONE; }
- virtual bool slaveOk(){ return true; }
+ virtual LockType locktype() const { return NONE; }
+ virtual bool slaveOk() const { return true; }
virtual bool adminOnly(){ return true; }
virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
rotateLogs();
@@ -392,9 +397,10 @@ namespace mongo {
class ListCommandsCmd : public Command {
public:
- ListCommandsCmd() : Command( "listCommands" ){}
- virtual LockType locktype(){ return NONE; }
- virtual bool slaveOk(){ return true; }
+ virtual void help( stringstream &help ) const { help << "get a list of all db commands"; }
+ ListCommandsCmd() : Command( "listCommands", false ){}
+ virtual LockType locktype() const { return NONE; }
+ virtual bool slaveOk() const { return true; }
virtual bool adminOnly(){ return false; }
virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
BSONObjBuilder b( result.subobjStart( "commands" ) );
diff --git a/db/dbeval.cpp b/db/dbeval.cpp
index a3be894be4a..ab7e1db69db 100644
--- a/db/dbeval.cpp
+++ b/db/dbeval.cpp
@@ -108,16 +108,19 @@ namespace mongo {
class CmdEval : public Command {
public:
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return false;
}
+ virtual void help( stringstream &help ) const {
+ help << "Evaluate javascript at the server.\n" "http://www.mongodb.org/display/DOCS/Server-side+Code+Execution";
+ }
// We need at least read only access to run db.eval - auth for eval'd writes will be checked
// as they are requested.
virtual bool requiresAuth() {
return false;
}
- virtual LockType locktype(){ return WRITE; }
- CmdEval() : Command("$eval") { }
+ virtual LockType locktype() const { return WRITE; }
+ CmdEval() : Command("eval", false, "$eval") { }
bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
AuthenticationInfo *ai = cc().getAuthenticationInfo();
uassert( 12598 , "$eval reads unauthorized", ai->isAuthorizedReads(cc().database()->name.c_str()));
diff --git a/db/dbwebserver.cpp b/db/dbwebserver.cpp
index 943f1b2b3fe..3c02d099b74 100644
--- a/db/dbwebserver.cpp
+++ b/db/dbwebserver.cpp
@@ -189,15 +189,13 @@ namespace mongo {
ss << mongodVersion() << '\n';
ss << "git hash: " << gitVersion() << '\n';
ss << "sys info: " << sysInfo() << '\n';
- ss << '\n';
ss << "<a "
<< "href=\"http://www.mongodb.org/pages/viewpage.action?pageId=7209296\""
<< "title=\"snapshot: was the db in the write lock when this page was generated?\">";
ss << "write locked:</a> " << (dbMutex.info().isLocked() ? "true" : "false") << "\n";
- ss << "uptime: " << time(0)-started << " seconds\n";
+ ss << "uptime: " << time(0)-started << " seconds\n";
if ( replAllDead )
ss << "<b>replication replAllDead=" << replAllDead << "</b>\n";
- ss << "\n";
ss << "<a title=\"information on caught assertion exceptions\">";
ss << "assertions:</a>\n";
for ( int i = 0; i < 4; i++ ) {
@@ -211,7 +209,7 @@ namespace mongo {
}
}
- ss << "Clients:\n";
+ ss << "\nClients:\n";
ss << "<table border=1 cellpadding=2 cellspacing=0>";
ss << "<tr align='left'>"
<< "<th>Thread</th>"
@@ -358,6 +356,31 @@ namespace mongo {
return;
}
+ if( url.find("/_commands") == 0 ) {
+ if ( ! allowed( rq , headers, from ) ){
+ responseCode = 401;
+ headers.push_back( "Content-Type: text/plain" );
+ responseMsg = "not allowed\n";
+ return;
+ }
+ headers.push_back( "Content-Type: text/html" );
+ stringstream ss;
+ ss << "<html><title>Commands List</title><body><h1><a href=\"http://www.mongodb.org/display/DOCS/Commands\">Commands</a> List</h1>\n";
+ ss << "<p><a href=\"/\">Back</a></p>\n";
+ const map<string, Command*> *m = Command::commandsByBestName();
+ ss << "S:slave-only N:no-lock R:read-lock W:write-lock<br>\n";
+ ss << "<table border=1 cellpadding=2 cellspacing=0>";
+ ss << "<tr><th>Command</th><th>Attributes</th><th>Help</th></tr>\n";
+ for( map<string, Command*>::const_iterator i = m->begin(); i != m->end(); i++ ) {
+ i->second->htmlHelp(ss);
+ }
+ ss << "</table>";
+ ss << "</body></html>";
+ responseMsg = ss.str();
+ responseCode = 200;
+ return;
+ }
+
/* run a command from the web ui */
const char *p = url.c_str();
if( *p == '/' ) {
@@ -412,13 +435,20 @@ namespace mongo {
dbname = z.str();
}
ss << dbname << "</title></head><body><h2>" << dbname << "</h2>\n";
+ ss << "<a href=\"/_commands\">List all commands</a>\n";
ss << "<pre>";
//ss << "<a href=\"/_status\">_status</a>";
{
const map<string, Command*> *m = Command::webCommands();
if( m ) {
for( map<string, Command*>::const_iterator i = m->begin(); i != m->end(); i++ ) {
- ss << "<a href=\"/" << i->first << "?text\">" << i->first << "</a> ";
+ stringstream h;
+ i->second->help(h);
+ string help = h.str();
+ ss << "<a href=\"/" << i->first << "?text\"";
+ if( help != "no help defined" )
+ ss << " title=\"" << help << '"';
+ ss << ">" << i->first << "</a> ";
}
ss << '\n';
}
diff --git a/db/index_geo2d.cpp b/db/index_geo2d.cpp
index e30e95fea5f..6170ad2662d 100644
--- a/db/index_geo2d.cpp
+++ b/db/index_geo2d.cpp
@@ -1542,8 +1542,8 @@ namespace mongo {
class Geo2dFindNearCmd : public Command {
public:
Geo2dFindNearCmd() : Command( "geoNear" ){}
- virtual LockType locktype(){ return READ; }
- bool slaveOk() { return true; }
+ virtual LockType locktype() const { return READ; }
+ bool slaveOk() const { return true; }
bool slaveOverrideOk() { return true; }
bool run(const char * stupidns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl){
string ns = nsToDatabase( stupidns ) + "." + cmdObj.firstElement().valuestr();
@@ -1643,8 +1643,8 @@ namespace mongo {
class GeoWalkCmd : public Command {
public:
GeoWalkCmd() : Command( "geoWalk" ){}
- virtual LockType locktype(){ return READ; }
- bool slaveOk() { return true; }
+ virtual LockType locktype() const { return READ; }
+ bool slaveOk() const { return true; }
bool slaveOverrideOk() { return true; }
bool run(const char * stupidns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl){
string ns = nsToDatabase( stupidns ) + "." + cmdObj.firstElement().valuestr();
diff --git a/db/mr.cpp b/db/mr.cpp
index 0cd26c9679f..4cc254f24c7 100644
--- a/db/mr.cpp
+++ b/db/mr.cpp
@@ -408,12 +408,12 @@ namespace mongo {
class MapReduceCommand : public Command {
public:
MapReduceCommand() : Command("mapreduce"){}
- virtual bool slaveOk() { return true; }
+ virtual bool slaveOk() const { return true; }
virtual void help( stringstream &help ) const {
help << "see http://www.mongodb.org/display/DOCS/MapReduce";
}
- virtual LockType locktype(){ return NONE; }
+ virtual LockType locktype() const { return NONE; }
bool run(const char *dbname, BSONObj& cmd, string& errmsg, BSONObjBuilder& result, bool fromRepl ){
Timer t;
Client::GodScope cg;
@@ -618,9 +618,9 @@ namespace mongo {
class MapReduceFinishCommand : public Command {
public:
MapReduceFinishCommand() : Command( "mapreduce.shardedfinish" ){}
- virtual bool slaveOk() { return true; }
+ virtual bool slaveOk() const { return true; }
- virtual LockType locktype(){ return WRITE; }
+ virtual LockType locktype() const { return WRITE; }
bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool){
string dbname = cc().database()->name; // this has to come before dbtemprelease
dbtemprelease temprelease; // we don't touch the db directly
diff --git a/db/oplog.cpp b/db/oplog.cpp
index d5d0d670294..840b8f76382 100644
--- a/db/oplog.cpp
+++ b/db/oplog.cpp
@@ -189,10 +189,10 @@ namespace mongo {
class CmdLogCollection : public Command {
public:
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return false;
}
- virtual LockType locktype(){ return WRITE; }
+ virtual LockType locktype() const { return WRITE; }
CmdLogCollection() : Command( "logCollection" ) {}
virtual void help( stringstream &help ) const {
help << "examples: { logCollection: <collection ns>, start: 1 }, "
diff --git a/db/repl.cpp b/db/repl.cpp
index 5b1727ec5c2..684af34d288 100644
--- a/db/repl.cpp
+++ b/db/repl.cpp
@@ -133,7 +133,7 @@ namespace mongo {
class CmdReplacePeer : public Command {
public:
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return true;
}
virtual bool adminOnly() {
@@ -142,7 +142,7 @@ namespace mongo {
virtual bool logTheOp() {
return false;
}
- virtual LockType locktype(){ return WRITE; }
+ virtual LockType locktype() const { return WRITE; }
CmdReplacePeer() : Command("replacepeer") { }
virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
if ( replPair == 0 ) {
@@ -194,7 +194,7 @@ namespace mongo {
class CmdForceDead : public Command {
public:
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return true;
}
virtual bool adminOnly() {
@@ -203,7 +203,7 @@ namespace mongo {
virtual bool logTheOp() {
return false;
}
- virtual LockType locktype(){ return WRITE; }
+ virtual LockType locktype() const { return WRITE; }
CmdForceDead() : Command("forcedead") { }
virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
replAllDead = "replication forced to stop by 'forcedead' command";
@@ -216,7 +216,7 @@ namespace mongo {
/* operator requested resynchronization of replication (on the slave). { resync : 1 } */
class CmdResync : public Command {
public:
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return true;
}
virtual bool adminOnly() {
@@ -225,7 +225,7 @@ namespace mongo {
virtual bool logTheOp() {
return false;
}
- virtual LockType locktype(){ return WRITE; }
+ virtual LockType locktype() const { return WRITE; }
CmdResync() : Command("resync") { }
virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
if ( cmdObj.getBoolField( "force" ) ) {
@@ -340,10 +340,14 @@ namespace mongo {
class CmdIsMasterOld : public Command {
public:
virtual bool requiresAuth() { return false; }
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return true;
}
- virtual LockType locktype(){ return NONE; }
+ virtual void help( stringstream &help ) const {
+ help << "Check if this server is primary\n";
+ help << "{ isMaster : 1 }";
+ }
+ virtual LockType locktype() const { return NONE; }
CmdIsMasterOld(const char * name="ismaster") : Command(name, name=="isMaster") { }
virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool /*fromRepl*/) {
/* currently request to arbiter is (somewhat arbitrarily) an ismaster request that is not
@@ -378,10 +382,10 @@ namespace mongo {
class CmdIsInitialSyncComplete : public Command {
public:
virtual bool requiresAuth() { return false; }
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return true;
}
- virtual LockType locktype(){ return WRITE; }
+ virtual LockType locktype() const { return WRITE; }
CmdIsInitialSyncComplete() : Command( "isinitialsynccomplete" ) {}
virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool /*fromRepl*/) {
result.appendBool( "initialsynccomplete", getInitialSyncCompleted() );
@@ -409,13 +413,13 @@ namespace mongo {
class CmdNegotiateMaster : public Command {
public:
CmdNegotiateMaster() : Command("negotiatemaster") { }
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return true;
}
virtual bool adminOnly() {
return true;
}
- virtual LockType locktype(){ return WRITE; }
+ virtual LockType locktype() const { return WRITE; }
virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool) {
if ( replPair == 0 ) {
massert( 10383 , "Another mongod instance believes incorrectly that this node is its peer", !cmdObj.getBoolField( "fromArbiter" ) );
diff --git a/db/repl/health.cpp b/db/repl/health.cpp
index d9b81111814..9a37b6e711b 100644
--- a/db/repl/health.cpp
+++ b/db/repl/health.cpp
@@ -27,10 +27,10 @@ namespace mongo {
/* { replSetHeartbeat : <setname> } */
class CmdReplSetHeartbeat : public Command {
public:
- virtual bool slaveOk() { return true; }
+ virtual bool slaveOk() const { return true; }
virtual bool adminOnly() { return false; }
virtual bool logTheOp() { return false; }
- virtual LockType locktype(){ return NONE; }
+ virtual LockType locktype() const { return NONE; }
CmdReplSetHeartbeat() : Command("replSetHeartbeat") { }
virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
if( !replSet ) {
diff --git a/db/repl/replset_commands.cpp b/db/repl/replset_commands.cpp
index 9071d27aed8..eeebe487a32 100644
--- a/db/repl/replset_commands.cpp
+++ b/db/repl/replset_commands.cpp
@@ -24,8 +24,8 @@ namespace mongo {
class CmdReplSetInitiate : public Command {
public:
- virtual LockType locktype(){ return WRITE; }
- virtual bool slaveOk() { return true; }
+ virtual LockType locktype() const { return WRITE; }
+ virtual bool slaveOk() const { return true; }
virtual bool adminOnly() { return true; }
virtual bool logTheOp() { return false; }
CmdReplSetInitiate() : Command("replSetInitiate") { }
@@ -59,10 +59,15 @@ namespace mongo {
class CmdReplSetGetStatus : public Command {
public:
- virtual bool slaveOk() { return true; }
+ virtual bool slaveOk() const { return true; }
virtual bool adminOnly() { return true; }
virtual bool logTheOp() { return false; }
- virtual LockType locktype(){ return NONE; }
+ virtual LockType locktype() const { return NONE; }
+ virtual void help( stringstream &help ) const {
+ help << "Report status of a replica set from the POV of this server\n";
+ help << "{ replSetGetStatus : 1 }";
+ }
+
CmdReplSetGetStatus() : Command("replSetGetStatus", true) { }
virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
if( !replSet ) {
diff --git a/db/security_commands.cpp b/db/security_commands.cpp
index 326d6e4cc54..0ff2ead21d7 100644
--- a/db/security_commands.cpp
+++ b/db/security_commands.cpp
@@ -52,10 +52,10 @@ namespace mongo {
virtual bool logTheOp() {
return false;
}
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return true;
}
- virtual LockType locktype(){ return NONE; }
+ virtual LockType locktype() const { return NONE; }
CmdGetNonce() : Command("getnonce") {}
bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
nonce *n = new nonce(security.getNonce());
@@ -72,10 +72,10 @@ namespace mongo {
virtual bool logTheOp() {
return false;
}
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return true;
}
- virtual LockType locktype(){ return NONE; }
+ virtual LockType locktype() const { return NONE; }
CmdLogout() : Command("logout") {}
bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
// database->name is the one we are logging out...
@@ -91,10 +91,10 @@ namespace mongo {
virtual bool logTheOp() {
return false;
}
- virtual bool slaveOk() {
+ virtual bool slaveOk() const {
return true;
}
- virtual LockType locktype(){ return WRITE; } // TODO: make this READ
+ virtual LockType locktype() const { return WRITE; } // TODO: make this READ
CmdAuthenticate() : Command("authenticate") {}
bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
log(1) << " authenticate: " << cmdObj << endl;
diff --git a/db/stats/top.cpp b/db/stats/top.cpp
index 18572e49741..4bbc5a3ff1f 100644
--- a/db/stats/top.cpp
+++ b/db/stats/top.cpp
@@ -150,9 +150,9 @@ namespace mongo {
public:
TopCmd() : Command( "top", true ){}
- virtual bool slaveOk(){ return true; }
+ virtual bool slaveOk() const { return true; }
virtual bool adminOnly(){ return true; }
- virtual LockType locktype(){ return READ; }
+ virtual LockType locktype() const { return READ; }
virtual void help( stringstream& help ) const { help << "usage by collection"; }
virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl){