Skip to content

Commit e5cc8f9

Browse files
abstractmachinesspenap
authored andcommitted
provision wal_autocheckpoint to prevent the log file growing to large size
1 parent 8d3c8fd commit e5cc8f9

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

Source/WebCore/platform/sql/SQLiteDatabase.cpp

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

4749
#if !USE(SYSTEM_MALLOC)
4850
#include <bmalloc/BPlatform.h>
@@ -207,7 +209,17 @@ static int walAutomaticTruncationHook(void* context, sqlite3* db, const char* db
207209
{
208210
UNUSED_PARAM(context);
209211

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

212224
if (walPageCount >= checkpointThreshold) {
213225
int newWalPageCount = 0;

Source/WebKit/NetworkProcess/storage/SQLiteStorageArea.cpp

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

198+
m_database->enableAutomaticWALTruncation();
199+
198200
if (!createTableIfNecessary()) {
199201
m_database = nullptr;
200202
return false;

0 commit comments

Comments
 (0)