OLD | NEW |
---|---|
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/bind.h" | 9 #include "base/bind.h" |
10 #include "base/debug/dump_without_crashing.h" | 10 #include "base/debug/dump_without_crashing.h" |
(...skipping 1610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1621 | 1621 |
1622 // http://www.sqlite.org/pragma.html#pragma_journal_mode | 1622 // http://www.sqlite.org/pragma.html#pragma_journal_mode |
1623 // DELETE (default) - delete -journal file to commit. | 1623 // DELETE (default) - delete -journal file to commit. |
1624 // TRUNCATE - truncate -journal file to commit. | 1624 // TRUNCATE - truncate -journal file to commit. |
1625 // PERSIST - zero out header of -journal file to commit. | 1625 // PERSIST - zero out header of -journal file to commit. |
1626 // TRUNCATE should be faster than DELETE because it won't need directory | 1626 // TRUNCATE should be faster than DELETE because it won't need directory |
1627 // changes for each transaction. PERSIST may break the spirit of using | 1627 // changes for each transaction. PERSIST may break the spirit of using |
1628 // secure_delete. | 1628 // secure_delete. |
1629 ignore_result(Execute("PRAGMA journal_mode = TRUNCATE")); | 1629 ignore_result(Execute("PRAGMA journal_mode = TRUNCATE")); |
1630 | 1630 |
1631 // Enable memory-mapped access. This value will be capped by | |
1632 // SQLITE_MAX_MMAP_SIZE, which could be different between 32-bit and 64-bit | |
1633 // platforms. | |
1634 mmap_enabled_ = false; | |
1635 if (!mmap_disabled_) | |
1636 ignore_result(Execute("PRAGMA mmap_size = 268435456")); // 256MB. | |
1637 { | |
1638 Statement s(GetUniqueStatement("PRAGMA mmap_size")); | |
1639 if (s.Step() && s.ColumnInt64(0) > 0) | |
1640 mmap_enabled_ = true; | |
1641 } | |
1642 | |
1643 const base::TimeDelta kBusyTimeout = | 1631 const base::TimeDelta kBusyTimeout = |
1644 base::TimeDelta::FromSeconds(kBusyTimeoutSeconds); | 1632 base::TimeDelta::FromSeconds(kBusyTimeoutSeconds); |
1645 | 1633 |
1646 if (page_size_ != 0) { | 1634 if (page_size_ != 0) { |
1647 // Enforce SQLite restrictions on |page_size_|. | 1635 // Enforce SQLite restrictions on |page_size_|. |
1648 DCHECK(!(page_size_ & (page_size_ - 1))) | 1636 DCHECK(!(page_size_ & (page_size_ - 1))) |
1649 << " page_size_ " << page_size_ << " is not a power of two."; | 1637 << " page_size_ " << page_size_ << " is not a power of two."; |
1650 const int kSqliteMaxPageSize = 32768; // from sqliteLimit.h | 1638 const int kSqliteMaxPageSize = 32768; // from sqliteLimit.h |
1651 DCHECK_LE(page_size_, kSqliteMaxPageSize); | 1639 DCHECK_LE(page_size_, kSqliteMaxPageSize); |
1652 const std::string sql = | 1640 const std::string sql = |
1653 base::StringPrintf("PRAGMA page_size=%d", page_size_); | 1641 base::StringPrintf("PRAGMA page_size=%d", page_size_); |
1654 ignore_result(ExecuteWithTimeout(sql.c_str(), kBusyTimeout)); | 1642 ignore_result(ExecuteWithTimeout(sql.c_str(), kBusyTimeout)); |
1655 } | 1643 } |
1656 | 1644 |
1657 if (cache_size_ != 0) { | 1645 if (cache_size_ != 0) { |
1658 const std::string sql = | 1646 const std::string sql = |
1659 base::StringPrintf("PRAGMA cache_size=%d", cache_size_); | 1647 base::StringPrintf("PRAGMA cache_size=%d", cache_size_); |
1660 ignore_result(ExecuteWithTimeout(sql.c_str(), kBusyTimeout)); | 1648 ignore_result(ExecuteWithTimeout(sql.c_str(), kBusyTimeout)); |
1661 } | 1649 } |
1662 | 1650 |
1663 if (!ExecuteWithTimeout("PRAGMA secure_delete=ON", kBusyTimeout)) { | 1651 if (!ExecuteWithTimeout("PRAGMA secure_delete=ON", kBusyTimeout)) { |
1664 bool was_poisoned = poisoned_; | 1652 bool was_poisoned = poisoned_; |
1665 Close(); | 1653 Close(); |
1666 if (was_poisoned && retry_flag == RETRY_ON_POISON) | 1654 if (was_poisoned && retry_flag == RETRY_ON_POISON) |
1667 return OpenInternal(file_name, NO_RETRY); | 1655 return OpenInternal(file_name, NO_RETRY); |
1668 return false; | 1656 return false; |
1669 } | 1657 } |
1670 | 1658 |
1659 // Enable memory-mapped access. The explicit-disable case is because SQLite | |
1660 // can be built to default-enable mmap. This value will be capped by | |
1661 // SQLITE_MAX_MMAP_SIZE, which could be different between 32-bit and 64-bit | |
1662 // platforms. | |
1663 if (mmap_disabled_) { | |
1664 ignore_result(Execute("PRAGMA mmap_size = 0")); | |
1665 } else { | |
1666 ignore_result(Execute("PRAGMA mmap_size = 268435456")); // 256MB. | |
1667 } | |
1668 | |
1669 // Determine if memory-mapping has actually been enabled. The Execute() above | |
1670 // can succeed without changing the amount mapped. | |
1671 mmap_enabled_ = false; | |
1672 { | |
1673 Statement s(GetUniqueStatement("PRAGMA mmap_size")); | |
1674 if (s.Step() && s.ColumnInt64(0) > 0) | |
1675 mmap_enabled_ = true; | |
1676 } | |
1677 | |
Scott Hess - ex-Googler
2015/11/04 23:36:42
Hmm, and I moved the stanza down here because it s
| |
1671 return true; | 1678 return true; |
1672 } | 1679 } |
1673 | 1680 |
1674 void Connection::DoRollback() { | 1681 void Connection::DoRollback() { |
1675 Statement rollback(GetCachedStatement(SQL_FROM_HERE, "ROLLBACK")); | 1682 Statement rollback(GetCachedStatement(SQL_FROM_HERE, "ROLLBACK")); |
1676 | 1683 |
1677 // Collect the rollback time manually, sql::Statement would register it as | 1684 // Collect the rollback time manually, sql::Statement would register it as |
1678 // query time only. | 1685 // query time only. |
1679 const base::TimeTicks before = Now(); | 1686 const base::TimeTicks before = Now(); |
1680 rollback.RunWithoutTimers(); | 1687 rollback.RunWithoutTimers(); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1800 ignore_result(Execute(kNoWritableSchema)); | 1807 ignore_result(Execute(kNoWritableSchema)); |
1801 | 1808 |
1802 return ret; | 1809 return ret; |
1803 } | 1810 } |
1804 | 1811 |
1805 base::TimeTicks TimeSource::Now() { | 1812 base::TimeTicks TimeSource::Now() { |
1806 return base::TimeTicks::Now(); | 1813 return base::TimeTicks::Now(); |
1807 } | 1814 } |
1808 | 1815 |
1809 } // namespace sql | 1816 } // namespace sql |
OLD | NEW |