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

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: 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");
afakhry 2016/08/18 21:32:29 Shouldn't we use Execute() instead so that the err
Scott Hess - ex-Googler 2016/08/18 22:06:53 Sqlite.OpenProbeFailure tracks the specific SQLite
afakhry 2016/08/19 15:25:09 Oh yes, sorry, I didn't notice the OnSqliteError()
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, NULL, "PRAGMA auto_vacuum");
afakhry 2016/08/19 15:25:09 Nit: NULL --> nullptr.
Scott Hess - ex-Googler 2016/08/19 21:51:03 Done.
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.
1715 // TODO(shess): This code is brittle. Find the cases where code 1728 // TODO(shess): This code is brittle. Find the cases where code
1716 // doesn't request |exclusive_locking_| and audit that it does the 1729 // doesn't request |exclusive_locking_| and audit that it does the
1717 // right thing with SQLITE_BUSY, and that it doesn't make 1730 // right thing with SQLITE_BUSY, and that it doesn't make
1718 // assumptions about who might change things in the database. 1731 // assumptions about who might change things in the database.
1719 // http://crbug.com/56559 1732 // http://crbug.com/56559
1720 if (exclusive_locking_) { 1733 if (exclusive_locking_) {
1721 // TODO(shess): This should probably be a failure. Code which 1734 // TODO(shess): This should probably be a failure. Code which
1722 // requests exclusive locking but doesn't get it is almost certain 1735 // requests exclusive locking but doesn't get it is almost certain
1723 // to be ill-tested. 1736 // to be ill-tested.
1724 ignore_result(Execute("PRAGMA locking_mode=EXCLUSIVE")); 1737 ignore_result(Execute("PRAGMA locking_mode=EXCLUSIVE"));
1725 } 1738 }
1726 1739
1727 // http://www.sqlite.org/pragma.html#pragma_journal_mode 1740 // http://www.sqlite.org/pragma.html#pragma_journal_mode
1728 // DELETE (default) - delete -journal file to commit. 1741 // DELETE (default) - delete -journal file to commit.
1729 // TRUNCATE - truncate -journal file to commit. 1742 // TRUNCATE - truncate -journal file to commit.
1730 // PERSIST - zero out header of -journal file to commit. 1743 // PERSIST - zero out header of -journal file to commit.
1731 // TRUNCATE should be faster than DELETE because it won't need directory 1744 // TRUNCATE should be faster than DELETE because it won't need directory
1732 // changes for each transaction. PERSIST may break the spirit of using 1745 // changes for each transaction. PERSIST may break the spirit of using
1733 // secure_delete. 1746 // secure_delete.
1734 ignore_result(Execute("PRAGMA journal_mode = TRUNCATE")); 1747 ignore_result(Execute("PRAGMA journal_mode = TRUNCATE"));
afakhry 2016/08/18 21:32:29 Why retrying up there and not here?
Scott Hess - ex-Googler 2016/08/18 22:06:52 Any Execute() calls in between will cause poisoned
afakhry 2016/08/19 15:25:09 Makes sense. Thanks. Acknowledged.
1735 1748
1736 const base::TimeDelta kBusyTimeout = 1749 const base::TimeDelta kBusyTimeout =
1737 base::TimeDelta::FromSeconds(kBusyTimeoutSeconds); 1750 base::TimeDelta::FromSeconds(kBusyTimeoutSeconds);
1738 1751
1739 if (page_size_ != 0) { 1752 if (page_size_ != 0) {
1740 // Enforce SQLite restrictions on |page_size_|. 1753 // Enforce SQLite restrictions on |page_size_|.
1741 DCHECK(!(page_size_ & (page_size_ - 1))) 1754 DCHECK(!(page_size_ & (page_size_ - 1)))
1742 << " page_size_ " << page_size_ << " is not a power of two."; 1755 << " page_size_ " << page_size_ << " is not a power of two.";
1743 const int kSqliteMaxPageSize = 32768; // from sqliteLimit.h 1756 const int kSqliteMaxPageSize = 32768; // from sqliteLimit.h
1744 DCHECK_LE(page_size_, kSqliteMaxPageSize); 1757 DCHECK_LE(page_size_, kSqliteMaxPageSize);
(...skipping 229 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