diff options
author | Jeff Brown <jeffbrown@google.com> | 2012-03-02 10:33:52 -0800 |
---|---|---|
committer | Jeff Brown <jeffbrown@google.com> | 2012-03-02 11:17:16 -0800 |
commit | 8dc3cc2e13b500e368f5ba1aacfaf0eddbce668c (patch) | |
tree | 6abe2b6b52d1ae6a749d17f7664e84b3f5595eff /core/java | |
parent | 24dc6aa03eaa63c75d1dfb4872850735f8c76963 (diff) | |
download | frameworks_base-8dc3cc2e13b500e368f5ba1aacfaf0eddbce668c.zip frameworks_base-8dc3cc2e13b500e368f5ba1aacfaf0eddbce668c.tar.gz frameworks_base-8dc3cc2e13b500e368f5ba1aacfaf0eddbce668c.tar.bz2 |
Allow the SQLite sync mode to be set independently for WAL.
This change leaves the sync mode at FULL for both WAL and non-WAL
but makes it easy to change it for one but not the other.
To reduce the number of synchronous writes, it might make sense to
change the sync mode for non-WAL to NORMAL instead of FULL which
should be just as safe.
On the other hand, the sync mode for WAL should probably remain FULL
because there may be an impact on transaction durability otherwise.
Initial experiments show that there might not be a significant
performance benefit to using NORMAL, but we may revisit this later.
Change-Id: Ifcd55bedcfefa6600974c2295ca5d4163b408cbf
Diffstat (limited to 'core/java')
4 files changed, 39 insertions, 13 deletions
diff --git a/core/java/android/database/sqlite/SQLiteConnection.java b/core/java/android/database/sqlite/SQLiteConnection.java index 1900301..d16f29f 100644 --- a/core/java/android/database/sqlite/SQLiteConnection.java +++ b/core/java/android/database/sqlite/SQLiteConnection.java @@ -208,11 +208,11 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen mConfiguration.label, SQLiteDebug.DEBUG_SQL_STATEMENTS, SQLiteDebug.DEBUG_SQL_TIME); - setSyncMode(); setPageSize(); - setAutoCheckpointInterval(); - setJournalSizeLimit(); + setSyncModeFromConfiguration(); setJournalModeFromConfiguration(); + setJournalSizeLimit(); + setAutoCheckpointInterval(); setLocaleFromConfiguration(); } @@ -236,12 +236,6 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen } } - private void setSyncMode() { - if (!mConfiguration.isInMemoryDb()) { - execute("PRAGMA synchronous=" + SQLiteGlobal.getSyncMode(), null, null); - } - } - private void setPageSize() { if (!mConfiguration.isInMemoryDb()) { execute("PRAGMA page_size=" + SQLiteGlobal.getDefaultPageSize(), null, null); @@ -262,6 +256,12 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen } } + private void setSyncModeFromConfiguration() { + if (!mConfiguration.isInMemoryDb()) { + execute("PRAGMA synchronous=" + mConfiguration.syncMode, null, null); + } + } + private void setJournalModeFromConfiguration() { if (!mConfiguration.isInMemoryDb()) { String result = executeForString("PRAGMA journal_mode=" + mConfiguration.journalMode, @@ -290,6 +290,8 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen } // Remember what changed. + boolean syncModeChanged = !configuration.syncMode.equalsIgnoreCase( + mConfiguration.syncMode); boolean journalModeChanged = !configuration.journalMode.equalsIgnoreCase( mConfiguration.journalMode); boolean localeChanged = !configuration.locale.equals(mConfiguration.locale); @@ -300,6 +302,11 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen // Update prepared statement cache size. mPreparedStatementCache.resize(configuration.maxSqlCacheSize); + // Update sync mode. + if (syncModeChanged) { + setSyncModeFromConfiguration(); + } + // Update journal mode. if (journalModeChanged) { setJournalModeFromConfiguration(); diff --git a/core/java/android/database/sqlite/SQLiteDatabase.java b/core/java/android/database/sqlite/SQLiteDatabase.java index 2f3dc06..04ee142 100644 --- a/core/java/android/database/sqlite/SQLiteDatabase.java +++ b/core/java/android/database/sqlite/SQLiteDatabase.java @@ -1781,6 +1781,7 @@ public class SQLiteDatabase extends SQLiteClosable { mIsWALEnabledLocked = true; mConfigurationLocked.maxConnectionPoolSize = SQLiteGlobal.getWALConnectionPoolSize(); + mConfigurationLocked.syncMode = SQLiteGlobal.getWALSyncMode(); mConfigurationLocked.journalMode = "WAL"; mConnectionPoolLocked.reconfigure(mConfigurationLocked); } @@ -1801,6 +1802,7 @@ public class SQLiteDatabase extends SQLiteClosable { mIsWALEnabledLocked = false; mConfigurationLocked.maxConnectionPoolSize = 1; + mConfigurationLocked.syncMode = SQLiteGlobal.getDefaultSyncMode(); mConfigurationLocked.journalMode = SQLiteGlobal.getDefaultJournalMode(); mConnectionPoolLocked.reconfigure(mConfigurationLocked); } diff --git a/core/java/android/database/sqlite/SQLiteDatabaseConfiguration.java b/core/java/android/database/sqlite/SQLiteDatabaseConfiguration.java index 32a1bcb..efbcaca 100644 --- a/core/java/android/database/sqlite/SQLiteDatabaseConfiguration.java +++ b/core/java/android/database/sqlite/SQLiteDatabaseConfiguration.java @@ -85,6 +85,13 @@ public final class SQLiteDatabaseConfiguration { public Locale locale; /** + * The database synchronization mode. + * + * Default is {@link SQLiteGlobal#getDefaultSyncMode()}. + */ + public String syncMode; + + /** * The database journal mode. * * Default is {@link SQLiteGlobal#getDefaultJournalMode()}. @@ -117,6 +124,7 @@ public final class SQLiteDatabaseConfiguration { maxConnectionPoolSize = 1; maxSqlCacheSize = 25; locale = Locale.getDefault(); + syncMode = SQLiteGlobal.getDefaultSyncMode(); journalMode = SQLiteGlobal.getDefaultJournalMode(); } @@ -154,6 +162,7 @@ public final class SQLiteDatabaseConfiguration { maxConnectionPoolSize = other.maxConnectionPoolSize; maxSqlCacheSize = other.maxSqlCacheSize; locale = other.locale; + syncMode = other.syncMode; journalMode = other.journalMode; customFunctions.clear(); customFunctions.addAll(other.customFunctions); diff --git a/core/java/android/database/sqlite/SQLiteGlobal.java b/core/java/android/database/sqlite/SQLiteGlobal.java index af0cf45..5d8f80e 100644 --- a/core/java/android/database/sqlite/SQLiteGlobal.java +++ b/core/java/android/database/sqlite/SQLiteGlobal.java @@ -83,11 +83,19 @@ public final class SQLiteGlobal { } /** - * Gets the database synchronization mode. + * Gets the default database synchronization mode when WAL is not in use. */ - public static String getSyncMode() { + public static String getDefaultSyncMode() { return Resources.getSystem().getString( - com.android.internal.R.string.db_sync_mode); + com.android.internal.R.string.db_default_sync_mode); + } + + /** + * Gets the database synchronization mode when in WAL mode. + */ + public static String getWALSyncMode() { + return Resources.getSystem().getString( + com.android.internal.R.string.db_wal_sync_mode); } /** @@ -99,7 +107,7 @@ public final class SQLiteGlobal { } /** - * Gets the default connection pool size when in WAL mode. + * Gets the connection pool size when in WAL mode. */ public static int getWALConnectionPoolSize() { return Math.max(2, Resources.getSystem().getInteger( |