/ Check-in [22e10cc2]
Login

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

Overview
Comment:If an IO error is encountered on a commit, close the journal so that it persists and can (hopefully) rollback the failed transaction later. (CVS 3792)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 22e10cc24e4407feb276abfa8cc9964f20c6e54a
User & Date: drh 2007-04-02 11:22:22
Context
2007-04-02
12:22
In the amalgamation, put date.c before os.c so that the time_t typedef can be correctly resolved by windows compilers. (CVS 3793) check-in: 9c5697c7 user: drh tags: trunk
11:22
If an IO error is encountered on a commit, close the journal so that it persists and can (hopefully) rollback the failed transaction later. (CVS 3792) check-in: 22e10cc2 user: drh tags: trunk
11:08
Correctly handle the obscure case of a read-only hot-journal file. (CVS 3791) check-in: 4d8c6bf4 user: danielk1977 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.315 2007/04/02 11:08:59 danielk1977 Exp $
           21  +** @(#) $Id: pager.c,v 1.316 2007/04/02 11:22:22 drh Exp $
    22     22   */
    23     23   #ifndef SQLITE_OMIT_DISKIO
    24     24   #include "sqliteInt.h"
    25     25   #include "os.h"
    26     26   #include "pager.h"
    27     27   #include <assert.h>
    28     28   #include <string.h>
................................................................................
   938    938     }
   939    939     sqlite3PagerStmtCommit(pPager);
   940    940     if( pPager->stmtOpen && !pPager->exclusiveMode ){
   941    941       sqlite3OsClose(&pPager->stfd);
   942    942       pPager->stmtOpen = 0;
   943    943     }
   944    944     if( pPager->journalOpen ){
   945         -    if( pPager->exclusiveMode ){
   946         -      rc = sqlite3OsTruncate(pPager->jfd, 0);
          945  +    if( pPager->exclusiveMode 
          946  +          && (rc = sqlite3OsTruncate(pPager->jfd, 0))==SQLITE_OK ){;
   947    947         sqlite3OsSeek(pPager->jfd, 0);
   948    948         pPager->journalOff = 0;
   949    949         pPager->journalStarted = 0;
   950    950       }else{
   951    951         sqlite3OsClose(&pPager->jfd);
   952    952         pPager->journalOpen = 0;
   953         -      /* If this is a temporary pager file, then the journal file should
   954         -      ** have been configured as delete-on-close. Otherwise, it should still
   955         -      ** be in the file system. This pager still holds a RESERVED or greater
   956         -      ** lock on the database file, so there is no chance another process
   957         -      ** could create or remove a journal file.
   958         -      **
   959         -      ** These asserts are not valid for asynchronous I/O such as is found
   960         -      ** in async.test
   961         -      */
   962         -      /*assert( sqlite3OsFileExists(pPager->zJournal) || pPager->tempFile );*/
   963         -      /*assert( !sqlite3OsFileExists(pPager->zJournal) || !pPager->tempFile );*/
   964         -      if( !pPager->tempFile ){
          953  +      if( rc==SQLITE_OK ){
   965    954           rc = sqlite3OsDelete(pPager->zJournal);
   966    955         }
   967    956       }
   968    957       sqliteFree( pPager->aInJournal );
   969    958       pPager->aInJournal = 0;
   970    959       for(pPg=pPager->pAll; pPg; pPg=pPg->pNextAll){
   971    960         pPg->inJournal = 0;
................................................................................
  3184   3173       }
  3185   3174     }
  3186   3175     return rc;
  3187   3176   
  3188   3177   failed_to_open_journal:
  3189   3178     sqliteFree(pPager->aInJournal);
  3190   3179     pPager->aInJournal = 0;
  3191         -#if 0
  3192         -  if( rc==SQLITE_NOMEM ){
  3193         -    /* If this was a malloc() failure, then we will not be closing the pager
  3194         -    ** file. So delete any journal file we may have just created. Otherwise,
  3195         -    ** the system will get confused, we have a read-lock on the file and a
  3196         -    ** mysterious journal has appeared in the filesystem.
  3197         -    */
  3198         -    /* sqlite3OsDelete(pPager->zJournal); */
  3199         -  }else{
  3200         -    /* If we reset the pager here, we will delete pages out from under
  3201         -    ** various cursors and will ultimately segfault. */
  3202         -    /* pager_reset(pPager); */
  3203         -  }
  3204         -#endif
  3205   3180     return rc;
  3206   3181   }
  3207   3182   
  3208   3183   /*
  3209   3184   ** Acquire a write-lock on the database.  The lock is removed when
  3210   3185   ** the any of the following happen:
  3211   3186   **