/ Check-in [480a5090]
Login

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

Overview
Comment:Fix test cases. Avoid unnecessary tests for MemPage.nFree less than zero.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | deferred-free-space
Files: files | file ages | folders
SHA3-256: 480a5090befdc29eaeb6f0b22831c980d6ee92438d9b2e766de68b037ded38b8
User & Date: drh 2019-02-11 17:22:30
Context
2019-02-11
19:27
Improvements to comments. No changes to code. check-in: 16eb0fc8 user: drh tags: deferred-free-space
17:22
Fix test cases. Avoid unnecessary tests for MemPage.nFree less than zero. check-in: 480a5090 user: drh tags: deferred-free-space
12:51
Updates to a comment to keep it in alignment to the changes on this branch. check-in: 7499f743 user: drh tags: deferred-free-space
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

  7221   7221     Pgno pgnoNew;                        /* Page number of pNew */
  7222   7222   
  7223   7223     assert( sqlite3_mutex_held(pPage->pBt->mutex) );
  7224   7224     assert( sqlite3PagerIswriteable(pParent->pDbPage) );
  7225   7225     assert( pPage->nOverflow==1 );
  7226   7226     
  7227   7227     if( pPage->nCell==0 ) return SQLITE_CORRUPT_BKPT;  /* dbfuzz001.test */
  7228         -  if( pPage->nFree<0 ){
  7229         -    rc = btreeComputeFreeSpace(pPage);
  7230         -    if( rc ) return rc;
  7231         -  }
  7232         -  if( pParent->nFree<0 ){
  7233         -    rc = btreeComputeFreeSpace(pParent);
  7234         -    if( rc ) return rc;
  7235         -  }
  7236         -
         7228  +  assert( pPage->nFree>=0 );
         7229  +  assert( pParent->nFree>=0 );
  7237   7230   
  7238   7231     /* Allocate a new page. This page will become the right-sibling of 
  7239   7232     ** pPage. Make the parent page writable, so that the new divider cell
  7240   7233     ** may be inserted. If both these operations are successful, proceed.
  7241   7234     */
  7242   7235     rc = allocateBtreePage(pBt, &pNew, &pgnoNew, 0, 0);
  7243   7236   
