Chromium Code Reviews| 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()); |