/ Check-in [98a9713e]
Login

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

Overview
Comment:Further coverage tests.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 98a9713e0030a36ea99a18a12a2e7685c6db72b3
User & Date: dan 2010-05-06 15:56:28
Context
2010-05-06
16:06
After throwing an error to say that one cannot change into WAL mode within a tranactions, do not then go and change into WAL mode. check-in: 56a17dae user: drh tags: trunk
15:56
Further coverage tests. check-in: 98a9713e user: dan tags: trunk
15:36
Update configure scripts for WAL support. check-in: 2edc5129 user: shaneh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/pager.c.

5259
5260
5261
5262
5263
5264
5265

5266
5267
5268
5269
5270
5271
5272
  PAGERTRACE(("ROLLBACK %d\n", PAGERID(pPager)));
  if( pagerUseWal(pPager) ){
    int rc2;

    rc = sqlite3PagerSavepoint(pPager, SAVEPOINT_ROLLBACK, -1);
    rc2 = pager_end_transaction(pPager, pPager->setMaster);
    if( rc==SQLITE_OK ) rc = rc2;

  }else if( !pPager->dbModified || !isOpen(pPager->jfd) ){
    rc = pager_end_transaction(pPager, pPager->setMaster);
  }else if( pPager->errCode && pPager->errCode!=SQLITE_FULL ){
    if( pPager->state>=PAGER_EXCLUSIVE ){
      pager_playback(pPager, 0);
    }
    rc = pPager->errCode;







>







5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
  PAGERTRACE(("ROLLBACK %d\n", PAGERID(pPager)));
  if( pagerUseWal(pPager) ){
    int rc2;

    rc = sqlite3PagerSavepoint(pPager, SAVEPOINT_ROLLBACK, -1);
    rc2 = pager_end_transaction(pPager, pPager->setMaster);
    if( rc==SQLITE_OK ) rc = rc2;
    rc = pager_error(pPager, rc);
  }else if( !pPager->dbModified || !isOpen(pPager->jfd) ){
    rc = pager_end_transaction(pPager, pPager->setMaster);
  }else if( pPager->errCode && pPager->errCode!=SQLITE_FULL ){
    if( pPager->state>=PAGER_EXCLUSIVE ){
      pager_playback(pPager, 0);
    }
    rc = pPager->errCode;

Changes to src/test_vfs.c.

491
492
493
494
495
496
497

498

499
500
501
502
503
504
505
  TestvfsShm *pShm = (TestvfsShm *)pShmHandle;

  tvfsGrowBuffer(pShm, reqMapSize, pMapSize);
  tvfsExecTcl(p, "xShmGet", 
      Tcl_NewStringObj(pShm->pBuffer->zFile, -1), pShm->id, 0
  );
  tvfsResultCode(p, &rc);

  *pp = pShm->pBuffer->a;

  return rc;
}

static int tvfsShmRelease(sqlite3_vfs *pVfs, sqlite3_shm *pShmHandle){
  int rc = SQLITE_OK;
  Testvfs *p = (Testvfs *)(pVfs->pAppData);
  TestvfsShm *pShm = (TestvfsShm *)pShmHandle;







>
|
>







491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
  TestvfsShm *pShm = (TestvfsShm *)pShmHandle;

  tvfsGrowBuffer(pShm, reqMapSize, pMapSize);
  tvfsExecTcl(p, "xShmGet", 
      Tcl_NewStringObj(pShm->pBuffer->zFile, -1), pShm->id, 0
  );
  tvfsResultCode(p, &rc);
  if( rc==SQLITE_OK ){
    *pp = pShm->pBuffer->a;
  }
  return rc;
}

static int tvfsShmRelease(sqlite3_vfs *pVfs, sqlite3_shm *pShmHandle){
  int rc = SQLITE_OK;
  Testvfs *p = (Testvfs *)(pVfs->pAppData);
  TestvfsShm *pShm = (TestvfsShm *)pShmHandle;

Changes to src/wal.c.

395
396
397
398
399
400
401

402
403
404
405
406
407
408
....
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123

1124
1125
1126
1127
1128
1129
1130
1131
1132
                             &pWal->szWIndex, (void**)(char*)&pWal->pWiData);
    if( rc==SQLITE_OK && pWal->pWiData==0 ){
      /* Make sure pWal->pWiData is not NULL while we are holding the
      ** lock on the mapping. */
      assert( pWal->szWIndex==0 );
      pWal->pWiData = &pWal->iCallback;
    }

  }
  return rc;
}

