1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-08 14:02:16 +03:00

Fix a pager bug that might have made multi-database commits non-atomic

if a power failure occurred at just the wrong moment. (CVS 1900)

FossilOrigin-Name: b6eb4bf8c7763ef73723fc3d3697af435c19bae4
This commit is contained in:
drh
2004-08-21 19:20:42 +00:00
parent 290c19482e
commit fdb38064b0
5 changed files with 25 additions and 19 deletions

View File

@@ -1,5 +1,5 @@
C Optimizations\sto\sthe\scode\sgenerator.\s(CVS\s1899) C Fix\sa\spager\sbug\sthat\smight\shave\smade\smulti-database\scommits\snon-atomic\nif\sa\spower\sfailure\soccurred\sat\sjust\sthe\swrong\smoment.\s(CVS\s1900)
D 2004-08-21T17:54:45 D 2004-08-21T19:20:42
F Makefile.in 4a5e570a9e2d35b09c31b3cf01b78cea764ade4b F Makefile.in 4a5e570a9e2d35b09c31b3cf01b78cea764ade4b
F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457 F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@@ -45,13 +45,13 @@ F src/os.h d1780e0db95cad01f213d48da22ab490eb4fd345
F src/os_common.h cd7eb025fdab7dc91e0e97bf6310f1648205857f F src/os_common.h cd7eb025fdab7dc91e0e97bf6310f1648205857f
F src/os_mac.c 3d31e26be1411acfb7961033098631b4f3486fdf F src/os_mac.c 3d31e26be1411acfb7961033098631b4f3486fdf
F src/os_mac.h 51d2445f47e182ed32d3bd6937f81070c6fd9bd4 F src/os_mac.h 51d2445f47e182ed32d3bd6937f81070c6fd9bd4
F src/os_test.c 6bf10100de2ca199a91fe7ac6474561c8a7166ae F src/os_test.c d3cb336448d28cb6238f8c0d7a44b0ff010601ea
F src/os_test.h 6a26a4978492e4bbdbf385554958418ff02db162 F src/os_test.h 6a26a4978492e4bbdbf385554958418ff02db162
F src/os_unix.c 3239a45dbd2f50195bfc97f1ed35cb8fe5a3f60c F src/os_unix.c 3239a45dbd2f50195bfc97f1ed35cb8fe5a3f60c
F src/os_unix.h f3097815e041e82e24d92505e1ff61ba24172d13 F src/os_unix.h f3097815e041e82e24d92505e1ff61ba24172d13
F src/os_win.c 54181eb73cb4783c4241feca9eaa490768b39008 F src/os_win.c 54181eb73cb4783c4241feca9eaa490768b39008
F src/os_win.h babd4e912967c6b09088cfe38a45e8005a07ba44 F src/os_win.h babd4e912967c6b09088cfe38a45e8005a07ba44
F src/pager.c 2698653a3bd895b2156c108a37a32d240a55bb0e F src/pager.c 6ecf24602f56ac98914685d449f6653903f36fec
F src/pager.h 67739fe649f33be55dba522ca8a9cc4e42d14f71 F src/pager.h 67739fe649f33be55dba522ca8a9cc4e42d14f71
F src/parse.y 8b4cab1901900927f717d10885b7a1bd3375345b F src/parse.y 8b4cab1901900927f717d10885b7a1bd3375345b
F src/pragma.c a7cea75286fcff6666a5412b04478fcf0ecef5c4 F src/pragma.c a7cea75286fcff6666a5412b04478fcf0ecef5c4
@@ -105,7 +105,7 @@ F test/collate4.test 4a7902b7560686af11d6cace717d876c6937b7ef
F test/collate5.test 1dd5f0f508c46667f9d4606c7950c414b0bdc0d5 F test/collate5.test 1dd5f0f508c46667f9d4606c7950c414b0bdc0d5
F test/collate6.test 2a45768914f04c1447a69d1358bbede376552675 F test/collate6.test 2a45768914f04c1447a69d1358bbede376552675
F test/conflict.test c5b849b01cfbe0a4f63a90cba6f68e2fe3a75f87 F test/conflict.test c5b849b01cfbe0a4f63a90cba6f68e2fe3a75f87
F test/crash.test 59a91b7fbb41e9e5cb8ab652f22a7e639a0adc78 F test/crash.test a3f6d27f7cb7f7bd752461db1e14f7c781ecedc3
F test/crashtest1.c 09c1c7d728ccf4feb9e481671e29dda5669bbcc2 F test/crashtest1.c 09c1c7d728ccf4feb9e481671e29dda5669bbcc2
F test/date.test fd3db29bba089578b1b008e3511ea9e74840377a F test/date.test fd3db29bba089578b1b008e3511ea9e74840377a
F test/delete.test ec0b455f2dcc0e189d96ee438438ba026c4e51d8 F test/delete.test ec0b455f2dcc0e189d96ee438438ba026c4e51d8
@@ -243,7 +243,7 @@ F www/tclsqlite.tcl 06a86cba4d7fc88e2bcd633b57702d3d16abebb5
F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9 F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9
F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0 F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0
F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4 F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
P e97c331362545ce21117776c7b61d3488668f2bf P bd6649c5aae1bf182610eb267b546c297a34481d
R b22d8f216bcbbb8b75e2380cdf547c74 R f44107658e3b90d9c7e881af0ccb6474
U drh U drh
Z d01e8ee90bb832b679bd3adc8a30a5ef Z 5a36877b594a25790956a9835b384791

