/ Check-in [a2ba61d9]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:The hasHotJournal() fix of check-in (6687) causes some minor problems in various alternative operating modes, such as locking_mode=EXCLUSIVE. This additional patch attempts to fix those concerns. Ticket #3883. (CVS 6688)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:a2ba61d927a06c390a9a818a013328092b802222
User & Date: drh 2009-05-29 10:55:30
Context
2009-05-29
11:57
Still more refinements to the hasHotJournal() fix of ticket #3883. (CVS 6689) check-in: 726b425e user: drh tags: trunk
10:55
The hasHotJournal() fix of check-in (6687) causes some minor problems in various alternative operating modes, such as locking_mode=EXCLUSIVE. This additional patch attempts to fix those concerns. Ticket #3883. (CVS 6688) check-in: a2ba61d9 user: drh tags: trunk
00:30
Modify the hasHotJournal() routine to return a false-positive if it is unable to open the journal file to check its header due to a race condition. Processing downstream of hasHotJournal() already knows how to deal with false-positives. Ticket #3883. (CVS 6687) check-in: d6b5d8e1 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/pager.c.

    14     14   ** The pager is used to access a database disk file.  It implements
    15     15   ** atomic commit and rollback through the use of a journal file that
    16     16   ** is separate from the database file.  The pager also implements file
    17     17   ** locking to prevent two processes from writing the same database
    18     18   ** file simultaneously, or one process from reading the database while
    19     19   ** another is writing.
    20     20   **
    21         -** @(#) $Id: pager.c,v 1.588 2009/05/29 00:30:30 drh Exp $
           21  +** @(#) $Id: pager.c,v 1.589 2009/05/29 10:55:30 drh Exp $
    22     22   */
    23     23   #ifndef SQLITE_OMIT_DISKIO
    24     24   #include "sqliteInt.h"
    25     25   
    26     26   /*
    27     27   ** Macros for troubleshooting.  Normally turned off
    28     28   */
................................................................................
  3401   3401         ** then delete the journal file. See the header comment above for 
  3402   3402         ** the reasoning here.  Delete the obsolete journal file under
  3403   3403         ** a RESERVED lock to avoid race conditions.
  3404   3404         */
  3405   3405         rc = sqlite3PagerPagecount(pPager, &nPage);
  3406   3406         if( rc==SQLITE_OK ){
  3407   3407           if( nPage==0 ){
  3408         -          if( sqlite3OsLock(pPager->fd, RESERVED_LOCK)==SQLITE_OK ){
         3408  +          sqlite3BeginBenignMalloc();
         3409  +          if( pPager->exclusiveMode
         3410  +                 ||  sqlite3OsLock(pPager->fd, RESERVED_LOCK)==SQLITE_OK ){
  3409   3411               sqlite3OsDelete(pVfs, pPager->zJournal, 0);
  3410         -            sqlite3OsUnlock(pPager->fd, SHARED_LOCK);
         3412  +            if( !pPager->exclusiveMode ){
         3413  +              sqlite3OsUnlock(pPager->fd, SHARED_LOCK);
         3414  +            }
  3411   3415             }
         3416  +          sqlite3EndBenignMalloc();
  3412   3417           }else{
  3413   3418             /* The journal file exists and no other connection has a reserved
  3414   3419             ** or greater lock on the database file. Now check that there is
  3415   3420             ** at least one non-zero bytes at the start of the journal file.
  3416   3421             ** If there is, then we consider this journal to be hot. If not, 
  3417   3422             ** it can be ignored.
  3418   3423             */
................................................................................
  3422   3427               u8 first = 0;
  3423   3428               rc = sqlite3OsRead(pPager->jfd, (void *)&first, 1, 0);
  3424   3429               if( rc==SQLITE_IOERR_SHORT_READ ){
  3425   3430                 rc = SQLITE_OK;
  3426   3431               }
  3427   3432               sqlite3OsClose(pPager->jfd);
  3428   3433               *pExists = (first!=0);
  3429         -          }else{
         3434  +          }else if( rc==SQLITE_CANTOPEN ){
  3430   3435               /* If we cannot open the rollback journal file in order to see if
  3431   3436               ** its has a zero header, that might be due to an I/O error, or
  3432   3437               ** it might be due to the race condition described above and in
  3433   3438               ** ticket #3883.  Either way, assume that the journal is hot.
  3434   3439               ** This might be a false positive.  But if it is, then the
  3435   3440               ** automatic journal playback and recovery mechanism will deal
  3436   3441               ** with it under an EXCLUSIVE lock where we do not need to