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

Side by Side Diff: sql/recovery.h

Issue 2727553006: [sql] Convert thumbnails and top-sites databases to auto-recovery. (Closed)
Patch Set: tests and review comments Created 3 years, 9 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 unified diff | Download patch
« no previous file with comments | « components/history/core/browser/top_sites_database_unittest.cc ('k') | sql/recovery.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stddef.h> 8 #include <stddef.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 bool SetupMeta(); 149 bool SetupMeta();
150 150
151 // Fetch the version number from temp.recover_meta. Returns false 151 // Fetch the version number from temp.recover_meta. Returns false
152 // if the query fails, or if there is no version row. Otherwise 152 // if the query fails, or if there is no version row. Otherwise
153 // returns true, with the version in |*version_number|. 153 // returns true, with the version in |*version_number|.
154 // 154 //
155 // Only valid to call after successful SetupMeta(). 155 // Only valid to call after successful SetupMeta().
156 bool GetMetaVersionNumber(int* version_number); 156 bool GetMetaVersionNumber(int* version_number);
157 157
158 // Attempt to recover the database by creating a new database with schema from 158 // Attempt to recover the database by creating a new database with schema from
159 // |db|, then copying over as much data as possible. After this call, the 159 // |db|, then copying over as much data as possible. If successful, the
160 // |db| handle will be poisoned (though technically remaining open) so that 160 // recovery handle is returned to allow the caller to make additional changes,
161 // future calls will return errors until the handle is re-opened. 161 // such as validating constraints not expressed in the schema.
162 //
163 // If a corrupt database contains tables without unique indices, the resulting
164 // table may contain duplication. If this is not acceptable, the client
165 // should use the manual process as described in the example at the top of the
166 // file, cleaning up data at the appropriate points.
167 // 162 //
168 // In case of SQLITE_NOTADB, the database is deemed unrecoverable and deleted. 163 // In case of SQLITE_NOTADB, the database is deemed unrecoverable and deleted.
164 static std::unique_ptr<Recovery> BeginRecoverDatabase(
165 Connection* db,
166 const base::FilePath& db_path) WARN_UNUSED_RESULT;
167
168 // Call BeginRecoverDatabase() to recover the database, then commit the
169 // changes using Recovered(). After this call, the |db| handle will be
170 // poisoned (though technically remaining open) so that future calls will
171 // return errors until the handle is re-opened.
169 static void RecoverDatabase(Connection* db, const base::FilePath& db_path); 172 static void RecoverDatabase(Connection* db, const base::FilePath& db_path);
170 173
174 // Variant on RecoverDatabase() which requires that the database have a valid
175 // meta table with a version value. The meta version value is used by some
176 // clients to make assertions about the database schema. If this information
177 // cannot be determined, the database is considered unrecoverable.
178 static void RecoverDatabaseWithMetaVersion(Connection* db,
179 const base::FilePath& db_path);
180
171 // Returns true for SQLite errors which RecoverDatabase() can plausibly fix. 181 // Returns true for SQLite errors which RecoverDatabase() can plausibly fix.
172 // This does not guarantee that RecoverDatabase() will successfully recover 182 // This does not guarantee that RecoverDatabase() will successfully recover
173 // the database. 183 // the database.
174 static bool ShouldRecover(int extended_error); 184 static bool ShouldRecover(int extended_error);
175 185
176 private: 186 private:
177 explicit Recovery(Connection* connection); 187 explicit Recovery(Connection* connection);
178 188
179 // Setup the recovery database handle for Begin(). Returns false in 189 // Setup the recovery database handle for Begin(). Returns false in
180 // case anything failed. 190 // case anything failed.
(...skipping 13 matching lines...) Expand all
194 204
195 Connection* db_; // Original database connection. 205 Connection* db_; // Original database connection.
196 Connection recover_db_; // Recovery connection. 206 Connection recover_db_; // Recovery connection.
197 207
198 DISALLOW_COPY_AND_ASSIGN(Recovery); 208 DISALLOW_COPY_AND_ASSIGN(Recovery);
199 }; 209 };
200 210
201 } // namespace sql 211 } // namespace sql
202 212
203 #endif // SQL_RECOVERY_H_ 213 #endif // SQL_RECOVERY_H_
OLDNEW
« no previous file with comments | « components/history/core/browser/top_sites_database_unittest.cc ('k') | sql/recovery.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698