summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/java/android/database/sqlite/SQLiteConnection.java25
-rw-r--r--core/java/android/database/sqlite/SQLiteDatabase.java2
-rw-r--r--core/java/android/database/sqlite/SQLiteDatabaseConfiguration.java9
-rw-r--r--core/java/android/database/sqlite/SQLiteGlobal.java16
-rwxr-xr-xcore/res/res/values/config.xml15
-rw-r--r--core/res/res/values/public.xml3
6 files changed, 54 insertions, 16 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(
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index be43513..eaf9c8c 100755
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -661,9 +661,20 @@
truncate it after committing the transaction. -->
<integer name="db_journal_size_limit">524288</integer>
- <!-- The database synchronization mode.
+ <!-- The database synchronization mode when using the default journal mode.
+ FULL is safest and preserves durability at the cost of extra fsyncs.
+ NORMAL also preserves durability in non-WAL modes and uses checksums to ensure
+ integrity although there is a small chance that an error might go unnoticed.
Choices are: FULL, NORMAL, OFF. -->
- <string name="db_sync_mode">FULL</string>
+ <string name="db_default_sync_mode">FULL</string>
+
+ <!-- The database synchronization mode when using Write-Ahead Logging.
+ FULL is safest and preserves durability at the cost of extra fsyncs.
+ NORMAL sacrifices durability in WAL mode because syncs are only performed before
+ and after checkpoint operations. If checkpoints are infrequent and power loss
+ occurs, then committed transactions could be lost and applications might break.
+ Choices are: FULL, NORMAL, OFF. -->
+ <string name="db_wal_sync_mode">FULL</string>
<!-- The Write-Ahead Log auto-checkpoint interval in database pages (typically 1 to 4KB).
The log is checkpointed automatically whenever it exceeds this many pages.
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index 2c80fb7..f87e155 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -441,7 +441,8 @@
<java-symbol type="string" name="day_of_week_shortest_tuesday" />
<java-symbol type="string" name="day_of_week_shortest_wednesday" />
<java-symbol type="string" name="db_default_journal_mode" />
- <java-symbol type="string" name="db_sync_mode" />
+ <java-symbol type="string" name="db_default_sync_mode" />
+ <java-symbol type="string" name="db_wal_sync_mode" />
<java-symbol type="string" name="decline" />
<java-symbol type="string" name="default_permission_group" />
<java-symbol type="string" name="default_text_encoding" />