SQLite

Check-in [1274549037]
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
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 127454903764daff17390941a002f527ee2ffc87
User & Date: danielk1977 2007-03-26 12:26:27.000
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: ab53f50863 user: drh tags: trunk)
12:26
Run some malloc() tests with exclusive-access mode. (CVS 3717) (check-in: 1274549037 user: danielk1977 tags: trunk)
10:27
Add some tests and fixes surrounding exclusive-access mode and the pager change-counter. (CVS 3716) (check-in: 72cb2e1a73 user: danielk1977 tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/pager.c.
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
** The pager is used to access a database disk file.  It implements
** atomic commit and rollback through the use of a journal file that
** is separate from the database file.  The pager also implements file
** locking to prevent two processes from writing the same database
** file simultaneously, or one process from reading the database while
** another is writing.
**
** @(#) $Id: pager.c,v 1.296 2007/03/26 10:27:19 danielk1977 Exp $
*/
#ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h"
#include "os.h"
#include "pager.h"
#include <assert.h>
#include <string.h>







|







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
** The pager is used to access a database disk file.  It implements
** atomic commit and rollback through the use of a journal file that
** is separate from the database file.  The pager also implements file
** locking to prevent two processes from writing the same database
** file simultaneously, or one process from reading the database while
** another is writing.
**
** @(#) $Id: pager.c,v 1.297 2007/03/26 12:26:27 danielk1977 Exp $
*/
#ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h"
#include "os.h"
#include "pager.h"
#include <assert.h>
#include <string.h>
870
871
872
873
874
875
876

877
878
879
880
881
882
883
/*
** Execute a rollback if a transaction is active and unlock the 
** database file. This is a no-op if the pager has already entered
** the error-state.
*/
static void pagerUnlockAndRollback(Pager *p){
  if( p->errCode ) return;

  if( p->state>=PAGER_RESERVED ){
    sqlite3PagerRollback(p);
  }
  pager_unlock(p);
  assert( p->errCode || !p->journalOpen || (p->exclusiveMode&&!p->journalOff) );
  assert( p->errCode || !p->stmtOpen || p->exclusiveMode );
}







>







870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
/*
** Execute a rollback if a transaction is active and unlock the 
** database file. This is a no-op if the pager has already entered
** the error-state.
*/
static void pagerUnlockAndRollback(Pager *p){
  if( p->errCode ) return;
  assert( p->state>=PAGER_RESERVED || p->journalOpen==0 );
  if( p->state>=PAGER_RESERVED ){
    sqlite3PagerRollback(p);
  }
  pager_unlock(p);
  assert( p->errCode || !p->journalOpen || (p->exclusiveMode&&!p->journalOff) );
  assert( p->errCode || !p->stmtOpen || p->exclusiveMode );
}
2718
2719
2720
2721
2722
2723
2724



2725
2726
2727
2728
2729
2730
2731
        /* Playback and delete the journal.  Drop the database write
        ** lock and reacquire the read lock.
        */
        rc = pager_playback(pPager, 1);
        if( rc!=SQLITE_OK ){
          return pager_error(pPager, rc);
        }



      }

      if( pPager->pAll ){
        PgHdr *pPage1 = pager_lookup(pPager, 1);
        if( pPage1 ){
          unlinkHashChain(pPager, pPage1);
        }







>
>
>







2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
        /* Playback and delete the journal.  Drop the database write
        ** lock and reacquire the read lock.
        */
        rc = pager_playback(pPager, 1);
        if( rc!=SQLITE_OK ){
          return pager_error(pPager, rc);
        }
        assert(pPager->state==PAGER_SHARED || 
            (pPager->exclusiveMode && pPager->state>PAGER_SHARED)
        );
      }

      if( pPager->pAll ){
        PgHdr *pPage1 = pager_lookup(pPager, 1);
        if( pPage1 ){
          unlinkHashChain(pPager, pPage1);
        }
2743
2744
2745
2746
2747
2748
2749


2750

2751
2752
2753
2754
2755
2756
2757
          if( iChangeCount!=pPager->iChangeCount ){
            pager_reset(pPager);
          }
          pPager->iChangeCount = iChangeCount;
        }
      }
    }


    pPager->state = PAGER_SHARED;

  }

  return rc;
}

