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

Side by Side Diff: sql/connection.cc

Issue 2258703004: [sql] Retry post-poison open as soon as possible. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nullptr Created 4 years, 4 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 | « 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 <limits.h> 7 #include <limits.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <string.h> 10 #include <string.h>
(...skipping 1675 matching lines...) Expand 10 before | Expand all | Expand 10 after
1686 sqlite3_db_config(db_, SQLITE_DBCONFIG_LOOKASIDE, NULL, 0, 0); 1686 sqlite3_db_config(db_, SQLITE_DBCONFIG_LOOKASIDE, NULL, 0, 0);
1687 1687
1688 // Enable extended result codes to provide more color on I/O errors. 1688 // Enable extended result codes to provide more color on I/O errors.
1689 // Not having extended result codes is not a fatal problem, as 1689 // Not having extended result codes is not a fatal problem, as
1690 // Chromium code does not attempt to handle I/O errors anyhow. The 1690 // Chromium code does not attempt to handle I/O errors anyhow. The
1691 // current implementation always returns SQLITE_OK, the DCHECK is to 1691 // current implementation always returns SQLITE_OK, the DCHECK is to
1692 // quickly notify someone if SQLite changes. 1692 // quickly notify someone if SQLite changes.
1693 err = sqlite3_extended_result_codes(db_, 1); 1693 err = sqlite3_extended_result_codes(db_, 1);
1694 DCHECK_EQ(err, SQLITE_OK) << "Could not enable extended result codes"; 1694 DCHECK_EQ(err, SQLITE_OK) << "Could not enable extended result codes";
1695 1695
1696 // sqlite3_open() does not actually read the database file (unless a 1696 // sqlite3_open() does not actually read the database file (unless a hot
1697 // hot journal is found). Successfully executing this pragma on an 1697 // journal is found). Successfully executing this pragma on an existing
1698 // existing database requires a valid header on page 1. 1698 // database requires a valid header on page 1. ExecuteAndReturnErrorCode() to
1699 // get the error code before error callback (potentially) overwrites.
1699 // TODO(shess): For now, just probing to see what the lay of the 1700 // TODO(shess): For now, just probing to see what the lay of the
1700 // land is. If it's mostly SQLITE_NOTADB, then the database should 1701 // land is. If it's mostly SQLITE_NOTADB, then the database should
1701 // be razed. 1702 // be razed.
1702 err = ExecuteAndReturnErrorCode("PRAGMA auto_vacuum"); 1703 err = ExecuteAndReturnErrorCode("PRAGMA auto_vacuum");
1703 if (err != SQLITE_OK) 1704 if (err != SQLITE_OK) {
1704 UMA_HISTOGRAM_SPARSE_SLOWLY("Sqlite.OpenProbeFailure", err); 1705 UMA_HISTOGRAM_SPARSE_SLOWLY("Sqlite.OpenProbeFailure", err);
1706 OnSqliteError(err, nullptr, "PRAGMA auto_vacuum");
1707
1708 // Retry or bail out if the error handler poisoned the handle.
1709 // TODO(shess): Move this handling to one place (see also sqlite3_open and
1710 // secure_delete). Possibly a wrapper function?
1711 if (poisoned_) {
1712 Close();
1713 if (retry_flag == RETRY_ON_POISON)
1714 return OpenInternal(file_name, NO_RETRY);
1715 return false;
1716 }
1717 }
1705 1718
1706 #if defined(OS_IOS) && defined(USE_SYSTEM_SQLITE) 1719 #if defined(OS_IOS) && defined(USE_SYSTEM_SQLITE)
1707 // The version of SQLite shipped with iOS doesn't enable ICU, which includes 1720 // The version of SQLite shipped with iOS doesn't enable ICU, which includes
1708 // REGEXP support. Add it in dynamically. 1721 // REGEXP support. Add it in dynamically.
1709 err = sqlite3IcuInit(db_); 1722 err = sqlite3IcuInit(db_);
1710 DCHECK_EQ(err, SQLITE_OK) << "Could not enable ICU support"; 1723 DCHECK_EQ(err, SQLITE_OK) << "Could not enable ICU support";
1711 #endif // OS_IOS && USE_SYSTEM_SQLITE 1724 #endif // OS_IOS && USE_SYSTEM_SQLITE
1712 1725
1713 // If indicated, lock up the database before doing anything else, so 1726 // If indicated, lock up the database before doing anything else, so
1714 // that the following code doesn't have to deal with locking. 1727 // that the following code doesn't have to deal with locking.
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
1974 ignore_result(Execute(kNoWritableSchema)); 1987 ignore_result(Execute(kNoWritableSchema));
1975 1988
1976 return ret; 1989 return ret;
1977 } 1990 }
1978 1991
1979 base::TimeTicks TimeSource::Now() { 1992 base::TimeTicks TimeSource::Now() {
1980 return base::TimeTicks::Now(); 1993 return base::TimeTicks::Now();
1981 } 1994 }
1982 1995
1983 } // namespace sql 1996 } // 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