diff options
author | shess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-06 23:05:00 +0000 |
---|---|---|
committer | shess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-06 23:05:00 +0000 |
commit | 4658e2a06d382973cd9059740784f3c57aab293a (patch) | |
tree | e0c4946ca31d09e367894071e5505490630e70c0 /sql | |
parent | 0b6c588379303979ef7148a6630d483c4fd0f54e (diff) | |
download | chromium_src-4658e2a06d382973cd9059740784f3c57aab293a.zip chromium_src-4658e2a06d382973cd9059740784f3c57aab293a.tar.gz chromium_src-4658e2a06d382973cd9059740784f3c57aab293a.tar.bz2 |
[sql] Enable writable_schema during integrity_check.
Logging integrity_check for corruption in thumbnail_database.cc has
caught one bit of info, and a bunch of empty results. I suspect that
"PRAGMA integrity_check" is itself failing. writable_schema enables
an internal RecoveryMode flag which allows SQLite to work through
certain simple forms of corruption.
More Sqlite.SizeKB.Thumbnail results have come in. 8M covers >90% of
Favicon databases and seems like a reasonable bet.
Tweak the chance of running the integrity check. Previously,
SQLITE_CORRUPT was overwhelming the other errors, now it is around 3%
of cases caught (on dev channel). This aims to get around 25%-30%.
BUG=240396
Review URL: https://chromiumcodereview.appspot.com/16406002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@204645 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sql')
-rw-r--r-- | sql/connection.cc | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/sql/connection.cc b/sql/connection.cc index d27814d..a7a599c 100644 --- a/sql/connection.cc +++ b/sql/connection.cc @@ -777,19 +777,36 @@ int Connection::OnSqliteError(int err, sql::Statement *stmt) { // TODO(shess): Allow specifying integrity_check versus quick_check. // TODO(shess): Allow specifying maximum results (default 100 lines). bool Connection::IntegrityCheck(std::vector<std::string>* messages) { - const char kSql[] = "PRAGMA integrity_check"; - sql::Statement stmt(GetUniqueStatement(kSql)); - messages->clear(); - // The pragma appears to return all results (up to 100 by default) - // as a single string. This doesn't appear to be an API contract, - // it could return separate lines, so loop _and_ split. - while (stmt.Step()) { - std::string result(stmt.ColumnString(0)); - base::SplitString(result, '\n', messages); + // This has the side effect of setting SQLITE_RecoveryMode, which + // allows SQLite to process through certain cases of corruption. + // Failing to set this pragma probably means that the database is + // beyond recovery. + const char kWritableSchema[] = "PRAGMA writable_schema = ON"; + if (!Execute(kWritableSchema)) + return false; + + bool ret = false; + { + const char kSql[] = "PRAGMA integrity_check"; + sql::Statement stmt(GetUniqueStatement(kSql)); + + // The pragma appears to return all results (up to 100 by default) + // as a single string. This doesn't appear to be an API contract, + // it could return separate lines, so loop _and_ split. + while (stmt.Step()) { + std::string result(stmt.ColumnString(0)); + base::SplitString(result, '\n', messages); + } + ret = stmt.Succeeded(); } - return stmt.Succeeded(); + + // Best effort to put things back as they were before. + const char kNoWritableSchema[] = "PRAGMA writable_schema = OFF"; + ignore_result(Execute(kNoWritableSchema)); + + return ret; } } // namespace sql |