17b94a
From ecaa0f10820f4b6e803021919ce59a43aedf356b Mon Sep 17 00:00:00 2001
17b94a
From: Ravishankar N <ravishankar@redhat.com>
17b94a
Date: Thu, 4 Jun 2020 16:15:35 +0530
17b94a
Subject: [PATCH 402/449] afr: wake up index healer threads
17b94a
17b94a
...whenever shd is re-enabled after disabling or there is a change in
17b94a
`cluster.heal-timeout`, without needing to restart shd or waiting for the
17b94a
current `cluster.heal-timeout` seconds to expire.
17b94a
17b94a
> Upstream patch link:https://review.gluster.org/#/c/glusterfs/+/23288/
17b94a
> Change-Id: Ia5ebd7c8e9f5b54cba3199c141fdd1af2f9b9bfe
17b94a
> fixes: bz#1744548
17b94a
> Reported-by: Glen Kiessling <glenk1973@hotmail.com>
17b94a
> Signed-off-by: Ravishankar N <ravishankar@redhat.com>
17b94a
17b94a
BUG: 1764091
17b94a
Change-Id: I42aa0807f09b5a09510fe9efb4a1697dad3410a3
17b94a
Signed-off-by: Ravishankar N <ravishankar@redhat.com>
17b94a
Reviewed-on: https://code.engineering.redhat.com/gerrit/202368
17b94a
Tested-by: RHGS Build Bot <nigelb@redhat.com>
17b94a
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
17b94a
---
17b94a
 tests/bugs/replicate/bug-1744548-heal-timeout.t | 42 +++++++++++++++++++++++++
17b94a
 xlators/cluster/afr/src/afr-common.c            |  6 ++--
17b94a
 xlators/cluster/afr/src/afr-self-heald.c        | 14 ++++++---
17b94a
 xlators/cluster/afr/src/afr-self-heald.h        |  3 --
17b94a
 xlators/cluster/afr/src/afr.c                   | 10 ++++++
17b94a
 xlators/cluster/afr/src/afr.h                   |  2 ++
17b94a
 6 files changed, 66 insertions(+), 11 deletions(-)
17b94a
 create mode 100644 tests/bugs/replicate/bug-1744548-heal-timeout.t
