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