summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDwight <dmerriman@gmail.com>2008-07-11 12:27:23 -0400
committerDwight <dmerriman@gmail.com>2008-07-11 12:27:23 -0400
commit51bb240a58e2f80c338a8295f837711dad1a713b (patch)
treef2ba89a893ef3dc5c779a35b8f7d70e86bc4267e
parent86fd5369aa675b0f0aa2ed46877c32e3a73b9521 (diff)
downloadmongo-51bb240a58e2f80c338a8295f837711dad1a713b.tar.gz
--nojni option.
-rw-r--r--db/db.cpp48
-rw-r--r--db/jsobj.cpp2
-rw-r--r--db/pdfile.cpp3
-rw-r--r--db/query.cpp6
-rw-r--r--stdafx.cpp5
-rw-r--r--stdafx.h4
-rw-r--r--util/log.h91
7 files changed, 81 insertions, 78 deletions
diff --git a/db/db.cpp b/db/db.cpp
index d9e04348850..55db7028ae4 100644
--- a/db/db.cpp
+++ b/db/db.cpp
@@ -13,10 +13,11 @@
#include "query.h"
#include "introspect.h"
+bool useJNI = true;
extern const char *dbpath;
extern int curOp;
-/* only off if --nocursor which is for debugging. */
+/* only off if --nocursors which is for debugging. */
bool useCursors = true;
boost::mutex dbMutex;
@@ -230,11 +231,9 @@ void receivedQuery(DbResponse& dbresponse, /*AbstractMessagingPort& dbMsgPort, *
}
catch( AssertionException ) {
ss << " exception ";
- problem() << " Caught Assertion in runQuery " << ns << endl;
- cout << " Caught Assertion in runQuery, continuing" << endl;
- cout << " ntoskip:" << ntoskip << " ntoreturn:" << ntoreturn << endl;
- cout << " ns:" << ns << endl;
- cout << " query:" << query.toString() << endl;
+ problem() << " Caught Assertion in runQuery ns:" << ns << endl;
+ cout << " ntoskip:" << ntoskip << " ntoreturn:" << ntoreturn << '\n';
+ cout << " query:" << query.toString() << '\n';
msgdata = (QueryResult*) malloc(sizeof(QueryResult));
QueryResult *qr = msgdata;
qr->_data[0] = 0;
@@ -445,7 +444,6 @@ void jniCallback(Message& m, Message& out)
}
catch( AssertionException ) {
problem() << "Caught Assertion in kill cursors, continuing" << endl;
- cout << "Caught Assertion in kill cursors, continuing" << endl;
ss << " exception ";
}
}
@@ -471,7 +469,6 @@ void jniCallback(Message& m, Message& out)
}
catch( AssertionException ) {
problem() << "Caught AssertionException in jniCall()" << endl;
- cout << "Caught AssertionException in jniCall()" << endl;
}
curOp = curOpOld;
@@ -569,7 +566,6 @@ void connThread()
}
catch( AssertionException ) {
problem() << " Caught Assertion insert, continuing" << endl;
- cout << "Caught Assertion, continuing" << endl;
ss << " exception ";
}
}
@@ -581,7 +577,6 @@ void connThread()
}
catch( AssertionException ) {
problem() << " Caught Assertion update, continuing" << endl;
- cout << "Caught Assertion update, continuing" << endl;
ss << " exception ";
}
}
@@ -593,7 +588,6 @@ void connThread()
}
catch( AssertionException ) {
problem() << " Caught Assertion receivedDelete, continuing" << endl;
- cout << "Caught Assertion receivedDelete, continuing" << endl;
ss << " exception ";
}
}
@@ -611,7 +605,6 @@ void connThread()
receivedKillCursors(m);
}
catch( AssertionException ) {
- cout << "Caught Assertion in kill cursors, continuing" << endl;
problem() << " Caught Assertion in kill cursors, continuing" << endl;
ss << " exception ";
}
@@ -735,7 +728,7 @@ void setupSignals() {}
#endif
void initAndListen(int listenPort, const char *dbPath, const char *appserverLoc = null) {
- if( opLogging )
+ if( opLogging )
cout << "opLogging = " << opLogging << endl;
_oplog.init();
@@ -768,8 +761,10 @@ void initAndListen(int listenPort, const char *dbPath, const char *appserverLoc
cout << "10Gen DB : starting : pid = " << pid << " port = " << port << " dbpath = " << dbpath << endl;
problem() << "10Gen DB : starting : pid = " << pid << " port = " << port << " dbpath = " << dbpath << endl;
- JavaJS = new JavaJSImpl(appserverLoc);
- javajstest();
+ if( useJNI ) {
+ JavaJS = new JavaJSImpl(appserverLoc);
+ javajstest();
+ }
setupSignals();
@@ -872,21 +867,20 @@ int main(int argc, char* argv[], char *envp[] )
for (int i = 1; i < argc; i++) {
- char *s = argv[i];
- if( s == 0 ) continue;
-
- if (strcmp(s, "--port") == 0) {
+ if( argv[i] == 0 ) continue;
+ string s = argv[i];
+
+ if( s == "--port" )
port = atoi(argv[++i]);
- }
- else if (strcmp(s, "--dbpath") == 0) {
+ else if( s == "--nojni" )
+ useJNI = false;
+ else if( s == "--dbpath" )
dbpath = argv[++i];
- }
- else if (strcmp(s, "--appsrvpath") == 0) {
+ else if( s == "--appsrvpath" )
appsrvPath = argv[++i];
- }
- else if( strcmp(s, "--nocursors") == 0)
+ else if( s == "--nocursors" )
useCursors = false;
- else if( strncmp(s, "--oplog", 7) == 0 ) {
+ else if( strncmp(s.c_str(), "--oplog", 7) == 0 ) {
int x = s[7] - '0';
if( x < 0 || x > 7 ) {
cout << "can't interpret --oplog setting" << endl;
@@ -913,7 +907,7 @@ int main(int argc, char* argv[], char *envp[] )
cout << " dev run in dev mode (diff db loc, diff port #)" << endl;
cout << endl << "Alternate Usage :" << endl;
cout << " --port <portno> --dbpath <root> --appsrvpath <root of appsrv>" << endl;
- cout << " --nocursors" << endl;
+ cout << " --nocursors --nojni" << endl;
cout << " --oplog<n> 0=off 1=W 2=R 3=both 7=W+some reads" << endl;
cout << endl;
diff --git a/db/jsobj.cpp b/db/jsobj.cpp
index 6fe927efafd..02d00192058 100644
--- a/db/jsobj.cpp
+++ b/db/jsobj.cpp
@@ -321,7 +321,7 @@ JSMatcher::JSMatcher(JSObj &_jsobj) :
assert( where == 0 );
where = new Where();
const char *code = e.valuestr();
- assert( JavaJS );
+ massert( "$where query, but jni is disabled", JavaJS );
where->scope = JavaJS->scopeCreate();
JavaJS->scopeSetString(where->scope, "$client", client->name.c_str());
where->setFunc(code);
diff --git a/db/pdfile.cpp b/db/pdfile.cpp
index 1f6282ccb86..6563e41ae77 100644
--- a/db/pdfile.cpp
+++ b/db/pdfile.cpp
@@ -690,7 +690,6 @@ void _unindexRecord(const char *ns, IndexDetails& id, JSObj& obj, const DiskLoc&
ok = id.head.btree()->unindex(id.head, id, j, dl);
}
catch(AssertionException) {
- cout << " caught assertion _unindexRecord " << id.indexNamespace() << '\n';
problem() << "Assertion failure: _unindex failed " << id.indexNamespace() << endl;
cout << "Assertion failure: _unindex failed" << '\n';
cout << " obj:" << obj.toString() << '\n';
@@ -842,7 +841,6 @@ void DataFileMgr::update(
}
catch(AssertionException) {
ss << " exception update unindex ";
- cout << " caught assertion update unindex " << idxns.c_str() << '\n';
problem() << " caught assertion update unindex " << idxns.c_str() << endl;
}
}
@@ -896,7 +894,6 @@ void _indexRecord(IndexDetails& idx, JSObj& obj, DiskLoc newRecordLoc) {
(JSObj&) *i, false, idx, true);
}
catch(AssertionException) {
- cout << " caught assertion _indexRecord " << idx.indexNamespace() << '\n';
problem() << " caught assertion _indexRecord " << idx.indexNamespace() << endl;
}
}
diff --git a/db/query.cpp b/db/query.cpp
index e09bb2d3fbe..49b87d90f2f 100644
--- a/db/query.cpp
+++ b/db/query.cpp
@@ -474,8 +474,10 @@ bool dbEval(JSObj& cmd, JSObjBuilder& result) {
Element e = cmd.firstElement();
assert( e.type() == Code );
const char *code = e.valuestr();
- if ( ! JavaJS )
- JavaJS = new JavaJSImpl();
+ if ( ! JavaJS ) {
+ result.append("errmsg", "db side execution is disabled");
+ return false;
+ }
jlong f = JavaJS->functionCreate(code);
if( f == 0 ) {
diff --git a/stdafx.cpp b/stdafx.cpp
index aa22e5e1b73..fc986b5f6dc 100644
--- a/stdafx.cpp
+++ b/stdafx.cpp
@@ -29,3 +29,8 @@ void asserted(const char *msg, const char *file, unsigned line) {
wasserted(msg, file, line);
throw AssertionException();
}
+
+void msgasserted(const char *msg) {
+ cout << "Assertion: " << msg << '\n';
+ throw AssertionException();
+}
diff --git a/stdafx.h b/stdafx.h
index 8ff133a8eba..b1356a410ba 100644
--- a/stdafx.h
+++ b/stdafx.h
@@ -23,6 +23,7 @@ public:
void asserted(const char *msg, const char *file, unsigned line);
void wasserted(const char *msg, const char *file, unsigned line);
+void msgasserted(const char *msg);
#ifdef assert
#undef assert
@@ -37,6 +38,9 @@ void wasserted(const char *msg, const char *file, unsigned line);
/* warning only - keeps going */
#define wassert(_Expression) (void)( (!!(_Expression)) || (wasserted(#_Expression, __FILE__, __LINE__), 0) )
+// display a message, no context, and throw assertionexception
+#define massert(msg,_Expression) (void)( (!!(_Expression)) || (msgasserted(msg), 0) )
+
/* dassert is 'debug assert' -- might want to turn off for production as these
could be slow.
*/
diff --git a/util/log.h b/util/log.h
index 2c560843009..d4496de02c5 100644
--- a/util/log.h
+++ b/util/log.h
@@ -1,53 +1,54 @@
-// log.h
-
-#pragma once
-
-class Nullstream {
-public:
- Nullstream& operator<<(const char *) { return *this; }
- Nullstream& operator<<(int) { return *this; }
- Nullstream& operator<<(unsigned long) { return *this; }
- Nullstream& operator<<(unsigned) { return *this; }
- Nullstream& operator<<(double) { return *this; }
- Nullstream& operator<<(void *) { return *this; }
- Nullstream& operator<<(long long) { return *this; }
- Nullstream& operator<<(unsigned long long) { return *this; }
- Nullstream& operator<<(const string&) { return *this; }
- Nullstream& operator<< (ostream& ( *endl )(ostream&)) { return *this; }
- Nullstream& operator<< (ios_base& (*hex)(ios_base&)) { return *this; }
-};
-inline Nullstream& endl ( Nullstream& os ) { }
-extern Nullstream nullstream;
-
-#define LOGIT { lock lk(mutex); cout << x; return *this; }
-class Logstream {
- static boost::mutex mutex;
-public:
- Logstream& operator<<(const char *x) LOGIT
- Logstream& operator<<(int x) LOGIT
- Logstream& operator<<(unsigned long x) LOGIT
- Logstream& operator<<(unsigned x) LOGIT
- Logstream& operator<<(double x) LOGIT
- Logstream& operator<<(void *x) LOGIT
- Logstream& operator<<(long long x) LOGIT
- Logstream& operator<<(unsigned long long x) LOGIT
- Logstream& operator<<(const string& x) LOGIT
- Logstream& operator<< (ostream& ( *_endl )(ostream&)) { lock lk(mutex); cout << _endl; return *this; }
- Logstream& operator<< (ios_base& (*_hex)(ios_base&)) { lock lk(mutex); cout << _hex; return *this; }
- Logstream& prolog() {
- lock lk(mutex);
+// log.h
+
+#pragma once
+
+class Nullstream {
+public:
+ Nullstream& operator<<(const char *) { return *this; }
+ Nullstream& operator<<(int) { return *this; }
+ Nullstream& operator<<(unsigned long) { return *this; }
+ Nullstream& operator<<(unsigned) { return *this; }
+ Nullstream& operator<<(double) { return *this; }
+ Nullstream& operator<<(void *) { return *this; }
+ Nullstream& operator<<(long long) { return *this; }
+ Nullstream& operator<<(unsigned long long) { return *this; }
+ Nullstream& operator<<(const string&) { return *this; }
+ Nullstream& operator<< (ostream& ( *endl )(ostream&)) { return *this; }
+ Nullstream& operator<< (ios_base& (*hex)(ios_base&)) { return *this; }
+};
+inline Nullstream& endl ( Nullstream& os ) { }
+extern Nullstream nullstream;
+
+#define LOGIT { lock lk(mutex); cout << x; return *this; }
+class Logstream {
+ static boost::mutex mutex;
+public:
+ Logstream& operator<<(const char *x) LOGIT
+ Logstream& operator<<(char x) LOGIT
+ Logstream& operator<<(int x) LOGIT
+ Logstream& operator<<(unsigned long x) LOGIT
+ Logstream& operator<<(unsigned x) LOGIT
+ Logstream& operator<<(double x) LOGIT
+ Logstream& operator<<(void *x) LOGIT
+ Logstream& operator<<(long long x) LOGIT
+ Logstream& operator<<(unsigned long long x) LOGIT
+ Logstream& operator<<(const string& x) LOGIT
+ Logstream& operator<< (ostream& ( *_endl )(ostream&)) { lock lk(mutex); cout << _endl; return *this; }
+ Logstream& operator<< (ios_base& (*_hex)(ios_base&)) { lock lk(mutex); cout << _hex; return *this; }
+ Logstream& prolog() {
+ lock lk(mutex);
time_t t;
time(&t);
string now(ctime(&t),0,20);
cout << "~ " << now;
if( client )
- cout << curNs << ' ';
- return *this;
- }
-};
-inline Logstream& endl ( Logstream& os ) { }
-extern Logstream logstream;
-
+ cout << curNs << ' ';
+ return *this;
+ }
+};
+inline Logstream& endl ( Logstream& os ) { }
+extern Logstream logstream;
+
// not threadsafe
inline Logstream& problem() { return logstream.prolog(); }