14f8ab
From 759c12fc016a6399bb179aa0f930602c87d1e0f8 Mon Sep 17 00:00:00 2001
14f8ab
From: Barak Sason Rofman <bsasonro@redhat.com>
14f8ab
Date: Tue, 24 Nov 2020 12:56:10 +0200
14f8ab
Subject: [PATCH 480/480] DHT/Rebalance - Ensure Rebalance reports status only
14f8ab
 once upon stopping
14f8ab
14f8ab
Upon issuing rebalance stop command, the status of rebalance is being
14f8ab
logged twice to the log file, which can sometime result in an
14f8ab
inconsistent reports (one report states status stopped, while the other
14f8ab
may report something else).
14f8ab
14f8ab
This fix ensures rebalance reports it's status only once and that the
14f8ab
correct status is being reported.
14f8ab
14f8ab
Upstream:
14f8ab
> Reviewed-on: https://github.com/gluster/glusterfs/pull/1783
14f8ab
> fixes: #1782
14f8ab
> Change-Id: Id3206edfad33b3db60e9df8e95a519928dc7cb37
14f8ab
> Signed-off-by: Barak Sason Rofman bsasonro@redhat.com
14f8ab
14f8ab
BUG: 1286171
14f8ab
Change-Id: Id3206edfad33b3db60e9df8e95a519928dc7cb37
14f8ab
Signed-off-by: Barak Sason Rofman <bsasonro@redhat.com>
14f8ab
Reviewed-on: https://code.engineering.redhat.com/gerrit/218953
14f8ab
Tested-by: RHGS Build Bot <nigelb@redhat.com>
14f8ab
Reviewed-by: Csaba Henk <chenk@redhat.com>
14f8ab
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
14f8ab
---
14f8ab
 tests/bugs/distribute/bug-1286171.t     | 75 +++++++++++++++++++++++++++++++++
14f8ab
 xlators/cluster/dht/src/dht-common.c    |  2 +-
14f8ab
 xlators/cluster/dht/src/dht-common.h    |  2 +-
14f8ab
 xlators/cluster/dht/src/dht-rebalance.c | 63 ++++++++++++++-------------
14f8ab
 4 files changed, 108 insertions(+), 34 deletions(-)
14f8ab
 create mode 100644 tests/bugs/distribute/bug-1286171.t
14f8ab
14f8ab
diff --git a/tests/bugs/distribute/bug-1286171.t b/tests/bugs/distribute/bug-1286171.t
14f8ab
new file mode 100644
14f8ab
index 0000000..a2ca36f
14f8ab
--- /dev/null
14f8ab
+++ b/tests/bugs/distribute/bug-1286171.t
14f8ab
@@ -0,0 +1,75 @@
14f8ab
+#!/bin/bash
14f8ab
+
14f8ab
+. $(dirname $0)/../../include.rc
14f8ab
+. $(dirname $0)/../../cluster.rc
14f8ab
+. $(dirname $0)/../../volume.rc
14f8ab
+
14f8ab
+# Initialize
14f8ab
+#------------------------------------------------------------
14f8ab
+cleanup;
14f8ab
+
14f8ab
+volname=bug-1286171
14f8ab
+
14f8ab
+# Start glusterd
14f8ab
+TEST glusterd;
14f8ab
+TEST pidof glusterd;
14f8ab
+TEST $CLI volume info;
14f8ab
+
14f8ab
+# Create a volume
14f8ab
+TEST $CLI volume create $volname $H0:$B0/${volname}{1,2}
14f8ab
+
14f8ab
+# Verify volume creation
14f8ab
+EXPECT "$volname" volinfo_field $volname 'Volume Name';
14f8ab
+EXPECT 'Created' volinfo_field $volname 'Status';
14f8ab
+
14f8ab
+# Start volume and verify successful start
14f8ab
+TEST $CLI volume start $volname;
14f8ab
+EXPECT 'Started' volinfo_field $volname 'Status';
14f8ab
+TEST glusterfs --volfile-id=$volname --volfile-server=$H0 --entry-timeout=0 $M0;
14f8ab
+#------------------------------------------------------------
14f8ab
+
14f8ab
+# Create a nested dir structure and some file under MP
14f8ab
+cd $M0;
14f8ab
+for i in {1..5}
14f8ab
+do
14f8ab
+	mkdir dir$i
14f8ab
+	cd dir$i
14f8ab
+	for j in {1..5}
14f8ab
+	do
14f8ab
+		mkdir dir$i$j
14f8ab
+		cd dir$i$j
14f8ab
+		for k in {1..5}
14f8ab
+		do
14f8ab
+			mkdir dir$i$j$k
14f8ab
+			cd dir$i$j$k
14f8ab
+			touch {1..300}
14f8ab
+			cd ..
14f8ab
+		done
14f8ab
+		touch {1..300}
14f8ab
+		cd ..
14f8ab
+	done
14f8ab
+	touch {1..300}
14f8ab
+	cd ..
14f8ab
+done
14f8ab
+touch {1..300}
14f8ab
+
14f8ab
+# Add-brick and start rebalance
14f8ab
+TEST $CLI volume add-brick $volname $H0:$B0/${volname}4;
14f8ab
+TEST $CLI volume rebalance $volname start;
14f8ab
+
14f8ab
+# Let rebalance run for a while
14f8ab
+sleep 5
14f8ab
+
14f8ab
+# Stop rebalance
14f8ab
+TEST $CLI volume rebalance $volname stop;
14f8ab
+
14f8ab
+# Allow rebalance to stop
14f8ab
+sleep 5
14f8ab
+
14f8ab
+# Examine the logfile for errors
14f8ab
+cd /var/log/glusterfs;
14f8ab
+failures=`grep "failures:" ${volname}-rebalance.log | tail -1 | sed 's/.*failures: //; s/,.*//'`;
14f8ab
+
14f8ab
+TEST [ $failures == 0 ];
14f8ab
+
14f8ab
+cleanup;
14f8ab
diff --git a/xlators/cluster/dht/src/dht-common.c b/xlators/cluster/dht/src/dht-common.c
14f8ab
index 23cc80c..4db89df 100644
14f8ab
--- a/xlators/cluster/dht/src/dht-common.c
14f8ab
+++ b/xlators/cluster/dht/src/dht-common.c
14f8ab
@@ -10969,7 +10969,7 @@ dht_notify(xlator_t *this, int event, void *data, ...)
14f8ab
                 if ((cmd == GF_DEFRAG_CMD_STATUS) ||
14f8ab
                     (cmd == GF_DEFRAG_CMD_STATUS_TIER) ||
14f8ab
                     (cmd == GF_DEFRAG_CMD_DETACH_STATUS))
