From 681d4590bd7e13b742c399573da55c509eb5b2a2 Mon Sep 17 00:00:00 2001 From: Joseph Fernandes Date: Fri, 4 Mar 2016 08:55:09 +0530 Subject: tier/libgfdb: Ordering query results from libgfdb When querying we will order the query result to get the hotest or the coldest files in the queried list so that these files are migrated first. Now here we are giving priority to the write heat(time and counters), as it requires complex queries to have a composite ordering of write and read + it has it impact on performance. Backport of http://review.gluster.org/13607 > Change-Id: I2e0415dcfad4218b42c68fc5c2ed8d1f075ce9ea > Signed-off-by: Joseph Fernandes > Reviewed-on: http://review.gluster.org/13607 > Smoke: Gluster Build System > Tested-by: Joseph Fernandes > NetBSD-regression: NetBSD Build System > CentOS-regression: Gluster Build System > Reviewed-by: Dan Lambright Signed-off-by: Joseph Fernandes Change-Id: If5fad07f8d0f50016b10e256803abd5266cd708f BUG: 1323017 Reviewed-on: http://review.gluster.org/13881 Smoke: Gluster Build System Reviewed-by: Joseph Fernandes Tested-by: Joseph Fernandes NetBSD-regression: NetBSD Build System CentOS-regression: Gluster Build System Reviewed-by: Dan Lambright --- libglusterfs/src/gfdb/gfdb_sqlite3.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'libglusterfs/src') diff --git a/libglusterfs/src/gfdb/gfdb_sqlite3.c b/libglusterfs/src/gfdb/gfdb_sqlite3.c index abd96b7e68d..7e60d133f00 100644 --- a/libglusterfs/src/gfdb/gfdb_sqlite3.c +++ b/libglusterfs/src/gfdb/gfdb_sqlite3.c @@ -706,7 +706,11 @@ gf_sqlite3_find_recently_changed_files(void *db_conn, " OR " /*Second condition: For reads*/ "((" GF_COL_TB_RWSEC " * " TOSTRING(GFDB_MICROSEC) " + " - GF_COL_TB_RWMSEC ") >= ?) )", base_query_str); + GF_COL_TB_RWMSEC ") >= ?) )" + /* Order by write wind time in a descending order + * i.e most hot files w.r.t to write */ + " ORDER BY GF_FILE_TB.W_SEC DESC", + base_query_str); if (ret < 0) { gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_QUERY_FAILED, @@ -802,7 +806,11 @@ gf_sqlite3_find_unchanged_for_time (void *db_conn, " AND " /*Second condition: For reads*/ "((" GF_COL_TB_RWSEC " * " TOSTRING(GFDB_MICROSEC) " + " - GF_COL_TB_RWMSEC ") <= ?) )", base_query_str); + GF_COL_TB_RWMSEC ") <= ?) )" + /* Order by write wind time in a ascending order + * i.e most cold files w.r.t to write */ + " ORDER BY GF_FILE_TB.W_SEC ASC", + base_query_str); if (ret < 0) { gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_QUERY_FAILED, @@ -909,7 +917,12 @@ gf_sqlite3_find_recently_changed_files_freq (void *db_conn, /*Second condition: For Reads */ "( ((" GF_COL_TB_RWSEC " * " TOSTRING(GFDB_MICROSEC) " + " GF_COL_TB_RWMSEC ") >= ?)" - " AND "" (" GF_COL_TB_RFC " >= ? ) ) )", base_query_str); + " AND "" (" GF_COL_TB_RFC " >= ? ) ) )" + /* Order by write wind time and write freq in a descending order + * i.e most hot files w.r.t to write */ + " ORDER BY GF_FILE_TB.W_SEC DESC, " + "GF_FILE_TB.WRITE_FREQ_CNTR DESC", + base_query_str); if (ret < 0) { gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_QUERY_FAILED, @@ -1055,7 +1068,7 @@ gf_sqlite3_find_unchanged_for_time_freq (void *db_conn, GF_COL_TB_WMSEC ") >= ? ) ) )" " AND " /*Second condition: For Reads - * Files that have read wind time smaller than for_time + * Files that have reaASCd wind time smaller than for_time * OR * File that have read wind time greater than for_time, * but write_frequency less than freq_write_cnt*/ @@ -1064,7 +1077,12 @@ gf_sqlite3_find_unchanged_for_time_freq (void *db_conn, " OR " "( (" GF_COL_TB_RFC " < ? ) AND" "((" GF_COL_TB_RWSEC " * " TOSTRING(GFDB_MICROSEC) " + " - GF_COL_TB_RWMSEC ") >= ? ) ) ) )", base_query_str); + GF_COL_TB_RWMSEC ") >= ? ) ) ) )" + /* Order by write wind time and write freq in ascending order + * i.e most cold files w.r.t to write */ + " ORDER BY GF_FILE_TB.W_SEC ASC, " + "GF_FILE_TB.WRITE_FREQ_CNTR ASC", + base_query_str); if (ret < 0) { gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_QUERY_FAILED, -- cgit