View File

@@ -1 +1 @@
bd6649c5aae1bf182610eb267b546c297a34481d b6eb4bf8c7763ef73723fc3d3697af435c19bae4

View File

@@ -96,11 +96,13 @@ static int crashRequired(char const *zPath){
}else if( strlen(zPath)>n ){ }else if( strlen(zPath)>n ){
n = strlen(zPath); n = strlen(zPath);
} }
r = ( r = 0;
iCrashDelay>0 && if( iCrashDelay>0 && strncmp(zPath, zCrashFile, n)==0 ){
!strncmp(zPath, zCrashFile, n) && iCrashDelay--;
--iCrashDelay==0 if( iCrashDelay<=0 ){
)?1:0; r = 1;
}
}
sqlite3OsLeaveMutex(); sqlite3OsLeaveMutex();
return r; return r;
} }
@@ -157,6 +159,7 @@ static off_t osTell(OsTestFile *pFile){
static int cacheBlock(OsTestFile *pFile, int blk){ static int cacheBlock(OsTestFile *pFile, int blk){
if( blk>=pFile->nBlk ){ if( blk>=pFile->nBlk ){
int n = ((pFile->nBlk * 2) + 100 + blk); int n = ((pFile->nBlk * 2) + 100 + blk);
/* if( pFile->nBlk==0 ){ printf("DIRTY %s\n", pFile->zName); } */
pFile->apBlk = (u8 **)sqliteRealloc(pFile->apBlk, n * sizeof(u8*)); pFile->apBlk = (u8 **)sqliteRealloc(pFile->apBlk, n * sizeof(u8*));
if( !pFile->apBlk ) return SQLITE_NOMEM; if( !pFile->apBlk ) return SQLITE_NOMEM;
memset(&pFile->apBlk[pFile->nBlk], 0, (n - pFile->nBlk)*sizeof(u8*)); memset(&pFile->apBlk[pFile->nBlk], 0, (n - pFile->nBlk)*sizeof(u8*));
@@ -283,6 +286,7 @@ static int writeCache(OsTestFile *pFile){
int sqlite3OsClose(OsFile *id){ int sqlite3OsClose(OsFile *id){
if( !(*id) ) return SQLITE_OK; if( !(*id) ) return SQLITE_OK;
if( (*id)->fd.isOpen ){ if( (*id)->fd.isOpen ){
/* printf("CLOSE %s (%d blocks)\n", (*id)->zName, (*id)->nBlk); */
writeCache(*id); writeCache(*id);
sqlite3RealClose(&(*id)->fd); sqlite3RealClose(&(*id)->fd);
} }
@@ -386,7 +390,9 @@ int sqlite3OsWrite(OsFile *id, const void *pBuf, int amt){
** real sync() function. ** real sync() function.
*/ */
int sqlite3OsSync(OsFile *id){ int sqlite3OsSync(OsFile *id){
int rc = writeCache(*id); int rc;
/* printf("SYNC %s (%d blocks)\n", (*id)->zName, (*id)->nBlk); */
rc = writeCache(*id);
if( rc!=SQLITE_OK ) return rc; if( rc!=SQLITE_OK ) return rc;
rc = sqlite3RealSync(&(*id)->fd); rc = sqlite3RealSync(&(*id)->fd);
return rc; return rc;

View File

@@ -18,7 +18,7 @@
** file simultaneously, or one process from reading the database while ** file simultaneously, or one process from reading the database while
** another is writing. ** another is writing.
** **
** @(#) $Id: pager.c,v 1.159 2004/08/19 13:29:15 drh Exp $ ** @(#) $Id: pager.c,v 1.160 2004/08/21 19:20:42 drh Exp $
*/ */
#include "os.h" /* Must be first to enable large file support */ #include "os.h" /* Must be first to enable large file support */
#include "sqliteInt.h" #include "sqliteInt.h"
@@ -222,6 +222,7 @@ struct Pager {
u8 memDb; /* True to inhibit all file I/O */ u8 memDb; /* True to inhibit all file I/O */
u8 *aInJournal; /* One bit for each page in the database file */ u8 *aInJournal; /* One bit for each page in the database file */
u8 *aInStmt; /* One bit for each page in the database */ u8 *aInStmt; /* One bit for each page in the database */
u8 setMaster; /* True if a m-j name has been written to jrnl */
BusyHandler *pBusyHandler; /* Pointer to sqlite.busyHandler */ BusyHandler *pBusyHandler; /* Pointer to sqlite.busyHandler */
PgHdr *pFirst, *pLast; /* List of free pages */ PgHdr *pFirst, *pLast; /* List of free pages */
PgHdr *pFirstSynced; /* First free page with PgHdr.needSync==0 */ PgHdr *pFirstSynced; /* First free page with PgHdr.needSync==0 */
@@ -233,7 +234,6 @@ struct Pager {
off_t stmtHdrOff; /* First journal header written this statement */ off_t stmtHdrOff; /* First journal header written this statement */
off_t stmtCksum; /* cksumInit when statement was started */ off_t stmtCksum; /* cksumInit when statement was started */
int sectorSize; /* Assumed sector size during rollback */ int sectorSize; /* Assumed sector size during rollback */
u8 setMaster; /* True if a m-j name has been written to jrnl */
}; };
/* /*
@@ -660,6 +660,7 @@ static int writeMasterJournal(Pager *pPager, const char *zMaster){
if( rc!=SQLITE_OK ) return rc; if( rc!=SQLITE_OK ) return rc;
rc = sqlite3OsWrite(&pPager->jfd, aJournalMagic, sizeof(aJournalMagic)); rc = sqlite3OsWrite(&pPager->jfd, aJournalMagic, sizeof(aJournalMagic));
pPager->needSync = 1;
return rc; return rc;
} }

View File

@@ -20,7 +20,7 @@
# The special crash-test module with its os_test.c backend only works # The special crash-test module with its os_test.c backend only works
# on Unix. # on Unix.
# #
# $Id: crash.test,v 1.8 2004/08/21 17:54:46 drh Exp $ # $Id: crash.test,v 1.9 2004/08/21 19:20:42 drh Exp $
set testdir [file dirname $argv0] set testdir [file dirname $argv0]
source $testdir/tester.tcl source $testdir/tester.tcl
@@ -273,7 +273,6 @@ for {set i 1} {$i<$repeats} {incr i} {
} $sig2 } $sig2
} }
set i 0 set i 0
set i 55
while {[incr i]} { while {[incr i]} {
set sig [signature] set sig [signature]
set sig2 [signature2] set sig2 [signature2]