Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fa489205 authored by Sameer Thatte's avatar Sameer Thatte Committed by Steve Kondik
Browse files

frameworks/base: Use WAL mode for selected databases. Others use default mode: DELETE.

Change-Id: I4cb3c87a751f83bf47a73c4652ce1d8bf64a60fd
parent 31990cd0
Loading
Loading
Loading
Loading
+46 −14
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@
#include <ctype.h>

#include <stdio.h>
#include <libgen.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
@@ -93,6 +94,26 @@ static void registerLoggingFunc(const char *path) {
    loggingFuncSet = true;
}

static int use_wal_mode (char const *path8)
{
    char *temp = basename(path8);
    int i;
    const char *wal_dbs[] = {
         "database_test.db","contacts2.db","calendar.db",\
         "telephony.db","launcher.db","user_dict.db",\
         "downloads.db", "mmssms.db", "internal.db", \
         "EmailProvider.db","alarms.db","EmailProviderBody.db",\
         "btopp.db","picasa.db","webview.db",\
         "webviewCache.db","browser.db","quadrant.db", NULL};

    for (i = 0 ; wal_dbs[i]!= NULL ; i++) {
        if(strcmp(temp, wal_dbs[i]) == 0)
            return 1;
    }

    return 0;
}

/* public native void dbopen(String path, int flags, String locale); */
static void dbopen(JNIEnv* env, jobject object, jstring pathString, jint flags)
{
@@ -123,16 +144,26 @@ static void dbopen(JNIEnv* env, jobject object, jstring pathString, jint flags)
        goto done;
    }

    // WAL is a new rollback method available in SQLite v3.7+. WAL speeds up writes to
    // SQLite databases. WAL cannot be used with Read Only databases or databases opened
    // in read only mode.

    // Check if DB can use WAL mode; Open in WAL mode for non-ReadOnly DBs
    if(!(flags & OPEN_READONLY) && (use_wal_mode(path8))) {
        // Configure databases to run in WAL mode.
    if(!(flags & OPEN_READONLY)) {
        err = sqlite3_exec(handle,"PRAGMA journal_mode = WAL;",
                           NULL, NULL,&zErrMsg);
        if (SQLITE_OK != err) {
           LOGE("sqlite3_exec to set journal_mode = WAL failed\n");
           LOGE("sqlite3_exec - Failed to set WAL mode for [%s] \n", path8);
           err = sqlite3_exec(handle,"PRAGMA journal_mode = DELETE;",
                           NULL, NULL,&zErrMsg);
           if(SQLITE_OK != err) {
               LOGE("sqlite3_exec - Failed to set DELETE mode for [%s] \n", path8);
               throw_sqlite3_exception(env, handle);
               goto done;
           }

        }
        else {
            // Set autocheckpoint = 100 pages
            err = sqlite3_wal_autocheckpoint(handle,
                                             100);
@@ -142,6 +173,7 @@ static void dbopen(JNIEnv* env, jobject object, jstring pathString, jint flags)
               goto done;
            }
        }
    }

    // The soft heap limit prevents the page cache allocations from growing
    // beyond the given limit, no matter what the max page cache sizes are