diff --git a/manifest b/manifest index 29c6ab584d..5e2dbfc2b3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\sthe\sfilefmt.test\stest\sscript\sto\sconform\sto\sthe\sprevious\scheck-in.\s(CVS\s6781) -D 2009-06-18T11:34:43 +C Move\scodec\smanagement\sfrom\sdatabase\sconnections\sinto\sthe\spager\sso\sthat\sit\nwill\swork\stogether\swith\sshared\scache.\s(CVS\s6782) +D 2009-06-18T17:22:39 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in 8b8fb7823264331210cddf103831816c286ba446 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -106,10 +106,10 @@ F src/auth.c 98db07c2088455797678eb1031f42d4d94d18a71 F src/backup.c ff50af53184a5fd7bdee4d620b5dabef74717c79 F src/bitvec.c 0ef0651714728055d43de7a4cdd95e703fac0119 F src/btmutex.c 9b899c0d8df3bd68f527b0afe03088321b696d3c -F src/btree.c 067ad47d83912806c4ca6dff16eda544d3dc3952 +F src/btree.c 0fbea81d1efef20d440179d7092e594432153f60 F src/btree.h f70b694e8c163227369a66863b01fbff9009f323 F src/btreeInt.h 122021a7d70633b389c447d9a05f9242f410809d -F src/build.c 75b57e3f4de1b34d4e1e49d350dc87febff48ba0 +F src/build.c e98868af6a04c8d7191c39fd05c69da34a8d9c68 F src/callback.c cb68b21b0d4ae7d11ae0e487933bce3323784dcf F src/complete.c 5ad5c6cd4548211867c204c41a126d73a9fbcea0 F src/date.c ab5f7137656652a48434d64f96bdcdc823bb23b3 @@ -146,8 +146,8 @@ F src/os_common.h 8c61457df58f1a4bd5f5adc3e90e01b37bf7afbc F src/os_os2.c bed77dc26e3a95ce4a204936b9a1ca6fe612fcc5 F src/os_unix.c b64129c296e480c2827606e206ea51bb30904626 F src/os_win.c 725c38a524d168ce280446ad8761d731bc516405 -F src/pager.c efdd56a49622fe87d5cf4b6e69aeb62b45bcb9b0 -F src/pager.h 73f481a308a873ccd626d97331c081db3b53e2e5 +F src/pager.c 5fee0ea97b1bd12a97006d64ddc9224f83fdbfde +F src/pager.h 5aec418bf99f568b92ae82816a1463400513726d F src/parse.y bab89225c2543a350ef96995926520bbbd781aba F src/pcache.c 395f752a13574120bd7513a400ba02a265aaa76d F src/pcache.h 9b927ccc5a538e31b4c3bc7eec4f976db42a1324 @@ -162,13 +162,13 @@ F src/select.c 71748b8e244112cf73df9446c4246c192276c30d F src/shell.c db2643650b9268df89a4bedca3f1c6d9e786f1bb F src/sqlite.h.in 9fe53ec7a8310d7d18d482b85e46f5556abfd1de F src/sqlite3ext.h 1db7d63ab5de4b3e6b83dd03d1a4e64fef6d2a17 -F src/sqliteInt.h d1e70cdb3a19c5e65735d1615b4ded7bff40f2cb +F src/sqliteInt.h ad6f72619f491cc1732e7b83cc5acea621edabd7 F src/sqliteLimit.h ffe93f5a0c4e7bd13e70cd7bf84cfb5c3465f45d F src/status.c 237b193efae0cf6ac3f0817a208de6c6c6ef6d76 F src/table.c cc86ad3d6ad54df7c63a3e807b5783c90411a08d F src/tclsqlite.c d3195e0738c101a155404ecdb1cd9532a2fd34f2 F src/test1.c c8f9358879876660b721369f576bf6e4ac5b9210 -F src/test2.c 71c22e2974f8094fe0fd1eba8f27872dde9b2a39 +F src/test2.c d73e4a490349245fb196b990b80684513e0ceaee F src/test3.c abd651f387a42696976dd5560c46b596e421cfb8 F src/test4.c f79ab52d27ff49b784b631a42e2ccd52cfd5c84c F src/test5.c 162a1cea2105a2c460a3f39fa6919617b562a288 @@ -736,7 +736,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl 672f81d693a03f80f5ae60bfefacd8a349e76746 -P db4fb835363c9c7e38c891e01188a6e2db88472d -R 86cedc96e291a5a2447f0fcd24fed5e9 +P 40a40e81b3ad80114422d6a48146e5fb27e2551d +R 9e4b8b3ab226d1138a21e4657cb77ee7 U drh -Z 685bf1a411eee02fbcb3368900cae4e1 +Z 5171f5cb6ff49910af6921574145401f diff --git a/manifest.uuid b/manifest.uuid index 01c61de90c..c9490968e9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -40a40e81b3ad80114422d6a48146e5fb27e2551d \ No newline at end of file +ed08b53cd64c4ff2c94ef4e48441c5236041c9ca \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 8d6a1482d6..a83c8115d1 100644 --- a/src/btree.c +++ b/src/btree.c @@ -9,7 +9,7 @@ ** May you share freely, never taking more than you give. ** ************************************************************************* -** $Id: btree.c,v 1.635 2009/06/18 11:29:21 drh Exp $ +** $Id: btree.c,v 1.636 2009/06/18 17:22:39 drh Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** See the header comment on "btreeInt.h" for additional information. @@ -1589,7 +1589,7 @@ int sqlite3BtreeOpen( pBt->incrVacuum = (get4byte(&zDbHeader[36 + 7*4])?1:0); #endif } - rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize); + rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize, nReserve); if( rc ) goto btree_open_out; pBt->usableSize = pBt->pageSize - nReserve; assert( (pBt->pageSize & 7)==0 ); /* 8-byte alignment of pageSize */ @@ -1880,8 +1880,8 @@ int sqlite3BtreeSetPageSize(Btree *p, int pageSize, int nReserve, int iFix){ assert( !pBt->pPage1 && !pBt->pCursor ); pBt->pageSize = (u16)pageSize; freeTempSpace(pBt); - rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize); } + rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize, nReserve); pBt->usableSize = pBt->pageSize - (u16)nReserve; if( iFix ) pBt->pageSizeFixed = 1; sqlite3BtreeLeave(p); @@ -2036,7 +2036,8 @@ static int lockBtree(BtShared *pBt){ pBt->usableSize = (u16)usableSize; pBt->pageSize = (u16)pageSize; freeTempSpace(pBt); - rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize); + rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize, + pageSize-usableSize); if( rc ) goto page1_init_failed; return SQLITE_OK; } diff --git a/src/build.c b/src/build.c index a159ee43a4..53d03b7437 100644 --- a/src/build.c +++ b/src/build.c @@ -22,7 +22,7 @@ ** COMMIT ** ROLLBACK ** -** $Id: build.c,v 1.551 2009/06/16 04:35:39 danielk1977 Exp $ +** $Id: build.c,v 1.552 2009/06/18 17:22:39 drh Exp $ */ #include "sqliteInt.h" @@ -429,15 +429,6 @@ void sqlite3ResetInternalSchema(sqlite3 *db, int iDb){ ** schema hash tables and therefore do not have to make any changes ** to any of those tables. */ -#ifdef SQLITE_HAS_CODEC - for(i=0; inDb; i++){ - struct Db *pDb = &db->aDb[i]; - if( pDb->pBt==0 ){ - if( pDb->pAux && pDb->xFreeAux ) pDb->xFreeAux(pDb->pAux); - pDb->pAux = 0; - } - } -#endif for(i=j=2; inDb; i++){ struct Db *pDb = &db->aDb[i]; if( pDb->pBt==0 ){ diff --git a/src/pager.c b/src/pager.c index 522a926b57..60ef5678f4 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.593 2009/06/11 17:32:45 drh Exp $ +** @(#) $Id: pager.c,v 1.594 2009/06/18 17:22:39 drh Exp $ */ #ifndef SQLITE_OMIT_DISKIO #include "sqliteInt.h" @@ -104,10 +104,10 @@ int sqlite3PagerTrace=1; /* True to enable tracing */ */ #ifdef SQLITE_HAS_CODEC # define CODEC1(P,D,N,X,E) \ - if( P->xCodec && P->xCodec(P->pCodecArg,D,N,X)==0 ){ E; } + if( P->xCodec && P->xCodec(P->pCodec,D,N,X)==0 ){ E; } # define CODEC2(P,D,N,X,E,O) \ if( P->xCodec==0 ){ O=(char*)D; }else \ - if( (O=(char*)(P->xCodec(P->pCodecArg,D,N,X)))==0 ){ E; } + if( (O=(char*)(P->xCodec(P->pCodec,D,N,X)))==0 ){ E; } #else # define CODEC1(P,D,N,X,E) /* NO-OP */ # define CODEC2(P,D,N,X,E,O) O=(char*)D @@ -290,7 +290,8 @@ struct Pager { char dbFileVers[16]; /* Changes whenever database file changes */ u32 sectorSize; /* Assumed sector size during rollback */ - int nExtra; /* Add this many bytes to each in-memory page */ + u16 nExtra; /* Add this many bytes to each in-memory page */ + i16 nReserve; /* Number of unused bytes at end of each page */ u32 vfsFlags; /* Flags for sqlite3_vfs.xOpen() */ int pageSize; /* Number of bytes in a page */ Pgno mxPgno; /* Maximum allowed size of the database */ @@ -305,7 +306,9 @@ struct Pager { void (*xReiniter)(DbPage*); /* Call this routine when reloading pages */ #ifdef SQLITE_HAS_CODEC void *(*xCodec)(void*,void*,Pgno,int); /* Routine for en/decoding data */ - void *pCodecArg; /* First argument to xCodec() */ + void (*xCodecSizeChng)(void*,int,int); /* Notify of page size changes */ + void (*xCodecFree)(void*); /* Destructor for the codec */ + void *pCodec; /* First argument to xCodec... methods */ #endif char *pTmpSpace; /* Pager.pageSize bytes of space for tmp use */ i64 journalSizeLimit; /* Size limit for persistent journal files */ @@ -927,7 +930,7 @@ static int readJournalHdr( ** PagerSetPagesize() is tested. */ iPageSize16 = (u16)iPageSize; - rc = sqlite3PagerSetPagesize(pPager, &iPageSize16); + rc = sqlite3PagerSetPagesize(pPager, &iPageSize16, -1); testcase( rc!=SQLITE_OK ); assert( rc!=SQLITE_OK || iPageSize16==(u16)iPageSize ); @@ -2361,6 +2364,21 @@ void sqlite3PagerSetReiniter(Pager *pPager, void (*xReinit)(DbPage*)){ pPager->xReiniter = xReinit; } +/* +** Report the current page size and number of reserved bytes back +** to the codec. +*/ +#ifdef SQLITE_HAS_CODEC +static void pagerReportSize(Pager *pPager){ + if( pPager->xCodecSizeChng ){ + pPager->xCodecSizeChng(pPager->pCodec, pPager->pageSize, + (int)pPager->nReserve); + } +} +#else +# define pagerReportSize(X) /* No-op if we do not support a codec */ +#endif + /* ** Change the page size used by the Pager object. The new page size ** is passed in *pPageSize. @@ -2391,7 +2409,7 @@ void sqlite3PagerSetReiniter(Pager *pPager, void (*xReinit)(DbPage*)){ ** function was called, or because the memory allocation attempt failed, ** then *pPageSize is set to the old, retained page size before returning. */ -int sqlite3PagerSetPagesize(Pager *pPager, u16 *pPageSize){ +int sqlite3PagerSetPagesize(Pager *pPager, u16 *pPageSize, int nReserve){ int rc = pPager->errCode; if( rc==SQLITE_OK ){ u16 pageSize = *pPageSize; @@ -2412,6 +2430,10 @@ int sqlite3PagerSetPagesize(Pager *pPager, u16 *pPageSize){ } } *pPageSize = (u16)pPager->pageSize; + if( nReserve<0 ) nReserve = pPager->nReserve; + assert( nReserve>=0 && nReserve<1000 ); + pPager->nReserve = (i16)nReserve; + pagerReportSize(pPager); } return rc; } @@ -2660,6 +2682,10 @@ int sqlite3PagerClose(Pager *pPager){ sqlite3PageFree(pPager->pTmpSpace); sqlite3PcacheClose(pPager->pPCache); +#ifdef SQLITE_HAS_CODEC + if( pPager->xCodecFree ) pPager->xCodecFree(pPager->pCodec); +#endif + assert( !pPager->aSavepoint && !pPager->pInJournal ); assert( !isOpen(pPager->jfd) && !isOpen(pPager->sjfd) ); @@ -3281,7 +3307,7 @@ int sqlite3PagerOpen( */ if( rc==SQLITE_OK ){ assert( pPager->memDb==0 ); - rc = sqlite3PagerSetPagesize(pPager, &szPageDflt); + rc = sqlite3PagerSetPagesize(pPager, &szPageDflt, -1); testcase( rc!=SQLITE_OK ); } @@ -3296,6 +3322,7 @@ int sqlite3PagerOpen( } /* Initialize the PCache object. */ + assert( nExtra<1000 ); nExtra = ROUND8(nExtra); sqlite3PcacheOpen(szPageDflt, nExtra, !memDb, !memDb?pagerStress:0, (void *)pPager, pPager->pPCache); @@ -3331,7 +3358,7 @@ int sqlite3PagerOpen( /* pPager->pFirst = 0; */ /* pPager->pFirstSynced = 0; */ /* pPager->pLast = 0; */ - pPager->nExtra = nExtra; + pPager->nExtra = (u16)nExtra; pPager->journalSizeLimit = SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT; assert( isOpen(pPager->fd) || tempFile ); setSectorSize(pPager); @@ -5044,15 +5071,24 @@ int sqlite3PagerNosync(Pager *pPager){ #ifdef SQLITE_HAS_CODEC /* -** Set the codec for this pager +** Set or retrieve the codec for this pager */ -void sqlite3PagerSetCodec( +static void sqlite3PagerSetCodec( Pager *pPager, void *(*xCodec)(void*,void*,Pgno,int), - void *pCodecArg + void (*xCodecSizeChng)(void*,int,int), + void (*xCodecFree)(void*), + void *pCodec ){ + if( pPager->xCodecFree ) pPager->xCodecFree(pPager->pCodec); pPager->xCodec = xCodec; - pPager->pCodecArg = pCodecArg; + pPager->xCodecSizeChng = xCodecSizeChng; + pPager->xCodecFree = xCodecFree; + pPager->pCodec = pCodec; + pagerReportSize(pPager); +} +static void *sqlite3PagerGetCodec(Pager *pPager){ + return pPager->pCodec; } #endif diff --git a/src/pager.h b/src/pager.h index a0110f8595..aed165f06a 100644 --- a/src/pager.h +++ b/src/pager.h @@ -13,7 +13,7 @@ ** subsystem. The page cache subsystem reads and writes a file a page ** at a time and provides a journal for rollback. ** -** @(#) $Id: pager.h,v 1.101 2009/04/30 09:10:38 danielk1977 Exp $ +** @(#) $Id: pager.h,v 1.102 2009/06/18 17:22:39 drh Exp $ */ #ifndef _PAGER_H_ @@ -93,7 +93,7 @@ int sqlite3PagerReadFileheader(Pager*, int, unsigned char*); /* Functions used to configure a Pager object. */ void sqlite3PagerSetBusyhandler(Pager*, int(*)(void *), void *); void sqlite3PagerSetReiniter(Pager*, void(*)(DbPage*)); -int sqlite3PagerSetPagesize(Pager*, u16*); +int sqlite3PagerSetPagesize(Pager*, u16*, int); int sqlite3PagerMaxPageCount(Pager*, int); void sqlite3PagerSetCachesize(Pager*, int); void sqlite3PagerSetSafetyLevel(Pager*,int,int); @@ -141,11 +141,6 @@ int sqlite3PagerIsMemdb(Pager*); /* Functions used to truncate the database file. */ void sqlite3PagerTruncateImage(Pager*,Pgno); -/* Used by encryption extensions. */ -#ifdef SQLITE_HAS_CODEC - void sqlite3PagerSetCodec(Pager*,void*(*)(void*,void*,Pgno,int),void*); -#endif - /* Functions to support testing and debugging. */ #if !defined(NDEBUG) || defined(SQLITE_TEST) Pgno sqlite3PagerPagenumber(DbPage*); diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 0601584b89..67fc1344f0 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -11,7 +11,7 @@ ************************************************************************* ** Internal interface definitions for SQLite. ** -** @(#) $Id: sqliteInt.h,v 1.884 2009/06/15 20:45:35 drh Exp $ +** @(#) $Id: sqliteInt.h,v 1.885 2009/06/18 17:22:39 drh Exp $ */ #ifndef _SQLITEINT_H_ #define _SQLITEINT_H_ @@ -645,10 +645,6 @@ struct Db { u8 inTrans; /* 0: not writable. 1: Transaction. 2: Checkpoint */ u8 safety_level; /* How aggressive at syncing data to disk */ Schema *pSchema; /* Pointer to database schema (possibly shared) */ -#ifdef SQLITE_HAS_CODEC - void *pAux; /* Auxiliary data. Usually NULL */ - void (*xFreeAux)(void*); /* Routine to free pAux */ -#endif }; /* diff --git a/src/test2.c b/src/test2.c index 4db8eede68..0ea382830c 100644 --- a/src/test2.c +++ b/src/test2.c @@ -13,7 +13,7 @@ ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** -** $Id: test2.c,v 1.70 2009/02/05 16:31:46 drh Exp $ +** $Id: test2.c,v 1.71 2009/06/18 17:22:39 drh Exp $ */ #include "sqliteInt.h" #include "tcl.h" @@ -86,7 +86,7 @@ static int pager_open( } sqlite3PagerSetCachesize(pPager, nPage); pageSize = test_pagesize; - sqlite3PagerSetPagesize(pPager, &pageSize); + sqlite3PagerSetPagesize(pPager, &pageSize, -1); sqlite3_snprintf(sizeof(zBuf),zBuf,"%p",pPager); Tcl_AppendResult(interp, zBuf, 0); return TCL_OK;