/*
** Remap the wal-index so that the mapping covers the full size
** of the underlying file.
................................................................................
** returned to the caller.
**
** Otherwise, if the callback function does not return an error, this
** function returns SQLITE_OK.
*/
int sqlite3WalUndo(Wal *pWal, int (*xUndo)(void *, Pgno), void *pUndoCtx){
  int unused;
  int rc = SQLITE_OK;
  Pgno iMax = pWal->hdr.iLastPg;
  Pgno iFrame;


  rc = walIndexReadHdr(pWal, &unused);
  for(iFrame=pWal->hdr.iLastPg+1; iFrame<=iMax && rc==SQLITE_OK; iFrame++){
    assert( pWal->lockState==SQLITE_SHM_WRITE );
    rc = xUndo(pUndoCtx, pWal->pWiData[walIndexEntry(iFrame)]);
  }
  walIndexUnmap(pWal);
  return rc;
}








>







 







|



>

|







395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
....
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
                             &pWal->szWIndex, (void**)(char*)&pWal->pWiData);
    if( rc==SQLITE_OK && pWal->pWiData==0 ){
      /* Make sure pWal->pWiData is not NULL while we are holding the
      ** lock on the mapping. */
      assert( pWal->szWIndex==0 );
      pWal->pWiData = &pWal->iCallback;
    }
    assert( rc==SQLITE_OK || pWal->pWiData==0 );
  }
  return rc;
}

/*
** Remap the wal-index so that the mapping covers the full size
** of the underlying file.
................................................................................
** returned to the caller.
**
** Otherwise, if the callback function does not return an error, this
** function returns SQLITE_OK.
*/
int sqlite3WalUndo(Wal *pWal, int (*xUndo)(void *, Pgno), void *pUndoCtx){
  int unused;
  int rc;
  Pgno iMax = pWal->hdr.iLastPg;
  Pgno iFrame;

  assert( pWal->pWiData==0 );
  rc = walIndexReadHdr(pWal, &unused);
  for(iFrame=pWal->hdr.iLastPg+1; rc==SQLITE_OK && iFrame<=iMax; iFrame++){
    assert( pWal->lockState==SQLITE_SHM_WRITE );
    rc = xUndo(pUndoCtx, pWal->pWiData[walIndexEntry(iFrame)]);
  }
  walIndexUnmap(pWal);
  return rc;
}

Changes to test/tester.tcl.

745
746
747
748
749
750
751

752
753
754
755
756
757
758
      }
      set ::sqlite_io_error_hit 0

      # One of two things must have happened. either
      #   1.  We never hit the IO error and the SQL returned OK
      #   2.  An IO error was hit and the SQL failed
      #

      expr { ($s && !$r && !$q) || (!$s && $r && $q) }
    } {1}

    set ::sqlite_io_error_hit 0
    set ::sqlite_io_error_pending 0

    # Check that no page references were leaked. There should be 







>







745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
      }
      set ::sqlite_io_error_hit 0

      # One of two things must have happened. either
      #   1.  We never hit the IO error and the SQL returned OK
      #   2.  An IO error was hit and the SQL failed
      #
      #puts "s=$s r=$r q=$q"
      expr { ($s && !$r && !$q) || (!$s && $r && $q) }
    } {1}

    set ::sqlite_io_error_hit 0
    set ::sqlite_io_error_pending 0

    # Check that no page references were leaked. There should be 

Changes to test/walfault.test.

101
102
103
104
105
106
107

108
109
110
111
112
113
114
...
126
127
128
129
130
131
132

133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
...
230
231
232
233
234
235
236














