Rollback media-scan-extractor-v2 61/243661/1
authorMinje Ahn <minje.ahn@samsung.com>
Wed, 9 Sep 2020 03:21:56 +0000 (12:21 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Wed, 9 Sep 2020 03:21:56 +0000 (12:21 +0900)
Rollback __msc_check_extract_stop_status() for performance issue.

Change-Id: I01ce0d35a9ad38424ba5cf7a4d4235ca2a9b71cf
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
src/common/include/media-common-db-svc.h
src/common/media-common-db-svc.c
src/scanner-v2/media-scanner-extract-v2.c

index 9cd7c86..5ab7942 100755 (executable)
@@ -70,7 +70,8 @@ int ms_update_folder_time(sqlite3 *handle, const char *storage_id, char *folder_
 int ms_set_storage_scan_status(sqlite3 *handle, char *storage_id, media_scan_status_e scan_status, uid_t uid);
 int ms_genarate_uuid(char **uuid);
 int ms_scan_item_batch(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid);
-int ms_get_and_extract_media(sqlite3 *handle, const char *storage_id, ms_msg_type_e msg_type, const char *path);
+int ms_get_extract_list(sqlite3 *handle, const char *storage_id, int scan_type, const char* path, int is_end, void *array);
+int ms_update_one_extract_item(sqlite3 *handle, const char *storage_id, int storage_type, void *data);
 int ms_delete_invalid_items_in_folder(sqlite3 *handle, const char *storage_id, const char *path, bool is_recursive, uid_t uid);
 int ms_delete_invalid_folder_by_path(sqlite3 *handle, const char *storage_id, const char *folder_path, uid_t uid);
 int ms_get_folder_scan_status(sqlite3 *handle, const char *storage_id, const char *path, int *scan_status);
index 5b9b3b4..451dae8 100644 (file)
@@ -67,7 +67,8 @@ typedef int (*UPDATE_ITEM_META)(sqlite3 *, uid_t);
 
 typedef int (*DELETE_INVALID_FOLDER_BY_PATH)(sqlite3 *, const char *, const char *, uid_t);
 typedef int (*CHECK_FOLDER_EXIST)(sqlite3*, const char*, const char*);
-typedef int (*GET_AND_EXTRACT_MEDIA)(sqlite3*, const char*, int, const char *);
+typedef int (*GET_EXTRACT_LIST)(sqlite3*, const char*, int, const char*, int, void*);
+typedef int (*UPDATE_ONE_EXTRACT_ITEM)(sqlite3*, const char*, int, void *);
 typedef int (*GET_MEDIA_TYPE)(const char *, int *);
 typedef int (*REFRESH_ITEM)(sqlite3 *, const char *, const char *, uid_t);
 
@@ -101,7 +102,8 @@ enum func_list {
        eDELETE_INVALID_FOLDER_BY_PATH,
        eCHECK_FOLDER_EXIST,
        eGET_MEDIA_TYPE,
-       eGET_AND_EXTRACT_MEDIA,
+       eGET_EXTRACT_LIST,
+       eUPDATE_ONE_EXTRACT_ITEM,
        eREFRESH_ITEM,
        eFUNC_MAX
 };
@@ -139,7 +141,8 @@ int ms_load_functions(void)
                "delete_invalid_folder_by_path",
                "check_folder_exist",
                "get_media_type",
-               "get_and_extract_media",
+               "get_extract_list",
+               "update_one_extract_item",
                "refresh_item",
                };
 
@@ -348,13 +351,22 @@ int ms_scan_item_batch(sqlite3 *handle, const char *storage_id, const char *path
        return ret;
 }
 
-int ms_get_and_extract_media(sqlite3 *handle, const char *storage_id, ms_msg_type_e msg_type, const char *path)
+int ms_get_extract_list(sqlite3 *handle, const char* storage_id, int scan_type, const char* path, int is_end, void *array)
 {
        int ret = MS_MEDIA_ERR_NONE;
 
-       ret = ((GET_AND_EXTRACT_MEDIA)func_array[eGET_AND_EXTRACT_MEDIA])(handle, storage_id, msg_type, path);
-       if (ret != MS_MEDIA_ERR_NONE && ret != MS_MEDIA_ERR_DB_NO_RECORD)
-               MS_DBG_ERR("GET_AND_EXTRACT_MEDIA failed [%d]", ret);
+       ret = ((GET_EXTRACT_LIST)func_array[eGET_EXTRACT_LIST])(handle, storage_id, scan_type, path, is_end, array);
+       MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "GET_EXTRACT_LIST failed [%d]", ret);
+
+       return ret;
+}
+
+int ms_update_one_extract_item(sqlite3 *handle, const char* storage_id, int storage_type, void *data)
+{
+       int ret = MS_MEDIA_ERR_NONE;
+
+       ret = ((UPDATE_ONE_EXTRACT_ITEM)func_array[eUPDATE_ONE_EXTRACT_ITEM])(handle, storage_id, storage_type, data);
+       MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "UPDATE_ONE_EXTRACT_ITEM failed [%d]", ret);
 
        return ret;
 }
