stuff
This commit is contained in:
parent
9e15413679
commit
5380b6e591
16
db/db.cpp
16
db/db.cpp
@ -36,7 +36,8 @@ void pdfileInit();
|
||||
class DbMessage {
|
||||
public:
|
||||
DbMessage(Message& _m) : m(_m) {
|
||||
int *r = (int *) _m.data;
|
||||
theEnd = _m.data->_data + _m.data->dataLen();
|
||||
int *r = (int *) _m.data->_data;
|
||||
reserved = *r;
|
||||
r++;
|
||||
data = (const char *) r;
|
||||
@ -67,8 +68,11 @@ public:
|
||||
JSObj js(nextjsobj);
|
||||
if( js.size <= 4 )
|
||||
nextjsobj = null;
|
||||
else
|
||||
else {
|
||||
nextjsobj += js.size;
|
||||
if( nextjsobj >= theEnd )
|
||||
nextjsobj = 0;
|
||||
}
|
||||
return js;
|
||||
}
|
||||
|
||||
@ -77,6 +81,7 @@ private:
|
||||
int reserved;
|
||||
const char *data;
|
||||
const char *nextjsobj;
|
||||
const char *theEnd;
|
||||
};
|
||||
|
||||
Record* findByOID(const char *ns, OID *oid) {
|
||||
@ -103,7 +108,7 @@ void updateByOID(const char *ns, char *objdata, int objsize, OID *oid) {
|
||||
cout << "ERROR: updateByOID: growing records not implemented yet." << endl;
|
||||
return;
|
||||
}
|
||||
/* note: need to be smarter if it gets a lot smaller??? */
|
||||
/* note: need to be smarter if it gets a lot smaller? */
|
||||
/* this really dumb for now as it gets smaller but doesn't allow regrowth
|
||||
to the original size! */
|
||||
memcpy(r->data, objdata, objsize);
|
||||
@ -146,6 +151,7 @@ void dbinsert(Message& m) {
|
||||
DbMessage d(m);
|
||||
while( d.moreJSObjs() ) {
|
||||
JSObj js = d.nextJsObj();
|
||||
cout << " temp dbinsert: got js object, size=" << js.objsize() << " ns:" << d.getns() << endl;
|
||||
if( m.data->operation == dbInsert ) {
|
||||
theDataFileMgr.insert(d.getns(), (void*) js.objdata(), js.objsize());
|
||||
} else {
|
||||
@ -164,7 +170,7 @@ void run() {
|
||||
|
||||
pdfileInit();
|
||||
|
||||
theDataFileMgr.insert("sys.unittest.pdfile", "hello world", 12);
|
||||
theDataFileMgr.insert("sys.unittest.pdfile", (void *) "hello world", 12);
|
||||
cout << "findAll:\n";
|
||||
Cursor c = theDataFileMgr.findAll("sys.unittest.pdfile");
|
||||
while( c.ok() ) {
|
||||
@ -209,7 +215,7 @@ void run() {
|
||||
cout << "dbGetMore: not implemented!" << endl;
|
||||
}
|
||||
else {
|
||||
cout << " operation isn't supported (???)" << endl;
|
||||
cout << " operation isn't supported ?" << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
29
db/jsobj.h
29
db/jsobj.h
@ -61,34 +61,7 @@ struct OID {
|
||||
int reserved;
|
||||
string collection;
|
||||
a series of JSObjects terminated with a null object (i.e., just EOO)
|
||||
GetByOID:
|
||||
int reserved;
|
||||
string collection;
|
||||
OID oid;
|
||||
Query:
|
||||
int reserved;
|
||||
string collection;
|
||||
unsigned nToReturn; // how many you want back as the beginning of the cursor data
|
||||
string query;
|
||||
GetMore:
|
||||
int reserved;
|
||||
unsigned cursorID;
|
||||
unsigned nToReturn;
|
||||
|
||||
byte EOM
|
||||
*/
|
||||
|
||||
/* db response format
|
||||
|
||||
GetByOID operation:
|
||||
marshalled JSObject returned. always specified, even if an error.
|
||||
|
||||
Query or GetMore: see query.h
|
||||
int reserved;
|
||||
unsigned cursorID;
|
||||
unsigned startOfs;
|
||||
unsigned nReturned;
|
||||
list of marshalled JSObjects;
|
||||
Query: see query.h
|
||||
*/
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
@ -40,7 +40,7 @@ QueryResult* runQuery(const char *ns, const char *query, int ntoreturn) {
|
||||
qr->reserved = 0;
|
||||
qr->operation = opReply;
|
||||
qr->cursorId = nextCursorId++;
|
||||
qr->startOfs = 0;
|
||||
qr->startingFrom = 0;
|
||||
qr->nReturned = n;
|
||||
b.decouple();
|
||||
|
||||
|
||||
26
db/query.h
26
db/query.h
@ -5,18 +5,32 @@
|
||||
#include "../stdafx.h"
|
||||
#include "../grid/message.h"
|
||||
|
||||
/*
|
||||
/* requests:
|
||||
|
||||
Query:
|
||||
int reserved;
|
||||
string collection;
|
||||
int nToReturn; // how many you want back as the beginning of the cursor data
|
||||
JSObject query;
|
||||
GetMore:
|
||||
int reserved;;
|
||||
int64 cursorID;
|
||||
int nToReturn;
|
||||
*/
|
||||
|
||||
/* db response format
|
||||
|
||||
Query or GetMore:
|
||||
int reserved;
|
||||
unsigned cursorID;
|
||||
unsigned startOfs;
|
||||
unsigned nReturned;
|
||||
int64 cursorID;
|
||||
int startingFrom;
|
||||
int nReturned;
|
||||
list of marshalled JSObjects;
|
||||
*/
|
||||
|
||||
struct QueryResult : public MsgData {
|
||||
int cursorId;
|
||||
int startOfs;
|
||||
long long cursorId;
|
||||
int startingFrom;
|
||||
int nReturned;
|
||||
char data[4];
|
||||
};
|
||||
|
||||
@ -6,10 +6,58 @@
|
||||
|
||||
class BufBuilder {
|
||||
public:
|
||||
void skip(int n) { }
|
||||
char* buf() { return 0; }
|
||||
void decouple() { }
|
||||
void append(int) { }
|
||||
void append(void *, int len) { }
|
||||
int len() { return 0; }
|
||||
BufBuilder(int initsize = 32768) : size(initsize) {
|
||||
data = (char *) malloc(size);
|
||||
l = 0;
|
||||
}
|
||||
~BufBuilder() {
|
||||
if( data ) {
|
||||
free(data);
|
||||
data = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* leave room for some stuff later */
|
||||
void skip(int n) { grow(n); }
|
||||
|
||||
/* note this may be deallocated (realloced) if you keep writing. */
|
||||
char* buf() { return data; }
|
||||
|
||||
/* assume ownership of the buffer - you must then free it */
|
||||
void decouple() { data = 0; }
|
||||
|
||||
template<class T> void append(T j) { *((T*)grow(sizeof(T))) = j; }
|
||||
void append(short j) { append<short>(j); }
|
||||
void append(int j) { append<int>(j); }
|
||||
void append(unsigned j) { append<unsigned>(j); }
|
||||
void append(bool j) { append<bool>(j); }
|
||||
void append(double j) { append<double>(j); }
|
||||
|
||||
void append(void *src, int len) { memcpy(grow(len), src, len); }
|
||||
|
||||
void append(const char *str) {
|
||||
append((void*) str, strlen(str)+1);
|
||||
}
|
||||
|
||||
int len() { return l; }
|
||||
|
||||
private:
|
||||
/* returns the pre-grow write position */
|
||||
char* grow(int by) {
|
||||
int oldlen = l;
|
||||
l += by;
|
||||
if( l > size ) {
|
||||
int a = size * 2;
|
||||
if( l > a )
|
||||
a = l + 16 * 1024;
|
||||
assert( a < 64 * 1024 * 1024 );
|
||||
data = (char *) realloc(data, a);
|
||||
size= a;
|
||||
}
|
||||
return data + oldlen;
|
||||
}
|
||||
|
||||
char *data;
|
||||
int l;
|
||||
int size;
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user