| Index: components/sync/model_impl/model_type_store_backend.cc
|
| diff --git a/components/sync/model_impl/model_type_store_backend.cc b/components/sync/model_impl/model_type_store_backend.cc
|
| index 7ee2c6aaede1bc2cf08aeb77de1e2caa5db82271..ec474d227d3f58941fad0c0dcc7b2d98402657c7 100644
|
| --- a/components/sync/model_impl/model_type_store_backend.cc
|
| +++ b/components/sync/model_impl/model_type_store_backend.cc
|
| @@ -28,6 +28,8 @@ const int64_t kInvalidSchemaVersion = -1;
|
| const int64_t ModelTypeStoreBackend::kLatestSchemaVersion = 1;
|
| const char ModelTypeStoreBackend::kDBSchemaDescriptorRecordId[] =
|
| "_mts_schema_descriptor";
|
| +const char ModelTypeStoreBackend::kStoreInitResultHistogramName[] =
|
| + "Sync.ModelTypeStoreInitResult";
|
|
|
| // static
|
| base::LazyInstance<ModelTypeStoreBackend::BackendMap>
|
| @@ -35,34 +37,6 @@ base::LazyInstance<ModelTypeStoreBackend::BackendMap>
|
|
|
| namespace {
|
|
|
| -// Different reasons for ModelTypeStoreBackend initialization failure are mapped
|
| -// to these values. The enum is used for recording UMA histogram. Don't reorder,
|
| -// change or delete values.
|
| -enum StoreInitResultForHistogram {
|
| - STORE_INIT_RESULT_SUCCESS = 0,
|
| -
|
| - // Following values reflect leveldb initialization errors.
|
| - STORE_INIT_RESULT_NOT_FOUND,
|
| - STORE_INIT_RESULT_CORRUPTION,
|
| - STORE_INIT_RESULT_NOT_SUPPORTED,
|
| - STORE_INIT_RESULT_INVALID_ARGUMENT,
|
| - STORE_INIT_RESULT_IO_ERROR,
|
| -
|
| - // Issues encountered when reading or parsing schema descriptor.
|
| - STORE_INIT_RESULT_SCHEMA_DESCRIPTOR_ISSUE,
|
| -
|
| - // Database schema migration failed.
|
| - STORE_INIT_RESULT_MIGRATION,
|
| -
|
| - STORE_INIT_RESULT_UNKNOWN,
|
| - STORE_INIT_RESULT_COUNT
|
| -};
|
| -
|
| -void RecordStoreInitResultHistogram(StoreInitResultForHistogram result) {
|
| - UMA_HISTOGRAM_ENUMERATION("Sync.ModelTypeStoreInitResult", result,
|
| - STORE_INIT_RESULT_COUNT);
|
| -}
|
| -
|
| StoreInitResultForHistogram LevelDbStatusToStoreInitResult(
|
| const leveldb::Status& status) {
|
| if (status.ok())
|
| @@ -121,24 +95,24 @@ ModelTypeStore::Result ModelTypeStoreBackend::Init(
|
| const std::string& path,
|
| std::unique_ptr<leveldb::Env> env) {
|
| DFAKE_SCOPED_LOCK(push_pop_);
|
| - leveldb::DB* db_raw = nullptr;
|
|
|
| - leveldb::Options options;
|
| - options.create_if_missing = true;
|
| - options.reuse_logs = leveldb_env::kDefaultLogReuseOptionValue;
|
| - options.paranoid_checks = true;
|
| - if (env.get()) {
|
| - options.env = env.get();
|
| - env_ = std::move(env);
|
| + env_ = std::move(env);
|
| +
|
| + leveldb::Status status = OpenDatabase(path, env_.get());
|
| + if (status.IsCorruption()) {
|
| + DCHECK(db_ == nullptr);
|
| + status = DestroyDatabase(path, env_.get());
|
| + if (status.ok())
|
| + status = OpenDatabase(path, env_.get());
|
| + if (status.ok())
|
| + RecordStoreInitResultHistogram(
|
| + STORE_INIT_RESULT_RECOVERED_AFTER_CORRUPTION);
|
| }
|
| -
|
| - leveldb::Status status = leveldb::DB::Open(options, path, &db_raw);
|
| if (!status.ok()) {
|
| - DCHECK(db_raw == nullptr);
|
| + DCHECK(db_ == nullptr);
|
| RecordStoreInitResultHistogram(LevelDbStatusToStoreInitResult(status));
|
| return ModelTypeStore::Result::UNSPECIFIED_ERROR;
|
| }
|
| - db_.reset(db_raw);
|
|
|
| int64_t current_version = GetStoreVersion();
|
| if (current_version == kInvalidSchemaVersion) {
|
| @@ -158,6 +132,31 @@ ModelTypeStore::Result ModelTypeStoreBackend::Init(
|
| return ModelTypeStore::Result::SUCCESS;
|
| }
|
|
|
| +leveldb::Status ModelTypeStoreBackend::OpenDatabase(const std::string& path,
|
| + leveldb::Env* env) {
|
| + leveldb::DB* db_raw = nullptr;
|
| + leveldb::Options options;
|
| + options.create_if_missing = true;
|
| + options.reuse_logs = leveldb_env::kDefaultLogReuseOptionValue;
|
| + options.paranoid_checks = true;
|
| + if (env)
|
| + options.env = env;
|
| +
|
| + leveldb::Status status = leveldb::DB::Open(options, path, &db_raw);
|
| + DCHECK(status.ok() != (db_raw == nullptr));
|
| + if (status.ok())
|
| + db_.reset(db_raw);
|
| + return status;
|
| +}
|
| +
|
| +leveldb::Status ModelTypeStoreBackend::DestroyDatabase(const std::string& path,
|
| + leveldb::Env* env) {
|
| + leveldb::Options options;
|
| + if (env)
|
| + options.env = env;
|
| + return leveldb::DestroyDB(path, options);
|
| +}
|
| +
|
| ModelTypeStore::Result ModelTypeStoreBackend::ReadRecordsWithPrefix(
|
| const std::string& prefix,
|
| const ModelTypeStore::IdList& id_list,
|
| @@ -257,4 +256,11 @@ bool ModelTypeStoreBackend::Migrate0To1() {
|
| return status.ok();
|
| }
|
|
|
| +// static
|
| +void ModelTypeStoreBackend::RecordStoreInitResultHistogram(
|
| + StoreInitResultForHistogram result) {
|
| + UMA_HISTOGRAM_ENUMERATION(kStoreInitResultHistogramName, result,
|
| + STORE_INIT_RESULT_COUNT);
|
| +}
|
| +
|
| } // namespace syncer
|
|
|