summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDwight <dmerriman@gmail.com>2008-06-25 14:25:34 -0400
committerEliot Horowitz <eliot@10gen.com>2008-06-25 17:39:33 -0400
commit12adc2c060e0e312b376183448c6c109f02bba0f (patch)
tree05c7a09a8542ecd2a78ca167ea49345db3a60784
parent2a67e2319195fdec48b1fbdc6bfa304035b2c7cb (diff)
downloadmongo-12adc2c060e0e312b376183448c6c109f02bba0f.tar.gz
better opLogging - smarter with $cmd, log subset of reads option.
-rw-r--r--db/db.cpp73
-rw-r--r--db/jsobj.cpp2
-rw-r--r--db/jsobj.h1
-rw-r--r--db/pdfile.cpp4
4 files changed, 49 insertions, 31 deletions
diff --git a/db/db.cpp b/db/db.cpp
index 379c57c169a..727c72febb3 100644
--- a/db/db.cpp
+++ b/db/db.cpp
@@ -24,6 +24,36 @@ struct MyStartupTests {
}
} mystartupdbcpp;
+/* 0 = off; 1 = writes, 2 = reads, 3 = both
+ 7 = log a few reads, and all writes.
+*/
+int opLogging = 7;
+//int opLogging = 0;
+struct OpLog {
+ ofstream *f;
+ OpLog() : f(0) { }
+ void init() {
+ stringstream ss;
+ ss << "oplog." << hex << time(0);
+ string name = ss.str();
+ f = new ofstream(name.c_str(), ios::out | ios::binary);
+ if ( ! f->good() ){
+ problem() << "couldn't open log stream" << endl;
+ throw 1717;
+ }
+ }
+ void readop(char *data, int len) {
+ bool log = (opLogging & 4) == 0;
+ OCCASIONALLY log = true;
+ if( log )
+ f->write(data,len);
+ }
+} _oplog;
+void flushOpLog() { _oplog.f->flush(); }
+#define oplog (*(_oplog.f))
+#define OPWRITE if( opLogging & 1 ) oplog.write((char *) m.data, m.data->len);
+#define OPREAD if( opLogging & 2 ) _oplog.readop((char *) m.data, m.data->len);
+
/* example for
var zz = { x: 3, y: "foo", v: { z:5, arr: [1, 2] } }
zz.v.arr.prop = "zoo";
@@ -151,11 +181,22 @@ void receivedDelete(Message& m) {
deleteObjects(ns, pattern, flags & 1);
}
-void receivedQuery(AbstractMessagingPort& dbMsgPort, Message& m, stringstream& ss) {
+void receivedQuery(AbstractMessagingPort& dbMsgPort, Message& m, stringstream& ss, bool logit) {
MSGID responseTo = m.data->id;
DbMessage d(m);
const char *ns = d.getns();
+
+ if( opLogging && logit ) {
+ if( strstr(ns, "$cmd") ) {
+ /* $cmd queries are "commands" and usually best treated as write operations */
+ OPWRITE;
+ }
+ else {
+ OPREAD;
+ }
+ }
+
setClient(ns);
int ntoskip = d.pullInt();
int ntoreturn = d.pullInt();
@@ -352,8 +393,7 @@ void jniCallback(Message& m, Message& out)
assert( m.data->len > 0 && m.data->len < 32000000 );
Message copy(malloc(m.data->len), true);
memcpy(copy.data, m.data, m.data->len);
-
- receivedQuery(jmp, copy, ss);
+ receivedQuery(jmp, copy, ss, false);
}
else if( m.data->operation == dbInsert ) {
ss << "insert ";
@@ -418,28 +458,6 @@ void jniCallback(Message& m, Message& out)
}
}
-/* 0 = off; 1 = writes, 2 = reads, 3 = both */
-int opLogging = 1;
-//int opLogging = 0;
-struct OpLog {
- ofstream *f;
- OpLog() : f(0) { }
- void init() {
- stringstream ss;
- ss << "oplog." << hex << time(0);
- string name = ss.str();
- f = new ofstream(name.c_str(), ios::out | ios::binary);
- if ( ! f->good() ){
- problem() << "couldn't open log stream" << endl;
- throw 1717;
- }
- }
-} _oplog;
-void flushOpLog() { _oplog.f->flush(); }
-#define oplog (*(_oplog.f))
-#define OPWRITE if( opLogging & 1 ) oplog.write((char *) m.data, m.data->len);
-#define OPREAD if( opLogging & 2 ) oplog.write((char *) m.data, m.data->len);
-
void connThread()
{
try {
@@ -498,8 +516,7 @@ void connThread()
}
}
else if( m.data->operation == dbQuery ) {
- OPREAD;
- receivedQuery(dbMsgPort, m, ss);
+ receivedQuery(dbMsgPort, m, ss, true);
}
else if( m.data->operation == dbInsert ) {
OPWRITE;
@@ -532,7 +549,7 @@ void connThread()
receivedDelete(m);
}
catch( AssertionException ) {
- problem() << " Caught Assertion receviedDelete, continuing" << endl;
+ problem() << " Caught Assertion receivedDelete, continuing" << endl;
cout << "Caught Assertion receivedDelete, continuing" << endl;
ss << " exception ";
}
diff --git a/db/jsobj.cpp b/db/jsobj.cpp
index e2118bc8b60..963a80c8451 100644
--- a/db/jsobj.cpp
+++ b/db/jsobj.cpp
@@ -574,7 +574,7 @@ string JSObj::toString() const {
/* well ordered compare */
int JSObj::woCompare(const JSObj& r) const {
- assert( _objdata );
+ assert( _objdata );
if( isEmpty() )
return r.isEmpty() ? 0 : -1;
if( r.isEmpty() )
diff --git a/db/jsobj.h b/db/jsobj.h
index c0fac57ec36..8f829d14e75 100644
--- a/db/jsobj.h
+++ b/db/jsobj.h
@@ -512,4 +512,3 @@ inline void JSObjBuilder::appendElements(JSObj x) {
append(e);
}
}
-
diff --git a/db/pdfile.cpp b/db/pdfile.cpp
index 1daac07ff83..811bf47ddce 100644
--- a/db/pdfile.cpp
+++ b/db/pdfile.cpp
@@ -597,6 +597,7 @@ void IndexDetails::getKeysFromObject(JSObj& obj, set<JSObj>& keys) {
if( f.type() != Array ) {
b.decouple();
key.iWillFree();
+ assert( !key.isEmpty() );
keys.insert(key);
return;
}
@@ -610,7 +611,8 @@ void IndexDetails::getKeysFromObject(JSObj& obj, set<JSObj>& keys) {
b.appendAs(e, f.fieldName());
JSObj o = b.doneAndDecouple();
- assert( o.objdata() );
+// assert( o.objdata() );
+ assert( !o.isEmpty() );
keys.insert(o);
}
}