index 0507837..d96e477 100644 (file)
@@ -40,6 +40,7 @@ bool g_directory_extract_processing;
 static int stg_extract_status;
 
 static GMutex extract_item_mutex;
+static GMutex decode_mutex;
 
 static s_extract_item *cancel_extract_item = NULL;
 static s_extract_item *cur_extract_item = NULL;
@@ -47,6 +48,8 @@ static s_extract_item *cur_extract_item = NULL;
 static GCond extract_data_cond;
 static GMutex extract_data_mutex;
 #define VCONFKEY_PRIVATE_EXTRACTSTATUS "db/private/extractstatus"
+#define LAST_EVENT 1
+#define NORMAL_EVENT 0
 
 static int __msc_check_extract_stop_status(ms_msg_type_e msg_type, const char *start_path, int pid);
 static void __msc_set_storage_extract_status(ms_storage_scan_status_e status);
@@ -59,6 +62,12 @@ static void __msc_set_cur_extract_item(const char* cur_path, int pid);
 static void __msc_del_cur_extract_item(void);
 static void __msc_del_extract_blocked_path(const char* blocked_path);
 
+
+typedef struct {
+       int media_type;
+       char *path;
+} ms_item_info_s;
+
 void msc_init_extract_thread(void)
 {
        if (!storage_extract_queue) storage_extract_queue = g_async_queue_new();
@@ -69,6 +78,7 @@ void msc_init_extract_thread(void)
        g_mutex_init(&extract_data_mutex);
 
        g_mutex_init(&extract_item_mutex);
+       g_mutex_init(&decode_mutex);
 
        g_cond_init(&extract_data_cond);
 }
@@ -83,39 +93,66 @@ void msc_deinit_extract_thread(void)
        g_mutex_clear(&extract_data_mutex);
 
        g_mutex_clear(&extract_item_mutex);
+       g_mutex_clear(&decode_mutex);
 
        g_cond_clear(&extract_data_cond);
 }
 
-static int __msc_folder_bulk_extract(sqlite3 *handle, const char *storage_id, const char *path, ms_msg_type_e msg_type, int pid)
+static int __msc_folder_bulk_extract(sqlite3 *handle, const char *storage_id, int storage_type, const char *path, int scan_type, int pid, bool is_end)
 {
+       MS_DBG_WARN("begin of __msc_folder_bulk_extract");
        int ret = MS_MEDIA_ERR_NONE;
+       GArray *data_array = NULL;
+       ms_item_info_s* db_data = NULL;
+       int sleep_count = 0;
 
-       MS_DBG_FENTER();
+       ret = ms_get_extract_list(handle, storage_id, scan_type, path, is_end, (void *)&data_array);
+       MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, MS_MEDIA_ERR_NONE, "ms_get_extract_list failed!!!");
+       MS_DBG_RETVM_IF(!data_array, MS_MEDIA_ERR_NONE, "data_array is NULL!!!");
 
