From 8a66ac7a48e608c2939817d826af355e698a880c Mon Sep 17 00:00:00 2001 From: Dwight Date: Thu, 28 Feb 2008 13:38:56 -0500 Subject: [PATCH 1/2] ntoreturn < 0 for no wantMore --- db/query.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/db/query.cpp b/db/query.cpp index 92c80ed8bfc..0c2bf038890 100644 --- a/db/query.cpp +++ b/db/query.cpp @@ -458,9 +458,17 @@ done: int nCaught = 0; -QueryResult* runQuery(const char *ns, int ntoskip, int ntoreturn, JSObj jsobj, - auto_ptr< set > filter, stringstream& ss) { - ss << "query:" << ns << " ntoreturn:" << ntoreturn; +QueryResult* runQuery(const char *ns, int ntoskip, int _ntoreturn, JSObj jsobj, + auto_ptr< set > filter, stringstream& ss) +{ + bool wantMore = true; + int ntoreturn = _ntoreturn; + if( _ntoreturn < 0 ) { + ntoreturn = -_ntoreturn; + wantMore = false; + } + + ss << "query:" << ns << " _ntoreturn:" << _ntoreturn; if( ntoskip ) ss << " ntoskip:" << ntoskip; if( jsobj.objsize() > 100 ) ss << " querysz:" << jsobj.objsize(); @@ -539,7 +547,7 @@ assert( debug.getN() < 5000 ); if( (ntoreturn>0 && (n >= ntoreturn || b.len() > 16*1024*1024)) || (ntoreturn==0 && b.len()>1*1024*1024) ) { /* if only 1 requested, no cursor saved for efficiency...we assume it is findOne() */ - if( ntoreturn != 1 ) { + if( wantMore && ntoreturn != 1 ) { // more...so save a cursor ClientCursor *cc = new ClientCursor(); cc->c = c; From 225d58f88ee2233ef868ef570228bcbe52735dd1 Mon Sep 17 00:00:00 2001 From: Dwight Date: Thu, 28 Feb 2008 16:29:31 -0500 Subject: [PATCH 2/2] granular indexing assertion catch. --- db/pdfile.cpp | 71 ++++++++++++++++++++++----------------------------- 1 file changed, 30 insertions(+), 41 deletions(-) diff --git a/db/pdfile.cpp b/db/pdfile.cpp index 90cebcfc11f..6f5c45e7ced 100644 --- a/db/pdfile.cpp +++ b/db/pdfile.cpp @@ -406,7 +406,13 @@ void _unindexRecord(const char *ns, IndexDetails& id, JSObj& obj, const DiskLoc& cout << "\n unindex:" << j.toString() << endl; } nUnindexes++; - bool ok = id.head.btree()->unindex(id.head, ns, j, dl); + bool ok = false; + try { + ok = id.head.btree()->unindex(id.head, ns, j, dl); + } + catch(AssertionException) { + cout << " caught assertion _unindexRecord " << id.indexNamespace() << '\n'; + } #if defined(_WIN32) id.head.btree()->fullValidate(id.head); @@ -416,7 +422,6 @@ void _unindexRecord(const char *ns, IndexDetails& id, JSObj& obj, const DiskLoc& cout << " obj:" << obj.toString() << '\n'; cout << " key:" << j.toString() << '\n'; cout << " dl:" << dl.toString() << endl; - //id.head.btree()->unindex(id.head, ns, j, dl); } } } @@ -516,36 +521,28 @@ void DataFileMgr::update( vector removed; setDifference(oldkeys, newkeys, removed); string idxns = idx.indexNamespace(); - for( unsigned i = 0; i < removed.size(); i++ ) { - idx.head.btree()->unindex(idx.head, idxns.c_str(), *removed[i], dl); + for( unsigned i = 0; i < removed.size(); i++ ) { + try { + idx.head.btree()->unindex(idx.head, idxns.c_str(), *removed[i], dl); + } + catch(AssertionException) { + cout << " caught assertion update unindex " << idxns.c_str() << '\n'; + } } vector added; setDifference(newkeys, oldkeys, added); assert( !dl.isNull() ); for( unsigned i = 0; i < added.size(); i++ ) { - idx.head.btree()->insert( - idx.head, idxns.c_str(), - dl, *added[i], false, idx, true); + try { + idx.head.btree()->insert( + idx.head, idxns.c_str(), + dl, *added[i], false, idx, true); + } + catch(AssertionException) { + cout << " caught assertion update index " << idxns.c_str() << '\n'; + } } -/* - JSObjBuilder b1,b2; - JSObj kNew = newObj.extractFields(idxKey, b1); - JSObj kOld = oldObj.extractFields(idxKey, b2); - if( !kNew.woEqual(kOld) ) { - cout << " updating index, key changed " << idx.indexNamespace() << endl; - // delete old key - if( !kOld.isEmpty() ) - idx.head.btree()->unindex(kOld); - // add new key - if( !kNew.isEmpty() ) { - idx.head.btree()->insert( - idx.head, - idx.indexNamespace().c_str(), - dl, kNew, false, idx); - } - } -*/ } } } @@ -578,27 +575,19 @@ int followupExtentSize(int len, int lastExtentLen) { /* add keys to indexes for a new record */ void _indexRecord(IndexDetails& idx, JSObj& obj, DiskLoc newRecordLoc) { -// cout << "temp: " << obj.toString() << endl; set keys; idx.getKeysFromObject(obj, keys); for( set::iterator i=keys.begin(); i != keys.end(); i++ ) { -// cout << "temp: _indexRecord " << i->toString() << endl; + // cout << "temp: _indexRecord " << i->toString() << endl; assert( !newRecordLoc.isNull() ); - idx.head.btree()->insert(idx.head, idx.indexNamespace().c_str(), newRecordLoc, - (JSObj&) *i, false, idx, true); + try { + idx.head.btree()->insert(idx.head, idx.indexNamespace().c_str(), newRecordLoc, + (JSObj&) *i, false, idx, true); + } + catch(AssertionException) { + cout << " caught assertion _indexRecord " << idx.indexNamespace() << '\n'; + } } -/* - JSObj idxInfo = idx.info.obj(); - JSObjBuilder b; - JSObj key = obj.extractFields(idxInfo.getObjectField("key"), b); - if( !key.isEmpty() ) { - cout << "_indexRecord " << key.toString() << endl; - idx.head.btree()->insert( - idx.head, - idx.indexNamespace().c_str(), - newRecordLoc, key, false, idx); - } -*/ } /* note there are faster ways to build an index in bulk, that can be