Fossil SCM

Update the built-in SQLite to version 3.13.0 final.

drh 2016-05-18 15:19 trunk
Commit 3747b4b5ea9e4c9b7e9730806178670e7aae009a
2 files changed +226 -82 +1 -1
+226 -82
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -363,11 +363,11 @@
363363
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
364364
** [sqlite_version()] and [sqlite_source_id()].
365365
*/
366366
#define SQLITE_VERSION "3.13.0"
367367
#define SQLITE_VERSION_NUMBER 3013000
368
-#define SQLITE_SOURCE_ID "2016-05-09 19:03:42 14e53d0e2f62d82ae1d64a72fd9711548e3bf5ea"
368
+#define SQLITE_SOURCE_ID "2016-05-18 10:57:30 fc49f556e48970561d7ab6a2f24fdd7d9eb81ff2"
369369
370370
/*
371371
** CAPI3REF: Run-Time Library Version Numbers
372372
** KEYWORDS: sqlite3_version, sqlite3_sourceid
373373
**
@@ -10917,11 +10917,11 @@
1091710917
**
1091810918
** When doing coverage testing ALWAYS and NEVER are hard-coded to
1091910919
** be true and false so that the unreachable code they specify will
1092010920
** not be counted as untested code.
1092110921
*/
10922
-#if defined(SQLITE_COVERAGE_TEST)
10922
+#if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_MUTATION_TEST)
1092310923
# define ALWAYS(X) (1)
1092410924
# define NEVER(X) (0)
1092510925
#elif !defined(NDEBUG)
1092610926
# define ALWAYS(X) ((X)?1:(assert(0),0))
1092710927
# define NEVER(X) ((X)?(assert(0),1):0)
@@ -12954,11 +12954,11 @@
1295412954
*/
1295512955
struct PgHdr {
1295612956
sqlite3_pcache_page *pPage; /* Pcache object page handle */
1295712957
void *pData; /* Page data */
1295812958
void *pExtra; /* Extra content */
12959
- PgHdr *pDirty; /* Transient list of dirty pages */
12959
+ PgHdr *pDirty; /* Transient list of dirty sorted by pgno */
1296012960
Pager *pPager; /* The pager this page is part of */
1296112961
Pgno pgno; /* Page number for this page */
1296212962
#ifdef SQLITE_CHECK_PAGES
1296312963
u32 pageHash; /* Hash of page content */
1296412964
#endif
@@ -12979,15 +12979,14 @@
1297912979
#define PGHDR_CLEAN 0x001 /* Page not on the PCache.pDirty list */
1298012980
#define PGHDR_DIRTY 0x002 /* Page is on the PCache.pDirty list */
1298112981
#define PGHDR_WRITEABLE 0x004 /* Journaled and ready to modify */
1298212982
#define PGHDR_NEED_SYNC 0x008 /* Fsync the rollback journal before
1298312983
** writing this page to the database */
12984
-#define PGHDR_NEED_READ 0x010 /* Content is unread */
12985
-#define PGHDR_DONT_WRITE 0x020 /* Do not write content to disk */
12986
-#define PGHDR_MMAP 0x040 /* This is an mmap page object */
12984
+#define PGHDR_DONT_WRITE 0x010 /* Do not write content to disk */
12985
+#define PGHDR_MMAP 0x020 /* This is an mmap page object */
1298712986
12988
-#define PGHDR_WAL_APPEND 0x080 /* Appended to wal file */
12987
+#define PGHDR_WAL_APPEND 0x040 /* Appended to wal file */
1298912988
1299012989
/* Initialize and shutdown the page cache subsystem */
1299112990
SQLITE_PRIVATE int sqlite3PcacheInitialize(void);
1299212991
SQLITE_PRIVATE void sqlite3PcacheShutdown(void);
1299312992
@@ -13065,10 +13064,15 @@
1306513064
** interface is only available if SQLITE_CHECK_PAGES is defined when the
1306613065
** library is built.
1306713066
*/
1306813067
SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *));
1306913068
#endif
13069
+
13070
+#if defined(SQLITE_DEBUG)
13071
+/* Check invariants on a PgHdr object */
13072
+SQLITE_PRIVATE int sqlite3PcachePageSanity(PgHdr*);
13073
+#endif
1307013074
1307113075
/* Set and get the suggested cache-size for the specified pager-cache.
1307213076
**
1307313077
** If no global maximum is configured, then the system attempts to limit
1307413078
** the total number of pages cached by purgeable pager-caches to the sum
@@ -43115,11 +43119,33 @@
4311543119
** This file implements that page cache.
4311643120
*/
4311743121
/* #include "sqliteInt.h" */
4311843122
4311943123
/*
43120
-** A complete page cache is an instance of this structure.
43124
+** A complete page cache is an instance of this structure. Every
43125
+** entry in the cache holds a single page of the database file. The
43126
+** btree layer only operates on the cached copy of the database pages.
43127
+**
43128
+** A page cache entry is "clean" if it exactly matches what is currently
43129
+** on disk. A page is "dirty" if it has been modified and needs to be
43130
+** persisted to disk.
43131
+**
43132
+** pDirty, pDirtyTail, pSynced:
43133
+** All dirty pages are linked into the doubly linked list using
43134
+** PgHdr.pDirtyNext and pDirtyPrev. The list is maintained in LRU order
43135
+** such that p was added to the list more recently than p->pDirtyNext.
43136
+** PCache.pDirty points to the first (newest) element in the list and
43137
+** pDirtyTail to the last (oldest).
43138
+**
43139
+** The PCache.pSynced variable is used to optimize searching for a dirty
43140
+** page to eject from the cache mid-transaction. It is better to eject
43141
+** a page that does not require a journal sync than one that does.
43142
+** Therefore, pSynced is maintained to that it *almost* always points
43143
+** to either the oldest page in the pDirty/pDirtyTail list that has a
43144
+** clear PGHDR_NEED_SYNC flag or to a page that is older than this one
43145
+** (so that the right page to eject can be found by following pDirtyPrev
43146
+** pointers).
4312143147
*/
4312243148
struct PCache {
4312343149
PgHdr *pDirty, *pDirtyTail; /* List of dirty pages in LRU order */
4312443150
PgHdr *pSynced; /* Last synced page in dirty page list */
4312543151
int nRefSum; /* Sum of ref counts over all pages */
@@ -43131,10 +43157,99 @@
4313143157
u8 eCreate; /* eCreate value for for xFetch() */
4313243158
int (*xStress)(void*,PgHdr*); /* Call to try make a page clean */
4313343159
void *pStress; /* Argument to xStress */
4313443160
sqlite3_pcache *pCache; /* Pluggable cache module */
4313543161
};
43162
+
43163
+/********************************** Test and Debug Logic **********************/
43164
+/*
43165
+** Debug tracing macros. Enable by by changing the "0" to "1" and
43166
+** recompiling.
43167
+**
43168
+** When sqlite3PcacheTrace is 1, single line trace messages are issued.
43169
+** When sqlite3PcacheTrace is 2, a dump of the pcache showing all cache entries
43170
+** is displayed for many operations, resulting in a lot of output.
43171
+*/
43172
+#if defined(SQLITE_DEBUG) && 0
43173
+ int sqlite3PcacheTrace = 2; /* 0: off 1: simple 2: cache dumps */
43174
+ int sqlite3PcacheMxDump = 9999; /* Max cache entries for pcacheDump() */
43175
+# define pcacheTrace(X) if(sqlite3PcacheTrace){sqlite3DebugPrintf X;}
43176
+ void pcacheDump(PCache *pCache){
43177
+ int N;
43178
+ int i, j;
43179
+ sqlite3_pcache_page *pLower;
43180
+ PgHdr *pPg;
43181
+ unsigned char *a;
43182
+
43183
+ if( sqlite3PcacheTrace<2 ) return;
43184
+ if( pCache->pCache==0 ) return;
43185
+ N = sqlite3PcachePagecount(pCache);
43186
+ if( N>sqlite3PcacheMxDump ) N = sqlite3PcacheMxDump;
43187
+ for(i=1; i<=N; i++){
43188
+ pLower = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, i, 0);
43189
+ if( pLower==0 ) continue;
43190
+ pPg = (PgHdr*)pLower->pExtra;
43191
+ printf("%3d: nRef %2d flgs %02x data ", i, pPg->nRef, pPg->flags);
43192
+ a = (unsigned char *)pLower->pBuf;
43193
+ for(j=0; j<12; j++) printf("%02x", a[j]);
43194
+ printf("\n");
43195
+ if( pPg->pPage==0 ){
43196
+ sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, pLower, 0);
43197
+ }
43198
+ }
43199
+ }
43200
+ #else
43201
+# define pcacheTrace(X)
43202
+# define pcacheDump(X)
43203
+#endif
43204
+
43205
+/*
43206
+** Check invariants on a PgHdr entry. Return true if everything is OK.
43207
+** Return false if any invariant is violated.
43208
+**
43209
+** This routine is for use inside of assert() statements only. For
43210
+** example:
43211
+**
43212
+** assert( sqlite3PcachePageSanity(pPg) );
43213
+*/
43214
+#if SQLITE_DEBUG
43215
+SQLITE_PRIVATE int sqlite3PcachePageSanity(PgHdr *pPg){
43216
+ PCache *pCache;
43217
+ assert( pPg!=0 );
43218
+ assert( pPg->pgno>0 ); /* Page number is 1 or more */
43219
+ pCache = pPg->pCache;
43220
+ assert( pCache!=0 ); /* Every page has an associated PCache */
43221
+ if( pPg->flags & PGHDR_CLEAN ){
43222
+ assert( (pPg->flags & PGHDR_DIRTY)==0 );/* Cannot be both CLEAN and DIRTY */
43223
+ assert( pCache->pDirty!=pPg ); /* CLEAN pages not on dirty list */
43224
+ assert( pCache->pDirtyTail!=pPg );
43225
+ }
43226
+ /* WRITEABLE pages must also be DIRTY */
43227
+ if( pPg->flags & PGHDR_WRITEABLE ){
43228
+ assert( pPg->flags & PGHDR_DIRTY ); /* WRITEABLE implies DIRTY */
43229
+ }
43230
+ /* NEED_SYNC can be set independently of WRITEABLE. This can happen,
43231
+ ** for example, when using the sqlite3PagerDontWrite() optimization:
43232
+ ** (1) Page X is journalled, and gets WRITEABLE and NEED_SEEK.
43233
+ ** (2) Page X moved to freelist, WRITEABLE is cleared
43234
+ ** (3) Page X reused, WRITEABLE is set again
43235
+ ** If NEED_SYNC had been cleared in step 2, then it would not be reset
43236
+ ** in step 3, and page might be written into the database without first
43237
+ ** syncing the rollback journal, which might cause corruption on a power
43238
+ ** loss.
43239
+ **
43240
+ ** Another example is when the database page size is smaller than the
43241
+ ** disk sector size. When any page of a sector is journalled, all pages
43242
+ ** in that sector are marked NEED_SYNC even if they are still CLEAN, just
43243
+ ** in case they are later modified, since all pages in the same sector
43244
+ ** must be journalled and synced before any of those pages can be safely
43245
+ ** written.
43246
+ */
43247
+ return 1;
43248
+}
43249
+#endif /* SQLITE_DEBUG */
43250
+
4313643251
4313743252
/********************************** Linked List Management ********************/
4313843253
4313943254
/* Allowed values for second argument to pcacheManageDirtyList() */
4314043255
#define PCACHE_DIRTYLIST_REMOVE 1 /* Remove pPage from dirty list */
@@ -43148,21 +43263,20 @@
4314843263
** the dirty list. Doing both moves pPage to the front of the dirty list.
4314943264
*/
4315043265
static void pcacheManageDirtyList(PgHdr *pPage, u8 addRemove){
4315143266
PCache *p = pPage->pCache;
4315243267
43268
+ pcacheTrace(("%p.DIRTYLIST.%s %d\n", p,
43269
+ addRemove==1 ? "REMOVE" : addRemove==2 ? "ADD" : "FRONT",
43270
+ pPage->pgno));
4315343271
if( addRemove & PCACHE_DIRTYLIST_REMOVE ){
4315443272
assert( pPage->pDirtyNext || pPage==p->pDirtyTail );
4315543273
assert( pPage->pDirtyPrev || pPage==p->pDirty );
4315643274
4315743275
/* Update the PCache1.pSynced variable if necessary. */
4315843276
if( p->pSynced==pPage ){
43159
- PgHdr *pSynced = pPage->pDirtyPrev;
43160
- while( pSynced && (pSynced->flags&PGHDR_NEED_SYNC) ){
43161
- pSynced = pSynced->pDirtyPrev;
43162
- }
43163
- p->pSynced = pSynced;
43277
+ p->pSynced = pPage->pDirtyPrev;
4316443278
}
4316543279
4316643280
if( pPage->pDirtyNext ){
4316743281
pPage->pDirtyNext->pDirtyPrev = pPage->pDirtyPrev;
4316843282
}else{
@@ -43170,14 +43284,19 @@
4317043284
p->pDirtyTail = pPage->pDirtyPrev;
4317143285
}
4317243286
if( pPage->pDirtyPrev ){
4317343287
pPage->pDirtyPrev->pDirtyNext = pPage->pDirtyNext;
4317443288
}else{
43289
+ /* If there are now no dirty pages in the cache, set eCreate to 2.
43290
+ ** This is an optimization that allows sqlite3PcacheFetch() to skip
43291
+ ** searching for a dirty page to eject from the cache when it might
43292
+ ** otherwise have to. */
4317543293
assert( pPage==p->pDirty );
4317643294
p->pDirty = pPage->pDirtyNext;
43177
- if( p->pDirty==0 && p->bPurgeable ){
43178
- assert( p->eCreate==1 );
43295
+ assert( p->bPurgeable || p->eCreate==2 );
43296
+ if( p->pDirty==0 ){ /*OPTIMIZATION-IF-TRUE*/
43297
+ assert( p->bPurgeable==0 || p->eCreate==1 );
4317943298
p->eCreate = 2;
4318043299
}
4318143300
}
4318243301
pPage->pDirtyNext = 0;
4318343302
pPage->pDirtyPrev = 0;
@@ -43195,23 +43314,34 @@
4319543314
assert( p->eCreate==2 );
4319643315
p->eCreate = 1;
4319743316
}
4319843317
}
4319943318
p->pDirty = pPage;
43200
- if( !p->pSynced && 0==(pPage->flags&PGHDR_NEED_SYNC) ){
43319
+
43320
+ /* If pSynced is NULL and this page has a clear NEED_SYNC flag, set
43321
+ ** pSynced to point to it. Checking the NEED_SYNC flag is an
43322
+ ** optimization, as if pSynced points to a page with the NEED_SYNC
43323
+ ** flag set sqlite3PcacheFetchStress() searches through all newer
43324
+ ** entries of the dirty-list for a page with NEED_SYNC clear anyway. */
43325
+ if( !p->pSynced
43326
+ && 0==(pPage->flags&PGHDR_NEED_SYNC) /*OPTIMIZATION-IF-FALSE*/
43327
+ ){
4320143328
p->pSynced = pPage;
4320243329
}
4320343330
}
43331
+ pcacheDump(p);
4320443332
}
4320543333
4320643334
/*
4320743335
** Wrapper around the pluggable caches xUnpin method. If the cache is
4320843336
** being used for an in-memory database, this function is a no-op.
4320943337
*/
4321043338
static void pcacheUnpin(PgHdr *p){
4321143339
if( p->pCache->bPurgeable ){
43340
+ pcacheTrace(("%p.UNPIN %d\n", p->pCache, p->pgno));
4321243341
sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 0);
43342
+ pcacheDump(p->pCache);
4321343343
}
4321443344
}
4321543345
4321643346
/*
4321743347
** Compute the number of pages of cache requested. p->szCache is the
@@ -43277,10 +43407,11 @@
4327743407
p->eCreate = 2;
4327843408
p->xStress = xStress;
4327943409
p->pStress = pStress;
4328043410
p->szCache = 100;
4328143411
p->szSpill = 1;
43412
+ pcacheTrace(("%p.OPEN szPage %d bPurgeable %d\n",p,szPage,bPurgeable));
4328243413
return sqlite3PcacheSetPageSize(p, szPage);
4328343414
}
4328443415
4328543416
/*
4328643417
** Change the page size for PCache object. The caller must ensure that there
@@ -43299,10 +43430,11 @@
4329943430
if( pCache->pCache ){
4330043431
sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
4330143432
}
4330243433
pCache->pCache = pNew;
4330343434
pCache->szPage = szPage;
43435
+ pcacheTrace(("%p.PAGESIZE %d\n",pCache,szPage));
4330443436
}
4330543437
return SQLITE_OK;
4330643438
}
4330743439
4330843440
/*
@@ -43333,15 +43465,17 @@
4333343465
PCache *pCache, /* Obtain the page from this cache */
4333443466
Pgno pgno, /* Page number to obtain */
4333543467
int createFlag /* If true, create page if it does not exist already */
4333643468
){
4333743469
int eCreate;
43470
+ sqlite3_pcache_page *pRes;
4333843471
4333943472
assert( pCache!=0 );
4334043473
assert( pCache->pCache!=0 );
4334143474
assert( createFlag==3 || createFlag==0 );
4334243475
assert( pgno>0 );
43476
+ assert( pCache->eCreate==((pCache->bPurgeable && pCache->pDirty) ? 1 : 2) );
4334343477
4334443478
/* eCreate defines what to do if the page does not exist.
4334543479
** 0 Do not allocate a new page. (createFlag==0)
4334643480
** 1 Allocate a new page if doing so is inexpensive.
4334743481
** (createFlag==1 AND bPurgeable AND pDirty)
@@ -43350,11 +43484,14 @@
4335043484
*/
4335143485
eCreate = createFlag & pCache->eCreate;
4335243486
assert( eCreate==0 || eCreate==1 || eCreate==2 );
4335343487
assert( createFlag==0 || pCache->eCreate==eCreate );
4335443488
assert( createFlag==0 || eCreate==1+(!pCache->bPurgeable||!pCache->pDirty) );
43355
- return sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
43489
+ pRes = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
43490
+ pcacheTrace(("%p.FETCH %d%s (result: %p)\n",pCache,pgno,
43491
+ createFlag?" create":"",pRes));
43492
+ return pRes;
4335643493
}
4335743494
4335843495
/*
4335943496
** If the sqlite3PcacheFetch() routine is unable to allocate a new
4336043497
** page because no clean pages are available for reuse and the cache
@@ -43377,11 +43514,15 @@
4337743514
if( sqlite3PcachePagecount(pCache)>pCache->szSpill ){
4337843515
/* Find a dirty page to write-out and recycle. First try to find a
4337943516
** page that does not require a journal-sync (one with PGHDR_NEED_SYNC
4338043517
** cleared), but if that is not possible settle for any other
4338143518
** unreferenced dirty page.
43382
- */
43519
+ **
43520
+ ** If the LRU page in the dirty list that has a clear PGHDR_NEED_SYNC
43521
+ ** flag is currently referenced, then the following may leave pSynced
43522
+ ** set incorrectly (pointing to other than the LRU page with NEED_SYNC
43523
+ ** cleared). This is Ok, as pSynced is just an optimization. */
4338343524
for(pPg=pCache->pSynced;
4338443525
pPg && (pPg->nRef || (pPg->flags&PGHDR_NEED_SYNC));
4338543526
pPg=pPg->pDirtyPrev
4338643527
);
4338743528
pCache->pSynced = pPg;
@@ -43395,11 +43536,13 @@
4339543536
"spill page %d making room for %d - cache used: %d/%d",
4339643537
pPg->pgno, pgno,
4339743538
sqlite3GlobalConfig.pcache.xPagecount(pCache->pCache),
4339843539
numberOfCachePages(pCache));
4339943540
#endif
43541
+ pcacheTrace(("%p.SPILL %d\n",pCache,pPg->pgno));
4340043542
rc = pCache->xStress(pCache->pStress, pPg);
43543
+ pcacheDump(pCache);
4340143544
if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){
4340243545
return rc;
4340343546
}
4340443547
}
4340543548
}
@@ -43455,10 +43598,11 @@
4345543598
if( !pPgHdr->pPage ){
4345643599
return pcacheFetchFinishWithInit(pCache, pgno, pPage);
4345743600
}
4345843601
pCache->nRefSum++;
4345943602
pPgHdr->nRef++;
43603
+ assert( sqlite3PcachePageSanity(pPgHdr) );
4346043604
return pPgHdr;
4346143605
}
4346243606
4346343607
/*
4346443608
** Decrement the reference count on a page. If the page is clean and the
@@ -43468,12 +43612,15 @@
4346843612
assert( p->nRef>0 );
4346943613
p->pCache->nRefSum--;
4347043614
if( (--p->nRef)==0 ){
4347143615
if( p->flags&PGHDR_CLEAN ){
4347243616
pcacheUnpin(p);
43473
- }else if( p->pDirtyPrev!=0 ){
43474
- /* Move the page to the head of the dirty list. */
43617
+ }else if( p->pDirtyPrev!=0 ){ /*OPTIMIZATION-IF-FALSE*/
43618
+ /* Move the page to the head of the dirty list. If p->pDirtyPrev==0,
43619
+ ** then page p is already at the head of the dirty list and the
43620
+ ** following call would be a no-op. Hence the OPTIMIZATION-IF-FALSE
43621
+ ** tag above. */
4347543622
pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT);
4347643623
}
4347743624
}
4347843625
}
4347943626
@@ -43480,10 +43627,11 @@
4348043627
/*
4348143628
** Increase the reference count of a supplied page by 1.
4348243629
*/
4348343630
SQLITE_PRIVATE void sqlite3PcacheRef(PgHdr *p){
4348443631
assert(p->nRef>0);
43632
+ assert( sqlite3PcachePageSanity(p) );
4348543633
p->nRef++;
4348643634
p->pCache->nRefSum++;
4348743635
}
4348843636
4348943637
/*
@@ -43491,10 +43639,11 @@
4349143639
** page. This function deletes that reference, so after it returns the
4349243640
** page pointed to by p is invalid.
4349343641
*/
4349443642
SQLITE_PRIVATE void sqlite3PcacheDrop(PgHdr *p){
4349543643
assert( p->nRef==1 );
43644
+ assert( sqlite3PcachePageSanity(p) );
4349643645
if( p->flags&PGHDR_DIRTY ){
4349743646
pcacheManageDirtyList(p, PCACHE_DIRTYLIST_REMOVE);
4349843647
}
4349943648
p->pCache->nRefSum--;
4350043649
sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 1);
@@ -43504,30 +43653,36 @@
4350443653
** Make sure the page is marked as dirty. If it isn't dirty already,
4350543654
** make it so.
4350643655
*/
4350743656
SQLITE_PRIVATE void sqlite3PcacheMakeDirty(PgHdr *p){
4350843657
assert( p->nRef>0 );
43509
- if( p->flags & (PGHDR_CLEAN|PGHDR_DONT_WRITE) ){
43658
+ assert( sqlite3PcachePageSanity(p) );
43659
+ if( p->flags & (PGHDR_CLEAN|PGHDR_DONT_WRITE) ){ /*OPTIMIZATION-IF-FALSE*/
4351043660
p->flags &= ~PGHDR_DONT_WRITE;
4351143661
if( p->flags & PGHDR_CLEAN ){
4351243662
p->flags ^= (PGHDR_DIRTY|PGHDR_CLEAN);
43663
+ pcacheTrace(("%p.DIRTY %d\n",p->pCache,p->pgno));
4351343664
assert( (p->flags & (PGHDR_DIRTY|PGHDR_CLEAN))==PGHDR_DIRTY );
4351443665
pcacheManageDirtyList(p, PCACHE_DIRTYLIST_ADD);
4351543666
}
43667
+ assert( sqlite3PcachePageSanity(p) );
4351643668
}
4351743669
}
4351843670
4351943671
/*
4352043672
** Make sure the page is marked as clean. If it isn't clean already,
4352143673
** make it so.
4352243674
*/
4352343675
SQLITE_PRIVATE void sqlite3PcacheMakeClean(PgHdr *p){
43524
- if( (p->flags & PGHDR_DIRTY) ){
43676
+ assert( sqlite3PcachePageSanity(p) );
43677
+ if( ALWAYS((p->flags & PGHDR_DIRTY)!=0) ){
4352543678
assert( (p->flags & PGHDR_CLEAN)==0 );
4352643679
pcacheManageDirtyList(p, PCACHE_DIRTYLIST_REMOVE);
4352743680
p->flags &= ~(PGHDR_DIRTY|PGHDR_NEED_SYNC|PGHDR_WRITEABLE);
4352843681
p->flags |= PGHDR_CLEAN;
43682
+ pcacheTrace(("%p.CLEAN %d\n",p->pCache,p->pgno));
43683
+ assert( sqlite3PcachePageSanity(p) );
4352943684
if( p->nRef==0 ){
4353043685
pcacheUnpin(p);
4353143686
}
4353243687
}
4353343688
}
@@ -43535,10 +43690,11 @@
4353543690
/*
4353643691
** Make every page in the cache clean.
4353743692
*/
4353843693
SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache *pCache){
4353943694
PgHdr *p;
43695
+ pcacheTrace(("%p.CLEAN-ALL\n",pCache));
4354043696
while( (p = pCache->pDirty)!=0 ){
4354143697
sqlite3PcacheMakeClean(p);
4354243698
}
4354343699
}
4354443700
@@ -43545,10 +43701,11 @@
4354543701
/*
4354643702
** Clear the PGHDR_NEED_SYNC and PGHDR_WRITEABLE flag from all dirty pages.
4354743703
*/
4354843704
SQLITE_PRIVATE void sqlite3PcacheClearWritable(PCache *pCache){
4354943705
PgHdr *p;
43706
+ pcacheTrace(("%p.CLEAR-WRITEABLE\n",pCache));
4355043707
for(p=pCache->pDirty; p; p=p->pDirtyNext){
4355143708
p->flags &= ~(PGHDR_NEED_SYNC|PGHDR_WRITEABLE);
4355243709
}
4355343710
pCache->pSynced = pCache->pDirtyTail;
4355443711
}
@@ -43569,10 +43726,12 @@
4356943726
*/
4357043727
SQLITE_PRIVATE void sqlite3PcacheMove(PgHdr *p, Pgno newPgno){
4357143728
PCache *pCache = p->pCache;
4357243729
assert( p->nRef>0 );
4357343730
assert( newPgno>0 );
43731
+ assert( sqlite3PcachePageSanity(p) );
43732
+ pcacheTrace(("%p.MOVE %d -> %d\n",pCache,p->pgno,newPgno));
4357443733
sqlite3GlobalConfig.pcache2.xRekey(pCache->pCache, p->pPage, p->pgno,newPgno);
4357543734
p->pgno = newPgno;
4357643735
if( (p->flags&PGHDR_DIRTY) && (p->flags&PGHDR_NEED_SYNC) ){
4357743736
pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT);
4357843737
}
@@ -43589,10 +43748,11 @@
4358943748
*/
4359043749
SQLITE_PRIVATE void sqlite3PcacheTruncate(PCache *pCache, Pgno pgno){
4359143750
if( pCache->pCache ){
4359243751
PgHdr *p;
4359343752
PgHdr *pNext;
43753
+ pcacheTrace(("%p.TRUNCATE %d\n",pCache,pgno));
4359443754
for(p=pCache->pDirty; p; p=pNext){
4359543755
pNext = p->pDirtyNext;
4359643756
/* This routine never gets call with a positive pgno except right
4359743757
** after sqlite3PcacheCleanAll(). So if there are dirty pages,
4359843758
** it must be that pgno==0.
@@ -43619,10 +43779,11 @@
4361943779
/*
4362043780
** Close a cache.
4362143781
*/
4362243782
SQLITE_PRIVATE void sqlite3PcacheClose(PCache *pCache){
4362343783
assert( pCache->pCache!=0 );
43784
+ pcacheTrace(("%p.CLOSE\n",pCache));
4362443785
sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
4362543786
}
4362643787
4362743788
/*
4362843789
** Discard the contents of the cache.
@@ -47585,24 +47746,28 @@
4758547746
}
4758647747
4758747748
static int pager_truncate(Pager *pPager, Pgno nPage);
4758847749
4758947750
/*
47590
-** The write transaction open on the pager passed as the only argument is
47591
-** being committed. This function returns true if all dirty pages should
47592
-** be flushed to disk, or false otherwise. Pages should be flushed to disk
47593
-** unless one of the following is true:
47594
-**
47595
-** * The db is an in-memory database.
47596
-**
47597
-** * The db is a temporary database and the db file has not been opened.
47598
-**
47599
-** * The db is a temporary database and the cache contains less than
47600
-** C/4 dirty pages, where C is the configured cache-size.
47601
-*/
47602
-static int pagerFlushOnCommit(Pager *pPager){
47751
+** The write transaction open on pPager is being committed (bCommit==1)
47752
+** or rolled back (bCommit==0).
47753
+**
47754
+** Return TRUE if and only if all dirty pages should be flushed to disk.
47755
+**
47756
+** Rules:
47757
+**
47758
+** * For non-TEMP databases, always sync to disk. This is necessary
47759
+** for transactions to be durable.
47760
+**
47761
+** * Sync TEMP database only on a COMMIT (not a ROLLBACK) when the backing
47762
+** file has been created already (via a spill on pagerStress()) and
47763
+** when the number of dirty pages in memory exceeds 25% of the total
47764
+** cache size.
47765
+*/
47766
+static int pagerFlushOnCommit(Pager *pPager, int bCommit){
4760347767
if( pPager->tempFile==0 ) return 1;
47768
+ if( !bCommit ) return 0;
4760447769
if( !isOpen(pPager->fd) ) return 0;
4760547770
return (sqlite3PCachePercentDirty(pPager->pPCache)>=25);
4760647771
}
4760747772
4760847773
/*
@@ -47706,11 +47871,11 @@
4770647871
}
4770747872
pPager->journalOff = 0;
4770847873
}else if( pPager->journalMode==PAGER_JOURNALMODE_PERSIST
4770947874
|| (pPager->exclusiveMode && pPager->journalMode!=PAGER_JOURNALMODE_WAL)
4771047875
){
47711
- rc = zeroJournalHdr(pPager, hasMaster);
47876
+ rc = zeroJournalHdr(pPager, hasMaster||pPager->tempFile);
4771247877
pPager->journalOff = 0;
4771347878
}else{
4771447879
/* This branch may be executed with Pager.journalMode==MEMORY if
4771547880
** a hot-journal was just rolled back. In this case the journal
4771647881
** file should be closed and deleted. If this connection writes to
@@ -47741,16 +47906,18 @@
4774147906
#endif
4774247907
4774347908
sqlite3BitvecDestroy(pPager->pInJournal);
4774447909
pPager->pInJournal = 0;
4774547910
pPager->nRec = 0;
47746
- if( MEMDB || pagerFlushOnCommit(pPager) ){
47747
- sqlite3PcacheCleanAll(pPager->pPCache);
47748
- }else{
47749
- sqlite3PcacheClearWritable(pPager->pPCache);
47911
+ if( rc==SQLITE_OK ){
47912
+ if( pagerFlushOnCommit(pPager, bCommit) ){
47913
+ sqlite3PcacheCleanAll(pPager->pPCache);
47914
+ }else{
47915
+ sqlite3PcacheClearWritable(pPager->pPCache);
47916
+ }
47917
+ sqlite3PcacheTruncate(pPager->pPCache, pPager->dbSize);
4775047918
}
47751
- sqlite3PcacheTruncate(pPager->pPCache, pPager->dbSize);
4775247919
4775347920
if( pagerUseWal(pPager) ){
4775447921
/* Drop the WAL write-lock, if any. Also, if the connection was in
4775547922
** locking_mode=exclusive mode but is no longer, drop the EXCLUSIVE
4775647923
** lock held on the database file.
@@ -48080,11 +48247,10 @@
4808048247
pPager->doNotSpill |= SPILLFLAG_ROLLBACK;
4808148248
rc = sqlite3PagerGet(pPager, pgno, &pPg, 1);
4808248249
assert( (pPager->doNotSpill & SPILLFLAG_ROLLBACK)!=0 );
4808348250
pPager->doNotSpill &= ~SPILLFLAG_ROLLBACK;
4808448251
if( rc!=SQLITE_OK ) return rc;
48085
- pPg->flags &= ~PGHDR_NEED_READ;
4808648252
sqlite3PcacheMakeDirty(pPg);
4808748253
}
4808848254
if( pPg ){
4808948255
/* No page should ever be explicitly rolled back that is in use, except
4809048256
** for page 1 which is held in use in order to keep the lock on the
@@ -48094,37 +48260,14 @@
4809448260
*/
4809548261
void *pData;
4809648262
pData = pPg->pData;
4809748263
memcpy(pData, (u8*)aData, pPager->pageSize);
4809848264
pPager->xReiniter(pPg);
48099
- if( isMainJrnl && (!isSavepnt || *pOffset<=pPager->journalHdr) ){
48100
- /* If the contents of this page were just restored from the main
48101
- ** journal file, then its content must be as they were when the
48102
- ** transaction was first opened. In this case we can mark the page
48103
- ** as clean, since there will be no need to write it out to the
48104
- ** database.
48105
- **
48106
- ** There is one exception to this rule. If the page is being rolled
48107
- ** back as part of a savepoint (or statement) rollback from an
48108
- ** unsynced portion of the main journal file, then it is not safe
48109
- ** to mark the page as clean. This is because marking the page as
48110
- ** clean will clear the PGHDR_NEED_SYNC flag. Since the page is
48111
- ** already in the journal file (recorded in Pager.pInJournal) and
48112
- ** the PGHDR_NEED_SYNC flag is cleared, if the page is written to
48113
- ** again within this transaction, it will be marked as dirty but
48114
- ** the PGHDR_NEED_SYNC flag will not be set. It could then potentially
48115
- ** be written out into the database file before its journal file
48116
- ** segment is synced. If a crash occurs during or following this,
48117
- ** database corruption may ensue.
48118
- **
48119
- ** Update: Another exception is for temp files that are not
48120
- ** in-memory databases. In this case the page may have been dirty
48121
- ** at the start of the transaction.
48122
- */
48123
- assert( !pagerUseWal(pPager) );
48124
- if( pPager->tempFile==0 ) sqlite3PcacheMakeClean(pPg);
48125
- }
48265
+ /* It used to be that sqlite3PcacheMakeClean(pPg) was called here. But
48266
+ ** that call was dangerous and had no detectable benefit since the cache
48267
+ ** is normally cleaned by sqlite3PcacheCleanAll() after rollback and so
48268
+ ** has been removed. */
4812648269
pager_set_pagehash(pPg);
4812748270
4812848271
/* If this was page 1, then restore the value of Pager.dbFileVers.
4812948272
** Do this before any decoding. */
4813048273
if( pgno==1 ){
@@ -51731,10 +51874,11 @@
5173151874
if( !pPager->tempFile && (pPg->flags&PGHDR_DIRTY) && pPager->nSavepoint==0 ){
5173251875
PAGERTRACE(("DONT_WRITE page %d of %d\n", pPg->pgno, PAGERID(pPager)));
5173351876
IOTRACE(("CLEAN %p %d\n", pPager, pPg->pgno))
5173451877
pPg->flags |= PGHDR_DONT_WRITE;
5173551878
pPg->flags &= ~PGHDR_WRITEABLE;
51879
+ testcase( pPg->flags & PGHDR_NEED_SYNC );
5173651880
pager_set_pagehash(pPg);
5173751881
}
5173851882
}
5173951883
5174051884
/*
@@ -51926,21 +52070,21 @@
5192652070
5192752071
/* If a prior error occurred, report that error again. */
5192852072
if( NEVER(pPager->errCode) ) return pPager->errCode;
5192952073
5193052074
/* Provide the ability to easily simulate an I/O error during testing */
51931
- if( (rc = sqlite3FaultSim(400))!=SQLITE_OK ) return rc;
52075
+ if( sqlite3FaultSim(400) ) return SQLITE_IOERR;
5193252076
5193352077
PAGERTRACE(("DATABASE SYNC: File=%s zMaster=%s nSize=%d\n",
5193452078
pPager->zFilename, zMaster, pPager->dbSize));
5193552079
5193652080
/* If no database changes have been made, return early. */
5193752081
if( pPager->eState<PAGER_WRITER_CACHEMOD ) return SQLITE_OK;
5193852082
5193952083
assert( MEMDB==0 || pPager->tempFile );
5194052084
assert( isOpen(pPager->fd) || pPager->tempFile );
51941
- if( 0==pagerFlushOnCommit(pPager) ){
52085
+ if( 0==pagerFlushOnCommit(pPager, 1) ){
5194252086
/* If this is an in-memory db, or no pages have been written to, or this
5194352087
** function has already been called, it is mostly a no-op. However, any
5194452088
** backup in progress needs to be restarted. */
5194552089
sqlite3BackupRestart(pPager->pBackup);
5194652090
}else{
@@ -52561,10 +52705,11 @@
5256152705
assert( assert_pager_state(pPager) );
5256252706
5256352707
/* In order to be able to rollback, an in-memory database must journal
5256452708
** the page we are moving from.
5256552709
*/
52710
+ assert( pPager->tempFile || !MEMDB );
5256652711
if( pPager->tempFile ){
5256752712
rc = sqlite3PagerWrite(pPg);
5256852713
if( rc ) return rc;
5256952714
}
5257052715
@@ -52635,12 +52780,11 @@
5263552780
5263652781
/* For an in-memory database, make sure the original page continues
5263752782
** to exist, in case the transaction needs to roll back. Use pPgOld
5263852783
** as the original page since it has already been allocated.
5263952784
*/
52640
- if( pPager->tempFile ){
52641
- assert( pPgOld );
52785
+ if( pPager->tempFile && pPgOld ){
5264252786
sqlite3PcacheMove(pPgOld, origPgno);
5264352787
sqlite3PagerUnrefNotNull(pPgOld);
5264452788
}
5264552789
5264652790
if( needSyncPgno ){
@@ -59256,15 +59400,15 @@
5925659400
flagByte &= ~PTF_LEAF;
5925759401
pPage->childPtrSize = 4-4*pPage->leaf;
5925859402
pPage->xCellSize = cellSizePtr;
5925959403
pBt = pPage->pBt;
5926059404
if( flagByte==(PTF_LEAFDATA | PTF_INTKEY) ){
59261
- /* EVIDENCE-OF: R-03640-13415 A value of 5 means the page is an interior
59262
- ** table b-tree page. */
59405
+ /* EVIDENCE-OF: R-07291-35328 A value of 5 (0x05) means the page is an
59406
+ ** interior table b-tree page. */
5926359407
assert( (PTF_LEAFDATA|PTF_INTKEY)==5 );
59264
- /* EVIDENCE-OF: R-20501-61796 A value of 13 means the page is a leaf
59265
- ** table b-tree page. */
59408
+ /* EVIDENCE-OF: R-26900-09176 A value of 13 (0x0d) means the page is a
59409
+ ** leaf table b-tree page. */
5926659410
assert( (PTF_LEAFDATA|PTF_INTKEY|PTF_LEAF)==13 );
5926759411
pPage->intKey = 1;
5926859412
if( pPage->leaf ){
5926959413
pPage->intKeyLeaf = 1;
5927059414
pPage->xParseCell = btreeParseCellPtr;
@@ -59274,15 +59418,15 @@
5927459418
pPage->xParseCell = btreeParseCellPtrNoPayload;
5927559419
}
5927659420
pPage->maxLocal = pBt->maxLeaf;
5927759421
pPage->minLocal = pBt->minLeaf;
5927859422
}else if( flagByte==PTF_ZERODATA ){
59279
- /* EVIDENCE-OF: R-27225-53936 A value of 2 means the page is an interior
59280
- ** index b-tree page. */
59423
+ /* EVIDENCE-OF: R-43316-37308 A value of 2 (0x02) means the page is an
59424
+ ** interior index b-tree page. */
5928159425
assert( (PTF_ZERODATA)==2 );
59282
- /* EVIDENCE-OF: R-16571-11615 A value of 10 means the page is a leaf
59283
- ** index b-tree page. */
59426
+ /* EVIDENCE-OF: R-59615-42828 A value of 10 (0x0a) means the page is a
59427
+ ** leaf index b-tree page. */
5928459428
assert( (PTF_ZERODATA|PTF_LEAF)==10 );
5928559429
pPage->intKey = 0;
5928659430
pPage->intKeyLeaf = 0;
5928759431
pPage->xParseCell = btreeParseCellPtrIndex;
5928859432
pPage->maxLocal = pBt->maxLocal;
@@ -192850,11 +192994,11 @@
192850192994
int nArg, /* Number of args */
192851192995
sqlite3_value **apUnused /* Function arguments */
192852192996
){
192853192997
assert( nArg==0 );
192854192998
UNUSED_PARAM2(nArg, apUnused);
192855
- sqlite3_result_text(pCtx, "fts5: 2016-05-09 19:03:42 14e53d0e2f62d82ae1d64a72fd9711548e3bf5ea", -1, SQLITE_TRANSIENT);
192999
+ sqlite3_result_text(pCtx, "fts5: 2016-05-05 23:59:22 d2efd3c176f0eba2d78105f0bb3161db38bd4bab", -1, SQLITE_TRANSIENT);
192856193000
}
192857193001
192858193002
static int fts5Init(sqlite3 *db){
192859193003
static const sqlite3_module fts5Mod = {
192860193004
/* iVersion */ 2,
192861193005
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -363,11 +363,11 @@
363 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
364 ** [sqlite_version()] and [sqlite_source_id()].
365 */
366 #define SQLITE_VERSION "3.13.0"
367 #define SQLITE_VERSION_NUMBER 3013000
368 #define SQLITE_SOURCE_ID "2016-05-09 19:03:42 14e53d0e2f62d82ae1d64a72fd9711548e3bf5ea"
369
370 /*
371 ** CAPI3REF: Run-Time Library Version Numbers
372 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
373 **
@@ -10917,11 +10917,11 @@
10917 **
10918 ** When doing coverage testing ALWAYS and NEVER are hard-coded to
10919 ** be true and false so that the unreachable code they specify will
10920 ** not be counted as untested code.
10921 */
10922 #if defined(SQLITE_COVERAGE_TEST)
10923 # define ALWAYS(X) (1)
10924 # define NEVER(X) (0)
10925 #elif !defined(NDEBUG)
10926 # define ALWAYS(X) ((X)?1:(assert(0),0))
10927 # define NEVER(X) ((X)?(assert(0),1):0)
@@ -12954,11 +12954,11 @@
12954 */
12955 struct PgHdr {
12956 sqlite3_pcache_page *pPage; /* Pcache object page handle */
12957 void *pData; /* Page data */
12958 void *pExtra; /* Extra content */
12959 PgHdr *pDirty; /* Transient list of dirty pages */
12960 Pager *pPager; /* The pager this page is part of */
12961 Pgno pgno; /* Page number for this page */
12962 #ifdef SQLITE_CHECK_PAGES
12963 u32 pageHash; /* Hash of page content */
12964 #endif
@@ -12979,15 +12979,14 @@
12979 #define PGHDR_CLEAN 0x001 /* Page not on the PCache.pDirty list */
12980 #define PGHDR_DIRTY 0x002 /* Page is on the PCache.pDirty list */
12981 #define PGHDR_WRITEABLE 0x004 /* Journaled and ready to modify */
12982 #define PGHDR_NEED_SYNC 0x008 /* Fsync the rollback journal before
12983 ** writing this page to the database */
12984 #define PGHDR_NEED_READ 0x010 /* Content is unread */
12985 #define PGHDR_DONT_WRITE 0x020 /* Do not write content to disk */
12986 #define PGHDR_MMAP 0x040 /* This is an mmap page object */
12987
12988 #define PGHDR_WAL_APPEND 0x080 /* Appended to wal file */
12989
12990 /* Initialize and shutdown the page cache subsystem */
12991 SQLITE_PRIVATE int sqlite3PcacheInitialize(void);
12992 SQLITE_PRIVATE void sqlite3PcacheShutdown(void);
12993
@@ -13065,10 +13064,15 @@
13065 ** interface is only available if SQLITE_CHECK_PAGES is defined when the
13066 ** library is built.
13067 */
13068 SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *));
13069 #endif
 
 
 
 
 
13070
13071 /* Set and get the suggested cache-size for the specified pager-cache.
13072 **
13073 ** If no global maximum is configured, then the system attempts to limit
13074 ** the total number of pages cached by purgeable pager-caches to the sum
@@ -43115,11 +43119,33 @@
43115 ** This file implements that page cache.
43116 */
43117 /* #include "sqliteInt.h" */
43118
43119 /*
43120 ** A complete page cache is an instance of this structure.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43121 */
43122 struct PCache {
43123 PgHdr *pDirty, *pDirtyTail; /* List of dirty pages in LRU order */
43124 PgHdr *pSynced; /* Last synced page in dirty page list */
43125 int nRefSum; /* Sum of ref counts over all pages */
@@ -43131,10 +43157,99 @@
43131 u8 eCreate; /* eCreate value for for xFetch() */
43132 int (*xStress)(void*,PgHdr*); /* Call to try make a page clean */
43133 void *pStress; /* Argument to xStress */
43134 sqlite3_pcache *pCache; /* Pluggable cache module */
43135 };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43136
43137 /********************************** Linked List Management ********************/
43138
43139 /* Allowed values for second argument to pcacheManageDirtyList() */
43140 #define PCACHE_DIRTYLIST_REMOVE 1 /* Remove pPage from dirty list */
@@ -43148,21 +43263,20 @@
43148 ** the dirty list. Doing both moves pPage to the front of the dirty list.
43149 */
43150 static void pcacheManageDirtyList(PgHdr *pPage, u8 addRemove){
43151 PCache *p = pPage->pCache;
43152
 
 
 
43153 if( addRemove & PCACHE_DIRTYLIST_REMOVE ){
43154 assert( pPage->pDirtyNext || pPage==p->pDirtyTail );
43155 assert( pPage->pDirtyPrev || pPage==p->pDirty );
43156
43157 /* Update the PCache1.pSynced variable if necessary. */
43158 if( p->pSynced==pPage ){
43159 PgHdr *pSynced = pPage->pDirtyPrev;
43160 while( pSynced && (pSynced->flags&PGHDR_NEED_SYNC) ){
43161 pSynced = pSynced->pDirtyPrev;
43162 }
43163 p->pSynced = pSynced;
43164 }
43165
43166 if( pPage->pDirtyNext ){
43167 pPage->pDirtyNext->pDirtyPrev = pPage->pDirtyPrev;
43168 }else{
@@ -43170,14 +43284,19 @@
43170 p->pDirtyTail = pPage->pDirtyPrev;
43171 }
43172 if( pPage->pDirtyPrev ){
43173 pPage->pDirtyPrev->pDirtyNext = pPage->pDirtyNext;
43174 }else{
 
 
 
 
43175 assert( pPage==p->pDirty );
43176 p->pDirty = pPage->pDirtyNext;
43177 if( p->pDirty==0 && p->bPurgeable ){
43178 assert( p->eCreate==1 );
 
43179 p->eCreate = 2;
43180 }
43181 }
43182 pPage->pDirtyNext = 0;
43183 pPage->pDirtyPrev = 0;
@@ -43195,23 +43314,34 @@
43195 assert( p->eCreate==2 );
43196 p->eCreate = 1;
43197 }
43198 }
43199 p->pDirty = pPage;
43200 if( !p->pSynced && 0==(pPage->flags&PGHDR_NEED_SYNC) ){
 
 
 
 
 
 
 
 
43201 p->pSynced = pPage;
43202 }
43203 }
 
43204 }
43205
43206 /*
43207 ** Wrapper around the pluggable caches xUnpin method. If the cache is
43208 ** being used for an in-memory database, this function is a no-op.
43209 */
43210 static void pcacheUnpin(PgHdr *p){
43211 if( p->pCache->bPurgeable ){
 
43212 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 0);
 
43213 }
43214 }
43215
43216 /*
43217 ** Compute the number of pages of cache requested. p->szCache is the
@@ -43277,10 +43407,11 @@
43277 p->eCreate = 2;
43278 p->xStress = xStress;
43279 p->pStress = pStress;
43280 p->szCache = 100;
43281 p->szSpill = 1;
 
43282 return sqlite3PcacheSetPageSize(p, szPage);
43283 }
43284
43285 /*
43286 ** Change the page size for PCache object. The caller must ensure that there
@@ -43299,10 +43430,11 @@
43299 if( pCache->pCache ){
43300 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
43301 }
43302 pCache->pCache = pNew;
43303 pCache->szPage = szPage;
 
43304 }
43305 return SQLITE_OK;
43306 }
43307
43308 /*
@@ -43333,15 +43465,17 @@
43333 PCache *pCache, /* Obtain the page from this cache */
43334 Pgno pgno, /* Page number to obtain */
43335 int createFlag /* If true, create page if it does not exist already */
43336 ){
43337 int eCreate;
 
43338
43339 assert( pCache!=0 );
43340 assert( pCache->pCache!=0 );
43341 assert( createFlag==3 || createFlag==0 );
43342 assert( pgno>0 );
 
43343
43344 /* eCreate defines what to do if the page does not exist.
43345 ** 0 Do not allocate a new page. (createFlag==0)
43346 ** 1 Allocate a new page if doing so is inexpensive.
43347 ** (createFlag==1 AND bPurgeable AND pDirty)
@@ -43350,11 +43484,14 @@
43350 */
43351 eCreate = createFlag & pCache->eCreate;
43352 assert( eCreate==0 || eCreate==1 || eCreate==2 );
43353 assert( createFlag==0 || pCache->eCreate==eCreate );
43354 assert( createFlag==0 || eCreate==1+(!pCache->bPurgeable||!pCache->pDirty) );
43355 return sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
 
 
 
43356 }
43357
43358 /*
43359 ** If the sqlite3PcacheFetch() routine is unable to allocate a new
43360 ** page because no clean pages are available for reuse and the cache
@@ -43377,11 +43514,15 @@
43377 if( sqlite3PcachePagecount(pCache)>pCache->szSpill ){
43378 /* Find a dirty page to write-out and recycle. First try to find a
43379 ** page that does not require a journal-sync (one with PGHDR_NEED_SYNC
43380 ** cleared), but if that is not possible settle for any other
43381 ** unreferenced dirty page.
43382 */
 
 
 
 
43383 for(pPg=pCache->pSynced;
43384 pPg && (pPg->nRef || (pPg->flags&PGHDR_NEED_SYNC));
43385 pPg=pPg->pDirtyPrev
43386 );
43387 pCache->pSynced = pPg;
@@ -43395,11 +43536,13 @@
43395 "spill page %d making room for %d - cache used: %d/%d",
43396 pPg->pgno, pgno,
43397 sqlite3GlobalConfig.pcache.xPagecount(pCache->pCache),
43398 numberOfCachePages(pCache));
43399 #endif
 
43400 rc = pCache->xStress(pCache->pStress, pPg);
 
43401 if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){
43402 return rc;
43403 }
43404 }
43405 }
@@ -43455,10 +43598,11 @@
43455 if( !pPgHdr->pPage ){
43456 return pcacheFetchFinishWithInit(pCache, pgno, pPage);
43457 }
43458 pCache->nRefSum++;
43459 pPgHdr->nRef++;
 
43460 return pPgHdr;
43461 }
43462
43463 /*
43464 ** Decrement the reference count on a page. If the page is clean and the
@@ -43468,12 +43612,15 @@
43468 assert( p->nRef>0 );
43469 p->pCache->nRefSum--;
43470 if( (--p->nRef)==0 ){
43471 if( p->flags&PGHDR_CLEAN ){
43472 pcacheUnpin(p);
43473 }else if( p->pDirtyPrev!=0 ){
43474 /* Move the page to the head of the dirty list. */
 
 
 
43475 pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT);
43476 }
43477 }
43478 }
43479
@@ -43480,10 +43627,11 @@
43480 /*
43481 ** Increase the reference count of a supplied page by 1.
43482 */
43483 SQLITE_PRIVATE void sqlite3PcacheRef(PgHdr *p){
43484 assert(p->nRef>0);
 
43485 p->nRef++;
43486 p->pCache->nRefSum++;
43487 }
43488
43489 /*
@@ -43491,10 +43639,11 @@
43491 ** page. This function deletes that reference, so after it returns the
43492 ** page pointed to by p is invalid.
43493 */
43494 SQLITE_PRIVATE void sqlite3PcacheDrop(PgHdr *p){
43495 assert( p->nRef==1 );
 
43496 if( p->flags&PGHDR_DIRTY ){
43497 pcacheManageDirtyList(p, PCACHE_DIRTYLIST_REMOVE);
43498 }
43499 p->pCache->nRefSum--;
43500 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 1);
@@ -43504,30 +43653,36 @@
43504 ** Make sure the page is marked as dirty. If it isn't dirty already,
43505 ** make it so.
43506 */
43507 SQLITE_PRIVATE void sqlite3PcacheMakeDirty(PgHdr *p){
43508 assert( p->nRef>0 );
43509 if( p->flags & (PGHDR_CLEAN|PGHDR_DONT_WRITE) ){
 
43510 p->flags &= ~PGHDR_DONT_WRITE;
43511 if( p->flags & PGHDR_CLEAN ){
43512 p->flags ^= (PGHDR_DIRTY|PGHDR_CLEAN);
 
43513 assert( (p->flags & (PGHDR_DIRTY|PGHDR_CLEAN))==PGHDR_DIRTY );
43514 pcacheManageDirtyList(p, PCACHE_DIRTYLIST_ADD);
43515 }
 
43516 }
43517 }
43518
43519 /*
43520 ** Make sure the page is marked as clean. If it isn't clean already,
43521 ** make it so.
43522 */
43523 SQLITE_PRIVATE void sqlite3PcacheMakeClean(PgHdr *p){
43524 if( (p->flags & PGHDR_DIRTY) ){
 
43525 assert( (p->flags & PGHDR_CLEAN)==0 );
43526 pcacheManageDirtyList(p, PCACHE_DIRTYLIST_REMOVE);
43527 p->flags &= ~(PGHDR_DIRTY|PGHDR_NEED_SYNC|PGHDR_WRITEABLE);
43528 p->flags |= PGHDR_CLEAN;
 
 
43529 if( p->nRef==0 ){
43530 pcacheUnpin(p);
43531 }
43532 }
43533 }
@@ -43535,10 +43690,11 @@
43535 /*
43536 ** Make every page in the cache clean.
43537 */
43538 SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache *pCache){
43539 PgHdr *p;
 
43540 while( (p = pCache->pDirty)!=0 ){
43541 sqlite3PcacheMakeClean(p);
43542 }
43543 }
43544
@@ -43545,10 +43701,11 @@
43545 /*
43546 ** Clear the PGHDR_NEED_SYNC and PGHDR_WRITEABLE flag from all dirty pages.
43547 */
43548 SQLITE_PRIVATE void sqlite3PcacheClearWritable(PCache *pCache){
43549 PgHdr *p;
 
43550 for(p=pCache->pDirty; p; p=p->pDirtyNext){
43551 p->flags &= ~(PGHDR_NEED_SYNC|PGHDR_WRITEABLE);
43552 }
43553 pCache->pSynced = pCache->pDirtyTail;
43554 }
@@ -43569,10 +43726,12 @@
43569 */
43570 SQLITE_PRIVATE void sqlite3PcacheMove(PgHdr *p, Pgno newPgno){
43571 PCache *pCache = p->pCache;
43572 assert( p->nRef>0 );
43573 assert( newPgno>0 );
 
 
43574 sqlite3GlobalConfig.pcache2.xRekey(pCache->pCache, p->pPage, p->pgno,newPgno);
43575 p->pgno = newPgno;
43576 if( (p->flags&PGHDR_DIRTY) && (p->flags&PGHDR_NEED_SYNC) ){
43577 pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT);
43578 }
@@ -43589,10 +43748,11 @@
43589 */
43590 SQLITE_PRIVATE void sqlite3PcacheTruncate(PCache *pCache, Pgno pgno){
43591 if( pCache->pCache ){
43592 PgHdr *p;
43593 PgHdr *pNext;
 
43594 for(p=pCache->pDirty; p; p=pNext){
43595 pNext = p->pDirtyNext;
43596 /* This routine never gets call with a positive pgno except right
43597 ** after sqlite3PcacheCleanAll(). So if there are dirty pages,
43598 ** it must be that pgno==0.
@@ -43619,10 +43779,11 @@
43619 /*
43620 ** Close a cache.
43621 */
43622 SQLITE_PRIVATE void sqlite3PcacheClose(PCache *pCache){
43623 assert( pCache->pCache!=0 );
 
43624 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
43625 }
43626
43627 /*
43628 ** Discard the contents of the cache.
@@ -47585,24 +47746,28 @@
47585 }
47586
47587 static int pager_truncate(Pager *pPager, Pgno nPage);
47588
47589 /*
47590 ** The write transaction open on the pager passed as the only argument is
47591 ** being committed. This function returns true if all dirty pages should
47592 ** be flushed to disk, or false otherwise. Pages should be flushed to disk
47593 ** unless one of the following is true:
47594 **
47595 ** * The db is an in-memory database.
47596 **
47597 ** * The db is a temporary database and the db file has not been opened.
47598 **
47599 ** * The db is a temporary database and the cache contains less than
47600 ** C/4 dirty pages, where C is the configured cache-size.
47601 */
47602 static int pagerFlushOnCommit(Pager *pPager){
 
 
 
47603 if( pPager->tempFile==0 ) return 1;
 
47604 if( !isOpen(pPager->fd) ) return 0;
47605 return (sqlite3PCachePercentDirty(pPager->pPCache)>=25);
47606 }
47607
47608 /*
@@ -47706,11 +47871,11 @@
47706 }
47707 pPager->journalOff = 0;
47708 }else if( pPager->journalMode==PAGER_JOURNALMODE_PERSIST
47709 || (pPager->exclusiveMode && pPager->journalMode!=PAGER_JOURNALMODE_WAL)
47710 ){
47711 rc = zeroJournalHdr(pPager, hasMaster);
47712 pPager->journalOff = 0;
47713 }else{
47714 /* This branch may be executed with Pager.journalMode==MEMORY if
47715 ** a hot-journal was just rolled back. In this case the journal
47716 ** file should be closed and deleted. If this connection writes to
@@ -47741,16 +47906,18 @@
47741 #endif
47742
47743 sqlite3BitvecDestroy(pPager->pInJournal);
47744 pPager->pInJournal = 0;
47745 pPager->nRec = 0;
47746 if( MEMDB || pagerFlushOnCommit(pPager) ){
47747 sqlite3PcacheCleanAll(pPager->pPCache);
47748 }else{
47749 sqlite3PcacheClearWritable(pPager->pPCache);
 
 
 
47750 }
47751 sqlite3PcacheTruncate(pPager->pPCache, pPager->dbSize);
47752
47753 if( pagerUseWal(pPager) ){
47754 /* Drop the WAL write-lock, if any. Also, if the connection was in
47755 ** locking_mode=exclusive mode but is no longer, drop the EXCLUSIVE
47756 ** lock held on the database file.
@@ -48080,11 +48247,10 @@
48080 pPager->doNotSpill |= SPILLFLAG_ROLLBACK;
48081 rc = sqlite3PagerGet(pPager, pgno, &pPg, 1);
48082 assert( (pPager->doNotSpill & SPILLFLAG_ROLLBACK)!=0 );
48083 pPager->doNotSpill &= ~SPILLFLAG_ROLLBACK;
48084 if( rc!=SQLITE_OK ) return rc;
48085 pPg->flags &= ~PGHDR_NEED_READ;
48086 sqlite3PcacheMakeDirty(pPg);
48087 }
48088 if( pPg ){
48089 /* No page should ever be explicitly rolled back that is in use, except
48090 ** for page 1 which is held in use in order to keep the lock on the
@@ -48094,37 +48260,14 @@
48094 */
48095 void *pData;
48096 pData = pPg->pData;
48097 memcpy(pData, (u8*)aData, pPager->pageSize);
48098 pPager->xReiniter(pPg);
48099 if( isMainJrnl && (!isSavepnt || *pOffset<=pPager->journalHdr) ){
48100 /* If the contents of this page were just restored from the main
48101 ** journal file, then its content must be as they were when the
48102 ** transaction was first opened. In this case we can mark the page
48103 ** as clean, since there will be no need to write it out to the
48104 ** database.
48105 **
48106 ** There is one exception to this rule. If the page is being rolled
48107 ** back as part of a savepoint (or statement) rollback from an
48108 ** unsynced portion of the main journal file, then it is not safe
48109 ** to mark the page as clean. This is because marking the page as
48110 ** clean will clear the PGHDR_NEED_SYNC flag. Since the page is
48111 ** already in the journal file (recorded in Pager.pInJournal) and
48112 ** the PGHDR_NEED_SYNC flag is cleared, if the page is written to
48113 ** again within this transaction, it will be marked as dirty but
48114 ** the PGHDR_NEED_SYNC flag will not be set. It could then potentially
48115 ** be written out into the database file before its journal file
48116 ** segment is synced. If a crash occurs during or following this,
48117 ** database corruption may ensue.
48118 **
48119 ** Update: Another exception is for temp files that are not
48120 ** in-memory databases. In this case the page may have been dirty
48121 ** at the start of the transaction.
48122 */
48123 assert( !pagerUseWal(pPager) );
48124 if( pPager->tempFile==0 ) sqlite3PcacheMakeClean(pPg);
48125 }
48126 pager_set_pagehash(pPg);
48127
48128 /* If this was page 1, then restore the value of Pager.dbFileVers.
48129 ** Do this before any decoding. */
48130 if( pgno==1 ){
@@ -51731,10 +51874,11 @@
51731 if( !pPager->tempFile && (pPg->flags&PGHDR_DIRTY) && pPager->nSavepoint==0 ){
51732 PAGERTRACE(("DONT_WRITE page %d of %d\n", pPg->pgno, PAGERID(pPager)));
51733 IOTRACE(("CLEAN %p %d\n", pPager, pPg->pgno))
51734 pPg->flags |= PGHDR_DONT_WRITE;
51735 pPg->flags &= ~PGHDR_WRITEABLE;
 
51736 pager_set_pagehash(pPg);
51737 }
51738 }
51739
51740 /*
@@ -51926,21 +52070,21 @@
51926
51927 /* If a prior error occurred, report that error again. */
51928 if( NEVER(pPager->errCode) ) return pPager->errCode;
51929
51930 /* Provide the ability to easily simulate an I/O error during testing */
51931 if( (rc = sqlite3FaultSim(400))!=SQLITE_OK ) return rc;
51932
51933 PAGERTRACE(("DATABASE SYNC: File=%s zMaster=%s nSize=%d\n",
51934 pPager->zFilename, zMaster, pPager->dbSize));
51935
51936 /* If no database changes have been made, return early. */
51937 if( pPager->eState<PAGER_WRITER_CACHEMOD ) return SQLITE_OK;
51938
51939 assert( MEMDB==0 || pPager->tempFile );
51940 assert( isOpen(pPager->fd) || pPager->tempFile );
51941 if( 0==pagerFlushOnCommit(pPager) ){
51942 /* If this is an in-memory db, or no pages have been written to, or this
51943 ** function has already been called, it is mostly a no-op. However, any
51944 ** backup in progress needs to be restarted. */
51945 sqlite3BackupRestart(pPager->pBackup);
51946 }else{
@@ -52561,10 +52705,11 @@
52561 assert( assert_pager_state(pPager) );
52562
52563 /* In order to be able to rollback, an in-memory database must journal
52564 ** the page we are moving from.
52565 */
 
52566 if( pPager->tempFile ){
52567 rc = sqlite3PagerWrite(pPg);
52568 if( rc ) return rc;
52569 }
52570
@@ -52635,12 +52780,11 @@
52635
52636 /* For an in-memory database, make sure the original page continues
52637 ** to exist, in case the transaction needs to roll back. Use pPgOld
52638 ** as the original page since it has already been allocated.
52639 */
52640 if( pPager->tempFile ){
52641 assert( pPgOld );
52642 sqlite3PcacheMove(pPgOld, origPgno);
52643 sqlite3PagerUnrefNotNull(pPgOld);
52644 }
52645
52646 if( needSyncPgno ){
@@ -59256,15 +59400,15 @@
59256 flagByte &= ~PTF_LEAF;
59257 pPage->childPtrSize = 4-4*pPage->leaf;
59258 pPage->xCellSize = cellSizePtr;
59259 pBt = pPage->pBt;
59260 if( flagByte==(PTF_LEAFDATA | PTF_INTKEY) ){
59261 /* EVIDENCE-OF: R-03640-13415 A value of 5 means the page is an interior
59262 ** table b-tree page. */
59263 assert( (PTF_LEAFDATA|PTF_INTKEY)==5 );
59264 /* EVIDENCE-OF: R-20501-61796 A value of 13 means the page is a leaf
59265 ** table b-tree page. */
59266 assert( (PTF_LEAFDATA|PTF_INTKEY|PTF_LEAF)==13 );
59267 pPage->intKey = 1;
59268 if( pPage->leaf ){
59269 pPage->intKeyLeaf = 1;
59270 pPage->xParseCell = btreeParseCellPtr;
@@ -59274,15 +59418,15 @@
59274 pPage->xParseCell = btreeParseCellPtrNoPayload;
59275 }
59276 pPage->maxLocal = pBt->maxLeaf;
59277 pPage->minLocal = pBt->minLeaf;
59278 }else if( flagByte==PTF_ZERODATA ){
59279 /* EVIDENCE-OF: R-27225-53936 A value of 2 means the page is an interior
59280 ** index b-tree page. */
59281 assert( (PTF_ZERODATA)==2 );
59282 /* EVIDENCE-OF: R-16571-11615 A value of 10 means the page is a leaf
59283 ** index b-tree page. */
59284 assert( (PTF_ZERODATA|PTF_LEAF)==10 );
59285 pPage->intKey = 0;
59286 pPage->intKeyLeaf = 0;
59287 pPage->xParseCell = btreeParseCellPtrIndex;
59288 pPage->maxLocal = pBt->maxLocal;
@@ -192850,11 +192994,11 @@
192850 int nArg, /* Number of args */
192851 sqlite3_value **apUnused /* Function arguments */
192852 ){
192853 assert( nArg==0 );
192854 UNUSED_PARAM2(nArg, apUnused);
192855 sqlite3_result_text(pCtx, "fts5: 2016-05-09 19:03:42 14e53d0e2f62d82ae1d64a72fd9711548e3bf5ea", -1, SQLITE_TRANSIENT);
192856 }
192857
192858 static int fts5Init(sqlite3 *db){
192859 static const sqlite3_module fts5Mod = {
192860 /* iVersion */ 2,
192861
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -363,11 +363,11 @@
363 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
364 ** [sqlite_version()] and [sqlite_source_id()].
365 */
366 #define SQLITE_VERSION "3.13.0"
367 #define SQLITE_VERSION_NUMBER 3013000
368 #define SQLITE_SOURCE_ID "2016-05-18 10:57:30 fc49f556e48970561d7ab6a2f24fdd7d9eb81ff2"
369
370 /*
371 ** CAPI3REF: Run-Time Library Version Numbers
372 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
373 **
@@ -10917,11 +10917,11 @@
10917 **
10918 ** When doing coverage testing ALWAYS and NEVER are hard-coded to
10919 ** be true and false so that the unreachable code they specify will
10920 ** not be counted as untested code.
10921 */
10922 #if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_MUTATION_TEST)
10923 # define ALWAYS(X) (1)
10924 # define NEVER(X) (0)
10925 #elif !defined(NDEBUG)
10926 # define ALWAYS(X) ((X)?1:(assert(0),0))
10927 # define NEVER(X) ((X)?(assert(0),1):0)
@@ -12954,11 +12954,11 @@
12954 */
12955 struct PgHdr {
12956 sqlite3_pcache_page *pPage; /* Pcache object page handle */
12957 void *pData; /* Page data */
12958 void *pExtra; /* Extra content */
12959 PgHdr *pDirty; /* Transient list of dirty sorted by pgno */
12960 Pager *pPager; /* The pager this page is part of */
12961 Pgno pgno; /* Page number for this page */
12962 #ifdef SQLITE_CHECK_PAGES
12963 u32 pageHash; /* Hash of page content */
12964 #endif
@@ -12979,15 +12979,14 @@
12979 #define PGHDR_CLEAN 0x001 /* Page not on the PCache.pDirty list */
12980 #define PGHDR_DIRTY 0x002 /* Page is on the PCache.pDirty list */
12981 #define PGHDR_WRITEABLE 0x004 /* Journaled and ready to modify */
12982 #define PGHDR_NEED_SYNC 0x008 /* Fsync the rollback journal before
12983 ** writing this page to the database */
12984 #define PGHDR_DONT_WRITE 0x010 /* Do not write content to disk */
12985 #define PGHDR_MMAP 0x020 /* This is an mmap page object */
 
12986
12987 #define PGHDR_WAL_APPEND 0x040 /* Appended to wal file */
12988
12989 /* Initialize and shutdown the page cache subsystem */
12990 SQLITE_PRIVATE int sqlite3PcacheInitialize(void);
12991 SQLITE_PRIVATE void sqlite3PcacheShutdown(void);
12992
@@ -13065,10 +13064,15 @@
13064 ** interface is only available if SQLITE_CHECK_PAGES is defined when the
13065 ** library is built.
13066 */
13067 SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *));
13068 #endif
13069
13070 #if defined(SQLITE_DEBUG)
13071 /* Check invariants on a PgHdr object */
13072 SQLITE_PRIVATE int sqlite3PcachePageSanity(PgHdr*);
13073 #endif
13074
13075 /* Set and get the suggested cache-size for the specified pager-cache.
13076 **
13077 ** If no global maximum is configured, then the system attempts to limit
13078 ** the total number of pages cached by purgeable pager-caches to the sum
@@ -43115,11 +43119,33 @@
43119 ** This file implements that page cache.
43120 */
43121 /* #include "sqliteInt.h" */
43122
43123 /*
43124 ** A complete page cache is an instance of this structure. Every
43125 ** entry in the cache holds a single page of the database file. The
43126 ** btree layer only operates on the cached copy of the database pages.
43127 **
43128 ** A page cache entry is "clean" if it exactly matches what is currently
43129 ** on disk. A page is "dirty" if it has been modified and needs to be
43130 ** persisted to disk.
43131 **
43132 ** pDirty, pDirtyTail, pSynced:
43133 ** All dirty pages are linked into the doubly linked list using
43134 ** PgHdr.pDirtyNext and pDirtyPrev. The list is maintained in LRU order
43135 ** such that p was added to the list more recently than p->pDirtyNext.
43136 ** PCache.pDirty points to the first (newest) element in the list and
43137 ** pDirtyTail to the last (oldest).
43138 **
43139 ** The PCache.pSynced variable is used to optimize searching for a dirty
43140 ** page to eject from the cache mid-transaction. It is better to eject
43141 ** a page that does not require a journal sync than one that does.
43142 ** Therefore, pSynced is maintained to that it *almost* always points
43143 ** to either the oldest page in the pDirty/pDirtyTail list that has a
43144 ** clear PGHDR_NEED_SYNC flag or to a page that is older than this one
43145 ** (so that the right page to eject can be found by following pDirtyPrev
43146 ** pointers).
43147 */
43148 struct PCache {
43149 PgHdr *pDirty, *pDirtyTail; /* List of dirty pages in LRU order */
43150 PgHdr *pSynced; /* Last synced page in dirty page list */
43151 int nRefSum; /* Sum of ref counts over all pages */
@@ -43131,10 +43157,99 @@
43157 u8 eCreate; /* eCreate value for for xFetch() */
43158 int (*xStress)(void*,PgHdr*); /* Call to try make a page clean */
43159 void *pStress; /* Argument to xStress */
43160 sqlite3_pcache *pCache; /* Pluggable cache module */
43161 };
43162
43163 /********************************** Test and Debug Logic **********************/
43164 /*
43165 ** Debug tracing macros. Enable by by changing the "0" to "1" and
43166 ** recompiling.
43167 **
43168 ** When sqlite3PcacheTrace is 1, single line trace messages are issued.
43169 ** When sqlite3PcacheTrace is 2, a dump of the pcache showing all cache entries
43170 ** is displayed for many operations, resulting in a lot of output.
43171 */
43172 #if defined(SQLITE_DEBUG) && 0
43173 int sqlite3PcacheTrace = 2; /* 0: off 1: simple 2: cache dumps */
43174 int sqlite3PcacheMxDump = 9999; /* Max cache entries for pcacheDump() */
43175 # define pcacheTrace(X) if(sqlite3PcacheTrace){sqlite3DebugPrintf X;}
43176 void pcacheDump(PCache *pCache){
43177 int N;
43178 int i, j;
43179 sqlite3_pcache_page *pLower;
43180 PgHdr *pPg;
43181 unsigned char *a;
43182
43183 if( sqlite3PcacheTrace<2 ) return;
43184 if( pCache->pCache==0 ) return;
43185 N = sqlite3PcachePagecount(pCache);
43186 if( N>sqlite3PcacheMxDump ) N = sqlite3PcacheMxDump;
43187 for(i=1; i<=N; i++){
43188 pLower = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, i, 0);
43189 if( pLower==0 ) continue;
43190 pPg = (PgHdr*)pLower->pExtra;
43191 printf("%3d: nRef %2d flgs %02x data ", i, pPg->nRef, pPg->flags);
43192 a = (unsigned char *)pLower->pBuf;
43193 for(j=0; j<12; j++) printf("%02x", a[j]);
43194 printf("\n");
43195 if( pPg->pPage==0 ){
43196 sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, pLower, 0);
43197 }
43198 }
43199 }
43200 #else
43201 # define pcacheTrace(X)
43202 # define pcacheDump(X)
43203 #endif
43204
43205 /*
43206 ** Check invariants on a PgHdr entry. Return true if everything is OK.
43207 ** Return false if any invariant is violated.
43208 **
43209 ** This routine is for use inside of assert() statements only. For
43210 ** example:
43211 **
43212 ** assert( sqlite3PcachePageSanity(pPg) );
43213 */
43214 #if SQLITE_DEBUG
43215 SQLITE_PRIVATE int sqlite3PcachePageSanity(PgHdr *pPg){
43216 PCache *pCache;
43217 assert( pPg!=0 );
43218 assert( pPg->pgno>0 ); /* Page number is 1 or more */
43219 pCache = pPg->pCache;
43220 assert( pCache!=0 ); /* Every page has an associated PCache */
43221 if( pPg->flags & PGHDR_CLEAN ){
43222 assert( (pPg->flags & PGHDR_DIRTY)==0 );/* Cannot be both CLEAN and DIRTY */
43223 assert( pCache->pDirty!=pPg ); /* CLEAN pages not on dirty list */
43224 assert( pCache->pDirtyTail!=pPg );
43225 }
43226 /* WRITEABLE pages must also be DIRTY */
43227 if( pPg->flags & PGHDR_WRITEABLE ){
43228 assert( pPg->flags & PGHDR_DIRTY ); /* WRITEABLE implies DIRTY */
43229 }
43230 /* NEED_SYNC can be set independently of WRITEABLE. This can happen,
43231 ** for example, when using the sqlite3PagerDontWrite() optimization:
43232 ** (1) Page X is journalled, and gets WRITEABLE and NEED_SEEK.
43233 ** (2) Page X moved to freelist, WRITEABLE is cleared
43234 ** (3) Page X reused, WRITEABLE is set again
43235 ** If NEED_SYNC had been cleared in step 2, then it would not be reset
43236 ** in step 3, and page might be written into the database without first
43237 ** syncing the rollback journal, which might cause corruption on a power
43238 ** loss.
43239 **
43240 ** Another example is when the database page size is smaller than the
43241 ** disk sector size. When any page of a sector is journalled, all pages
43242 ** in that sector are marked NEED_SYNC even if they are still CLEAN, just
43243 ** in case they are later modified, since all pages in the same sector
43244 ** must be journalled and synced before any of those pages can be safely
43245 ** written.
43246 */
43247 return 1;
43248 }
43249 #endif /* SQLITE_DEBUG */
43250
43251
43252 /********************************** Linked List Management ********************/
43253
43254 /* Allowed values for second argument to pcacheManageDirtyList() */
43255 #define PCACHE_DIRTYLIST_REMOVE 1 /* Remove pPage from dirty list */
@@ -43148,21 +43263,20 @@
43263 ** the dirty list. Doing both moves pPage to the front of the dirty list.
43264 */
43265 static void pcacheManageDirtyList(PgHdr *pPage, u8 addRemove){
43266 PCache *p = pPage->pCache;
43267
43268 pcacheTrace(("%p.DIRTYLIST.%s %d\n", p,
43269 addRemove==1 ? "REMOVE" : addRemove==2 ? "ADD" : "FRONT",
43270 pPage->pgno));
43271 if( addRemove & PCACHE_DIRTYLIST_REMOVE ){
43272 assert( pPage->pDirtyNext || pPage==p->pDirtyTail );
43273 assert( pPage->pDirtyPrev || pPage==p->pDirty );
43274
43275 /* Update the PCache1.pSynced variable if necessary. */
43276 if( p->pSynced==pPage ){
43277 p->pSynced = pPage->pDirtyPrev;
 
 
 
 
43278 }
43279
43280 if( pPage->pDirtyNext ){
43281 pPage->pDirtyNext->pDirtyPrev = pPage->pDirtyPrev;
43282 }else{
@@ -43170,14 +43284,19 @@
43284 p->pDirtyTail = pPage->pDirtyPrev;
43285 }
43286 if( pPage->pDirtyPrev ){
43287 pPage->pDirtyPrev->pDirtyNext = pPage->pDirtyNext;
43288 }else{
43289 /* If there are now no dirty pages in the cache, set eCreate to 2.
43290 ** This is an optimization that allows sqlite3PcacheFetch() to skip
43291 ** searching for a dirty page to eject from the cache when it might
43292 ** otherwise have to. */
43293 assert( pPage==p->pDirty );
43294 p->pDirty = pPage->pDirtyNext;
43295 assert( p->bPurgeable || p->eCreate==2 );
43296 if( p->pDirty==0 ){ /*OPTIMIZATION-IF-TRUE*/
43297 assert( p->bPurgeable==0 || p->eCreate==1 );
43298 p->eCreate = 2;
43299 }
43300 }
43301 pPage->pDirtyNext = 0;
43302 pPage->pDirtyPrev = 0;
@@ -43195,23 +43314,34 @@
43314 assert( p->eCreate==2 );
43315 p->eCreate = 1;
43316 }
43317 }
43318 p->pDirty = pPage;
43319
43320 /* If pSynced is NULL and this page has a clear NEED_SYNC flag, set
43321 ** pSynced to point to it. Checking the NEED_SYNC flag is an
43322 ** optimization, as if pSynced points to a page with the NEED_SYNC
43323 ** flag set sqlite3PcacheFetchStress() searches through all newer
43324 ** entries of the dirty-list for a page with NEED_SYNC clear anyway. */
43325 if( !p->pSynced
43326 && 0==(pPage->flags&PGHDR_NEED_SYNC) /*OPTIMIZATION-IF-FALSE*/
43327 ){
43328 p->pSynced = pPage;
43329 }
43330 }
43331 pcacheDump(p);
43332 }
43333
43334 /*
43335 ** Wrapper around the pluggable caches xUnpin method. If the cache is
43336 ** being used for an in-memory database, this function is a no-op.
43337 */
43338 static void pcacheUnpin(PgHdr *p){
43339 if( p->pCache->bPurgeable ){
43340 pcacheTrace(("%p.UNPIN %d\n", p->pCache, p->pgno));
43341 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 0);
43342 pcacheDump(p->pCache);
43343 }
43344 }
43345
43346 /*
43347 ** Compute the number of pages of cache requested. p->szCache is the
@@ -43277,10 +43407,11 @@
43407 p->eCreate = 2;
43408 p->xStress = xStress;
43409 p->pStress = pStress;
43410 p->szCache = 100;
43411 p->szSpill = 1;
43412 pcacheTrace(("%p.OPEN szPage %d bPurgeable %d\n",p,szPage,bPurgeable));
43413 return sqlite3PcacheSetPageSize(p, szPage);
43414 }
43415
43416 /*
43417 ** Change the page size for PCache object. The caller must ensure that there
@@ -43299,10 +43430,11 @@
43430 if( pCache->pCache ){
43431 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
43432 }
43433 pCache->pCache = pNew;
43434 pCache->szPage = szPage;
43435 pcacheTrace(("%p.PAGESIZE %d\n",pCache,szPage));
43436 }
43437 return SQLITE_OK;
43438 }
43439
43440 /*
@@ -43333,15 +43465,17 @@
43465 PCache *pCache, /* Obtain the page from this cache */
43466 Pgno pgno, /* Page number to obtain */
43467 int createFlag /* If true, create page if it does not exist already */
43468 ){
43469 int eCreate;
43470 sqlite3_pcache_page *pRes;
43471
43472 assert( pCache!=0 );
43473 assert( pCache->pCache!=0 );
43474 assert( createFlag==3 || createFlag==0 );
43475 assert( pgno>0 );
43476 assert( pCache->eCreate==((pCache->bPurgeable && pCache->pDirty) ? 1 : 2) );
43477
43478 /* eCreate defines what to do if the page does not exist.
43479 ** 0 Do not allocate a new page. (createFlag==0)
43480 ** 1 Allocate a new page if doing so is inexpensive.
43481 ** (createFlag==1 AND bPurgeable AND pDirty)
@@ -43350,11 +43484,14 @@
43484 */
43485 eCreate = createFlag & pCache->eCreate;
43486 assert( eCreate==0 || eCreate==1 || eCreate==2 );
43487 assert( createFlag==0 || pCache->eCreate==eCreate );
43488 assert( createFlag==0 || eCreate==1+(!pCache->bPurgeable||!pCache->pDirty) );
43489 pRes = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
43490 pcacheTrace(("%p.FETCH %d%s (result: %p)\n",pCache,pgno,
43491 createFlag?" create":"",pRes));
43492 return pRes;
43493 }
43494
43495 /*
43496 ** If the sqlite3PcacheFetch() routine is unable to allocate a new
43497 ** page because no clean pages are available for reuse and the cache
@@ -43377,11 +43514,15 @@
43514 if( sqlite3PcachePagecount(pCache)>pCache->szSpill ){
43515 /* Find a dirty page to write-out and recycle. First try to find a
43516 ** page that does not require a journal-sync (one with PGHDR_NEED_SYNC
43517 ** cleared), but if that is not possible settle for any other
43518 ** unreferenced dirty page.
43519 **
43520 ** If the LRU page in the dirty list that has a clear PGHDR_NEED_SYNC
43521 ** flag is currently referenced, then the following may leave pSynced
43522 ** set incorrectly (pointing to other than the LRU page with NEED_SYNC
43523 ** cleared). This is Ok, as pSynced is just an optimization. */
43524 for(pPg=pCache->pSynced;
43525 pPg && (pPg->nRef || (pPg->flags&PGHDR_NEED_SYNC));
43526 pPg=pPg->pDirtyPrev
43527 );
43528 pCache->pSynced = pPg;
@@ -43395,11 +43536,13 @@
43536 "spill page %d making room for %d - cache used: %d/%d",
43537 pPg->pgno, pgno,
43538 sqlite3GlobalConfig.pcache.xPagecount(pCache->pCache),
43539 numberOfCachePages(pCache));
43540 #endif
43541 pcacheTrace(("%p.SPILL %d\n",pCache,pPg->pgno));
43542 rc = pCache->xStress(pCache->pStress, pPg);
43543 pcacheDump(pCache);
43544 if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){
43545 return rc;
43546 }
43547 }
43548 }
@@ -43455,10 +43598,11 @@
43598 if( !pPgHdr->pPage ){
43599 return pcacheFetchFinishWithInit(pCache, pgno, pPage);
43600 }
43601 pCache->nRefSum++;
43602 pPgHdr->nRef++;
43603 assert( sqlite3PcachePageSanity(pPgHdr) );
43604 return pPgHdr;
43605 }
43606
43607 /*
43608 ** Decrement the reference count on a page. If the page is clean and the
@@ -43468,12 +43612,15 @@
43612 assert( p->nRef>0 );
43613 p->pCache->nRefSum--;
43614 if( (--p->nRef)==0 ){
43615 if( p->flags&PGHDR_CLEAN ){
43616 pcacheUnpin(p);
43617 }else if( p->pDirtyPrev!=0 ){ /*OPTIMIZATION-IF-FALSE*/
43618 /* Move the page to the head of the dirty list. If p->pDirtyPrev==0,
43619 ** then page p is already at the head of the dirty list and the
43620 ** following call would be a no-op. Hence the OPTIMIZATION-IF-FALSE
43621 ** tag above. */
43622 pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT);
43623 }
43624 }
43625 }
43626
@@ -43480,10 +43627,11 @@
43627 /*
43628 ** Increase the reference count of a supplied page by 1.
43629 */
43630 SQLITE_PRIVATE void sqlite3PcacheRef(PgHdr *p){
43631 assert(p->nRef>0);
43632 assert( sqlite3PcachePageSanity(p) );
43633 p->nRef++;
43634 p->pCache->nRefSum++;
43635 }
43636
43637 /*
@@ -43491,10 +43639,11 @@
43639 ** page. This function deletes that reference, so after it returns the
43640 ** page pointed to by p is invalid.
43641 */
43642 SQLITE_PRIVATE void sqlite3PcacheDrop(PgHdr *p){
43643 assert( p->nRef==1 );
43644 assert( sqlite3PcachePageSanity(p) );
43645 if( p->flags&PGHDR_DIRTY ){
43646 pcacheManageDirtyList(p, PCACHE_DIRTYLIST_REMOVE);
43647 }
43648 p->pCache->nRefSum--;
43649 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 1);
@@ -43504,30 +43653,36 @@
43653 ** Make sure the page is marked as dirty. If it isn't dirty already,
43654 ** make it so.
43655 */
43656 SQLITE_PRIVATE void sqlite3PcacheMakeDirty(PgHdr *p){
43657 assert( p->nRef>0 );
43658 assert( sqlite3PcachePageSanity(p) );
43659 if( p->flags & (PGHDR_CLEAN|PGHDR_DONT_WRITE) ){ /*OPTIMIZATION-IF-FALSE*/
43660 p->flags &= ~PGHDR_DONT_WRITE;
43661 if( p->flags & PGHDR_CLEAN ){
43662 p->flags ^= (PGHDR_DIRTY|PGHDR_CLEAN);
43663 pcacheTrace(("%p.DIRTY %d\n",p->pCache,p->pgno));
43664 assert( (p->flags & (PGHDR_DIRTY|PGHDR_CLEAN))==PGHDR_DIRTY );
43665 pcacheManageDirtyList(p, PCACHE_DIRTYLIST_ADD);
43666 }
43667 assert( sqlite3PcachePageSanity(p) );
43668 }
43669 }
43670
43671 /*
43672 ** Make sure the page is marked as clean. If it isn't clean already,
43673 ** make it so.
43674 */
43675 SQLITE_PRIVATE void sqlite3PcacheMakeClean(PgHdr *p){
43676 assert( sqlite3PcachePageSanity(p) );
43677 if( ALWAYS((p->flags & PGHDR_DIRTY)!=0) ){
43678 assert( (p->flags & PGHDR_CLEAN)==0 );
43679 pcacheManageDirtyList(p, PCACHE_DIRTYLIST_REMOVE);
43680 p->flags &= ~(PGHDR_DIRTY|PGHDR_NEED_SYNC|PGHDR_WRITEABLE);
43681 p->flags |= PGHDR_CLEAN;
43682 pcacheTrace(("%p.CLEAN %d\n",p->pCache,p->pgno));
43683 assert( sqlite3PcachePageSanity(p) );
43684 if( p->nRef==0 ){
43685 pcacheUnpin(p);
43686 }
43687 }
43688 }
@@ -43535,10 +43690,11 @@
43690 /*
43691 ** Make every page in the cache clean.
43692 */
43693 SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache *pCache){
43694 PgHdr *p;
43695 pcacheTrace(("%p.CLEAN-ALL\n",pCache));
43696 while( (p = pCache->pDirty)!=0 ){
43697 sqlite3PcacheMakeClean(p);
43698 }
43699 }
43700
@@ -43545,10 +43701,11 @@
43701 /*
43702 ** Clear the PGHDR_NEED_SYNC and PGHDR_WRITEABLE flag from all dirty pages.
43703 */
43704 SQLITE_PRIVATE void sqlite3PcacheClearWritable(PCache *pCache){
43705 PgHdr *p;
43706 pcacheTrace(("%p.CLEAR-WRITEABLE\n",pCache));
43707 for(p=pCache->pDirty; p; p=p->pDirtyNext){
43708 p->flags &= ~(PGHDR_NEED_SYNC|PGHDR_WRITEABLE);
43709 }
43710 pCache->pSynced = pCache->pDirtyTail;
43711 }
@@ -43569,10 +43726,12 @@
43726 */
43727 SQLITE_PRIVATE void sqlite3PcacheMove(PgHdr *p, Pgno newPgno){
43728 PCache *pCache = p->pCache;
43729 assert( p->nRef>0 );
43730 assert( newPgno>0 );
43731 assert( sqlite3PcachePageSanity(p) );
43732 pcacheTrace(("%p.MOVE %d -> %d\n",pCache,p->pgno,newPgno));
43733 sqlite3GlobalConfig.pcache2.xRekey(pCache->pCache, p->pPage, p->pgno,newPgno);
43734 p->pgno = newPgno;
43735 if( (p->flags&PGHDR_DIRTY) && (p->flags&PGHDR_NEED_SYNC) ){
43736 pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT);
43737 }
@@ -43589,10 +43748,11 @@
43748 */
43749 SQLITE_PRIVATE void sqlite3PcacheTruncate(PCache *pCache, Pgno pgno){
43750 if( pCache->pCache ){
43751 PgHdr *p;
43752 PgHdr *pNext;
43753 pcacheTrace(("%p.TRUNCATE %d\n",pCache,pgno));
43754 for(p=pCache->pDirty; p; p=pNext){
43755 pNext = p->pDirtyNext;
43756 /* This routine never gets call with a positive pgno except right
43757 ** after sqlite3PcacheCleanAll(). So if there are dirty pages,
43758 ** it must be that pgno==0.
@@ -43619,10 +43779,11 @@
43779 /*
43780 ** Close a cache.
43781 */
43782 SQLITE_PRIVATE void sqlite3PcacheClose(PCache *pCache){
43783 assert( pCache->pCache!=0 );
43784 pcacheTrace(("%p.CLOSE\n",pCache));
43785 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
43786 }
43787
43788 /*
43789 ** Discard the contents of the cache.
@@ -47585,24 +47746,28 @@
47746 }
47747
47748 static int pager_truncate(Pager *pPager, Pgno nPage);
47749
47750 /*
47751 ** The write transaction open on pPager is being committed (bCommit==1)
47752 ** or rolled back (bCommit==0).
47753 **
47754 ** Return TRUE if and only if all dirty pages should be flushed to disk.
47755 **
47756 ** Rules:
47757 **
47758 ** * For non-TEMP databases, always sync to disk. This is necessary
47759 ** for transactions to be durable.
47760 **
47761 ** * Sync TEMP database only on a COMMIT (not a ROLLBACK) when the backing
47762 ** file has been created already (via a spill on pagerStress()) and
47763 ** when the number of dirty pages in memory exceeds 25% of the total
47764 ** cache size.
47765 */
47766 static int pagerFlushOnCommit(Pager *pPager, int bCommit){
47767 if( pPager->tempFile==0 ) return 1;
47768 if( !bCommit ) return 0;
47769 if( !isOpen(pPager->fd) ) return 0;
47770 return (sqlite3PCachePercentDirty(pPager->pPCache)>=25);
47771 }
47772
47773 /*
@@ -47706,11 +47871,11 @@
47871 }
47872 pPager->journalOff = 0;
47873 }else if( pPager->journalMode==PAGER_JOURNALMODE_PERSIST
47874 || (pPager->exclusiveMode && pPager->journalMode!=PAGER_JOURNALMODE_WAL)
47875 ){
47876 rc = zeroJournalHdr(pPager, hasMaster||pPager->tempFile);
47877 pPager->journalOff = 0;
47878 }else{
47879 /* This branch may be executed with Pager.journalMode==MEMORY if
47880 ** a hot-journal was just rolled back. In this case the journal
47881 ** file should be closed and deleted. If this connection writes to
@@ -47741,16 +47906,18 @@
47906 #endif
47907
47908 sqlite3BitvecDestroy(pPager->pInJournal);
47909 pPager->pInJournal = 0;
47910 pPager->nRec = 0;
47911 if( rc==SQLITE_OK ){
47912 if( pagerFlushOnCommit(pPager, bCommit) ){
47913 sqlite3PcacheCleanAll(pPager->pPCache);
47914 }else{
47915 sqlite3PcacheClearWritable(pPager->pPCache);
47916 }
47917 sqlite3PcacheTruncate(pPager->pPCache, pPager->dbSize);
47918 }
 
47919
47920 if( pagerUseWal(pPager) ){
47921 /* Drop the WAL write-lock, if any. Also, if the connection was in
47922 ** locking_mode=exclusive mode but is no longer, drop the EXCLUSIVE
47923 ** lock held on the database file.
@@ -48080,11 +48247,10 @@
48247 pPager->doNotSpill |= SPILLFLAG_ROLLBACK;
48248 rc = sqlite3PagerGet(pPager, pgno, &pPg, 1);
48249 assert( (pPager->doNotSpill & SPILLFLAG_ROLLBACK)!=0 );
48250 pPager->doNotSpill &= ~SPILLFLAG_ROLLBACK;
48251 if( rc!=SQLITE_OK ) return rc;
 
48252 sqlite3PcacheMakeDirty(pPg);
48253 }
48254 if( pPg ){
48255 /* No page should ever be explicitly rolled back that is in use, except
48256 ** for page 1 which is held in use in order to keep the lock on the
@@ -48094,37 +48260,14 @@
48260 */
48261 void *pData;
48262 pData = pPg->pData;
48263 memcpy(pData, (u8*)aData, pPager->pageSize);
48264 pPager->xReiniter(pPg);
48265 /* It used to be that sqlite3PcacheMakeClean(pPg) was called here. But
48266 ** that call was dangerous and had no detectable benefit since the cache
48267 ** is normally cleaned by sqlite3PcacheCleanAll() after rollback and so
48268 ** has been removed. */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48269 pager_set_pagehash(pPg);
48270
48271 /* If this was page 1, then restore the value of Pager.dbFileVers.
48272 ** Do this before any decoding. */
48273 if( pgno==1 ){
@@ -51731,10 +51874,11 @@
51874 if( !pPager->tempFile && (pPg->flags&PGHDR_DIRTY) && pPager->nSavepoint==0 ){
51875 PAGERTRACE(("DONT_WRITE page %d of %d\n", pPg->pgno, PAGERID(pPager)));
51876 IOTRACE(("CLEAN %p %d\n", pPager, pPg->pgno))
51877 pPg->flags |= PGHDR_DONT_WRITE;
51878 pPg->flags &= ~PGHDR_WRITEABLE;
51879 testcase( pPg->flags & PGHDR_NEED_SYNC );
51880 pager_set_pagehash(pPg);
51881 }
51882 }
51883
51884 /*
@@ -51926,21 +52070,21 @@
52070
52071 /* If a prior error occurred, report that error again. */
52072 if( NEVER(pPager->errCode) ) return pPager->errCode;
52073
52074 /* Provide the ability to easily simulate an I/O error during testing */
52075 if( sqlite3FaultSim(400) ) return SQLITE_IOERR;
52076
52077 PAGERTRACE(("DATABASE SYNC: File=%s zMaster=%s nSize=%d\n",
52078 pPager->zFilename, zMaster, pPager->dbSize));
52079
52080 /* If no database changes have been made, return early. */
52081 if( pPager->eState<PAGER_WRITER_CACHEMOD ) return SQLITE_OK;
52082
52083 assert( MEMDB==0 || pPager->tempFile );
52084 assert( isOpen(pPager->fd) || pPager->tempFile );
52085 if( 0==pagerFlushOnCommit(pPager, 1) ){
52086 /* If this is an in-memory db, or no pages have been written to, or this
52087 ** function has already been called, it is mostly a no-op. However, any
52088 ** backup in progress needs to be restarted. */
52089 sqlite3BackupRestart(pPager->pBackup);
52090 }else{
@@ -52561,10 +52705,11 @@
52705 assert( assert_pager_state(pPager) );
52706
52707 /* In order to be able to rollback, an in-memory database must journal
52708 ** the page we are moving from.
52709 */
52710 assert( pPager->tempFile || !MEMDB );
52711 if( pPager->tempFile ){
52712 rc = sqlite3PagerWrite(pPg);
52713 if( rc ) return rc;
52714 }
52715
@@ -52635,12 +52780,11 @@
52780
52781 /* For an in-memory database, make sure the original page continues
52782 ** to exist, in case the transaction needs to roll back. Use pPgOld
52783 ** as the original page since it has already been allocated.
52784 */
52785 if( pPager->tempFile && pPgOld ){
 
52786 sqlite3PcacheMove(pPgOld, origPgno);
52787 sqlite3PagerUnrefNotNull(pPgOld);
52788 }
52789
52790 if( needSyncPgno ){
@@ -59256,15 +59400,15 @@
59400 flagByte &= ~PTF_LEAF;
59401 pPage->childPtrSize = 4-4*pPage->leaf;
59402 pPage->xCellSize = cellSizePtr;
59403 pBt = pPage->pBt;
59404 if( flagByte==(PTF_LEAFDATA | PTF_INTKEY) ){
59405 /* EVIDENCE-OF: R-07291-35328 A value of 5 (0x05) means the page is an
59406 ** interior table b-tree page. */
59407 assert( (PTF_LEAFDATA|PTF_INTKEY)==5 );
59408 /* EVIDENCE-OF: R-26900-09176 A value of 13 (0x0d) means the page is a
59409 ** leaf table b-tree page. */
59410 assert( (PTF_LEAFDATA|PTF_INTKEY|PTF_LEAF)==13 );
59411 pPage->intKey = 1;
59412 if( pPage->leaf ){
59413 pPage->intKeyLeaf = 1;
59414 pPage->xParseCell = btreeParseCellPtr;
@@ -59274,15 +59418,15 @@
59418 pPage->xParseCell = btreeParseCellPtrNoPayload;
59419 }
59420 pPage->maxLocal = pBt->maxLeaf;
59421 pPage->minLocal = pBt->minLeaf;
59422 }else if( flagByte==PTF_ZERODATA ){
59423 /* EVIDENCE-OF: R-43316-37308 A value of 2 (0x02) means the page is an
59424 ** interior index b-tree page. */
59425 assert( (PTF_ZERODATA)==2 );
59426 /* EVIDENCE-OF: R-59615-42828 A value of 10 (0x0a) means the page is a
59427 ** leaf index b-tree page. */
59428 assert( (PTF_ZERODATA|PTF_LEAF)==10 );
59429 pPage->intKey = 0;
59430 pPage->intKeyLeaf = 0;
59431 pPage->xParseCell = btreeParseCellPtrIndex;
59432 pPage->maxLocal = pBt->maxLocal;
@@ -192850,11 +192994,11 @@
192994 int nArg, /* Number of args */
192995 sqlite3_value **apUnused /* Function arguments */
192996 ){
192997 assert( nArg==0 );
192998 UNUSED_PARAM2(nArg, apUnused);
192999 sqlite3_result_text(pCtx, "fts5: 2016-05-05 23:59:22 d2efd3c176f0eba2d78105f0bb3161db38bd4bab", -1, SQLITE_TRANSIENT);
193000 }
193001
193002 static int fts5Init(sqlite3 *db){
193003 static const sqlite3_module fts5Mod = {
193004 /* iVersion */ 2,
193005
+1 -1
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -111,11 +111,11 @@
111111
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112112
** [sqlite_version()] and [sqlite_source_id()].
113113
*/
114114
#define SQLITE_VERSION "3.13.0"
115115
#define SQLITE_VERSION_NUMBER 3013000
116
-#define SQLITE_SOURCE_ID "2016-05-09 19:03:42 14e53d0e2f62d82ae1d64a72fd9711548e3bf5ea"
116
+#define SQLITE_SOURCE_ID "2016-05-18 10:57:30 fc49f556e48970561d7ab6a2f24fdd7d9eb81ff2"
117117
118118
/*
119119
** CAPI3REF: Run-Time Library Version Numbers
120120
** KEYWORDS: sqlite3_version, sqlite3_sourceid
121121
**
122122
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -111,11 +111,11 @@
111 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112 ** [sqlite_version()] and [sqlite_source_id()].
113 */
114 #define SQLITE_VERSION "3.13.0"
115 #define SQLITE_VERSION_NUMBER 3013000
116 #define SQLITE_SOURCE_ID "2016-05-09 19:03:42 14e53d0e2f62d82ae1d64a72fd9711548e3bf5ea"
117
118 /*
119 ** CAPI3REF: Run-Time Library Version Numbers
120 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
121 **
122
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -111,11 +111,11 @@
111 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112 ** [sqlite_version()] and [sqlite_source_id()].
113 */
114 #define SQLITE_VERSION "3.13.0"
115 #define SQLITE_VERSION_NUMBER 3013000
116 #define SQLITE_SOURCE_ID "2016-05-18 10:57:30 fc49f556e48970561d7ab6a2f24fdd7d9eb81ff2"
117
118 /*
119 ** CAPI3REF: Run-Time Library Version Numbers
120 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
121 **
122

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button