Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Unified Diff: extensions/browser/value_store/leveldb_value_store.cc

Issue 1428843002: LeveldbValueStore: Deleting db when open fails due to corruption. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: base::File::DeleteFile -> base::DeleteFile Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « extensions/browser/value_store/leveldb_value_store.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/browser/value_store/leveldb_value_store.cc
diff --git a/extensions/browser/value_store/leveldb_value_store.cc b/extensions/browser/value_store/leveldb_value_store.cc
index 39a1346df7d2c2ca41d92585254cf4401e397436..d6f186639ebad9570cb3bb8109594e75a688e0d2 100644
--- a/extensions/browser/value_store/leveldb_value_store.cc
+++ b/extensions/browser/value_store/leveldb_value_store.cc
@@ -25,6 +25,15 @@ namespace {
const char kInvalidJson[] = "Invalid JSON";
const char kCannotSerialize[] = "Cannot serialize value to JSON";
+// UMA values used when recovering from a corrupted leveldb.
+// Do not change/delete these values as you will break reporting for older
+// copies of Chrome. Only add new values to the end.
+enum LevelDBCorruptionRecoveryValue {
+ LEVELDB_CORRUPTION_RECOVERY_DELETE_SUCCESS = 0,
+ LEVELDB_CORRUPTION_RECOVERY_DELETE_FAILURE,
+ LEVELDB_CORRUPTION_RECOVERY_MAX
+};
+
// Scoped leveldb snapshot which releases the snapshot on destruction.
class ScopedSnapshot {
public:
@@ -50,7 +59,9 @@ class ScopedSnapshot {
LeveldbValueStore::LeveldbValueStore(const std::string& uma_client_name,
const base::FilePath& db_path)
- : db_path_(db_path), open_histogram_(nullptr) {
+ : db_path_(db_path),
+ open_histogram_(nullptr),
+ corruption_recovery_histogram_(nullptr) {
DCHECK_CURRENTLY_ON(BrowserThread::FILE);
// Used in lieu of UMA_HISTOGRAM_ENUMERATION because the histogram name is
@@ -59,6 +70,10 @@ LeveldbValueStore::LeveldbValueStore(const std::string& uma_client_name,
"Extensions.Database.Open." + uma_client_name, 1,
leveldb_env::LEVELDB_STATUS_MAX, leveldb_env::LEVELDB_STATUS_MAX + 1,
base::Histogram::kUmaTargetedHistogramFlag);
+ corruption_recovery_histogram_ = base::LinearHistogram::FactoryGet(
+ "Extensions.Database.CorruptionRecovery." + uma_client_name, 1,
+ LEVELDB_CORRUPTION_RECOVERY_MAX, LEVELDB_CORRUPTION_RECOVERY_MAX + 1,
+ base::Histogram::kUmaTargetedHistogramFlag);
}
LeveldbValueStore::~LeveldbValueStore() {
@@ -341,6 +356,16 @@ scoped_ptr<ValueStore::Error> LeveldbValueStore::EnsureDbIsOpen() {
leveldb::DB::Open(options, db_path_.AsUTF8Unsafe(), &db);
if (open_histogram_)
open_histogram_->Add(leveldb_env::GetLevelDBStatusUMAValue(status));
+ if (status.IsCorruption()) {
+ // We do not currently recover from corrupted databases, so completely
Devlin 2015/10/29 17:57:26 We do try to recover. See ValueStore::Restore().
cmumford 2015/10/29 22:34:22 Yes, it appears as though ValueStoreFrontend::Back
Devlin 2015/10/30 20:13:17 We try to restore when a call fails - this is in s
+ // delete it to avoid future open failures.
+ if (base::DeleteFile(db_path_, true /* recursive */))
+ corruption_recovery_histogram_->Add(
+ LEVELDB_CORRUPTION_RECOVERY_DELETE_SUCCESS);
+ else
+ corruption_recovery_histogram_->Add(
+ LEVELDB_CORRUPTION_RECOVERY_DELETE_FAILURE);
+ }
if (!status.ok())
return ToValueStoreError(status, util::NoKey());
« no previous file with comments | « extensions/browser/value_store/leveldb_value_store.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698