From: Christian Kamm Date: Tue, 12 Sep 2017 11:39:45 +0000 (+0200) Subject: Journal: Fall back to DELETE on IO error #5723 X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~701^2~113 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=4acb70e79dc7ce500168fd7e7338248fa06e9777;p=nextcloud-desktop.git Journal: Fall back to DELETE on IO error #5723 Also add logging of extended error codes for this IO error, maybe we can become more specific about which situations should trigger a journal mode switch. --- diff --git a/src/libsync/ownsql.cpp b/src/libsync/ownsql.cpp index 759f1981d..e66fdfb3e 100644 --- a/src/libsync/ownsql.cpp +++ b/src/libsync/ownsql.cpp @@ -280,6 +280,12 @@ bool SqlQuery::exec() if (_errId != SQLITE_DONE && _errId != SQLITE_ROW) { _error = QString::fromUtf8(sqlite3_errmsg(_db)); qCWarning(lcSql) << "Sqlite exec statement error:" << _errId << _error << "in" << _sql; + if (_errId == SQLITE_IOERR) { + qCWarning(lcSql) << "IOERR extended errcode: " << sqlite3_extended_errcode(_db); +#if SQLITE_VERSION_NUMBER >= 3012000 + qCWarning(lcSql) << "IOERR system errno: " << sqlite3_system_errno(_db); +#endif + } } else { qCDebug(lcSql) << "Last exec affected" << numRowsAffected() << "rows."; } diff --git a/src/libsync/syncjournaldb.cpp b/src/libsync/syncjournaldb.cpp index 6706fb65e..f4d3510dd 100644 --- a/src/libsync/syncjournaldb.cpp +++ b/src/libsync/syncjournaldb.cpp @@ -323,7 +323,26 @@ bool SyncJournalDb::checkConnect() ");"); if (!createQuery.exec()) { - return sqlFail("Create table metadata", createQuery); + bool fail = true; + + // In certain situations the io error can be avoided by switching + // to the DELETE journal mode, see #5723 + if (createQuery.errorId() == SQLITE_IOERR) { + qCWarning(lcDb) << "IO error on table creation, attempting with DELETE journal mode"; + + pragma1.prepare(QString("PRAGMA journal_mode=DELETE;")); + if (!pragma1.exec()) { + return sqlFail("Set PRAGMA journal_mode", pragma1); + } + pragma1.next(); + qCInfo(lcDb) << "sqlite3 journal_mode=" << pragma1.stringValue(0); + + if (createQuery.exec()) { + fail = false; + } + } + if (fail) + return sqlFail("Create table metadata", createQuery); } createQuery.prepare("CREATE TABLE IF NOT EXISTS downloadinfo("