................................................................................
  7507   7500     */
  7508   7501     assert( pParent->nOverflow==0 || pParent->nOverflow==1 );
  7509   7502     assert( pParent->nOverflow==0 || pParent->aiOvfl[0]==iParentIdx );
  7510   7503   
  7511   7504     if( !aOvflSpace ){
  7512   7505       return SQLITE_NOMEM_BKPT;
  7513   7506     }
  7514         -  if( pParent->nFree<0 ){
  7515         -    rc = btreeComputeFreeSpace(pParent);
  7516         -    if( rc ) return rc;
  7517         -  }
         7507  +  assert( pParent->nFree>=0 );
  7518   7508   
  7519   7509     /* Find the sibling pages to balance. Also locate the cells in pParent 
  7520   7510     ** that divide the siblings. An attempt is made to find NN siblings on 
  7521   7511     ** either side of pPage. More siblings are taken from one side, however, 
  7522   7512     ** if there are fewer than NN siblings on the other side. If pParent
  7523   7513     ** has NB or fewer children then all children of pParent are taken.  
  7524   7514     **
................................................................................
  8332   8322       }else if( pPage->nOverflow==0 && pPage->nFree<=nMin ){
  8333   8323         break;
  8334   8324       }else{
  8335   8325         MemPage * const pParent = pCur->apPage[iPage-1];
  8336   8326         int const iIdx = pCur->aiIdx[iPage-1];
  8337   8327   
  8338   8328         rc = sqlite3PagerWrite(pParent->pDbPage);
         8329  +      if( rc==SQLITE_OK && pParent->nFree<0 ){
         8330  +        rc = btreeComputeFreeSpace(pParent);
         8331  +      }
  8339   8332         if( rc==SQLITE_OK ){
  8340   8333   #ifndef SQLITE_OMIT_QUICKBALANCE
  8341   8334           if( pPage->intKeyLeaf
  8342   8335            && pPage->nOverflow==1
  8343   8336            && pPage->aiOvfl[0]==pPage->nCell
  8344   8337            && pParent->pgno!=1
  8345   8338            && pParent->nCell==iIdx

Changes to test/corrupt2.test.

    91     91     set f [open corrupt.db RDWR]
    92     92     fconfigure $f -encoding binary
    93     93     seek $f 101 start
    94     94     puts -nonewline $f "\xFF\xFF"
    95     95     close $f
    96     96   
    97     97     sqlite3 db2 corrupt.db
    98         -  catchsql "
    99         -    $::presql
   100         -    SELECT * FROM sqlite_master;
   101         -  " db2
   102         -} {1 {database disk image is malformed}}
           98  +  # Note: This test is no longer meaningful due to the deferred computation
           99  +  # of MemPage.nFree 
          100  +  catchsql {PRAGMA quick_check} db2
          101  +} {0 {{*** in database main ***
          102  +Page 1: free space corruption}}}
   103    103   
   104    104   do_test corrupt2-1.5 {
   105    105     db2 close
   106    106   
   107    107     # Corrupt the free-block list on page 1.
   108    108     forcedelete corrupt.db
   109    109     forcedelete corrupt.db-journal
................................................................................
   114    114     puts -nonewline $f "\x00\xC8"
   115    115     seek $f 200 start
   116    116     puts -nonewline $f "\x00\x00"
   117    117     puts -nonewline $f "\x10\x00"
   118    118     close $f
   119    119   
   120    120     sqlite3 db2 corrupt.db
   121         -  catchsql "
   122         -    $::presql
   123         -    SELECT * FROM sqlite_master;
   124         -  " db2
   125         -} {1 {database disk image is malformed}}
          121  +  catchsql {PRAGMA quick_check} db2
          122  +} {0 {{*** in database main ***
          123  +Page 1: free space corruption}}}
   126    124   db2 close
   127    125   
   128    126   # Corrupt a database by having 2 indices of the same name:
   129    127   do_test corrupt2-2.1 {
   130    128   
   131    129     forcedelete corrupt.db
   132    130     forcedelete corrupt.db-journal

Changes to test/corruptD.test.

   107    107   #-------------------------------------------------------------------------
   108    108   # The following tests, corruptD-1.1.*, focus on the page header field
   109    109   # containing the offset of the first free block in a page. 
   110    110   #
   111    111   do_test corruptD-1.1.1 {
   112    112     incr_change_counter
   113    113     hexio_write test.db [expr 1024+1] FFFF
   114         -  catchsql { SELECT * FROM t1 ORDER BY rowid }
   115         -} {1 {database disk image is malformed}}
          114  +  catchsql { PRAGMA quick_check }
          115  +} {0 {{*** in database main ***
          116  +Page 2: free space corruption}}}
   116    117   do_test corruptD-1.1.2 {
   117    118     incr_change_counter
   118    119     hexio_write test.db [expr 1024+1] [hexio_render_int32 1021]
   119    120     catchsql { SELECT * FROM t1 ORDER BY rowid }
   120    121   } {1 {database disk image is malformed}}
   121    122   
   122    123   #-------------------------------------------------------------------------

Changes to test/corruptK.test.

    64     64     seek $fd 30
    65     65     puts -nonewline $fd "\x18"
    66     66     close $fd
    67     67   } {}
    68     68   do_execsql_test 1.3 {
    69     69     INSERT INTO t1 VALUES(randomblob(20));
    70     70   }
           71  +
           72  +# This test no longer functions due to the deferred computation of
           73  +# MemPage.nFree.
           74  +#
           75  +if 0 {
    71     76   do_catchsql_test 1.4 {
    72     77     INSERT INTO t1 VALUES(randomblob(90));
    73     78   } {1 {database disk image is malformed}}
           79  +}
    74     80   
    75     81   #-------------------------------------------------------------------------
    76     82   reset_db
    77     83   do_execsql_test 2.1 {
    78     84     PRAGMA page_size=1024;
    79     85     PRAGMA auto_vacuum=0;
    80     86     CREATE TABLE t1(x);