aboutsummaryrefslogtreecommitdiff
path: root/src/wal.c
diff options
context:
space:
mode:
authordan <dan@noemail.net>2010-08-11 06:04:19 +0000
committerdan <dan@noemail.net>2010-08-11 06:04:19 +0000
commit216eaab2822b1ac5a91bd6ebaf985e9d8455f35b (patch)
tree767e1276efbce92ddf5185719f38d5140aa21275 /src/wal.c
parent84612fec1c94840c7175a4aa03ffac5505960467 (diff)
parent7e68423894fae26d25ef4e1d6b8513469020db07 (diff)
downloadsqlite-216eaab2822b1ac5a91bd6ebaf985e9d8455f35b.tar.gz
sqlite-216eaab2822b1ac5a91bd6ebaf985e9d8455f35b.zip
Merge experimental changes into trunk.
FossilOrigin-Name: aa092ac928dc19bd356d25a1dfd3f432dc145ce6
Diffstat (limited to 'src/wal.c')
-rw-r--r--src/wal.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/wal.c b/src/wal.c
index 54274640e..5924a6375 100644
--- a/src/wal.c
+++ b/src/wal.c
@@ -1521,6 +1521,7 @@ static int walCheckpoint(
u32 iDbpage = 0; /* Next database page to write */
u32 iFrame = 0; /* Wal frame containing data for iDbpage */
u32 mxSafeFrame; /* Max frame that can be backfilled */
+ u32 mxPage; /* Max database page to write */
int i; /* Loop counter */
volatile WalCkptInfo *pInfo; /* The checkpoint status information */
@@ -1545,6 +1546,7 @@ static int walCheckpoint(
** cannot be backfilled from the WAL.
*/
mxSafeFrame = pWal->hdr.mxFrame;
+ mxPage = pWal->hdr.nPage;
pInfo = walCkptInfo(pWal);
for(i=1; i<WAL_NREADER; i++){
u32 y = pInfo->aReadMark[i];
@@ -1565,6 +1567,7 @@ static int walCheckpoint(
if( pInfo->nBackfill<mxSafeFrame
&& (rc = walLockExclusive(pWal, WAL_READ_LOCK(0), 1))==SQLITE_OK
){
+ i64 nSize; /* Current size of database file */
u32 nBackfill = pInfo->nBackfill;
/* Sync the WAL to disk */
@@ -1572,11 +1575,22 @@ static int walCheckpoint(
rc = sqlite3OsSync(pWal->pWalFd, sync_flags);
}
+ /* If the database file may grow as a result of this checkpoint, hint
+ ** about the eventual size of the db file to the VFS layer.
+ */
+ if( rc==SQLITE_OK ){
+ i64 nReq = ((i64)mxPage * szPage);
+ rc = sqlite3OsFileSize(pWal->pDbFd, &nSize);
+ if( rc==SQLITE_OK && nSize<nReq ){
+ sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_SIZE_HINT, &nReq);
+ }
+ }
+
/* Iterate through the contents of the WAL, copying data to the db file. */
while( rc==SQLITE_OK && 0==walIteratorNext(pIter, &iDbpage, &iFrame) ){
i64 iOffset;
assert( walFramePgno(pWal, iFrame)==iDbpage );
- if( iFrame<=nBackfill || iFrame>mxSafeFrame ) continue;
+ if( iFrame<=nBackfill || iFrame>mxSafeFrame || iDbpage>mxPage ) continue;
iOffset = walFrameOffset(iFrame, szPage) + WAL_FRAME_HDRSIZE;
/* testcase( IS_BIG_INT(iOffset) ); // requires a 4GiB WAL file */
rc = sqlite3OsRead(pWal->pWalFd, zBuf, szPage, iOffset);
@@ -2031,6 +2045,7 @@ int sqlite3WalBeginReadTransaction(Wal *pWal, int *pChanged){
** read-lock.
*/
void sqlite3WalEndReadTransaction(Wal *pWal){
+ sqlite3WalEndWriteTransaction(pWal);
if( pWal->readLock>=0 ){
walUnlockShared(pWal, WAL_READ_LOCK(pWal->readLock));
pWal->readLock = -1;
@@ -2153,11 +2168,13 @@ int sqlite3WalRead(
/*
-** Set *pPgno to the size of the database file (or zero, if unknown).
+** Return the size of the database in pages (or zero, if unknown).
*/
-void sqlite3WalDbsize(Wal *pWal, Pgno *pPgno){
- assert( pWal->readLock>=0 || pWal->lockError );
- *pPgno = pWal->hdr.nPage;
+Pgno sqlite3WalDbsize(Wal *pWal){
+ if( pWal && pWal->readLock>=0 ){
+ return pWal->hdr.nPage;
+ }
+ return 0;
}