summaryrefslogtreecommitdiffstats
path: root/sql/meta_table.cc
diff options
context:
space:
mode:
authorshess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-08 02:19:17 +0000
committershess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-08 02:19:17 +0000
commitfe4e3de5276edc05c36979ee5383cddb425e35f1 (patch)
treef20c3e55a6f935b0b35fffe4cbaffe6eb38387b8 /sql/meta_table.cc
parentf8feb29903155d73053e7ea5cca63c523c2bd215 (diff)
downloadchromium_src-fe4e3de5276edc05c36979ee5383cddb425e35f1.zip
chromium_src-fe4e3de5276edc05c36979ee5383cddb425e35f1.tar.gz
chromium_src-fe4e3de5276edc05c36979ee5383cddb425e35f1.tar.bz2
Deprecate old Favicons database versions.
Histograms show a non-zero number of users with very old databases at startup. These old databases likely result from some sort of corruption or filesystem problem, and are unlikely to spontaneously progress forward. Since the number of databases involved is very low (<.03% of users), just delete them in hopes that that allows forward progress. Arbitrarily set a 2-year deprecation deadline for this database. This is a few weeks early, as version 5 landed on 2011-10-12. BUG=240396 Review URL: https://codereview.chromium.org/24443002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@227433 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sql/meta_table.cc')
-rw-r--r--sql/meta_table.cc90
1 files changed, 87 insertions, 3 deletions
diff --git a/sql/meta_table.cc b/sql/meta_table.cc
index c7e803c..b1b9562 100644
--- a/sql/meta_table.cc
+++ b/sql/meta_table.cc
@@ -5,16 +5,52 @@
#include "sql/meta_table.h"
#include "base/logging.h"
+#include "base/metrics/histogram.h"
#include "base/strings/string_util.h"
#include "sql/connection.h"
#include "sql/statement.h"
#include "sql/transaction.h"
-namespace sql {
+namespace {
// Key used in our meta table for version numbers.
-static const char kVersionKey[] = "version";
-static const char kCompatibleVersionKey[] = "last_compatible_version";
+const char kVersionKey[] = "version";
+const char kCompatibleVersionKey[] = "last_compatible_version";
+
+// Used to track success/failure of deprecation checks.
+enum DeprecationEventType {
+ // Database has info, but no meta table. This is probably bad.
+ DEPRECATION_DATABASE_NOT_EMPTY = 0,
+
+ // No meta, unable to query sqlite_master. This is probably bad.
+ DEPRECATION_DATABASE_UNKNOWN,
+
+ // Failure querying meta table, corruption or similar problem likely.
+ DEPRECATION_FAILED_VERSION,
+
+ // Version key not found in meta table. Some sort of update error likely.
+ DEPRECATION_NO_VERSION,
+
+ // Version was out-dated, database successfully razed. Should only
+ // happen once per long-idle user, low volume expected.
+ DEPRECATION_RAZED,
+
+ // Version was out-dated, database raze failed. This user's
+ // database will be stuck.
+ DEPRECATION_RAZE_FAILED,
+
+ // Always keep this at the end.
+ DEPRECATION_EVENT_MAX,
+};
+
+void RecordDeprecationEvent(DeprecationEventType deprecation_event) {
+ UMA_HISTOGRAM_ENUMERATION("Sqlite.DeprecationVersionResult",
+ deprecation_event, DEPRECATION_EVENT_MAX);
+}
+
+} // namespace
+
+namespace sql {
MetaTable::MetaTable() : db_(NULL) {
}
@@ -28,6 +64,54 @@ bool MetaTable::DoesTableExist(sql::Connection* db) {
return db->DoesTableExist("meta");
}
+// static
+void MetaTable::RazeIfDeprecated(Connection* db, int deprecated_version) {
+ DCHECK_GT(deprecated_version, 0);
+ DCHECK_EQ(0, db->transaction_nesting());
+
+ if (!DoesTableExist(db)) {
+ sql::Statement s(db->GetUniqueStatement(
+ "SELECT COUNT(*) FROM sqlite_master"));
+ if (s.Step()) {
+ if (s.ColumnInt(0) != 0) {
+ RecordDeprecationEvent(DEPRECATION_DATABASE_NOT_EMPTY);
+ }
+ // NOTE(shess): Empty database at first run is expected, so
+ // don't histogram that case.
+ } else {
+ RecordDeprecationEvent(DEPRECATION_DATABASE_UNKNOWN);
+ }
+ return;
+ }
+
+ // TODO(shess): Share sql with PrepareGetStatement().
+ sql::Statement s(db->GetUniqueStatement(
+ "SELECT value FROM meta WHERE key=?"));
+ s.BindCString(0, kVersionKey);
+ if (!s.Step()) {
+ if (!s.Succeeded()) {
+ RecordDeprecationEvent(DEPRECATION_FAILED_VERSION);
+ } else {
+ RecordDeprecationEvent(DEPRECATION_NO_VERSION);
+ }
+ return;
+ }
+
+ int version = s.ColumnInt(0);
+ s.Clear(); // Clear potential automatic transaction for Raze().
+ if (version <= deprecated_version) {
+ if (db->Raze()) {
+ RecordDeprecationEvent(DEPRECATION_RAZED);
+ } else {
+ RecordDeprecationEvent(DEPRECATION_RAZE_FAILED);
+ }
+ return;
+ }
+
+ // NOTE(shess): Successfully getting a version which is not
+ // deprecated is expected, so don't histogram that case.
+}
+
bool MetaTable::Init(Connection* db, int version, int compatible_version) {
DCHECK(!db_ && db);
db_ = db;