/ Check-in [ac348ae2]
Login

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

Overview
Comment:Add extra test cases for blocking checkpoints.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | blocking-checkpoint
Files: files | file ages | folders
SHA1: ac348ae25cb0239dc525bb473cc83cdb1b3de205
User & Date: dan 2010-11-19 07:17:10
Context
2010-11-19
09:58
Add file test/tt3_checkpoint.c that adds a multi-threaded test for blocking checkpoints to threadtest3. check-in: 648dd157 user: dan tags: blocking-checkpoint
07:17
Add extra test cases for blocking checkpoints. check-in: ac348ae2 user: dan tags: blocking-checkpoint
2010-11-18
19:28
Fixes for SQLITE_BUSY handling in blocking checkpoint code. check-in: 4c663a4d user: dan tags: blocking-checkpoint
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to test/wal5.test.

   135    135   proc file_page_counts {} {
   136    136     list [db_page_count  test.db ] \
   137    137          [wal_page_count test.db ] \
   138    138          [db_page_count  test.db2] \
   139    139          [wal_page_count test.db2]
   140    140   }
   141    141   
          142  +# Test that executing "PRAGMA wal_checkpoint" checkpoints all attached
          143  +# databases, not just the main db.
          144  +#
   142    145   do_multiclient_test tn {
   143    146     setup_and_attach_aux
   144    147     do_test 2.1.$tn.1 {
   145    148       sql1 {
   146    149         CREATE TABLE t1(a, b);
   147    150         INSERT INTO t1 VALUES(1, 2);
   148    151         CREATE TABLE aux.t2(a, b);
   149    152         INSERT INTO t2 VALUES(1, 2);
   150    153       }
   151    154     } {}
   152         -
   153    155     do_test 2.2.$tn.2 { file_page_counts } {1 5 1 5}
   154    156     do_test 2.1.$tn.3 { sql1 { PRAGMA wal_checkpoint } } {0 5 5}
   155    157     do_test 2.1.$tn.4 { file_page_counts } {2 5 2 5}
   156    158   }
   157    159   
   158    160   do_multiclient_test tn {
   159         -
   160    161     setup_and_attach_aux
   161         -
   162    162     do_test 2.2.$tn.1 {
   163    163       execsql {
   164    164         CREATE TABLE t1(a, b);
   165    165         INSERT INTO t1 VALUES(1, 2);
   166    166         CREATE TABLE aux.t2(a, b);
   167    167         INSERT INTO t2 VALUES(1, 2);
   168    168         INSERT INTO t2 VALUES(3, 4);
   169    169       }
   170    170     } {}
   171         -
   172    171     do_test 2.2.$tn.2 { file_page_counts } {1 5 1 7}
   173    172     do_test 2.2.$tn.3 { sql2 { BEGIN; SELECT * FROM t1 } } {1 2}
   174    173     do_test 2.2.$tn.4 { sql1 { PRAGMA wal_checkpoint = RESTART } } {1 5 5}
   175    174     do_test 2.2.$tn.5 { file_page_counts } {2 5 2 7}
   176    175   }
   177    176   
   178    177   do_multiclient_test tn {
   179         -
   180    178     setup_and_attach_aux
   181         -
   182    179     do_test 2.3.$tn.1 {
   183    180       execsql {
   184    181         CREATE TABLE t1(a, b);
   185    182         INSERT INTO t1 VALUES(1, 2);
   186    183         CREATE TABLE aux.t2(a, b);
   187    184         INSERT INTO t2 VALUES(1, 2);
   188    185       }
   189    186     } {}
   190         -
   191    187     do_test 2.3.$tn.2 { file_page_counts } {1 5 1 5}
   192    188     do_test 2.3.$tn.3 { sql2 { BEGIN; SELECT * FROM t1 } } {1 2}
   193    189     do_test 2.3.$tn.4 { sql1 { INSERT INTO t1 VALUES(3, 4) } } {}
   194    190     do_test 2.3.$tn.5 { sql1 { INSERT INTO t2 VALUES(3, 4) } } {}
   195    191     do_test 2.3.$tn.6 { file_page_counts } {1 7 1 7}
   196         -
   197    192     do_test 2.3.$tn.7 { sql1 { PRAGMA wal_checkpoint = FULL } } {1 7 5}
   198    193     do_test 2.3.$tn.8 { file_page_counts } {1 7 2 7}
   199    194   }
   200    195   
          196  +# Check that checkpoints block on the correct locks. And respond correctly
          197  +# if they cannot obtain those locks. There are three locks that a checkpoint
          198  +# may block on (in the following order):
          199  +#
          200  +#   1. The writer lock: FULL and RESTART checkpoints block until any writer
          201  +#      process releases its lock.
          202  +#
          203  +#   2. Readers using part of the log file. FULL and RESTART checkpoints block
          204  +#      until readers using part (but not all) of the log file have finished.
          205  +#
          206  +#   3. Readers using any of the log file. After copying data into the
          207  +#      database file, RESTART checkpoints block until readers using any part
          208  +#      of the log file have finished.
          209  +#
          210  +foreach {tn1 checkpoint busy_on ckpt_expected expected} {
          211  +  1   PASSIVE   -   {0 5 5}   -
          212  +  2   TYPO      -   {0 5 5}   -
          213  +
          214  +  3   FULL      -   {0 7 7}   2
          215  +  4   FULL      1   {1 5 5}   1
          216  +  5   FULL      2   {1 7 5}   2
          217  +  6   FULL      3   {0 7 7}   2
          218  +
          219  +  7   RESTART   -   {0 7 7}   3
          220  +  8   RESTART   1   {1 5 5}   1
          221  +  9   RESTART   2   {1 7 5}   2
          222  +  10  RESTART   3   {1 7 7}   3
          223  +
          224  +} {
          225  +  do_multiclient_test tn {
          226  +    setup_and_attach_aux
          227  +  
          228  +    proc busyhandler {x} {
          229  +      set ::max_busyhandler $x
          230  +      if {$::busy_on!="-" && $x==$::busy_on} { return 1 }
          231  +      switch -- $x {
          232  +        1 { sql2 "COMMIT ; BEGIN ; SELECT * FROM t1" }
          233  +        2 { sql3 "COMMIT" }
          234  +        3 { sql2 "COMMIT" }
          235  +      }
          236  +      return 0
          237  +    }
          238  +    set ::max_busyhandler -
          239  +  
          240  +    do_test 2.4.$tn1.$tn.1 {
          241  +      sql1 {
          242  +        CREATE TABLE t1(a, b);
          243  +        INSERT INTO t1 VALUES(1, 2);
          244  +      }
          245  +      sql2 { BEGIN; INSERT INTO t1 VALUES(3, 4) }
          246  +      sql3 { BEGIN; SELECT * FROM t1 }
          247  +    } {1 2}
          248  +  
          249  +    do_test 2.4.$tn1.$tn.2 {
          250  +      code1 { db busy busyhandler }
          251  +      sql1 "PRAGMA wal_checkpoint = $checkpoint"
          252  +    } $ckpt_expected
          253  +    do_test 2.4.$tn1.$tn.3 { set ::max_busyhandler } $expected
          254  +  }
          255  +}
   201    256   
   202    257   
   203    258   finish_test
          259  +