14f8ab
-                    gf_defrag_status_get(conf, output);
14f8ab
+                	gf_defrag_status_get(conf, output, _gf_false);
14f8ab
                 else if (cmd == GF_DEFRAG_CMD_START_DETACH_TIER)
14f8ab
                     gf_defrag_start_detach_tier(defrag);
14f8ab
                 else if (cmd == GF_DEFRAG_CMD_DETACH_START)
14f8ab
diff --git a/xlators/cluster/dht/src/dht-common.h b/xlators/cluster/dht/src/dht-common.h
14f8ab
index 9ec5b51..92f1b89 100644
14f8ab
--- a/xlators/cluster/dht/src/dht-common.h
14f8ab
+++ b/xlators/cluster/dht/src/dht-common.h
14f8ab
@@ -1252,7 +1252,7 @@ dht_fxattrop_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
14f8ab
                  int32_t op_ret, int32_t op_errno, dict_t *dict, dict_t *xdata);
14f8ab
 
14f8ab
 int
14f8ab
-gf_defrag_status_get(dht_conf_t *conf, dict_t *dict);
14f8ab
+gf_defrag_status_get(dht_conf_t *conf, dict_t *dict, gf_boolean_t log_status);
14f8ab
 
14f8ab
 void
14f8ab
 gf_defrag_set_pause_state(gf_tier_conf_t *tier_conf, tier_pause_state_t state);
14f8ab
diff --git a/xlators/cluster/dht/src/dht-rebalance.c b/xlators/cluster/dht/src/dht-rebalance.c
14f8ab
index d49a719..16ac16c 100644
14f8ab
--- a/xlators/cluster/dht/src/dht-rebalance.c
14f8ab
+++ b/xlators/cluster/dht/src/dht-rebalance.c
14f8ab
@@ -2720,7 +2720,6 @@ gf_defrag_migrate_single_file(void *opaque)
14f8ab
     iatt_ptr = &entry->d_stat;
14f8ab
 
14f8ab
     if (defrag->defrag_status != GF_DEFRAG_STATUS_STARTED) {
14f8ab
-        ret = -1;
14f8ab
         goto out;
14f8ab
     }
14f8ab
 
