0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

set options flag when $err is returned

This commit is contained in:
Dwight 2009-01-09 11:20:16 -05:00
parent da9a8dcac0
commit 96d4406ece
9 changed files with 46 additions and 51 deletions

View File

@ -220,7 +220,7 @@ void DBClientCursor::requestMore() {
void DBClientCursor::dataReceived() {
QueryResult *qr = (QueryResult *) m->data;
if ( qr->resultFlags() & ResultFlag_CursorNotFound ) {
if ( qr->resultFlags() & QueryResult::ResultFlag_CursorNotFound ) {
// cursor id no longer valid at the server.
assert( qr->cursorId == 0 );
cursorId = 0; // 0 indicates no longer valid (dead)

View File

@ -22,7 +22,7 @@
#include "../db/jsobj.h"
/* the query field 'options' can have these bits set: */
enum {
enum QueryOptions {
/* Tailable means cursor is not closed when the last data is retrieved. rather, the cursor marks
the final object's position. you can resume using the cursor later, from where it was located,
if more data were received. Set on dbQuery and dbGetMore.
@ -42,8 +42,23 @@ enum {
class BSONObj;
/* db response format
Query or GetMore: // see struct QueryResult
int resultFlags;
int64 cursorID;
int startingFrom;
int nReturned;
list of marshalled JSObjects;
*/
#pragma pack(push,1)
struct QueryResult : public MsgData {
enum {
ResultFlag_CursorNotFound = 1, /* returned, with zero results, when getMore is called but the cursor id is not valid at the server. */
ResultFlag_ErrSet = 2 /* { $err : ... } is being returned */
};
long long cursorId;
int startingFrom;
int nReturned;

View File

@ -545,10 +545,6 @@
RelativePath=".\minilex.h"
>
</File>
<File
RelativePath="..\client\model.h"
>
</File>
<File
RelativePath=".\namespace.h"
>
@ -645,6 +641,22 @@
>
</File>
</Filter>
<Filter
Name="client"
>
<File
RelativePath="..\client\connpool.h"
>
</File>
<File
RelativePath="..\client\dbclient.h"
>
</File>
<File
RelativePath="..\client\model.h"
>
</File>
</Filter>
</Filter>
<Filter
Name="Resource Files"

View File

@ -123,7 +123,8 @@ public:
#include "../client/dbclient.h"
inline void replyToQuery(MessagingPort& p, Message& requestMsg,
inline void replyToQuery(int queryResultFlags,
MessagingPort& p, Message& requestMsg,
void *data, int size,
int nReturned, int startingFrom = 0,
long long cursorId = 0
@ -132,10 +133,7 @@ inline void replyToQuery(MessagingPort& p, Message& requestMsg,
b.skip(sizeof(QueryResult));
b.append(data, size);
QueryResult *qr = (QueryResult *) b.buf();
qr->_data[0] = 0;
qr->_data[1] = 0;
qr->_data[2] = 0;
qr->_data[3] = 0;
qr->resultFlags() = queryResultFlags;
qr->len = b.len();
qr->setOperation(opReply);
qr->cursorId = cursorId;
@ -149,10 +147,11 @@ inline void replyToQuery(MessagingPort& p, Message& requestMsg,
//#include "bsonobj.h"
inline void replyToQuery(MessagingPort& p, Message& requestMsg,
inline void replyToQuery(int queryResultFlags,
MessagingPort& p, Message& requestMsg,
BSONObj& responseObj)
{
replyToQuery(
replyToQuery(queryResultFlags,
p, requestMsg,
(void *) responseObj.objdata(), responseObj.objsize(), 1);
}

View File

@ -293,10 +293,7 @@ void receivedQuery(DbResponse& dbresponse, /*AbstractMessagingPort& dbMsgPort, *
msgdata = (QueryResult *) b.buf();
b.decouple();
QueryResult *qr = msgdata;
qr->_data[0] = queryError;
qr->_data[1] = 0;
qr->_data[2] = 0;
qr->_data[3] = 0;
qr->resultFlags() = QueryResult::ResultFlag_ErrSet;
qr->len = b.len();
qr->setOperation(opReply);
qr->cursorId = 0;

View File

@ -754,10 +754,7 @@ QueryResult* runQuery(Message& message, const char *ns, int ntoskip, int _ntoret
}
QueryResult *qr = (QueryResult *) b.buf();
qr->_data[0] = 0;
qr->_data[1] = 0;
qr->_data[2] = 0;
qr->_data[3] = 0;
qr->resultFlags() = 0;
qr->len = b.len();
ss << " reslen:" << b.len();
// qr->channel = 0;
@ -810,7 +807,7 @@ QueryResult* getMore(const char *ns, int ntoreturn, long long cursorid) {
if ( !cc ) {
DEV log() << "getMore: cursorid not found " << ns << " " << cursorid << endl;
cursorid = 0;
resultFlags = ResultFlag_CursorNotFound;
resultFlags = QueryResult::ResultFlag_CursorNotFound;
}
else {
start = cc->pos;

View File

@ -63,25 +63,7 @@
Note that the update field layout is very similar layout to Query.
*/
// see dbclient.h for query options enum
/* db response format
Query or GetMore: // see struct QueryResult
int resultFlags = 0;
int64 cursorID;
int startingFrom;
int nReturned;
list of marshalled JSObjects;
*/
/* the field 'resultFlags' above */
enum {
/* returned, with zero results, when getMore is called but the cursor id is not valid at the server. */
ResultFlag_CursorNotFound = 1
};
// grab struct QueryResult from:
// struct QueryOptions, QueryResult, QueryResultFlags in:
#include "../client/dbclient.h"
// for an existing query (ie a ClientCursor), send back additional information.

View File

@ -72,7 +72,7 @@ void queryOp(Message& m, MessagingPort& p) {
bool ok = runCommandAgainstRegistered(q.ns, q.query, builder);
if ( ok ) {
BSONObj x = builder.done();
replyToQuery(p, m, x);
replyToQuery(0, p, m, x);
return;
}
}
@ -91,7 +91,7 @@ void queryOp(Message& m, MessagingPort& p) {
BSONObjBuilder err;
err.append("$err", string("dbgrid ") + (e.msg.empty() ? "dbgrid assertion during query" : e.msg));
BSONObj errObj = err.done();
replyToQuery(p, m, errObj);
replyToQuery(QueryResult::ResultFlag_ErrSet, p, m, errObj);
return;
}
}
@ -99,6 +99,7 @@ void queryOp(Message& m, MessagingPort& p) {
void writeOp(int op, Message& m, MessagingPort& p) {
DbMessage d(m);
const char *ns = d.getns();
assert( *ns );
ScopedDbConnection dbcon(tempHost);
DBClientConnection &c = dbcon.conn();

View File

@ -82,14 +82,6 @@ enum Operations {
dbKillCursors = 2007
};
/*
* flags for query responses
*/
enum ReponseMsgFlags {
operationOk = 0x00,
queryError = 0x01
};
struct MsgData {
int len; /* len of the msg, including this field */
MSGID id; /* request/reply id's match... */