summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2020-04-23 18:59:47 +1000
committerAmitay Isaacs <amitay@samba.org>2020-05-22 06:41:45 +0000
commit53b73b9b0f99c9683fca043f4fee74be6a488c66 (patch)
treef2a8d2fc811bd3ab1ea3ade6827d6bfd210b46b0
parent5c8dfbbf9bea05c35fe1ce454ee47dbee5172722 (diff)
downloadsamba-53b73b9b0f99c9683fca043f4fee74be6a488c66.tar.gz
ctdb-daemon: Fix sorting of hot keys
The current code only ever swaps with slot 0. This will only ever happen with slots 0 and 1, so probably never sorts. Replace with qsort(). Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
-rw-r--r--ctdb/server/ctdb_call.c33
1 files changed, 19 insertions, 14 deletions
diff --git a/ctdb/server/ctdb_call.c b/ctdb/server/ctdb_call.c
index f833cac04c8..14baa797bd6 100644
--- a/ctdb/server/ctdb_call.c
+++ b/ctdb/server/ctdb_call.c
@@ -820,6 +820,21 @@ ctdb_defer_pinned_down_request(struct ctdb_context *ctdb, struct ctdb_db_context
return 0;
}
+static int hot_key_cmp(const void *a, const void *b)
+{
+ const struct ctdb_db_hot_key *ka = (const struct ctdb_db_hot_key *)a;
+ const struct ctdb_db_hot_key *kb = (const struct ctdb_db_hot_key *)b;
+
+ if (ka->count < kb->count) {
+ return -1;
+ }
+ if (ka->count > kb->count) {
+ return 1;
+ }
+
+ return 0;
+}
+
static void
ctdb_update_db_stat_hot_keys(struct ctdb_db_context *ctdb_db, TDB_DATA key,
unsigned int count)
@@ -890,20 +905,10 @@ ctdb_update_db_stat_hot_keys(struct ctdb_db_context *ctdb_db, TDB_DATA key,
ctdb_db->hot_keys[id].last_logged_count = count;
sort_keys:
- for (i = 1; i < MAX_HOT_KEYS; i++) {
- if (ctdb_db->hot_keys[i].count == 0) {
- continue;
- }
- if (ctdb_db->hot_keys[i].count < ctdb_db->hot_keys[0].count) {
- count = ctdb_db->hot_keys[i].count;
- ctdb_db->hot_keys[i].count = ctdb_db->hot_keys[0].count;
- ctdb_db->hot_keys[0].count = count;
-
- key = ctdb_db->hot_keys[i].key;
- ctdb_db->hot_keys[i].key = ctdb_db->hot_keys[0].key;
- ctdb_db->hot_keys[0].key = key;
- }
- }
+ qsort(&ctdb_db->hot_keys[0],
+ ctdb_db->statistics.num_hot_keys,
+ sizeof(struct ctdb_db_hot_key),
+ hot_key_cmp);
}
/*