From 96c4c3c47c914aced8864e7d178a4d57f7fced05 Mon Sep 17 00:00:00 2001
From: Tamar Shacked <tshacked@redhat.com>
Date: Sun, 6 Jun 2021 14:26:18 +0300
Subject: [PATCH 579/584] cli: changing rebal task ID to "None" in case status
is being reset
Rebalance status is being reset during replace/reset-brick operations.
This cause 'volume status' to shows rebalance as "not started".
Fix:
change rebalance-status to "reset due to (replace|reset)-brick"
Backport of:
> Upstream-patch-link: https://github.com/gluster/glusterfs/pull/1869
> Change-Id: Ia73a8bea3dcd8e51acf4faa6434c3cb0d09856d0
> Signed-off-by: Tamar Shacked <tshacked@redhat.com>
> Fixes: #1717
BUG: 1889966
Signed-off-by: Tamar Shacked <tshacked@redhat.com>
Change-Id: Ia73a8bea3dcd8e51acf4faa6434c3cb0d09856d0
Reviewed-on: https://code.engineering.redhat.com/gerrit/c/rhs-glusterfs/+/245402
Tested-by: RHGS Build Bot <nigelb@redhat.com>
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
---
cli/src/cli-rpc-ops.c | 15 ++++++-
rpc/xdr/src/cli1-xdr.x | 2 +
tests/bugs/glusterd/reset-rebalance-state.t | 46 ++++++++++++++++++++++
xlators/mgmt/glusterd/src/glusterd-replace-brick.c | 4 +-
xlators/mgmt/glusterd/src/glusterd-reset-brick.c | 3 +-
5 files changed, 65 insertions(+), 5 deletions(-)
create mode 100644 tests/bugs/glusterd/reset-rebalance-state.t
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c
index 51b5447..4167c68 100644
--- a/cli/src/cli-rpc-ops.c
+++ b/cli/src/cli-rpc-ops.c
@@ -72,6 +72,8 @@ char *cli_vol_task_status_str[] = {"not started",
"fix-layout stopped",
"fix-layout completed",
"fix-layout failed",
+ "reset due to replace-brick",
+ "reset due to reset-brick",
"unknown"};
int32_t
@@ -8357,12 +8359,21 @@ cli_print_volume_status_tasks(dict_t *dict)
ret = dict_get_str(dict, key, &task_id_str);
if (ret)
return;
- cli_out("%-20s : %-20s", "ID", task_id_str);
snprintf(key, sizeof(key), "task%d.status", i);
ret = dict_get_int32(dict, key, &status);
- if (ret)
+ if (ret) {
+ cli_out("%-20s : %-20s", "ID", task_id_str);
return;
+ }
+
+ if (!strcmp(op, "Rebalance") &&
+ (status == GF_DEFRAG_STATUS_RESET_DUE_REPLACE_BRC ||
+ status == GF_DEFRAG_STATUS_RESET_DUE_RESET_BRC)) {
+ task_id_str = "None";
+ }
+
+ cli_out("%-20s : %-20s", "ID", task_id_str);
snprintf(task, sizeof(task), "task%d", i);
diff --git a/rpc/xdr/src/cli1-xdr.x b/rpc/xdr/src/cli1-xdr.x
index 777cb00..17d96f1 100644
--- a/rpc/xdr/src/cli1-xdr.x
+++ b/rpc/xdr/src/cli1-xdr.x
@@ -45,6 +45,8 @@
GF_DEFRAG_STATUS_LAYOUT_FIX_STOPPED,
GF_DEFRAG_STATUS_LAYOUT_FIX_COMPLETE,
GF_DEFRAG_STATUS_LAYOUT_FIX_FAILED,
+ GF_DEFRAG_STATUS_RESET_DUE_REPLACE_BRC,
+ GF_DEFRAG_STATUS_RESET_DUE_RESET_BRC,
GF_DEFRAG_STATUS_MAX
};
diff --git a/tests/bugs/glusterd/reset-rebalance-state.t b/tests/bugs/glusterd/reset-rebalance-state.t
new file mode 100644
index 0000000..829d2b1
--- /dev/null
+++ b/tests/bugs/glusterd/reset-rebalance-state.t
@@ -0,0 +1,46 @@
+#!/bin/bash
+
+. $(dirname $0)/../../include.rc
+. $(dirname $0)/../../cluster.rc
+. $(dirname $0)/../../volume.rc
+
+
+get_rebalance_status() {
+ $CLI volume status $V0 | egrep ^"Status " | awk '{print $3}'
+}
+
+run_rebal_check_status() {
+ TEST $CLI volume rebalance $V0 start
+ EXPECT_WITHIN $REBALANCE_TIMEOUT "completed" rebalance_status_field $V0
+ REBAL_STATE=$(get_rebalance_status)
+ TEST [ $REBAL_STATE == "completed" ]
+}
+
+replace_brick_check_status() {
+ TEST $CLI volume replace-brick $V0 $H0:$B0/${V0}1 $H0:$B0/${V0}1_replace commit force
+ REBAL_STATE=$(get_rebalance_status)
+ TEST [ $REBAL_STATE == "reset" ]
+}
+
+reset_brick_check_status() {
+ TEST $CLI volume reset-brick $V0 $H0:$B0/${V0}2 start
+ TEST $CLI volume reset-brick $V0 $H0:$B0/${V0}2 $H0:$B0/${V0}2 commit force
+ REBAL_STATE=$(get_rebalance_status)
+ TEST [ $REBAL_STATE == "reset" ]
+}
+
+cleanup;
+
+TEST glusterd;
+TEST pidof glusterd;
+
+TEST $CLI volume info;
+TEST $CLI volume create $V0 replica 3 $H0:$B0/${V0}{1..6} force;
+TEST $CLI volume start $V0;
+
+run_rebal_check_status;
+replace_brick_check_status;
+reset_brick_check_status;
+
+cleanup;
+
diff --git a/xlators/mgmt/glusterd/src/glusterd-replace-brick.c b/xlators/mgmt/glusterd/src/glusterd-replace-brick.c
index 0615081..80b80e4 100644
--- a/xlators/mgmt/glusterd/src/glusterd-replace-brick.c
+++ b/xlators/mgmt/glusterd/src/glusterd-replace-brick.c
@@ -548,8 +548,8 @@ glusterd_op_replace_brick(dict_t *dict, dict_t *rsp_dict)
(void)glusterd_svcs_manager(volinfo);
goto out;
}
-
- volinfo->rebal.defrag_status = 0;
+ if (volinfo->rebal.defrag_status != GF_DEFRAG_STATUS_NOT_STARTED)
+ volinfo->rebal.defrag_status = GF_DEFRAG_STATUS_RESET_DUE_REPLACE_BRC;
ret = glusterd_svcs_manager(volinfo);
if (ret) {
diff --git a/xlators/mgmt/glusterd/src/glusterd-reset-brick.c b/xlators/mgmt/glusterd/src/glusterd-reset-brick.c
index cf04ce8..19d7549 100644
--- a/xlators/mgmt/glusterd/src/glusterd-reset-brick.c
+++ b/xlators/mgmt/glusterd/src/glusterd-reset-brick.c
@@ -342,7 +342,8 @@ glusterd_op_reset_brick(dict_t *dict, dict_t *rsp_dict)
goto out;
}
- volinfo->rebal.defrag_status = 0;
+ if (volinfo->rebal.defrag_status != GF_DEFRAG_STATUS_NOT_STARTED)
+ volinfo->rebal.defrag_status = GF_DEFRAG_STATUS_RESET_DUE_RESET_BRC;
ret = glusterd_svcs_manager(volinfo);
if (ret) {
--
1.8.3.1