/*
** Acquire a page.







>
>
|
>







2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
          if( iChangeCount!=pPager->iChangeCount ){
            pager_reset(pPager);
          }
          pPager->iChangeCount = iChangeCount;
        }
      }
    }
    assert( pPager->exclusiveMode || pPager->state<=PAGER_SHARED );
    if( pPager->state==PAGER_UNLOCK ){
      pPager->state = PAGER_SHARED;
    }
  }

  return rc;
}

/*
** Acquire a page.
Changes to test/malloc.test.
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#***********************************************************************
# This file attempts to check the library in an out-of-memory situation.
# When compiled with -DSQLITE_DEBUG=1, the SQLite library accepts a special
# command (sqlite_malloc_fail N) which causes the N-th malloc to fail.  This
# special feature is used to see what happens in the library if a malloc
# were to really fail due to an out-of-memory situation.
#
# $Id: malloc.test,v 1.37 2007/03/17 10:26:59 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Only run these tests if memory debugging is turned on.
#
if {[info command sqlite_malloc_stat]==""} {







|







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#***********************************************************************
# This file attempts to check the library in an out-of-memory situation.
# When compiled with -DSQLITE_DEBUG=1, the SQLite library accepts a special
# command (sqlite_malloc_fail N) which causes the N-th malloc to fail.  This
# special feature is used to see what happens in the library if a malloc
# were to really fail due to an out-of-memory situation.
#
# $Id: malloc.test,v 1.38 2007/03/26 12:26:27 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Only run these tests if memory debugging is turned on.
#
if {[info command sqlite_malloc_stat]==""} {
330
331
332
333
334
335
336

337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
}

# This block tests malloc() failures that occur while opening a 
# connection to a database.
do_malloc_test 10 -sqlprep {
  CREATE TABLE abc(a, b, c);
} -tclbody {

  sqlite3 db2 test.db
  db2 eval {SELECT * FROM sqlite_master}
  db2 close
} 

# This block tests malloc() failures that occur within calls to
# sqlite3_create_function().
do_malloc_test 11  -tclbody {
  set rc [sqlite3_create_function $::DB]
  if {[string match $rc SQLITE_NOMEM]} {
    error "out of memory"
  }
}

do_malloc_test 12 -tclbody {
  set sql16 [encoding convertto unicode "SELECT * FROM sqlite_master"]
  append sql16 "\00\00"
  set ::STMT [sqlite3_prepare16 $::DB $sql16 -1 DUMMY]
  sqlite3_finalize $::STMT
} 

# Test malloc errors when replaying two hot journals from a 2-file 
# transaction.
ifcapable crashtest {
  do_malloc_test 13 -tclprep {
    set rc [crashsql -delay 1 -file test2.db {
      ATTACH 'test2.db' as aux;







>



















|







330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
}

# This block tests malloc() failures that occur while opening a 
# connection to a database.
do_malloc_test 10 -sqlprep {
  CREATE TABLE abc(a, b, c);
} -tclbody {
  db close
  sqlite3 db2 test.db
  db2 eval {SELECT * FROM sqlite_master}
  db2 close
} 

# This block tests malloc() failures that occur within calls to
# sqlite3_create_function().
do_malloc_test 11  -tclbody {
  set rc [sqlite3_create_function $::DB]
  if {[string match $rc SQLITE_NOMEM]} {
    error "out of memory"
  }
}

do_malloc_test 12 -tclbody {
  set sql16 [encoding convertto unicode "SELECT * FROM sqlite_master"]
  append sql16 "\00\00"
  set ::STMT [sqlite3_prepare16 $::DB $sql16 -1 DUMMY]
  sqlite3_finalize $::STMT
}

# Test malloc errors when replaying two hot journals from a 2-file 
# transaction.
ifcapable crashtest {
  do_malloc_test 13 -tclprep {
    set rc [crashsql -delay 1 -file test2.db {
      ATTACH 'test2.db' as aux;
Changes to test/quick.test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file runs all tests.
#
# $Id: quick.test,v 1.48 2007/03/17 10:26:59 danielk1977 Exp $

proc lshift {lvar} {
  upvar $lvar l
  set ret [lindex $l 0]
  set l [lrange $l 1 end]
  return $ret
}








|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file runs all tests.
#
# $Id: quick.test,v 1.49 2007/03/26 12:26:27 danielk1977 Exp $

proc lshift {lvar} {
  upvar $lvar l
  set ret [lindex $l 0]
  set l [lrange $l 1 end]
  return $ret
}
40
41
42
43
44
45
46

47
48
49
50
51
52
53
  btree3.test
  btree4.test
  btree5.test
  btree6.test
  corrupt.test
  crash.test
  crash2.test

  loadext.test
  malloc.test
  malloc2.test
  malloc3.test
  memleak.test
  misuse.test
  quick.test







>







40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
  btree3.test
  btree4.test
  btree5.test
  btree6.test
  corrupt.test
  crash.test
  crash2.test
  exclusive3.test
  loadext.test
  malloc.test
  malloc2.test
  malloc3.test
  memleak.test
  misuse.test
  quick.test