Fix a bug in the rollback logic for the new journal format. (CVS 864)

FossilOrigin-Name: 7c22aa3f817e737cfd943d903856756468e8678b
This commit is contained in:
drh 2003-02-13 01:58:20 +00:00
parent 8ba1b31379
commit 4a0681ef1b
3 changed files with 17 additions and 47 deletions

@ -1,5 +1,5 @@
C Added\sthe\snew\sFULL\soption\sto\sthe\sSYNCHRONOUS\spragma.\s\sStill\sneed\sto\stest\sit.\s(CVS\s1728)
D 2003-02-12T14:09:44
C Fix\sa\sbug\sin\sthe\srollback\slogic\sfor\sthe\snew\sjournal\sformat.\s(CVS\s864)
D 2003-02-13T01:58:21
F Makefile.in 6606854b1512f185b8e8c779b8d7fc2750463d64
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@ -33,7 +33,7 @@ F src/main.c f88dfe09ed79588899cb4013836dd940f73a17fa
F src/md5.c fe4f9c9c6f71dfc26af8da63e4d04489b1430565
F src/os.c ed27e178e0c4b71f2807da81b8851f0fadc50778
F src/os.h afa3e096213bad86845f8bdca81a9e917505e401
F src/pager.c f7658e5d07ef66c966443a3f4420510ce640442b
F src/pager.c a64f69216ebef0e6ce90e65700674b7c64f6b16e
F src/pager.h e5b8e301a732007766dc04880c764d7ee1aa34dd
F src/parse.y cdaed5009423d851708848bd279147c268e6022e
F src/printf.c f8fd911a8738f9b2eb07aca2870473d34707055d
@ -155,7 +155,7 @@ F www/speed.tcl 4d463e2aea41f688ed320a937f93ff885be918c3
F www/sqlite.tcl ae3dcfb077e53833b59d4fcc94d8a12c50a44098
F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331
F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
P 792a9e157dd066fcaffd4f5b373010151fb4ca61
R 4c767e05bbbde68a52aa488a93a1a8fd
P 8968bc063607856775ad63b6594d40c55cf288c0
R 5afba469118d5ff096906c926faadaaa
U drh
Z 628b9de7e355f82d06d514404826a9e9
Z dea82f51b0a81ba078f1ce14af670302

@ -1 +1 @@
8968bc063607856775ad63b6594d40c55cf288c0
7c22aa3f817e737cfd943d903856756468e8678b

@ -18,7 +18,7 @@
** file simultaneously, or one process from reading the database while
** another is writing.
**
** @(#) $Id: pager.c,v 1.75 2003/02/12 14:09:44 drh Exp $
** @(#) $Id: pager.c,v 1.76 2003/02/13 01:58:21 drh Exp $
*/
#include "os.h" /* Must be first to enable large file support */
#include "sqliteInt.h"
@ -135,9 +135,6 @@ struct Pager {
int origDbSize; /* dbSize before the current change */
int ckptSize; /* Size of database (in pages) at ckpt_begin() */
off_t ckptJSize; /* Size of journal at ckpt_begin() */
#ifndef NDEBUG
off_t syncJSize; /* Size of journal at last fsync() call */
#endif
int nRec; /* Number of pages written to the journal */
u32 cksumInit; /* Quasi-random value added to every checksum */
int ckptNRec; /* Number of records in the checkpoint journal */
@ -634,20 +631,15 @@ static int pager_playback(Pager *pPager){
}
}
end_playback:
#if !defined(NDEBUG) && defined(SQLITE_TEST)
/* For pages that were never written into the journal, restore the
** memory copy from the original database file.
**
** This is code is used during testing only. It is necessary to
** compensate for the sqliteOsTruncate() call inside
** sqlitepager_rollback().
/* Pages that have been written to the journal but never synced
** where not restored by the loop above. We have to restore those
** pages by reading the back from the original database.
*/
if( rc==SQLITE_OK ){
PgHdr *pPg;
for(pPg=pPager->pAll; pPg; pPg=pPg->pNextAll){
char zBuf[SQLITE_PAGE_SIZE];
if( !pPg->dirty ) continue;
if( (int)pPg->pgno <= pPager->origDbSize ){
sqliteOsSeek(&pPager->fd, SQLITE_PAGE_SIZE*(off_t)(pPg->pgno-1));
rc = sqliteOsRead(&pPager->fd, zBuf, SQLITE_PAGE_SIZE);
@ -663,7 +655,8 @@ end_playback:
pPg->dirty = 0;
}
}
#endif
end_playback:
if( rc!=SQLITE_OK ){
pager_unwritelock(pPager);
pPager->errMask |= PAGER_ERR_CORRUPT;
@ -1057,12 +1050,12 @@ static int syncAllPages(Pager *pPager){
assert( !pPager->noSync );
#ifndef NDEBUG
{
off_t hdrSz, pgSz;
off_t hdrSz, pgSz, jSz;
hdrSz = JOURNAL_HDR_SZ(journal_format);
pgSz = JOURNAL_PG_SZ(journal_format);
rc = sqliteOsFileSize(&pPager->jfd, &pPager->syncJSize);
rc = sqliteOsFileSize(&pPager->jfd, &jSz);
if( rc!=0 ) return rc;
assert( pPager->nRec*pgSz+hdrSz==pPager->syncJSize );
assert( pPager->nRec*pgSz+hdrSz==jSz );
}
#endif
if( journal_format>=3 ){
@ -1542,9 +1535,6 @@ static int pager_open_journal(Pager *pPager){
rc = SQLITE_FULL;
}
}
#ifndef NDEBUG
pPager->syncJSize = 0;
#endif
return rc;
}
@ -1889,26 +1879,6 @@ int sqlitepager_rollback(Pager *pPager){
return rc;
}
#if defined(SQLITE_TEST) && !defined(NDEBUG)
/* Truncate the journal to the size it was at the conclusion of the
** last sqliteOsSync() call. This is really an error check. If the
** rollback still works, it means that the rollback would have also
** worked if it had occurred after an OS crash or unexpected power
** loss.
*/
if( !pPager->noSync ){
int m = JOURNAL_HDR_SZ(journal_format);
assert( !pPager->tempFile );
if( pPager->syncJSize<m ){
pPager->syncJSize = m;
}
TRACE2("TRUNCATE JOURNAL %lld\n", pPager->syncJSize);
rc = sqliteOsTruncate(&pPager->jfd, pPager->syncJSize);
if( rc ) return rc;
pPager->nRec = 0;
}
#endif
if( pPager->errMask!=0 && pPager->errMask!=PAGER_ERR_FULL ){
if( pPager->state>=SQLITE_WRITELOCK ){
pager_playback(pPager);