Skip to content

Commit

Permalink
Resolve #27 Remove unnecessary WAL disable when using attach database
Browse files Browse the repository at this point in the history
  • Loading branch information
npurushe committed Sep 1, 2016
1 parent a182edb commit 8b7081f
Showing 1 changed file with 0 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,6 @@ protected SQLiteSession initialValue() {
// INVARIANT: Guarded by mLock.
private SQLiteConnectionPool mConnectionPoolLocked;

// True if the database has attached databases.
// INVARIANT: Guarded by mLock.
private boolean mHasAttachedDbsLocked;

/**
* When a constraint violation occurs, an immediate ROLLBACK occurs,
* thus ending the current transaction, and the command aborts with a
Expand Down Expand Up @@ -1675,19 +1671,6 @@ public void execSQL(String sql, Object[] bindArgs) throws SQLException {
private int executeSql(String sql, Object[] bindArgs) throws SQLException {
acquireReference();
try {
if (SQLiteStatementType.getSqlStatementType(sql) == SQLiteStatementType.STATEMENT_ATTACH) {
boolean disableWal = false;
synchronized (mLock) {
if (!mHasAttachedDbsLocked) {
mHasAttachedDbsLocked = true;
disableWal = true;
}
}
if (disableWal) {
disableWriteAheadLogging();
}
}

SQLiteStatement statement = new SQLiteStatement(this, sql, bindArgs);
try {
return statement.executeUpdateDelete();
Expand Down Expand Up @@ -1960,16 +1943,6 @@ public boolean enableWriteAheadLogging() {
return false;
}

// make sure this database has NO attached databases because sqlite's write-ahead-logging
// doesn't work for databases with attached databases
if (mHasAttachedDbsLocked) {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "this database: " + mConfigurationLocked.label
+ " has attached databases. can't enable WAL.");
}
return false;
}

mConfigurationLocked.openFlags |= ENABLE_WRITE_AHEAD_LOGGING;
try {
mConnectionPoolLocked.reconfigure(mConfigurationLocked);
Expand Down Expand Up @@ -2085,20 +2058,6 @@ public List<Pair<String, String>> getAttachedDbs() {
return null; // not open
}

if (!mHasAttachedDbsLocked) {
// No attached databases.
// There is a small window where attached databases exist but this flag is not
// set yet. This can occur when this thread is in a race condition with another
// thread that is executing the SQL statement: "attach database <blah> as <foo>"
// If this thread is NOT ok with such a race condition (and thus possibly not
// receivethe entire list of attached databases), then the caller should ensure
// that no thread is executing any SQL statements while a thread is calling this
// method. Typically, this method is called when 'adb bugreport' is done or the
// caller wants to collect stats on the database and all its attached databases.
attachedDbs.add(new Pair<>("main", mConfigurationLocked.path));
return attachedDbs;
}

acquireReference();
}

Expand Down

0 comments on commit 8b7081f

Please sign in to comment.