/ Check-in [c47144e9]
Login

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

Overview
Comment:Avoid unnecessarily reseting the pager cache after committing a transaction that takes advantage of the SQLITE_IOCAP_ATOMIC related optimization.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: c47144e98c0a0f9e09780c945de10c57b6a495ea
User & Date: dan 2013-04-26 18:36:58
Context
2013-04-26
19:33
Fix a formatting typo in a comment. No changes to code. check-in: 7a97226f user: drh tags: trunk
18:36
Avoid unnecessarily reseting the pager cache after committing a transaction that takes advantage of the SQLITE_IOCAP_ATOMIC related optimization. check-in: c47144e9 user: dan tags: trunk
17:00
Avoid using posix_fallocate() in WAL mode, as it is not supported by all file-systems. check-in: 1bbb4be1 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/pager.c.

  5923   5923           assert( pPager->dbFileSize>0 );
  5924   5924           CODEC2(pPager, pPgHdr->pData, 1, 6, rc=SQLITE_NOMEM, zBuf);
  5925   5925           if( rc==SQLITE_OK ){
  5926   5926             rc = sqlite3OsWrite(pPager->fd, zBuf, pPager->pageSize, 0);
  5927   5927             pPager->aStat[PAGER_STAT_WRITE]++;
  5928   5928           }
  5929   5929           if( rc==SQLITE_OK ){
         5930  +          /* Update the pager's copy of the change-counter. Otherwise, the
         5931  +          ** next time a read transaction is opened the cache will be
         5932  +          ** flushed (as the change-counter values will not match).  */
         5933  +          const void *pCopy = (const void *)&((const char *)zBuf)[24];
         5934  +          memcpy(&pPager->dbFileVers, pCopy, sizeof(pPager->dbFileVers));
  5930   5935             pPager->changeCountDone = 1;
  5931   5936           }
  5932   5937         }else{
  5933   5938           pPager->changeCountDone = 1;
  5934   5939         }
  5935   5940       }
  5936   5941   

Changes to test/io.test.

    34     34   # io-4.* -  Test the IO traffic enhancements triggered when the 
    35     35   #           IOCAP_SAFE_APPEND device capability flag is set (fewer 
    36     36   #           fsync() calls on the journal file, no need to set nRec
    37     37   #           field in the single journal header).
    38     38   #
    39     39   # io-5.* -  Test that the default page size is selected and used 
    40     40   #           correctly.
           41  +#
           42  +# io-6.* -  Test that the pager-cache is not being flushed unnecessarily 
           43  +#           after a transaction that uses the special atomic-write path
           44  +#           is committed.
    41     45   #           
    42     46   
    43     47   set ::nWrite 0
    44     48   proc nWrite {db} {
    45     49     set bt [btree_from_db $db]
    46     50     db_enter $db
    47     51     array set stats [btree_pager_stats $bt]
................................................................................
   560    564     do_test io-5.$tn {
   561    565       execsql {
   562    566         CREATE TABLE abc(a, b, c);
   563    567       }
   564    568       expr {[file size test.db]/2}
   565    569     } $pgsize
   566    570   }
          571  +
          572  +#----------------------------------------------------------------------
          573  +#
          574  +do_test io-6.1 {
          575  +  db close
          576  +  sqlite3_simulate_device -char atomic
          577  +  forcedelete test.db
          578  +  sqlite3 db test.db -vfs devsym
          579  +  execsql {
          580  +    PRAGMA mmap_size = 0;
          581  +    PRAGMA page_size = 1024;
          582  +    CREATE TABLE t1(x);
          583  +    CREATE TABLE t2(x);
          584  +    CREATE TABLE t3(x);
          585  +    CREATE INDEX i3 ON t3(x);
          586  +    INSERT INTO t3 VALUES(randomblob(100));
          587  +    INSERT INTO t3 SELECT randomblob(100) FROM t3;
          588  +    INSERT INTO t3 SELECT randomblob(100) FROM t3;
          589  +    INSERT INTO t3 SELECT randomblob(100) FROM t3;
          590  +    INSERT INTO t3 SELECT randomblob(100) FROM t3;
          591  +    INSERT INTO t3 SELECT randomblob(100) FROM t3;
          592  +    INSERT INTO t3 SELECT randomblob(100) FROM t3;
          593  +    INSERT INTO t3 SELECT randomblob(100) FROM t3;
          594  +    INSERT INTO t3 SELECT randomblob(100) FROM t3;
          595  +    INSERT INTO t3 SELECT randomblob(100) FROM t3;
          596  +    INSERT INTO t3 SELECT randomblob(100) FROM t3;
          597  +    INSERT INTO t3 SELECT randomblob(100) FROM t3;
          598  +  }
          599  +
          600  +  db_save_and_close
          601  +} {}
          602  +
          603  +foreach {tn sql} {
          604  +  1 { BEGIN;
          605  +        INSERT INTO t1 VALUES('123');
          606  +        INSERT INTO t2 VALUES('456');
          607  +      COMMIT;
          608  +  }
          609  +  2 { BEGIN;
          610  +        INSERT INTO t1 VALUES('123');
          611  +      COMMIT;
          612  +  }
          613  +} {
          614  +  db_restore
          615  +  sqlite3 db test.db -vfs devsym
          616  +  execsql {
          617  +    PRAGMA mmap_size = 0;
          618  +    SELECT x FROM t3 ORDER BY rowid;
          619  +    SELECT x FROM t3 ORDER BY x;
          620  +  }
          621  +  do_execsql_test 6.2.$tn.1 { PRAGMA integrity_check } {ok}
          622  +  do_execsql_test 6.2.$tn.2 $sql
          623  +
          624  +  # Corrupt the database file on disk. This should not matter for the
          625  +  # purposes of the following "PRAGMA integrity_check", as the entire
          626  +  # database should be cached in the pager-cache. If corruption is
          627  +  # reported, it indicates that executing $sql caused the pager cache
          628  +  # to be flushed. Which is a bug.
          629  +  hexio_write test.db [expr 1024 * 5] [string repeat 00 2048]
          630  +  do_execsql_test 6.2.$tn.3 { PRAGMA integrity_check } {ok}
          631  +}
   567    632   
   568    633   sqlite3_simulate_device -char {} -sectorsize 0
   569    634   finish_test
          635  +