237
238
239
#
proc do_shmfault_test {name args} {

  set A(-tclprep) "sqlite3 db test.db -vfs shmfault"
  set A(-sqlprep) ""
  set A(-sqlbody) ""
  set A(-methods) [list xShmGet xShmOpen xShmSize]

  array set A $args

  # Create a VFS to use:
  testvfs shmfault shmfault_vfs_cb

  unset -nocomplain ::shmfault_ioerr_methods
  foreach m $A(-methods) { set ::shmfault_ioerr_methods($m) 1 }
................................................................................
      set ::shmfault_ioerr_countdown $nDelay
      set rc [catch { db eval $A(-sqlbody) } msg]
      set hit_error [expr {$::shmfault_ioerr_countdown<=0}]
      unset ::shmfault_ioerr_countdown

      catch { db close }
      

      do_test $name-$mode.$nDelay.1 [list set {} $hit_error] $rc
  
      if {$hit_error==0} break
    }
  }

  shmfault delete
}


do_shmfault_test walfault-shm-1 -sqlbody {
  PRAGMA journal_mode = WAL;
  CREATE TABLE t1(a PRIMARY KEY, b);
  INSERT INTO t1 VALUES('a', 'b');
  PRAGMA wal_checkpoint;
}
................................................................................
  db close
  unset ::shmfault_ioerr_methods(xShmGet)
  if {[file exists test.db-wal]==0} {error "Failed to create WAL file!"}
  sqlite3 db test.db -vfs shmfault
} -sqlbody {
  SELECT count(*) FROM t1;
}















finish_test








>







 







>








<







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
...
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142

143
144
145
146
147
148
149
...
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#
proc do_shmfault_test {name args} {

  set A(-tclprep) "sqlite3 db test.db -vfs shmfault"
  set A(-sqlprep) ""
  set A(-sqlbody) ""
  set A(-methods) [list xShmGet xShmOpen xShmSize]
  set A(-coverageonly) 0
  array set A $args

  # Create a VFS to use:
  testvfs shmfault shmfault_vfs_cb

  unset -nocomplain ::shmfault_ioerr_methods
  foreach m $A(-methods) { set ::shmfault_ioerr_methods($m) 1 }
................................................................................
      set ::shmfault_ioerr_countdown $nDelay
      set rc [catch { db eval $A(-sqlbody) } msg]
      set hit_error [expr {$::shmfault_ioerr_countdown<=0}]
      unset ::shmfault_ioerr_countdown

      catch { db close }
      
      if {$A(-coverageonly)} { set rc $hit_error }
      do_test $name-$mode.$nDelay.1 [list set {} $hit_error] $rc
  
      if {$hit_error==0} break
    }
  }

  shmfault delete
}


do_shmfault_test walfault-shm-1 -sqlbody {
  PRAGMA journal_mode = WAL;
  CREATE TABLE t1(a PRIMARY KEY, b);
  INSERT INTO t1 VALUES('a', 'b');
  PRAGMA wal_checkpoint;
}
................................................................................
  db close
  unset ::shmfault_ioerr_methods(xShmGet)
  if {[file exists test.db-wal]==0} {error "Failed to create WAL file!"}
  sqlite3 db test.db -vfs shmfault
} -sqlbody {
  SELECT count(*) FROM t1;
}

do_shmfault_test walfault-shm-5 -coverageonly 1 -sqlprep {
  PRAGMA cache_size = 10;
  PRAGMA journal_mode = WAL;
  CREATE TABLE abc(a PRIMARY KEY);
  INSERT INTO abc VALUES(randomblob(900));
} -sqlbody {
  BEGIN;
    INSERT INTO abc SELECT randomblob(900) FROM abc;    /* 1 */
    INSERT INTO abc SELECT randomblob(900) FROM abc;    /* 2 */
    INSERT INTO abc SELECT randomblob(900) FROM abc;    /* 4 */
    INSERT INTO abc SELECT randomblob(900) FROM abc;    /* 8 */
  ROLLBACK;
}

finish_test