=== modified file 'storage/falcon/Cache.cpp' --- old/storage/falcon/Cache.cpp 2008-09-04 17:28:23 +0000 +++ new/storage/falcon/Cache.cpp 2008-09-09 20:57:57 +0000 @@ -249,7 +249,6 @@ if (bdb != NULL) bdb->incrementUseCount(ADD_HISTORY); - lockHash.unlock(); return bdb; } @@ -262,11 +261,9 @@ if (bdb->pageNumber == pageNumber) { bdb->incrementUseCount(ADD_HISTORY); - lockHash.unlock(); return bdb; } - lockHash.unlock(); return NULL; } @@ -292,8 +289,8 @@ bdb = lockFindBdbIncrementUseCount(dbb, pageNumber); if (!bdb) { - // get getFreeBuffer() locks a hash bucket to remove the candidate bdb - // if we locked out hash bucket before the call then we could have + // getFreeBuffer() locks a hash bucket to remove the candidate bdb + // if we locked our hash bucket before the call then we could have // a deadlock // thus we get the free buffer before we lock the hash bucket we will // be inserting into. This avoids a dead lock but generates a race @@ -305,15 +302,8 @@ bdbAvailable = getFreeBuffer(); /* assume we'll be inserting this new BDB. Set new page number. */ - bdbAvailable->addRef (Exclusive COMMA_ADD_HISTORY); - bdbAvailable->decrementUseCount(REL_HISTORY); - - bdbAvailable->hash = hashTable [slot]; bdbAvailable->pageNumber = pageNumber; bdbAvailable->dbb = dbb; -#ifdef COLLECT_BDB_HISTORY - bdbAvailable->initHistory(); -#endif lockHash.lock(Exclusive); bdb = findBdb(dbb, pageNumber, slot); @@ -321,6 +311,7 @@ { // we won the race so lets use the free bdb // relink into hash table + bdbAvailable->hash = hashTable [slot]; hashTable [slot] = bdbAvailable; lockHash.unlock(); @@ -345,19 +336,19 @@ } else { - // lost a race. put our available back to useable - // side effect, bdbAvailable will have to age again before we re-use it. - bdbAvailable->hash = NULL; - bdbAvailable->pageNumber = -1; - bdbAvailable->dbb = NULL; - bdbAvailable->release(); - //syncObject.validateExclusive("Cache::fetchPage (retry)"); bdb->incrementUseCount(ADD_HISTORY); lockHash.unlock(); bdb->addRef(lockType COMMA_ADD_HISTORY); bdb->decrementUseCount(REL_HISTORY); moveToHead(bdb); + + // lost a race. put our available back to useable + // side effect, bdbAvailable will have to age again before we re-use it. + bdbAvailable->hash = NULL; + bdbAvailable->pageNumber = -1; + bdbAvailable->dbb = NULL; + bdbAvailable->release(REL_HISTORY); } } else @@ -378,7 +369,7 @@ if (pageType && page->pageType != pageType) { /*** future code - bdb->release(); + bdb->release(REL_HISTORY); throw SQLError (DATABASE_CORRUPTION, "page %d wrong page type, expected %d got %d\n", pageNumber, pageType, page->pageType); ***/ @@ -406,8 +397,8 @@ bdb = lockFindBdbIncrementUseCount(dbb, pageNumber); if (!bdb) { - // get getFreeBuffer() locks a hash bucket to remove the candidate bdb - // if we locked out hash bucket before the call then we could have + // getFreeBuffer() locks a hash bucket to remove the candidate bdb + // if we locked our hash bucket before the call then we could have // a deadlock // thus we get the free buffer before we lock the hash bucket we will // be inserting into. This avoids a dead lock but generates a race @@ -419,15 +410,8 @@ bdbAvailable = getFreeBuffer(); /* assume we'll be inserting this new BDB. Set new page number. */ - bdbAvailable->addRef (Exclusive COMMA_ADD_HISTORY); - bdbAvailable->decrementUseCount(REL_HISTORY); - - bdbAvailable->hash = hashTable [slot]; bdbAvailable->pageNumber = pageNumber; bdbAvailable->dbb = dbb; -#ifdef COLLECT_BDB_HISTORY - bdbAvailable->initHistory(); -#endif lockHash.lock(Exclusive); bdb = findBdb(dbb, pageNumber, slot); @@ -435,6 +419,7 @@ { // we won the race so lets use the free bdb // relink into hash table + bdbAvailable->hash = hashTable [slot]; hashTable [slot] = bdbAvailable; lockHash.unlock(); @@ -442,19 +427,19 @@ } else { - // lost a race. put our available back to useable - // side effect, bdbAvailable will have to age again before we re-use it. - bdbAvailable->hash = NULL; - bdbAvailable->pageNumber = -1; - bdbAvailable->dbb = NULL; - bdbAvailable->release(); - //syncObject.validateExclusive("Cache::fetchPage (retry)"); bdb->incrementUseCount(ADD_HISTORY); lockHash.unlock(); bdb->addRef(Exclusive COMMA_ADD_HISTORY); bdb->decrementUseCount(REL_HISTORY); moveToHead(bdb); + + // lost a race. put our available back to useable + // side effect, bdbAvailable will have to age again before we re-use it. + bdbAvailable->hash = NULL; + bdbAvailable->pageNumber = -1; + bdbAvailable->dbb = NULL; + bdbAvailable->release(REL_HISTORY); } } else @@ -617,9 +602,15 @@ break; } #ifdef CHECK_STALLED_BDB - bdb->stallCount = 0; + bdb->stallCount = 0; #endif // CHECK_STALLED_BDB +#ifdef COLLECT_BDB_HISTORY + bdb->initHistory(); +#endif + bdb->addRef (Exclusive COMMA_ADD_HISTORY); + bdb->decrementUseCount(REL_HISTORY); + return bdb; } @@ -826,7 +817,6 @@ { if (bdb->isDirty) { - lockHash.unlock(); markClean (bdb); } @@ -860,10 +850,8 @@ for (Bdb *bdb = firstDirty; bdb; bdb = bdb->nextDirty) if (bdb->dbb == dbb) { - dirtyLock.unlock(); return true; } - dirtyLock.unlock(); return false; }