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