summaryrefslogtreecommitdiffstats
path: root/sql/connection.h
diff options
context:
space:
mode:
authorshess <shess@chromium.org>2015-11-12 18:24:31 -0800
committerCommit bot <commit-bot@chromium.org>2015-11-13 02:25:28 +0000
commitd90aeea87619c019f8b4be171b65476748868ece (patch)
tree99a05a0c61b68d2fe2f2119ae80ab698dac35bdd /sql/connection.h
parentcc5ac2aca0c601c848b6dc356f949ff3ec0a6194 (diff)
downloadchromium_src-d90aeea87619c019f8b4be171b65476748868ece.zip
chromium_src-d90aeea87619c019f8b4be171b65476748868ece.tar.gz
chromium_src-d90aeea87619c019f8b4be171b65476748868ece.tar.bz2
[sql] Validate database files before enabling memory-mapping.
With regular I/O, filesystem corruption would cause SQLite to return SQLITE_IOERR codes. With memory-mapping, filesystem errors can cause a crash when accessed. There are databases with filesystem corruption, this CL only enables memory-mapped I/O for parts of the database which have been successfully read at some point using regular I/O. [Relands https://codereview.chromium.org/1426743006 which was reverted at https://codereview.chromium.org/1432953002 . CL is identical, fix to sql::Connection was landed at https://codereview.chromium.org/1426743006 .] BUG=537742 TBR=rmcilroy@chromium.org, isherman+reviewer@chromium.org Review URL: https://codereview.chromium.org/1442753004 Cr-Commit-Position: refs/heads/master@{#359478}
Diffstat (limited to 'sql/connection.h')
-rw-r--r--sql/connection.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/sql/connection.h b/sql/connection.h
index 5b219db..18b2cb7 100644
--- a/sql/connection.h
+++ b/sql/connection.h
@@ -204,6 +204,19 @@ class SQL_EXPORT Connection : public base::trace_event::MemoryDumpProvider {
EVENT_COMMIT,
EVENT_ROLLBACK,
+ // Track success and failure in GetAppropriateMmapSize().
+ // GetAppropriateMmapSize() should record at most one of these per run. The
+ // case of mapping everything is not recorded.
+ EVENT_MMAP_META_MISSING, // No meta table present.
+ EVENT_MMAP_META_FAILURE_READ, // Failed reading meta table.
+ EVENT_MMAP_META_FAILURE_UPDATE, // Failed updating meta table.
+ EVENT_MMAP_VFS_FAILURE, // Failed to access VFS.
+ EVENT_MMAP_FAILED, // Failure from past run.
+ EVENT_MMAP_FAILED_NEW, // Read error in this run.
+ EVENT_MMAP_SUCCESS_NEW, // Read to EOF in this run.
+ EVENT_MMAP_SUCCESS_PARTIAL, // Read but did not reach EOF.
+ EVENT_MMAP_SUCCESS_NO_PROGRESS, // Read quota exhausted.
+
// Leave this at the end.
// TODO(shess): |EVENT_MAX| causes compile fail on Windows.
EVENT_MAX_VALUE
@@ -693,6 +706,16 @@ class SQL_EXPORT Connection : public base::trace_event::MemoryDumpProvider {
// Helper to collect diagnostic info for errors.
std::string CollectErrorInfo(int error, Statement* stmt) const;
+ // Calculates a value appropriate to pass to "PRAGMA mmap_size = ". So errors
+ // can make it unsafe to map a file, so the file is read using regular I/O,
+ // with any errors causing 0 (don't map anything) to be returned. If the
+ // entire file is read without error, a large value is returned which will
+ // allow the entire file to be mapped in most cases.
+ //
+ // Results are recorded in the database's meta table for future reference, so
+ // the file should only be read through once.
+ size_t GetAppropriateMmapSize();
+
// The actual sqlite database. Will be NULL before Init has been called or if
// Init resulted in an error.
sqlite3* db_;