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

Unified Diff: components/sync/model_impl/model_type_store_backend.h

Issue 2692993008: [Sync] Reset ModelTypeStore's leveldb database after corruption (Closed)
Patch Set: Created 3 years, 10 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 | « no previous file | components/sync/model_impl/model_type_store_backend.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/sync/model_impl/model_type_store_backend.h
diff --git a/components/sync/model_impl/model_type_store_backend.h b/components/sync/model_impl/model_type_store_backend.h
index 4c99ad24bea51e434282809279e14fe4c1eefd83..0618432c4851c9e5c7b03cb7eb69c4c93946f741 100644
--- a/components/sync/model_impl/model_type_store_backend.h
+++ b/components/sync/model_impl/model_type_store_backend.h
@@ -13,6 +13,7 @@
#include "base/macros.h"
#include "base/threading/thread_collision_warner.h"
#include "components/sync/model/model_type_store.h"
+#include "third_party/leveldatabase/src/include/leveldb/status.h"
namespace leveldb {
class DB;
@@ -22,6 +23,32 @@ class WriteBatch;
namespace syncer {
+// 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,
+
+ // Database was reset after attempt to open failed with corruption.
+ STORE_INIT_RESULT_RECOVERED_AFTER_CORRUPTION,
+ STORE_INIT_RESULT_COUNT
+};
+
// ModelTypeStoreBackend handles operations with leveldb. It is oblivious of the
// fact that it is called from separate thread (with the exception of ctor),
// meaning it shouldn't deal with callbacks and task_runners.
@@ -69,29 +96,11 @@ class ModelTypeStoreBackend
static const int64_t kLatestSchemaVersion;
static const char kDBSchemaDescriptorRecordId[];
+ static const char kStoreInitResultHistogramName[];
explicit ModelTypeStoreBackend(const std::string& path);
~ModelTypeStoreBackend();
- // In some scenarios ModelTypeStoreBackend holds ownership of env. Typical
- // example is when test creates in memory environment with CreateInMemoryEnv
- // and wants it to be destroyed along with backend. This is achieved by
- // passing ownership of env to TakeEnvOwnership function.
- //
- // env_ declaration should appear before declaration of db_ because
- // environment object should still be valid when db_'s destructor is called.
- std::unique_ptr<leveldb::Env> env_;
-
- std::unique_ptr<leveldb::DB> db_;
-
- std::string path_;
-
- // backend_map_ holds raw pointer of backend, and when stores ask for backend,
- // GetOrCreateBackend will return scoped_refptr of backend. backend_map_
- // doesn't take reference to backend, therefore doesn't block backend
- // destruction.
- static base::LazyInstance<BackendMap> backend_map_;
-
// Init opens database at |path|. If database doesn't exist it creates one.
// Normally |env| should be nullptr, this causes leveldb to use default disk
// based environment from leveldb::Env::Default().
@@ -100,6 +109,14 @@ class ModelTypeStoreBackend
ModelTypeStore::Result Init(const std::string& path,
std::unique_ptr<leveldb::Env> env);
+ // Opens leveldb database passing correct options. On success sets |db_| and
+ // returns ok status. On failure |db_| is nullptr and returned status reflects
+ // failure type.
+ leveldb::Status OpenDatabase(const std::string& path, leveldb::Env* env);
+
+ // Destroys leveldb database. Used for recovering after database corruption.
+ leveldb::Status DestroyDatabase(const std::string& path, leveldb::Env* env);
+
// Attempts to read and return the database's version.
// If there is not a schema descriptor present, the value returned is 0.
// If an error occurs, the value returned is kInvalidSchemaVersion(-1).
@@ -114,6 +131,28 @@ class ModelTypeStoreBackend
// the schema, returning true on success.
bool Migrate0To1();
+ static void RecordStoreInitResultHistogram(
+ StoreInitResultForHistogram result);
+
+ // In some scenarios ModelTypeStoreBackend holds ownership of env. Typical
+ // example is when test creates in memory environment with CreateInMemoryEnv
+ // and wants it to be destroyed along with backend. This is achieved by
+ // passing ownership of env to TakeEnvOwnership function.
+ //
+ // env_ declaration should appear before declaration of db_ because
+ // environment object should still be valid when db_'s destructor is called.
+ std::unique_ptr<leveldb::Env> env_;
+
+ std::unique_ptr<leveldb::DB> db_;
+
+ std::string path_;
+
+ // backend_map_ holds raw pointer of backend, and when stores ask for backend,
+ // GetOrCreateBackend will return scoped_refptr of backend. backend_map_
+ // doesn't take reference to backend, therefore doesn't block backend
+ // destruction.
+ static base::LazyInstance<BackendMap> backend_map_;
+
// Macro wrapped mutex to guard against concurrent calls in debug builds.
DFAKE_MUTEX(push_pop_);
« no previous file with comments | « no previous file | components/sync/model_impl/model_type_store_backend.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698