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

Side by Side Diff: sql/recovery.h

Issue 50493012: [sql] Recover Favicons v5 databases, with more recovery automation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase and cleanup Created 7 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef SQL_RECOVERY_H_ 5 #ifndef SQL_RECOVERY_H_
6 #define SQL_RECOVERY_H_ 6 #define SQL_RECOVERY_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 9
10 #include "sql/connection.h" 10 #include "sql/connection.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 // database states are not well-understood without further 86 // database states are not well-understood without further
87 // diagnostics. Abandon recovery but do not raze the original 87 // diagnostics. Abandon recovery but do not raze the original
88 // database. 88 // database.
89 // NOTE(shess): Only call this when adding recovery support. In the 89 // NOTE(shess): Only call this when adding recovery support. In the
90 // steady state, all databases should progress to recovered or razed. 90 // steady state, all databases should progress to recovered or razed.
91 static void Rollback(scoped_ptr<Recovery> r); 91 static void Rollback(scoped_ptr<Recovery> r);
92 92
93 // Handle to the temporary recovery database. 93 // Handle to the temporary recovery database.
94 sql::Connection* db() { return &recover_db_; } 94 sql::Connection* db() { return &recover_db_; }
95 95
96 // Attempt to recover the named table from the corrupt database into
97 // the recovery database using a temporary recover virtual table.
98 // The virtual table schema is derived from the named table's schema
99 // in database [main]. Data is copied using INSERT OR REPLACE, so
100 // duplicates overwrite each other.
101 //
102 // |extend_columns| allows recovering tables which have excess
103 // columns relative to the target schema. The recover virtual table
104 // treats more data than specified as a sign of corruption.
105 //
106 // Returns true if all operations succeeded.
107 //
108 // NOTE(shess): Due to a flaw in the recovery virtual table, at this
109 // time this code injects the DEFAULT value of the target table in
110 // locations where the recovery table returns NULL. This is not
111 // entirely correct, because it happens both when there is a short
112 // row (correct) but also where there is an actual NULL value
113 // (incorrect).
114 //
115 // TODO(shess): Flag for INSERT OR REPLACE vs IGNORE.
116 // TODO(shess): Expose number of rows copied.
117 // TODO(shess): Handle extended table names.
118 bool AutoRecoverTable(const char* table_name, size_t extend_columns);
119
120 // Setup a recover virtual table at temp.recover_meta, reading from
121 // corrupt.meta. Returns true if created.
122 // TODO(shess): Perhaps integrate into Begin().
123 // TODO(shess): Add helpers to fetch additional items from the meta
124 // table as needed.
125 bool SetupMeta();
126
127 // Fetch the version number from temp.recover_meta. Returns false
128 // if the query fails, or if there is no version row. Otherwise
129 // returns true, with the version in |*version_number|.
130 //
131 // Only valid to call after successful SetupMeta().
132 bool GetMetaVersionNumber(int* version_number);
133
96 private: 134 private:
97 explicit Recovery(Connection* connection); 135 explicit Recovery(Connection* connection);
98 136
99 // Setup the recovery database handle for Begin(). Returns false in 137 // Setup the recovery database handle for Begin(). Returns false in
100 // case anything failed. 138 // case anything failed.
101 bool Init(const base::FilePath& db_path) WARN_UNUSED_RESULT; 139 bool Init(const base::FilePath& db_path) WARN_UNUSED_RESULT;
102 140
103 // Copy the recovered database over the original database. 141 // Copy the recovered database over the original database.
104 bool Backup() WARN_UNUSED_RESULT; 142 bool Backup() WARN_UNUSED_RESULT;
105 143
106 // Close the recovery database, and poison the original handle. 144 // Close the recovery database, and poison the original handle.
107 // |raze| controls whether the original database is razed or just 145 // |raze| controls whether the original database is razed or just
108 // poisoned. 146 // poisoned.
109 enum Disposition { 147 enum Disposition {
110 RAZE_AND_POISON, 148 RAZE_AND_POISON,
111 POISON, 149 POISON,
112 }; 150 };
113 void Shutdown(Disposition raze); 151 void Shutdown(Disposition raze);
114 152
115 Connection* db_; // Original database connection. 153 Connection* db_; // Original database connection.
116 Connection recover_db_; // Recovery connection. 154 Connection recover_db_; // Recovery connection.
117 155
118 DISALLOW_COPY_AND_ASSIGN(Recovery); 156 DISALLOW_COPY_AND_ASSIGN(Recovery);
119 }; 157 };
120 158
121 } // namespace sql 159 } // namespace sql
122 160
123 #endif // SQL_RECOVERY_H_ 161 #endif // SQL_RECOVERY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698