Bug 1162342 Enable sqlite WAL transactions in Cache API. r=ehsan
authorBen Kelly <ben@wanderview.com>
Wed, 13 May 2015 17:55:48 -0700
changeset 243775 c2020109ebd04e6f6e6be9925eb1a29746ae6540
parent 243774 cafa8c19cc6336f05aa2d9b022e1f7cc627a862f
child 243776 a1f7ae44c7bb8c2cc49ba5728a6f6a41898f4c99
push id28753
push userkwierso@gmail.com
push dateThu, 14 May 2015 22:33:43 +0000
treeherdermozilla-central@07e2e15703cb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1162342
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1162342 Enable sqlite WAL transactions in Cache API. r=ehsan
dom/cache/DBAction.cpp
dom/cache/DBSchema.cpp
--- a/dom/cache/DBAction.cpp
+++ b/dom/cache/DBAction.cpp
@@ -182,16 +182,19 @@ DBAction::OpenConnection(const QuotaInfo
 }
 
 nsresult
 DBAction::WipeDatabase(nsIFile* aDBFile, nsIFile* aDBDir)
 {
   nsresult rv = aDBFile->Remove(false);
   if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
 
+  // Note, the -wal journal file will be automatically deleted by sqlite when
+  // the new database is created.  No need to explicitly delete it here.
+
   // Delete the morgue as well.
   rv = BodyDeleteDir(aDBDir);
   if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
 
   return rv;
 }
 
 SyncDBAction::SyncDBAction(Mode aMode)
--- a/dom/cache/DBSchema.cpp
+++ b/dom/cache/DBSchema.cpp
@@ -23,21 +23,21 @@
 #include "mozilla/dom/ResponseBinding.h"
 #include "nsIContentPolicy.h"
 
 namespace mozilla {
 namespace dom {
 namespace cache {
 namespace db {
 
-const int32_t kMaxWipeSchemaVersion = 7;
+const int32_t kMaxWipeSchemaVersion = 8;
 
 namespace {
 
-const int32_t kLatestSchemaVersion = 7;
+const int32_t kLatestSchemaVersion = 8;
 const int32_t kMaxEntriesPerStatement = 255;
 
 } // anonymous namespace
 
 // If any of the static_asserts below fail, it means that you have changed
 // the corresponding WebIDL enum in a way that may be incompatible with the
 // existing data stored in the DOM Cache.  You would need to update the Cache
 // database schema accordingly and adjust the failing static_assert.
@@ -338,22 +338,22 @@ InitializeConnection(mozIStorageConnecti
 {
   MOZ_ASSERT(!NS_IsMainThread());
   MOZ_ASSERT(aConn);
 
   // This function needs to perform per-connection initialization tasks that
   // need to happen regardless of the schema.
 
   nsAutoCString pragmas(
-#if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_GONK)
-    // Switch the journaling mode to TRUNCATE to avoid changing the directory
-    // structure at the conclusion of every transaction for devices with slower
-    // file systems.
-    "PRAGMA journal_mode = TRUNCATE; "
-#endif
+    "PRAGMA journal_mode = WAL; "
+    // Use default mozStorage 32kb page size for now
+    // WAL journal can grow to 512kb before being flushed to disk
+    "PRAGMA wal_autocheckpoint = 16; "
+    // Always truncate the journal back to 512kb after large transactions
+    "PRAGMA journal_size_limit = 524288; "
     "PRAGMA foreign_keys = ON; "
 
     // Note, the default encoding of UTF-8 is preferred.  mozStorage does all
     // the work necessary to convert UTF-16 nsString values for us.  We don't
     // need ordering and the binary equality operations are correct.  So, do
     // NOT set PRAGMA encoding to UTF-16.
   );