Index: lsm-test/lsmtest_main.c ================================================================== --- lsm-test/lsmtest_main.c +++ lsm-test/lsmtest_main.c @@ -1,6 +1,7 @@ +#include #include "lsmtest.h" #include "stdio.h" #include "assert.h" #include "string.h" #include "stdlib.h" Index: src/btInt.h ================================================================== --- src/btInt.h +++ src/btInt.h @@ -334,13 +334,11 @@ BtLock *pNext; /* Next connection using pShared */ u32 mExclLock; /* Mask of exclusive locks held */ u32 mSharedLock; /* Mask of shared locks held */ BtFile *pBtFile; /* Used to defer close if necessary */ -#ifndef NDEBUG u8 *aUsed; -#endif }; struct BtReadSlot { u32 iFirst; u32 iLast; Index: src/bt_main.c ================================================================== --- src/bt_main.c +++ src/bt_main.c @@ -1146,15 +1146,15 @@ static int btCsrStep(BtCursor *pCsr, int bNext){ const int pgsz = sqlite4BtPagerPagesize(pCsr->base.pDb->pPager); int rc = SQLITE4_OK; int bRequireDescent = 0; - pCsr->ovfl.nKey = 0; rc = btCsrReseek(pCsr); if( rc==SQLITE4_OK && pCsr->nPg==0 ){ rc = SQLITE4_NOTFOUND; } + pCsr->ovfl.nKey = 0; if( (pCsr->bSkipNext && bNext) || (pCsr->bSkipPrev && bNext==0) ){ pCsr->bSkipPrev = pCsr->bSkipNext = 0; return rc; } @@ -4731,17 +4731,19 @@ ){ u32 pgno = sqlite4BtPagePgno(pSub->apPage[pSub->nPg-1]); int iCell = pSub->aiCell[pSub->nPg-1]; if( p->aTrunk==0 ){ + assert( p->nOvfl==0 ); rc = btNewBuffer(p->db, &p->aTrunk); if( rc==SQLITE4_OK ) memset(p->aTrunk, 0, 8); - assert( p->nOvfl==0 ); }else if( p->nOvflPerPage==p->nOvfl ){ rc = fiWriterFlushOvfl(p, 0); + assert( p->nOvfl==0 ); } if( rc==SQLITE4_OK ){ + assert( p->nOvflnOvflPerPage ); btPutU32(&p->aTrunk[8 + p->nOvfl*8], pgno); btPutU32(&p->aTrunk[8 + p->nOvfl*8 + 4], iCell); p->nOvfl++; } } @@ -4948,10 +4950,11 @@ btCheckPageRefs(db); db->bFastInsertOp = 0; return rc; } +#ifndef NDEBUG void sqlite4BtDebugTree(bt_db *db, int iCall, u32 iRoot){ BtPage *pPg; sqlite4_buffer buf; int pgsz; @@ -4984,10 +4987,11 @@ iSubRoot = btGetU32((const u8*)pK); sqlite4BtDebugTree(db, iCall, iSubRoot); } btCsrReset(&mcsr, 1); } +#endif /* ifndef NDEBUG */ /* ** Delete the entry that the cursor currently points to. */ @@ -5214,12 +5218,10 @@ } return rc; } -#ifndef NDEBUG - static void markBlockAsUsed( bt_db *db, u32 iBlk, u8 *aUsed ){ @@ -5411,10 +5413,7 @@ } } return SQLITE4_OK; } -#endif - - Index: src/bt_pager.c ================================================================== --- src/bt_pager.c +++ src/bt_pager.c @@ -377,13 +377,15 @@ for(i=p->nSavepoint-1; i>=nReq; i--){ BtSavepoint *pSavepoint = &p->aSavepoint[i]; BtSavepage *pSavepg; BtSavepage *pNext; - /* Restore the BtDbHdr object to the state it was in at the start of - ** this savepoint. */ - memcpy(p->pHdr, &pSavepoint->hdr, sizeof(BtDbHdr)); + /* If this is a rollback operation, restore the BtDbHdr object to the + ** state it was in at the start of this savepoint. */ + if( bRollback ){ + memcpy(p->pHdr, &pSavepoint->hdr, sizeof(BtDbHdr)); + } /* Loop through each of the BtSavepage objects associated with this ** savepoint. Detach them from the BtPage objects and free all ** allocated memory. */ for(pSavepg=pSavepoint->pSavepage; pSavepg; pSavepg=pNext){ @@ -434,13 +436,16 @@ /* ** Close a pager database handle. */ int sqlite4BtPagerClose(BtPager *p){ int rc; + + if( p->btl.pFd ){ + sqlite4BtPagerRollback(p, 0); + } rc = sqlite4BtLockDisconnect((BtLock*)p, btCheckpoint, btCleanup); - p->iTransactionLevel = 0; btCloseSavepoints(p, 0, 0); btPurgeCache(p); sqlite4BtLogClose(p->pLog, 0); sqlite4_free(p->btl.pEnv, p->zFile); @@ -822,10 +827,11 @@ if( rc==SQLITE4_OK ){ pRet->pgno = pgno; if( pgno<=p->pHdr->nPg ){ rc = btLoadPageData(p, pRet); }else{ + assert( p->iTransactionLevel>=2 ); memset(pRet->aData, 0, p->pHdr->pgsz); } if( rc==SQLITE4_OK ){ rc = btHashAdd(p, pRet); Index: test/manydb.test ================================================================== --- test/manydb.test +++ test/manydb.test @@ -16,11 +16,11 @@ # $Id: manydb.test,v 1.4 2008/11/21 00:10:35 aswift Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl -set N 300 +set N 200 set num_fd_per_openwrite_db 4 # First test how many file descriptors are available for use. To open a # database for writing SQLite requires 3 file descriptors (the database, the # journal and the directory). Index: test/src4.test ================================================================== --- test/src4.test +++ test/src4.test @@ -13,5 +13,6 @@ run_test_suite src4 run_test_suite bt finish_test +