/ Check-in [66ac7aea]
Login

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

Overview
Comment:Open the journal file for read-only when doing a playback. Ticket #351. (CVS 1019)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:66ac7aea3df8533a49c8c05ba57c5a7015626828
User & Date: drh 2003-06-14 11:42:58
Context
2003-06-14
12:04
Bug fix: sqliteFree() called twice on the same allocation during error handling in attach.c. (CVS 1020) check-in: 9ec40935 user: drh tags: trunk
11:42
Open the journal file for read-only when doing a playback. Ticket #351. (CVS 1019) check-in: 66ac7aea user: drh tags: trunk
2003-06-12
08:59
Added missing error string to sqlite_error_string(). (CVS 1018) check-in: 3afb7b35 user: jplyon 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.84 2003/06/04 16:24:40 drh Exp $
           21  +** @(#) $Id: pager.c,v 1.85 2003/06/14 11:42:58 drh Exp $
    22     22   */
    23     23   #include "os.h"         /* Must be first to enable large file support */
    24     24   #include "sqliteInt.h"
    25     25   #include "pager.h"
    26     26   #include <assert.h>
    27     27   #include <string.h>
    28     28   
................................................................................
  1217   1217         return rc;
  1218   1218       }
  1219   1219       pPager->state = SQLITE_READLOCK;
  1220   1220   
  1221   1221       /* If a journal file exists, try to play it back.
  1222   1222       */
  1223   1223       if( pPager->useJournal && sqliteOsFileExists(pPager->zJournal) ){
  1224         -       int rc, dummy;
         1224  +       int rc;
  1225   1225   
  1226   1226          /* Get a write lock on the database
  1227   1227          */
  1228   1228          rc = sqliteOsWriteLock(&pPager->fd);
  1229   1229          if( rc!=SQLITE_OK ){
  1230   1230            if( sqliteOsUnlock(&pPager->fd)!=SQLITE_OK ){
  1231   1231              /* This should never happen! */
  1232   1232              rc = SQLITE_INTERNAL;
  1233   1233            }
  1234   1234            return rc;
  1235   1235          }
  1236   1236          pPager->state = SQLITE_WRITELOCK;
  1237   1237   
  1238         -       /* Open the journal for exclusive access.  Return SQLITE_BUSY if
  1239         -       ** we cannot get exclusive access to the journal file. 
         1238  +       /* Open the journal for reading only.  Return SQLITE_BUSY if
         1239  +       ** we are unable to open the journal file. 
  1240   1240          **
  1241         -       ** Even though we will only be reading from the journal, not writing,
  1242         -       ** we have to open the journal for writing in order to obtain an
  1243         -       ** exclusive access lock.
         1241  +       ** The journal file does not need to be locked itself.  The
         1242  +       ** journal file is never open unless the main database file holds
         1243  +       ** a write lock, so there is never any chance of two or more
         1244  +       ** processes opening the journal at the same time.
  1244   1245          */
  1245         -       rc = sqliteOsOpenReadWrite(pPager->zJournal, &pPager->jfd, &dummy);
         1246  +       rc = sqliteOsOpenReadOnly(pPager->zJournal, &pPager->jfd);
  1246   1247          if( rc!=SQLITE_OK ){
  1247   1248            rc = sqliteOsUnlock(&pPager->fd);
  1248   1249            assert( rc==SQLITE_OK );
  1249   1250            return SQLITE_BUSY;
  1250   1251          }
  1251   1252          pPager->journalOpen = 1;
  1252   1253          pPager->journalStarted = 0;