Change default page size of sqlite3 wal_autocheckpoint 25/160225/6
authorInkyun Kil <inkyun.kil@samsung.com>
Wed, 15 Nov 2017 02:12:18 +0000 (11:12 +0900)
committerInkyun Kil <inkyun.kil@samsung.com>
Thu, 16 Nov 2017 01:36:47 +0000 (10:36 +0900)
- Default page of sqlite3 wal is 1000. In other words, memory increases
up to 4M. It is somewhat big on '/run'. That's why it should be changed
to 100page.
- Change magic string to platform-config

Change-Id: Ia1829a7ba61a9f152d7a803c5521426e3b5dc36d
Signed-off-by: Inkyun Kil <inkyun.kil@samsung.com>
backend/CMakeLists.txt
backend/sqlite.c
packaging/buxton2.spec

index 164686c88b8faecab6167f3b44d72309f11a751f..06f53cb5d2611d10448cbcaded221171f16502d2 100644 (file)
@@ -16,5 +16,13 @@ SET_TARGET_PROPERTIES(${TARGET} PROPERTIES
                PREFIX ""
                COMPILE_FLAGS "-fvisibility=hidden"
 )
-TARGET_LINK_LIBRARIES(${TARGET} ${PKGS_LDFLAGS} -lsqlite3)
+
+INCLUDE(FindPkgConfig)
+PKG_CHECK_MODULES(SQLITE_PKGS REQUIRED sqlite3 libtzplatform-config)
+SET(EXTRA_LDFLAGS "${PKGS_LDFLAGS}")
+FOREACH(flag ${SQLITE_PKGS_LDFLAGS})
+       SET(EXTRA_LDFLAGS "${EXTRA_LDFLAGS} ${flag}")
+ENDFOREACH()
+
+TARGET_LINK_LIBRARIES(${TARGET} ${EXTRA_LDFLAGS})
 INSTALL(TARGETS ${TARGET} DESTINATION ${MODULE_DIR} COMPONENT RuntimeLibraries)
index b18750cf177f56fa006d6fc8cc1c35b1ef850ac1..35f70236bf675b6c71d308d6231e152ac431c8f1 100644 (file)
 
 #include <glib.h>
 #include <sqlite3.h>
+#include <tzplatform_config.h>
 
 #include "backend.h"
 #include "log.h"
 
+#define BUXTON_DEFAULT_WAL_AUTOCHECKPOINT 100
+#define BASE_DB_PATH tzplatform_getenv(TZ_SYS_RO_ETC)
+
 #define QUERY_MAX_LEN   8192
 #define QUERY_CREATE_TABLE_BUXTON "create table if not exists buxton " \
        "(key text, " \
@@ -92,7 +96,7 @@ static sqlite3 *open_sqlite3(const char *dbpath, bool readonly)
        if (db_exist && r == SQLITE_CORRUPT) {
                bxt_err("Open '%s' failed: %s", dbpath, sqlite3_errmsg(db));
 
-               if (!strncmp("/etc", dbpath, 4)) {
+               if (!strncmp(BASE_DB_PATH, dbpath, strlen(dbpath))) {
                        free(nm);
                        return NULL;
                }
@@ -119,7 +123,7 @@ static sqlite3 *open_sqlite3(const char *dbpath, bool readonly)
        }
 
        if (!db_exist) {
-               if (strncmp("/etc", dbpath, 4)) {
+               if (strncmp(BASE_DB_PATH, dbpath, strlen(dbpath))) {
                        r = sqlite3_exec(db, "PRAGMA journal_mode = WAL",
                                        NULL, NULL, NULL);
                        if (r) {
@@ -142,6 +146,12 @@ static sqlite3 *open_sqlite3(const char *dbpath, bool readonly)
                }
        }
 
+       if (strncmp(BASE_DB_PATH, dbpath, strlen(dbpath))) {
+               r = sqlite3_wal_autocheckpoint(db, BUXTON_DEFAULT_WAL_AUTOCHECKPOINT);
+               if (r != SQLITE_OK)
+                       bxt_err("SET DEFAULT_WAL_AUTOCHECKPOINT failed : %d", r);
+       }
+
        g_hash_table_insert(dbs, nm, db);
 
        bxt_dbg("Open '%s'", dbpath);
index e56ff7c6c137cb3be7a04c381272390bc8851833..6f0fde6329238535b6460b48a7ad7bb53f735e8a 100755 (executable)
@@ -22,6 +22,7 @@ BuildRequires:  pkgconfig(libsystemd)
 BuildRequires:  pkgconfig(cynara-client-async)
 BuildRequires:  pkgconfig(dlog)
 BuildRequires:  pkgconfig(sqlite3)
+BuildRequires:  pkgconfig(libtzplatform-config)
 Requires:       security-config
 Requires(post): /usr/bin/getent
 Requires(post): /usr/bin/chown