[sql] Consider fresh databases suitable for memory-mapped I/O.
GetAppropriateMmapSize() is called to validate the database as
error-free before enabling memory-mapped mode. The validation status is
stored in the [meta] table, since new databases have no [meta] table it
previously defaulted to not turning on memory-mapping. Then on second
open the file would be validated.
This change uses the lack of [meta] table as a signal that the file is
new and should be safe to memory-map. Additionally the code creating
[meta] pre-populates that setting.
Additionally disable memory-mapped mode for databases which do not make
use of the [meta] table. This makes the existing settings explicit.
BUG=537742, 555578
[email protected], [email protected], [email protected], [email protected]
Review URL: https://codereview.chromium.org/1533703002
Cr-Commit-Position: refs/heads/master@{#365959}
diff --git a/sql/meta_table.h b/sql/meta_table.h
index 0ae76bd..85c0c82 100644
--- a/sql/meta_table.h
+++ b/sql/meta_table.h
@@ -21,6 +21,13 @@
MetaTable();
~MetaTable();
+ // Values for Get/SetMmapStatus(). |kMmapFailure| indicates that there was at
+ // some point a read error and the database should not be memory-mapped, while
+ // |kMmapSuccess| indicates that the entire file was read at some point and
+ // can be memory-mapped without constraint.
+ static int64_t kMmapFailure;
+ static int64_t kMmapSuccess;
+
// Returns true if the 'meta' table exists.
static bool DoesTableExist(Connection* db);
@@ -38,10 +45,18 @@
// transaction.
static void RazeIfDeprecated(Connection* db, int deprecated_version);
+ // Used to tuck some data into the meta table about mmap status. The value
+ // represents how much data in bytes has successfully been read from the
+ // database, or |kMmapFailure| or |kMmapSuccess|.
+ static bool GetMmapStatus(Connection* db, int64_t* status);
+ static bool SetMmapStatus(Connection* db, int64_t status);
+
// Initializes the MetaTableHelper, creating the meta table if necessary. For
// new tables, it will initialize the version number to |version| and the
// compatible version number to |compatible_version|. Versions must be
// greater than 0 to distinguish missing versions (see GetVersionNumber()).
+ // If there was no meta table (proxy for a fresh database), mmap status is set
+ // to |kMmapSuccess|.
bool Init(Connection* db, int version, int compatible_version);
// Resets this MetaTable object, making another call to Init() possible.