summaryrefslogtreecommitdiff
path: root/db/dbcommands_admin.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'db/dbcommands_admin.cpp')
-rw-r--r--db/dbcommands_admin.cpp79
1 files changed, 28 insertions, 51 deletions
diff --git a/db/dbcommands_admin.cpp b/db/dbcommands_admin.cpp
index 7265002..2d08ac8 100644
--- a/db/dbcommands_admin.cpp
+++ b/db/dbcommands_admin.cpp
@@ -22,7 +22,7 @@
*/
-#include "stdafx.h"
+#include "pch.h"
#include "jsobj.h"
#include "pdfile.h"
#include "namespace.h"
@@ -35,37 +35,20 @@
namespace mongo {
- class FeaturesCmd : public Command {
- public:
- FeaturesCmd() : Command( "features" ){}
-
- virtual bool slaveOk(){ return true; }
- virtual bool readOnly(){ return true; }
- virtual LockType locktype(){ return READ; }
- virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl){
- result.append( "readlock" , readLockSupported() );
- if ( globalScriptEngine ){
- BSONObjBuilder bb( result.subobjStart( "js" ) );
- result.append( "utf8" , globalScriptEngine->utf8Ok() );
- bb.done();
- }
- return true;
- }
-
- } featuresCmd;
-
class CleanCmd : public Command {
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; }
- bool run(const char *nsRaw, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl ){
- string dropns = cc().database()->name + "." + cmdObj.firstElement().valuestrsafe();
+ virtual void help(stringstream& h) const { h << "internal"; }
+
+ bool run(const string& dbname, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl ){
+ string dropns = dbname + "." + cmdObj.firstElement().valuestrsafe();
if ( !cmdLine.quiet )
- log() << "CMD: clean " << dropns << endl;
+ tlog() << "CMD: clean " << dropns << endl;
NamespaceDetails *d = nsdetails(dropns.c_str());
@@ -87,18 +70,20 @@ 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 ){
- string ns = cc().database()->name + "." + cmdObj.firstElement().valuestrsafe();
+ bool run(const string& dbname , BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl ){
+ string ns = dbname + "." + cmdObj.firstElement().valuestrsafe();
NamespaceDetails * d = nsdetails( ns.c_str() );
if ( !cmdLine.quiet )
- log() << "CMD: validate " << ns << endl;
+ tlog() << "CMD: validate " << ns << endl;
if ( ! d ){
errmsg = "ns not found";
@@ -118,7 +103,7 @@ namespace mongo {
bool valid = true;
stringstream ss;
ss << "\nvalidate\n";
- ss << " details: " << hex << d << " ofs:" << nsindex(ns)->detailsOffset(d) << dec << endl;
+ //ss << " details: " << hex << d << " ofs:" << nsindex(ns)->detailsOffset(d) << dec << endl;
if ( d->capped )
ss << " capped:" << d->capped << " max:" << d->max << '\n';
@@ -158,7 +143,7 @@ namespace mongo {
set<DiskLoc> recs;
if( scanData ) {
- auto_ptr<Cursor> c = theDataFileMgr.findAll(ns);
+ shared_ptr<Cursor> c = theDataFileMgr.findAll(ns);
int n = 0;
long long len = 0;
long long nlen = 0;
@@ -190,7 +175,7 @@ namespace mongo {
else ss << " (OK)";
ss << '\n';
}
- ss << " " << n << " objects found, nobj:" << d->nrecords << "\n";
+ ss << " " << n << " objects found, nobj:" << d->nrecords << '\n';
ss << " " << len << " bytes data w/headers\n";
ss << " " << nlen << " bytes data wout/headers\n";
}
@@ -281,8 +266,8 @@ namespace mongo {
public:
UnlockCommand() : Command( "unlock" ) { }
virtual bool readOnly() { return true; }
- virtual bool slaveOk(){ return true; }
- virtual bool adminOnly(){ return true; }
+ virtual bool slaveOk() const { return true; }
+ virtual bool adminOnly() const { return true; }
virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
if( lockedForWriting ) {
log() << "command: unlock requested" << endl;
@@ -304,6 +289,7 @@ namespace mongo {
class FSyncCommand : public Command {
class LockDBJob : public BackgroundJob {
protected:
+ string name() { return "lockdbjob"; }
void run() {
Client::initThread("fsyncjob");
Client& c = cc();
@@ -337,14 +323,15 @@ namespace mongo {
};
public:
FSyncCommand() : Command( "fsync" ){}
- virtual LockType locktype(){ return WRITE; }
- virtual bool slaveOk(){ return true; }
- virtual bool adminOnly(){ return true; }
+ virtual LockType locktype() const { return WRITE; }
+ virtual bool slaveOk() const { return true; }
+ virtual bool adminOnly() const { return true; }
/*virtual bool localHostOnlyIfNoAuth(const BSONObj& cmdObj) {
string x = cmdObj["exec"].valuestrsafe();
return !x.empty();
}*/
- virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
+ virtual void help(stringstream& h) const { h << "http://www.mongodb.org/display/DOCS/fsync+Command"; }
+ virtual bool run(const string& dbname, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
/* async means do an fsync, but return immediately */
bool sync = ! cmdObj["async"].trueValue();
bool lock = cmdObj["lock"].trueValue();
@@ -376,18 +363,8 @@ namespace mongo {
}
} fsyncCmd;
+
+
- class LogRotateCmd : public Command {
- public:
- LogRotateCmd() : Command( "logRotate" ){}
- virtual LockType locktype(){ return NONE; }
- virtual bool slaveOk(){ return true; }
- virtual bool adminOnly(){ return true; }
- virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
- rotateLogs();
- return 1;
- }
-
- } logRotateCmd;
}