summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--db/db.cpp77
-rw-r--r--db/jsobj.cpp2
-rw-r--r--db/jsobj.h1
-rw-r--r--db/pdfile.cpp11
4 files changed, 53 insertions, 38 deletions
diff --git a/db/db.cpp b/db/db.cpp
index 89a438b8754..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() ){
- cerr << "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,14 +549,14 @@ 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 ";
}
}
else if( m.data->operation == dbGetMore ) {
OPREAD;
- log = true;
+ DEV log = true;
ss << "getmore ";
receivedGetMore(dbMsgPort, m, ss);
}
@@ -665,10 +682,8 @@ void setupSignals() {}
#endif
void initAndListen(int listenPort, const char *dbPath, const char *appserverLoc = null) {
-
_oplog.init();
-
#if !defined(_WIN32)
assert( signal(SIGSEGV, segvhandler) != SIG_ERR );
#endif
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 e8ec7c6ee40..811bf47ddce 100644
--- a/db/pdfile.cpp
+++ b/db/pdfile.cpp
@@ -268,10 +268,9 @@ DiskLoc NamespaceDetails::_alloc(const char *ns, int len) {
DiskLoc fr = firstExtent.ext()->firstRecord;
if( fr.isNull() ) {
- cout << "couldn't make room for new record in capped ns\n";
- cout << " ns:" << ns;
- cout << "\n len: " << len << endl;
- assert(false);
+ cout << "couldn't make room for new record in capped ns " << ns
+ << " len: " << len << " extentsize:" << lastExtentSize << '\n';
+ assert( len * 5 > lastExtentSize ); // assume it is unusually large record; if not, something is broken
return DiskLoc();
}
@@ -598,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;
}
@@ -611,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);
}
}