Merge "Introduced DISABLE_COMPATIBILITY_WAL flag" into pi-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
8de43e93cd
@@ -292,8 +292,10 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen
|
|||||||
final boolean walEnabled =
|
final boolean walEnabled =
|
||||||
(mConfiguration.openFlags & SQLiteDatabase.ENABLE_WRITE_AHEAD_LOGGING) != 0;
|
(mConfiguration.openFlags & SQLiteDatabase.ENABLE_WRITE_AHEAD_LOGGING) != 0;
|
||||||
// Use compatibility WAL unless an app explicitly set journal/synchronous mode
|
// Use compatibility WAL unless an app explicitly set journal/synchronous mode
|
||||||
|
// or DISABLE_COMPATIBILITY_WAL flag is set
|
||||||
final boolean useCompatibilityWal = mConfiguration.journalMode == null
|
final boolean useCompatibilityWal = mConfiguration.journalMode == null
|
||||||
&& mConfiguration.syncMode == null && mConfiguration.useCompatibilityWal;
|
&& mConfiguration.syncMode == null
|
||||||
|
&& (mConfiguration.openFlags & SQLiteDatabase.DISABLE_COMPATIBILITY_WAL) == 0;
|
||||||
if (walEnabled || useCompatibilityWal) {
|
if (walEnabled || useCompatibilityWal) {
|
||||||
setJournalMode("WAL");
|
setJournalMode("WAL");
|
||||||
if (useCompatibilityWal && SQLiteCompatibilityWalFlags.areFlagsSet()) {
|
if (useCompatibilityWal && SQLiteCompatibilityWalFlags.areFlagsSet()) {
|
||||||
@@ -423,8 +425,8 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen
|
|||||||
boolean foreignKeyModeChanged = configuration.foreignKeyConstraintsEnabled
|
boolean foreignKeyModeChanged = configuration.foreignKeyConstraintsEnabled
|
||||||
!= mConfiguration.foreignKeyConstraintsEnabled;
|
!= mConfiguration.foreignKeyConstraintsEnabled;
|
||||||
boolean walModeChanged = ((configuration.openFlags ^ mConfiguration.openFlags)
|
boolean walModeChanged = ((configuration.openFlags ^ mConfiguration.openFlags)
|
||||||
& SQLiteDatabase.ENABLE_WRITE_AHEAD_LOGGING) != 0
|
& (SQLiteDatabase.ENABLE_WRITE_AHEAD_LOGGING
|
||||||
|| configuration.useCompatibilityWal != mConfiguration.useCompatibilityWal;
|
| SQLiteDatabase.DISABLE_COMPATIBILITY_WAL)) != 0;
|
||||||
boolean localeChanged = !configuration.locale.equals(mConfiguration.locale);
|
boolean localeChanged = !configuration.locale.equals(mConfiguration.locale);
|
||||||
|
|
||||||
// Update configuration parameters.
|
// 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
|
// 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
|
// we have no choice but to close the primary connection beforehand
|
||||||
// because there can only be one connection open when we change WAL mode.
|
// 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;
|
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)}.
|
* 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.idleConnectionTimeoutMs = effectiveTimeoutMs;
|
||||||
mConfigurationLocked.journalMode = journalMode;
|
mConfigurationLocked.journalMode = journalMode;
|
||||||
mConfigurationLocked.syncMode = syncMode;
|
mConfigurationLocked.syncMode = syncMode;
|
||||||
mConfigurationLocked.useCompatibilityWal = SQLiteGlobal.isCompatibilityWalSupported();
|
if (!SQLiteGlobal.isCompatibilityWalSupported() || (
|
||||||
if (!mConfigurationLocked.isInMemoryDb() && SQLiteCompatibilityWalFlags.areFlagsSet()) {
|
SQLiteCompatibilityWalFlags.areFlagsSet() && !SQLiteCompatibilityWalFlags
|
||||||
mConfigurationLocked.useCompatibilityWal = SQLiteCompatibilityWalFlags
|
.isCompatibilityWalSupported())) {
|
||||||
.isCompatibilityWalSupported();
|
mConfigurationLocked.openFlags |= DISABLE_COMPATIBILITY_WAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2082,21 +2089,21 @@ public final class SQLiteDatabase extends SQLiteClosable {
|
|||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
throwIfNotOpenLocked();
|
throwIfNotOpenLocked();
|
||||||
|
|
||||||
final boolean oldUseCompatibilityWal = mConfigurationLocked.useCompatibilityWal;
|
|
||||||
final int oldFlags = mConfigurationLocked.openFlags;
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mConfigurationLocked.openFlags &= ~ENABLE_WRITE_AHEAD_LOGGING;
|
mConfigurationLocked.openFlags &= ~ENABLE_WRITE_AHEAD_LOGGING;
|
||||||
// If an app explicitly disables WAL, do not even use compatibility mode
|
// If an app explicitly disables WAL, compatibility mode should be disabled too
|
||||||
mConfigurationLocked.useCompatibilityWal = false;
|
mConfigurationLocked.openFlags |= DISABLE_COMPATIBILITY_WAL;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mConnectionPoolLocked.reconfigure(mConfigurationLocked);
|
mConnectionPoolLocked.reconfigure(mConfigurationLocked);
|
||||||
} catch (RuntimeException ex) {
|
} catch (RuntimeException ex) {
|
||||||
mConfigurationLocked.openFlags = oldFlags;
|
mConfigurationLocked.openFlags = oldFlags;
|
||||||
mConfigurationLocked.useCompatibilityWal = oldUseCompatibilityWal;
|
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,15 +110,6 @@ public final class SQLiteDatabaseConfiguration {
|
|||||||
*/
|
*/
|
||||||
public long idleConnectionTimeoutMs = Long.MAX_VALUE;
|
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.
|
* Journal mode to use when {@link SQLiteDatabase#ENABLE_WRITE_AHEAD_LOGGING} is not set.
|
||||||
* <p>Default is returned by {@link SQLiteGlobal#getDefaultJournalMode()}
|
* <p>Default is returned by {@link SQLiteGlobal#getDefaultJournalMode()}
|
||||||
@@ -191,7 +182,6 @@ public final class SQLiteDatabaseConfiguration {
|
|||||||
lookasideSlotSize = other.lookasideSlotSize;
|
lookasideSlotSize = other.lookasideSlotSize;
|
||||||
lookasideSlotCount = other.lookasideSlotCount;
|
lookasideSlotCount = other.lookasideSlotCount;
|
||||||
idleConnectionTimeoutMs = other.idleConnectionTimeoutMs;
|
idleConnectionTimeoutMs = other.idleConnectionTimeoutMs;
|
||||||
useCompatibilityWal = other.useCompatibilityWal;
|
|
||||||
journalMode = other.journalMode;
|
journalMode = other.journalMode;
|
||||||
syncMode = other.syncMode;
|
syncMode = other.syncMode;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -197,6 +197,8 @@ public abstract class SQLiteOpenHelper {
|
|||||||
}
|
}
|
||||||
mOpenParamsBuilder.setWriteAheadLoggingEnabled(enabled);
|
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