/ Check-in [197d00d6]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Activate test cases for new journal format. (CVS 1687)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 197d00d6a6a440848a0b4710157272558868221c
User & Date: danielk1977 2004-06-25 06:23:23
Context
2004-06-25
07:21
Add a comment on the implementation of sqlite3OsLock(). No code changes. (CVS 1688) check-in: 084f3fff user: danielk1977 tags: trunk
06:23
Activate test cases for new journal format. (CVS 1687) check-in: 197d00d6 user: danielk1977 tags: trunk
02:38
Modifications to the journal format to make it more robust. (CVS 1686) check-in: 504246a1 user: danielk1977 tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_test.c.

   186    186         if( rc!=SQLITE_OK ) return rc;
   187    187       }
   188    188     }
   189    189   
   190    190     return SQLITE_OK;
   191    191   }
   192    192   
   193         -/* #define TRACE_WRITECACHE  */
          193  +/* #define TRACE_WRITECACHE */
   194    194   
   195    195   /*
   196    196   ** Write the cache of pFile to disk. If crash is non-zero, randomly
   197    197   ** skip blocks when writing. The cache is deleted before returning.
   198    198   */
   199    199   static int writeCache2(OsTestFile *pFile, int crash){
   200    200     int i;
................................................................................
   208    208       if( p ){
   209    209         int skip = 0;
   210    210         int trash = 0;
   211    211         if( crash ){
   212    212           char random;
   213    213           sqlite3Randomness(1, &random);
   214    214           if( random & 0x01 ){
   215         -          if( 0 && random & 0x02 ){
          215  +          if( random & 0x02 ){
   216    216               trash = 1;
   217    217   #ifdef TRACE_WRITECACHE
   218    218   printf("Trashing block %d of %s\n", i, pFile->zName); 
   219    219   #endif
   220    220             }else{
   221    221               skip = 1;
   222    222   #ifdef TRACE_WRITECACHE
................................................................................
   261    261   */
   262    262   static int writeCache(OsTestFile *pFile){
   263    263     if( pFile->apBlk ){
   264    264       int c = crashRequired(pFile->zName);
   265    265       if( c ){
   266    266         OsTestFile *p;
   267    267   #ifdef TRACE_WRITECACHE
   268         -      printf("Crash during sync of %s\n", pFile->zName);
          268  +      printf("\nCrash during sync of %s\n", pFile->zName);
   269    269   #endif
   270    270         for(p=pAllFiles; p; p=p->pNext){
   271    271           writeCache2(p, 1);
   272    272         }
   273    273         exit(-1);
   274    274       }else{
   275    275         return writeCache2(pFile, 0);

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.138 2004/06/25 02:38:55 danielk1977 Exp $
           21  +** @(#) $Id: pager.c,v 1.139 2004/06/25 06:23:23 danielk1977 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   
................................................................................
  2042   2042             /* If in full-sync mode, write a new journal header into the
  2043   2043   	  ** journal file. This is done to avoid ever modifying a journal
  2044   2044   	  ** header that is involved in the rollback of pages that have
  2045   2045   	  ** already been written to the database (in case the header is
  2046   2046   	  ** trashed when the nRec field is updated).
  2047   2047             */
  2048   2048             pPager->nRec = 0;
         2049  +          assert( pPager->journalOff > 0 );
  2049   2050             rc = writeJournalHdr(pPager);
  2050   2051             if( rc!=0 ){
  2051   2052               sqlite3pager_rollback(pPager);
  2052   2053               return SQLITE_IOERR;
  2053   2054             }
  2054   2055           }
  2055   2056           pPg = pPager->pFirst;

Changes to test/crash.test.

     6      6   #    May you do good and not evil.
     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.
    12     12   #
    13         -# $Id: crash.test,v 1.3 2004/06/23 10:43:15 danielk1977 Exp $
           13  +# $Id: crash.test,v 1.4 2004/06/25 06:23:23 danielk1977 Exp $
    14     14   
    15     15   set testdir [file dirname $argv0]
    16     16   source $testdir/tester.tcl
    17     17   
    18     18   set repeats 100
    19         -# set repeats 5
           19  +# set repeats 10
    20     20   
    21     21   # This proc execs a seperate process that crashes midway through executing
    22     22   # the SQL script $sql on database test.db.
    23     23   #
    24     24   # The crash occurs during a sync() of file $crashfile. When the crash
    25     25   # occurs a random subset of all unsynced writes made by the process are
    26     26   # written into the files on disk. Argument $crashdelay indicates the
................................................................................
    33     33   # occured.
    34     34   proc crashsql {crashdelay crashfile sql} {
    35     35     set cfile [file join [pwd] $crashfile]
    36     36   
    37     37     set f [open crash.tcl w]
    38     38     puts $f "sqlite3_crashparams $crashdelay $cfile"
    39     39     puts $f "sqlite3 db test.db"
    40         -  puts $f "db eval {pragma full_synchronous = 1}"
           40  +  puts $f "db eval {pragma synchronous = full}"
           41  +  puts $f "db eval {pragma cache_size = 10}"
    41     42     puts $f "db eval {"
    42     43     puts $f   "$sql"
    43     44     puts $f "}"
    44     45     close $f
    45     46   
    46     47     set r [catch {
    47         -    exec [file join . crashtest] crash.tcl
           48  +    exec [file join . crashtest] crash.tcl >@stdout
    48     49     } msg]
    49     50     lappend r $msg
    50     51   }
    51     52   
    52     53   # The following procedure computes a "signature" for table "abc".  If
    53     54   # abc changes in any way, the signature should change.  
    54     55   proc signature {} {
    55     56     return [db eval {SELECT count(*), md5sum(a), md5sum(b), md5sum(c) FROM abc}]
    56     57   }
    57     58   proc signature2 {} {
    58     59     return [db eval {SELECT count(*), md5sum(a), md5sum(b), md5sum(c) FROM abc2}]
    59     60   }
    60     61   
    61         -# Use a small pager-cache for these tests.
    62         -do_test crash-0.1 {
    63         -  execsql { pragma default_cache_size = 10 }
    64         -} {}
    65         -
    66     62   #--------------------------------------------------------------------------
    67     63   # Simple crash test:
    68     64   #
    69     65   # crash-1.1: Create a database with a table with two rows.
    70     66   # crash-1.2: Run a 'DELETE FROM abc WHERE a = 1' that crashes during
    71     67   #            the first journal-sync.
    72     68   # crash-1.3: Ensure the database is in the same state as after crash-1.1.
    73     69   # crash-1.4: Run a 'DELETE FROM abc WHERE a = 1' that crashes during
    74     70   #            the first database-sync.
    75     71   # crash-1.5: Ensure the database is in the same state as after crash-1.1.
           72  +# crash-1.6: Run a 'DELETE FROM abc WHERE a = 1' that crashes during
           73  +#            the second journal-sync.
           74  +# crash-1.7: Ensure the database is in the same state as after crash-1.1.
    76     75   #
    77         -# Tests 1.6 through 1.9 are the same as 1.2 through 1.5, except the crash
    78         -# is requested on the second sync of each file. This doesn't happen in
    79         -# such a small test case, so these tests are just to verify that the
    80         -# test infrastructure operates as expected.
           76  +# Tests 1.8 through 1.11 test for crashes on the third journal sync and
           77  +# second database sync.  Neither of these is required in such a small test
           78  +# case, so these tests are just to verify that the test infrastructure
           79  +# operates as expected.
    81     80   #
    82     81   do_test crash-1.1 {
    83     82     execsql {
    84     83       CREATE TABLE abc(a, b, c);
    85     84       INSERT INTO abc VALUES(1, 2, 3);
    86     85       INSERT INTO abc VALUES(4, 5, 6);
    87     86     }
................................................................................
    89     88     expr 0
    90     89   } {0}
    91     90   do_test crash-1.2 {
    92     91     crashsql 1 test.db-journal {
    93     92       DELETE FROM abc WHERE a = 1;
    94     93     }
    95     94   } {1 {child process exited abnormally}}
    96         -
    97         -# exit
    98         -
    99     95   do_test crash-1.3 {
   100     96     signature
   101     97   } $::sig
   102     98   do_test crash-1.4 {
   103     99     crashsql 1 test.db {
   104    100       DELETE FROM abc WHERE a = 1;
   105    101     }
................................................................................
   107    103   do_test crash-1.5 {
   108    104     signature
   109    105   } $::sig
   110    106   do_test crash-1.6 {
   111    107     crashsql 2 test.db-journal {
   112    108       DELETE FROM abc WHERE a = 1;
   113    109     }
   114         -} {0 {}}
          110  +} {1 {child process exited abnormally}}
   115    111   do_test crash-1.7 {
   116    112     catchsql {
   117    113       SELECT * FROM abc;
   118    114     }
   119         -} {0 {4 5 6}}
          115  +} {0 {1 2 3 4 5 6}}
          116  +
   120    117   do_test crash-1.8 {
          118  +  crashsql 3 test.db-journal {
          119  +    DELETE FROM abc WHERE a = 1;
          120  +  }
          121  +} {0 {}}
          122  +do_test crash-1.9 {
          123  +  catchsql {
          124  +    SELECT * FROM abc;
          125  +  }
          126  +} {0 {4 5 6}}
          127  +do_test crash-1.10 {
   121    128     crashsql 2 test.db {
   122    129       DELETE FROM abc WHERE a = 4;
   123    130     }
   124    131   } {0 {}}
   125         -do_test crash-1.9 {
          132  +do_test crash-1.11 {
   126    133     catchsql {
   127    134       SELECT * FROM abc;
   128    135     }
   129    136   } {0 {}}
   130    137   
   131    138   #--------------------------------------------------------------------------
   132    139   # The following tests test recovery when both the database file and the the
................................................................................
   222    229   # crash-4.3.*: Test recovery when crash occurs during sync() of the master
   223    230   #              journal file. 
   224    231   #
   225    232   do_test crash-4.0 {
   226    233     file delete -force test2.db
   227    234     file delete -force test2.db-journal
   228    235     sqlite3 db2 test2.db
   229         -  execsql {pragma default_cache_size = 10} db2
          236  +  execsql {
          237  +    pragma default_cache_size = 10;
          238  +    pragma default_synchronous = full;
          239  +  } db2
   230    240     db2 close
   231    241     execsql {
   232    242       ATTACH 'test2.db' AS aux;
   233    243       CREATE TABLE aux.abc2 AS SELECT 2*a as a, 2*b as b, 2*c as c FROM abc;
   234    244     }
   235    245     expr [file size test2.db] / 1024
   236    246   } {559}
................................................................................
   298    308       signature
   299    309     } $sig
   300    310     do_test crash-4.3.$i.3 {
   301    311       signature2
   302    312     } $sig2
   303    313   }
   304    314   
   305         -finish_test
   306    315