On commit, flush dirty temp-file pages only if the file is already open and 25% or more of the cache is dirty.

FossilOrigin-Name: f6babf2920340f25815c0a3c58de1e902c2f5542
This commit is contained in:
dan 2016-04-13 16:52:11 +00:00
parent 199f56b984
commit 0f52455a35
5 changed files with 46 additions and 10 deletions

View File

@ -1,5 +1,5 @@
C Once\sa\stemporary\sdatabase\sfile\shas\sbeen\sopened,\sflush\sall\sdirty\spages\sto\sdisk\swhen\scomitting\sa\stransaction.
D 2016-04-12T19:09:29.339
C On\scommit,\sflush\sdirty\stemp-file\spages\sonly\sif\sthe\sfile\sis\salready\sopen\sand\s25%\sor\smore\sof\sthe\scache\sis\sdirty.
D 2016-04-13T16:52:11.775
F Makefile.in eba680121821b8a60940a81454316f47a341487a
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
F Makefile.msc 71b8b16cf9393f68e2e2035486ca104872558836
@ -362,11 +362,11 @@ F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa
F src/os_unix.c bde4844f0849cab5924c6a81178f8500774ce76b
F src/os_win.c b3ba9573d8d893e70a6a8015bbee572ecf7ffbef
F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca
F src/pager.c 525f3698f9a6b47a6e0f5496675529a183c2462b
F src/pager.c 4d849ad718980d698157cd136a40dc91cbeff4d3
F src/pager.h e1d38a2f14849e219df0f91f8323504d134c8a56
F src/parse.y 10eb2f3fb62341291528c7984498054731f9d31e
F src/pcache.c e9c00846d3dcdaa75b288c6f16238c2fe2177823
F src/pcache.h 4d0ccaad264d360981ec5e6a2b596d6e85242545
F src/pcache.c d63b34cce0a8aba1fa552428b2790e13877db553
F src/pcache.h 60bc9893bfc0e16f8178fb5d8b6fcb8fab1d93c0
F src/pcache1.c c40cdb93586e21b5dd826b5e671240bd91c26b05
F src/pragma.c faf42922bb7ab2f6672cb550356c1967abae3c84
F src/pragma.h 64c78a648751b9f4f297276c4eb7507b14b4628c
@ -1484,7 +1484,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 9682c0433c04713c28bd9105a7e20af7372f873e
R ade8e2f9d92ad43fcc4c6c4e5d1634ec
P bbac71aa2aa2380d393cda3be64b0208b464b27e
R d455655e720096e5ec7c439c248aa874
T *branch * tempfiles-25
T *sym-tempfiles-25 *
T -sym-tempfiles-lazy-open *
U dan
Z 4a91ff9d1af5229ff41acb5284c79d70
Z 1d78549afb34b97c4ff4b3e2f6fd7c59

View File

@ -1 +1 @@
bbac71aa2aa2380d393cda3be64b0208b464b27e
f6babf2920340f25815c0a3c58de1e902c2f5542

View File

@ -1873,6 +1873,25 @@ static int pager_error(Pager *pPager, int rc){
static int pager_truncate(Pager *pPager, Pgno nPage);
/*
** The write transaction open on the pager passed as the only argument is
** being committed. This function returns true if all dirty pages should
** be flushed to disk, or false otherwise. Pages should be flushed to disk
** unless one of the following is true:
**
** * The db is an in-memory database.
**
** * The db is a temporary database and the db file has not been opened.
**
** * The db is a temporary database and the cache contains less than
** C/4 dirty pages, where C is the configured cache-size.
*/
static int pagerFlushOnCommit(Pager *pPager){
if( pPager->tempFile==0 ) return 1;
if( !isOpen(pPager->fd) ) return 0;
return (sqlite3PCachePercentDirty(pPager->pPCache)>=25);
}
/*
** This routine ends a transaction. A transaction is usually ended by
** either a COMMIT or a ROLLBACK operation. This routine may be called
@ -2011,7 +2030,7 @@ static int pager_end_transaction(Pager *pPager, int hasMaster, int bCommit){
sqlite3BitvecDestroy(pPager->pInJournal);
pPager->pInJournal = 0;
pPager->nRec = 0;
if( isOpen(pPager->fd) || MEMDB ){
if( pagerFlushOnCommit(pPager) ){
sqlite3PcacheCleanAll(pPager->pPCache);
}else{
sqlite3PcacheClearWritable(pPager->pPCache);

View File

@ -686,6 +686,17 @@ void sqlite3PcacheShrink(PCache *pCache){
*/
int sqlite3HeaderSizePcache(void){ return ROUND8(sizeof(PgHdr)); }
/*
** Return the number of dirty pages currently in the cache, as a percentage
** of the configured cache size.
*/
int sqlite3PCachePercentDirty(PCache *pCache){
PgHdr *pDirty;
int nDirty = 0;
int nCache = numberOfCachePages(pCache);
for(pDirty=pCache->pDirty; pDirty; pDirty=pDirty->pDirtyNext) nDirty++;
return (int)(((i64)nDirty * 100) / nCache);
}
#if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG)
/*

View File

@ -173,4 +173,7 @@ void sqlite3PCacheSetDefault(void);
int sqlite3HeaderSizePcache(void);
int sqlite3HeaderSizePcache1(void);
/* Number of dirty pages as a percentage of the configured cache size */
int sqlite3PCachePercentDirty(PCache*);
#endif /* _PCACHE_H_ */