Merge "Introduced DISABLE_COMPATIBILITY_WAL flag" into pi-dev am: 8de43e93cd
am: c6e158d790
Change-Id: I24a1f8481e0163bdbff7883eff9a72af78513ab3
This commit is contained in:
@@ -292,8 +292,10 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen
|
||||
final boolean walEnabled =
|
||||
(mConfiguration.openFlags & SQLiteDatabase.ENABLE_WRITE_AHEAD_LOGGING) != 0;
|
||||
// Use compatibility WAL unless an app explicitly set journal/synchronous mode
|
||||
// or DISABLE_COMPATIBILITY_WAL flag is set
|
||||
final boolean useCompatibilityWal = mConfiguration.journalMode == null
|
||||
&& mConfiguration.syncMode == null && mConfiguration.useCompatibilityWal;
|
||||
&& mConfiguration.syncMode == null
|
||||
&& (mConfiguration.openFlags & SQLiteDatabase.DISABLE_COMPATIBILITY_WAL) == 0;
|
||||
if (walEnabled || useCompatibilityWal) {
|
||||
setJournalMode("WAL");
|
||||
if (useCompatibilityWal && SQLiteCompatibilityWalFlags.areFlagsSet()) {
|
||||
@@ -423,8 +425,8 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen
|
||||
boolean foreignKeyModeChanged = configuration.foreignKeyConstraintsEnabled
|
||||
!= mConfiguration.foreignKeyConstraintsEnabled;
|
||||
boolean walModeChanged = ((configuration.openFlags ^ mConfiguration.openFlags)
|
||||
& SQLiteDatabase.ENABLE_WRITE_AHEAD_LOGGING) != 0
|
||||
|| configuration.useCompatibilityWal != mConfiguration.useCompatibilityWal;
|
||||
& (SQLiteDatabase.ENABLE_WRITE_AHEAD_LOGGING
|
||||
| SQLiteDatabase.DISABLE_COMPATIBILITY_WAL)) != 0;
|
||||
boolean localeChanged = !configuration.locale.equals(mConfiguration.locale);
|
||||
|
||||
// Update configuration parameters.
|
||||
|
||||
@@ -315,7 +315,12 @@ public final class SQLiteConnectionPool implements Closeable {
|
||||
}
|
||||
}
|
||||
|
||||
if (mConfiguration.openFlags != configuration.openFlags) {
|
||||
// We should do in-place switching when transitioning from compatibility WAL
|
||||
// to rollback journal. Otherwise transient connection state will be lost
|
||||
boolean onlyCompatWalChanged = (mConfiguration.openFlags ^ configuration.openFlags)
|
||||
== SQLiteDatabase.DISABLE_COMPATIBILITY_WAL;
|
||||
|
||||
if (!onlyCompatWalChanged && mConfiguration.openFlags != configuration.openFlags) {
|
||||
// If we are changing open flags and WAL mode at the same time, then
|
||||
// we have no choice but to close the primary connection beforehand
|
||||
// because there can only be one connection open when we change WAL mode.
|
||||
|
||||
@@ -252,6 +252,13 @@ public final class SQLiteDatabase extends SQLiteClosable {
|
||||
*/
|
||||
public static final int ENABLE_WRITE_AHEAD_LOGGING = 0x20000000;
|
||||
|
||||
/**
|
||||
* Open flag: Flag for {@link #openDatabase} to disable Compatibility WAL when opening database.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public static final int DISABLE_COMPATIBILITY_WAL = 0x40000000;
|
||||
|
||||
/**
|
||||
* Absolute max value that can be set by {@link #setMaxSqlCacheSize(int)}.
|
||||
*
|
||||
@@ -288,10 +295,10 @@ public final class SQLiteDatabase extends SQLiteClosable {
|
||||
mConfigurationLocked.idleConnectionTimeoutMs = effectiveTimeoutMs;
|
||||
mConfigurationLocked.journalMode = journalMode;
|
||||
mConfigurationLocked.syncMode = syncMode;
|
||||
mConfigurationLocked.useCompatibilityWal = SQLiteGlobal.isCompatibilityWalSupported();
|
||||
if (!mConfigurationLocked.isInMemoryDb() && SQLiteCompatibilityWalFlags.areFlagsSet()) {
|
||||
mConfigurationLocked.useCompatibilityWal = SQLiteCompatibilityWalFlags
|
||||
.isCompatibilityWalSupported();
|
||||
if (!SQLiteGlobal.isCompatibilityWalSupported() || (
|
||||
SQLiteCompatibilityWalFlags.areFlagsSet() && !SQLiteCompatibilityWalFlags
|
||||
.isCompatibilityWalSupported())) {
|
||||
mConfigurationLocked.openFlags |= DISABLE_COMPATIBILITY_WAL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2082,21 +2089,21 @@ public final class SQLiteDatabase extends SQLiteClosable {
|
||||
synchronized (mLock) {
|
||||
throwIfNotOpenLocked();
|
||||
|
||||
final boolean oldUseCompatibilityWal = mConfigurationLocked.useCompatibilityWal;
|
||||
final int oldFlags = mConfigurationLocked.openFlags;
|
||||
if (!oldUseCompatibilityWal && (oldFlags & ENABLE_WRITE_AHEAD_LOGGING) == 0) {
|
||||
final boolean walDisabled = (oldFlags & ENABLE_WRITE_AHEAD_LOGGING) == 0;
|
||||
final boolean compatibilityWalDisabled = (oldFlags & DISABLE_COMPATIBILITY_WAL) != 0;
|
||||
if (walDisabled && compatibilityWalDisabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mConfigurationLocked.openFlags &= ~ENABLE_WRITE_AHEAD_LOGGING;
|
||||
// If an app explicitly disables WAL, do not even use compatibility mode
|
||||
mConfigurationLocked.useCompatibilityWal = false;
|
||||
// If an app explicitly disables WAL, compatibility mode should be disabled too
|
||||
mConfigurationLocked.openFlags |= DISABLE_COMPATIBILITY_WAL;
|
||||
|
||||
try {
|
||||
mConnectionPoolLocked.reconfigure(mConfigurationLocked);
|
||||
} catch (RuntimeException ex) {
|
||||
mConfigurationLocked.openFlags = oldFlags;
|
||||
mConfigurationLocked.useCompatibilityWal = oldUseCompatibilityWal;
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,15 +110,6 @@ public final class SQLiteDatabaseConfiguration {
|
||||
*/
|
||||
public long idleConnectionTimeoutMs = Long.MAX_VALUE;
|
||||
|
||||
/**
|
||||
* Enables compatibility WAL mode. Applications cannot explicitly choose compatibility WAL mode,
|
||||
* therefore it is not exposed as a flag.
|
||||
*
|
||||
* <p>In this mode, only database journal mode will be changed, connection pool
|
||||
* size will still be limited to a single connection.
|
||||
*/
|
||||
public boolean useCompatibilityWal;
|
||||
|
||||
/**
|
||||
* Journal mode to use when {@link SQLiteDatabase#ENABLE_WRITE_AHEAD_LOGGING} is not set.
|
||||
* <p>Default is returned by {@link SQLiteGlobal#getDefaultJournalMode()}
|
||||
@@ -191,7 +182,6 @@ public final class SQLiteDatabaseConfiguration {
|
||||
lookasideSlotSize = other.lookasideSlotSize;
|
||||
lookasideSlotCount = other.lookasideSlotCount;
|
||||
idleConnectionTimeoutMs = other.idleConnectionTimeoutMs;
|
||||
useCompatibilityWal = other.useCompatibilityWal;
|
||||
journalMode = other.journalMode;
|
||||
syncMode = other.syncMode;
|
||||
}
|
||||
|
||||
@@ -197,6 +197,8 @@ public abstract class SQLiteOpenHelper {
|
||||
}
|
||||
mOpenParamsBuilder.setWriteAheadLoggingEnabled(enabled);
|
||||
}
|
||||
// Compatibility WAL is disabled if an app disables or enables WAL
|
||||
mOpenParamsBuilder.addOpenFlags(SQLiteDatabase.DISABLE_COMPATIBILITY_WAL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user