17b94a
17b94a
diff --git a/tests/bugs/replicate/bug-1744548-heal-timeout.t b/tests/bugs/replicate/bug-1744548-heal-timeout.t
17b94a
new file mode 100644
17b94a
index 0000000..3cb73bc
17b94a
--- /dev/null
17b94a
+++ b/tests/bugs/replicate/bug-1744548-heal-timeout.t
17b94a
@@ -0,0 +1,42 @@
17b94a
+#!/bin/bash
17b94a
+
17b94a
+. $(dirname $0)/../../include.rc
17b94a
+. $(dirname $0)/../../volume.rc
17b94a
+. $(dirname $0)/../../afr.rc
17b94a
+
17b94a
+cleanup;
17b94a
+
17b94a
+TEST glusterd;
17b94a
+TEST pidof glusterd;
17b94a
+TEST $CLI volume create $V0 replica 3 $H0:$B0/${V0}{0,1,2}
17b94a
+TEST $CLI volume heal $V0 disable
17b94a
+TEST $CLI volume start $V0
17b94a
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V0 $H0 $B0/${V0}0
17b94a
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V0 $H0 $B0/${V0}1
17b94a
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V0 $H0 $B0/${V0}2
17b94a
+TEST ! $CLI volume heal $V0
17b94a
+
17b94a
+# Enable shd and verify that index crawl is triggered immediately.
17b94a
+TEST $CLI volume profile $V0 start
17b94a
+TEST $CLI volume profile $V0 info clear
17b94a
+TEST $CLI volume heal $V0 enable
17b94a
+TEST $CLI volume heal $V0
17b94a
+# Each brick does 3 opendirs, corresponding to dirty, xattrop and entry-changes
17b94a
+COUNT=`$CLI volume profile $V0 info incremental |grep OPENDIR|awk '{print $8}'|tr -d '\n'`
17b94a
+TEST [ "$COUNT" == "333" ]
17b94a
+
17b94a
+# Check that a change in heal-timeout is honoured immediately.
17b94a
+TEST $CLI volume set $V0 cluster.heal-timeout 5
17b94a
+sleep 10
17b94a
+COUNT=`$CLI volume profile $V0 info incremental |grep OPENDIR|awk '{print $8}'|tr -d '\n'`
17b94a
+# Two crawls must have happened.
17b94a
+TEST [ "$COUNT" == "666" ]
17b94a
+
17b94a
+# shd must not heal if it is disabled and heal-timeout is changed.
17b94a
+TEST $CLI volume heal $V0 disable
17b94a
+TEST $CLI volume profile $V0 info clear
17b94a
+TEST $CLI volume set $V0 cluster.heal-timeout 6
17b94a
+sleep 6
17b94a
+COUNT=`$CLI volume profile $V0 info incremental |grep OPENDIR|awk '{print $8}'|tr -d '\n'`
17b94a
+TEST [ -z $COUNT ]
17b94a
+cleanup;
17b94a
diff --git a/xlators/cluster/afr/src/afr-common.c b/xlators/cluster/afr/src/afr-common.c
17b94a
index 3690b84..eef7fd2 100644
17b94a
--- a/xlators/cluster/afr/src/afr-common.c
17b94a
+++ b/xlators/cluster/afr/src/afr-common.c
17b94a
@@ -5613,10 +5613,8 @@ afr_notify(xlator_t *this, int32_t event, void *data, void *data2)
17b94a
          * b) Already heard from everyone, but we now got a child-up
17b94a
          *    event.
17b94a
          */
17b94a
-        if (have_heard_from_all && priv->shd.iamshd) {
17b94a
-            for (i = 0; i < priv->child_count; i++)
17b94a
-                if (priv->child_up[i])
17b94a
-                    afr_selfheal_childup(this, i);
17b94a
+        if (have_heard_from_all) {
17b94a
+            afr_selfheal_childup(this, priv);
17b94a
         }
17b94a
     }
17b94a
 out:
17b94a
diff --git a/xlators/cluster/afr/src/afr-self-heald.c b/xlators/cluster/afr/src/afr-self-heald.c
17b94a
index 7eb1207..95ac5f2 100644
17b94a
--- a/xlators/cluster/afr/src/afr-self-heald.c
17b94a
+++ b/xlators/cluster/afr/src/afr-self-heald.c
17b94a
@@ -1258,12 +1258,18 @@ out:
17b94a
     return ret;
17b94a
 }
17b94a
 
17b94a
-int
17b94a
-afr_selfheal_childup(xlator_t *this, int subvol)
17b94a
+void
17b94a
+afr_selfheal_childup(xlator_t *this, afr_private_t *priv)
17b94a
 {
17b94a
-    afr_shd_index_healer_spawn(this, subvol);
17b94a
+    int subvol = 0;
17b94a
 
17b94a
-    return 0;
17b94a
+    if (!priv->shd.iamshd)
17b94a
+        return;
17b94a
+    for (subvol = 0; subvol < priv->child_count; subvol++)
17b94a
+        if (priv->child_up[subvol])
17b94a
+            afr_shd_index_healer_spawn(this, subvol);
17b94a
+
17b94a
+    return;
17b94a
 }
17b94a
 
17b94a
 int
17b94a
diff --git a/xlators/cluster/afr/src/afr-self-heald.h b/xlators/cluster/afr/src/afr-self-heald.h
17b94a
index 7de7c43..1990539 100644
17b94a
--- a/xlators/cluster/afr/src/afr-self-heald.h
17b94a
+++ b/xlators/cluster/afr/src/afr-self-heald.h
17b94a
@@ -60,9 +60,6 @@ typedef struct {
17b94a
 } afr_self_heald_t;
