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

latent cursor checkUnused bug

This commit is contained in:
Dwight 2008-02-12 10:12:07 -05:00
parent f6c30d15f0
commit 33b635ea54
4 changed files with 53 additions and 7 deletions

View File

@ -706,16 +706,43 @@ void BtreeCursor::noteLocation() {
/* see if things moved around (deletes, splits, inserts) */
void BtreeCursor::checkLocation() {
if( eof() || bucket.btree()->keyAt(keyOfs).woEqual(keyAtKeyOfs) )
return;
cout << " key seems to have moved in the index, refinding it" << endl;
try {
if( eof() )
return;
BtreeBucket *b = bucket.btree();
if( b->keyAt(keyOfs).woEqual(keyAtKeyOfs) &&
b->k(keyOfs).isUsed()
)
return;
}
catch( AssertionException ) {
cout << "Caught exception in checkLocation(), that's maybe ok" << endl;
}
bool found;
DiskLoc bold = bucket;
/* probably just moved in our node, so to be fast start from here rather than the head */
bucket = bucket.btree()->locate(bucket, keyAtKeyOfs, keyOfs, found, direction);
if( found || bucket.btree()->isHead() )
if( found || bucket.btree()->isHead() ) {
cout << " key seems to have moved in the index, refinding. found:" << found << endl;
checkUnused();
/*
if( found && !bucket.btree()->k(keyOfs).isUsed() ) {
cout << " " << keyAtKeyOfs.toString() << endl;
cout << " " << keyOfs << endl;
cout << " " << bucket.btree()->keyNode(keyOfs).key.toString() << endl;
cout << " " << bucket.btree()->keyNode(keyOfs).recordLoc.toString() << endl;
bucket.btree()->dump();
assert(false);
}
*/
return;
}
/* didn't find, check from the top */
DiskLoc head = bold.btree()->getHead(bold);
head.btree()->locate(head, keyAtKeyOfs, keyOfs, found);
cout << " key seems to have moved in the index, refinding. found:" << found << endl;
if( found )
checkUnused();
// assert( !found || bucket.btree()->k(keyOfs).isUsed() );
}

View File

@ -116,7 +116,11 @@ public:
JSObj& key, bool dupsAllowed, IndexDetails& idx, bool toplevel);
void update(const DiskLoc& recordLoc, JSObj& key);
bool unindex(const DiskLoc& thisLoc, const char *ns, JSObj& key, const DiskLoc& recordLoc);
/* locate may return an "unused" key that is just a marker. so be careful.
*/
DiskLoc locate(const DiskLoc& thisLoc, JSObj& key, int& pos, bool& found, int direction=1);
/* advance one key position in the index: */
DiskLoc advance(const DiskLoc& thisLoc, int& keyOfs, int direction, const char *caller);
DiskLoc getHead(const DiskLoc& thisLoc);

View File

@ -52,13 +52,17 @@ ClientCursor::~ClientCursor() {
}
void ClientCursor::updateLocation() {
DiskLoc cl = c->currLoc();
cout<< " TEMP: updateLocation last:" << lastLoc.toString() << " cl:" << cl.toString() << '\n';
if( !lastLoc.isNull() ) {
int n = cursorsByLocation.erase(lastLoc);
assert( n == 1 );
}
if( !c->currLoc().isNull() )
cursorsByLocation[c->currLoc()] = this;
lastLoc = c->currLoc();
if( !cl.isNull() )
cursorsByLocation[cl] = this;
lastLoc = cl;
c->noteLocation();
}

View File

@ -148,7 +148,16 @@ void deleteObjects(const char *ns, JSObj pattern, bool justOne) {
auto_ptr<Cursor> c = getIndexCursor(ns, pattern, order);
if( c.get() == 0 )
c = theDataFileMgr.findAll(ns);
Cursor &tempDebug = *c;
int temp = 0;
int tempd = 0;
DiskLoc _tempDelLoc;
while( c->ok() ) {
temp++;
Record *r = c->_current();
DiskLoc rloc = c->currLoc();
c->advance(); // must advance before deleting as the next ptr will die
@ -163,7 +172,9 @@ void deleteObjects(const char *ns, JSObj pattern, bool justOne) {
// cout << " found match to delete" << endl;
if( !justOne )
c->noteLocation();
_tempDelLoc = rloc;
theDataFileMgr.deleteRecord(ns, r, rloc);
tempd = temp;
if( justOne )
return;
c->checkLocation();