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

Side by Side Diff: chrome/browser/sync/syncable/directory_backing_store.cc

Issue 8496002: Sync: Improve handling of database load failures (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Many improvements and scope expansion Created 9 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "chrome/browser/sync/syncable/directory_backing_store.h" 5 #include "chrome/browser/sync/syncable/directory_backing_store.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #include <limits> 9 #include <limits>
10 10
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 #endif 229 #endif
230 230
231 return true; 231 return true;
232 } 232 }
233 return false; 233 return false;
234 } 234 }
235 235
236 bool DirectoryBackingStore::CheckIntegrity(sqlite3* handle, string* error) 236 bool DirectoryBackingStore::CheckIntegrity(sqlite3* handle, string* error)
237 const { 237 const {
238 sqlite_utils::SQLStatement statement; 238 sqlite_utils::SQLStatement statement;
239 statement.prepare(handle, "PRAGMA integrity_check(1)"); 239 if (SQLITE_OK !=
240 statement.prepare(handle, "PRAGMA integrity_check(1)")) {
lipalani1 2011/11/14 21:34:24 We can add a UMA metric here.
rlarocque 2011/11/14 22:56:26 We could, but we'd probably end up taking it out i
241 *error = sqlite3_errmsg(handle);
242 return false;
243 }
240 if (SQLITE_ROW != statement.step()) { 244 if (SQLITE_ROW != statement.step()) {
241 *error = sqlite3_errmsg(handle); 245 *error = sqlite3_errmsg(handle);
242 return false; 246 return false;
243 } 247 }
244 string integrity_result = statement.column_text(0); 248 string integrity_result = statement.column_text(0);
245 if (integrity_result != "ok") { 249 if (integrity_result != "ok") {
246 *error = integrity_result; 250 *error = integrity_result;
247 return false; 251 return false;
248 } 252 }
249 return true; 253 return true;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 STLDeleteElements(entry_bucket); 286 STLDeleteElements(entry_bucket);
283 287
284 // Close database handle. 288 // Close database handle.
285 EndLoad(); 289 EndLoad();
286 290
287 return result; 291 return result;
288 } 292 }
289 293
290 bool DirectoryBackingStore::BeginLoad() { 294 bool DirectoryBackingStore::BeginLoad() {
291 DCHECK(load_dbhandle_ == NULL); 295 DCHECK(load_dbhandle_ == NULL);
292 bool ret = OpenAndConfigureHandleHelper(&load_dbhandle_); 296 return OpenAndConfigureHandleHelper(&load_dbhandle_);
293 if (ret)
294 return true;
295 // Something's gone wrong. Nuke the database and try again.
296 using ::operator<<; // For string16.
297 LOG(ERROR) << "Sync database " << backing_filepath_.value()
298 << " corrupt. Deleting and recreating.";
299 file_util::Delete(backing_filepath_, false);
300 bool failed_again = !OpenAndConfigureHandleHelper(&load_dbhandle_);
301
302 // Using failed_again here lets us distinguish from cases where corruption
303 // occurred even when re-opening a fresh directory (they'll go in a separate
304 // double weight histogram bucket). Failing twice in a row means we disable
305 // sync, so it's useful to see this number separately.
306 int bucket = failed_again ? 2 : 1;
307 #if defined(OS_WIN)
308 UMA_HISTOGRAM_COUNTS_100("Sync.DirectoryOpenFailedWin", bucket);
Nicolas Zea 2011/11/14 19:29:21 Since I suppose these histograms don't make sense
rlarocque 2011/11/14 22:56:26 Done in a separate CL that also adds replacement h
309 #elif defined(OS_MACOSX)
310 UMA_HISTOGRAM_COUNTS_100("Sync.DirectoryOpenFailedMac", bucket);
311 #else
312 UMA_HISTOGRAM_COUNTS_100("Sync.DirectoryOpenFailedNotWinMac", bucket);
313
314 #if defined(OS_CHROMEOS)
315 UMA_HISTOGRAM_COUNTS_100("Sync.DirectoryOpenFailedCros", bucket);
316 #elif defined(OS_LINUX)
317 UMA_HISTOGRAM_COUNTS_100("Sync.DirectoryOpenFailedLinux", bucket);
318 #else
319 UMA_HISTOGRAM_COUNTS_100("Sync.DirectoryOpenFailedOther", bucket);
320 #endif // OS_LINUX && !OS_CHROMEOS
321 #endif // OS_WIN
322 return !failed_again;
323 } 297 }
324 298
325 void DirectoryBackingStore::EndLoad() { 299 void DirectoryBackingStore::EndLoad() {
326 sqlite3_close(load_dbhandle_); 300 sqlite3_close(load_dbhandle_);
327 load_dbhandle_ = NULL; // No longer used. 301 load_dbhandle_ = NULL; // No longer used.
328 } 302 }
329 303
330 void DirectoryBackingStore::EndSave() { 304 void DirectoryBackingStore::EndSave() {
331 sqlite3_close(save_dbhandle_); 305 sqlite3_close(save_dbhandle_);
332 save_dbhandle_ = NULL; 306 save_dbhandle_ = NULL;
(...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after
1270 "id TEXT primary key, " 1244 "id TEXT primary key, "
1271 "name TEXT, " 1245 "name TEXT, "
1272 "store_birthday TEXT, " 1246 "store_birthday TEXT, "
1273 "db_create_version TEXT, " 1247 "db_create_version TEXT, "
1274 "db_create_time INT, " 1248 "db_create_time INT, "
1275 "next_id INT default -2, " 1249 "next_id INT default -2, "
1276 "cache_guid TEXT )"); 1250 "cache_guid TEXT )");
1277 return ExecQuery(load_dbhandle_, query.c_str()); 1251 return ExecQuery(load_dbhandle_, query.c_str());
1278 } 1252 }
1279 } // namespace syncable 1253 } // namespace syncable
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698