17b94a
 
17b94a
 int
17b94a
-afr_selfheal_childup(xlator_t *this, int subvol);
17b94a
-
17b94a
-int
17b94a
 afr_selfheal_daemon_init(xlator_t *this);
17b94a
 
17b94a
 int
17b94a
diff --git a/xlators/cluster/afr/src/afr.c b/xlators/cluster/afr/src/afr.c
17b94a
index 33258a0..8f9e71f 100644
17b94a
--- a/xlators/cluster/afr/src/afr.c
17b94a
+++ b/xlators/cluster/afr/src/afr.c
17b94a
@@ -141,6 +141,7 @@ reconfigure(xlator_t *this, dict_t *options)
17b94a
     afr_private_t *priv = NULL;
17b94a
     xlator_t *read_subvol = NULL;
17b94a
     int read_subvol_index = -1;
17b94a
+    int timeout_old = 0;
17b94a
     int ret = -1;
17b94a
     int index = -1;
17b94a
     char *qtype = NULL;
17b94a
@@ -150,6 +151,7 @@ reconfigure(xlator_t *this, dict_t *options)
17b94a
     char *locking_scheme = NULL;
17b94a
     gf_boolean_t consistent_io = _gf_false;
17b94a
     gf_boolean_t choose_local_old = _gf_false;
17b94a
+    gf_boolean_t enabled_old = _gf_false;
17b94a
 
17b94a
     priv = this->private;
17b94a
 
17b94a
@@ -255,11 +257,13 @@ reconfigure(xlator_t *this, dict_t *options)
17b94a
     GF_OPTION_RECONF("ensure-durability", priv->ensure_durability, options,
17b94a
                      bool, out);
17b94a
 
17b94a
+    enabled_old = priv->shd.enabled;
17b94a
     GF_OPTION_RECONF("self-heal-daemon", priv->shd.enabled, options, bool, out);
17b94a
 
17b94a
     GF_OPTION_RECONF("iam-self-heal-daemon", priv->shd.iamshd, options, bool,
17b94a
                      out);
17b94a
 
17b94a
+    timeout_old = priv->shd.timeout;
17b94a
     GF_OPTION_RECONF("heal-timeout", priv->shd.timeout, options, int32, out);
17b94a
 
17b94a
     GF_OPTION_RECONF("consistent-metadata", priv->consistent_metadata, options,
17b94a
@@ -283,6 +287,12 @@ reconfigure(xlator_t *this, dict_t *options)
17b94a
         consistent_io = _gf_false;
17b94a
     priv->consistent_io = consistent_io;
17b94a
 
17b94a
+    if (priv->shd.enabled) {
17b94a
+        if ((priv->shd.enabled != enabled_old) ||
17b94a
+            (timeout_old != priv->shd.timeout))
17b94a
+            afr_selfheal_childup(this, priv);
17b94a
+    }
17b94a
+
17b94a
     ret = 0;
17b94a
 out:
17b94a
     return ret;
17b94a
diff --git a/xlators/cluster/afr/src/afr.h b/xlators/cluster/afr/src/afr.h
17b94a
index e731cfa..18f1a6a 100644
17b94a
--- a/xlators/cluster/afr/src/afr.h
17b94a
+++ b/xlators/cluster/afr/src/afr.h
17b94a
@@ -1332,4 +1332,6 @@ afr_lookup_has_quorum(call_frame_t *frame, xlator_t *this,
17b94a
 void
17b94a
 afr_mark_new_entry_changelog(call_frame_t *frame, xlator_t *this);
17b94a
 
17b94a
+void
17b94a
+afr_selfheal_childup(xlator_t *this, afr_private_t *priv);
17b94a
 #endif /* __AFR_H__ */
17b94a
-- 
17b94a
1.8.3.1
17b94a