1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-04 04:42:17 +03:00

In persistent WAL mode, truncate the WAL file to the size specified by the

journal_size_limit pragma when disconnecting from the WAL.

FossilOrigin-Name: 9687b305c2320109a8649612181eecd2e0da7c7b
This commit is contained in:
drh
2011-12-08 19:50:32 +00:00
parent c4eef45c14
commit 8dd4afadd8
4 changed files with 53 additions and 28 deletions

View File

@ -1781,6 +1781,26 @@ static int walCheckpoint(
return rc;
}
/*
** Attempt to limit the WAL size to the size limit defined by
** PRAGMA journal_size_limit.
*/
static void walLimitSize(Wal *pWal){
if( pWal->mxWalSize>=0 ){
i64 sz;
int rx;
sqlite3BeginBenignMalloc();
rx = sqlite3OsFileSize(pWal->pWalFd, &sz);
if( rx==SQLITE_OK && (sz > pWal->mxWalSize) ){
rx = sqlite3OsTruncate(pWal->pWalFd, pWal->mxWalSize);
}
sqlite3EndBenignMalloc();
if( rx ){
sqlite3_log(rx, "cannot limit WAL size: %s", pWal->zWalName);
}
}
}
/*
** Close a connection to a log file.
*/
@ -1814,6 +1834,8 @@ int sqlite3WalClose(
sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_PERSIST_WAL, &bPersistWal);
if( rc==SQLITE_OK && bPersistWal!=1 ){
isDelete = 1;
}else{
walLimitSize(pWal);
}
}
@ -2518,6 +2540,7 @@ int sqlite3WalSavepointUndo(Wal *pWal, u32 *aWalData){
return rc;
}
/*
** This function is called just before writing a set of frames to the log
** file (see sqlite3WalFrames()). It checks to see if, instead of appending
@ -2555,23 +2578,7 @@ static int walRestartLog(Wal *pWal){
int i; /* Loop counter */
u32 *aSalt = pWal->hdr.aSalt; /* Big-endian salt values */
/* Limit the size of WAL file if the journal_size_limit PRAGMA is
** set to a non-negative value. Log errors encountered
** during the truncation attempt. */
if( pWal->mxWalSize>=0 ){
i64 sz;
int rx;
sqlite3BeginBenignMalloc();
rx = sqlite3OsFileSize(pWal->pWalFd, &sz);
if( rx==SQLITE_OK && (sz > pWal->mxWalSize) ){
rx = sqlite3OsTruncate(pWal->pWalFd, pWal->mxWalSize);
}
sqlite3EndBenignMalloc();
if( rx ){
sqlite3_log(rx, "cannot limit WAL size: %s", pWal->zWalName);
}
}
walLimitSize(pWal);
pWal->nCkpt++;
pWal->hdr.mxFrame = 0;
sqlite3Put4byte((u8*)&aSalt[0], 1 + sqlite3Get4byte((u8*)&aSalt[0]));