Compare commits

...

4 Commits

Author SHA1 Message Date
Eliot Horowitz
2b4a78a748 -O3 2008-06-25 17:39:40 -04:00
Dwight
12adc2c060 better opLogging - smarter with $cmd, log subset of reads option. 2008-06-25 17:39:33 -04:00
Dwight
2a67e23191 capped: don't assert on what could be a user error 2008-06-25 17:39:28 -04:00
Dwight
1bd4cea01b log less (minor) 2008-06-25 17:39:22 -04:00
5 changed files with 55 additions and 40 deletions

View File

@@ -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

View File

@@ -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() )

View File

@@ -512,4 +512,3 @@ inline void JSObjBuilder::appendElements(JSObj x) {
append(e);
}
}

View File

@@ -1,6 +1,6 @@
# makefile for our db project
FLAGS= ${CFLAGS} -fPIC -ggdb -pthread -O0 -I .. -Isrc/p -I/src/p/db -L/usr/local/lib -L/usr/lib
FLAGS= ${CFLAGS} -fPIC -ggdb -pthread -O3 -I .. -Isrc/p -I/src/p/db -L/usr/local/lib -L/usr/lib
LIB_DEPS = -lpcrecpp -lpcre
LIB_BOOST = -lboost_thread -lboost_filesystem
@@ -69,4 +69,4 @@ info:
@echo 'Using version of GPP :' $(_GPP_VER)
@echo 'Req version of GPP :' $(_REQ_GPP_VER)
@# todo - determine if we have the right version of gcc and error if not
@echo ''
@echo ''

View File

@@ -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);
}
}