mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-30 00:56:44 +01:00
dbgrid.cpp added; return $err on assert
This commit is contained in:
parent
5f163f72b8
commit
1d4379a5d2
23
db/db.cpp
23
db/db.cpp
@ -253,22 +253,33 @@ void receivedQuery(DbResponse& dbresponse, /*AbstractMessagingPort& dbMsgPort, *
|
||||
try {
|
||||
msgdata = runQuery(m, ns, ntoskip, ntoreturn, query, fields, ss, m.data->dataAsInt());
|
||||
}
|
||||
catch( AssertionException ) {
|
||||
catch( AssertionException e ) {
|
||||
ss << " exception ";
|
||||
problem() << " Caught Assertion in runQuery ns:" << ns << endl;
|
||||
problem() << " Caught Assertion in runQuery ns:" << ns << ' ' << e.toString() << '\n';
|
||||
log() << " ntoskip:" << ntoskip << " ntoreturn:" << ntoreturn << '\n';
|
||||
log() << " query:" << query.toString() << '\n';
|
||||
msgdata = (QueryResult*) malloc(sizeof(QueryResult));
|
||||
log() << " query:" << query.toString() << endl;
|
||||
|
||||
JSObjBuilder err;
|
||||
err.append("$err", e.msg.empty() ? "assertion during query" : e.msg);
|
||||
JSObj errObj = err.done();
|
||||
|
||||
BufBuilder b;
|
||||
b.skip(sizeof(QueryResult));
|
||||
b.append((void*) errObj.objdata(), errObj.objsize());
|
||||
|
||||
msgdata = (QueryResult *) b.buf();
|
||||
b.decouple();
|
||||
QueryResult *qr = msgdata;
|
||||
qr->_data[0] = 0;
|
||||
qr->_data[1] = 0;
|
||||
qr->_data[2] = 0;
|
||||
qr->_data[3] = 0;
|
||||
qr->len = sizeof(QueryResult);
|
||||
qr->len = b.len();
|
||||
qr->setOperation(opReply);
|
||||
qr->cursorId = 0;
|
||||
qr->startingFrom = 0;
|
||||
qr->nReturned = 0;
|
||||
qr->nReturned = 1;
|
||||
|
||||
}
|
||||
Message *resp = new Message();
|
||||
resp->setData(msgdata, true); // transport will free
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "javajs.h"
|
||||
#include "json.h"
|
||||
#include "repl.h"
|
||||
#include "replset.h"
|
||||
#include "scanandorder.h"
|
||||
|
||||
/* We cut off further objects once we cross this threshold; thus, you might get
|
||||
@ -418,8 +419,9 @@ bool runCommands(const char *ns, JSObj& jsobj, stringstream& ss, BufBuilder &b,
|
||||
try {
|
||||
return _runCommands(ns, jsobj, ss, b, anObjBuilder);
|
||||
}
|
||||
catch( AssertionException ) {
|
||||
;
|
||||
catch( AssertionException e ) {
|
||||
if( !e.msg.empty() )
|
||||
anObjBuilder.append("assertion", e.msg);
|
||||
}
|
||||
ss << " assertion ";
|
||||
anObjBuilder.append("errmsg", "db assertion failure");
|
||||
@ -533,6 +535,8 @@ QueryResult* runQuery(Message& message, const char *ns, int ntoskip, int _ntoret
|
||||
}
|
||||
else {
|
||||
|
||||
uassert("not master", isMaster());
|
||||
|
||||
JSObj query = jsobj.getObjectField("query");
|
||||
JSObj order = jsobj.getObjectField("orderby");
|
||||
if( query.isEmpty() && order.isEmpty() )
|
||||
|
@ -35,7 +35,6 @@
|
||||
#include "db.h"
|
||||
#include "commands.h"
|
||||
|
||||
extern int port;
|
||||
extern boost::mutex dbMutex;
|
||||
auto_ptr<Cursor> findTableScan(const char *ns, JSObj& order);
|
||||
bool userCreateNS(const char *ns, JSObj& j, string& err);
|
||||
|
@ -16,6 +16,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
extern int port;
|
||||
|
||||
/* ReplPair is a pair of db servers replicating to one another and cooperating.
|
||||
|
||||
Only one member of the pair is active at a time; so this is a smart master/slave
|
||||
@ -54,7 +56,12 @@ public:
|
||||
void negotiate(DBClientConnection *conn);
|
||||
};
|
||||
|
||||
ReplPair::ReplPair(const char *remoteEnd) {
|
||||
extern ReplPair *replPair;
|
||||
|
||||
/* we should not allow most operations when not the master */
|
||||
inline bool isMaster() { return replPair == 0 || replPair->state == 1; }
|
||||
|
||||
inline ReplPair::ReplPair(const char *remoteEnd) {
|
||||
state = -1;
|
||||
remote = remoteEnd;
|
||||
remotePort = DBPort;
|
||||
|
63
dbgrid/dbgrid.cpp
Normal file
63
dbgrid/dbgrid.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
// dbgrid.cpp
|
||||
|
||||
/**
|
||||
* Copyright (C) 2008 10gen Inc.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "../util/unittest.h"
|
||||
|
||||
const char *curNs = "";
|
||||
Client *client = 0;
|
||||
|
||||
/* this is a good place to set a breakpoint when debugging, as lots of warning things
|
||||
(assert, wassert) call it.
|
||||
*/
|
||||
void sayDbContext(const char *errmsg) {
|
||||
if( errmsg )
|
||||
problem() << errmsg << endl;
|
||||
printStackTrace();
|
||||
}
|
||||
|
||||
#if !defined(_WIN32)
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
void pipeSigHandler( int signal ) {
|
||||
psignal( signal, "Signal Received : ");
|
||||
}
|
||||
|
||||
#else
|
||||
void setupSignals() {}
|
||||
#endif
|
||||
|
||||
int main(int argc, char* argv[], char *envp[] ) {
|
||||
#if !defined(_WIN32)
|
||||
signal(SIGPIPE, pipeSigHandler);
|
||||
#endif
|
||||
|
||||
log() << "dbgrid starting" << endl;
|
||||
|
||||
UnitTest::runTests();
|
||||
|
||||
dbexit(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#undef exit
|
||||
void dbexit(int rc, const char *why) {
|
||||
log() << "dbexit: " << why << " rc:" << rc << endl;
|
||||
exit(rc);
|
||||
}
|
14
stdafx.h
14
stdafx.h
@ -48,14 +48,15 @@ inline void * ourrealloc(void *ptr, size_t size) {
|
||||
|
||||
#include "targetver.h"
|
||||
|
||||
//#include "assert.h"
|
||||
|
||||
#include <string>
|
||||
using namespace std;
|
||||
// you can catch these
|
||||
class AssertionException {
|
||||
public:
|
||||
const char *msg;
|
||||
AssertionException() { msg = ""; }
|
||||
string msg;
|
||||
AssertionException() { }
|
||||
virtual bool isUserAssertion() { return false; }
|
||||
virtual string toString() { return msg; }
|
||||
};
|
||||
|
||||
/* we use the same mechanism for bad things the user does -- which are really just errors */
|
||||
@ -63,6 +64,7 @@ class UserAssertionException : public AssertionException {
|
||||
public:
|
||||
UserAssertionException(const char *_msg) { msg = _msg; }
|
||||
virtual bool isUserAssertion() { return true; }
|
||||
virtual string toString() { return "userassert:" + msg; }
|
||||
};
|
||||
|
||||
void asserted(const char *msg, const char *file, unsigned line);
|
||||
@ -107,13 +109,11 @@ typedef char _TCHAR;
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
using namespace std;
|
||||
|
||||
#include "time.h"
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
//using namespace std;
|
||||
|
||||
#if !defined(_WIN32)
|
||||
typedef int HANDLE;
|
||||
|
Loading…
Reference in New Issue
Block a user