diff --git a/manifest b/manifest index d7699b7c1c..26524642a9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Changes\sto\stest\sscripts\sto\ssupport\srunning\son\ssymbian.\s(CVS\s5714) -D 2008-09-17T16:14:10 +C Speed\simprovements\sfor\sin-memory\sdatabases\sby\somitting\sflag\sclearing\son\spages\nwhere\sit\sis\simpossible\sfor\sthe\sflag\sto\sbe\sset\sand\sby\savoiding\sassert()s\son\nnon-debugging\sbuilds.\s\sTicket\s#3384.\s(CVS\s5715) +D 2008-09-17T20:06:26 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in d15a7ebfe5e057a72a49805ffb302dbb601c8329 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -137,11 +137,11 @@ F src/os_common.h 24525d8b7bce66c374dfc1810a6c9043f3359b60 F src/os_os2.c e391fc95adc744bbdcefd4d11e3066998185a0a0 F src/os_unix.c 8f4def6a92681735908fa1b87b5cc0291ebafde6 F src/os_win.c 3209dc0ed734291764393ea8d534ba0d8696a540 -F src/pager.c f21654d1fcfd62ce058dbb88d07159745dc5bd84 +F src/pager.c 34318b85cead25e179a6ff83092c79d6dcecb2fd F src/pager.h c45380ca9d0933ea5bc4ecb3a43958b6d2ec5a9c F src/parse.y d0f76d2cb8d6883d5600dc20beb961a6022b94b8 -F src/pcache.c a39908e73cf5001dec2cc7a55a477fe8e8611db9 -F src/pcache.h 53730c33310cdf7a5c94e8333c853d59a3b30226 +F src/pcache.c c799d753a5d4b913961a4fe66c8a7c706b04d28d +F src/pcache.h deddea69babf3e0931b11eea3bf5c9e33a654389 F src/pragma.c e633b6b7dabc110e2abfed4e35ba34a4039cb65c F src/prepare.c c7e00ed1b0bdcf699b1aad651247d4dc3d281b0b F src/printf.c 785f87120589c1db672e37c6eb1087c456e6f84d @@ -637,7 +637,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P 94fde77b9a4efde5f7fb2a84fedaf38b0ebbac70 -R 5cb1f4f412c11fd992c399fc6668cf38 -U danielk1977 -Z f12860bdb96f15ad02a57af76d19c3b1 +P 6ef34e9d3118965781c69011deaede1ebbb19b12 +R a27713f2ccd1c6c2e7e56fb7534b72ec +U drh +Z ee142ff5e27b59538a7c71659e26324f diff --git a/manifest.uuid b/manifest.uuid index 49f28380e0..7992787902 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6ef34e9d3118965781c69011deaede1ebbb19b12 \ No newline at end of file +a7fd9e622bc1050e78f227ec42b6ba90c87c865a \ No newline at end of file diff --git a/src/pager.c b/src/pager.c index cb2f3849ba..51fafebd7d 100644 --- a/src/pager.c +++ b/src/pager.c @@ -18,7 +18,7 @@ ** file simultaneously, or one process from reading the database while ** another is writing. ** -** @(#) $Id: pager.c,v 1.490 2008/09/16 05:12:24 danielk1977 Exp $ +** @(#) $Id: pager.c,v 1.491 2008/09/17 20:06:26 drh Exp $ */ #ifndef SQLITE_OMIT_DISKIO #include "sqliteInt.h" @@ -994,8 +994,8 @@ static int pager_end_transaction(Pager *pPager, int hasMaster){ #ifdef SQLITE_CHECK_PAGES sqlite3PcacheIterate(pPager->pPCache, pager_set_pagehash); #endif - sqlite3PcacheSetFlags(pPager->pPCache, - ~(PGHDR_IN_JOURNAL | PGHDR_NEED_SYNC), 0 + sqlite3PcacheClearFlags(pPager->pPCache, + PGHDR_IN_JOURNAL | PGHDR_NEED_SYNC ); pPager->dirtyCache = 0; pPager->nRec = 0; @@ -1663,7 +1663,7 @@ void sqlite3PagerSetCachesize(Pager *pPager, int mxPage){ */ #ifndef SQLITE_OMIT_PAGER_PRAGMAS void sqlite3PagerSetSafetyLevel(Pager *pPager, int level, int bFullFsync){ - pPager->noSync = level==1 || pPager->tempFile; + pPager->noSync = level==1 || pPager->tempFile || MEMDB; pPager->fullSync = level==3 && !pPager->tempFile; pPager->sync_flags = (bFullFsync?SQLITE_SYNC_FULL:SQLITE_SYNC_NORMAL); if( pPager->noSync ) pPager->needSync = 0; @@ -1761,6 +1761,7 @@ int sqlite3PagerOpen( if( strcmp(zFilename,":memory:")==0 ){ memDb = 1; zPathname[0] = 0; + useJournal = 0; }else #endif { @@ -1885,7 +1886,7 @@ int sqlite3PagerOpen( } /* pPager->journalOpen = 0; */ - pPager->useJournal = useJournal && !memDb; + pPager->useJournal = useJournal; pPager->noReadlock = noReadlock && readOnly; /* pPager->stmtOpen = 0; */ /* pPager->stmtInUse = 0; */ @@ -2322,8 +2323,7 @@ static int syncJournal(Pager *pPager){ /* Erase the needSync flag from every page. */ - sqlite3PcacheSetFlags(pPager->pPCache, ~PGHDR_NEED_SYNC, 0); - /* lruListSetFirstSynced(pPager); */ + sqlite3PcacheClearFlags(pPager->pPCache, PGHDR_NEED_SYNC); } #ifndef NDEBUG @@ -2333,7 +2333,6 @@ static int syncJournal(Pager *pPager){ */ else{ sqlite3PcacheAssertFlags(pPager->pPCache, 0, PGHDR_NEED_SYNC); - /* assert( pPager->lru.pFirstSynced==pPager->lru.pFirst ); */ } #endif @@ -2411,11 +2410,9 @@ static int pager_write_pagelist(PgHdr *pList){ #ifdef SQLITE_CHECK_PAGES pList->pageHash = pager_pagehash(pList); #endif - /* makeClean(pList); */ pList = pList->pDirty; } - /* sqlite3PcacheCleanAll(pPager->pPCache); */ return SQLITE_OK; } @@ -2845,6 +2842,7 @@ static int pagerAcquire( PAGER_INCR(pPager->nMiss); pPg->pPager = pPager; if( sqlite3BitvecTest(pPager->pInJournal, pgno) ){ + assert( !MEMDB ); pPg->flags |= PGHDR_IN_JOURNAL; } memset(pPg->pExtra, 0, pPager->nExtra); @@ -3393,6 +3391,7 @@ int sqlite3PagerWrite(DbPage *pDbPage){ ** before any of them can be written out to the database file. */ if( needSync ){ + assert( !MEMDB && pPager->noSync==0 ); for(ii=0; iiflags |= PGHDR_NEED_SYNC; @@ -3805,9 +3804,7 @@ int sqlite3PagerCommitPhaseTwo(Pager *pPager){ if( MEMDB ){ sqlite3PcacheCommit(pPager->pPCache, 0); sqlite3PcacheCleanAll(pPager->pPCache); - sqlite3PcacheSetFlags(pPager->pPCache, - ~(PGHDR_IN_JOURNAL | PGHDR_NEED_SYNC), 0 - ); + sqlite3PcacheAssertFlags(pPager->pPCache, 0, PGHDR_IN_JOURNAL); pPager->state = PAGER_SHARED; }else{ assert( pPager->state==PAGER_SYNCED || !pPager->dirtyCache ); @@ -3836,9 +3833,7 @@ int sqlite3PagerRollback(Pager *pPager){ sqlite3PcacheRollback(pPager->pPCache, 1); sqlite3PcacheRollback(pPager->pPCache, 0); sqlite3PcacheCleanAll(pPager->pPCache); - sqlite3PcacheSetFlags(pPager->pPCache, - ~(PGHDR_IN_JOURNAL | PGHDR_NEED_SYNC), 0 - ); + sqlite3PcacheAssertFlags(pPager->pPCache, 0, PGHDR_IN_JOURNAL); pPager->dbSize = pPager->origDbSize; pager_truncate_cache(pPager); pPager->stmtInUse = 0; @@ -3976,7 +3971,6 @@ int sqlite3PagerStmtCommit(Pager *pPager){ if( pPager->stmtInUse ){ PAGERTRACE2("STMT-COMMIT %d\n", PAGERID(pPager)); if( !MEMDB ){ - /* sqlite3OsTruncate(pPager->stfd, 0); */ sqlite3BitvecDestroy(pPager->pInStmt); pPager->pInStmt = 0; }else{ @@ -4077,7 +4071,7 @@ void sqlite3PagerSetCodec( ** ** There must be no references to the page previously located at ** pgno (which we call pPgOld) though that page is allowed to be -** in cache. If the page previous located at pgno is not already +** in cache. If the page previously located at pgno is not already ** in the rollback journal, it is not put there by by this routine. ** ** References to the page pPg remain valid. Updating any @@ -4132,6 +4126,7 @@ int sqlite3PagerMovepage(Pager *pPager, DbPage *pPg, Pgno pgno, int isCommit){ pPg->flags |= (pPgOld->flags&PGHDR_NEED_SYNC); } if( sqlite3BitvecTest(pPager->pInJournal, pgno) ){ + assert( !MEMDB ); pPg->flags |= PGHDR_IN_JOURNAL; } @@ -4174,6 +4169,7 @@ int sqlite3PagerMovepage(Pager *pPager, DbPage *pPg, Pgno pgno, int isCommit){ return rc; } pPager->needSync = 1; + assert( pPager->noSync==0 && !MEMDB ); pPgHdr->flags |= PGHDR_NEED_SYNC; pPgHdr->flags |= PGHDR_IN_JOURNAL; makeDirty(pPgHdr); diff --git a/src/pcache.c b/src/pcache.c index c7c7fac78f..29672095aa 100644 --- a/src/pcache.c +++ b/src/pcache.c @@ -11,7 +11,7 @@ ************************************************************************* ** This file implements that page cache. ** -** @(#) $Id: pcache.c,v 1.28 2008/09/17 11:02:57 danielk1977 Exp $ +** @(#) $Id: pcache.c,v 1.29 2008/09/17 20:06:26 drh Exp $ */ #include "sqliteInt.h" @@ -875,7 +875,6 @@ void sqlite3PcacheMove(PgHdr *p, Pgno newPgno){ pcacheRemoveFromHash(p); p->pgno = newPgno; if( newPgno==0 ){ - p->flags |= PGHDR_REUSE_UNLIKELY; pcacheFree(p->apSave[0]); pcacheFree(p->apSave[1]); p->apSave[0] = 0; @@ -883,6 +882,7 @@ void sqlite3PcacheMove(PgHdr *p, Pgno newPgno){ if( (p->flags & PGHDR_DIRTY) ){ pcacheMakeClean(p); } + p->flags = PGHDR_REUSE_UNLIKELY; } pcacheAddToHash(p); pcacheExitMutex(); @@ -1004,12 +1004,14 @@ int sqlite3PcachePreserve(PgHdr *p, int idJournal){ */ void sqlite3PcacheCommit(PCache *pCache, int idJournal){ PgHdr *p; + int mask = idJournal==0 ? ~PGHDR_IN_JOURNAL : 0xffffff; pcacheEnterMutex(); /* Mutex is required to call pcacheFree() */ for(p=pCache->pDirty; p; p=p->pNext){ if( p->apSave[idJournal] ){ pcacheFree(p->apSave[idJournal]); p->apSave[idJournal] = 0; } + p->flags &= mask; } pcacheExitMutex(); } @@ -1020,6 +1022,7 @@ void sqlite3PcacheCommit(PCache *pCache, int idJournal){ void sqlite3PcacheRollback(PCache *pCache, int idJournal){ PgHdr *p; int sz; + int mask = idJournal==0 ? ~PGHDR_IN_JOURNAL : 0xffffff; pcacheEnterMutex(); /* Mutex is required to call pcacheFree() */ sz = pCache->szPage; for(p=pCache->pDirty; p; p=p->pNext){ @@ -1028,10 +1031,12 @@ void sqlite3PcacheRollback(PCache *pCache, int idJournal){ pcacheFree(p->apSave[idJournal]); p->apSave[idJournal] = 0; } + p->flags &= mask; } pcacheExitMutex(); } +#ifndef NDEBUG /* ** Assert flags settings on all pages. Debugging only. */ @@ -1046,6 +1051,7 @@ void sqlite3PcacheAssertFlags(PCache *pCache, int trueMask, int falseMask){ assert( (p->flags&falseMask)==0 ); } } +#endif /* ** Discard the contents of the cache. @@ -1178,24 +1184,23 @@ void sqlite3PcacheIterate(PCache *pCache, void (*xIter)(PgHdr *)){ /* ** Set flags on all pages in the page cache */ -void sqlite3PcacheSetFlags(PCache *pCache, int andMask, int orMask){ +void sqlite3PcacheClearFlags(PCache *pCache, int mask){ PgHdr *p; - assert( (orMask&PGHDR_NEED_SYNC)==0 ); - /* Obtain the global mutex before modifying any PgHdr.flags variables ** or traversing the LRU list. */ pcacheEnterMutex(); + mask = ~mask; for(p=pCache->pDirty; p; p=p->pNext){ - p->flags = (p->flags&andMask)|orMask; + p->flags &= mask; } for(p=pCache->pClean; p; p=p->pNext){ - p->flags = (p->flags&andMask)|orMask; + p->flags &= mask; } - if( 0==(andMask&PGHDR_NEED_SYNC) ){ + if( 0==(mask&PGHDR_NEED_SYNC) ){ pCache->pSynced = pCache->pDirtyTail; assert( !pCache->pSynced || (pCache->pSynced->flags&PGHDR_NEED_SYNC)==0 ); } diff --git a/src/pcache.h b/src/pcache.h index f01e98b89c..3d24025ca9 100644 --- a/src/pcache.h +++ b/src/pcache.h @@ -12,7 +12,7 @@ ** This header file defines the interface that the sqlite page cache ** subsystem. ** -** @(#) $Id: pcache.h,v 1.9 2008/08/29 09:10:03 danielk1977 Exp $ +** @(#) $Id: pcache.h,v 1.10 2008/09/17 20:06:26 drh Exp $ */ #ifndef _PCACHE_H_ @@ -53,13 +53,12 @@ struct PgHdr { /* Bit values for PgHdr.flags */ #define PGHDR_IN_JOURNAL 0x001 /* Page is in rollback journal */ -#define PGHDR_IN_STMTJRNL 0x002 /* Page is in the statement journal */ -#define PGHDR_DIRTY 0x004 /* Page has changed */ -#define PGHDR_NEED_SYNC 0x008 /* Peed to fsync this page */ -#define PGHDR_NEED_READ 0x020 /* Content is unread */ -#define PGHDR_IS_INIT 0x040 /* pData is initialized */ -#define PGHDR_REUSE_UNLIKELY 0x080 /* Hint: Reuse is unlikely */ -#define PGHDR_DONT_WRITE 0x100 /* Do not write content to disk */ +#define PGHDR_DIRTY 0x002 /* Page has changed */ +#define PGHDR_NEED_SYNC 0x004 /* Fsync the rollback journal before + ** writing this page to the database */ +#define PGHDR_NEED_READ 0x008 /* Content is unread */ +#define PGHDR_REUSE_UNLIKELY 0x010 /* A hint that reuse is unlikely */ +#define PGHDR_DONT_WRITE 0x020 /* Do not write content to disk */ /* Initialize and shutdown the page cache subsystem */ int sqlite3PcacheInitialize(void); @@ -122,11 +121,15 @@ PgHdr *sqlite3PcacheDirtyList(PCache*); /* Reset and close the cache object */ void sqlite3PcacheClose(PCache*); -/* Set flags on all pages in the page cache */ -void sqlite3PcacheSetFlags(PCache*, int andMask, int orMask); +/* Clear flags from pages of the page cache */ +void sqlite3PcacheClearFlags(PCache*, int mask); /* Assert flags settings on all pages. Debugging only */ -void sqlite3PcacheAssertFlags(PCache*, int trueMask, int falseMask); +#ifndef NDEBUG + void sqlite3PcacheAssertFlags(PCache*, int trueMask, int falseMask); +#else +# define sqlite3PcacheAssertFlags(A,B,C) +#endif /* Return true if the number of dirty pages is 0 or 1 */ int sqlite3PcacheZeroOrOneDirtyPages(PCache*);