From 01a6722a25216005fbe5f1977a1a6b00a7ff596f Mon Sep 17 00:00:00 2001 From: Dwight Date: Fri, 15 Oct 2010 17:00:34 -0400 Subject: [PATCH] allow changing notablescan at runtime via {set:} command --- db/cmdline.h | 4 ++-- db/db.cpp | 4 ++-- db/dbcommands.cpp | 1 - db/dbcommands_generic.cpp | 50 +++++++++++++++++++++++++++++++++++++-- db/queryoptimizer.cpp | 4 ++-- 5 files changed, 54 insertions(+), 9 deletions(-) diff --git a/db/cmdline.h b/db/cmdline.h index 4818887985d..21b3f87f015 100644 --- a/db/cmdline.h +++ b/db/cmdline.h @@ -25,7 +25,7 @@ namespace mongo { /* concurrency: OK/READ */ struct CmdLine { CmdLine() : - port(DefaultDBPort), rest(false), jsonp(false), quiet(false), notablescan(false), prealloc(true), smallfiles(false), + port(DefaultDBPort), rest(false), jsonp(false), quiet(false), noTableScan(false), prealloc(true), smallfiles(false), quota(false), quotaFiles(8), cpu(false), oplogSize(0), defaultProfile(0), slowMS(100), pretouch(0), moveParanoia( true ) { } @@ -57,7 +57,7 @@ namespace mongo { string only; // --only bool quiet; // --quiet - bool notablescan; // --notablescan + bool noTableScan; // --notablescan bool prealloc; // --noprealloc bool smallfiles; // --smallfiles diff --git a/db/db.cpp b/db/db.cpp index d1a557170e8..a57e3afc178 100644 --- a/db/db.cpp +++ b/db/db.cpp @@ -876,8 +876,8 @@ int main(int argc, char* argv[], char *envp[] ) if (params.count("upgrade")) { shouldRepairDatabases = 1; } - if (params.count("notablescan")) { - cmdLine.notablescan = true; + if (params.count("noTableScan")) { + cmdLine.noTableScan = true; } if (params.count("master")) { replSettings.master = true; diff --git a/db/dbcommands.cpp b/db/dbcommands.cpp index 531b933d929..b1fc4c1ad3f 100644 --- a/db/dbcommands.cpp +++ b/db/dbcommands.cpp @@ -1625,7 +1625,6 @@ namespace mongo { log() << "command denied: " << cmdObj.toString() << endl; return false; } - if ( c->adminOnly() && ! fromRepl && dbname != "admin" ) { result.append( "errmsg" , "access denied; use admin db" ); diff --git a/db/dbcommands_generic.cpp b/db/dbcommands_generic.cpp index 1818cd87fa4..672f414e249 100644 --- a/db/dbcommands_generic.cpp +++ b/db/dbcommands_generic.cpp @@ -66,6 +66,54 @@ namespace mongo { } } cmdBuildInfo; + class CmdGet : public Command { + public: + CmdGet() : Command( "get" ) { } + virtual bool slaveOk() const { return true; } + virtual bool adminOnly() const { return true; } + virtual LockType locktype() const { return NONE; } + virtual void help( stringstream &help ) const { + help << "get administrative option(s)\nexample:\n"; + help << "{ get:1, notablescan:1 }\n"; + help << "supported so far:\n"; + help << " notablescan\n"; + } + bool run(const string& dbname, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl ){ + if( cmdObj.hasElement("notablescan") ) { + result.append("notablescan", cmdLine.noTableScan); + } + else { + errmsg = "no option found to get"; + return false; + } + return true; + } + } cmdGet; + + class CmdSet : public Command { + public: + CmdSet() : Command( "set" ) { } + virtual bool slaveOk() const { return true; } + virtual bool adminOnly() const { return true; } + virtual LockType locktype() const { return NONE; } + virtual void help( stringstream &help ) const { + help << "set administrative option(s)\nexample:\n"; + help << "{ set:1, notablescan:true }\n"; + help << "supported so far:\n"; + help << " notablescan\n"; + } + bool run(const string& dbname, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl ){ + if( cmdObj.hasElement("notablescan") ) { + result.append("was", cmdLine.noTableScan); + cmdLine.noTableScan = cmdObj["notablescan"].Bool(); + } + else { + errmsg = "no option found to set"; + return false; + } + return true; + } + } cmdSet; /* just to check if the db has asserted */ class CmdAssertInfo : public Command { @@ -223,6 +271,4 @@ namespace mongo { } } cmdForceError; - - } diff --git a/db/queryoptimizer.cpp b/db/queryoptimizer.cpp index 3995b4a4675..60f46742c68 100644 --- a/db/queryoptimizer.cpp +++ b/db/queryoptimizer.cpp @@ -32,7 +32,7 @@ namespace mongo { void checkTableScanAllowed( const char * ns ){ - if ( ! cmdLine.notablescan ) + if ( ! cmdLine.noTableScan ) return; if ( strstr( ns , ".system." ) || @@ -42,7 +42,7 @@ namespace mongo { if ( ! nsdetails( ns ) ) return; - uassert( 10111 , (string)"table scans not allowed:" + ns , ! cmdLine.notablescan ); + uassert( 10111 , (string)"table scans not allowed:" + ns , ! cmdLine.noTableScan ); } double elementDirection( const BSONElement &e ) {