/ Check-in [9abeb798]
Login

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

Overview
Comment:Fix a bug in sqlite3_snapshot_recover() that could cause subsequent read transactions to use out-of-data cache entries.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | serializable-snapshot
Files: files | file ages | folders
SHA1:9abeb7980a34cec11a3420e14ad98a4ec0d9c599
User & Date: dan 2016-11-19 14:53:22
Context
2016-11-19
16:35
Fix a problem causing sqlite3_snapshot_recover() to return SQLITE_IOERR_SHORT_READ. check-in: 525f75fa user: dan tags: serializable-snapshot
14:53
Fix a bug in sqlite3_snapshot_recover() that could cause subsequent read transactions to use out-of-data cache entries. check-in: 9abeb798 user: dan tags: serializable-snapshot
2016-11-18
20:49
Add experimental sqlite3_snapshot_recover() API. check-in: 174a6076 user: dan tags: serializable-snapshot
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/wal.c.

2428
2429
2430
2431
2432
2433
2434




2435

2436
2437
2438
2439
2440
2441
2442
      }

      sqlite3_free(pBuf1);
      sqlite3_free(pBuf2);
      walUnlockExclusive(pWal, WAL_CKPT_LOCK, 1);
    }





    sqlite3WalEndReadTransaction(pWal);

  }

  return rc;
}

/*
** Begin a read transaction on the database.







>
>
>
>

>







2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
      }

      sqlite3_free(pBuf1);
      sqlite3_free(pBuf2);
      walUnlockExclusive(pWal, WAL_CKPT_LOCK, 1);
    }

    /* End the read transaction opened above. Also zero the cache of the
    ** wal-index header to force the pager-cache to be flushed when the next
    ** read transaction is open, as it may not match the current contents of
    ** pWal->hdr. */
    sqlite3WalEndReadTransaction(pWal);
    memset(&pWal->hdr, 0, sizeof(WalIndexHdr));
  }

  return rc;
}

/*
** Begin a read transaction on the database.

Changes to test/snapshot2.test.

75
76
77
78
79
80
81

82
83
84
85
86
87
88
...
132
133
134
135
136
137
138




















139
140
141
142
  execsql BEGIN
  string length [sqlite3_snapshot_get_blob db main]
} 48
execsql COMMIT
db2 close

#-------------------------------------------------------------------------

#
reset_db
do_execsql_test 2.0 {
  CREATE TABLE t1(x);
  PRAGMA journal_mode = wal;
  INSERT INTO t1 VALUES(1);
  INSERT INTO t1 VALUES(2);
................................................................................

  execsql {SELECT * FROM sqlite_master}
  sqlite3_snapshot_recover db main
  execsql BEGIN
  list [catch { sqlite3_snapshot_open_blob db main $snap } msg] $msg
} {1 SQLITE_BUSY_SNAPSHOT}






















finish_test









>







 







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




75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
...
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
  execsql BEGIN
  string length [sqlite3_snapshot_get_blob db main]
} 48
execsql COMMIT
db2 close

#-------------------------------------------------------------------------
# Simple tests for sqlite3_snapshot_recover().
#
reset_db
do_execsql_test 2.0 {
  CREATE TABLE t1(x);
  PRAGMA journal_mode = wal;
  INSERT INTO t1 VALUES(1);
  INSERT INTO t1 VALUES(2);
................................................................................

  execsql {SELECT * FROM sqlite_master}
  sqlite3_snapshot_recover db main
  execsql BEGIN
  list [catch { sqlite3_snapshot_open_blob db main $snap } msg] $msg
} {1 SQLITE_BUSY_SNAPSHOT}

#-------------------------------------------------------------------------
# Check that calling sqlite3_snapshot_recover() does not confuse the
# pager cache.
reset_db
do_execsql_test 3.0 {
  PRAGMA journal_mode = wal;
  CREATE TABLE t1(x, y);
  INSERT INTO t1 VALUES('a', 'b');
  INSERT INTO t1 VALUES('c', 'd');
} {wal}
do_test 3.1 {
  sqlite3 db2 test.db
  execsql { INSERT INTO t1 VALUES('e', 'f') } db2
  db2 close
  sqlite3_snapshot_recover db main
} {}
breakpoint
do_execsql_test 3.2 {
  SELECT * FROM t1;
} {a b c d e f}

finish_test