/ Check-in [c80c5c62]
Login

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

Overview
Comment:Fix a problem with mixing temp-files and mmap-mode.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tempfiles-25
Files: files | file ages | folders
SHA1:c80c5c62b2e2c5e47e0839f8e2d5b6341ca4a249
User & Date: dan 2016-04-23 17:24:16
Context
2016-04-23
19:55
Merge the latest trunk changes. check-in: 84da122d user: drh tags: tempfiles-25
17:24
Fix a problem with mixing temp-files and mmap-mode. check-in: c80c5c62 user: dan tags: tempfiles-25
14:55
Fix some problems to do with temp-file databases and recovering from IO and SQLITE_FULL errors. check-in: 3d61da4a user: dan tags: tempfiles-25
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/pager.c.

  2030   2030       }
  2031   2031     }
  2032   2032   #endif
  2033   2033   
  2034   2034     sqlite3BitvecDestroy(pPager->pInJournal);
  2035   2035     pPager->pInJournal = 0;
  2036   2036     pPager->nRec = 0;
  2037         -  if( pagerFlushOnCommit(pPager) ){
         2037  +  if( MEMDB || pagerFlushOnCommit(pPager) ){
  2038   2038       sqlite3PcacheCleanAll(pPager->pPCache);
  2039   2039     }else{
  2040   2040       sqlite3PcacheClearWritable(pPager->pPCache);
  2041   2041     }
  2042   2042     sqlite3PcacheTruncate(pPager->pPCache, pPager->dbSize);
  2043   2043   
  2044   2044     if( pagerUseWal(pPager) ){
................................................................................
  5377   5377         void *pData = 0;
  5378   5378   
  5379   5379         rc = sqlite3OsFetch(pPager->fd, 
  5380   5380             (i64)(pgno-1) * pPager->pageSize, pPager->pageSize, &pData
  5381   5381         );
  5382   5382   
  5383   5383         if( rc==SQLITE_OK && pData ){
  5384         -        if( pPager->eState>PAGER_READER ){
         5384  +        if( pPager->eState>PAGER_READER || pPager->tempFile ){
  5385   5385             pPg = sqlite3PagerLookup(pPager, pgno);
  5386   5386           }
  5387   5387           if( pPg==0 ){
  5388   5388             rc = pagerAcquireMapPage(pPager, pgno, pData, &pPg);
  5389   5389           }else{
  5390   5390             sqlite3OsUnfetch(pPager->fd, (i64)(pgno-1)*pPager->pageSize, pData);
  5391   5391           }
................................................................................
  6215   6215         pPager->zFilename, zMaster, pPager->dbSize));
  6216   6216   
  6217   6217     /* If no database changes have been made, return early. */
  6218   6218     if( pPager->eState<PAGER_WRITER_CACHEMOD ) return SQLITE_OK;
  6219   6219   
  6220   6220     assert( MEMDB==0 || pPager->tempFile );
  6221   6221     assert( isOpen(pPager->fd) || pPager->tempFile );
  6222         -  if( !isOpen(pPager->fd) ){
         6222  +  if( 0==pagerFlushOnCommit(pPager) ){
  6223   6223       /* If this is an in-memory db, or no pages have been written to, or this
  6224   6224       ** function has already been called, it is mostly a no-op.  However, any
  6225   6225       ** backup in progress needs to be restarted.  */
  6226   6226       sqlite3BackupRestart(pPager->pBackup);
  6227   6227     }else{
  6228   6228       if( pagerUseWal(pPager) ){
  6229   6229         PgHdr *pList = sqlite3PcacheDirtyList(pPager->pPCache);

Changes to test/temptable2.test.

   311    311           INSERT INTO tx SELECT randomblob(100), randomblob(100) FROM x;
   312    312         COMMIT;
   313    313       }
   314    314   
   315    315       do_execsql_test 9.$tn.$i.6 { PRAGMA integrity_check } ok
   316    316     }
   317    317   }
          318  +
          319  +#-------------------------------------------------------------------------
          320  +# When using mmap mode with a temp file, SQLite must search the cache 
          321  +# before using a mapped page even when there is no write transaction
          322  +# open. For a temp file, the on-disk version may not be up to date.
          323  +#
          324  +sqlite3 db ""
          325  +do_execsql_test 10.0 {
          326  +  PRAGMA cache_size = 50;
          327  +  PRAGMA page_size = 1024;
          328  +  CREATE TABLE t1(a, b, PRIMARY KEY(a)) WITHOUT ROWID;
          329  +  CREATE INDEX i1 ON t1(a);
          330  +  CREATE TABLE t2(x, y);
          331  +  INSERT INTO t2 VALUES(1, 2);
          332  +}
          333  +
          334  +do_execsql_test 10.1 {
          335  +  BEGIN;
          336  +    WITH x(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM x WHERE i<500 )
          337  +      INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM x;
          338  +  COMMIT;
          339  +  INSERT INTO t2 VALUES(3, 4);
          340  +}
          341  +
          342  +do_execsql_test 10.2 {
          343  +  PRAGMA mmap_size = 512000;
          344  +  SELECT * FROM t2;
          345  +  PRAGMA integrity_check;
          346  +} {512000 1 2 3 4 ok}
   318    347   
   319    348   finish_test
   320    349