Browse Source

Switch SQLite to use WAL journaling mode

PR #18048.
adaptive-webui-19844
Vladimir Golovnev 2 years ago committed by GitHub
parent
commit
a31755bbc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 28
      src/base/bittorrent/dbresumedatastorage.cpp
  2. 1
      src/base/bittorrent/dbresumedatastorage.h

28
src/base/bittorrent/dbresumedatastorage.cpp

@ -452,9 +452,17 @@ int BitTorrent::DBResumeDataStorage::currentDBVersion() const @@ -452,9 +452,17 @@ int BitTorrent::DBResumeDataStorage::currentDBVersion() const
void BitTorrent::DBResumeDataStorage::createDB() const
{
auto db = QSqlDatabase::database(DB_CONNECTION_NAME);
try
{
enableWALMode();
}
catch (const RuntimeError &err)
{
LogMsg(tr("Couldn't enable Write-Ahead Logging (WAL) journaling mode. Error: %1.")
.arg(err.message()), Log::WARNING);
}
const QWriteLocker locker {&m_dbLock};
auto db = QSqlDatabase::database(DB_CONNECTION_NAME);
if (!db.transaction())
throw RuntimeError(db.lastError().text());
@ -568,6 +576,22 @@ void BitTorrent::DBResumeDataStorage::updateDB(const int fromVersion) const @@ -568,6 +576,22 @@ void BitTorrent::DBResumeDataStorage::updateDB(const int fromVersion) const
}
}
void BitTorrent::DBResumeDataStorage::enableWALMode() const
{
auto db = QSqlDatabase::database(DB_CONNECTION_NAME);
QSqlQuery query {db};
if (!query.exec(u"PRAGMA journal_mode = WAL;"_qs))
throw RuntimeError(query.lastError().text());
if (!query.next())
throw RuntimeError(tr("Couldn't obtain query result."));
const QString result = query.value(0).toString();
if (result.compare(u"WAL"_qs, Qt::CaseInsensitive) != 0)
throw RuntimeError(tr("WAL mode is probably unsupported due to filesystem limitations."));
}
BitTorrent::DBResumeDataStorage::Worker::Worker(const Path &dbPath, const QString &dbConnectionName, QReadWriteLock &dbLock)
: m_path {dbPath}
, m_connectionName {dbConnectionName}

1
src/base/bittorrent/dbresumedatastorage.h

@ -58,6 +58,7 @@ namespace BitTorrent @@ -58,6 +58,7 @@ namespace BitTorrent
int currentDBVersion() const;
void createDB() const;
void updateDB(int fromVersion) const;
void enableWALMode() const;
QThread *m_ioThread = nullptr;

Loading…
Cancel
Save