diff options
-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 | ||||
-rw-r--r-- | xlators/features/changetimerecorder/src/changetimerecorder.c | 61 | ||||
-rw-r--r-- | xlators/features/changetimerecorder/src/ctr-helper.c | 4 | ||||
-rw-r--r-- | xlators/features/changetimerecorder/src/ctr-helper.h | 11 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-volume-set.c | 99 |
10 files changed, 353 insertions, 175 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); diff --git a/xlators/features/changetimerecorder/src/changetimerecorder.c b/xlators/features/changetimerecorder/src/changetimerecorder.c index ce6978470ee..d339189edb8 100644 --- a/xlators/features/changetimerecorder/src/changetimerecorder.c +++ b/xlators/features/changetimerecorder/src/changetimerecorder.c @@ -107,7 +107,6 @@ ctr_lookup_wind(call_frame_t *frame, goto out; }; ctr_local = frame->local; - ctr_local->client_pid = frame->root->pid; /*Definately no internal fops will reach here*/ ctr_local->is_internal_fop = _gf_false; /*Dont record counters*/ @@ -129,8 +128,6 @@ ctr_lookup_wind(call_frame_t *frame, *((NEW_LINK_CX(ctr_inode_cx))->pargfid)); strcpy (CTR_DB_REC(ctr_local).file_name, NEW_LINK_CX(ctr_inode_cx)->basename); - strcpy (CTR_DB_REC(ctr_local).file_path, - NEW_LINK_CX(ctr_inode_cx)->basepath); /* Since we are in lookup we can ignore errors while * Inserting in the DB, because there may be many @@ -334,8 +331,7 @@ ctr_lookup (call_frame_t *frame, xlator_t *this, goto out; /*fill ctr link context*/ - FILL_CTR_LINK_CX(_link_cx, loc->parent->gfid, loc->name, - loc->path, out); + FILL_CTR_LINK_CX(_link_cx, loc->parent->gfid, loc->name, out); /* Fill ctr inode context*/ /* IA_IFREG : We assume its a file in the wind @@ -902,12 +898,10 @@ ctr_rename (call_frame_t *frame, xlator_t *this, loc_t *oldloc, CTR_IF_INTERNAL_FOP_THEN_GOTO (frame, xdata, out); /*Fill old link context*/ - FILL_CTR_LINK_CX(_olink_cx, oldloc->pargfid, oldloc->name, - oldloc->path, out); + FILL_CTR_LINK_CX(_olink_cx, oldloc->pargfid, oldloc->name, out); /*Fill new link context*/ - FILL_CTR_LINK_CX(_nlink_cx, newloc->pargfid, newloc->name, - newloc->path, out); + FILL_CTR_LINK_CX(_nlink_cx, newloc->pargfid, newloc->name, out); /*Fill ctr inode context*/ FILL_CTR_INODE_CONTEXT(_inode_cx, oldloc->inode->ia_type, @@ -1077,7 +1071,7 @@ ctr_unlink (call_frame_t *frame, xlator_t *this, CTR_IS_DISABLED_THEN_GOTO(this, out); /*Fill link context*/ - FILL_CTR_LINK_CX(_link_cx, loc->pargfid, loc->name, loc->path, out); + FILL_CTR_LINK_CX(_link_cx, loc->pargfid, loc->name, out); /*Fill ctr inode context*/ FILL_CTR_INODE_CONTEXT(_inode_cx, loc->inode->ia_type, @@ -1394,7 +1388,7 @@ ctr_mknod (call_frame_t *frame, xlator_t *this, gf_uuid_copy (gfid, uuid_req); /*fill ctr link context*/ - FILL_CTR_LINK_CX (_link_cx, loc->pargfid, loc->name, loc->path, out); + FILL_CTR_LINK_CX (_link_cx, loc->pargfid, loc->name, out); /*Fill ctr inode context*/ FILL_CTR_INODE_CONTEXT (_inode_cx, loc->inode->ia_type, @@ -1485,7 +1479,7 @@ ctr_create (call_frame_t *frame, xlator_t *this, gf_uuid_copy (gfid, uuid_req); /*fill ctr link context*/ - FILL_CTR_LINK_CX(_link_cx, loc->pargfid, loc->name, loc->path, out); + FILL_CTR_LINK_CX(_link_cx, loc->pargfid, loc->name, out); /*Fill ctr inode context*/ FILL_CTR_INODE_CONTEXT(_inode_cx, loc->inode->ia_type, @@ -1567,8 +1561,7 @@ ctr_link (call_frame_t *frame, xlator_t *this, GF_ASSERT(frame->root); /*fill ctr link context*/ - FILL_CTR_LINK_CX(_link_cx, newloc->pargfid, newloc->name, - newloc->path, out); + FILL_CTR_LINK_CX(_link_cx, newloc->pargfid, newloc->name, out); /*Fill ctr inode context*/ FILL_CTR_INODE_CONTEXT(_inode_cx, oldloc->inode->ia_type, @@ -1881,7 +1874,7 @@ ctr_ipc_helper (xlator_t *this, dict_t *in_dict, goto out; } - ret = get_db_setting (priv->_db_conn, db_param_key, &db_param); + ret = get_db_params (priv->_db_conn, db_param_key, &db_param); if (ret == -1 || !db_param) { goto out; } @@ -1955,7 +1948,6 @@ out: /******************************************************************************/ - int reconfigure (xlator_t *this, dict_t *options) { @@ -1966,7 +1958,7 @@ reconfigure (xlator_t *this, dict_t *options) priv = this->private; if (dict_get_str(options, "changetimerecorder.frequency", &temp_str)) { - gf_msg(this->name, GF_LOG_INFO, 0, CTR_MSG_SET, "set!"); + gf_msg(this->name, GF_LOG_INFO, 0, CTR_MSG_SET, "set"); } GF_OPTION_RECONF ("ctr-enabled", priv->enabled, options, @@ -1996,6 +1988,41 @@ reconfigure (xlator_t *this, dict_t *options) GF_OPTION_RECONF ("record-entry", priv->ctr_record_wind, options, bool, out); + + + + /* If database is sqlite */ + if (priv->gfdb_db_type == GFDB_SQLITE3) { + + /* AUTOCHECKPOINT */ + if (dict_get_str (options, GFDB_SQL_PARAM_WAL_AUTOCHECK, + &temp_str) == 0) { + ret = set_db_params (priv->_db_conn, + "wal_autocheckpoint", temp_str); + if (ret) { + gf_msg (this->name, GF_LOG_ERROR, 0, + CTR_MSG_SET_VALUE_TO_SQL_PARAM_FAILED, + "Failed to set %s", + GFDB_SQL_PARAM_WAL_AUTOCHECK); + } + } + + /* CACHE_SIZE */ + if (dict_get_str (options, GFDB_SQL_PARAM_CACHE_SIZE, &temp_str) + == 0) { + ret = set_db_params (priv->_db_conn, "cache_size", + temp_str); + if (ret) { + gf_msg (this->name, GF_LOG_ERROR, 0, + CTR_MSG_SET_VALUE_TO_SQL_PARAM_FAILED, + "Failed to set %s", + GFDB_SQL_PARAM_CACHE_SIZE); + } + } + } + + ret = 0; + out: return ret; diff --git a/xlators/features/changetimerecorder/src/ctr-helper.c b/xlators/features/changetimerecorder/src/ctr-helper.c index 44abf7d5142..263eb58db6f 100644 --- a/xlators/features/changetimerecorder/src/ctr-helper.c +++ b/xlators/features/changetimerecorder/src/ctr-helper.c @@ -138,8 +138,6 @@ fill_db_record_for_wind (xlator_t *this, *((NEW_LINK_CX(ctr_inode_cx))->pargfid)); strcpy (CTR_DB_REC(ctr_local).file_name, NEW_LINK_CX(ctr_inode_cx)->basename); - strcpy (CTR_DB_REC(ctr_local).file_path, - NEW_LINK_CX(ctr_inode_cx)->basepath); } /*rename fop*/ if (OLD_LINK_CX(ctr_inode_cx)) { @@ -147,8 +145,6 @@ fill_db_record_for_wind (xlator_t *this, *((OLD_LINK_CX(ctr_inode_cx))->pargfid)); strcpy (CTR_DB_REC(ctr_local).old_file_name, OLD_LINK_CX(ctr_inode_cx)->basename); - strcpy (CTR_DB_REC(ctr_local).old_path, - OLD_LINK_CX(ctr_inode_cx)->basepath); } } diff --git a/xlators/features/changetimerecorder/src/ctr-helper.h b/xlators/features/changetimerecorder/src/ctr-helper.h index 2b2dc3e17c7..486b9452eb4 100644 --- a/xlators/features/changetimerecorder/src/ctr-helper.h +++ b/xlators/features/changetimerecorder/src/ctr-helper.h @@ -97,8 +97,8 @@ do {\ 0, sizeof(gfdb_time_t));\ gf_uuid_clear (ctr_local->gfdb_db_record.gfid);\ gf_uuid_clear (ctr_local->gfdb_db_record.pargfid);\ - memset(ctr_local->gfdb_db_record.file_name, 0, PATH_MAX);\ - memset(ctr_local->gfdb_db_record.old_file_name, 0, PATH_MAX);\ + memset(ctr_local->gfdb_db_record.file_name, 0, GF_NAME_MAX + 1);\ + memset(ctr_local->gfdb_db_record.old_file_name, 0, GF_NAME_MAX + 1);\ ctr_local->gfdb_db_record.gfdb_fop_type = GFDB_FOP_INVALID_OP;\ ctr_local->ia_inode_type = IA_INVAL;\ } while (0) @@ -159,8 +159,6 @@ free_ctr_local (gf_ctr_local_t *ctr_local) typedef struct gf_ctr_link_context { uuid_t *pargfid; const char *basename; - /*basepath is redundent. Will go off*/ - const char *basepath; } gf_ctr_link_context_t; /*Context Carrier Structure for inodes*/ @@ -187,21 +185,18 @@ do {\ if (ctr_link_cx->pargfid)\ GF_ASSERT (*(ctr_link_cx->pargfid));\ GF_ASSERT (ctr_link_cx->basename);\ - GF_ASSERT (ctr_link_cx->basepath);\ };\ } while (0) /*Clear and fill the ctr_link_context with values*/ -#define FILL_CTR_LINK_CX(ctr_link_cx, _pargfid, _basename, _basepath, label)\ +#define FILL_CTR_LINK_CX(ctr_link_cx, _pargfid, _basename, label)\ do {\ GF_VALIDATE_OR_GOTO ("ctr", ctr_link_cx, label);\ GF_VALIDATE_OR_GOTO ("ctr", _pargfid, label);\ GF_VALIDATE_OR_GOTO ("ctr", _basename, label);\ - GF_VALIDATE_OR_GOTO ("ctr", _basepath, label);\ memset (ctr_link_cx, 0, sizeof (*ctr_link_cx));\ ctr_link_cx->pargfid = &_pargfid;\ ctr_link_cx->basename = _basename;\ - ctr_link_cx->basepath = _basepath;\ } while (0) #define NEW_LINK_CX(ctr_inode_cx)\ diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-set.c b/xlators/mgmt/glusterd/src/glusterd-volume-set.c index 593ae2aa833..f582009bb5b 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volume-set.c +++ b/xlators/mgmt/glusterd/src/glusterd-volume-set.c @@ -77,15 +77,15 @@ validate_tier_counters (glusterd_volinfo_t *volinfo, current_rt = get_tier_freq_threshold (volinfo, "cluster.read-freq-threshold"); if (current_rt == -1) { - snprintf (errstr, sizeof (errstr), " Failed to retrive value of" - "cluster.read-freq-threshold"); + snprintf (errstr, sizeof (errstr), " Failed to retrieve value" + " of cluster.read-freq-threshold"); goto out; } current_wt = get_tier_freq_threshold (volinfo, "cluster.write-freq-threshold"); if (current_wt == -1) { - snprintf (errstr, sizeof (errstr), " Failed to retrive value of" - "cluster.write-freq-threshold"); + snprintf (errstr, sizeof (errstr), " Failed to retrieve value " + "of cluster.write-freq-threshold"); goto out; } /* If record-counters is set to off */ @@ -133,6 +133,69 @@ out: } + +/* + * Validation function for ctr sql params + * features.ctr-sql-db-cachesize (Range: 1000 to 262144 pages) + * features.ctr-sql-db-wal-autocheckpoint (Range: 1000 to 262144 pages) + * */ +static int +validate_ctr_sql_params (glusterd_volinfo_t *volinfo, + dict_t *dict, + char *key, + char *value, + char **op_errstr) +{ + int ret = -1; + xlator_t *this = NULL; + char errstr[2048] = ""; + int origin_val = -1; + + this = THIS; + GF_ASSERT (this); + + + ret = gf_string2int (value, &origin_val); + if (ret) { + snprintf (errstr, sizeof (errstr), "%s is not a compatible " + "value. %s expects an integer value.", value, key); + ret = -1; + goto out; + } + + if (origin_val < 0) { + snprintf (errstr, sizeof (errstr), "%s is not a " + "compatible value. %s expects a positive" + "integer value.", value, key); + ret = -1; + goto out; + } + + if (strstr (key, "sql-db-cachesize") || + strstr (key, "sql-db-wal-autocheckpoint")) { + if ((origin_val < 1000) || (origin_val > 262144)) { + snprintf (errstr, sizeof (errstr), "%s is not a " + "compatible value. %s " + "expects a value between : " + "1000 to 262144.", + value, key); + ret = -1; + goto out; + } + } + + + ret = 0; +out: + if (ret) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + GD_MSG_INCOMPATIBLE_VALUE, "%s", errstr); + *op_errstr = gf_strdup (errstr); + } + return ret; +} + + /* Validation for tiering frequency thresholds * If any of the frequency thresholds are set to a non-zero value, * switch record-counters on, if not already on @@ -2444,6 +2507,34 @@ struct volopt_map_entry glusterd_volopt_map[] = { "hits an attempt to heal the database per " "inode is done" }, + { .key = "features.ctr-sql-db-cachesize", + .voltype = "features/changetimerecorder", + .value = "1000", + .option = "sql-db-cachesize", + .validate_fn = validate_ctr_sql_params, + .op_version = GD_OP_VERSION_3_7_7, + .description = "Defines the cache size of the sqlite database of " + "changetimerecorder xlator." + "The input to this option is in pages." + "Each page is 4096 bytes. Default value is 1000 " + "pages i.e ~ 4 MB. " + "The max value is 262144 pages i.e 1 GB and " + "the min value is 1000 pages i.e ~ 4 MB. " + }, + { .key = "features.ctr-sql-db-wal-autocheckpoint", + .voltype = "features/changetimerecorder", + .value = "1000", + .option = "sql-db-wal-autocheckpoint", + .validate_fn = validate_ctr_sql_params, + .op_version = GD_OP_VERSION_3_7_7, + .description = "Defines the autocheckpoint of the sqlite database of " + " changetimerecorder. " + "The input to this option is in pages. " + "Each page is 4096 bytes. Default value is 1000 " + "pages i.e ~ 4 MB." + "The max value is 262144 pages i.e 1 GB and " + "the min value is 1000 pages i.e ~4 MB." + }, #endif /* USE_GFDB */ { .key = "locks.trace", .voltype = "features/locks", |