/ Check-in [bf823217]
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:Add tests for the changes on this branch. Fix a problem with calls to the new progress indicator API made after an rbu update has been resumed.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | rbu-percent-progress
Files: files | file ages | folders
SHA1: bf82321724d3b0feb51e26d9b76090e03cc3964a
User & Date: dan 2016-03-18 10:29:47
Context
2016-03-18
18:56
Change the name of the new API on this branch to "sqlite3_bp_progress". Add tests and documentation for the same. check-in: 1a1b69e8 user: dan tags: rbu-percent-progress
10:29
Add tests for the changes on this branch. Fix a problem with calls to the new progress indicator API made after an rbu update has been resumed. check-in: bf823217 user: dan tags: rbu-percent-progress
2016-03-17
21:06
Add an API to indicate the percentage progress of an rbu update. check-in: ffc58d2c user: dan tags: rbu-percent-progress
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/rbu/rbuprogress.test.

     9      9   #
    10     10   #***********************************************************************
    11     11   #
    12     12   
    13     13   source [file join [file dirname [info script]] rbu_common.tcl]
    14     14   set ::testprefix rbuprogress
    15     15   
    16         -
    17     16   # Create a simple RBU database. That expects to write to a table:
    18     17   #
    19     18   #   CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
    20     19   #
    21     20   proc create_rbu1 {filename} {
    22     21     forcedelete $filename
    23     22     sqlite3 rbu1 $filename  
................................................................................
    54     53   do_test 1.9 { rbu step ; rbu stage_progress } {10000 10000}
    55     54   
    56     55   do_test 1.10 {
    57     56     rbu close
    58     57   } {SQLITE_DONE}
    59     58   
    60     59   #-------------------------------------------------------------------------
    61         -
    62         -proc do_sp_test {tn target rbu reslist} {
           60  +#
           61  +proc do_sp_test {tn bReopen target rbu reslist} {
    63     62     uplevel [list do_test $tn [subst -nocommands {
    64         -    sqlite3rbu rbu $target $rbu
           63  +    if {$bReopen==0} { sqlite3rbu rbu $target $rbu }
    65     64       set res [list]
    66     65       while 1 {
           66  +      if {$bReopen} { sqlite3rbu rbu $target $rbu }
    67     67         set rc [rbu step]
    68     68         if {[set rc] != "SQLITE_OK"} { error "error 1" }
    69     69         lappend res [lindex [rbu stage_progress] 0]
    70     70         if {[lindex [set res] end]==10000} break
           71  +      if {$bReopen} { rbu close }
    71     72       }
    72     73       if {[set res] != [list $reslist]} {
    73         -      error "reslist is incorrect (expect=$reslist got=[set res])"
           74  +      error "1. reslist incorrect (expect=$reslist got=[set res])"
    74     75       }
    75     76   
    76     77       # One step to clean up the temporary tables used to update the only
    77     78       # target table in the rbu database. And one more to move the *-oal 
    78         -    # file to *-wal.
           79  +    # file to *-wal. After each of these steps, the progress remains
           80  +    # at "10000 0".
           81  +    #
           82  +    rbu step
           83  +    set res [rbu stage_progress]
           84  +    if {[set res] != [list 10000 0]} {
           85  +      error "2. reslist incorrect (expect=10000 0 got=[set res])"
           86  +    }
    79     87       rbu step
    80         -    rbu step
           88  +    set res [rbu stage_progress]
           89  +    if {[set res] != [list 10000 0]} {
           90  +      error "3. reslist incorrect (expect=10000 0 got=[set res])"
           91  +    }
    81     92   
    82     93       # Do the checkpoint.
    83         -    while {[rbu step]=="SQLITE_OK"} { }
           94  +    while {[rbu step]=="SQLITE_OK"} { 
           95  +      foreach {a b} [rbu stage_progress] {}
           96  +      if {[set a]!=10000 || [set b]<=0 || [set b]>10000} {
           97  +        error "4. reslist incorrect (expect=10000 1..10000 got=[set a] [set b])"
           98  +      }
           99  +    }
          100  +
          101  +    set res [rbu stage_progress]
          102  +    if {[set res] != [list 10000 10000]} {
          103  +      error "5. reslist is incorrect (expect=10000 10000 got=[set res])"
          104  +    }
    84    105   
    85    106       rbu close
    86    107     }] {SQLITE_DONE}]
    87    108   }
    88    109   
    89    110   proc create_db_file {filename sql} {
    90    111     forcedelete $filename
    91    112     sqlite3 tmpdb $filename  
    92    113     tmpdb eval $sql
    93    114     tmpdb close
    94    115   }
    95    116   
    96         -reset_db
    97         -do_test 2.1.0 {
    98         -  execsql {
    99         -    CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
   100         -  }
   101         -  create_db_file rbu.db {
   102         -    CREATE TABLE data_t1(a, b, c, rbu_control);
   103         -    INSERT INTO data_t1 VALUES(4, 4, 4, 0);
   104         -    INSERT INTO data_t1 VALUES(5, 5, 5, 0);
          117  +foreach {bReopen} { 0 1 } {
   105    118   
   106         -    CREATE TABLE rbu_count(tbl, cnt);
   107         -    INSERT INTO rbu_count VALUES('data_t1', 2);
   108         -  }
   109         -} {}
   110         -do_sp_test 2.1.1 test.db rbu.db {5000 10000}
   111         -
   112         -reset_db
   113         -do_test 2.2.0 {
   114         -  execsql { CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c) }
   115         -  create_rbu1 rbu.db
   116         -} {rbu.db}
   117         -do_sp_test 2.2.1 test.db rbu.db {3333 6666 10000}
   118         -
   119         -reset_db
   120         -do_test 2.3.0 {
   121         -  execsql { 
   122         -    CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
   123         -    CREATE INDEX i1 ON t1(b);
   124         -    INSERT INTO t1 VALUES(1, 1, 1);
   125         -    INSERT INTO t1 VALUES(2, 2, 2);
   126         -    INSERT INTO t1 VALUES(3, 3, 3);
   127         -  }
   128         -  create_db_file rbu.db {
   129         -    CREATE TABLE data_t1(a, b, c, rbu_control);
   130         -    INSERT INTO data_t1 VALUES(4, 4, 4, 0);
   131         -    INSERT INTO data_t1 VALUES(2, NULL, NULL, 1);
   132         -    INSERT INTO data_t1 VALUES(5, NULL, NULL, 1);
   133         -
   134         -    CREATE TABLE rbu_count(tbl, cnt);
   135         -    INSERT INTO rbu_count VALUES('data_t1', 3);
   136         -  }
   137         -} {}
   138         -do_sp_test 2.3.1 test.db rbu.db {1666 3333 6000 8000 10000}
   139         -
   140         -reset_db
   141         -do_test 2.4.0 {
   142         -  execsql { 
   143         -    CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
   144         -    CREATE INDEX i1 ON t1(b);
   145         -    INSERT INTO t1 VALUES(1, 1, 1);
   146         -    INSERT INTO t1 VALUES(2, 2, 2);
   147         -    INSERT INTO t1 VALUES(3, 3, 3);
   148         -  }
   149         -  create_db_file rbu.db {
   150         -    CREATE TABLE data_t1(a, b, c, rbu_control);
   151         -    INSERT INTO data_t1 VALUES(2, 4, 4, '.xx');
   152         -
   153         -    CREATE TABLE rbu_count(tbl, cnt);
   154         -    INSERT INTO rbu_count VALUES('data_t1', 1);
   155         -  }
   156         -} {}
   157         -do_sp_test 2.4.1 test.db rbu.db {3333 6666 10000}
   158         -
   159         -reset_db
   160         -do_test 2.5.0 {
   161         -  execsql { 
   162         -    CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
   163         -    CREATE INDEX i1 ON t1(b);
   164         -    INSERT INTO t1 VALUES(1, 1, 1);
   165         -    INSERT INTO t1 VALUES(2, 2, 2);
   166         -    INSERT INTO t1 VALUES(3, 3, 3);
   167         -  }
   168         -  create_db_file rbu.db {
   169         -    CREATE TABLE data_t1(a, b, c, rbu_control);
   170         -    INSERT INTO data_t1 VALUES(4, NULL, 4, '.xx');
   171         -
   172         -    CREATE TABLE rbu_count(tbl, cnt);
   173         -    INSERT INTO rbu_count VALUES('data_t1', 1);
   174         -  }
   175         -} {}
   176         -do_sp_test 2.5.1 test.db rbu.db {10000}
          119  +  reset_db
          120  +  do_test 2.$bReopen.1.0 {
          121  +    execsql {
          122  +      CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
          123  +    }
          124  +    create_db_file rbu.db {
          125  +      CREATE TABLE data_t1(a, b, c, rbu_control);
          126  +      INSERT INTO data_t1 VALUES(4, 4, 4, 0);
          127  +      INSERT INTO data_t1 VALUES(5, 5, 5, 0);
          128  +  
          129  +      CREATE TABLE rbu_count(tbl, cnt);
          130  +      INSERT INTO rbu_count VALUES('data_t1', 2);
          131  +    }
          132  +  } {}
          133  +  do_sp_test 2.$bReopen.1.1 $bReopen test.db rbu.db {5000 10000}
          134  +  
          135  +  reset_db
          136  +  do_test 2.$bReopen.2.0 {
          137  +    execsql { CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c) }
          138  +    create_rbu1 rbu.db
          139  +  } {rbu.db}
          140  +  do_sp_test 2.$bReopen.2.1 $bReopen test.db rbu.db {3333 6666 10000}
          141  +  
          142  +  reset_db
          143  +  do_test 2.$bReopen.3.0 {
          144  +    execsql { 
          145  +      CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
          146  +      CREATE INDEX i1 ON t1(b);
          147  +      INSERT INTO t1 VALUES(1, 1, 1);
          148  +      INSERT INTO t1 VALUES(2, 2, 2);
          149  +      INSERT INTO t1 VALUES(3, 3, 3);
          150  +    }
          151  +    create_db_file rbu.db {
          152  +      CREATE TABLE data_t1(a, b, c, rbu_control);
          153  +      INSERT INTO data_t1 VALUES(4, 4, 4, 0);
          154  +      INSERT INTO data_t1 VALUES(2, NULL, NULL, 1);
          155  +      INSERT INTO data_t1 VALUES(5, NULL, NULL, 1);
          156  +  
          157  +      CREATE TABLE rbu_count(tbl, cnt);
          158  +      INSERT INTO rbu_count VALUES('data_t1', 3);
          159  +    }
          160  +  } {}
          161  +  do_sp_test 2.$bReopen.3.1 $bReopen test.db rbu.db {1666 3333 6000 8000 10000}
          162  +  
          163  +  reset_db
          164  +  do_test 2.$bReopen.4.0 {
          165  +    execsql { 
          166  +      CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
          167  +      CREATE INDEX i1 ON t1(b);
          168  +      INSERT INTO t1 VALUES(1, 1, 1);
          169  +      INSERT INTO t1 VALUES(2, 2, 2);
          170  +      INSERT INTO t1 VALUES(3, 3, 3);
          171  +    }
          172  +    create_db_file rbu.db {
          173  +      CREATE TABLE data_t1(a, b, c, rbu_control);
          174  +      INSERT INTO data_t1 VALUES(2, 4, 4, '.xx');
          175  +  
          176  +      CREATE TABLE rbu_count(tbl, cnt);
          177  +      INSERT INTO rbu_count VALUES('data_t1', 1);
          178  +    }
          179  +  } {}
          180  +  do_sp_test 2.$bReopen.4.1 $bReopen test.db rbu.db {3333 6666 10000}
          181  +  
          182  +  reset_db
          183  +  do_test 2.$bReopen.5.0 {
          184  +    execsql { 
          185  +      CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
          186  +      CREATE INDEX i1 ON t1(b);
          187  +      INSERT INTO t1 VALUES(1, 1, 1);
          188  +      INSERT INTO t1 VALUES(2, 2, 2);
          189  +      INSERT INTO t1 VALUES(3, 3, 3);
          190  +    }
          191  +    create_db_file rbu.db {
          192  +      CREATE TABLE data_t1(a, b, c, rbu_control);
          193  +      INSERT INTO data_t1 VALUES(4, NULL, 4, '.xx');
          194  +  
          195  +      CREATE TABLE rbu_count(tbl, cnt);
          196  +      INSERT INTO rbu_count VALUES('data_t1', 1);
          197  +    }
          198  +  } {}
          199  +  do_sp_test 2.$bReopen.5.1 $bReopen test.db rbu.db {10000}
          200  +}
   177    201   
   178    202   finish_test
   179    203   

Changes to ext/rbu/sqlite3rbu.c.

  3203   3203   
  3204   3204           if( pState->eStage==0 ){ 
  3205   3205             rbuDeleteOalFile(p);
  3206   3206             rbuInitPhaseOneSteps(p);
  3207   3207             p->eStage = RBU_STAGE_OAL;
  3208   3208           }else{
  3209   3209             p->eStage = pState->eStage;
         3210  +          p->nPhaseOneStep = pState->nPhaseOneStep;
  3210   3211           }
  3211   3212           p->nProgress = pState->nProgress;
  3212   3213           p->iOalSz = pState->iOalSz;
  3213   3214         }
  3214   3215       }
  3215   3216       assert( p->rc!=SQLITE_OK || p->eStage!=0 );
  3216   3217