From c6f1e2983c709f625e8634228b0c701b14e63d72 Mon Sep 17 00:00:00 2001 From: N Balachandran Date: Fri, 16 Sep 2016 22:23:51 +0530 Subject: dht/events: Added rebalance events The rebalance process will now send an event when it is complete. Also fixed a problem where the run-time was not always set causing spurious rebalance failure events to be sent. > Change-Id: Ib445171c78c9560940022bca20c887d31a9bb1ca > BUG: 1371874 > Signed-off-by: N Balachandran > Reviewed-on: http://review.gluster.org/15501 > Reviewed-by: Raghavendra G > Reviewed-by: Shyamsundar Ranganathan (cherry picked from commit e872917dbf4563703b8f396d7d30f8168ed646cd) Change-Id: Ia24038c04548a98aac899df10414585b988caa76 BUG: 1376477 Signed-off-by: N Balachandran Reviewed-on: http://review.gluster.org/15520 Smoke: Gluster Build System CentOS-regression: Gluster Build System NetBSD-regression: NetBSD Build System Reviewed-by: Atin Mukherjee --- xlators/cluster/dht/src/dht-rebalance.c | 56 +++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 6 deletions(-) (limited to 'xlators') diff --git a/xlators/cluster/dht/src/dht-rebalance.c b/xlators/cluster/dht/src/dht-rebalance.c index f7fa267b7f5..2fe786ec6ba 100644 --- a/xlators/cluster/dht/src/dht-rebalance.c +++ b/xlators/cluster/dht/src/dht-rebalance.c @@ -73,6 +73,49 @@ dht_set_global_defrag_error (gf_defrag_info_t *defrag, int ret) return; } +static int +dht_send_rebalance_event (xlator_t *this, gf_defrag_status_t status) +{ + int ret = -1; + char *volname = NULL; + char *tmpstr = NULL; + + eventtypes_t event = EVENT_LAST; + + switch (status) { + case GF_DEFRAG_STATUS_COMPLETE: + event = EVENT_VOLUME_REBALANCE_COMPLETE; + break; + case GF_DEFRAG_STATUS_FAILED: + event = EVENT_VOLUME_REBALANCE_FAILED; + break; + case GF_DEFRAG_STATUS_STOPPED: + event = EVENT_VOLUME_REBALANCE_STOP; + break; + default: + break; + + } + + tmpstr = gf_strdup (this->name); + if (tmpstr) { + volname = strtok(tmpstr, "-dht"); + } + + if (!volname) + volname = this->name; + + if (event != EVENT_LAST) { + ret = gf_event (event, "volume=%s", volname); + } + GF_FREE (tmpstr); + return ret; +} + + + + + static int dht_write_with_holes (xlator_t *to, fd_t *fd, struct iovec *vec, int count, int32_t size, off_t offset, struct iobref *iobref) @@ -3830,6 +3873,8 @@ out: defrag->defrag_status = GF_DEFRAG_STATUS_COMPLETE; } + dht_send_rebalance_event (this, defrag->defrag_status); + LOCK (&defrag->lock); { status = dict_new (); @@ -3980,12 +4025,11 @@ gf_defrag_status_get (gf_defrag_info_t *defrag, dict_t *dict) if (ret) gf_log (THIS->name, GF_LOG_WARNING, "failed to set status"); - if (elapsed) { - ret = dict_set_double (dict, "run-time", elapsed); - if (ret) - gf_log (THIS->name, GF_LOG_WARNING, - "failed to set run-time"); - } + + ret = dict_set_double (dict, "run-time", elapsed); + if (ret) + gf_log (THIS->name, GF_LOG_WARNING, + "failed to set run-time"); ret = dict_set_uint64 (dict, "failures", failures); if (ret) -- cgit