SQLite

Check-in [9e1502e1b6]
Login

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

Overview
Comment:Fix a bug in recovering wal2 mode databases introduced by the previous commit.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | wal2
Files: files | file ages | folders
SHA3-256: 9e1502e1b650217efc361732a3dfe686caa2e6352d040c73865f1faf09bf4591
User & Date: dan 2017-10-06 14:08:39.369
Context
2017-10-06
14:25
Merge latest trunk changes into this branch. (check-in: 7e43517861 user: dan tags: wal2)
14:08
Fix a bug in recovering wal2 mode databases introduced by the previous commit. (check-in: 9e1502e1b6 user: dan tags: wal2)
13:43
Fix frame overwriting in wal2 mode. (check-in: a4b02bc938 user: dan tags: wal2)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/wal.c.
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
  ** previous frame.  */
  assert( pWal->iReCksum>0 );
  if( pWal->iReCksum==1 ){
    iCksumOff = 24;
  }else{
    iCksumOff = walFrameOffset(pWal->iReCksum-1, szPage) + 16;
  }
  rc = sqlite3OsRead(pWal->apWalFd[0], aBuf, sizeof(u32)*2, iCksumOff);
  pWal->hdr.aFrameCksum[0] = sqlite3Get4byte(aBuf);
  pWal->hdr.aFrameCksum[1] = sqlite3Get4byte(&aBuf[sizeof(u32)]);

  iRead = pWal->iReCksum;
  pWal->iReCksum = 0;
  for(; rc==SQLITE_OK && iRead<=iLast; iRead++){
    i64 iOff = walFrameOffset(iRead, szPage);
    rc = sqlite3OsRead(pWal->apWalFd[0], aBuf, szPage+WAL_FRAME_HDRSIZE, iOff);
    if( rc==SQLITE_OK ){
      u32 iPgno, nDbSize;
      iPgno = sqlite3Get4byte(aBuf);
      nDbSize = sqlite3Get4byte(&aBuf[4]);

      walEncodeFrame(pWal, iPgno, nDbSize, &aBuf[WAL_FRAME_HDRSIZE], aFrame);
      rc = sqlite3OsWrite(pWal->apWalFd[0], aFrame, sizeof(aFrame), iOff);
    }
  }

  sqlite3_free(aBuf);
  return rc;
}








|







|






|







3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
  ** previous frame.  */
  assert( pWal->iReCksum>0 );
  if( pWal->iReCksum==1 ){
    iCksumOff = 24;
  }else{
    iCksumOff = walFrameOffset(pWal->iReCksum-1, szPage) + 16;
  }
  rc = sqlite3OsRead(pWalFd, aBuf, sizeof(u32)*2, iCksumOff);
  pWal->hdr.aFrameCksum[0] = sqlite3Get4byte(aBuf);
  pWal->hdr.aFrameCksum[1] = sqlite3Get4byte(&aBuf[sizeof(u32)]);

  iRead = pWal->iReCksum;
  pWal->iReCksum = 0;
  for(; rc==SQLITE_OK && iRead<=iLast; iRead++){
    i64 iOff = walFrameOffset(iRead, szPage);
    rc = sqlite3OsRead(pWalFd, aBuf, szPage+WAL_FRAME_HDRSIZE, iOff);
    if( rc==SQLITE_OK ){
      u32 iPgno, nDbSize;
      iPgno = sqlite3Get4byte(aBuf);
      nDbSize = sqlite3Get4byte(&aBuf[4]);

      walEncodeFrame(pWal, iPgno, nDbSize, &aBuf[WAL_FRAME_HDRSIZE], aFrame);
      rc = sqlite3OsWrite(pWalFd, aFrame, sizeof(aFrame), iOff);
    }
  }

  sqlite3_free(aBuf);
  return rc;
}

Changes to test/wal2rewrite.test.
67
68
69
70
71
72
73
74

75











76
77
78
79
80
      UPDATE t1 SET b=b+10, c=randomblob(800);
      UPDATE t1 SET b=b+10, c=randomblob(800);
    }
    execsql COMMIT

    do_test $tn.$i.3 { expr [filesize test.db-wal]  < 100000 } 1
    do_test $tn.$i.4 { expr [filesize test.db-wal2] < 100000 } 1
  }













}
    


finish_test







|
>

>
>
>
>
>
>
>
>
>
>
>





67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
      UPDATE t1 SET b=b+10, c=randomblob(800);
      UPDATE t1 SET b=b+10, c=randomblob(800);
    }
    execsql COMMIT

    do_test $tn.$i.3 { expr [filesize test.db-wal]  < 100000 } 1
    do_test $tn.$i.4 { expr [filesize test.db-wal2] < 100000 } 1

    set sum [db eval {SELECT sum(b), md5sum(c) FROM t1}]

    do_test $tn.$i.5 {
      foreach f [glob -nocomplain test.db2*] {forcedelete $f}
      foreach f [glob -nocomplain test.db*] {
        forcecopy $f [string map {test.db test.db2} $f]
      }

      sqlite3 db2 test.db2
      db2 eval {SELECT sum(b), md5sum(c) FROM t1}
    } $sum
    db2 close
  }
}
    


finish_test