/ Check-in [d2bb0066]
Login

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

Overview
Comment:Do not invoke codec macros for in-memory subjournals.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | codecless-inmemory-subjournal
Files: files | file ages | folders
SHA3-256:d2bb0066f7c8413ef9992e6b07641cdf40ad260778074bd83cc22dcaba87860b
User & Date: drh 2017-05-10 12:49:50
Context
2017-05-10
12:58
Avoid unnecessary codec operations on in-memory subjournals. check-in: 199b2a84 user: drh tags: trunk
12:49
Do not invoke codec macros for in-memory subjournals. Closed-Leaf check-in: d2bb0066 user: drh tags: codecless-inmemory-subjournal
2017-05-08
18:29
Do not invoke codec macros when reading or writing an in-memory sub-journal. check-in: 2c145ee6 user: dan tags: codecless-inmemory-subjournal
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/pager.c.

  2254   2254     int rc;
  2255   2255     PgHdr *pPg;                   /* An existing page in the cache */
  2256   2256     Pgno pgno;                    /* The page number of a page in journal */
  2257   2257     u32 cksum;                    /* Checksum used for sanity checking */
  2258   2258     char *aData;                  /* Temporary storage for the page */
  2259   2259     sqlite3_file *jfd;            /* The file descriptor for the journal file */
  2260   2260     int isSynced;                 /* True if journal page is synced */
         2261  +#ifdef SQLITE_HAS_CODEC
         2262  +  /* The jrnlEnc flag is true if Journal pages should be passed through
         2263  +  ** the codec.  It is false for pure in-memory journals. */
  2261   2264     const int jrnlEnc = (isMainJrnl || pPager->subjInMemory==0);
         2265  +#endif
  2262   2266   
  2263   2267     assert( (isMainJrnl&~1)==0 );      /* isMainJrnl is 0 or 1 */
  2264   2268     assert( (isSavepnt&~1)==0 );       /* isSavepnt is 0 or 1 */
  2265   2269     assert( isMainJrnl || pDone );     /* pDone always used on sub-journals */
  2266   2270     assert( isSavepnt || pDone==0 );   /* pDone never used on non-savepoint */
  2267   2271   
  2268   2272     aData = pPager->pTmpSpace;
................................................................................
  2385   2389   
  2386   2390       /* Write the data read from the journal back into the database file.
  2387   2391       ** This is usually safe even for an encrypted database - as the data
  2388   2392       ** was encrypted before it was written to the journal file. The exception
  2389   2393       ** is if the data was just read from an in-memory sub-journal. In that
  2390   2394       ** case it must be encrypted here before it is copied into the database
  2391   2395       ** file.  */
  2392         -    if( !jrnlEnc ){CODEC2(pPager, aData, pgno, 7, rc=SQLITE_NOMEM_BKPT, aData);}
         2396  +#ifdef SQLITE_HAS_CODEC
         2397  +    if( !jrnlEnc ){
         2398  +      CODEC2(pPager, aData, pgno, 7, rc=SQLITE_NOMEM_BKPT, aData);
         2399  +      rc = sqlite3OsWrite(pPager->fd, (u8 *)aData, pPager->pageSize, ofst);
         2400  +      CODEC1(pPager, aData, pgno, 3, rc=SQLITE_NOMEM_BKPT);
         2401  +    }else
         2402  +#endif
  2393   2403       rc = sqlite3OsWrite(pPager->fd, (u8 *)aData, pPager->pageSize, ofst);
  2394         -    if( !jrnlEnc ){CODEC1(pPager, aData, pgno, 3, rc=SQLITE_NOMEM_BKPT);}
  2395   2404   
  2396   2405       if( pgno>pPager->dbFileSize ){
  2397   2406         pPager->dbFileSize = pgno;
  2398   2407       }
  2399   2408       if( pPager->pBackup ){
  2400         -      if( jrnlEnc ){CODEC1(pPager, aData, pgno, 3, rc=SQLITE_NOMEM_BKPT);}
         2409  +#ifdef SQLITE_HAS_CODEC
         2410  +      if( jrnlEnc ){
         2411  +        CODEC1(pPager, aData, pgno, 3, rc=SQLITE_NOMEM_BKPT);
         2412  +        sqlite3BackupUpdate(pPager->pBackup, pgno, (u8*)aData);
         2413  +        CODEC2(pPager, aData, pgno, 7, rc=SQLITE_NOMEM_BKPT,aData);
         2414  +      }else
         2415  +#endif
  2401   2416         sqlite3BackupUpdate(pPager->pBackup, pgno, (u8*)aData);
  2402         -      if( jrnlEnc ){CODEC2(pPager, aData, pgno, 7, rc=SQLITE_NOMEM_BKPT,aData);}
  2403   2417       }
  2404   2418     }else if( !isMainJrnl && pPg==0 ){
  2405   2419       /* If this is a rollback of a savepoint and data was not written to
  2406   2420       ** the database and the page is not in-memory, there is a potential
  2407   2421       ** problem. When the page is next fetched by the b-tree layer, it 
  2408   2422       ** will be read from the database file, which may or may not be 
  2409   2423       ** current. 
................................................................................
  2447   2461       /* If this was page 1, then restore the value of Pager.dbFileVers.
  2448   2462       ** Do this before any decoding. */
  2449   2463       if( pgno==1 ){
  2450   2464         memcpy(&pPager->dbFileVers, &((u8*)pData)[24],sizeof(pPager->dbFileVers));
  2451   2465       }
  2452   2466   
  2453   2467       /* Decode the page just read from disk */
  2454         -    if( jrnlEnc ) CODEC1(pPager, pData, pPg->pgno, 3, rc=SQLITE_NOMEM_BKPT);
         2468  +#if SQLITE_HAS_CODEC
         2469  +    if( jrnlEnc ){ CODEC1(pPager, pData, pPg->pgno, 3, rc=SQLITE_NOMEM_BKPT); }
         2470  +#endif
  2455   2471       sqlite3PcacheRelease(pPg);
  2456   2472     }
  2457   2473     return rc;
  2458   2474   }
  2459   2475   
  2460   2476   /*
  2461   2477   ** Parameter zMaster is the name of a master journal file. A single journal
................................................................................
  4459   4475   
  4460   4476       /* If the sub-journal was opened successfully (or was already open),
  4461   4477       ** write the journal record into the file.  */
  4462   4478       if( rc==SQLITE_OK ){
  4463   4479         void *pData = pPg->pData;
  4464   4480         i64 offset = (i64)pPager->nSubRec*(4+pPager->pageSize);
  4465   4481         char *pData2;
  4466         -  
  4467         -      if( pPager->subjInMemory ){
  4468         -        pData2 = pData;
  4469         -      }else{
         4482  +
         4483  +#if SQLITE_HAS_CODEC   
         4484  +      if( !pPager->subjInMemory ){
  4470   4485           CODEC2(pPager, pData, pPg->pgno, 7, return SQLITE_NOMEM_BKPT, pData2);
  4471         -      }
         4486  +      }else
         4487  +#endif
         4488  +      pData2 = pData;
  4472   4489         PAGERTRACE(("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno));
  4473   4490         rc = write32bits(pPager->sjfd, offset, pPg->pgno);
  4474   4491         if( rc==SQLITE_OK ){
  4475   4492           rc = sqlite3OsWrite(pPager->sjfd, pData2, pPager->pageSize, offset+4);
  4476   4493         }
  4477   4494       }
  4478   4495     }