/ Check-in [d5b5326d]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:If possible, delete the journal file when a database connection is closed.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | server-edition
Files: files | file ages | folders
SHA3-256: d5b5326df25b85b1c3926cd693bcde1ca08e6e03b8aea151a82d222fc9c23dd6
User & Date: dan 2017-04-27 13:05:43
Context
2017-04-27
14:12
Do not write master journal filenames into server-mode journal files. Use SQLITE_MUTEX_STATIC_APP1 to protect critical sections in server.c. check-in: 3144ae40 user: dan tags: server-edition
13:05
If possible, delete the journal file when a database connection is closed. check-in: d5b5326d user: dan tags: server-edition
2017-04-26
20:45
Experimental implementation of pessimistic page-level locking based on rollback mode. check-in: 64ecf7c7 user: dan tags: server-edition
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/pager.c.

  4095   4095     pPager->exclusiveMode = 0;
  4096   4096   #ifndef SQLITE_OMIT_WAL
  4097   4097     assert( db || pPager->pWal==0 );
  4098   4098     sqlite3WalClose(pPager->pWal, db, pPager->ckptSyncFlags, pPager->pageSize,
  4099   4099         (db && (db->flags & SQLITE_NoCkptOnClose) ? 0 : pTmp)
  4100   4100     );
  4101   4101     pPager->pWal = 0;
  4102         -#endif
  4103         -#ifdef SQLITE_SERVER_EDITION
  4104         -  if( pPager->pServer ){
  4105         -    sqlite3ServerDisconnect(pPager->pServer, pPager->fd);
  4106         -    pPager->pServer = 0;
  4107         -    sqlite3_free(pPager->zJournal);
  4108         -  }
  4109   4102   #endif
  4110   4103     pager_reset(pPager);
  4111   4104     if( MEMDB ){
  4112   4105       pager_unlock(pPager);
  4113   4106     }else{
  4114   4107       /* If it is open, sync the journal file before calling UnlockAndRollback.
  4115   4108       ** If this is not done, then an unsynced portion of the open journal 
................................................................................
  4119   4112       ** If an error occurs while trying to sync the journal, shift the pager
  4120   4113       ** into the ERROR state. This causes UnlockAndRollback to unlock the
  4121   4114       ** database and close the journal file without attempting to roll it
  4122   4115       ** back or finalize it. The next database user will have to do hot-journal
  4123   4116       ** rollback before accessing the database file.
  4124   4117       */
  4125   4118       if( isOpen(pPager->jfd) ){
         4119  +      if( pagerIsServer(pPager) ){
         4120  +        assert( pPager->journalMode==PAGER_JOURNALMODE_PERSIST );
         4121  +        pPager->journalMode = PAGER_JOURNALMODE_DELETE;
         4122  +        /* If necessary, change the pager state so that the journal file 
         4123  +        ** is deleted by the call to pagerUnlockAndRollback() below.  */
         4124  +        if( pPager->eState==PAGER_OPEN ) pPager->eState = PAGER_READER;
         4125  +      }
  4126   4126         pager_error(pPager, pagerSyncHotJournal(pPager));
  4127   4127       }
  4128   4128       pagerUnlockAndRollback(pPager);
  4129   4129     }
         4130  +#ifdef SQLITE_SERVER_EDITION
         4131  +  if( pagerIsServer(pPager) ){
         4132  +    sqlite3ServerDisconnect(pPager->pServer, pPager->fd);
         4133  +    pPager->pServer = 0;
         4134  +    sqlite3_free(pPager->zJournal);
         4135  +  }
         4136  +#endif
  4130   4137     sqlite3EndBenignMalloc();
  4131   4138     enable_simulated_io_errors();
  4132   4139     PAGERTRACE(("CLOSE %d\n", PAGERID(pPager)));
  4133   4140     IOTRACE(("CLOSE %p\n", pPager))
  4134   4141     sqlite3OsClose(pPager->jfd);
  4135   4142     sqlite3OsClose(pPager->fd);
  4136   4143     sqlite3PageFree(pTmp);

Changes to test/server2.test.

    90     90     # Transaction is automatically rolled back in this case.
    91     91     sqlite3_get_autocommit db2
    92     92   } {1}
    93     93   do_test 2.8 {
    94     94     execsql COMMIT
    95     95     execsql { SELECT * FROM t1 } db2
    96     96   } {1 2 5 6}
           97  +db2 close
           98  +
           99  +#-------------------------------------------------------------------------
          100  +#
          101  +reset_db
          102  +do_execsql_test 3.0 {
          103  +  CREATE TABLE t1(a, b);
          104  +}
    97    105   
          106  +do_test 3.1 {
          107  +  glob test.db*
          108  +} {test.db-journal0 test.db test.db-hma}
    98    109   
          110  +do_test 3.2 {
          111  +  db close
          112  +  glob test.db*
          113  +} {test.db}
    99    114   
   100    115   finish_test
   101    116