From 840441debbacf9c6a35397219f6409c99675a40a Mon Sep 17 00:00:00 2001
From: N Balachandran <nbalacha@redhat.com>
Date: Thu, 17 Nov 2016 20:33:17 +0530
Subject: [PATCH 172/206] cli/rebalance: remove brick status is incorrect
If a remove brick operation is preceded by a fix-layout,
running remove-brick status on a node which does not
contain any of the bricks that were removed displays
fix-layout status.
The defrag_cmd variable was not updated in glusterd
for the nodes not hosting removed bricks causing the
status parsing to go wrong. This is now updated.
Also made minor modifications to the spacing in
the fix-layout status output.
Upstream patches:
master : http://review.gluster.org/15749
Change-Id: Ia4a7928644f85a646587061b0e9635a084c4ea83
BUG: 1386127
Signed-off-by: N Balachandran <nbalacha@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/90472
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
Tested-by: Atin Mukherjee <amukherj@redhat.com>
---
cli/src/cli-rpc-ops.c | 21 ++++++++++---
tests/bugs/distribute/bug-1389697.t | 42 ++++++++++++++++++++++++++
xlators/mgmt/glusterd/src/glusterd-brick-ops.c | 3 ++
3 files changed, 61 insertions(+), 5 deletions(-)
create mode 100644 tests/bugs/distribute/bug-1389697.t
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c
index 58884a2..bbb5894 100644
--- a/cli/src/cli-rpc-ops.c
+++ b/cli/src/cli-rpc-ops.c
@@ -1610,6 +1610,7 @@ gf_cli_print_rebalance_status (dict_t *dict, enum gf_task_types task_type,
int min = 0;
int sec = 0;
gf_boolean_t down = _gf_false;
+ gf_boolean_t fix_layout = _gf_false;
ret = dict_get_int32 (dict, "count", &count);
if (ret) {
@@ -1627,10 +1628,20 @@ gf_cli_print_rebalance_status (dict_t *dict, enum gf_task_types task_type,
goto out;
}
- if (status_rcd >= GF_DEFRAG_STATUS_LAYOUT_FIX_STARTED) {
- cli_out ("%10s %40s %18s", "Node", "status",
+ /* Fix layout will be sent to all nodes for the volume
+ so every status should be of type
+ GF_DEFRAG_STATUS_LAYOUT_FIX*
+ */
+
+ if ((task_type == GF_TASK_TYPE_REBALANCE)
+ && (status_rcd >= GF_DEFRAG_STATUS_LAYOUT_FIX_STARTED)) {
+ fix_layout = _gf_true;
+ }
+
+ if (fix_layout) {
+ cli_out ("%20s %40s %18s", "Node", "status",
"run time in h:m:s");
- cli_out ("%10s %40s %18s", "---------", "-----------",
+ cli_out ("%20s %40s %18s", "---------", "-----------",
"------------");
} else {
cli_out ("%40s %16s %13s %13s %13s %13s %20s %18s",
@@ -1739,8 +1750,8 @@ gf_cli_print_rebalance_status (dict_t *dict, enum gf_task_types task_type,
min = ((int) elapsed % 3600) / 60;
sec = ((int) elapsed % 3600) % 60;
- if (status_rcd >= GF_DEFRAG_STATUS_LAYOUT_FIX_STARTED) {
- cli_out ("%10s %40s %8d:%d:%d", node_name, status_str,
+ if (fix_layout) {
+ cli_out ("%20s %40s %8d:%d:%d", node_name, status_str,
hrs, min, sec);
} else {
if (size_str) {
diff --git a/tests/bugs/distribute/bug-1389697.t b/tests/bugs/distribute/bug-1389697.t
new file mode 100644
index 0000000..0d428b8
--- /dev/null
+++ b/tests/bugs/distribute/bug-1389697.t
@@ -0,0 +1,42 @@
+#!/bin/bash
+
+. $(dirname $0)/../../include.rc
+. $(dirname $0)/../../cluster.rc
+
+
+cleanup
+
+TEST launch_cluster 2;
+TEST $CLI_1 peer probe $H2;
+EXPECT_WITHIN $PROBE_TIMEOUT 1 peer_count
+
+TEST $CLI_1 volume create $V0 $H1:$B1/b1 $H1:$B1/b2 $H2:$B2/b3
+TEST $CLI_1 volume start $V0
+
+#Start a fix-layout
+TEST $CLI_1 volume rebalance $V0 fix-layout start
+
+#volume rebalance status should work
+TEST $CLI_1 volume rebalance $V0 status
+$CLI_1 volume rebalance $V0 status
+
+val=$($CLI_1 volume rebalance $V0 status |grep "fix-layout" 2>&1)
+val=$?
+TEST [ $val -eq 0 ];
+
+#Start a remove brick for the brick on H2
+TEST $CLI_1 volume remove-brick $V0 $H2:$B2/b3 start
+TEST $CLI_1 volume remove-brick $V0 $H2:$B2/b3 status
+
+#Check remove brick status from H1
+$CLI_1 volume remove-brick $V0 $H2:$B2/b3 status |grep "fix-layout" 2>&1
+val=$?
+TEST [ $val -eq 1 ];
+
+$CLI_1 volume remove-brick $V0 $H2:$B2/b3 status
+$CLI_2 volume remove-brick $V0 $H2:$B2/b3 status
+
+
+TEST $CLI_1 volume remove-brick $V0 $H2:$B2/b3 stop
+
+cleanup
diff --git a/xlators/mgmt/glusterd/src/glusterd-brick-ops.c b/xlators/mgmt/glusterd/src/glusterd-brick-ops.c
index 92e6386..971dac8 100644
--- a/xlators/mgmt/glusterd/src/glusterd-brick-ops.c
+++ b/xlators/mgmt/glusterd/src/glusterd-brick-ops.c
@@ -2646,7 +2646,10 @@ glusterd_op_remove_brick (dict_t *dict, char **op_errstr)
/* Reset defrag status to 'NOT STARTED' whenever a
* remove-brick/rebalance command is issued to remove
* stale information from previous run.
+ * Update defrag_cmd as well or it will only be done
+ * for nodes on which the brick to be removed exists.
*/
+ volinfo->rebal.defrag_cmd = cmd;
volinfo->rebal.defrag_status = GF_DEFRAG_STATUS_NOT_STARTED;
ret = dict_get_str (dict, GF_REMOVE_BRICK_TID_KEY, &task_id_str);
if (ret) {
--
2.9.3