From: danielk1977 Date: Tue, 27 Mar 2007 16:19:51 +0000 (+0000) Subject: Test handling of IO errors that occur in OsDelete() or OsTruncate() operations. Also... X-Git-Tag: version-3.6.10~2441 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=979f38e5ee852e318ddc3eeddd542f4bf2c290fe;p=thirdparty%2Fsqlite.git Test handling of IO errors that occur in OsDelete() or OsTruncate() operations. Also use an anonymous file for temporary storage during a VACUUM. (CVS 3729) FossilOrigin-Name: b24a6e7b024c8b9a0b6fd15bd8f247e458781ca2 --- diff --git a/manifest b/manifest index ee1a10bfbb..21038e73d5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Updates\sto\sthe\sVACUUM\sdocumentation.\s\sTicket\s#2257.\s(CVS\s3728) -D 2007-03-27T15:00:31 +C Test\shandling\sof\sIO\serrors\sthat\soccur\sin\sOsDelete()\sor\sOsTruncate()\soperations.\sAlso\suse\san\sanonymous\sfile\sfor\stemporary\sstorage\sduring\sa\sVACUUM.\s(CVS\s3729) +D 2007-03-27T16:19:52 F Makefile.in 1fe3d0b46e40fd684e1e61f8e8056cefed16de9f F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -82,12 +82,12 @@ F src/os_os2.c cb2c4f6d28810b5cee682d8df92352464d5c9d95 F src/os_os2.h e5f17dd69333632bbc3112881ea407c37d245eb3 F src/os_test.c 49833426101f99aee4bb5f6a44b7c4b2029fda1c F src/os_test.h 903c93554c23d88f34f667f1979e4a1cee792af3 -F src/os_unix.c 1f32d15449caa02ada876a0e5b7b774d90e1be77 +F src/os_unix.c 0d91b28d57c0885fe97fb9020fd1091578066b5b F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e -F src/os_win.c 13708a58aa24a9960fa45ac4a681e34f881ae77c +F src/os_win.c 84c02837a6ec216a07e83a1d10d5a01c417bb489 F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b -F src/pager.c 7a60e7e1f8b5abe841282a3dc90823b73fefe8b8 -F src/pager.h 3c16500c25051536e43fb19e246e58fc7cb51d9f +F src/pager.c 2cc40af071948f6e57eb042f3a99a8921931effc +F src/pager.h f1b17bf848b3dce5d9afb2701186d3c9a8826f8c F src/parse.y 207ab04273ae13aa4a729b96008d294d5f334ab3 F src/pragma.c 9cb8b94e7d38ba35a86037bd517d07ba9870b4b2 F src/prepare.c 37207b2b2ccb41d379b01dd62231686bcc48ef1f @@ -96,7 +96,7 @@ F src/random.c 6119474a6f6917f708c1dee25b9a8e519a620e88 F src/select.c 4d68a0d7f98fb59bcedd0be69750e0445b05899c F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96 F src/shell.c 3ae4654560e91220a95738a73d135d91d937cda1 -F src/sqlite.h.in 6b7383baf76070214f6381f603328ca9b22a7fae +F src/sqlite.h.in 6217831cf911d0c4dc3d31509cc2d0750bb28f0f F src/sqlite3ext.h 832e13de075d920e2c76584e2b7af1054bb212df F src/sqliteInt.h 7a3d16cd517dfce73eeac10963275454d6421f82 F src/table.c 6d0da66dde26ee75614ed8f584a1996467088d06 @@ -121,12 +121,12 @@ F src/trigger.c 8c55d31876013ed4e97ee7ce24478fbe00db49bb F src/update.c 876b3142b8db9ce6ddf8374a2ced65e576acabc7 F src/utf.c 67ecb1032bc0b42c105e88d65ef9d9f626eb0e1f F src/util.c 8e8180ee5597f2474c1da311ff3c464b6966c0f1 -F src/vacuum.c b74b11077318f69e3ab0a474d31c3af87efa35bd +F src/vacuum.c 8bd895d29e7074e78d4e80f948e35ddc9cf2beef F src/vdbe.c b68f3a86177fa4d10512a4e276a8961d5c1e2ccf F src/vdbe.h 0025259af1939fb264a545816c69e4b5b8d52691 F src/vdbeInt.h b2ca85ca8abfbba86e380b06c7673dc81c6784c3 F src/vdbeapi.c 6cff63a5b3a52af04b2bef0f7e27ed7ea6f85183 -F src/vdbeaux.c b98177089a57f496a6a36edef038b9d5df2befdb +F src/vdbeaux.c 1a50dce809a2f5c2d32e8096166b59016dab1b45 F src/vdbefifo.c 3ca8049c561d5d67cbcb94dc909ae9bb68c0bf8f F src/vdbemem.c 58a8be2231b0b13e2e77098debe173e79d22f791 F src/vtab.c 7fbda947e28cbe7adb3ba752a76ca9ef29936750 @@ -201,7 +201,7 @@ F test/enc2.test 45710bacfa9df29720bc84c067dfdf8c8ddfb797 F test/enc3.test 890508efff6677345e93bf2a8adb0489b30df030 F test/exclusive.test 83871f52ab1015dc1bfbf86b96e2ece29094d129 F test/exclusive2.test 187993598a83257f4a1126a40d89144c01965500 -F test/exclusive3.test 278bc5107b2f64c2594b2109e4edbfd4458e5851 +F test/exclusive3.test f2d1d0ab2a83bb8326dea516e1c99b833f44d8f8 F test/expr.test c78843f730ccbe973d0c2ad1c99978f936893131 F test/fkey1.test 153004438d51e6769fb1ce165f6313972d6263ce F test/format4.test bf3bed3b13c63abfb3cfec232597a319a31d0bcc @@ -442,7 +442,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513 -P cbebfb89603044e48b3a87b79d1eefbbc5b4c8a5 -R 33506ae108a3d63410cc88f37a0bf6d6 -U drh -Z f8417d4b89ac9d4701324dc273caa2e7 +P c61c97c978dab7535c94033631f5ad2355c55057 +R 0bc45e4cb76bfeab2e890a743828ed44 +U danielk1977 +Z 0cef8b7fd227f96700de124998af2737 diff --git a/manifest.uuid b/manifest.uuid index 0bafd3b3d8..5c15326457 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c61c97c978dab7535c94033631f5ad2355c55057 \ No newline at end of file +b24a6e7b024c8b9a0b6fd15bd8f247e458781ca2 \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index ba072f6d80..be3a30a977 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -783,6 +783,7 @@ static int transferOwnership(unixFile *pFile){ ** Delete the named file */ int sqlite3UnixDelete(const char *zFilename){ + SimulateIOError(return SQLITE_IOERR_DELETE); unlink(zFilename); return SQLITE_OK; } diff --git a/src/os_win.c b/src/os_win.c index d314651392..e5cf7ad5c1 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -596,6 +596,7 @@ int sqlite3WinDelete(const char *zFilename){ if( zConverted==0 ){ return SQLITE_NOMEM; } + SimulateIOError(return SQLITE_IOERR_DELETE); if( isNT() ){ do{ rc = DeleteFileW(zConverted); diff --git a/src/pager.c b/src/pager.c index 10817125fd..16c921a4a0 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.301 2007/03/27 13:36:37 drh Exp $ +** @(#) $Id: pager.c,v 1.302 2007/03/27 16:19:52 danielk1977 Exp $ */ #ifndef SQLITE_OMIT_DISKIO #include "sqliteInt.h" @@ -479,7 +479,7 @@ static u32 retrieve32bits(PgHdr *p, int offset){ static int pager_error(Pager *pPager, int rc){ int rc2 = rc & 0xff; assert( pPager->errCode==SQLITE_FULL || pPager->errCode==SQLITE_OK ); - if( + if( rc2==SQLITE_FULL || rc2==SQLITE_IOERR || rc2==SQLITE_CORRUPT || @@ -922,29 +922,26 @@ static void pager_reset(Pager *pPager){ static int pager_unwritelock(Pager *pPager){ PgHdr *pPg; int rc = SQLITE_OK; + int rc2 = SQLITE_OK; assert( !MEMDB ); if( pPager->statestmtOpen && !pPager->exclusiveMode ){ - if( !pPager->exclusiveMode ){ - sqlite3OsClose(&pPager->stfd); - pPager->stmtOpen = 0; - }else{ - sqlite3OsTruncate(pPager->stfd, 0); - } + sqlite3OsClose(&pPager->stfd); + pPager->stmtOpen = 0; } if( pPager->journalOpen ){ if( pPager->exclusiveMode ){ - sqlite3OsTruncate(pPager->jfd, 0); + rc = sqlite3OsTruncate(pPager->jfd, 0); sqlite3OsSeek(pPager->jfd, 0); pPager->journalOff = 0; pPager->journalStarted = 0; }else{ sqlite3OsClose(&pPager->jfd); pPager->journalOpen = 0; - sqlite3OsDelete(pPager->zJournal); + rc = sqlite3OsDelete(pPager->zJournal); } sqliteFree( pPager->aInJournal ); pPager->aInJournal = 0; @@ -964,8 +961,9 @@ static int pager_unwritelock(Pager *pPager){ assert( pPager->aInJournal==0 ); assert( pPager->dirtyCache==0 || pPager->useJournal==0 ); } + if( !pPager->exclusiveMode ){ - rc = sqlite3OsUnlock(pPager->fd, SHARED_LOCK); + rc2 = sqlite3OsUnlock(pPager->fd, SHARED_LOCK); pPager->state = PAGER_SHARED; }else if( pPager->state==PAGER_SYNCED ){ pPager->state = PAGER_EXCLUSIVE; @@ -975,7 +973,8 @@ static int pager_unwritelock(Pager *pPager){ pPager->needSync = 0; pPager->pFirstSynced = pPager->pFirst; pPager->dbSize = -1; - return rc; + + return (rc==SQLITE_OK?rc2:rc); } /* @@ -1193,7 +1192,7 @@ static int pager_delmaster(const char *zMaster){ } } - sqlite3OsDelete(zMaster); + rc = sqlite3OsDelete(zMaster); delmaster_out: if( zMasterJournal ){ @@ -1417,7 +1416,7 @@ end_playback: rc = pager_unwritelock(pPager); } if( zMaster ){ - /* If there was a master journal and this routine will return true, + /* If there was a master journal and this routine will return success, ** see if it is possible to delete the master journal. */ if( rc==SQLITE_OK ){ @@ -2705,8 +2704,21 @@ static int pagerSharedLock(Pager *pPager){ ** journal file is never open unless the main database file holds ** a write lock, so there is never any chance of two or more ** processes opening the journal at the same time. + ** + ** Open the journal for read/write access. This is because in + ** exclusive-access mode the file descriptor will be kept open and + ** possibly used for a transaction later on. On some systems, the + ** OsTruncate() call used in exclusive-access mode also requires + ** a read/write file handle. */ - rc = sqlite3OsOpenReadOnly(pPager->zJournal, &pPager->jfd); + rc = SQLITE_BUSY; + if( sqlite3OsFileExists(pPager->zJournal) ){ + int ro; + rc = sqlite3OsOpenReadWrite(pPager->zJournal, &pPager->jfd, &ro); + if( ro ){ + rc = SQLITE_BUSY; + } + } if( rc!=SQLITE_OK ){ pager_unlock(pPager); return SQLITE_BUSY; @@ -2823,6 +2835,7 @@ int sqlite3PagerAcquire(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag){ pPg = pager_lookup(pPager, pgno); if( pPg==0 ){ /* The requested page is not in the page cache. */ + int nMax; int h; TEST_INCR(pPager->nMiss); if( pPager->nPagemxPage || pPager->pFirst==0 || MEMDB || @@ -2886,6 +2899,7 @@ int sqlite3PagerAcquire(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag){ if( pPager->nExtra>0 ){ memset(PGHDR_TO_EXTRA(pPg, pPager), 0, pPager->nExtra); } + nMax = sqlite3PagerPagecount(pPager); if( pPager->errCode ){ sqlite3PagerUnref(pPg); rc = pPager->errCode; @@ -2895,9 +2909,7 @@ int sqlite3PagerAcquire(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag){ /* Populate the page with data, either by reading from the database ** file, or by setting the entire page to zero. */ - if( sqlite3PagerPagecount(pPager)<(int)pgno || MEMDB - || (clrFlag && !pPager->alwaysRollback) - ){ + if( nMax<(int)pgno || MEMDB || (clrFlag && !pPager->alwaysRollback) ){ memset(PGHDR_TO_DATA(pPg), 0, pPager->pageSize); }else{ assert( MEMDB==0 ); @@ -3015,6 +3027,7 @@ int sqlite3PagerUnref(DbPage *pPg){ */ pPager->nRef--; assert( pPager->nRef>=0 ); + // assert( pPager->nRef>0 || !pPager->journalOpen || pPager->journalOff==0 ); if( pPager->nRef==0 && !pPager->exclusiveMode ){ pagerUnlockAndRollback(pPager); } @@ -3086,7 +3099,7 @@ failed_to_open_journal: ** the system will get confused, we have a read-lock on the file and a ** mysterious journal has appeared in the filesystem. */ - sqlite3OsDelete(pPager->zJournal); + /* sqlite3OsDelete(pPager->zJournal); */ }else{ pager_reset(pPager); } @@ -3611,14 +3624,14 @@ int sqlite3PagerCommit(Pager *pPager){ ** if there have been no changes to the database file. */ assert( pPager->needSync==0 ); rc = pager_unwritelock(pPager); - return rc; - } - assert( pPager->journalOpen ); - rc = sqlite3PagerSync(pPager, 0, 0); - if( rc==SQLITE_OK ){ - rc = pager_unwritelock(pPager); + }else{ + assert( pPager->journalOpen ); + rc = sqlite3PagerSync(pPager, 0, 0); + if( rc==SQLITE_OK ){ + rc = pager_unwritelock(pPager); + } } - return rc; + return pager_error(pPager, rc); } /* diff --git a/src/pager.h b/src/pager.h index 3d8dbc5cce..e92bd0693a 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.55 2007/03/24 16:45:05 danielk1977 Exp $ +** @(#) $Id: pager.h,v 1.56 2007/03/27 16:19:52 danielk1977 Exp $ */ #ifndef _PAGER_H_ @@ -136,4 +136,12 @@ void sqlite3PagerRefdump(Pager*); int pager3_refinfo_enable; #endif +#ifdef SQLITE_TEST +void disable_simulated_io_errors(void); +void enable_simulated_io_errors(void); +#else +# define disable_simulated_io_errors() +# define enable_simulated_io_errors() +#endif + #endif /* _PAGER_H_ */ diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 7b69899415..7865e66391 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -12,7 +12,7 @@ ** This header file defines the interface that the SQLite library ** presents to client programs. ** -** @(#) $Id: sqlite.h.in,v 1.198 2007/01/26 00:51:44 drh Exp $ +** @(#) $Id: sqlite.h.in,v 1.199 2007/03/27 16:19:52 danielk1977 Exp $ */ #ifndef _SQLITE3_H_ #define _SQLITE3_H_ @@ -230,6 +230,7 @@ int sqlite3_exec( #define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8)) #define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8)) #define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8)) +#define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8)) /* ** Enable or disable the extended result codes. diff --git a/src/vacuum.c b/src/vacuum.c index c86a03601b..e34a4e9737 100644 --- a/src/vacuum.c +++ b/src/vacuum.c @@ -14,7 +14,7 @@ ** Most of the code in this file may be omitted by defining the ** SQLITE_OMIT_VACUUM macro. ** -** $Id: vacuum.c,v 1.68 2007/03/27 14:44:51 drh Exp $ +** $Id: vacuum.c,v 1.69 2007/03/27 16:19:52 danielk1977 Exp $ */ #include "sqliteInt.h" #include "vdbeInt.h" @@ -83,13 +83,11 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){ char *zSql = 0; /* SQL statements */ int saved_flags; /* Saved value of the db->flags */ Db *pDb = 0; /* Database to detach at end of vacuum */ - char zTemp[SQLITE_TEMPNAME_SIZE+20]; /* Name of the TEMP file */ /* Save the current value of the write-schema flag before setting it. */ saved_flags = db->flags; db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks; - sqlite3OsTempFileName(zTemp); if( !db->autoCommit ){ sqlite3SetString(pzErrMsg, "cannot VACUUM from within a transaction", (char*)0); @@ -106,14 +104,8 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){ ** ** An optimisation would be to use a non-journaled pager. */ - zSql = sqlite3MPrintf("ATTACH '%q' AS vacuum_db;", zTemp); - if( !zSql ){ - rc = SQLITE_NOMEM; - goto end_of_vacuum; - } + zSql = "ATTACH '' AS vacuum_db;"; rc = execSql(db, zSql); - sqliteFree(zSql); - zSql = 0; if( rc!=SQLITE_OK ) goto end_of_vacuum; pDb = &db->aDb[db->nDb-1]; assert( strcmp(db->aDb[db->nDb-1].zName,"vacuum_db")==0 ); @@ -263,10 +255,6 @@ end_of_vacuum: pDb->pSchema = 0; } - sqlite3OsDelete(zTemp); - strcat(zTemp, "-journal"); - sqlite3OsDelete(zTemp); - sqliteFree( zSql ); sqlite3ResetInternalSchema(db, 0); return rc; diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 45bf4a1a5f..7172766031 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -1094,14 +1094,18 @@ static int vdbeCommit(sqlite3 *db){ } } - /* Do the commit only if all databases successfully synced */ - if( rc==SQLITE_OK ){ - for(i=0; inDb; i++){ - Btree *pBt = db->aDb[i].pBt; - if( pBt ){ - sqlite3BtreeCommit(pBt); - } + /* Do the commit only if all databases successfully synced. + ** If one of the BtreeCommit() calls fails, this indicates an IO error + ** while deleting or truncating a journal file. It is unlikely, but + ** could happen. In this case abandon processing and return the error. + */ + for(i=0; rc==SQLITE_OK && inDb; i++){ + Btree *pBt = db->aDb[i].pBt; + if( pBt ){ + rc = sqlite3BtreeCommit(pBt); } + } + if( rc==SQLITE_OK ){ sqlite3VtabCommit(db); } } @@ -1225,12 +1229,15 @@ static int vdbeCommit(sqlite3 *db){ ** but some stray 'cold' journals may be lying around. Returning an ** error code won't help matters. */ + disable_simulated_io_errors(); for(i=0; inDb; i++){ Btree *pBt = db->aDb[i].pBt; if( pBt ){ sqlite3BtreeCommit(pBt); } } + enable_simulated_io_errors(); + sqlite3VtabCommit(db); } #endif diff --git a/test/exclusive3.test b/test/exclusive3.test index 3e15f8c172..f94e120341 100644 --- a/test/exclusive3.test +++ b/test/exclusive3.test @@ -12,7 +12,7 @@ # This file runs the tests in the file ioerr.test with auto-vacuum enabled # databases. # -# $Id: exclusive3.test,v 1.1 2007/03/26 16:13:59 danielk1977 Exp $ +# $Id: exclusive3.test,v 1.2 2007/03/27 16:19:52 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -47,7 +47,7 @@ proc do_test {args} { #source $testdir/select2.test source $testdir/malloc.test -#source $testdir/ioerr.test +source $testdir/ioerr.test rename sqlite3 ""