Skip to content

Commit

Permalink
replay better
Browse files Browse the repository at this point in the history
  • Loading branch information
dwight committed Jun 23, 2008
1 parent 5d2cdfb commit cb18407
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
29 changes: 25 additions & 4 deletions db/db.cpp
Expand Up @@ -289,7 +289,7 @@ class OurListener : public Listener {
115 replay, opLogging
*/
void listen(int port) {
const char *Version = "db version: 115 18jun2008";
const char *Version = "db version: 116 23jun2008";
problem() << Version << endl;
cout << Version << endl;
pdfileInit();
Expand Down Expand Up @@ -418,8 +418,19 @@ void jniCallback(Message& m, Message& out)
}

/* 0 = off; 1 = writes, 2 = reads, 3 = both */
int opLogging = 0;
ofstream oplog("oplog.bin", ios::out | ios::binary);
int opLogging = 1;
//int opLogging = 0;
struct OpLog {
ofstream *f;
OpLog() {
stringstream ss;
ss << "oplog." << hex << time(0);
string name = ss.str();
f = new ofstream(name.c_str(), ios::out | ios::binary);
}
} _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);

Expand Down Expand Up @@ -690,6 +701,9 @@ void initAndListen(int listenPort, const char *dbPath, const char *appserverLoc

int main(int argc, char* argv[], char *envp[] )
{
if( opLogging )
cout << "WARNING: this build has oplog enabled at startup. opLogging=" << opLogging << endl;

#if !defined(_WIN32)
signal(SIGPIPE, pipeSigHandler);
#endif
Expand Down Expand Up @@ -778,7 +792,7 @@ int main(int argc, char* argv[], char *envp[] )
initAndListen(port, dbpath, appsrvPath);

goingAway = true;
return 0;
exit(0);
}

cout << "usage:\n";
Expand All @@ -801,3 +815,10 @@ int main(int argc, char* argv[], char *envp[] )
// return _tmain(argc, 0);
//}
//#endif

#undef exit
void dbexit(int rc) {
flushOpLog();
exit(rc);
}

2 changes: 1 addition & 1 deletion db/db.vcproj
Expand Up @@ -43,7 +43,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;C:\Program Files\Java\jdk1.6.0_05\include&quot;;&quot;C:\Program Files\Java\jdk1.6.0_05\include\win32&quot;"
AdditionalIncludeDirectories="&quot;..\pcre-7.4&quot;;..\boost;&quot;C:\Program Files\Java\jdk1.6.0_05\include&quot;;&quot;C:\Program Files\Java\jdk1.6.0_05\include\win32&quot;"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_SCL_SECURE_NO_DEPRECATE;BOOST_ALL_NO_LIB;BOOST_LIB_DIAGNOSTIC;_CRT_SECURE_NO_WARNINGS;HAVE_CONFIG_H"
MinimalRebuild="true"
BasicRuntimeChecks="3"
Expand Down
4 changes: 2 additions & 2 deletions db/query.cpp
Expand Up @@ -458,7 +458,7 @@ bool dbEval(JSObj& cmd, JSObjBuilder& result) {
}

extern int opLogging;
extern ofstream oplog;
void flushOpLog();

// e.g.
// system.cmd$.find( { queryTraceLevel: 2 } );
Expand Down Expand Up @@ -506,7 +506,7 @@ inline bool _runCommands(const char *ns, JSObj& jsobj, stringstream& ss, BufBuil
if( strcmp(e.fieldName(),"opLogging") == 0 ) {
valid = ok = true;
opLogging = (int) e.number();
oplog.flush();
flushOpLog();
cout << "CMD: opLogging set to " << opLogging << endl;
} else if( strcmp(e.fieldName(),"queryTraceLevel") == 0 ) {
valid = ok = true;
Expand Down
3 changes: 3 additions & 0 deletions stdafx.h
Expand Up @@ -129,3 +129,6 @@ inline void our_debug_free(void *p) {
}
#define free our_debug_free
#endif

void dbexit(int resultcode);
#define exit dbexit

0 comments on commit cb18407

Please sign in to comment.