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

Side by Side Diff: sql/connection.cc

Issue 11468024: Add diagnostics to debug database open problems. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "sql/connection.h" 5 #include "sql/connection.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/metrics/histogram.h"
11 #include "base/string_util.h" 12 #include "base/string_util.h"
12 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
13 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
14 #include "sql/statement.h" 15 #include "sql/statement.h"
15 #include "third_party/sqlite/sqlite3.h" 16 #include "third_party/sqlite/sqlite3.h"
16 17
17 namespace { 18 namespace {
18 19
19 // Spin for up to a second waiting for the lock to clear when setting 20 // Spin for up to a second waiting for the lock to clear when setting
20 // up the database. 21 // up the database.
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 bool Connection::OpenInternal(const std::string& file_name) { 532 bool Connection::OpenInternal(const std::string& file_name) {
532 AssertIOAllowed(); 533 AssertIOAllowed();
533 534
534 if (db_) { 535 if (db_) {
535 DLOG(FATAL) << "sql::Connection is already open."; 536 DLOG(FATAL) << "sql::Connection is already open.";
536 return false; 537 return false;
537 } 538 }
538 539
539 int err = sqlite3_open(file_name.c_str(), &db_); 540 int err = sqlite3_open(file_name.c_str(), &db_);
540 if (err != SQLITE_OK) { 541 if (err != SQLITE_OK) {
542 // Histogram failures specific to initial open for debugging
543 // purposes.
544 UMA_HISTOGRAM_ENUMERATION("Sqlite.OpenFailure", err & 0xff, 50);
545
541 OnSqliteError(err, NULL); 546 OnSqliteError(err, NULL);
542 Close(); 547 Close();
543 db_ = NULL; 548 db_ = NULL;
544 return false; 549 return false;
545 } 550 }
546 551
552 // sqlite3_open() does not actually read the database file (unless a
553 // hot journal is found). Successfully executing this pragma on an
554 // existing database requires a valid header on page 1.
555 // TODO(shess): For now, just probing to see what the lay of the
556 // land is. If it's mostly SQLITE_NOTADB, then the database should
557 // be razed.
558 err = ExecuteAndReturnErrorCode("PRAGMA auto_vacuum");
559 if (err != SQLITE_OK)
560 UMA_HISTOGRAM_ENUMERATION("Sqlite.OpenProbeFailure", err & 0xff, 50);
561
547 // Enable extended result codes to provide more color on I/O errors. 562 // Enable extended result codes to provide more color on I/O errors.
548 // Not having extended result codes is not a fatal problem, as 563 // Not having extended result codes is not a fatal problem, as
549 // Chromium code does not attempt to handle I/O errors anyhow. The 564 // Chromium code does not attempt to handle I/O errors anyhow. The
550 // current implementation always returns SQLITE_OK, the DCHECK is to 565 // current implementation always returns SQLITE_OK, the DCHECK is to
551 // quickly notify someone if SQLite changes. 566 // quickly notify someone if SQLite changes.
552 err = sqlite3_extended_result_codes(db_, 1); 567 err = sqlite3_extended_result_codes(db_, 1);
553 DCHECK_EQ(err, SQLITE_OK) << "Could not enable extended result codes"; 568 DCHECK_EQ(err, SQLITE_OK) << "Could not enable extended result codes";
554 569
555 // If indicated, lock up the database before doing anything else, so 570 // If indicated, lock up the database before doing anything else, so
556 // that the following code doesn't have to deal with locking. 571 // that the following code doesn't have to deal with locking.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 654
640 int Connection::OnSqliteError(int err, sql::Statement *stmt) { 655 int Connection::OnSqliteError(int err, sql::Statement *stmt) {
641 if (error_delegate_.get()) 656 if (error_delegate_.get())
642 return error_delegate_->OnError(err, this, stmt); 657 return error_delegate_->OnError(err, this, stmt);
643 // The default handling is to assert on debug and to ignore on release. 658 // The default handling is to assert on debug and to ignore on release.
644 DLOG(FATAL) << GetErrorMessage(); 659 DLOG(FATAL) << GetErrorMessage();
645 return err; 660 return err;
646 } 661 }
647 662
648 } // namespace sql 663 } // namespace sql
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698