/ Check-in [12745490]
Login

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

Overview
Comment:Run some malloc() tests with exclusive-access mode. (CVS 3717)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 127454903764daff17390941a002f527ee2ffc87
User & Date: danielk1977 2007-03-26 12:26:27
Context
2007-03-26
13:48
Avoid unnecessary calls to pager_unwritelock() when in exclusive-access mode. Add the speed2.test script to the test suite. (CVS 3718) check-in: ab53f508 user: drh tags: trunk
12:26
Run some malloc() tests with exclusive-access mode. (CVS 3717) check-in: 12745490 user: danielk1977 tags: trunk
10:27
Add some tests and fixes surrounding exclusive-access mode and the pager change-counter. (CVS 3716) check-in: 72cb2e1a user: danielk1977 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.296 2007/03/26 10:27:19 danielk1977 Exp $
           21  +** @(#) $Id: pager.c,v 1.297 2007/03/26 12:26:27 danielk1977 Exp $
    22     22   */
    23     23   #ifndef SQLITE_OMIT_DISKIO
    24     24   #include "sqliteInt.h"
    25     25   #include "os.h"
    26     26   #include "pager.h"
    27     27   #include <assert.h>
    28     28   #include <string.h>
................................................................................
   870    870   /*
   871    871   ** Execute a rollback if a transaction is active and unlock the 
   872    872   ** database file. This is a no-op if the pager has already entered
   873    873   ** the error-state.
   874    874   */
   875    875   static void pagerUnlockAndRollback(Pager *p){
   876    876     if( p->errCode ) return;
          877  +  assert( p->state>=PAGER_RESERVED || p->journalOpen==0 );
   877    878     if( p->state>=PAGER_RESERVED ){
   878    879       sqlite3PagerRollback(p);
   879    880     }
   880    881     pager_unlock(p);
   881    882     assert( p->errCode || !p->journalOpen || (p->exclusiveMode&&!p->journalOff) );
   882    883     assert( p->errCode || !p->stmtOpen || p->exclusiveMode );
   883    884   }
................................................................................
  2718   2719           /* Playback and delete the journal.  Drop the database write
  2719   2720           ** lock and reacquire the read lock.
  2720   2721           */
  2721   2722           rc = pager_playback(pPager, 1);
  2722   2723           if( rc!=SQLITE_OK ){
  2723   2724             return pager_error(pPager, rc);
  2724   2725           }
         2726  +        assert(pPager->state==PAGER_SHARED || 
         2727  +            (pPager->exclusiveMode && pPager->state>PAGER_SHARED)
         2728  +        );
  2725   2729         }
  2726   2730   
  2727   2731         if( pPager->pAll ){
  2728   2732           PgHdr *pPage1 = pager_lookup(pPager, 1);
  2729   2733           if( pPage1 ){
  2730   2734             unlinkHashChain(pPager, pPage1);
  2731   2735           }
................................................................................
  2743   2747             if( iChangeCount!=pPager->iChangeCount ){
  2744   2748               pager_reset(pPager);
  2745   2749             }
  2746   2750             pPager->iChangeCount = iChangeCount;
  2747   2751           }
  2748   2752         }
  2749   2753       }
  2750         -    pPager->state = PAGER_SHARED;
         2754  +    assert( pPager->exclusiveMode || pPager->state<=PAGER_SHARED );
         2755  +    if( pPager->state==PAGER_UNLOCK ){
         2756  +      pPager->state = PAGER_SHARED;
         2757  +    }
  2751   2758     }
  2752   2759   
  2753   2760     return rc;
  2754   2761   }
  2755   2762   
  2756   2763   /*
  2757   2764   ** Acquire a page.

Changes to test/malloc.test.

    10     10   #***********************************************************************
    11     11   # This file attempts to check the library in an out-of-memory situation.
    12     12   # When compiled with -DSQLITE_DEBUG=1, the SQLite library accepts a special
    13     13   # command (sqlite_malloc_fail N) which causes the N-th malloc to fail.  This
    14     14   # special feature is used to see what happens in the library if a malloc
    15     15   # were to really fail due to an out-of-memory situation.
    16     16   #
    17         -# $Id: malloc.test,v 1.37 2007/03/17 10:26:59 danielk1977 Exp $
           17  +# $Id: malloc.test,v 1.38 2007/03/26 12:26:27 danielk1977 Exp $
    18     18   
    19     19   set testdir [file dirname $argv0]
    20     20   source $testdir/tester.tcl
    21     21   
    22     22   # Only run these tests if memory debugging is turned on.
    23     23   #
    24     24   if {[info command sqlite_malloc_stat]==""} {
................................................................................
   330    330   }
   331    331   
   332    332   # This block tests malloc() failures that occur while opening a 
   333    333   # connection to a database.
   334    334   do_malloc_test 10 -sqlprep {
   335    335     CREATE TABLE abc(a, b, c);
   336    336   } -tclbody {
          337  +  db close
   337    338     sqlite3 db2 test.db
   338    339     db2 eval {SELECT * FROM sqlite_master}
   339    340     db2 close
   340    341   } 
   341    342   
   342    343   # This block tests malloc() failures that occur within calls to
   343    344   # sqlite3_create_function().
................................................................................
   349    350   }
   350    351   
   351    352   do_malloc_test 12 -tclbody {
   352    353     set sql16 [encoding convertto unicode "SELECT * FROM sqlite_master"]
   353    354     append sql16 "\00\00"
   354    355     set ::STMT [sqlite3_prepare16 $::DB $sql16 -1 DUMMY]
   355    356     sqlite3_finalize $::STMT
   356         -} 
          357  +}
   357    358   
   358    359   # Test malloc errors when replaying two hot journals from a 2-file 
   359    360   # transaction.
   360    361   ifcapable crashtest {
   361    362     do_malloc_test 13 -tclprep {
   362    363       set rc [crashsql -delay 1 -file test2.db {
   363    364         ATTACH 'test2.db' as aux;

Changes to test/quick.test.

     2      2   #    May you do good and not evil.
     3      3   #    May you find forgiveness for yourself and forgive others.
     4      4   #    May you share freely, never taking more than you give.
     5      5   #
     6      6   #***********************************************************************
     7      7   # This file runs all tests.
     8      8   #
     9         -# $Id: quick.test,v 1.48 2007/03/17 10:26:59 danielk1977 Exp $
            9  +# $Id: quick.test,v 1.49 2007/03/26 12:26:27 danielk1977 Exp $
    10     10   
    11     11   proc lshift {lvar} {
    12     12     upvar $lvar l
    13     13     set ret [lindex $l 0]
    14     14     set l [lrange $l 1 end]
    15     15     return $ret
    16     16   }
................................................................................
    40     40     btree3.test
    41     41     btree4.test
    42     42     btree5.test
    43     43     btree6.test
    44     44     corrupt.test
    45     45     crash.test
    46     46     crash2.test
           47  +  exclusive3.test
    47     48     loadext.test
    48     49     malloc.test
    49     50     malloc2.test
    50     51     malloc3.test
    51     52     memleak.test
    52     53     misuse.test
    53     54     quick.test