diff options
author | Joseph Fernandes <josferna@redhat.com> | 2015-09-11 09:36:06 -0400 |
---|---|---|
committer | Dan Lambright <dlambrig@redhat.com> | 2015-09-11 13:46:50 -0700 |
commit | 1d02d4bd9b5f7d730ab08961c17ef58204c8e8fd (patch) | |
tree | b37cf8fffe901013185e8011ea32b680640871d1 /libglusterfs | |
parent | 46674c5d5caaa183f8ee99efb64ef268eded91ab (diff) |
tier/ctr: Solving DB Lock issue due to write contention from db connections
This is a backport of 12031.
> Problem: The DB on the brick is been accessed by CTR, for write and
> tier migrator, for read and write. The write from tier migrator is reseting
> the heat counters after a cycle. Since we are using sqlite, two connections
> trying to write would cause a db lock contention. As a result CTR used to fail
> to update the db.
> Solution: Using the same db connection of CTR for reseting the heat counters.
> 1) Introducted a new IPC FOP for CTR
> 2) After the query do a ipc syncop to the underlying client xlator associated
> to the brick.
> 3) CTR in brick will catch the IPC FOP and cleat the heat counters.
> Change-Id: I53306bfc08dcdba479deb4ccc154896521336150
> BUG: 1260730
> Signed-off-by: Joseph Fernandes <josferna@redhat.com>
> Reviewed-on: http://review.gluster.org/12031
> Tested-by: NetBSD Build System <jenkins@build.gluster.org>
> Tested-by: Gluster Build System <jenkins@build.gluster.com>
Signed-off-by: Dan Lambright <dlambrig@redhat.com>
Conflicts:
xlators/cluster/dht/src/tier.c
Change-Id: I88aa289cdf21e216b42c3d8ccfb4e7e828b43772
BUG: 1262341
Reviewed-on: http://review.gluster.org/12161
Reviewed-by: Joseph Fernandes
Tested-by: NetBSD Build System <jenkins@build.gluster.org>
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Tested-by: Dan Lambright <dlambrig@redhat.com>
Diffstat (limited to 'libglusterfs')
-rw-r--r-- | libglusterfs/src/common-utils.h | 1 | ||||
-rw-r--r-- | libglusterfs/src/gfdb/gfdb_data_store.c | 42 | ||||
-rw-r--r-- | libglusterfs/src/gfdb/gfdb_data_store.h | 18 | ||||
-rw-r--r-- | libglusterfs/src/gfdb/gfdb_data_store_types.h | 4 | ||||
-rw-r--r-- | libglusterfs/src/gfdb/gfdb_sqlite3.c | 25 | ||||
-rw-r--r-- | libglusterfs/src/gfdb/gfdb_sqlite3.h | 2 | ||||
-rw-r--r-- | libglusterfs/src/gfdb/gfdb_sqlite3_helper.c | 4 |
7 files changed, 90 insertions, 6 deletions
diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h index 9c197aa67e4..8edb78bd43d 100644 --- a/libglusterfs/src/common-utils.h +++ b/libglusterfs/src/common-utils.h @@ -131,6 +131,7 @@ enum _gf_client_pid enum _gf_xlator_ipc_targets { GF_IPC_TARGET_CHANGELOG = 0, + GF_IPC_TARGET_CTR = 1 }; typedef enum _gf_boolean gf_boolean_t; diff --git a/libglusterfs/src/gfdb/gfdb_data_store.c b/libglusterfs/src/gfdb/gfdb_data_store.c index 8559a626e18..5859a3d09a0 100644 --- a/libglusterfs/src/gfdb/gfdb_data_store.c +++ b/libglusterfs/src/gfdb/gfdb_data_store.c @@ -678,6 +678,46 @@ find_recently_changed_files_freq(gfdb_conn_node_t *_conn_node, } + + +/*Libgfdb API Function: Clear the heat for all the files + * + * Arguments: + * _conn_node : GFDB Connection node + * + * Returns : if successful return 0 or + * -ve value in case of failure + **/ + +int +clear_files_heat (gfdb_conn_node_t *_conn_node) { + int ret = 0; + gfdb_db_operations_t *db_operations_t = NULL; + void *gf_db_connection = NULL; + + CHECK_CONN_NODE(_conn_node); + + db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations; + gf_db_connection = _conn_node->gfdb_connection.gf_db_connection; + + if (db_operations_t->clear_files_heat_op) { + ret = db_operations_t->clear_files_heat_op (gf_db_connection); + if (ret) { + gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, + LG_MSG_FIND_OP_FAILED, + "Clear files heat operation failed!"); + } + } + + return ret; +} + +static const +char *get_db_path() +{ + return GFDB_SQL_PARAM_DBPATH; +} + void get_gfdb_methods (gfdb_methods_t *methods) { methods->init_db = init_db; @@ -686,5 +726,5 @@ void get_gfdb_methods (gfdb_methods_t *methods) methods->find_recently_changed_files = find_recently_changed_files; methods->find_unchanged_for_time_freq = find_unchanged_for_time_freq; methods->find_recently_changed_files_freq = find_recently_changed_files_freq; - methods->dbpath = strdup(GFDB_SQL_PARAM_DBPATH); + methods->get_db_path = get_db_path; } diff --git a/libglusterfs/src/gfdb/gfdb_data_store.h b/libglusterfs/src/gfdb/gfdb_data_store.h index 977794df5cb..2eb7edf1338 100644 --- a/libglusterfs/src/gfdb/gfdb_data_store.h +++ b/libglusterfs/src/gfdb/gfdb_data_store.h @@ -170,7 +170,8 @@ typedef int (*find_recently_changed_files_t) (gfdb_conn_node_t *_conn_node, gfdb_time_t *from_time); - +typedef const +char * (*get_db_path_t) (); /*Libgfdb API Function: Query records/files that have not changed/accessed * from a time in past to current time, with @@ -241,6 +242,19 @@ typedef int (*find_recently_changed_files_freq_t) (gfdb_conn_node_t *_conn_node, int read_freq_thresold, gf_boolean_t _clear_counters); + + +/*Libgfdb API Function: Clear the heat for all the files + * + * Arguments: + * _conn_node : GFDB Connection node + * + * Returns : if successful return 0 or + * -ve value in case of failure + **/ +int +clear_files_heat (gfdb_conn_node_t *_conn_node); + typedef struct gfdb_methods_s { init_db_t init_db; fini_db_t fini_db; @@ -249,10 +263,12 @@ typedef struct gfdb_methods_s { find_unchanged_for_time_freq_t find_unchanged_for_time_freq; find_recently_changed_files_freq_t find_recently_changed_files_freq; char *dbpath; + get_db_path_t get_db_path; } gfdb_methods_t; void get_gfdb_methods (gfdb_methods_t *methods); typedef void (*get_gfdb_methods_t) (gfdb_methods_t *methods); + #endif diff --git a/libglusterfs/src/gfdb/gfdb_data_store_types.h b/libglusterfs/src/gfdb/gfdb_data_store_types.h index f603254ed0d..e21c480cb26 100644 --- a/libglusterfs/src/gfdb/gfdb_data_store_types.h +++ b/libglusterfs/src/gfdb/gfdb_data_store_types.h @@ -654,6 +654,7 @@ typedef int gf_boolean_t _clear_counters); +typedef int (*gfdb_clear_files_heat_t)(void *db_conn); /*Data structure holding all the above plugin function pointers*/ @@ -669,10 +670,9 @@ typedef struct gfdb_db_operations { find_unchanged_for_time_freq_op; gfdb_find_recently_changed_files_freq_t find_recently_changed_files_freq_op; + gfdb_clear_files_heat_t clear_files_heat_op; } gfdb_db_operations_t; - - /******************************************************************************* * * Database connection object: This objected is maitained by libgfdb for each diff --git a/libglusterfs/src/gfdb/gfdb_sqlite3.c b/libglusterfs/src/gfdb/gfdb_sqlite3.c index 27ebef39882..40817af4902 100644 --- a/libglusterfs/src/gfdb/gfdb_sqlite3.c +++ b/libglusterfs/src/gfdb/gfdb_sqlite3.c @@ -248,6 +248,8 @@ gf_sqlite3_fill_db_operations(gfdb_db_operations_t *gfdb_db_ops) gf_sqlite3_find_unchanged_for_time_freq; gfdb_db_ops->find_recently_changed_files_freq_op = gf_sqlite3_find_recently_changed_files_freq; + + gfdb_db_ops->clear_files_heat_op = gf_sqlite3_clear_files_heat; } @@ -1116,3 +1118,26 @@ out: sqlite3_finalize(prep_stmt); return ret; } + + +int +gf_sqlite3_clear_files_heat (void *db_conn) +{ + int ret = -1; + gf_sql_connection_t *sql_conn = db_conn; + + CHECK_SQL_CONN (sql_conn, out); + + ret = gf_sql_clear_counters (sql_conn); + if (ret) { + gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, + LG_MSG_CLEAR_COUNTER_FAILED, "Failed clearing " + "files heat!"); + goto out; + } + + ret = 0; +out: + return ret; +} + diff --git a/libglusterfs/src/gfdb/gfdb_sqlite3.h b/libglusterfs/src/gfdb/gfdb_sqlite3.h index 4c9489fbb7c..34235e07241 100644 --- a/libglusterfs/src/gfdb/gfdb_sqlite3.h +++ b/libglusterfs/src/gfdb/gfdb_sqlite3.h @@ -284,6 +284,8 @@ int gf_sqlite3_find_recently_changed_files_freq (void *db_conn, int read_freq_cnt, gf_boolean_t clear_counters); +int gf_sqlite3_clear_files_heat (void *db_conn); + void gf_sqlite3_fill_db_operations (gfdb_db_operations_t *gfdb_db_ops); #endif diff --git a/libglusterfs/src/gfdb/gfdb_sqlite3_helper.c b/libglusterfs/src/gfdb/gfdb_sqlite3_helper.c index 68e0991bff2..266840ab7b5 100644 --- a/libglusterfs/src/gfdb/gfdb_sqlite3_helper.c +++ b/libglusterfs/src/gfdb/gfdb_sqlite3_helper.c @@ -1195,10 +1195,10 @@ gf_sql_clear_counters (gf_sql_connection_t *sql_conn) CHECK_SQL_CONN (sql_conn, out); - query_str = "BEGIN;UPDATE " + query_str = "UPDATE " GF_FILE_TABLE " SET " GF_COL_READ_FREQ_CNTR " = 0 , " - GF_COL_WRITE_FREQ_CNTR " = 0 ;COMMIT;"; + GF_COL_WRITE_FREQ_CNTR " = 0 ;"; ret = sqlite3_exec (sql_conn->sqlite3_db_conn, query_str, NULL, NULL, &sql_strerror); |