]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add tests to cover a couple of branches in wal.c.
authordan <dan@noemail.net>
Thu, 6 May 2010 14:42:34 +0000 (14:42 +0000)
committerdan <dan@noemail.net>
Thu, 6 May 2010 14:42:34 +0000 (14:42 +0000)
FossilOrigin-Name: 429f437fb776fc974a6adf791b729e25bea82fef

manifest
manifest.uuid
src/wal.c
test/walfault.test

index 4c31aab560bc7846d113deda1d8208d81fcb0798..96f692ea48b702b88f65bfcda7a4ae7926ac3a5b 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Unset\sa\stcl\svariable\sbefore\sreusing\sit\sin\swal.test.
-D 2010-05-06T13:36:47
+C Add\stests\sto\scover\sa\scouple\sof\sbranches\sin\swal.c.
+D 2010-05-06T14:42:35
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in d83a0ffef3dcbfb08b410a6c6dd6c009ec9167fb
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -224,7 +224,7 @@ F src/vdbeblob.c 5327132a42a91e8b7acfb60b9d2c3b1c5c863e0e
 F src/vdbemem.c 2a82f455f6ca6f78b59fb312f96054c04ae0ead1
 F src/vdbetrace.c 864cef96919323482ebd9986f2132435115e9cc2
 F src/vtab.c a0f8a40274e4261696ef57aa806de2776ab72cda
-F src/wal.c 5fa16130ca31747510f95cfdecfde0e2834f4923
+F src/wal.c cc0c15289777ce3bad07769f762040089492a917
 F src/wal.h b4c42014b5fa3b4e6244ac8c65de7ff67adeb27c
 F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f
 F src/where.c 75fee9e255b62f773fcadd1d1f25b6f63ac7a356
@@ -765,7 +765,7 @@ F test/wal.test 7dda3fc1637aa035510199e166941bfe987846ba
 F test/wal2.test 4a8e20416020f83b792464edee18107321dea99a
 F test/walbak.test a0e45187c7d8928df035dfea29b99b016b21ca3c
 F test/walcrash.test f6d5fb2bb108876f04848720a488065d9deef69f
-F test/walfault.test 2d6e00e07ae4287d6ae552589bcc8532697d8173
+F test/walfault.test e3e96418015d31fd492a4862fc3cd0c5936b2087
 F test/walhook.test a1c375ae791d5d7d511c166159729230791c574d
 F test/walmode.test bac6f06544a8554588a1543def996bbe2fc41792
 F test/walslow.test d21625e2e99e11c032ce949e8a94661576548933
@@ -813,7 +813,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P f0fcb9c9a67e2bf7bbedbedbc27791b605a21dd1
-R 6e3f6cf8a28ee26b2021cd53f530e545
+P e83efb232fe8d30714f4c7cffeef80092aea4df7
+R 0bf684f67aaa290741def7759e4f2363
 U dan
-Z 51fe938b1a898b4d46946fd2baefdd24
+Z 239bc029f8f147d89b1ba27be4213141
index 9aa00019cb07a04394c6712b2775912fcc95d9c2..408e469b4d77207d051f075678b9bfcae27285ab 100644 (file)
@@ -1 +1 @@
-e83efb232fe8d30714f4c7cffeef80092aea4df7
\ No newline at end of file
+429f437fb776fc974a6adf791b729e25bea82fef
\ No newline at end of file
index 5a28b0bbe345c198010145e921cf68d88dd4b11f..0eb525f41396a2a6865ae7d9f6f57d0728d14c71 100644 (file)
--- a/src/wal.c
+++ b/src/wal.c
@@ -564,6 +564,7 @@ static int walIndexRecover(Wal *pWal){
 
 finished:
   walIndexWriteHdr(pWal, &hdr);
+  memcpy(&pWal->hdr, &hdr, sizeof(hdr));
   return rc;
 }
 
