mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-05 15:55:57 +03:00
Pass all (relevant) regression tests when using the codec. (CVS 1223)
FossilOrigin-Name: 5200e9edc5fdba0285a3cb1cd808cbf66d7a349e
This commit is contained in:
51
src/pager.c
51
src/pager.c
@@ -18,7 +18,7 @@
|
||||
** file simultaneously, or one process from reading the database while
|
||||
** another is writing.
|
||||
**
|
||||
** @(#) $Id: pager.c,v 1.98 2004/02/10 23:51:06 drh Exp $
|
||||
** @(#) $Id: pager.c,v 1.99 2004/02/11 02:18:07 drh Exp $
|
||||
*/
|
||||
#include "os.h" /* Must be first to enable large file support */
|
||||
#include "sqliteInt.h"
|
||||
@@ -117,6 +117,16 @@ struct PgHdr {
|
||||
/* Pager.nExtra bytes of local data follow the page data */
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
** A macro used for invoking the codec if there is one
|
||||
*/
|
||||
#ifdef SQLITE_HAS_CODEC
|
||||
# define CODEC(P,D,N,X) if( P->xCodec ){ P->xCodec(P->pCodecArg,D,N,X); }
|
||||
#else
|
||||
# define CODEC(P,D,N,X)
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Convert a pointer to a PgHdr into a pointer to its data
|
||||
** and back again.
|
||||
@@ -158,7 +168,7 @@ struct Pager {
|
||||
int nRef; /* Number of in-memory pages with PgHdr.nRef>0 */
|
||||
int mxPage; /* Maximum number of pages to hold in cache */
|
||||
int nHit, nMiss, nOvfl; /* Cache hits, missing, and LRU overflows */
|
||||
void (*xCodec)(void*,void*,int); /* Routine for en/decoding on-disk data */
|
||||
void (*xCodec)(void*,void*,Pgno,int); /* Routine for en/decoding data */
|
||||
void *pCodecArg; /* First argument to xCodec() */
|
||||
u8 journalOpen; /* True if journal file descriptors is valid */
|
||||
u8 journalStarted; /* True if header of journal is synced */
|
||||
@@ -562,9 +572,7 @@ static int pager_playback_one_page(Pager *pPager, OsFile *jfd, int format){
|
||||
memset(PGHDR_TO_EXTRA(pPg), 0, pPager->nExtra);
|
||||
pPg->dirty = 0;
|
||||
pPg->needSync = 0;
|
||||
if( pPager->xCodec ){
|
||||
pPager->xCodec(pPager->pCodecArg, PGHDR_TO_DATA(pPg), 3);
|
||||
}
|
||||
CODEC(pPager, PGHDR_TO_DATA(pPg), pPg->pgno, 3);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
@@ -724,10 +732,9 @@ static int pager_playback(Pager *pPager, int useJournalSize){
|
||||
if( (int)pPg->pgno <= pPager->origDbSize ){
|
||||
sqliteOsSeek(&pPager->fd, SQLITE_PAGE_SIZE*(off_t)(pPg->pgno-1));
|
||||
rc = sqliteOsRead(&pPager->fd, zBuf, SQLITE_PAGE_SIZE);
|
||||
TRACE2("REFETCH %d\n", pPg->pgno);
|
||||
CODEC(pPager, zBuf, pPg->pgno, 2);
|
||||
if( rc ) break;
|
||||
if( pPager->xCodec ){
|
||||
pPager->xCodec(pPager->pCodecArg, zBuf, 2);
|
||||
}
|
||||
}else{
|
||||
memset(zBuf, 0, SQLITE_PAGE_SIZE);
|
||||
}
|
||||
@@ -1247,13 +1254,10 @@ static int pager_write_pagelist(PgHdr *pList){
|
||||
while( pList ){
|
||||
assert( pList->dirty );
|
||||
sqliteOsSeek(&pPager->fd, (pList->pgno-1)*(off_t)SQLITE_PAGE_SIZE);
|
||||
if( pPager->xCodec ){
|
||||
pPager->xCodec(pPager->pCodecArg, PGHDR_TO_DATA(pList), 6);
|
||||
}
|
||||
CODEC(pPager, PGHDR_TO_DATA(pList), pList->pgno, 6);
|
||||
TRACE2("STORE %d\n", pList->pgno);
|
||||
rc = sqliteOsWrite(&pPager->fd, PGHDR_TO_DATA(pList), SQLITE_PAGE_SIZE);
|
||||
if( pPager->xCodec ){
|
||||
pPager->xCodec(pPager->pCodecArg, PGHDR_TO_DATA(pList), 0);
|
||||
}
|
||||
CODEC(pPager, PGHDR_TO_DATA(pList), pList->pgno, 0);
|
||||
if( rc ) return rc;
|
||||
pList->dirty = 0;
|
||||
pList = pList->pDirty;
|
||||
@@ -1514,6 +1518,8 @@ int sqlitepager_get(Pager *pPager, Pgno pgno, void **ppPage){
|
||||
int rc;
|
||||
sqliteOsSeek(&pPager->fd, (pgno-1)*(off_t)SQLITE_PAGE_SIZE);
|
||||
rc = sqliteOsRead(&pPager->fd, PGHDR_TO_DATA(pPg), SQLITE_PAGE_SIZE);
|
||||
TRACE2("FETCH %d\n", pPg->pgno);
|
||||
CODEC(pPager, PGHDR_TO_DATA(pPg), pPg->pgno, 3);
|
||||
if( rc!=SQLITE_OK ){
|
||||
off_t fileSize;
|
||||
if( sqliteOsFileSize(&pPager->fd,&fileSize)!=SQLITE_OK
|
||||
@@ -1523,8 +1529,6 @@ int sqlitepager_get(Pager *pPager, Pgno pgno, void **ppPage){
|
||||
}else{
|
||||
memset(PGHDR_TO_DATA(pPg), 0, SQLITE_PAGE_SIZE);
|
||||
}
|
||||
}else if( pPager->xCodec ){
|
||||
pPager->xCodec(pPager->pCodecArg, PGHDR_TO_DATA(pPg), 3);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
@@ -1803,13 +1807,10 @@ int sqlitepager_write(void *pData){
|
||||
szPg = SQLITE_PAGE_SIZE+4;
|
||||
}
|
||||
store32bits(pPg->pgno, pPg, -4);
|
||||
if( pPager->xCodec ){
|
||||
pPager->xCodec(pPager->pCodecArg, pData, 3);
|
||||
}
|
||||
CODEC(pPager, pData, pPg->pgno, 7);
|
||||
rc = sqliteOsWrite(&pPager->jfd, &((char*)pData)[-4], szPg);
|
||||
if( pPager->xCodec ){
|
||||
pPager->xCodec(pPager->pCodecArg, pData, 0);
|
||||
}
|
||||
TRACE3("JOURNAL %d %d\n", pPg->pgno, pPg->needSync);
|
||||
CODEC(pPager, pData, pPg->pgno, 0);
|
||||
if( journal_format>=JOURNAL_FORMAT_3 ){
|
||||
*(u32*)PGHDR_TO_EXTRA(pPg) = saved;
|
||||
}
|
||||
@@ -1827,7 +1828,6 @@ int sqlitepager_write(void *pData){
|
||||
pPager->aInCkpt[pPg->pgno/8] |= 1<<(pPg->pgno&7);
|
||||
page_add_to_ckpt_list(pPg);
|
||||
}
|
||||
TRACE3("JOURNAL %d %d\n", pPg->pgno, pPg->needSync);
|
||||
}else{
|
||||
pPg->needSync = !pPager->journalStarted && !pPager->noSync;
|
||||
TRACE3("APPEND %d %d\n", pPg->pgno, pPg->needSync);
|
||||
@@ -1845,7 +1845,10 @@ int sqlitepager_write(void *pData){
|
||||
if( pPager->ckptInUse && !pPg->inCkpt && (int)pPg->pgno<=pPager->ckptSize ){
|
||||
assert( pPg->inJournal || (int)pPg->pgno>pPager->origDbSize );
|
||||
store32bits(pPg->pgno, pPg, -4);
|
||||
CODEC(pPager, pData, pPg->pgno, 7);
|
||||
rc = sqliteOsWrite(&pPager->cpfd, &((char*)pData)[-4], SQLITE_PAGE_SIZE+4);
|
||||
TRACE2("CKPT-JOURNAL %d\n", pPg->pgno);
|
||||
CODEC(pPager, pData, pPg->pgno, 0);
|
||||
if( rc!=SQLITE_OK ){
|
||||
sqlitepager_rollback(pPager);
|
||||
pPager->errMask |= PAGER_ERR_FULL;
|
||||
@@ -2192,7 +2195,7 @@ const char *sqlitepager_filename(Pager *pPager){
|
||||
*/
|
||||
void sqlitepager_set_codec(
|
||||
Pager *pPager,
|
||||
void (*xCodec)(void*,void*,int),
|
||||
void (*xCodec)(void*,void*,Pgno,int),
|
||||
void *pCodecArg
|
||||
){
|
||||
pPager->xCodec = xCodec;
|
||||
|
Reference in New Issue
Block a user