This commit is contained in:
Hongze Cheng 2022-02-21 08:08:36 +00:00
parent f2096385d0
commit 7248dc6868
3 changed files with 378 additions and 382 deletions

View File

@ -65,7 +65,10 @@ struct PCache {
#if defined(SQLITE_DEBUG) && 0 #if defined(SQLITE_DEBUG) && 0
int sqlite3PcacheTrace = 2; /* 0: off 1: simple 2: cache dumps */ int sqlite3PcacheTrace = 2; /* 0: off 1: simple 2: cache dumps */
int sqlite3PcacheMxDump = 9999; /* Max cache entries for pcacheDump() */ int sqlite3PcacheMxDump = 9999; /* Max cache entries for pcacheDump() */
# define pcacheTrace(X) if(sqlite3PcacheTrace){sqlite3DebugPrintf X;} #define pcacheTrace(X) \
if (sqlite3PcacheTrace) { \
sqlite3DebugPrintf X; \
}
void pcacheDump(PCache *pCache) { void pcacheDump(PCache *pCache) {
int N; int N;
int i, j; int i, j;
@ -78,7 +81,7 @@ struct PCache {
N = sqlite3PcachePagecount(pCache); N = sqlite3PcachePagecount(pCache);
if (N > sqlite3PcacheMxDump) N = sqlite3PcacheMxDump; if (N > sqlite3PcacheMxDump) N = sqlite3PcacheMxDump;
for (i = 1; i <= N; i++) { for (i = 1; i <= N; i++) {
pLower = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, i, 0); pLower = pcache2.xFetch(pCache->pCache, i, 0);
if (pLower == 0) continue; if (pLower == 0) continue;
pPg = (PgHdr *)pLower->pExtra; pPg = (PgHdr *)pLower->pExtra;
printf("%3d: nRef %2d flgs %02x data ", i, pPg->nRef, pPg->flags); printf("%3d: nRef %2d flgs %02x data ", i, pPg->nRef, pPg->flags);
@ -86,7 +89,7 @@ struct PCache {
for (j = 0; j < 12; j++) printf("%02x", a[j]); for (j = 0; j < 12; j++) printf("%02x", a[j]);
printf("\n"); printf("\n");
if (pPg->pPage == 0) { if (pPg->pPage == 0) {
sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, pLower, 0); pcache2.xUnpin(pCache->pCache, pLower, 0);
} }
} }
} }
@ -141,7 +144,6 @@ int sqlite3PcachePageSanity(PgHdr *pPg){
} }
#endif /* SQLITE_DEBUG */ #endif /* SQLITE_DEBUG */
/********************************** Linked List Management ********************/ /********************************** Linked List Management ********************/
/* Allowed values for second argument to pcacheManageDirtyList() */ /* Allowed values for second argument to pcacheManageDirtyList() */
@ -158,9 +160,7 @@ int sqlite3PcachePageSanity(PgHdr *pPg){
static void pcacheManageDirtyList(PgHdr *pPage, u8 addRemove) { static void pcacheManageDirtyList(PgHdr *pPage, u8 addRemove) {
PCache *p = pPage->pCache; PCache *p = pPage->pCache;
pcacheTrace(("%p.DIRTYLIST.%s %d\n", p, pcacheTrace(("%p.DIRTYLIST.%s %d\n", p, addRemove == 1 ? "REMOVE" : addRemove == 2 ? "ADD" : "FRONT", pPage->pgno));
addRemove==1 ? "REMOVE" : addRemove==2 ? "ADD" : "FRONT",
pPage->pgno));
if (addRemove & PCACHE_DIRTYLIST_REMOVE) { if (addRemove & PCACHE_DIRTYLIST_REMOVE) {
assert(pPage->pDirtyNext || pPage == p->pDirtyTail); assert(pPage->pDirtyNext || pPage == p->pDirtyTail);
assert(pPage->pDirtyPrev || pPage == p->pDirty); assert(pPage->pDirtyPrev || pPage == p->pDirty);
@ -212,8 +212,7 @@ static void pcacheManageDirtyList(PgHdr *pPage, u8 addRemove){
** optimization, as if pSynced points to a page with the NEED_SYNC ** optimization, as if pSynced points to a page with the NEED_SYNC
** flag set sqlite3PcacheFetchStress() searches through all newer ** flag set sqlite3PcacheFetchStress() searches through all newer
** entries of the dirty-list for a page with NEED_SYNC clear anyway. */ ** entries of the dirty-list for a page with NEED_SYNC clear anyway. */
if( !p->pSynced if (!p->pSynced && 0 == (pPage->flags & PGHDR_NEED_SYNC) /*OPTIMIZATION-IF-FALSE*/
&& 0==(pPage->flags&PGHDR_NEED_SYNC) /*OPTIMIZATION-IF-FALSE*/
) { ) {
p->pSynced = pPage; p->pSynced = pPage;
} }
@ -228,7 +227,7 @@ static void pcacheManageDirtyList(PgHdr *pPage, u8 addRemove){
static void pcacheUnpin(PgHdr *p) { static void pcacheUnpin(PgHdr *p) {
if (p->pCache->bPurgeable) { if (p->pCache->bPurgeable) {
pcacheTrace(("%p.UNPIN %d\n", p->pCache, p->pgno)); pcacheTrace(("%p.UNPIN %d\n", p->pCache, p->pgno));
sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 0); pcache2.xUnpin(p->pCache->pCache, p->pPage, 0);
pcacheDump(p->pCache); pcacheDump(p->pCache);
} }
} }
@ -259,20 +258,11 @@ static int numberOfCachePages(PCache *p){
** Initialize and shutdown the page cache subsystem. Neither of these ** Initialize and shutdown the page cache subsystem. Neither of these
** functions are threadsafe. ** functions are threadsafe.
*/ */
int sqlite3PcacheInitialize(void){ int sqlite3PcacheInitialize(void) { return pcache2.xInit(pcache2.pArg); }
if( sqlite3GlobalConfig.pcache2.xInit==0 ){
/* IMPLEMENTATION-OF: R-26801-64137 If the xInit() method is NULL, then the
** built-in default page cache is used instead of the application defined
** page cache. */
sqlite3PCacheSetDefault();
assert( sqlite3GlobalConfig.pcache2.xInit!=0 );
}
return sqlite3GlobalConfig.pcache2.xInit(sqlite3GlobalConfig.pcache2.pArg);
}
void sqlite3PcacheShutdown(void) { void sqlite3PcacheShutdown(void) {
if( sqlite3GlobalConfig.pcache2.xShutdown ){ if (pcache2.xShutdown) {
/* IMPLEMENTATION-OF: R-26000-56589 The xShutdown() method may be NULL. */ /* IMPLEMENTATION-OF: R-26000-56589 The xShutdown() method may be NULL. */
sqlite3GlobalConfig.pcache2.xShutdown(sqlite3GlobalConfig.pcache2.pArg); pcache2.xShutdown(pcache2.pArg);
} }
} }
@ -293,8 +283,7 @@ int sqlite3PcacheSize(void){ return sizeof(PCache); }
** to this module, the extra space really ends up being the MemPage ** to this module, the extra space really ends up being the MemPage
** structure in the pager. ** structure in the pager.
*/ */
int sqlite3PcacheOpen( int sqlite3PcacheOpen(int szPage, /* Size of every page */
int szPage, /* Size of every page */
int szExtra, /* Extra space associated with each page */ int szExtra, /* Extra space associated with each page */
int bPurgeable, /* True if pages are on backing store */ int bPurgeable, /* True if pages are on backing store */
int (*xStress)(void *, PgHdr *), /* Call to try to make pages clean */ int (*xStress)(void *, PgHdr *), /* Call to try to make pages clean */
@ -323,14 +312,11 @@ int sqlite3PcacheSetPageSize(PCache *pCache, int szPage){
assert(pCache->nRefSum == 0 && pCache->pDirty == 0); assert(pCache->nRefSum == 0 && pCache->pDirty == 0);
if (pCache->szPage) { if (pCache->szPage) {
sqlite3_pcache *pNew; sqlite3_pcache *pNew;
pNew = sqlite3GlobalConfig.pcache2.xCreate( pNew = pcache2.xCreate(szPage, pCache->szExtra + ROUND8(sizeof(PgHdr)), pCache->bPurgeable);
szPage, pCache->szExtra + ROUND8(sizeof(PgHdr)),
pCache->bPurgeable
);
if (pNew == 0) return SQLITE_NOMEM_BKPT; if (pNew == 0) return SQLITE_NOMEM_BKPT;
sqlite3GlobalConfig.pcache2.xCachesize(pNew, numberOfCachePages(pCache)); pcache2.xCachesize(pNew, numberOfCachePages(pCache));
if (pCache->pCache) { if (pCache->pCache) {
sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache); pcache2.xDestroy(pCache->pCache);
} }
pCache->pCache = pNew; pCache->pCache = pNew;
pCache->szPage = szPage; pCache->szPage = szPage;
@ -363,8 +349,7 @@ int sqlite3PcacheSetPageSize(PCache *pCache, int szPage){
** the stack on entry and pop them back off on exit, which saves a ** the stack on entry and pop them back off on exit, which saves a
** lot of pushing and popping. ** lot of pushing and popping.
*/ */
sqlite3_pcache_page *sqlite3PcacheFetch( sqlite3_pcache_page *sqlite3PcacheFetch(PCache *pCache, /* Obtain the page from this cache */
PCache *pCache, /* Obtain the page from this cache */
Pgno pgno, /* Page number to obtain */ Pgno pgno, /* Page number to obtain */
int createFlag /* If true, create page if it does not exist already */ int createFlag /* If true, create page if it does not exist already */
) { ) {
@ -387,9 +372,8 @@ sqlite3_pcache_page *sqlite3PcacheFetch(
assert(eCreate == 0 || eCreate == 1 || eCreate == 2); assert(eCreate == 0 || eCreate == 1 || eCreate == 2);
assert(createFlag == 0 || pCache->eCreate == eCreate); assert(createFlag == 0 || pCache->eCreate == eCreate);
assert(createFlag == 0 || eCreate == 1 + (!pCache->bPurgeable || !pCache->pDirty)); assert(createFlag == 0 || eCreate == 1 + (!pCache->bPurgeable || !pCache->pDirty));
pRes = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate); pRes = pcache2.xFetch(pCache->pCache, pgno, eCreate);
pcacheTrace(("%p.FETCH %d%s (result: %p)\n",pCache,pgno, pcacheTrace(("%p.FETCH %d%s (result: %p)\n", pCache, pgno, createFlag ? " create" : "", pRes));
createFlag?" create":"",pRes));
return pRes; return pRes;
} }
@ -404,8 +388,7 @@ sqlite3_pcache_page *sqlite3PcacheFetch(
** **
** This routine should be invoked only after sqlite3PcacheFetch() fails. ** This routine should be invoked only after sqlite3PcacheFetch() fails.
*/ */
int sqlite3PcacheFetchStress( int sqlite3PcacheFetchStress(PCache * pCache, /* Obtain the page from this cache */
PCache *pCache, /* Obtain the page from this cache */
Pgno pgno, /* Page number to obtain */ Pgno pgno, /* Page number to obtain */
sqlite3_pcache_page **ppPage /* Write result here */ sqlite3_pcache_page **ppPage /* Write result here */
) { ) {
@ -422,22 +405,18 @@ int sqlite3PcacheFetchStress(
** flag is currently referenced, then the following may leave pSynced ** flag is currently referenced, then the following may leave pSynced
** set incorrectly (pointing to other than the LRU page with NEED_SYNC ** set incorrectly (pointing to other than the LRU page with NEED_SYNC
** cleared). This is Ok, as pSynced is just an optimization. */ ** cleared). This is Ok, as pSynced is just an optimization. */
for(pPg=pCache->pSynced; for (pPg = pCache->pSynced; pPg && (pPg->nRef || (pPg->flags & PGHDR_NEED_SYNC)); pPg = pPg->pDirtyPrev)
pPg && (pPg->nRef || (pPg->flags&PGHDR_NEED_SYNC)); ;
pPg=pPg->pDirtyPrev
);
pCache->pSynced = pPg; pCache->pSynced = pPg;
if (!pPg) { if (!pPg) {
for(pPg=pCache->pDirtyTail; pPg && pPg->nRef; pPg=pPg->pDirtyPrev); for (pPg = pCache->pDirtyTail; pPg && pPg->nRef; pPg = pPg->pDirtyPrev)
;
} }
if (pPg) { if (pPg) {
int rc; int rc;
#ifdef SQLITE_LOG_CACHE_SPILL #ifdef SQLITE_LOG_CACHE_SPILL
sqlite3_log(SQLITE_FULL, sqlite3_log(SQLITE_FULL, "spill page %d making room for %d - cache used: %d/%d", pPg->pgno, pgno,
"spill page %d making room for %d - cache used: %d/%d", pcache2.xPagecount(pCache->pCache), numberOfCachePages(pCache));
pPg->pgno, pgno,
sqlite3GlobalConfig.pcache2.xPagecount(pCache->pCache),
numberOfCachePages(pCache));
#endif #endif
pcacheTrace(("%p.SPILL %d\n", pCache, pPg->pgno)); pcacheTrace(("%p.SPILL %d\n", pCache, pPg->pgno));
rc = pCache->xStress(pCache->pStress, pPg); rc = pCache->xStress(pCache->pStress, pPg);
@ -447,7 +426,7 @@ int sqlite3PcacheFetchStress(
} }
} }
} }
*ppPage = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, 2); *ppPage = pcache2.xFetch(pCache->pCache, pgno, 2);
return *ppPage == 0 ? SQLITE_NOMEM_BKPT : SQLITE_OK; return *ppPage == 0 ? SQLITE_NOMEM_BKPT : SQLITE_OK;
} }
@ -486,8 +465,7 @@ static SQLITE_NOINLINE PgHdr *pcacheFetchFinishWithInit(
** must be called after sqlite3PcacheFetch() in order to get a usable ** must be called after sqlite3PcacheFetch() in order to get a usable
** result. ** result.
*/ */
PgHdr *sqlite3PcacheFetchFinish( PgHdr *sqlite3PcacheFetchFinish(PCache * pCache, /* Obtain the page from this cache */
PCache *pCache, /* Obtain the page from this cache */
Pgno pgno, /* Page number obtained */ Pgno pgno, /* Page number obtained */
sqlite3_pcache_page *pPage /* Page obtained by prior PcacheFetch() call */ sqlite3_pcache_page *pPage /* Page obtained by prior PcacheFetch() call */
) { ) {
@ -543,7 +521,7 @@ void sqlite3PcacheDrop(PgHdr *p){
pcacheManageDirtyList(p, PCACHE_DIRTYLIST_REMOVE); pcacheManageDirtyList(p, PCACHE_DIRTYLIST_REMOVE);
} }
p->pCache->nRefSum--; p->pCache->nRefSum--;
sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 1); pcache2.xUnpin(p->pCache->pCache, p->pPage, 1);
} }
/* /*
@ -626,7 +604,7 @@ void sqlite3PcacheMove(PgHdr *p, Pgno newPgno){
assert(newPgno > 0); assert(newPgno > 0);
assert(sqlite3PcachePageSanity(p)); assert(sqlite3PcachePageSanity(p));
pcacheTrace(("%p.MOVE %d -> %d\n", pCache, p->pgno, newPgno)); pcacheTrace(("%p.MOVE %d -> %d\n", pCache, p->pgno, newPgno));
sqlite3GlobalConfig.pcache2.xRekey(pCache->pCache, p->pPage, p->pgno,newPgno); pcache2.xRekey(pCache->pCache, p->pPage, p->pgno, newPgno);
p->pgno = newPgno; p->pgno = newPgno;
if ((p->flags & PGHDR_DIRTY) && (p->flags & PGHDR_NEED_SYNC)) { if ((p->flags & PGHDR_DIRTY) && (p->flags & PGHDR_NEED_SYNC)) {
pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT); pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT);
@ -661,14 +639,14 @@ void sqlite3PcacheTruncate(PCache *pCache, Pgno pgno){
} }
if (pgno == 0 && pCache->nRefSum) { if (pgno == 0 && pCache->nRefSum) {
sqlite3_pcache_page *pPage1; sqlite3_pcache_page *pPage1;
pPage1 = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache,1,0); pPage1 = pcache2.xFetch(pCache->pCache, 1, 0);
if (ALWAYS(pPage1)) { /* Page 1 is always available in cache, because if (ALWAYS(pPage1)) { /* Page 1 is always available in cache, because
** pCache->nRefSum>0 */ ** pCache->nRefSum>0 */
memset(pPage1->pBuf, 0, pCache->szPage); memset(pPage1->pBuf, 0, pCache->szPage);
pgno = 1; pgno = 1;
} }
} }
sqlite3GlobalConfig.pcache2.xTruncate(pCache->pCache, pgno+1); pcache2.xTruncate(pCache->pCache, pgno + 1);
} }
} }
@ -678,15 +656,13 @@ void sqlite3PcacheTruncate(PCache *pCache, Pgno pgno){
void sqlite3PcacheClose(PCache *pCache) { void sqlite3PcacheClose(PCache *pCache) {
assert(pCache->pCache != 0); assert(pCache->pCache != 0);
pcacheTrace(("%p.CLOSE\n", pCache)); pcacheTrace(("%p.CLOSE\n", pCache));
sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache); pcache2.xDestroy(pCache->pCache);
} }
/* /*
** Discard the contents of the cache. ** Discard the contents of the cache.
*/ */
void sqlite3PcacheClear(PCache *pCache){ void sqlite3PcacheClear(PCache *pCache) { sqlite3PcacheTruncate(pCache, 0); }
sqlite3PcacheTruncate(pCache, 0);
}
/* /*
** Merge two lists of pages connected by pDirty and in pgno order. ** Merge two lists of pages connected by pDirty and in pgno order.
@ -778,32 +754,26 @@ PgHdr *sqlite3PcacheDirtyList(PCache *pCache){
** This is not the total number of pages referenced, but the sum of the ** This is not the total number of pages referenced, but the sum of the
** reference count for all pages. ** reference count for all pages.
*/ */
int sqlite3PcacheRefCount(PCache *pCache){ int sqlite3PcacheRefCount(PCache *pCache) { return pCache->nRefSum; }
return pCache->nRefSum;
}
/* /*
** Return the number of references to the page supplied as an argument. ** Return the number of references to the page supplied as an argument.
*/ */
int sqlite3PcachePageRefcount(PgHdr *p){ int sqlite3PcachePageRefcount(PgHdr *p) { return p->nRef; }
return p->nRef;
}
/* /*
** Return the total number of pages in the cache. ** Return the total number of pages in the cache.
*/ */
int sqlite3PcachePagecount(PCache *pCache) { int sqlite3PcachePagecount(PCache *pCache) {
assert(pCache->pCache != 0); assert(pCache->pCache != 0);
return sqlite3GlobalConfig.pcache2.xPagecount(pCache->pCache); return pcache2.xPagecount(pCache->pCache);
} }
#ifdef SQLITE_TEST #ifdef SQLITE_TEST
/* /*
** Get the suggested cache-size value. ** Get the suggested cache-size value.
*/ */
int sqlite3PcacheGetCachesize(PCache *pCache){ int sqlite3PcacheGetCachesize(PCache *pCache) { return numberOfCachePages(pCache); }
return numberOfCachePages(pCache);
}
#endif #endif
/* /*
@ -812,8 +782,7 @@ int sqlite3PcacheGetCachesize(PCache *pCache){
void sqlite3PcacheSetCachesize(PCache *pCache, int mxPage) { void sqlite3PcacheSetCachesize(PCache *pCache, int mxPage) {
assert(pCache->pCache != 0); assert(pCache->pCache != 0);
pCache->szCache = mxPage; pCache->szCache = mxPage;
sqlite3GlobalConfig.pcache2.xCachesize(pCache->pCache, pcache2.xCachesize(pCache->pCache, numberOfCachePages(pCache));
numberOfCachePages(pCache));
} }
/* /*
@ -840,7 +809,7 @@ int sqlite3PcacheSetSpillsize(PCache *p, int mxPage){
*/ */
void sqlite3PcacheShrink(PCache *pCache) { void sqlite3PcacheShrink(PCache *pCache) {
assert(pCache->pCache != 0); assert(pCache->pCache != 0);
sqlite3GlobalConfig.pcache2.xShrink(pCache->pCache); pcache2.xShrink(pCache->pCache);
} }
/* /*
@ -865,9 +834,7 @@ int sqlite3PCachePercentDirty(PCache *pCache){
/* /*
** Return true if there are one or more dirty pages in the cache. Else false. ** Return true if there are one or more dirty pages in the cache. Else false.
*/ */
int sqlite3PCacheIsDirty(PCache *pCache){ int sqlite3PCacheIsDirty(PCache *pCache) { return (pCache->pDirty != 0); }
return (pCache->pDirty!=0);
}
#endif #endif
#if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG) #if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG)

View File

@ -199,10 +199,26 @@ struct PgFreeslot {
PgFreeslot *pNext; /* Next free slot */ PgFreeslot *pNext; /* Next free slot */
}; };
sqlite3_pcache_methods2 pcache2 = {
1, /* iVersion */
0, /* pArg */
pcache1Init, /* xInit */
pcache1Shutdown, /* xShutdown */
pcache1Create, /* xCreate */
pcache1Cachesize, /* xCachesize */
pcache1Pagecount, /* xPagecount */
pcache1Fetch, /* xFetch */
pcache1Unpin, /* xUnpin */
pcache1Rekey, /* xRekey */
pcache1Truncate, /* xTruncate */
pcache1Destroy, /* xDestroy */
pcache1Shrink /* xShrink */
};
/* /*
** Global data used by this cache. ** Global data used by this cache.
*/ */
static SQLITE_WSD struct PCacheGlobal { static struct PCacheGlobal {
PGroup grp; /* The global PGroup for mode (2) */ PGroup grp; /* The global PGroup for mode (2) */
/* Variables related to SQLITE_CONFIG_PAGECACHE settings. The /* Variables related to SQLITE_CONFIG_PAGECACHE settings. The
@ -226,14 +242,7 @@ static SQLITE_WSD struct PCacheGlobal {
** (2) even if an incorrect value is read, no great harm is done since this ** (2) even if an incorrect value is read, no great harm is done since this
** is really just an optimization. */ ** is really just an optimization. */
int bUnderPressure; /* True if low on PAGECACHE memory */ int bUnderPressure; /* True if low on PAGECACHE memory */
} pcache1_g; } pcache1;
/*
** All code in this file should access the global structure above via the
** alias "pcache1". This ensures that the WSD emulation is used when
** compiling for systems that do not support real WSD.
*/
#define pcache1 (GLOBAL(struct PCacheGlobal, pcache1_g))
/* /*
** Macros to enter and leave the PCache LRU mutex. ** Macros to enter and leave the PCache LRU mutex.

View File

@ -51,7 +51,8 @@ struct PgHdr {
#define PGHDR_CLEAN 0x001 /* Page not on the PCache.pDirty list */ #define PGHDR_CLEAN 0x001 /* Page not on the PCache.pDirty list */
#define PGHDR_DIRTY 0x002 /* Page is on the PCache.pDirty list */ #define PGHDR_DIRTY 0x002 /* Page is on the PCache.pDirty list */
#define PGHDR_WRITEABLE 0x004 /* Journaled and ready to modify */ #define PGHDR_WRITEABLE 0x004 /* Journaled and ready to modify */
#define PGHDR_NEED_SYNC 0x008 /* Fsync the rollback journal before #define PGHDR_NEED_SYNC \
0x008 /* Fsync the rollback journal before \
** writing this page to the database */ ** writing this page to the database */
#define PGHDR_DONT_WRITE 0x010 /* Do not write content to disk */ #define PGHDR_DONT_WRITE 0x010 /* Do not write content to disk */
#define PGHDR_MMAP 0x020 /* This is an mmap page object */ #define PGHDR_MMAP 0x020 /* This is an mmap page object */
@ -71,8 +72,7 @@ void sqlite3PCacheBufferSetup(void *, int sz, int n);
** Under memory stress, invoke xStress to try to make pages clean. ** Under memory stress, invoke xStress to try to make pages clean.
** Only clean and unpinned pages can be reclaimed. ** Only clean and unpinned pages can be reclaimed.
*/ */
int sqlite3PcacheOpen( int sqlite3PcacheOpen(int szPage, /* Size of every page */
int szPage, /* Size of every page */
int szExtra, /* Extra space associated with each page */ int szExtra, /* Extra space associated with each page */
int bPurgeable, /* True if pages are on backing store */ int bPurgeable, /* True if pages are on backing store */
int (*xStress)(void *, PgHdr *), /* Call to try to make pages clean */ int (*xStress)(void *, PgHdr *), /* Call to try to make pages clean */
@ -187,4 +187,24 @@ int sqlite3PCachePercentDirty(PCache*);
int sqlite3PCacheIsDirty(PCache *pCache); int sqlite3PCacheIsDirty(PCache *pCache);
#endif #endif
// For real implementation of sqlite3_pcache ========================================
typedef struct sqlite3_pcache sqlite3_pcache;
typedef struct sqlite3_pcache_methods2 {
int iVersion;
void *pArg;
int (*xInit)(void *);
void (*xShutdown)(void *);
sqlite3_pcache *(*xCreate)(int szPage, int szExtra, int bPurgeable);
void (*xCachesize)(sqlite3_pcache *, int nCachesize);
int (*xPagecount)(sqlite3_pcache *);
sqlite3_pcache_page *(*xFetch)(sqlite3_pcache *, unsigned key, int createFlag);
void (*xUnpin)(sqlite3_pcache *, sqlite3_pcache_page *, int discard);
void (*xRekey)(sqlite3_pcache *, sqlite3_pcache_page *, unsigned oldKey, unsigned newKey);
void (*xTruncate)(sqlite3_pcache *, unsigned iLimit);
void (*xDestroy)(sqlite3_pcache *);
void (*xShrink)(sqlite3_pcache *);
} sqlite3_pcache_methods2;
extern sqlite3_pcache_methods2 pcache2;
#endif /* _PCACHE_H_ */ #endif /* _PCACHE_H_ */