Bug 1162342 - Enable sqlite WAL transactions in Cache API. r=ehsan, a=lizzard
authorBen Kelly <ben@wanderview.com>
Wed, 13 May 2015 17:55:48 -0700
changeset 274686 3008cae3f7c248e3da4b2f8c43c7e63b2e919c15
parent 274685 d3cbac8dbfeb6325c7e4761f62262602850af2d1
child 274687 d5fbc61783e40e127c15647c47bda58235803a4f
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan, lizzard
bugs1162342
milestone40.0a2
Bug 1162342 - Enable sqlite WAL transactions in Cache API. r=ehsan, a=lizzard
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.
   );