diff options
Diffstat (limited to 'libglusterfs')
-rw-r--r-- | libglusterfs/src/gfdb/gfdb_data_store.c | 165 | ||||
-rw-r--r-- | libglusterfs/src/gfdb/gfdb_data_store.h | 46 | ||||
-rw-r--r-- | libglusterfs/src/gfdb/gfdb_data_store_types.h | 19 | ||||
-rw-r--r-- | libglusterfs/src/gfdb/gfdb_sqlite3.c | 61 | ||||
-rw-r--r-- | libglusterfs/src/gfdb/gfdb_sqlite3.h | 20 | ||||
-rw-r--r-- | libglusterfs/src/gfdb/gfdb_sqlite3_helper.c | 42 |
6 files changed, 211 insertions, 142 deletions
diff --git a/libglusterfs/src/gfdb/gfdb_data_store.c b/libglusterfs/src/gfdb/gfdb_data_store.c index ffa3fb67905..9c042f9e82e 100644 --- a/libglusterfs/src/gfdb/gfdb_data_store.c +++ b/libglusterfs/src/gfdb/gfdb_data_store.c @@ -147,8 +147,7 @@ delete_conn_node (gfdb_conn_node_t *_conn_node) } else { if (IS_FIRST_NODE(db_conn_list, _conn_node)) { db_conn_list = list_entry (db_conn_list->conn_list.next, - gfdb_conn_node_t, - conn_list); + gfdb_conn_node_t, conn_list); } list_del(&_conn_node->conn_list); GF_FREE (_conn_node); @@ -176,8 +175,9 @@ out: /*Internal function: Used initialize/map db operation of * specified type of db plugin*/ static int -init_db_operations (gfdb_db_type_t gfdb_db_type, - gfdb_db_operations_t *gfdb_db_operations) { +init_db_operations (gfdb_db_type_t gfdb_db_type, + gfdb_db_operations_t *gfdb_db_operations) +{ int ret = -1; @@ -268,7 +268,7 @@ init_db (dict_t *args, gfdb_db_type_t gfdb_db_type) /*Calling the init_db_op of the respected db type*/ GF_ASSERT (db_operations_t->init_db_op); ret = db_operations_t->init_db_op (args, &_conn_node->gfdb_connection. - gf_db_connection); + gf_db_connection); if (ret) { gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_INIT_DB_FAILED, "Failed initializing database"); @@ -314,7 +314,7 @@ alloc_failed: int fini_db (gfdb_conn_node_t *_conn_node) { - int ret = -1; + int ret = -1; gfdb_db_operations_t *db_operations_t = NULL; CHECK_CONN_NODE_GOTO (_conn_node, empty); @@ -324,7 +324,7 @@ fini_db (gfdb_conn_node_t *_conn_node) GF_ASSERT (db_operations_t->fini_db_op); ret = db_operations_t->fini_db_op(&_conn_node->gfdb_connection. - gf_db_connection); + gf_db_connection); if (ret) { gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_CLOSE_CONNECTION_FAILED, "Failed close the db " @@ -366,9 +366,9 @@ out: * -ve value in case of failure*/ int insert_record (gfdb_conn_node_t *_conn_node, - gfdb_db_record_t *gfdb_db_record) + gfdb_db_record_t *gfdb_db_record) { - int ret = 0; + int ret = 0; gfdb_db_operations_t *db_operations_t = NULL; void *gf_db_connection = NULL; @@ -380,7 +380,7 @@ insert_record (gfdb_conn_node_t *_conn_node, if (db_operations_t->insert_record_op) { ret = db_operations_t->insert_record_op (gf_db_connection, - gfdb_db_record); + gfdb_db_record); if (ret) { gf_msg (GFDB_DATA_STORE, _gfdb_log_level (GF_LOG_ERROR, gfdb_db_record->ignore_errors), 0, @@ -407,9 +407,9 @@ insert_record (gfdb_conn_node_t *_conn_node, * -ve value in case of failure*/ int delete_record (gfdb_conn_node_t *_conn_node, - gfdb_db_record_t *gfdb_db_record) + gfdb_db_record_t *gfdb_db_record) { - int ret = 0; + int ret = 0; gfdb_db_operations_t *db_operations_t = NULL; void *gf_db_connection = NULL; @@ -421,7 +421,7 @@ delete_record (gfdb_conn_node_t *_conn_node, if (db_operations_t->delete_record_op) { ret = db_operations_t->delete_record_op (gf_db_connection, - gfdb_db_record); + gfdb_db_record); if (ret) { gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_DELETE_FAILED, "Delete operation " @@ -447,9 +447,11 @@ delete_record (gfdb_conn_node_t *_conn_node, * Returns : if successful return 0 or * -ve value in case of failure*/ int -find_all(gfdb_conn_node_t *_conn_node, gf_query_callback_t query_callback, - void *_query_cbk_args) { - int ret = 0; +find_all (gfdb_conn_node_t *_conn_node, + gf_query_callback_t query_callback, + void *_query_cbk_args) +{ + int ret = 0; gfdb_db_operations_t *db_operations_t = NULL; void *gf_db_connection = NULL; @@ -460,8 +462,8 @@ find_all(gfdb_conn_node_t *_conn_node, gf_query_callback_t query_callback, if (db_operations_t->find_all_op) { ret = db_operations_t->find_all_op (gf_db_connection, - query_callback, - _query_cbk_args); + query_callback, + _query_cbk_args); if (ret) { gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_FIND_OP_FAILED, "Find all operation " @@ -488,12 +490,13 @@ find_all(gfdb_conn_node_t *_conn_node, gf_query_callback_t query_callback, * Returns : if successful return 0 or * -ve value in case of failure*/ int -find_unchanged_for_time(gfdb_conn_node_t *_conn_node, - gf_query_callback_t query_callback, - void *_query_cbk_args, - gfdb_time_t *for_time) { +find_unchanged_for_time(gfdb_conn_node_t *_conn_node, + gf_query_callback_t query_callback, + void *_query_cbk_args, + gfdb_time_t *for_time) +{ - int ret = 0; + int ret = 0; gfdb_db_operations_t *db_operations_t = NULL; void *gf_db_connection = NULL; @@ -505,10 +508,8 @@ find_unchanged_for_time(gfdb_conn_node_t *_conn_node, if (db_operations_t->find_unchanged_for_time_op) { ret = db_operations_t->find_unchanged_for_time_op - (gf_db_connection, - query_callback, - _query_cbk_args, - for_time); + (gf_db_connection, query_callback, + _query_cbk_args, for_time); if (ret) { gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_FIND_OP_FAILED, "Find unchanged " @@ -533,12 +534,13 @@ find_unchanged_for_time(gfdb_conn_node_t *_conn_node, * Returns : if successful return 0 or * -ve value in case of failure*/ int -find_recently_changed_files(gfdb_conn_node_t *_conn_node, - gf_query_callback_t query_callback, - void *_query_cbk_args, - gfdb_time_t *from_time) { +find_recently_changed_files(gfdb_conn_node_t *_conn_node, + gf_query_callback_t query_callback, + void *_query_cbk_args, + gfdb_time_t *from_time) +{ - int ret = 0; + int ret = 0; gfdb_db_operations_t *db_operations_t = NULL; void *gf_db_connection = NULL; @@ -550,10 +552,8 @@ find_recently_changed_files(gfdb_conn_node_t *_conn_node, if (db_operations_t->find_recently_changed_files_op) { ret = db_operations_t->find_recently_changed_files_op ( - gf_db_connection, - query_callback, - _query_cbk_args, - from_time); + gf_db_connection, query_callback, + _query_cbk_args, from_time); if (ret) { gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_FIND_OP_FAILED, @@ -590,9 +590,9 @@ find_unchanged_for_time_freq(gfdb_conn_node_t *_conn_node, gfdb_time_t *for_time, int write_freq_thresold, int read_freq_thresold, - gf_boolean_t _clear_counters) { - - int ret = 0; + gf_boolean_t _clear_counters) +{ + int ret = 0; gfdb_db_operations_t *db_operations_t = NULL; void *gf_db_connection = NULL; @@ -604,13 +604,10 @@ find_unchanged_for_time_freq(gfdb_conn_node_t *_conn_node, if (db_operations_t->find_unchanged_for_time_freq_op) { ret = db_operations_t->find_unchanged_for_time_freq_op( - gf_db_connection, - query_callback, - _query_cbk_args, - for_time, - write_freq_thresold, - read_freq_thresold, - _clear_counters); + gf_db_connection, query_callback, + _query_cbk_args, for_time, + write_freq_thresold, read_freq_thresold, + _clear_counters); if (ret) { gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_FIND_OP_FAILED, @@ -646,9 +643,10 @@ find_recently_changed_files_freq(gfdb_conn_node_t *_conn_node, gfdb_time_t *from_time, int write_freq_thresold, int read_freq_thresold, - gf_boolean_t _clear_counters) { + gf_boolean_t _clear_counters) +{ - int ret = 0; + int ret = 0; gfdb_db_operations_t *db_operations_t = NULL; void *gf_db_connection = NULL; @@ -660,13 +658,10 @@ find_recently_changed_files_freq(gfdb_conn_node_t *_conn_node, if (db_operations_t->find_recently_changed_files_freq_op) { ret = db_operations_t->find_recently_changed_files_freq_op( - gf_db_connection, - query_callback, - _query_cbk_args, - from_time, - write_freq_thresold, - read_freq_thresold, - _clear_counters); + gf_db_connection, query_callback, + _query_cbk_args, from_time, + write_freq_thresold, read_freq_thresold, + _clear_counters); if (ret) { gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_FIND_OP_FAILED, @@ -691,9 +686,10 @@ find_recently_changed_files_freq(gfdb_conn_node_t *_conn_node, **/ int -clear_files_heat (gfdb_conn_node_t *conn_node) { - int ret = 0; - gfdb_db_operations_t *db_operations = NULL; +clear_files_heat (gfdb_conn_node_t *conn_node) +{ + int ret = 0; + gfdb_db_operations_t *db_operations = NULL; void *gf_db_connection = NULL; CHECK_CONN_NODE(conn_node); @@ -705,7 +701,7 @@ clear_files_heat (gfdb_conn_node_t *conn_node) { ret = db_operations->clear_files_heat_op (gf_db_connection); if (ret) { gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, - LG_MSG_FIND_OP_FAILED, + LG_MSG_INSERT_OR_UPDATE_FAILED, "Clear files heat operation failed"); } } @@ -728,8 +724,8 @@ clear_files_heat (gfdb_conn_node_t *conn_node) { int get_db_version (gfdb_conn_node_t *conn_node, char **version) { - int ret = 0; - gfdb_db_operations_t *db_operations = NULL; + int ret = 0; + gfdb_db_operations_t *db_operations = NULL; void *gf_db_connection = NULL; CHECK_CONN_NODE(conn_node); @@ -739,7 +735,7 @@ get_db_version (gfdb_conn_node_t *conn_node, char **version) if (db_operations->get_db_version) { ret = db_operations->get_db_version (gf_db_connection, - version); + version); if (ret < 0) { gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_FIND_OP_FAILED, @@ -751,11 +747,11 @@ get_db_version (gfdb_conn_node_t *conn_node, char **version) } int -get_db_setting (gfdb_conn_node_t *conn_node, char *param_key, +get_db_params (gfdb_conn_node_t *conn_node, char *param_key, char **param_value) { - int ret = -1; - gfdb_db_operations_t *db_operations = NULL; + int ret = -1; + gfdb_db_operations_t *db_operations = NULL; void *gf_db_connection = NULL; CHECK_CONN_NODE(conn_node); @@ -763,9 +759,10 @@ get_db_setting (gfdb_conn_node_t *conn_node, char *param_key, db_operations = &conn_node->gfdb_connection.gfdb_db_operations; gf_db_connection = conn_node->gfdb_connection.gf_db_connection; - if (db_operations->get_db_setting) { - ret = db_operations->get_db_setting (gf_db_connection, - param_key, param_value); + if (db_operations->get_db_params) { + ret = db_operations->get_db_params (gf_db_connection, + param_key, + param_value); if (ret < 0) { gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_FIND_OP_FAILED, @@ -777,6 +774,35 @@ get_db_setting (gfdb_conn_node_t *conn_node, char *param_key, } +int +set_db_params (gfdb_conn_node_t *conn_node, char *param_key, + char *param_value) +{ + int ret = -1; + gfdb_db_operations_t *db_operations = NULL; + void *gf_db_connection = NULL; + + CHECK_CONN_NODE(conn_node); + + db_operations = &conn_node->gfdb_connection.gfdb_db_operations; + gf_db_connection = conn_node->gfdb_connection.gf_db_connection; + + if (db_operations->set_db_params) { + ret = db_operations->set_db_params (gf_db_connection, + param_key, + param_value); + if (ret < 0) { + gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, + LG_MSG_INSERT_OR_UPDATE_FAILED, + "Failed to set database setting"); + } + } + + return ret; +} + + + static const char *get_db_path_key() @@ -795,7 +821,8 @@ void get_gfdb_methods (gfdb_methods_t *methods) find_recently_changed_files_freq; methods->clear_files_heat = clear_files_heat; methods->get_db_version = get_db_version; - methods->get_db_setting = get_db_setting; + methods->get_db_params = get_db_params; + methods->set_db_params = set_db_params; methods->get_db_path_key = get_db_path_key; /* Query Record related functions */ diff --git a/libglusterfs/src/gfdb/gfdb_data_store.h b/libglusterfs/src/gfdb/gfdb_data_store.h index 5d25fa44a4a..1e8c3ebe6ad 100644 --- a/libglusterfs/src/gfdb/gfdb_data_store.h +++ b/libglusterfs/src/gfdb/gfdb_data_store.h @@ -278,7 +278,7 @@ char *(*get_db_path_key_t)(); /*Libgfdb API Function: Clear the heat for all the files * * Arguments: - * _conn_node : GFDB Connection node + * _conn_node : GFDB Connection node * * Returns : if successful return 0 or * -ve value in case of failure @@ -292,10 +292,10 @@ typedef int (*clear_files_heat_t) (gfdb_conn_node_t *_conn_node); /* Libgfdb API Function: Function to extract version of the db * Arguments: - * gfdb_conn_node_t *_conn_node : GFDB Connection node - * char **version : the version is extracted as a string and will be stored in - * this variable. The freeing of the memory should be done by - * the caller. + * gfdb_conn_node_t *_conn_node : GFDB Connection node + * char **version : the version is extracted as a string + * and will be stored in this variable. + * The freeing of the memory should be done by the caller. * Return: * On success return the length of the version string that is * extracted. @@ -308,28 +308,47 @@ typedef int (*get_db_version_t)(gfdb_conn_node_t *_conn_node, char **version); -/* Libgfdb API Function: Function to extract setting from the db +/* Libgfdb API Function: Function to extract param from the db * Arguments: - * gfdb_conn_node_t *_conn_node : GFDB Connection node - * char *param_key : setting to be extracted - * char **param_value : the value of the setting that is + * gfdb_conn_node_t *_conn_node : GFDB Connection node + * char *param_key : param to be extracted + * char **param_value : the value of the param that is * extracted. This function will allocate memory * to pragma_value. The caller should free the memory. * Return: - * On success return the lenght of the pragma/setting value that is + * On success return the lenght of the param value that is * extracted. * On failure return -1 * */ int -get_db_setting (gfdb_conn_node_t *_conn_node, +get_db_params (gfdb_conn_node_t *_conn_node, char *param_key, char **param_value); -typedef int (*get_db_setting_t)(gfdb_conn_node_t *db_conn, +typedef int (*get_db_params_t)(gfdb_conn_node_t *db_conn, char *param_key, char **param_value); +/* Libgfdb API Function: Function to set db params + * Arguments: + * gfdb_conn_node_t *_conn_node : GFDB Connection node + * char *param_key : param to be set + * char *param_value : param value + * Return: + * On success return 0 + * On failure return -1 + * */ +int +set_db_params (gfdb_conn_node_t *_conn_node, + char *param_key, + char *param_value); + +typedef int (*set_db_params_t)(gfdb_conn_node_t *db_conn, + char *param_key, + char *param_value); + + typedef struct gfdb_methods_s { init_db_t init_db; @@ -340,7 +359,8 @@ typedef struct gfdb_methods_s { find_recently_changed_files_freq_t find_recently_changed_files_freq; clear_files_heat_t clear_files_heat; get_db_version_t get_db_version; - get_db_setting_t get_db_setting; + get_db_params_t get_db_params; + set_db_params_t set_db_params; /* Do not expose dbpath directly. Expose it via an */ /* access function: get_db_path_key(). */ char *dbpath; diff --git a/libglusterfs/src/gfdb/gfdb_data_store_types.h b/libglusterfs/src/gfdb/gfdb_data_store_types.h index d79bf41a8c9..1acbdf2f99f 100644 --- a/libglusterfs/src/gfdb/gfdb_data_store_types.h +++ b/libglusterfs/src/gfdb/gfdb_data_store_types.h @@ -52,7 +52,6 @@ typedef enum gf_db_operation { #define GF_COL_GF_ID "GF_ID" #define GF_COL_GF_PID "GF_PID" #define GF_COL_FILE_NAME "FNAME" -#define GF_COL_FPATH "FPATH" #define GF_COL_WSEC "W_SEC" #define GF_COL_WMSEC "W_MSEC" #define GF_COL_UWSEC "UW_SEC" @@ -276,11 +275,9 @@ typedef struct gfdb_db_record { /* Parent GFID */ uuid_t pargfid; uuid_t old_pargfid; - /* File names and paths */ - char file_name[GF_NAME_MAX]; - char file_path[PATH_MAX]; - char old_file_name[GF_NAME_MAX]; - char old_path[PATH_MAX]; + /* File names */ + char file_name[GF_NAME_MAX + 1]; + char old_file_name[GF_NAME_MAX + 1]; /* FOP type and FOP path*/ gfdb_fop_type_t gfdb_fop_type; gfdb_fop_path_t gfdb_fop_path; @@ -489,10 +486,15 @@ typedef int (*gfdb_clear_files_heat_t)(void *db_conn); typedef int (*gfdb_get_db_version_t)(void *db_conn, char **version); -typedef int (*gfdb_get_db_setting_t)(void *db_conn, +typedef int (*gfdb_get_db_params_t)(void *db_conn, char *param_key, char **param_value); +typedef int (*gfdb_set_db_params_t)(void *db_conn, + char *param_key, + char *param_value); + + /*Data structure holding all the above plugin function pointers*/ typedef struct gfdb_db_operations { @@ -509,7 +511,8 @@ typedef struct gfdb_db_operations { find_recently_changed_files_freq_op; gfdb_clear_files_heat_t clear_files_heat_op; gfdb_get_db_version_t get_db_version; - gfdb_get_db_setting_t get_db_setting; + gfdb_get_db_params_t get_db_params; + gfdb_set_db_params_t set_db_params; } gfdb_db_operations_t; /******************************************************************************* diff --git a/libglusterfs/src/gfdb/gfdb_sqlite3.c b/libglusterfs/src/gfdb/gfdb_sqlite3.c index d43911830ed..a2060fba7af 100644 --- a/libglusterfs/src/gfdb/gfdb_sqlite3.c +++ b/libglusterfs/src/gfdb/gfdb_sqlite3.c @@ -254,7 +254,9 @@ gf_sqlite3_fill_db_operations(gfdb_db_operations_t *gfdb_db_ops) gfdb_db_ops->get_db_version = gf_sqlite3_version; - gfdb_db_ops->get_db_setting = gf_sqlite3_pragma; + gfdb_db_ops->get_db_params = gf_sqlite3_pragma; + + gfdb_db_ops->set_db_params = gf_sqlite3_set_pragma; } @@ -300,7 +302,7 @@ apply_sql_params_db(gf_sql_connection_t *sql_conn, dict_t *param_dict) { int ret = -1; char *temp_str = NULL; - char sqlite3_config_str[PATH_MAX] = ""; + char sqlite3_config_str[GF_NAME_MAX] = ""; GF_ASSERT(sql_conn); GF_ASSERT(param_dict); @@ -526,15 +528,6 @@ int gf_sqlite3_insert(void *db_conn, gfdb_db_record_t *gfdb_db_record) GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, gfdb_db_record, out); - /*This is for debugging bug. Will be removed with a bug fix*/ - if ((GFDB_FOP_WIND == gfdb_db_record->gfdb_fop_path) && - (strncmp (gfdb_db_record->file_path, "<gfid", 5) == 0)) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_SKIP_PATH, - "Skip path <gfid fop=%d", - gfdb_db_record->gfdb_fop_type); - goto out; - } - switch (gfdb_db_record->gfdb_fop_path) { case GFDB_FOP_WIND: ret = gf_sql_insert_wind (sql_conn, gfdb_db_record); @@ -1267,7 +1260,7 @@ out: -/* Function to extract PRAGMA or setting from sqlite db +/* Function to extract PRAGMA from sqlite db * Input: * void *db_conn : Sqlite connection * char *pragma_key : PRAGMA or setting to be extracted @@ -1319,9 +1312,10 @@ gf_sqlite3_pragma (void *db_conn, char *pragma_key, char **pragma_value) ret = gf_asprintf (pragma_value, "%s", sqlite3_column_text (pre_stmt, 0)); if (ret <= 0) { gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_QUERY_FAILED, - "Failed to get version"); + "Failed to get %s from db", pragma_key); } + ret = 0; out: GF_FREE (sqlstring); @@ -1329,3 +1323,44 @@ out: return ret; } + +/* Function to set PRAGMA to sqlite db + * Input: + * void *db_conn : Sqlite connection + * char *pragma_key : PRAGMA to be set + * char *pragma_value : the value of the PRAGMA + * Return: + * On success return 0 + * On failure return -1 + * */ +int +gf_sqlite3_set_pragma (void *db_conn, char *pragma_key, char *pragma_value) +{ + int ret = -1; + gf_sql_connection_t *sql_conn = db_conn; + char sqlstring[GF_NAME_MAX] = ""; + char *db_pragma_value = NULL; + + CHECK_SQL_CONN (sql_conn, out); + GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, pragma_key, out); + GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, pragma_value, out); + + GF_SQLITE3_SET_PRAGMA(sqlstring, pragma_key, "%s", + pragma_value, ret, out); + + ret = gf_sqlite3_pragma (db_conn, pragma_key, &db_pragma_value); + if (ret < 0) { + gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_QUERY_FAILED, + "Failed to get %s pragma", pragma_key); + } else { + gf_msg (GFDB_STR_SQLITE3, GF_LOG_INFO, 0, 0, + "Value set on DB %s : %s", pragma_key, db_pragma_value); + } + GF_FREE (db_pragma_value); + + ret = 0; + +out: + + return ret; +} diff --git a/libglusterfs/src/gfdb/gfdb_sqlite3.h b/libglusterfs/src/gfdb/gfdb_sqlite3.h index f2b252faa05..9d0d996a322 100644 --- a/libglusterfs/src/gfdb/gfdb_sqlite3.h +++ b/libglusterfs/src/gfdb/gfdb_sqlite3.h @@ -47,7 +47,6 @@ do {\ "(GF_ID TEXT NOT NULL, "\ "GF_PID TEXT NOT NULL, "\ "FNAME TEXT NOT NULL, "\ - "FPATH TEXT NOT NULL, "\ "W_DEL_FLAG INTEGER NOT NULL DEFAULT 0, "\ "LINK_UPDATE INTEGER NOT NULL DEFAULT 0, "\ "PRIMARY KEY ( GF_ID, GF_PID, FNAME) "\ @@ -142,7 +141,8 @@ do {\ #define GF_SQLITE3_SET_PRAGMA(sqlite3_config_str, param_key, format, value,\ ret, error)\ do {\ - sprintf(sqlite3_config_str, "PRAGMA " param_key " = " format , value);\ + sprintf (sqlite3_config_str, "PRAGMA %s = " format , param_key,\ + value);\ ret = sqlite3_exec (sql_conn->sqlite3_db_conn, sqlite3_config_str,\ NULL, NULL, NULL);\ if (ret != SQLITE_OK) {\ @@ -169,7 +169,7 @@ do {\ #define GF_SQL_DEFAULT_CACHE_SIZE "1000" #define GF_SQL_DEFAULT_WAL_AUTOCHECKPOINT "1000" #define GF_SQL_DEFAULT_JOURNAL_MODE GF_SQL_JM_WAL -#define GF_SQL_DEFAULT_SYNC GF_SQL_SYNC_NORMAL +#define GF_SQL_DEFAULT_SYNC GF_SQL_SYNC_OFF #define GF_SQL_DEFAULT_AUTO_VACUUM GF_SQL_AV_NONE @@ -307,6 +307,20 @@ int gf_sqlite3_version (void *db_conn, char **version); * */ int gf_sqlite3_pragma (void *db_conn, char *pragma_key, char **pragma_value); +/* Function to set PRAGMA to sqlite db + * Input: + * void *db_conn : Sqlite connection + * char *pragma_key : PRAGMA to be set + * char *pragma_value : the value of the PRAGMA + * Return: + * On success return 0 + * On failure return -1 + * */ +int +gf_sqlite3_set_pragma (void *db_conn, char *pragma_key, char *pragma_value); + + + void gf_sqlite3_fill_db_operations (gfdb_db_operations_t *gfdb_db_ops); diff --git a/libglusterfs/src/gfdb/gfdb_sqlite3_helper.c b/libglusterfs/src/gfdb/gfdb_sqlite3_helper.c index 17480e1ff4a..906fdd261f7 100644 --- a/libglusterfs/src/gfdb/gfdb_sqlite3_helper.c +++ b/libglusterfs/src/gfdb/gfdb_sqlite3_helper.c @@ -319,7 +319,6 @@ gf_sql_insert_link (gf_sql_connection_t *sql_conn, char *gfid, char *pargfid, char *basename, - char *basepath, gf_boolean_t link_consistency, gf_boolean_t ignore_errors) { @@ -329,16 +328,15 @@ gf_sql_insert_link (gf_sql_connection_t *sql_conn, sprintf (insert_str, "INSERT INTO " GF_FILE_LINK_TABLE - " (GF_ID, GF_PID, FNAME, FPATH," + " (GF_ID, GF_PID, FNAME," " W_DEL_FLAG, LINK_UPDATE) " - " VALUES (?, ?, ?, ?, 0, %d);", + " VALUES (?, ?, ?, 0, %d);", link_consistency); CHECK_SQL_CONN (sql_conn, out); GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, gfid, out); GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, pargfid, out); GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, basename, out); - GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, basepath, out); /*Prepare statement*/ ret = sqlite3_prepare (sql_conn->sqlite3_db_conn, insert_str, -1, @@ -387,26 +385,14 @@ gf_sql_insert_link (gf_sql_connection_t *sql_conn, goto out; } - /*Bind basepath*/ - ret = sqlite3_bind_text (insert_stmt, 4, basepath, -1, NULL); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_BINDING_FAILED, - "Failed binding basepath %s : " - "%s", basepath, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - /*Execute the prepare statement*/ if (sqlite3_step (insert_stmt) != SQLITE_DONE) { gf_msg (GFDB_STR_SQLITE3, _gfdb_log_level (GF_LOG_ERROR, ignore_errors), 0, LG_MSG_EXEC_FAILED, "Failed executing the prepared " - "stmt %s %s %s %s %s : %s", - gfid, pargfid, basename, basepath, insert_str, + "stmt %s %s %s %s : %s", + gfid, pargfid, basename, insert_str, sqlite3_errmsg (sql_conn->sqlite3_db_conn)); ret = -1; goto out; @@ -425,7 +411,6 @@ gf_sql_update_link (gf_sql_connection_t *sql_conn, char *gfid, char *pargfid, char *basename, - char *basepath, char *old_pargfid, char *old_basename, gf_boolean_t link_consistency, @@ -437,16 +422,15 @@ gf_sql_update_link (gf_sql_connection_t *sql_conn, sprintf (insert_str, "INSERT INTO " GF_FILE_LINK_TABLE - " (GF_ID, GF_PID, FNAME, FPATH," + " (GF_ID, GF_PID, FNAME," " W_DEL_FLAG, LINK_UPDATE) " - " VALUES (? , ?, ?, ?, 0, %d);", + " VALUES (? , ?, ?, 0, %d);", link_consistency); CHECK_SQL_CONN (sql_conn, out); GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, gfid, out); GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, pargfid, out); GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, basename, out); - GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, basepath, out); GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, old_pargfid, out); GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, old_basename, out); @@ -513,17 +497,6 @@ gf_sql_update_link (gf_sql_connection_t *sql_conn, goto out; } - /*Bind new basepath*/ - ret = sqlite3_bind_text (insert_stmt, 4, basepath, -1, NULL); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_BINDING_FAILED, "Failed binding basename %s : " - "%s", basepath, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - /*Execute the prepare statement*/ if (sqlite3_step (insert_stmt) != SQLITE_DONE) { gf_msg (GFDB_STR_SQLITE3, @@ -805,7 +778,6 @@ gf_sql_insert_wind (gf_sql_connection_t *sql_conn, ret = gf_sql_insert_link(sql_conn, gfid_str, pargfid_str, gfdb_db_record->file_name, - gfdb_db_record->file_path, gfdb_db_record->link_consistency, _gf_true); if (ret) { @@ -869,7 +841,6 @@ gf_sql_insert_wind (gf_sql_connection_t *sql_conn, ret = gf_sql_update_link (sql_conn, gfid_str, pargfid_str, gfdb_db_record->file_name, - gfdb_db_record->file_path, old_pargfid_str, gfdb_db_record->old_file_name, gfdb_db_record-> @@ -891,7 +862,6 @@ gf_sql_insert_wind (gf_sql_connection_t *sql_conn, ret = gf_sql_insert_link (sql_conn, gfid_str, pargfid_str, gfdb_db_record->file_name, - gfdb_db_record->file_path, gfdb_db_record-> link_consistency, gfdb_db_record->ignore_errors); |