/ Check-in [270b7d1e]
Login

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

Overview
Comment:Fix a problem with wrapping the log file in server mode.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | server-edition
Files: files | file ages | folders
SHA3-256: 270b7d1eacb57827465946262b31c5c890d7fc5b5618ccd9e220bc2f9546de54
User & Date: dan 2017-05-09 16:32:19
Context
2017-05-10
13:46
Use a blocking call to obtain the wal-mode WRITER lock in some cases. check-in: 4464ca1d user: dan tags: server-edition
2017-05-09
16:32
Fix a problem with wrapping the log file in server mode. check-in: 270b7d1e user: dan tags: server-edition
2017-05-08
20:15
Add some support for wal mode to the hack on this branch. check-in: b733afc1 user: dan tags: server-edition
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/wal.c.

  2898   2898   ** unchanged.
  2899   2899   **
  2900   2900   ** SQLITE_OK is returned if no error is encountered (regardless of whether
  2901   2901   ** or not pWal->hdr.mxFrame is modified). An SQLite error code is returned
  2902   2902   ** if an error occurs.
  2903   2903   */
  2904   2904   static int walRestartLog(Wal *pWal){
         2905  +  volatile WalCkptInfo *pInfo = walCkptInfo(pWal);
  2905   2906     int rc = SQLITE_OK;
  2906   2907     int cnt;
  2907   2908   
  2908         -  if( pWal->readLock==0 ){
  2909         -    volatile WalCkptInfo *pInfo = walCkptInfo(pWal);
         2909  +  if( pWal->readLock==0 
         2910  +   || (walIsServer(pWal) && pInfo->nBackfill==pWal->hdr.mxFrame)
         2911  +  ){
  2910   2912       assert( pInfo->nBackfill==pWal->hdr.mxFrame );
  2911   2913       if( pInfo->nBackfill>0 ){
  2912   2914         u32 salt1;
  2913   2915         sqlite3_randomness(4, &salt1);
  2914   2916         rc = walLockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1);
  2915   2917         if( rc==SQLITE_OK ){
  2916   2918           /* If all readers are using WAL_READ_LOCK(0) (in other words if no
................................................................................
  2924   2926           ** to handle if this transaction is rolled back.  */
  2925   2927           walRestartHdr(pWal, salt1);
  2926   2928           walUnlockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1);
  2927   2929         }else if( rc!=SQLITE_BUSY ){
  2928   2930           return rc;
  2929   2931         }
  2930   2932       }
         2933  +    if( walIsServer(pWal) ) return rc;
  2931   2934       walUnlockShared(pWal, WAL_READ_LOCK(0));
  2932   2935       pWal->readLock = -1;
  2933   2936       cnt = 0;
  2934   2937       do{
  2935   2938         int notUsed;
  2936   2939         rc = walTryBeginRead(pWal, &notUsed, 1, ++cnt);
  2937   2940       }while( rc==WAL_RETRY );

Changes to test/serverwal.test.

    32     32     lsort [glob test.db*]
    33     33   } {test.db test.db-hma test.db-shm test.db-wal}
    34     34   do_test 1.4 {
    35     35     db close
    36     36     glob test.db*
    37     37   } {test.db}
    38     38   
           39  +#-------------------------------------------------------------------------
    39     40   # Two concurrent transactions.
    40     41   #
    41     42   do_test 2.0 {
    42     43     sqlite3 db  test.db
    43     44     sqlite3 db2 test.db
    44     45     db eval {
    45     46       CREATE TABLE t2(a, b);
................................................................................
    55     56         INSERT INTO t2 VALUES(1, 2);
    56     57     } db2
    57     58   } {}
    58     59   do_test 2.2 {
    59     60     execsql COMMIT db
    60     61     execsql COMMIT db2
    61     62   } {}
           63  +db close
           64  +
           65  +#-------------------------------------------------------------------------
           66  +# That the wal file can be wrapped around.
           67  +#
           68  +reset_db
           69  +do_execsql_test 3.0 {
           70  +  PRAGMA journal_mode = wal;
           71  +  CREATE TABLE ttt(a, b);
           72  +  INSERT INTO ttt VALUES(1, 2);
           73  +  INSERT INTO ttt VALUES(3, 4);
           74  +  INSERT INTO ttt VALUES(5, 6);
           75  +  INSERT INTO ttt VALUES(7, 8);
           76  +  INSERT INTO ttt VALUES(9, 10);
           77  +} {wal}
    62     78   
           79  +do_test 3.1 {
           80  +  set N [file size test.db-wal]
           81  +  execsql {
           82  +    PRAGMA wal_checkpoint;
           83  +    INSERT INTO ttt VALUES(11, 12);
           84  +    INSERT INTO ttt VALUES(13, 14);
           85  +  }
           86  +  expr {$N == [file size test.db-wal]}
           87  +} {1}
    63     88   
    64     89   finish_test
           90  +