summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorDwight <dmerriman@gmail.com>2008-12-05 10:09:16 -0500
committerDwight <dmerriman@gmail.com>2008-12-05 10:09:16 -0500
commit1a95c75d0ffa5dfb865ac40f8fafecd2732bc4ca (patch)
treeab882e4b052a1acde9528e52c275209db013a04f /db
parent9fadd09ac6356a6fdac62eb638ee7b92afb8e7c5 (diff)
downloadmongo-1a95c75d0ffa5dfb865ac40f8fafecd2732bc4ca.tar.gz
don't log to our oplog operations we are replicating from elsewhere
Diffstat (limited to 'db')
-rw-r--r--db/cloner.cpp19
-rw-r--r--db/commands.cpp2
-rw-r--r--db/commands.h6
-rw-r--r--db/dbcommands.cpp37
-rw-r--r--db/dbeval.cpp2
-rw-r--r--db/query.cpp8
-rw-r--r--db/repl.cpp8
7 files changed, 44 insertions, 38 deletions
diff --git a/db/cloner.cpp b/db/cloner.cpp
index f52e4e25aca..c63e116152b 100644
--- a/db/cloner.cpp
+++ b/db/cloner.cpp
@@ -30,7 +30,7 @@ extern int port;
class Cloner: boost::noncopyable {
DBClientConnection conn;
- void copy(const char *from_ns, const char *to_ns, bool isindex = false);
+ void copy(const char *from_ns, const char *to_ns, bool isindex, bool logForRepl);
public:
Cloner() { }
bool go(const char *masterHost, string& errmsg, const string& fromdb, bool logForRepl);
@@ -73,7 +73,7 @@ BSONObj fixindex(BSONObj o) {
/* copy the specified collection
isindex - if true, this is system.indexes collection.
*/
-void Cloner::copy(const char *from_collection, const char *to_collection, bool isindex) {
+void Cloner::copy(const char *from_collection, const char *to_collection, bool isindex, bool logForRepl) {
auto_ptr<DBClientCursor> c;
{
dbtemprelease r;
@@ -101,7 +101,8 @@ void Cloner::copy(const char *from_collection, const char *to_collection, bool i
}
theDataFileMgr.insert(to_collection, (void*) js.objdata(), js.objsize());
- logOp("i", to_collection, js);
+ if( logForRepl )
+ logOp("i", to_collection, js);
}
}
@@ -171,13 +172,13 @@ bool Cloner::go(const char *masterHost, string& errmsg, const string& fromdb, bo
string err;
userCreateNS(to_name.c_str(), options, err, logForRepl);
}
- copy(from_name, to_name.c_str());
+ copy(from_name, to_name.c_str(), false, logForRepl);
}
// now build the indexes
string system_indexes_from = fromdb + ".system.indexes";
string system_indexes_to = todb + ".system.indexes";
- copy(system_indexes_from.c_str(), system_indexes_to.c_str(), true);
+ copy(system_indexes_from.c_str(), system_indexes_to.c_str(), true, logForRepl);
return true;
}
@@ -195,14 +196,14 @@ class CmdClone : public Command {
public:
CmdClone() : Command("clone") { }
- virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result) {
+ virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
string from = cmdObj.getStringField("clone");
if( from.empty() )
return false;
/* replication note: we must logOp() not the command, but the cloned data -- if the slave
were to clone it would get a different point-in-time and not match.
*/
- return cloneFrom(from.c_str(), errmsg, database->name, true);
+ return cloneFrom(from.c_str(), errmsg, database->name, /*logForReplication=*/!fromRepl);
}
} cmdclone;
@@ -214,7 +215,7 @@ public:
CmdCopyDb() : Command("copydb") { }
virtual bool adminOnly() { return true; }
- virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result) {
+ virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
string fromhost = cmdObj.getStringField("fromhost");
if( fromhost.empty() ) {
/* copy from self */
@@ -229,7 +230,7 @@ public:
return false;
}
setClient(todb.c_str());
- bool res = cloneFrom(fromhost.c_str(), errmsg, fromdb, true);
+ bool res = cloneFrom(fromhost.c_str(), errmsg, fromdb, /*logForReplication=*/!fromRepl);
database = 0;
return res;
}
diff --git a/db/commands.cpp b/db/commands.cpp
index 8b4840ddc6b..73838b7ea50 100644
--- a/db/commands.cpp
+++ b/db/commands.cpp
@@ -57,7 +57,7 @@ bool runCommandAgainstRegistered(const char *ns, BSONObj& jsobj, BSONObjBuilder&
errmsg = "access denied";
}
else {
- ok = c->run(ns, jsobj, errmsg, anObjBuilder);
+ ok = c->run(ns, jsobj, errmsg, anObjBuilder, false);
}
if( !ok )
anObjBuilder.append("errmsg", errmsg);
diff --git a/db/commands.h b/db/commands.h
index 88bf552fb48..761af145721 100644
--- a/db/commands.h
+++ b/db/commands.h
@@ -28,9 +28,13 @@ public:
/* run the given command
implement this...
+
+ fromRepl - command is being invoked as part of replication syncing. In this situation you
+ normally do not want to log the command to the local oplog.
+
return value is true if succeeded. if false, set errmsg text.
*/
- virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result) = 0;
+ virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) = 0;
/* return true if only the admin ns has privileges to run this command. */
virtual bool adminOnly() { return false; }
diff --git a/db/dbcommands.cpp b/db/dbcommands.cpp
index d9d76b3689c..17f668441f4 100644
--- a/db/dbcommands.cpp
+++ b/db/dbcommands.cpp
@@ -169,7 +169,7 @@ string validateNS(const char *ns, NamespaceDetails *d) {
class CmdGetOpTime : public Command {
public:
CmdGetOpTime() : Command("getoptime") { }
- bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result) {
+ bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
result.appendDate("optime", OpTime::now().asDate());
return true;
}
@@ -190,7 +190,7 @@ class CmdOpLogging : public Command {
public:
CmdOpLogging() : Command("opLogging") { }
bool adminOnly() { return true; }
- bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result) {
+ bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool) {
opLogging = (int) cmdObj.findElement("opLogging").number();
flushOpLog();
log() << "CMD: opLogging set to " << opLogging << endl;
@@ -202,7 +202,7 @@ class CmdQueryTraceLevel : public Command {
public:
CmdQueryTraceLevel() : Command("queryTraceLevel") { }
bool adminOnly() { return true; }
- bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result) {
+ bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool) {
queryTraceLevel = (int) cmdObj.findElement(name.c_str()).number();
return true;
}
@@ -212,7 +212,7 @@ class Cmd : public Command {
public:
Cmd() : Command("traceAll") { }
bool adminOnly() { return true; }
- bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result) {
+ bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool) {
queryTraceLevel = otherTraceLevel = (int) cmdObj.findElement(name.c_str()).number();
return true;
}
@@ -220,14 +220,14 @@ public:
extern map<string,Command*> *commands;
-// TODO make these all command objects -- legacy stuff here
-//
-// e.g.
-// system.cmd$.find( { queryTraceLevel: 2 } );
-//
-// returns true if ran a cmd
-//
-bool _runCommands(const char *ns, BSONObj& jsobj, stringstream& ss, BufBuilder &b, BSONObjBuilder& anObjBuilder) {
+/* TODO make these all command objects -- legacy stuff here
+
+ usage:
+ abc.$cmd.findOne( { ismaster:1 } );
+
+ returns true if ran a cmd
+*/
+bool _runCommands(const char *ns, BSONObj& jsobj, stringstream& ss, BufBuilder &b, BSONObjBuilder& anObjBuilder, bool fromRepl) {
const char *p = strchr(ns, '.');
if( !p ) return false;
@@ -236,8 +236,6 @@ bool _runCommands(const char *ns, BSONObj& jsobj, stringstream& ss, BufBuilder &
bool ok = false;
bool valid = false;
- //cout << jsobj.toString() << endl;
-
BSONElement e;
e = jsobj.firstElement();
@@ -257,7 +255,7 @@ bool _runCommands(const char *ns, BSONObj& jsobj, stringstream& ss, BufBuilder &
errmsg = "access denied";
}
else {
- ok = c->run(ns, jsobj, errmsg, anObjBuilder);
+ ok = c->run(ns, jsobj, errmsg, anObjBuilder, fromRepl);
}
if( !ok )
anObjBuilder.append("errmsg", errmsg);
@@ -272,7 +270,8 @@ bool _runCommands(const char *ns, BSONObj& jsobj, stringstream& ss, BufBuilder &
ok = false;
} else {
dropDatabase(ns);
- logOp("c", ns, jsobj);
+ if( !fromRepl )
+ logOp("c", ns, jsobj);
ok = true;
}
}
@@ -353,7 +352,8 @@ bool _runCommands(const char *ns, BSONObj& jsobj, stringstream& ss, BufBuilder &
anObjBuilder.append("ns", nsToDrop.c_str());
ClientCursor::invalidate(nsToDrop.c_str());
dropNS(nsToDrop);
- logOp("c", ns, jsobj);
+ if( !fromRepl )
+ logOp("c", ns, jsobj);
/*
{
BSONObjBuilder b;
@@ -393,7 +393,8 @@ bool _runCommands(const char *ns, BSONObj& jsobj, stringstream& ss, BufBuilder &
d->aboutToDeleteAnIndex();
ClientCursor::invalidate(toDeleteNs.c_str());
- logOp("c", ns, jsobj);
+ if( !fromRepl )
+ logOp("c", ns, jsobj);
// delete a specific index or all?
if( f.type() == String ) {
diff --git a/db/dbeval.cpp b/db/dbeval.cpp
index 7b4f8663bdf..4391d54570d 100644
--- a/db/dbeval.cpp
+++ b/db/dbeval.cpp
@@ -97,7 +97,7 @@ bool dbEval(const char *ns, BSONObj& cmd, BSONObjBuilder& result, string& errmsg
class CmdEval : public Command {
public:
CmdEval() : Command("$eval") { }
- bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result) {
+ bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
return dbEval(ns, cmdObj, result, errmsg);
}
} cmdeval;
diff --git a/db/query.cpp b/db/query.cpp
index a51775efbb1..e2009e6c8a1 100644
--- a/db/query.cpp
+++ b/db/query.cpp
@@ -492,11 +492,11 @@ int otherTraceLevel = 0;
int initialExtentSize(int len);
-bool _runCommands(const char *ns, BSONObj& jsobj, stringstream& ss, BufBuilder &b, BSONObjBuilder& anObjBuilder);
+bool _runCommands(const char *ns, BSONObj& jsobj, stringstream& ss, BufBuilder &b, BSONObjBuilder& anObjBuilder, bool fromRepl);
-bool runCommands(const char *ns, BSONObj& jsobj, stringstream& ss, BufBuilder &b, BSONObjBuilder& anObjBuilder) {
+bool runCommands(const char *ns, BSONObj& jsobj, stringstream& ss, BufBuilder &b, BSONObjBuilder& anObjBuilder, bool fromRepl) {
try {
- return _runCommands(ns, jsobj, ss, b, anObjBuilder);
+ return _runCommands(ns, jsobj, ss, b, anObjBuilder, fromRepl);
}
catch( AssertionException e ) {
if( !e.msg.empty() )
@@ -634,7 +634,7 @@ QueryResult* runQuery(Message& message, const char *ns, int ntoskip, int _ntoret
b.skip(sizeof(QueryResult));
/* we assume you are using findOne() for running a cmd... */
- if( ntoreturn == 1 && runCommands(ns, jsobj, ss, b, cmdResBuf) ) {
+ if( ntoreturn == 1 && runCommands(ns, jsobj, ss, b, cmdResBuf, false) ) {
n = 1;
}
else {
diff --git a/db/repl.cpp b/db/repl.cpp
index 0ae93f6ab45..5546f861840 100644
--- a/db/repl.cpp
+++ b/db/repl.cpp
@@ -38,7 +38,7 @@
extern boost::mutex dbMutex;
auto_ptr<Cursor> findTableScan(const char *ns, BSONObj& order, bool *isSorted=0);
int _updateObjects(const char *ns, BSONObj updateobj, BSONObj pattern, bool upsert, stringstream& ss, bool logOp=false);
-bool _runCommands(const char *ns, BSONObj& jsobj, stringstream& ss, BufBuilder &b, BSONObjBuilder& anObjBuilder);
+bool _runCommands(const char *ns, BSONObj& jsobj, stringstream& ss, BufBuilder &b, BSONObjBuilder& anObjBuilder, bool fromRepl);
void ensureHaveIdIndex(const char *ns);
/* "dead" means something really bad happened like replication falling completely out of sync.
@@ -96,7 +96,7 @@ class CmdIsMaster : public Command {
public:
CmdIsMaster() : Command("ismaster") { }
- virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result) {
+ virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool /*fromRepl*/) {
if( allDead ) {
result.append("ismaster", 0.0);
if( replPair )
@@ -142,7 +142,7 @@ public:
virtual bool adminOnly() { return true; }
- virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result) {
+ virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool) {
if( replPair == 0 ) {
problem() << "got negotiatemaster cmd but we are not in paired mode." << endl;
errmsg = "not paired";
@@ -526,7 +526,7 @@ void ReplSource::sync_pullOpLog_applyOperation(BSONObj& op) {
BufBuilder bb;
BSONObjBuilder ob;
assert( *opType == 'c' );
- _runCommands(ns, o, ss, bb, ob);
+ _runCommands(ns, o, ss, bb, ob, true);
}
}
catch( UserAssertionException& e ) {