-       while (1) {
-               ret = __msc_check_extract_stop_status(msg_type, path, pid);
+       while (data_array->len != 0) {
+               db_data = NULL;
+
+               ret = __msc_check_extract_stop_status(scan_type, path, pid);
                if (ret == MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
                        MS_DBG_ERR("__msc_folder_bulk_extract MS_MEDIA_ERR_SCANNER_FORCE_STOP");
                        break;
                }
 
-               ret = ms_get_and_extract_media(handle, storage_id, msg_type, path);
-               if (ret != MS_MEDIA_ERR_NONE) {
-                       if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
-                               MS_DBG("Extract done");
-                       else
-                               MS_DBG_ERR("ms_get_and_extract_media failed!!!");
+               db_data = g_array_index(data_array, ms_item_info_s *, 0);
+               g_array_remove_index(data_array, 0);
 
-                       break;
+               g_mutex_lock(&decode_mutex);
+               ms_update_one_extract_item(handle, storage_id, storage_type, db_data);
+               g_mutex_unlock(&decode_mutex);
+
+               if (db_data) {
+                       g_free(db_data->path);
+                       g_free(db_data);
+                       db_data = NULL;
+               }
+
+               if (++sleep_count == 5) {
+                       sleep_count = 0;
+                       usleep(SCAN_SLEEP_TIME);
                }
-               /* Sleep per 10 items. refer to META_UPDATE_MAX */
-               usleep(SCAN_SLEEP_TIME);
        }
 
-       MS_DBG_FLEAVE();
+       while (data_array->len != 0) {
+               db_data = g_array_index(data_array, ms_item_info_s *, 0);
+               g_array_remove_index(data_array, 0);
 
-       return MS_MEDIA_ERR_NONE;
+               if (db_data) {
+                       g_free(db_data->path);
+                       g_free(db_data);
+                       db_data = NULL;
+               }
+       }
+       g_array_free(data_array, FALSE);
+       data_array = NULL;
+
+       MS_DBG_WARN("end of __msc_folder_bulk_extract");
+       return ret;
 }
 
 gpointer msc_folder_extract_thread(gpointer data)
@@ -123,6 +160,8 @@ gpointer msc_folder_extract_thread(gpointer data)
        ms_comm_msg_s *extract_data = NULL;
        int ret = MS_MEDIA_ERR_NONE;
        sqlite3 *handle = NULL;
+       int end_flag = NORMAL_EVENT;
+       ms_user_storage_type_e storage_type = MS_USER_STORAGE_INTERNAL;
 
        while (1) {
                extract_data = g_async_queue_pop(folder_extract_queue);
@@ -162,6 +201,13 @@ gpointer msc_folder_extract_thread(gpointer data)
                        ret = MS_MEDIA_ERR_INVALID_PARAMETER;
                        goto NEXT;
                }
+               end_flag = extract_data->result ? LAST_EVENT : NORMAL_EVENT;
+
+               ret = ms_user_get_storage_type(extract_data->uid, extract_data->msg, &storage_type);
+               if (ret != MS_MEDIA_ERR_NONE) {
+                       MS_DBG_ERR("ms_user_get_storage_type failed");
+                       goto NEXT;
+               }
 
                ret = __msc_check_extract_stop_status(extract_data->msg_type, extract_data->msg, extract_data->pid);
                if (ret == MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
@@ -178,7 +224,7 @@ gpointer msc_folder_extract_thread(gpointer data)
                        goto NEXT;
                }
 
-               ret = __msc_folder_bulk_extract(handle, extract_data->storage_id, extract_data->msg, extract_data->msg_type, extract_data->pid);
+               ret = __msc_folder_bulk_extract(handle, extract_data->storage_id, storage_type, extract_data->msg, extract_data->msg_type, extract_data->pid, end_flag);
 
 NEXT:
                g_directory_extract_processing = false;
@@ -237,6 +283,7 @@ gpointer msc_storage_extract_thread(gpointer data)
        int ret = MS_MEDIA_ERR_NONE;
        sqlite3 *handle = NULL;
        ms_user_storage_type_e storage_type = MS_USER_STORAGE_INTERNAL;
+       int end_flag = NORMAL_EVENT;
 
        while (1) {
                __msc_set_storage_extract_status(MS_STORAGE_SCAN_DONE);
@@ -263,6 +310,7 @@ gpointer msc_storage_extract_thread(gpointer data)
                        continue;
                }
 
+               end_flag = extract_data->result ? LAST_EVENT : NORMAL_EVENT;
                MS_DBG("path[%.*s] storage_id[%.*s]", MAX_MSG_SIZE, extract_data->msg, MS_UUID_SIZE, extract_data->storage_id);
 
                if (strlen(extract_data->storage_id) == 0) {
@@ -301,7 +349,7 @@ gpointer msc_storage_extract_thread(gpointer data)
                }
 
                /*extract meta*/
-               ret = __msc_folder_bulk_extract(handle, extract_data->storage_id, extract_data->msg, extract_data->msg_type, extract_data->pid);
+               ret = __msc_folder_bulk_extract(handle, extract_data->storage_id, storage_type, extract_data->msg, extract_data->msg_type, extract_data->pid, end_flag);
                MS_DBG_WARN("extract PAUSE");
                __msc_pause_extract();
                MS_DBG_WARN("extract RESUME");