From 6e584a17c9ddfa8a53b2900a7ce534d1f6b2b93d Mon Sep 17 00:00:00 2001 From: Kunhoon Baik Date: Wed, 24 May 2017 21:45:00 +0900 Subject: [PATCH] Heart: Remove the mechanism which removes logging-data from Heart DB by explict data-query In Tizen 3.0 and Early Tizen 4.0, we observed whether there are some requirements for deleting logging-data explictly. Meanwhile, the logging functions like logging_get_latest_in_cache,logging_read_foreach has been used for several purposes. However, there are some bugs that the logging functions do not consider such deleting data cache entries in module cache. Thus, our plan was to improve the functions if there are some requirement for deleting logging-data explictly. However, there are no requirements about it. Thus, finally, we decided to remove the explict logging-data removing mechanism because there are no use cases. Thus, from now, data of heart DBs will be removed according to just impliict(internal) rule. That is, in this time, the old data is removed automatically when the DB size limit is reached. Change-Id: Ief4cf1baa595030fddd6becd929165ee4857e8bb --- src/heart/heart-storage.c | 155 -------------------------------------------- src/heart/include/logging.h | 4 +- src/heart/logging.c | 33 ---------- 3 files changed, 1 insertion(+), 191 deletions(-) diff --git a/src/heart/heart-storage.c b/src/heart/heart-storage.c index e4ccee0..3d79e73 100644 --- a/src/heart/heart-storage.c +++ b/src/heart/heart-storage.c @@ -48,9 +48,6 @@ #define STORAGE_NAME "storage" static bool heart_storage_initailized = false; -static pthread_mutex_t heart_storage_verifying_mutex = PTHREAD_MUTEX_INITIALIZER; -static pthread_t heart_storage_verifying_thread = 0; -static GQueue *queue = NULL; static void dbus_insert_log(GDBusMethodInvocation *invocation, GVariant *params) { @@ -74,154 +71,15 @@ static void dbus_insert_log(GDBusMethodInvocation *invocation, GVariant *params) D_BUS_REPLY_NULL(invocation); } -void heart_storage_delete_cb(gpointer data, gpointer user_data) -{ - int ret; - struct logging_table_form *table = (struct logging_table_form *)data; - - if (!table) { - _E("the table is empty!"); - return; - } - - _SD("Delete callback for '%s'", table->data); - if (access(table->data, F_OK) == 0) - return; - - ret = logging_delete(table->uid, STORAGE_NAME, table->data); - if (ret != RESOURCED_ERROR_NONE) - _SE("Delete request failed: %s", table->data); -} - -void heart_storage_collect_candidate(struct logging_table_form *table, void *user_data) -{ - GPtrArray *candidates = (GPtrArray *)user_data; - if (!candidates) { - _E("There is no array to store candidates"); - return; - } - - g_ptr_array_add(candidates, table); -} - -void *heart_storage_verifying_thread_main(void *arg) -{ - int ret; - char *pkgid; - GPtrArray *candidates = g_ptr_array_new(); - - if (!candidates) { - _E("Failed to create GPtrArray"); - goto end; - } - - _D("Verifying thread is created!"); - do { - ret = pthread_mutex_lock(&heart_storage_verifying_mutex); - if (ret) { - _E("logging storage verifying thread::pthread_mutex_lock() failed, %d", ret); - break; - } - - pkgid = g_queue_pop_head(queue); - if (!pkgid) - break; - - pthread_mutex_unlock(&heart_storage_verifying_mutex); - - _SD("Verify '%s'", pkgid); - ret = logging_read_foreach(STORAGE_NAME, NULL, pkgid, 0, 0, - heart_storage_collect_candidate, candidates); - if (ret != RESOURCED_ERROR_NONE) - _E("Failed to read logs! : %d", ret); - free(pkgid); - - g_ptr_array_foreach(candidates, heart_storage_delete_cb, NULL); - g_ptr_array_free(candidates, TRUE); - } while (1); - - pthread_mutex_unlock(&heart_storage_verifying_mutex); - -end: - heart_storage_verifying_thread = 0; - pthread_exit((void *)0); -} - -void heart_storage_verifying_thread_create(const char *data) -{ - char *pkgid = strndup(data, strlen(data)+1); - if (!pkgid) { - _E("Failed to allocate memory"); - return; - } - - int ret = pthread_mutex_lock(&heart_storage_verifying_mutex); - if (ret) { - _E("logging storage verifying thread::pthread_mutex_lock() failed, %d", ret); - free(pkgid); - return; - } - - /* Add pkgid to queue */ - g_queue_push_tail(queue, pkgid); - - if (heart_storage_verifying_thread == 0) { - pthread_attr_t attr; - ret = pthread_attr_init(&attr); - if (ret < 0) { - _E("Failed to initialize pthread attributes, %d", ret); - pthread_mutex_unlock(&heart_storage_verifying_mutex); - return; - } - - ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - if (ret < 0) { - _E("Failed to set detached state, %d", ret); - pthread_mutex_unlock(&heart_storage_verifying_mutex); - return; - } - - ret = pthread_create(&heart_storage_verifying_thread, &attr, heart_storage_verifying_thread_main, NULL); - if (ret < 0) { - _E("pthread creation for heart_storage_verifying_thread_main failed, %d", ret); - pthread_mutex_unlock(&heart_storage_verifying_mutex); - return; - } - } - - pthread_mutex_unlock(&heart_storage_verifying_mutex); -} - -static void dbus_verify_log(GDBusMethodInvocation *invocation, GVariant *params) -{ - char *pkgid = NULL; - - g_variant_get(params, "(&s)", &pkgid); - if (!pkgid) { - _E("Wrong message arguments!"); - D_BUS_REPLY_NULL(invocation); - return; - } - /* flush module cache */ - logging_save_to_storage(true); - - heart_storage_verifying_thread_create(pkgid); - D_BUS_REPLY_NULL(invocation); -} - static const char dbus_methods_xml[] = " " " " " " " " -" " -" " -" " " "; static struct d_bus_method dbus_methods[] = { { "Insert", dbus_insert_log }, - { "Verify", dbus_verify_log }, }; static bool is_storage_logging(void) @@ -253,19 +111,6 @@ static int heart_storage_init(void *data) if (!is_storage_logging()) return RESOURCED_ERROR_UNINITIALIZED; - ret = pthread_mutex_init(&heart_storage_verifying_mutex, NULL); - if (ret < 0) { - _E("mutex_init failed %d", ret); - return RESOURCED_ERROR_FAIL; - } - - queue = g_queue_new(); - if (!queue) { - _E("queue init failed"); - return RESOURCED_ERROR_OUT_OF_MEMORY; - } - g_queue_init(queue); - ret = logging_module_init(STORAGE_NAME, FOUR_MONTH, FIVE_MINUTE, NULL, 0, USER_OWN); if (ret != RESOURCED_ERROR_NONE) { _E("logging module init failed"); diff --git a/src/heart/include/logging.h b/src/heart/include/logging.h index 1f31c17..01cabf4 100644 --- a/src/heart/include/logging.h +++ b/src/heart/include/logging.h @@ -73,8 +73,7 @@ enum logging_period { }; enum logging_operation { - INSERT = 0, - DELETE + INSERT = 0 }; /* @@ -126,7 +125,6 @@ int logging_register_listener(char *name, logging_listener_cb listener); int logging_unregister_listener(char *name, logging_listener_cb listener); int logging_get_latest_in_cache(char *name, char *appid, char **data); int logging_write(int pid, char *name, char *appid, char *pkgid, time_t time, char *data); -int logging_delete(int uid, char *name, char *data); int logging_read_foreach(char *name, char *appid, char *pkgid, time_t start_time, time_t end_time, logging_info_cb callback, void *user_data); int logging_modify_appid(char *module_name, char *old_appid, char *new_appid, int pid); diff --git a/src/heart/logging.c b/src/heart/logging.c index 371e8b5..9419f70 100644 --- a/src/heart/logging.c +++ b/src/heart/logging.c @@ -58,7 +58,6 @@ #define LOGGING_FILE_PATH HEART_FILE_PATH #define CREATE_QUERY "CREATE TABLE IF NOT EXISTS %s (appid TEXT, pkgid TEXT, time INT, data TEXT, idx INT, PRIMARY KEY(time, idx));" #define DELETE_QUERY_WITH_TIME "DELETE from %s where time < %d;" -#define DELETE_QUERY_WITH_DATA "DELETE from %s where data = ?;" #define INSERT_QUERY "INSERT INTO %s values (?, ?, ?, ?, ?);" #define SELECT_QUERY "SELECT * FROM %s WHERE time > %d AND time < %d;" #define UPDATE_APPID_QUERY "UPDATE %s SET appid = \'%s\' WHERE appid = \'%s\';" @@ -79,7 +78,6 @@ func(format, ##arg); \ pthread_mutex_unlock(&(module->cache_mutex)); \ sqlite3_finalize(db_elem->insert_stmt); \ - sqlite3_finalize(db_elem->delete_stmt); \ return; \ } } while (0) @@ -89,7 +87,6 @@ struct logging_db { char *path; sqlite3 *file; sqlite3_stmt *insert_stmt; - sqlite3_stmt *delete_stmt; }; struct logging_module { @@ -230,8 +227,6 @@ static void logging_free_db_value(gpointer data) struct logging_db *db_elem = (struct logging_db*)data; if (db_elem->insert_stmt) sqlite3_finalize(db_elem->insert_stmt); - if (db_elem->delete_stmt) - sqlite3_finalize(db_elem->delete_stmt); if (db_elem->file) sqlite3_close(db_elem->file); if (db_elem->path) @@ -353,7 +348,6 @@ static int logging_update_user_db_list(char *name, enum logging_db_type type, GH db_elem->file = file; db_elem->insert_stmt = NULL; - db_elem->delete_stmt = NULL; g_hash_table_insert(*db_list, (gpointer)uid, (gpointer)db_elem); } @@ -416,7 +410,6 @@ int logging_module_init(char *name, enum logging_period max_period, db_elem->path = strndup(db_path, sizeof(db_path)); db_elem->file = db_file; db_elem->insert_stmt = NULL; - db_elem->delete_stmt = NULL; g_hash_table_insert(module->db_list, GINT_TO_POINTER(UID_FOR_ROOT), (gpointer)db_elem); /* NOTICE : You MUST define schema at the sub-module */ break; @@ -669,12 +662,6 @@ int logging_write(int pid, char *name, char *appid, char *pkgid, time_t time, ch return logging_operate(uid, name, appid, pkgid, time, data, INSERT); } -int logging_delete(int uid, char *name, char *data) -{ - time_t time = 0; - return logging_operate(uid, name, NULL, NULL, time, data, DELETE); -} - int logging_leveldb_put(char *key, unsigned int key_len, char *value, unsigned int value_len) { char *err = NULL; @@ -1299,13 +1286,6 @@ void logging_save_to_storage(int force) FINALIZE_AND_RETURN_IF(ret != SQLITE_OK, _E, "insert %s table failed %s", module->name, sqlite3_errmsg(db_elem->file)); - - snprintf(buf, LOGGING_BUF_MAX, DELETE_QUERY_WITH_DATA, module->name); - ret = sqlite3_prepare_v2(db_elem->file, buf, read_until_null, - &(db_elem->delete_stmt), NULL); - FINALIZE_AND_RETURN_IF(ret != SQLITE_OK, _E, - "insert %s table failed %s", module->name, - sqlite3_errmsg(db_elem->file)); } for (j = 0; j < len; j++) { @@ -1336,16 +1316,6 @@ void logging_save_to_storage(int force) } switch (table->operation) { - case DELETE: - sqlite3_reset(db_elem->delete_stmt); - - ret = sqlite3_bind_text(db_elem->delete_stmt, 1, table->data, -1, SQLITE_STATIC); - FINALIZE_AND_RETURN_IF(ret != SQLITE_OK, _SE, "Can not bind data : %s for preparing statement", table->pkgid); - - ret = sqlite3_step(db_elem->delete_stmt); - FINALIZE_AND_RETURN_IF(ret != SQLITE_DONE, _E, "delete %s table failed %s", module->name, sqlite3_errmsg(db_elem->file)); - break; - case INSERT: sqlite3_reset(db_elem->insert_stmt); @@ -1384,8 +1354,6 @@ void logging_save_to_storage(int force) sqlite3_exec(db_elem->file, "COMMIT;", NULL, NULL, NULL); sqlite3_finalize(db_elem->insert_stmt); db_elem->insert_stmt = NULL; - sqlite3_finalize(db_elem->delete_stmt); - db_elem->delete_stmt = NULL; } } @@ -1662,7 +1630,6 @@ int logging_init(void *data) db_elem->file = db_file; db_elem->insert_stmt = NULL; - db_elem->delete_stmt = NULL; g_hash_table_insert(system_default_db, GINT_TO_POINTER(UID_FOR_ROOT), (gpointer)db_elem); /* Create user default DB */ -- 2.7.4