Bug 1014988 - Use Context.MODE_ENABLE_WRITE_AHEAD_LOGGING when opening databases. r=bnicholson
authorRichard Newman <rnewman@mozilla.com>
Wed, 28 May 2014 14:53:59 -0700
changeset 185430 dc94e2a05c97b689a2473485f767d495d651b2bd
parent 185429 62b743e5a4f92332ac11eff9fcf4706230bbfb2b
child 185431 d675b7fc9a0b0c9a97630fbb38357af5316c1986
push id7025
push userrnewman@mozilla.com
push dateWed, 28 May 2014 21:54:12 +0000
treeherderfx-team@d675b7fc9a0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbnicholson
bugs1014988
milestone32.0a1
Bug 1014988 - Use Context.MODE_ENABLE_WRITE_AHEAD_LOGGING when opening databases. r=bnicholson
mobile/android/base/db/BrowserDatabaseHelper.java
mobile/android/base/db/PerProfileDatabaseProvider.java
mobile/android/base/db/SharedBrowserDatabaseProvider.java
mobile/android/base/db/TabsProvider.java
--- a/mobile/android/base/db/BrowserDatabaseHelper.java
+++ b/mobile/android/base/db/BrowserDatabaseHelper.java
@@ -1717,18 +1717,23 @@ final class BrowserDatabaseHelper extend
         } finally {
             if (cursor != null)
                 cursor.close();
         }
 
         // From Honeycomb on, it's possible to run several db
         // commands in parallel using multiple connections.
         if (Build.VERSION.SDK_INT >= 11) {
-            db.enableWriteAheadLogging();
-            db.setLockingEnabled(false);
+            // Modern Android allows WAL to be enabled through a mode flag.
+            if (Build.VERSION.SDK_INT < 16) {
+                db.enableWriteAheadLogging();
+
+                // This does nothing on 16+.
+                db.setLockingEnabled(false);
+            }
         } else {
             // Pre-Honeycomb, we can do some lesser optimizations.
             cursor = null;
             try {
                 cursor = db.rawQuery("PRAGMA journal_mode=PERSIST", null);
             } finally {
                 if (cursor != null)
                     cursor.close();
--- a/mobile/android/base/db/PerProfileDatabaseProvider.java
+++ b/mobile/android/base/db/PerProfileDatabaseProvider.java
@@ -3,16 +3,17 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.db;
 
 import org.mozilla.gecko.db.PerProfileDatabases.DatabaseHelperFactory;
 
 import android.content.Context;
 import android.database.sqlite.SQLiteOpenHelper;
+import android.os.Build;
 
 /**
  * Abstract class containing methods needed to make a SQLite-based content
  * provider with a database helper of type T, where one database helper is
  * held per profile.
  */
 public abstract class PerProfileDatabaseProvider<T extends SQLiteOpenHelper> extends AbstractPerProfileDatabaseProvider {
     private PerProfileDatabases<T> databases;
@@ -35,16 +36,20 @@ public abstract class PerProfileDatabase
 
     @Override
     public boolean onCreate() {
         synchronized (this) {
             databases = new PerProfileDatabases<T>(
                 getContext(), getDatabaseName(), new DatabaseHelperFactory<T>() {
                     @Override
                     public T makeDatabaseHelper(Context context, String databasePath) {
-                        return createDatabaseHelper(context, databasePath);
+                        final T helper = createDatabaseHelper(context, databasePath);
+                        if (Build.VERSION.SDK_INT >= 16) {
+                            helper.setWriteAheadLoggingEnabled(true);
+                        }
+                        return helper;
                     }
                 });
         }
 
         return true;
     }
 }
--- a/mobile/android/base/db/SharedBrowserDatabaseProvider.java
+++ b/mobile/android/base/db/SharedBrowserDatabaseProvider.java
@@ -7,16 +7,17 @@ package org.mozilla.gecko.db;
 import org.mozilla.gecko.db.BrowserContract.CommonColumns;
 import org.mozilla.gecko.db.BrowserContract.SyncColumns;
 import org.mozilla.gecko.db.PerProfileDatabases.DatabaseHelperFactory;
 
 import android.content.Context;
 import android.database.Cursor;
 import android.database.sqlite.SQLiteDatabase;
 import android.net.Uri;
+import android.os.Build;
 import android.util.Log;
 
 /**
  * A ContentProvider subclass that provides per-profile browser.db access
  * that can be safely shared between multiple providers.
  *
  * If multiple ContentProvider classes wish to share a database, it's
  * vitally important that they use the same SQLiteOpenHelpers for access.
@@ -43,17 +44,21 @@ public abstract class SharedBrowserDatab
         synchronized (SharedBrowserDatabaseProvider.class) {
             if (databases != null) {
                 return true;
             }
 
             final DatabaseHelperFactory<BrowserDatabaseHelper> helperFactory = new DatabaseHelperFactory<BrowserDatabaseHelper>() {
                 @Override
                 public BrowserDatabaseHelper makeDatabaseHelper(Context context, String databasePath) {
-                    return new BrowserDatabaseHelper(context, databasePath);
+                    final BrowserDatabaseHelper helper = new BrowserDatabaseHelper(context, databasePath);
+                    if (Build.VERSION.SDK_INT >= 16) {
+                        helper.setWriteAheadLoggingEnabled(true);
+                    }
+                    return helper;
                 }
             };
 
             databases = new PerProfileDatabases<BrowserDatabaseHelper>(getContext(), BrowserDatabaseHelper.DATABASE_NAME, helperFactory);
         }
 
         return true;
     }
--- a/mobile/android/base/db/TabsProvider.java
+++ b/mobile/android/base/db/TabsProvider.java
@@ -15,16 +15,17 @@ import android.content.ContentUris;
 import android.content.ContentValues;
 import android.content.Context;
 import android.content.UriMatcher;
 import android.database.Cursor;
 import android.database.sqlite.SQLiteDatabase;
 import android.database.sqlite.SQLiteOpenHelper;
 import android.database.sqlite.SQLiteQueryBuilder;
 import android.net.Uri;
+import android.os.Build;
 import android.text.TextUtils;
 
 public class TabsProvider extends PerProfileDatabaseProvider<TabsProvider.TabsDatabaseHelper> {
     static final String DATABASE_NAME = "tabs.db";
 
     static final int DATABASE_VERSION = 2;
 
     static final String TABLE_TABS = "tabs";
@@ -149,17 +150,20 @@ public class TabsProvider extends PerPro
         }
 
         @Override
         public void onOpen(SQLiteDatabase db) {
             debug("Opening tabs.db: " + db.getPath());
             db.rawQuery("PRAGMA synchronous=OFF", null).close();
 
             if (shouldUseTransactions()) {
-                db.enableWriteAheadLogging();
+                // Modern Android allows WAL to be enabled through a mode flag.
+                if (Build.VERSION.SDK_INT < 16) {
+                    db.enableWriteAheadLogging();
+                }
                 db.setLockingEnabled(false);
                 return;
             }
 
             // If we're not using transactions (in particular, prior to
             // Honeycomb), then we can do some lesser optimizations.
             db.rawQuery("PRAGMA journal_mode=PERSIST", null).close();
         }