14f8ab
@@ -3833,7 +3832,6 @@ gf_defrag_fix_layout(xlator_t *this, gf_defrag_info_t *defrag, loc_t *loc,
14f8ab
         list_for_each_entry_safe(entry, tmp, &entries.list, list)
14f8ab
         {
14f8ab
             if (defrag->defrag_status != GF_DEFRAG_STATUS_STARTED) {
14f8ab
-                ret = 1;
14f8ab
                 goto out;
14f8ab
             }
14f8ab
 
14f8ab
@@ -4863,7 +4861,7 @@ out:
14f8ab
     LOCK(&defrag->lock);
14f8ab
     {
14f8ab
         status = dict_new();
14f8ab
-        gf_defrag_status_get(conf, status);
14f8ab
+        gf_defrag_status_get(conf, status, _gf_true);
14f8ab
         if (ctx && ctx->notify)
14f8ab
             ctx->notify(GF_EN_DEFRAG_STATUS, status);
14f8ab
         if (status)
14f8ab
@@ -4998,7 +4996,7 @@ out:
14f8ab
 }
14f8ab
 
14f8ab
 int
14f8ab
-gf_defrag_status_get(dht_conf_t *conf, dict_t *dict)
14f8ab
+gf_defrag_status_get(dht_conf_t *conf, dict_t *dict, gf_boolean_t log_status)
14f8ab
 {
14f8ab
     int ret = 0;
14f8ab
     uint64_t files = 0;
14f8ab
@@ -5095,34 +5093,35 @@ gf_defrag_status_get(dht_conf_t *conf, dict_t *dict)
14f8ab
         gf_log(THIS->name, GF_LOG_WARNING, "failed to set time-left");
14f8ab
 
14f8ab
 log:
14f8ab
-    switch (defrag->defrag_status) {
14f8ab
-        case GF_DEFRAG_STATUS_NOT_STARTED:
14f8ab
-            status = "not started";
14f8ab
-            break;
14f8ab
-        case GF_DEFRAG_STATUS_STARTED:
14f8ab
-            status = "in progress";
14f8ab
-            break;
14f8ab
-        case GF_DEFRAG_STATUS_STOPPED:
14f8ab
-            status = "stopped";
14f8ab
-            break;
14f8ab
-        case GF_DEFRAG_STATUS_COMPLETE:
14f8ab
-            status = "completed";
14f8ab
-            break;
14f8ab
-        case GF_DEFRAG_STATUS_FAILED:
14f8ab
-            status = "failed";
14f8ab
-            break;
14f8ab
-        default:
14f8ab
-            break;
14f8ab
-    }
14f8ab
+    if (log_status) {
14f8ab
+        switch (defrag->defrag_status) {
14f8ab
+            case GF_DEFRAG_STATUS_NOT_STARTED:
14f8ab
+                status = "not started";
14f8ab
+                break;
14f8ab
+            case GF_DEFRAG_STATUS_STARTED:
14f8ab
+                status = "in progress";
14f8ab
+                break;
14f8ab
+            case GF_DEFRAG_STATUS_STOPPED:
14f8ab
+                status = "stopped";
14f8ab
+                break;
14f8ab
+            case GF_DEFRAG_STATUS_COMPLETE:
14f8ab
+                status = "completed";
14f8ab
+                break;
14f8ab
+            case GF_DEFRAG_STATUS_FAILED:
14f8ab
+                status = "failed";
14f8ab
+                break;
14f8ab
+            default:
14f8ab
+                break;
14f8ab
+        }
14f8ab
 
14f8ab
-    gf_msg(THIS->name, GF_LOG_INFO, 0, DHT_MSG_REBALANCE_STATUS,
14f8ab
-           "Rebalance is %s. Time taken is %.2f secs", status, elapsed);
14f8ab
-    gf_msg(THIS->name, GF_LOG_INFO, 0, DHT_MSG_REBALANCE_STATUS,
14f8ab
-           "Files migrated: %" PRIu64 ", size: %" PRIu64 ", lookups: %" PRIu64
14f8ab
-           ", failures: %" PRIu64
14f8ab
-           ", skipped: "
14f8ab
-           "%" PRIu64,
14f8ab
-           files, size, lookup, failures, skipped);
14f8ab
+        gf_msg("DHT", GF_LOG_INFO, 0, DHT_MSG_REBALANCE_STATUS,
14f8ab
+               "Rebalance is %s. Time taken is %.2f secs "
14f8ab
+               "Files migrated: %" PRIu64 ", size: %" PRIu64
14f8ab
+               ", lookups: %" PRIu64 ", failures: %" PRIu64
14f8ab
+               ", skipped: "
14f8ab
+               "%" PRIu64,
14f8ab
+               status, elapsed, files, size, lookup, failures, skipped);
14f8ab
+    }
14f8ab
 out:
14f8ab
     return 0;
14f8ab
 }
14f8ab
@@ -5299,7 +5298,7 @@ gf_defrag_stop(dht_conf_t *conf, gf_defrag_status_t status, dict_t *output)
14f8ab
     defrag->defrag_status = status;
14f8ab
 
14f8ab
     if (output)
14f8ab
-        gf_defrag_status_get(conf, output);
14f8ab
+        gf_defrag_status_get(conf, output, _gf_false);
14f8ab
     ret = 0;
14f8ab
 out:
14f8ab
     gf_msg_debug("", 0, "Returning %d", ret);
14f8ab
-- 
14f8ab
1.8.3.1
14f8ab