-C Cleanup\sof\sthe\sPAGERTRACE\smacro.\s\sOther\scomment\schanges\sin\spager.c.\s(CVS\s6122)
-D 2009-01-06T15:58:57
+C Modify\stest_journal.c\sto\sverify\sthe\spage\sdata\sbeing\swritten\sto\sthe\sjournal\sfile.\s(CVS\s6123)
+D 2009-01-06T17:52:44
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in 05461a9b5803d5ad10c79f989801e9fd2cc3e592
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
F src/test_devsym.c 9f4bc2551e267ce7aeda195f3897d0f30c5228f4
F src/test_func.c a55c4d5479ff2eb5c0a22d4d88e9528ab59c953b
F src/test_hexio.c 2f1122aa3f012fa0142ee3c36ce5c902a70cd12f
-F src/test_journal.c a70ac20fd599427114fc6a6a7d39b494a25a256d
+F src/test_journal.c ce3da048786536f0264ca5135c9639e34d1fbe3f
F src/test_loadext.c 97dc8800e46a46ed002c2968572656f37e9c0dd9
F src/test_malloc.c 5127337c9fb4c851a7f604c0170e0e5ca1fbfe33
F src/test_md5.c 28209a4e2068711b5443c33104fe41f21d160071
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
-P ddc2ebfa529b15cdbdd3b6b6d4873cb085cfd3b9
-R 6b0877b5b9e58d59e7a8a4362c4eedfd
-U drh
-Z f01f333ede5e27c1b8f182af69841c07
+P ee7b4b60880e80e6fb0b2f93ebc6ee5ad6917f9d
+R df239d0a18ce55c45df67f391c4292ac
+U danielk1977
+Z 2c4d14960713eb79bb3320ac4beeb7d8
** b) the page was not a free-list leaf page when the transaction was
** first opened.
**
-** $Id: test_journal.c,v 1.5 2009/01/06 14:34:35 danielk1977 Exp $
+** $Id: test_journal.c,v 1.6 2009/01/06 17:52:44 danielk1977 Exp $
*/
#if SQLITE_TEST /* This file is used for testing only */
u32 nPage; /* Size of file in pages when transaction started */
u32 nPagesize; /* Page size when transaction started */
Bitvec *pWritable; /* Bitvec of pages that may be written to the file */
+ u32 *aCksum; /* Checksum for first nPage pages */
+
+ /* Only used by journal file-handles */
+ sqlite3_int64 iMaxOff; /* Maximum offset written to this transaction */
jt_file *pNext; /* All files are stored in a linked list */
sqlite3_file *pReal; /* The file handle for the underlying vfs */
static void closeTransaction(jt_file *p){
sqlite3BitvecDestroy(p->pWritable);
+ sqlite3_free(p->aCksum);
p->pWritable = 0;
+ p->aCksum = 0;
}
/*
return (z[0]<<24) + (z[1]<<16) + (z[2]<<8) + z[3];
}
+static int calculateCksums(jt_file *pMain){
+ int rc = SQLITE_OK;
+ int ii, jj;
+ unsigned char *aData = sqlite3_malloc(pMain->nPagesize);
+ if( !aData ){
+ return SQLITE_IOERR_NOMEM;
+ }
+
+ for(ii=0; rc==SQLITE_OK && ii<pMain->nPage; ii++){
+ u32 cksum = 0;
+ sqlite_int64 iOff = (sqlite3_int64)(pMain->nPagesize) * (sqlite3_int64)ii;
+ rc = sqlite3OsRead(pMain->pReal, aData, pMain->nPagesize, iOff);
+ for(jj=0; jj<pMain->nPagesize; jj++){
+ cksum = cksum + aData[jj] + (cksum<<3);
+ }
+ pMain->aCksum[ii] = cksum;
+ }
+ sqlite3_free(aData);
+
+ return rc;
+}
+
static int readFreelist(jt_file *pMain){
int rc;
sqlite3_file *p = pMain->pReal;
sqlite_int64 iOfst
){
jt_file *p = (jt_file *)pFile;
- if( p->flags&SQLITE_OPEN_MAIN_JOURNAL && iOfst==0 ){
- jt_file *pMain = locateDatabaseHandle(p->zName);
- assert( pMain );
-
- if( decodeJournalHdr(zBuf, 0, &pMain->nPage, 0, &pMain->nPagesize) ){
- /* Zeroing the first journal-file header. This is the end of a
- ** transaction. */
- closeTransaction(pMain);
- }else{
- /* Writing the first journal header to a journal file. This happens
- ** when a transaction is first started. */
- int rc;
- pMain->pWritable = sqlite3BitvecCreate(pMain->nPage);
- if( !pMain->pWritable ){
- return SQLITE_IOERR_NOMEM;
- }
- rc = readFreelist(pMain);
- if( rc!=SQLITE_OK ){
- return rc;
+ if( p->flags&SQLITE_OPEN_MAIN_JOURNAL ){
+ if( iOfst==0 ){
+ jt_file *pMain = locateDatabaseHandle(p->zName);
+ assert( pMain );
+
+ if( decodeJournalHdr(zBuf, 0, &pMain->nPage, 0, &pMain->nPagesize) ){
+ /* Zeroing the first journal-file header. This is the end of a
+ ** transaction. */
+ closeTransaction(pMain);
+ }else{
+ /* Writing the first journal header to a journal file. This happens
+ ** when a transaction is first started. */
+ int rc;
+ pMain->pWritable = sqlite3BitvecCreate(pMain->nPage);
+ pMain->aCksum = sqlite3_malloc(sizeof(u32) * (pMain->nPage + 1));
+ p->iMaxOff = 0;
+ if( !pMain->pWritable || !pMain->aCksum ){
+ return SQLITE_IOERR_NOMEM;
+ }
+ rc = readFreelist(pMain);
+ if( rc!=SQLITE_OK ){
+ return rc;
+ }
+ rc = calculateCksums(pMain);
+ if( rc!=SQLITE_OK ){
+ return rc;
+ }
}
}
+ if( p->iMaxOff<(iOfst + iAmt) ){
+ p->iMaxOff = iOfst + iAmt;
+ }
}
if( p->flags&SQLITE_OPEN_MAIN_DB && p->pWritable && iAmt==p->nPagesize ){
** page in the journal to the Bitvec object passed as the second argument.
*/
static int readJournalFile(jt_file *p, jt_file *pMain){
- int rc;
+ int rc = SQLITE_OK;
unsigned char zBuf[28];
sqlite3_file *pReal = p->pReal;
sqlite3_int64 iOff = 0;
sqlite3_int64 iSize = 0;
+ unsigned char *aPage;
- rc = sqlite3OsFileSize(p->pReal, &iSize);
+ aPage = sqlite3_malloc(pMain->nPagesize);
+ if( !aPage ){
+ return SQLITE_IOERR_NOMEM;
+ }
+ /* rc = sqlite3OsFileSize(p->pReal, &iSize); */
+ iSize = p->iMaxOff;
while( rc==SQLITE_OK && iOff<iSize ){
u32 nRec, nPage, nSector, nPagesize;
u32 ii;
** following this one. In this case, 0 records means 0 records,
** not "read until the end of the file". See also ticket #2565.
*/
- if( iSize>=(nRec+nSector) ){
+ if( iSize>=(iOff+nSector) ){
rc = sqlite3OsRead(pReal, zBuf, 28, iOff);
if( rc!=SQLITE_OK || 0==decodeJournalHdr(zBuf, 0, 0, 0, 0) ){
continue;
}
}
- nRec = (iSize - iOff)/(pMain->nPagesize + 8);
+ nRec = (iSize-iOff) / (pMain->nPagesize+8);
}
for(ii=0; rc==SQLITE_OK && ii<nRec && iOff<iSize; ii++){
u32 pgno;
rc = sqlite3OsRead(pReal, zBuf, 4, iOff);
if( rc==SQLITE_OK ){
pgno = decodeUint32(zBuf);
- iOff += (8 + pMain->nPagesize);
if( pgno>0 && pgno<=pMain->nPage ){
+ if( 0==sqlite3BitvecTest(pMain->pWritable, pgno) ){
+ rc = sqlite3OsRead(pReal, aPage, pMain->nPagesize, iOff+4);
+ if( rc==SQLITE_OK ){
+ int jj;
+ u32 cksum = 0;
+ for(jj=0; jj<pMain->nPagesize; jj++){
+ cksum = cksum + aPage[jj] + (cksum<<3);
+ }
+ assert( cksum==pMain->aCksum[pgno-1] );
+ }
+ }
sqlite3BitvecSet(pMain->pWritable, pgno);
}
+ iOff += (8 + pMain->nPagesize);
}
}
}
finish_rjf:
+ sqlite3_free(aPage);
if( rc==SQLITE_IOERR_SHORT_READ ){
rc = SQLITE_OK;
}
p->flags = flags;
p->pNext = 0;
p->pWritable = 0;
+ p->aCksum = 0;
if( zName ){
p->pNext = g.pList;
g.pList = p;