2008-06-06 15:43:15 +02:00
|
|
|
// db.cpp : Defines the entry point for the console application.
|
|
|
|
//
|
|
|
|
|
2008-07-20 23:37:33 +02:00
|
|
|
/**
|
2009-01-29 22:06:22 +01:00
|
|
|
* Copyright (C) 2008 10gen Inc.info
|
2008-12-29 02:28:49 +01:00
|
|
|
*
|
2008-07-20 23:37:33 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
2008-12-29 02:28:49 +01:00
|
|
|
*
|
2008-07-20 23:37:33 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
2008-12-29 02:28:49 +01:00
|
|
|
*
|
2008-07-20 23:37:33 +02:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-12-03 16:12:27 +01:00
|
|
|
#include "stdafx.h"
|
2008-06-06 15:43:15 +02:00
|
|
|
#include "db.h"
|
|
|
|
#include "javajs.h"
|
|
|
|
#include "query.h"
|
|
|
|
#include "introspect.h"
|
2008-07-28 23:52:44 +02:00
|
|
|
#include "repl.h"
|
2008-09-09 20:30:22 +02:00
|
|
|
#include "../util/unittest.h"
|
2008-09-30 00:00:53 +02:00
|
|
|
#include "dbmessage.h"
|
2008-12-02 18:54:32 +01:00
|
|
|
#include "instance.h"
|
2008-06-06 15:43:15 +02:00
|
|
|
|
2009-01-14 23:09:51 +01:00
|
|
|
namespace mongo {
|
|
|
|
|
2009-01-20 20:30:59 +01:00
|
|
|
extern bool objcheck, quiet, quota, cpu;
|
2009-01-15 16:17:11 +01:00
|
|
|
bool useJNI = true;
|
|
|
|
|
|
|
|
/* only off if --nocursors which is for debugging. */
|
|
|
|
extern bool useCursors;
|
|
|
|
|
|
|
|
extern int port;
|
|
|
|
extern int curOp;
|
|
|
|
extern string dashDashSource;
|
|
|
|
extern int opLogging;
|
|
|
|
extern long long oplogSize;
|
|
|
|
extern OpLog _oplog;
|
|
|
|
|
|
|
|
extern int ctr;
|
|
|
|
extern int callDepth;
|
|
|
|
|
|
|
|
void setupSignals();
|
|
|
|
void closeAllSockets();
|
|
|
|
void startReplication();
|
|
|
|
void pairWith(const char *remoteEnd, const char *arb);
|
|
|
|
|
|
|
|
struct MyStartupTests {
|
|
|
|
MyStartupTests() {
|
|
|
|
assert( sizeof(OID) == 12 );
|
|
|
|
}
|
|
|
|
} mystartupdbcpp;
|
2008-06-06 15:43:15 +02:00
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
void quicktest() {
|
2009-01-15 17:26:38 +01:00
|
|
|
out() << "quicktest()\n";
|
2008-06-06 15:43:15 +02:00
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
MemoryMappedFile mmf;
|
|
|
|
char *m = (char *) mmf.map("/tmp/quicktest", 16384);
|
2009-01-15 17:26:38 +01:00
|
|
|
// out() << "mmf reads: " << m << endl;
|
2009-01-15 16:17:11 +01:00
|
|
|
strcpy_s(m, 1000, "hello worldz");
|
|
|
|
}
|
2008-06-17 22:57:12 +02:00
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
QueryResult* emptyMoreResult(long long);
|
2008-06-06 15:43:15 +02:00
|
|
|
|
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
void testTheDb() {
|
|
|
|
stringstream ss;
|
2008-06-06 15:43:15 +02:00
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
setClient("sys.unittest.pdfile");
|
2008-06-06 15:43:15 +02:00
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
/* this is not validly formatted, if you query this namespace bad things will happen */
|
|
|
|
theDataFileMgr.insert("sys.unittest.pdfile", (void *) "hello worldx", 13);
|
|
|
|
theDataFileMgr.insert("sys.unittest.pdfile", (void *) "hello worldx", 13);
|
2008-06-06 15:43:15 +02:00
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
BSONObj j1((const char *) &js1);
|
|
|
|
deleteObjects("sys.unittest.delete", j1, false);
|
|
|
|
theDataFileMgr.insert("sys.unittest.delete", &js1, sizeof(js1));
|
|
|
|
deleteObjects("sys.unittest.delete", j1, false);
|
|
|
|
updateObjects("sys.unittest.delete", j1, j1, true,ss);
|
|
|
|
updateObjects("sys.unittest.delete", j1, j1, false,ss);
|
2008-06-06 15:43:15 +02:00
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
auto_ptr<Cursor> c = theDataFileMgr.findAll("sys.unittest.pdfile");
|
|
|
|
while ( c->ok() ) {
|
|
|
|
c->_current();
|
|
|
|
c->advance();
|
|
|
|
}
|
2009-01-15 17:26:38 +01:00
|
|
|
out() << endl;
|
2008-06-06 15:43:15 +02:00
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
database = 0;
|
2008-12-29 02:28:49 +01:00
|
|
|
}
|
2008-06-06 15:43:15 +02:00
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
MessagingPort *grab = 0;
|
|
|
|
void connThread();
|
|
|
|
|
|
|
|
class OurListener : public Listener {
|
|
|
|
public:
|
|
|
|
OurListener(int p) : Listener(p) { }
|
|
|
|
virtual void accepted(MessagingPort *mp) {
|
|
|
|
assert( grab == 0 );
|
|
|
|
grab = mp;
|
|
|
|
boost::thread thr(connThread);
|
|
|
|
while ( grab )
|
|
|
|
sleepmillis(1);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void webServerThread();
|
|
|
|
void pdfileInit();
|
|
|
|
|
|
|
|
/* versions
|
|
|
|
114 bad memory bug fixed
|
|
|
|
115 replay, opLogging
|
|
|
|
*/
|
|
|
|
void listen(int port) {
|
|
|
|
const char *Version = "db version 122";
|
|
|
|
log() << Version << ", pdfile version " << VERSION << "." << VERSION_MINOR << endl;
|
|
|
|
pdfileInit();
|
|
|
|
//testTheDb();
|
|
|
|
log() << "waiting for connections on port " << port << "..." << endl;
|
|
|
|
OurListener l(port);
|
|
|
|
startReplication();
|
|
|
|
boost::thread thr(webServerThread);
|
|
|
|
l.listen();
|
2008-12-29 02:28:49 +01:00
|
|
|
}
|
2009-01-15 16:17:11 +01:00
|
|
|
|
|
|
|
class JniMessagingPort : public AbstractMessagingPort {
|
|
|
|
public:
|
|
|
|
JniMessagingPort(Message& _container) : container(_container) { }
|
|
|
|
void reply(Message& received, Message& response, MSGID) {
|
|
|
|
container = response;
|
|
|
|
}
|
|
|
|
void reply(Message& received, Message& response) {
|
|
|
|
container = response;
|
|
|
|
}
|
|
|
|
Message & container;
|
|
|
|
};
|
2008-06-06 15:43:15 +02:00
|
|
|
|
2009-01-14 23:09:51 +01:00
|
|
|
} // namespace mongo
|
|
|
|
|
2009-01-05 21:30:07 +01:00
|
|
|
#include "lasterror.h"
|
2009-01-14 23:17:24 +01:00
|
|
|
#include "security.h"
|
2009-01-05 21:30:07 +01:00
|
|
|
|
2009-01-14 23:09:51 +01:00
|
|
|
namespace mongo {
|
|
|
|
|
2009-01-29 22:06:22 +01:00
|
|
|
void sysInfo() {
|
|
|
|
out() << "sysinfo:\n";
|
|
|
|
#if defined(_SC_PAGE_SIZE)
|
|
|
|
out() << " page size: " << (int) sysconf(_SC_PAGE_SIZE) << endl;
|
|
|
|
#endif
|
|
|
|
#if defined(_SC_PHYS_PAGES)
|
|
|
|
out() << " _SC_PHYS_PAGES: " << sysconf(_SC_PHYS_PAGES) << endl;
|
|
|
|
#endif
|
|
|
|
#if defined(_SC_AVPHYS_PAGES)
|
|
|
|
out() << " _SC_AVPHYS_PAGES: " << sysconf(_SC_AVPHYS_PAGES) << endl;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
/* we create one thread for each connection from an app server database.
|
|
|
|
app server will open a pool of threads.
|
|
|
|
*/
|
|
|
|
void connThread()
|
|
|
|
{
|
|
|
|
AuthenticationInfo *ai = new AuthenticationInfo();
|
|
|
|
authInfo.reset(ai);
|
|
|
|
LastError *le = new LastError();
|
|
|
|
lastError.reset(le);
|
2008-12-29 02:28:49 +01:00
|
|
|
|
2009-01-18 23:48:44 +01:00
|
|
|
MessagingPort& dbMsgPort = *grab;
|
|
|
|
grab = 0;
|
|
|
|
|
|
|
|
try {
|
2009-01-05 21:30:07 +01:00
|
|
|
|
2009-01-21 23:26:16 +01:00
|
|
|
ai->isLocalHost = dbMsgPort.farEnd.isLocalHost();
|
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
Message m;
|
|
|
|
while ( 1 ) {
|
|
|
|
m.reset();
|
|
|
|
|
|
|
|
if ( !dbMsgPort.recv(m) ) {
|
|
|
|
log() << "end connection " << dbMsgPort.farEnd.toString() << endl;
|
2008-12-29 02:28:49 +01:00
|
|
|
dbMsgPort.shutdown();
|
2009-01-15 16:17:11 +01:00
|
|
|
break;
|
2008-12-29 02:28:49 +01:00
|
|
|
}
|
2009-01-15 16:17:11 +01:00
|
|
|
|
|
|
|
le->nPrev++;
|
|
|
|
|
|
|
|
DbResponse dbresponse;
|
|
|
|
if ( !assembleResponse( m, dbresponse ) ) {
|
2009-01-15 17:26:38 +01:00
|
|
|
out() << curTimeMillis() % 10000 << " end msg " << dbMsgPort.farEnd.toString() << endl;
|
2009-01-19 02:31:33 +01:00
|
|
|
/* todo: we may not wish to allow this, even on localhost: very low priv accounts could stop us. */
|
2009-01-15 16:17:11 +01:00
|
|
|
if ( dbMsgPort.farEnd.isLocalHost() ) {
|
|
|
|
dbMsgPort.shutdown();
|
|
|
|
sleepmillis(50);
|
|
|
|
problem() << "exiting end msg" << endl;
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
else {
|
2009-01-15 17:26:38 +01:00
|
|
|
out() << " (not from localhost, ignoring end msg)" << endl;
|
2009-01-15 16:17:11 +01:00
|
|
|
}
|
2008-12-29 02:28:49 +01:00
|
|
|
}
|
2009-01-15 16:17:11 +01:00
|
|
|
|
|
|
|
if ( dbresponse.response )
|
|
|
|
dbMsgPort.reply(m, *dbresponse.response, dbresponse.responseTo);
|
2008-12-29 02:28:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2009-01-15 16:17:11 +01:00
|
|
|
catch ( AssertionException& ) {
|
2009-01-18 23:48:44 +01:00
|
|
|
problem() << "AssertionException in connThread, closing client connection" << endl;
|
|
|
|
dbMsgPort.shutdown();
|
2009-01-15 16:17:11 +01:00
|
|
|
}
|
|
|
|
catch ( std::exception &e ) {
|
|
|
|
problem() << "Uncaught std::exception: " << e.what() << ", terminating" << endl;
|
|
|
|
exit( 15 );
|
|
|
|
}
|
|
|
|
catch ( ... ) {
|
|
|
|
problem() << "Uncaught exception, terminating" << endl;
|
|
|
|
exit( 15 );
|
|
|
|
}
|
2008-12-29 05:11:09 +01:00
|
|
|
}
|
2008-06-06 15:43:15 +02:00
|
|
|
|
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
void msg(const char *m, const char *address, int port, int extras = 0) {
|
2008-06-06 15:43:15 +02:00
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
SockAddr db(address, port);
|
2008-06-06 15:43:15 +02:00
|
|
|
|
|
|
|
// SockAddr db("127.0.0.1", DBPort);
|
|
|
|
// SockAddr db("192.168.37.1", MessagingPort::DBPort);
|
|
|
|
// SockAddr db("10.0.21.60", MessagingPort::DBPort);
|
|
|
|
// SockAddr db("172.16.0.179", MessagingPort::DBPort);
|
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
MessagingPort p;
|
|
|
|
if ( !p.connect(db) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
const int Loops = 1;
|
|
|
|
for ( int q = 0; q < Loops; q++ ) {
|
|
|
|
Message send;
|
|
|
|
Message response;
|
|
|
|
|
|
|
|
send.setData( dbMsg , m);
|
|
|
|
int len = send.data->dataLen();
|
|
|
|
|
|
|
|
for ( int i = 0; i < extras; i++ )
|
|
|
|
p.say(/*db, */send);
|
|
|
|
|
|
|
|
Timer t;
|
|
|
|
bool ok = p.call(send, response);
|
|
|
|
double tm = t.micros() + 1;
|
2009-01-15 17:26:38 +01:00
|
|
|
out() << " ****ok. response.data:" << ok << " time:" << tm / 1000.0 << "ms " <<
|
2009-01-15 16:17:11 +01:00
|
|
|
((double) len) * 8 / 1000000 / (tm/1000000) << "Mbps" << endl;
|
|
|
|
if ( q+1 < Loops ) {
|
2009-01-15 17:26:38 +01:00
|
|
|
out() << "\t\tSLEEP 8 then sending again as a test" << endl;
|
2009-01-15 16:17:11 +01:00
|
|
|
sleepsecs(8);
|
|
|
|
}
|
2008-12-29 02:28:49 +01:00
|
|
|
}
|
2009-01-15 16:17:11 +01:00
|
|
|
sleepsecs(1);
|
2008-12-29 02:28:49 +01:00
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
p.shutdown();
|
|
|
|
}
|
2008-06-06 15:43:15 +02:00
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
void msg(const char *m, int extras = 0) {
|
|
|
|
msg(m, "127.0.0.1", DBPort, extras);
|
|
|
|
}
|
2008-06-06 15:43:15 +02:00
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
void repairDatabases() {
|
|
|
|
dblock lk;
|
|
|
|
vector< string > dbNames;
|
|
|
|
getDatabaseNames( dbNames );
|
|
|
|
for ( vector< string >::iterator i = dbNames.begin(); i != dbNames.end(); ++i ) {
|
|
|
|
string dbName = *i;
|
|
|
|
assert( !setClientTempNs( dbName.c_str() ) );
|
|
|
|
PhysicalDataFile *p = database->getFile( 0 );
|
|
|
|
PDFHeader *h = p->getHeader();
|
|
|
|
if ( !h->currentVersion() ) {
|
|
|
|
// QUESTION: Repair even if file format is higher version than code?
|
|
|
|
log() << "repairing database " << dbName << " with pdfile version " << h->version << "." << h->versionMinor << ", "
|
|
|
|
<< "new version: " << VERSION << "." << VERSION_MINOR << endl;
|
|
|
|
string errmsg;
|
|
|
|
assert( repairDatabase( dbName.c_str(), errmsg ) );
|
|
|
|
} else {
|
|
|
|
closeClient( dbName.c_str() );
|
|
|
|
}
|
2008-12-29 02:28:49 +01:00
|
|
|
}
|
|
|
|
}
|
2008-12-18 19:32:47 +01:00
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
void clearTmpFiles() {
|
|
|
|
boost::filesystem::path path( dbpath );
|
|
|
|
for ( boost::filesystem::directory_iterator i( path );
|
|
|
|
i != boost::filesystem::directory_iterator(); ++i ) {
|
|
|
|
string fileName = i->leaf();
|
|
|
|
if ( boost::filesystem::is_directory( *i ) &&
|
|
|
|
fileName.length() > 2 && fileName.substr( 0, 3 ) == "tmp" )
|
|
|
|
boost::filesystem::remove_all( *i );
|
|
|
|
}
|
2009-01-14 23:17:24 +01:00
|
|
|
}
|
2008-12-29 20:22:36 +01:00
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
Timer startupSrandTimer;
|
2009-01-07 19:31:16 +01:00
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
void segvhandler(int x);
|
|
|
|
void initAndListen(int listenPort, const char *appserverLoc = null) {
|
2009-01-21 17:44:40 +01:00
|
|
|
stringstream ss;
|
|
|
|
ss << "dbpath (" << dbpath << ") does not exist";
|
|
|
|
massert( ss.str().c_str(), boost::filesystem::exists( dbpath ) );
|
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
clearTmpFiles();
|
2009-01-14 23:17:24 +01:00
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
if ( opLogging )
|
|
|
|
log() << "opLogging = " << opLogging << endl;
|
|
|
|
_oplog.init();
|
2008-12-29 02:28:49 +01:00
|
|
|
|
2008-06-07 15:19:49 +02:00
|
|
|
#if !defined(_WIN32)
|
2009-01-15 16:17:11 +01:00
|
|
|
assert( signal(SIGSEGV, segvhandler) != SIG_ERR );
|
2008-06-07 15:19:49 +02:00
|
|
|
#endif
|
2008-06-06 15:43:15 +02:00
|
|
|
|
|
|
|
#if !defined(_WIN32)
|
2009-01-15 16:17:11 +01:00
|
|
|
pid_t pid = 0;
|
|
|
|
pid = getpid();
|
2008-06-06 15:43:15 +02:00
|
|
|
#else
|
2009-01-15 16:17:11 +01:00
|
|
|
int pid=0;
|
2008-06-06 15:43:15 +02:00
|
|
|
#endif
|
2008-12-29 02:28:49 +01:00
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
log() << "Mongo DB : starting : pid = " << pid << " port = " << port << " dbpath = " << dbpath
|
|
|
|
<< " master = " << master << " slave = " << slave << endl;
|
2008-06-06 15:43:15 +02:00
|
|
|
|
2008-12-22 18:38:12 +01:00
|
|
|
#if !defined(NOJNI)
|
2009-01-15 16:17:11 +01:00
|
|
|
if ( useJNI ) {
|
|
|
|
JavaJS = new JavaJSImpl(appserverLoc);
|
|
|
|
javajstest();
|
|
|
|
}
|
2008-12-22 18:38:12 +01:00
|
|
|
#endif
|
2008-06-06 15:43:15 +02:00
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
setupSignals();
|
2008-12-29 02:28:49 +01:00
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
repairDatabases();
|
2008-06-06 16:17:58 +02:00
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
/* this is for security on certain platforms */
|
2009-01-18 18:19:26 +01:00
|
|
|
srand(curTimeMicros() ^ startupSrandTimer.micros());
|
2009-01-07 19:31:16 +01:00
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
listen(listenPort);
|
|
|
|
}
|
2008-06-06 15:43:15 +02:00
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
int test2();
|
|
|
|
void testClient();
|
|
|
|
void pipeSigHandler( int signal );
|
2008-06-06 15:43:15 +02:00
|
|
|
|
2009-01-14 23:09:51 +01:00
|
|
|
} // namespace mongo
|
|
|
|
|
|
|
|
using namespace mongo;
|
|
|
|
|
2008-06-06 15:43:15 +02:00
|
|
|
int main(int argc, char* argv[], char *envp[] )
|
|
|
|
{
|
2009-01-22 17:15:51 +01:00
|
|
|
dbExecCommand = argv[0];
|
|
|
|
|
2009-01-18 18:19:26 +01:00
|
|
|
srand(curTimeMicros());
|
2008-12-29 23:59:44 +01:00
|
|
|
boost::filesystem::path::default_name_check( boost::filesystem::no_check );
|
2009-01-14 23:17:24 +01:00
|
|
|
|
2008-12-22 18:38:12 +01:00
|
|
|
{
|
|
|
|
unsigned x = 0x12345678;
|
|
|
|
unsigned char& b = (unsigned char&) x;
|
2008-12-29 02:28:49 +01:00
|
|
|
if ( b != 0x78 ) {
|
2009-01-15 17:26:38 +01:00
|
|
|
out() << "big endian cpus not yet supported" << endl;
|
2008-12-22 18:38:12 +01:00
|
|
|
return 33;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-15 17:26:38 +01:00
|
|
|
DEV out() << "warning: DEV mode enabled\n";
|
2008-06-25 23:13:40 +02:00
|
|
|
|
2008-06-06 15:43:15 +02:00
|
|
|
#if !defined(_WIN32)
|
|
|
|
signal(SIGPIPE, pipeSigHandler);
|
|
|
|
#endif
|
2008-12-29 02:28:49 +01:00
|
|
|
UnitTest::runTests();
|
2008-09-09 20:30:22 +02:00
|
|
|
|
2008-12-29 02:28:49 +01:00
|
|
|
if ( argc >= 2 ) {
|
|
|
|
if ( strcmp(argv[1], "quicktest") == 0 ) {
|
|
|
|
quicktest();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if ( strcmp(argv[1], "javatest") == 0 ) {
|
2008-12-22 18:38:12 +01:00
|
|
|
#if !defined(NOJNI)
|
|
|
|
JavaJS = new JavaJSImpl();
|
|
|
|
javajstest();
|
|
|
|
#else
|
2009-01-15 17:26:38 +01:00
|
|
|
out() << "NOJNI build cannot test" << endl;
|
2008-12-22 18:38:12 +01:00
|
|
|
#endif
|
2008-12-29 02:28:49 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if ( strcmp(argv[1], "test2") == 0 ) {
|
|
|
|
return test2();
|
|
|
|
}
|
|
|
|
if ( strcmp(argv[1], "msg") == 0 ) {
|
|
|
|
|
|
|
|
// msg(argc >= 3 ? argv[2] : "ping");
|
|
|
|
|
|
|
|
const char *m = "ping";
|
|
|
|
int thePort = DBPort;
|
|
|
|
|
|
|
|
if (argc >= 3) {
|
|
|
|
m = argv[2];
|
|
|
|
|
|
|
|
if (argc > 3) {
|
|
|
|
thePort = atoi(argv[3]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
msg(m, "127.0.0.1", thePort);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if ( strcmp(argv[1], "msglots") == 0 ) {
|
|
|
|
msg(argc >= 3 ? argv[2] : "ping", 1000);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if ( strcmp( argv[1], "testclient") == 0 ) {
|
|
|
|
testClient();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if ( strcmp(argv[1], "zzz") == 0 ) {
|
|
|
|
msg(argc >= 3 ? argv[2] : "ping", 1000);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if ( strcmp(argv[1], "run") == 0 ) {
|
|
|
|
initAndListen(port);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if ( strcmp(argv[1], "longmsg") == 0 ) {
|
|
|
|
char buf[800000];
|
|
|
|
memset(buf, 'a', 799999);
|
|
|
|
buf[799999] = 0;
|
|
|
|
buf[799998] = 'b';
|
|
|
|
buf[0] = 'c';
|
|
|
|
msg(buf);
|
|
|
|
return 0;
|
|
|
|
}
|
2008-06-06 15:43:15 +02:00
|
|
|
|
|
|
|
/*
|
2008-12-29 02:28:49 +01:00
|
|
|
* *** POST STANDARD SWITCH METHOD - if we don't satisfy, we switch to a
|
2008-06-06 15:43:15 +02:00
|
|
|
* slightly different mode where "run" is assumed and we can set values
|
|
|
|
*/
|
2008-12-29 02:28:49 +01:00
|
|
|
|
2008-06-06 15:43:15 +02:00
|
|
|
char *appsrvPath = null;
|
2008-12-29 02:28:49 +01:00
|
|
|
|
2008-06-06 15:43:15 +02:00
|
|
|
for (int i = 1; i < argc; i++) {
|
2008-07-11 18:27:23 +02:00
|
|
|
|
2008-12-29 02:28:49 +01:00
|
|
|
if ( argv[i] == 0 ) continue;
|
|
|
|
string s = argv[i];
|
|
|
|
|
|
|
|
if ( s == "--port" )
|
2008-06-06 15:43:15 +02:00
|
|
|
port = atoi(argv[++i]);
|
2008-12-29 02:28:49 +01:00
|
|
|
else if ( s == "--nojni" )
|
|
|
|
useJNI = false;
|
|
|
|
else if ( s == "--master" )
|
|
|
|
master = true;
|
|
|
|
else if ( s == "--slave" )
|
|
|
|
slave = true;
|
|
|
|
else if ( s == "--help" || s == "-?" || s == "--?" )
|
2008-12-11 16:27:05 +01:00
|
|
|
goto usage;
|
2008-12-29 02:28:49 +01:00
|
|
|
else if ( s == "--quiet" )
|
2008-12-11 16:27:05 +01:00
|
|
|
quiet = true;
|
2009-01-14 23:17:24 +01:00
|
|
|
else if ( s == "--cpu" )
|
|
|
|
cpu = true;
|
2009-01-19 02:31:33 +01:00
|
|
|
else if ( s == "--noauth" )
|
|
|
|
noauth = true;
|
|
|
|
else if ( s == "--auth" )
|
|
|
|
noauth = false;
|
2009-01-29 22:06:22 +01:00
|
|
|
else if( s == "--sysinfo" ) {
|
|
|
|
sysInfo();
|
|
|
|
return 0;
|
|
|
|
}
|
2008-12-29 17:47:20 +01:00
|
|
|
else if ( s == "--verbose" )
|
2009-01-20 20:30:59 +01:00
|
|
|
logLevel = 1;
|
|
|
|
else if ( s.find( "-v" ) == 0 ){
|
|
|
|
logLevel = s.size() - 1;
|
|
|
|
}
|
2008-12-29 02:28:49 +01:00
|
|
|
else if ( s == "--quota" )
|
2008-12-27 18:07:20 +01:00
|
|
|
quota = true;
|
2008-12-29 02:28:49 +01:00
|
|
|
else if ( s == "--objcheck" )
|
2008-12-08 17:21:00 +01:00
|
|
|
objcheck = true;
|
2008-12-29 02:28:49 +01:00
|
|
|
else if ( s == "--source" ) {
|
2008-11-10 17:20:30 +01:00
|
|
|
/* specifies what the source in local.sources should be */
|
|
|
|
dashDashSource = argv[++i];
|
2008-12-29 02:28:49 +01:00
|
|
|
}
|
|
|
|
else if ( s == "--pairwith" ) {
|
|
|
|
pairWith( argv[i+1], argv[i+2] );
|
2008-09-11 21:13:47 +02:00
|
|
|
i += 2;
|
2008-12-29 02:28:49 +01:00
|
|
|
}
|
|
|
|
else if ( s == "--dbpath" )
|
|
|
|
dbpath = argv[++i];
|
|
|
|
else if ( s == "--appsrvpath" )
|
2008-06-06 15:43:15 +02:00
|
|
|
appsrvPath = argv[++i];
|
2008-12-29 02:28:49 +01:00
|
|
|
else if ( s == "--nocursors" )
|
|
|
|
useCursors = false;
|
2009-01-13 16:34:18 +01:00
|
|
|
else if ( strncmp(s.c_str(), "--oplogSize", 11) == 0 ) {
|
2009-01-18 17:53:33 +01:00
|
|
|
long x = strtol( argv[ ++i ], 0, 10 );
|
|
|
|
uassert("bad arg", x > 0);
|
|
|
|
oplogSize = x * 1024 * 1024;
|
|
|
|
assert(oplogSize > 0);
|
2009-01-13 16:34:18 +01:00
|
|
|
}
|
2008-12-29 02:28:49 +01:00
|
|
|
else if ( strncmp(s.c_str(), "--oplog", 7) == 0 ) {
|
|
|
|
int x = s[7] - '0';
|
|
|
|
if ( x < 0 || x > 7 ) {
|
2009-01-15 17:26:38 +01:00
|
|
|
out() << "can't interpret --oplog setting" << endl;
|
2009-01-25 18:40:11 +01:00
|
|
|
dbexit(13);
|
2008-12-29 02:28:49 +01:00
|
|
|
}
|
|
|
|
opLogging = x;
|
|
|
|
}
|
2008-06-06 15:43:15 +02:00
|
|
|
}
|
2009-01-20 20:30:59 +01:00
|
|
|
|
2008-12-18 19:32:47 +01:00
|
|
|
initAndListen(port, appsrvPath);
|
2008-12-29 02:28:49 +01:00
|
|
|
|
2009-01-25 18:40:11 +01:00
|
|
|
dbexit(0);
|
2008-12-29 02:28:49 +01:00
|
|
|
}
|
2008-06-06 15:43:15 +02:00
|
|
|
|
2008-12-11 16:27:05 +01:00
|
|
|
usage:
|
2009-01-15 17:26:38 +01:00
|
|
|
out() << "Mongo db ";
|
2008-12-22 18:38:12 +01:00
|
|
|
#if defined(NOJNI)
|
2009-01-15 17:26:38 +01:00
|
|
|
out() << "[nojni build] ";
|
2008-12-22 18:38:12 +01:00
|
|
|
#endif
|
2009-01-15 17:26:38 +01:00
|
|
|
out() << "usage:\n";
|
|
|
|
out() << " run run db" << endl;
|
|
|
|
out() << " msg end [port] shut down db server listening on port (or default)" << endl;
|
|
|
|
out() << " msg [msg] [port] send a request to the db server listening on port (or default)" << endl;
|
|
|
|
out() << " msglots send a bunch of test messages, and then wait for answer on the last one" << endl;
|
|
|
|
out() << " longmsg send a long test message to the db server" << endl;
|
|
|
|
out() << " quicktest just check basic assertions and exit" << endl;
|
|
|
|
out() << " test2 run test2() - see code" << endl;
|
|
|
|
out() << "\nOptions:\n";
|
|
|
|
out() << " --help show this usage information\n";
|
|
|
|
out() << " --port <portno> specify port number, default is 27017\n";
|
|
|
|
out() << " --dbpath <root> directory for datafiles, default is /data/db/\n";
|
|
|
|
out() << " --quiet quieter output\n";
|
|
|
|
out() << " --cpu show cpu+iowait utilization periodically\n";
|
2009-01-19 02:31:33 +01:00
|
|
|
out() << " --noauth run without security\n";
|
2009-01-24 00:24:15 +01:00
|
|
|
out() << " --auth run with security\n";
|
2009-01-15 17:26:38 +01:00
|
|
|
out() << " --verbose\n";
|
2009-01-20 20:30:59 +01:00
|
|
|
out() << " -v+ increase verbose level -v = --verbose\n";
|
2009-01-15 17:26:38 +01:00
|
|
|
out() << " --objcheck inspect client data for validity on receipt\n";
|
|
|
|
out() << " --quota enable db quota management\n";
|
|
|
|
out() << " --appsrvpath <path> root directory for the babble app server\n";
|
|
|
|
out() << " --nocursors diagnostic/debugging option\n";
|
|
|
|
out() << " --nojni" << endl;
|
|
|
|
out() << " --oplog<n> 0=off 1=W 2=R 3=both 7=W+some reads" << endl;
|
2009-01-18 17:53:33 +01:00
|
|
|
out() << " --oplogSize <size_in_megabytes> custom size for replication operation log" << endl;
|
2009-01-29 22:06:22 +01:00
|
|
|
out() << " --sysinfo print out some diagnostic system information\n";
|
2009-01-15 17:26:38 +01:00
|
|
|
out() << "\nReplication:" << endl;
|
|
|
|
out() << " --master\n";
|
|
|
|
out() << " --slave" << endl;
|
|
|
|
out() << " --source <server:port>" << endl;
|
|
|
|
out() << " --pairwith <server:port> <arbiter>" << endl;
|
|
|
|
out() << endl;
|
2008-12-29 02:28:49 +01:00
|
|
|
|
2008-12-27 04:06:48 +01:00
|
|
|
return 0;
|
2008-06-06 15:43:15 +02:00
|
|
|
}
|
2009-01-07 00:25:38 +01:00
|
|
|
|
2009-01-14 23:09:51 +01:00
|
|
|
namespace mongo {
|
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
/* we do not use log() below as it uses a mutex and that could cause deadlocks.
|
|
|
|
*/
|
2009-01-07 00:25:38 +01:00
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
string getDbContext();
|
2009-01-07 00:25:38 +01:00
|
|
|
|
2009-01-18 17:53:33 +01:00
|
|
|
#undef out
|
2009-01-07 00:25:38 +01:00
|
|
|
|
|
|
|
#if !defined(_WIN32)
|
|
|
|
|
2009-01-14 23:09:51 +01:00
|
|
|
} // namespace mongo
|
|
|
|
|
2009-01-07 00:25:38 +01:00
|
|
|
#include <signal.h>
|
|
|
|
|
2009-01-14 23:09:51 +01:00
|
|
|
namespace mongo {
|
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
void pipeSigHandler( int signal ) {
|
|
|
|
psignal( signal, "Signal Received : ");
|
|
|
|
}
|
2009-01-07 00:25:38 +01:00
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
int segvs = 0;
|
|
|
|
void segvhandler(int x) {
|
|
|
|
if ( ++segvs > 1 ) {
|
|
|
|
signal(x, SIG_DFL);
|
|
|
|
if ( segvs == 2 ) {
|
2009-01-15 17:26:38 +01:00
|
|
|
out() << "\n\n\n got 2nd SIGSEGV" << endl;
|
2009-01-15 16:17:11 +01:00
|
|
|
sayDbContext();
|
|
|
|
}
|
|
|
|
return;
|
2009-01-07 00:25:38 +01:00
|
|
|
}
|
2009-01-15 17:26:38 +01:00
|
|
|
out() << "got SIGSEGV " << x << ", terminating :-(" << endl;
|
2009-01-15 16:17:11 +01:00
|
|
|
sayDbContext();
|
2009-01-07 00:25:38 +01:00
|
|
|
// closeAllSockets();
|
|
|
|
// MemoryMappedFile::closeAllFiles();
|
|
|
|
// flushOpLog();
|
2009-01-15 16:17:11 +01:00
|
|
|
dbexit(14);
|
|
|
|
}
|
2009-01-07 00:25:38 +01:00
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
void mysighandler(int x) {
|
|
|
|
signal(x, SIG_IGN);
|
2009-01-15 17:26:38 +01:00
|
|
|
out() << "got kill or ctrl c signal " << x << ", will terminate after current cmd ends" << endl;
|
2009-01-15 16:17:11 +01:00
|
|
|
{
|
|
|
|
dblock lk;
|
|
|
|
log() << "now exiting" << endl;
|
|
|
|
}
|
2009-01-27 17:52:52 +01:00
|
|
|
exit(12);
|
2009-01-07 00:25:38 +01:00
|
|
|
}
|
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
void setupSignals() {
|
|
|
|
assert( signal(SIGINT, mysighandler) != SIG_ERR );
|
|
|
|
assert( signal(SIGTERM, mysighandler) != SIG_ERR );
|
|
|
|
}
|
2009-01-07 00:25:38 +01:00
|
|
|
|
|
|
|
#else
|
2009-01-15 16:17:11 +01:00
|
|
|
void setupSignals() {}
|
2009-01-07 00:25:38 +01:00
|
|
|
#endif
|
2009-01-14 23:09:51 +01:00
|
|
|
|
|
|
|
} // namespace mongo
|