Skip to content

Commit 7789c4b

Browse files
provision wal_autocheckpoint to prevent the log file growing to large size
1 parent a979873 commit 7789c4b

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

Source/WebCore/platform/sql/SQLiteDatabase.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <wtf/Threading.h>
4444
#include <wtf/text/CString.h>
4545
#include <wtf/text/StringConcatenateNumbers.h>
46+
#include <wtf/text/StringToIntegerConversion.h>
4647

4748
#if !USE(SYSTEM_MALLOC)
4849
#include <bmalloc/BPlatform.h>
@@ -205,7 +206,17 @@ static int walAutomaticTruncationHook(void* context, sqlite3* db, const char* db
205206
{
206207
UNUSED_PARAM(context);
207208

208-
static constexpr int checkpointThreshold = 1000; // matches SQLITE_DEFAULT_WAL_AUTOCHECKPOINT
209+
// prevent -wal file from growing indefinitely w automatic checkpointing:
210+
// set threshold for number of pages after which checkpoint should be run
211+
static constexpr int checkpointThresholdDefault = 1000; // matches SQLITE_DEFAULT_WAL_AUTOCHECKPOINT
212+
static int checkpointThreshold = 0;
213+
214+
// control threshold w/ to checkpoint more frequently if desired
215+
if (!checkpointThreshold) {
216+
auto envValue = String::fromLatin1(getenv("WPE_WAL_AUTOCHECKPOINT"));
217+
checkpointThreshold = parseInteger<int>(envValue).value_or(checkpointThresholdDefault);
218+
checkpointThreshold = checkpointThreshold < 0 ? checkpointThresholdDefault : checkpointThreshold;
219+
}
209220

210221
if (walPageCount >= checkpointThreshold) {
211222
int newWalPageCount = 0;

Source/WebKit/NetworkProcess/storage/SQLiteStorageArea.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ bool SQLiteStorageArea::prepareDatabase(ShouldCreateIfNotExists shouldCreateIfNo
185185
// We will never access the database from different threads simultaneously.
186186
m_database->disableThreadingChecks();
187187

188+
m_database->enableAutomaticWALTruncation();
189+
188190
if (!createTableIfNecessary()) {
189191
m_database = nullptr;
190192
return false;

0 commit comments

Comments
 (0)