@@ -871,11 +872,7 @@ int walIndexTryHdr(Wal *pWal, int *pisValid, int *pChanged){
 
   /* Read the header. The caller may or may not have locked the wal-index
   ** file, meaning it is possible that an inconsistent snapshot is read
-  ** from the file. If this happens, return SQLITE_ERROR. The caller will
-  ** retry. Or, if the caller has already locked the file and the header
-  ** still looks inconsistent, it will run recovery.
-  **
-  ** FIX-ME:  It is no longer possible to have not locked the wal-index.
+  ** from the file. If this happens, return SQLITE_ERROR.
   */
   memcpy(aHdr, pWal->pWiData, sizeof(aHdr));
   walChecksumBytes((u8*)aHdr, sizeof(u32)*WALINDEX_HDR_NFIELD, aCksum);
@@ -887,9 +884,7 @@ int walIndexTryHdr(Wal *pWal, int *pisValid, int *pChanged){
   *pisValid = 1;
 
   if( memcmp(&pWal->hdr, aHdr, sizeof(WalIndexHdr)) ){
-    if( pChanged ){
-      *pChanged = 1;
-    }
+    *pChanged = 1;
     memcpy(&pWal->hdr, aHdr, sizeof(WalIndexHdr));
   }
   return SQLITE_OK;
@@ -908,6 +903,7 @@ static int walIndexReadHdr(Wal *pWal, int *pChanged){
   int isValid = 0;
 
   assert( pWal->lockState>=SQLITE_SHM_READ );
+  assert( pChanged );
   rc = walIndexMap(pWal, -1);
   if( rc!=SQLITE_OK ){
     return rc;
@@ -926,22 +922,19 @@ static int walIndexReadHdr(Wal *pWal, int *pChanged){
   ** time as well, run log recovery.
   */
   if( SQLITE_OK==(rc = walSetLock(pWal, SQLITE_SHM_RECOVER)) ){
+    /* This call to walIndexTryHdr() may not return an error code, as the
+    ** wal-index is already mapped. It may find that the header is invalid,
+    ** but there is no chance of hitting an actual error.  */
+    assert( pWal->szWIndex );
     rc = walIndexTryHdr(pWal, &isValid, pChanged);
-    if( rc==SQLITE_OK && isValid==0 ){
-      if( pChanged ){
-        *pChanged = 1;
-      }
+    assert( rc==SQLITE_OK );
+    if( isValid==0 ){
+      *pChanged = 1;
       rc = walIndexRecover(pWal);
-      if( rc==SQLITE_OK ){
-        rc = walIndexTryHdr(pWal, &isValid, 0);
-      }
     }
     walSetLock(pWal, SQLITE_SHM_READ);
   }
 
-  if( rc==SQLITE_OK && isValid==0 ){
-    rc = SQLITE_ERROR;
-  }
   return rc;
 }
 
@@ -1123,11 +1116,12 @@ int sqlite3WalWriteLock(Wal *pWal, int op){
 ** 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, 0);
+  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)]);
index 8702af5d828aba7194cea8ec6bb1e58bff3cb2d6..2830321aa518cedaa4e9b4b30b3b2305087ee7cf 100644 (file)
@@ -210,5 +210,30 @@ do_shmfault_test walfault-shm-3 -methods xShmSize -tclprep {
   SELECT count(*) FROM t1;
 }
 
+do_shmfault_test walfault-shm-4 -tclprep {
+  sqlite3 db test.db -vfs shmfault
+  unset -nocomplain ::shmfault_ioerr_countdown
+  db eval {
+    PRAGMA page_size = 512;
+    PRAGMA journal_mode = WAL;
+    PRAGMA wal_autocheckpoint = 0;
+    CREATE TABLE t1(x);
+    BEGIN;
+      INSERT INTO t1 VALUES(randomblob(400));           /* 1 */
+      INSERT INTO t1 SELECT randomblob(400) FROM t1;    /* 2 */
+      INSERT INTO t1 SELECT randomblob(400) FROM t1;    /* 4 */
+    COMMIT;
+  }
+
+  set ::shmfault_ioerr_countdown 1
+  set ::shmfault_ioerr_methods(xShmGet) 1
+  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