14f8ab
From 2b2eb846c49caba13ab92ec66af20292e7780fc1 Mon Sep 17 00:00:00 2001
14f8ab
From: Ravishankar N <ravishankar@redhat.com>
14f8ab
Date: Tue, 11 Feb 2020 14:34:48 +0530
14f8ab
Subject: [PATCH 410/449] afr: prevent spurious entry heals leading to gfid
14f8ab
 split-brain
14f8ab
14f8ab
Problem:
14f8ab
In a hyperconverged setup with granular-entry-heal enabled, if a file is
14f8ab
recreated while one of the bricks is down, and an index heal is triggered
14f8ab
(with the brick still down), entry-self heal was doing a spurious heal
14f8ab
with just the 2 good bricks. It was doing a post-op leading to removal
14f8ab
of the filename from .glusterfs/indices/entry-changes as well as
14f8ab
erroneous setting of afr xattrs on the parent. When the brick came up,
14f8ab
the xattrs were cleared, resulting in the renamed file not getting
14f8ab
healed and leading to gfid split-brain and EIO on the mount.
14f8ab
14f8ab
Fix:
14f8ab
Proceed with entry heal only when shd can connect to all bricks of the replica,
14f8ab
just like in data and metadata heal.
14f8ab
14f8ab
BUG: 1804164
14f8ab
14f8ab
> Upstream patch:https://review.gluster.org/#/c/glusterfs/+/24109/
14f8ab
> fixes: bz#1801624
14f8ab
> Change-Id: I916ae26ad1fabf259bc6362da52d433b7223b17e
14f8ab
> Signed-off-by: Ravishankar N <ravishankar@redhat.com>
14f8ab
14f8ab
Change-Id: I23f57e543cff1e3f35eb8dbc60a2babfae6838c7
14f8ab
Signed-off-by: Ravishankar N <ravishankar@redhat.com>
14f8ab
Reviewed-on: https://code.engineering.redhat.com/gerrit/202395
14f8ab
Tested-by: RHGS Build Bot <nigelb@redhat.com>
14f8ab
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
14f8ab
---
14f8ab
 .../bug-1433571-undo-pending-only-on-up-bricks.t   | 18 ++-----
14f8ab
 tests/bugs/replicate/bug-1801624-entry-heal.t      | 58 ++++++++++++++++++++++
14f8ab
 xlators/cluster/afr/src/afr-common.c               |  4 +-
14f8ab
 xlators/cluster/afr/src/afr-self-heal-common.c     |  8 +--
14f8ab
 xlators/cluster/afr/src/afr-self-heal-entry.c      |  6 +--
14f8ab
 xlators/cluster/afr/src/afr-self-heal-name.c       |  2 +-
14f8ab
 xlators/cluster/afr/src/afr-self-heal.h            |  2 -
14f8ab
 7 files changed, 69 insertions(+), 29 deletions(-)
14f8ab
 create mode 100644 tests/bugs/replicate/bug-1801624-entry-heal.t
14f8ab
14f8ab
diff --git a/tests/bugs/replicate/bug-1433571-undo-pending-only-on-up-bricks.t b/tests/bugs/replicate/bug-1433571-undo-pending-only-on-up-bricks.t
14f8ab
index 0767f47..10ce013 100644
14f8ab
--- a/tests/bugs/replicate/bug-1433571-undo-pending-only-on-up-bricks.t
14f8ab
+++ b/tests/bugs/replicate/bug-1433571-undo-pending-only-on-up-bricks.t
14f8ab
@@ -49,25 +49,15 @@ TEST $CLI volume start $V0 force
14f8ab
 EXPECT_WITHIN $CHILD_UP_TIMEOUT "1" afr_child_up_status $V0 0
14f8ab
 EXPECT_WITHIN $CHILD_UP_TIMEOUT "1" afr_child_up_status $V0 2
14f8ab
 
14f8ab
-#Kill brick 0 and turn on the client side heal and do ls to trigger the heal.
14f8ab
-#The pending xattrs on bricks 1 & 2 should have pending entry on brick 0.
14f8ab
-TEST kill_brick $V0 $H0 $B0/${V0}0
14f8ab
+# We were killing one brick and checking that entry heal does not reset the
14f8ab
+# pending xattrs for the down brick. Now that we need all bricks to be up for
14f8ab
+# entry heal, I'm removing that test from the .t
14f8ab
+
14f8ab
 TEST $CLI volume set $V0 cluster.data-self-heal on
14f8ab
 TEST $CLI volume set $V0 cluster.metadata-self-heal on
14f8ab
 TEST $CLI volume set $V0 cluster.entry-self-heal on
14f8ab
 
14f8ab
 TEST ls $M0
14f8ab
-EXPECT "000000000000000000000001" get_hex_xattr trusted.afr.$V0-client-0 $B0/${V0}1
14f8ab
-EXPECT "000000000000000000000001" get_hex_xattr trusted.afr.$V0-client-0 $B0/${V0}2
14f8ab
-EXPECT_WITHIN $HEAL_TIMEOUT "000000000000000000000000" get_hex_xattr trusted.afr.$V0-client-2 $B0/${V0}1
14f8ab
-EXPECT_WITHIN $HEAL_TIMEOUT "000000000000000000000000" get_hex_xattr trusted.afr.$V0-client-1 $B0/${V0}2
14f8ab
-
14f8ab
-#Bring back all the bricks and trigger the heal again by doing ls. Now the
14f8ab
-#pending xattrs on all the bricks should be 0.
14f8ab
-TEST $CLI volume start $V0 force
14f8ab
-EXPECT_WITHIN $CHILD_UP_TIMEOUT "1" afr_child_up_status $V0 0
14f8ab
-TEST ls $M0
14f8ab
-
14f8ab
 TEST cat $M0/f1
14f8ab
 TEST cat $M0/f2
14f8ab
 TEST cat $M0/f3
14f8ab
diff --git a/tests/bugs/replicate/bug-1801624-entry-heal.t b/tests/bugs/replicate/bug-1801624-entry-heal.t
14f8ab
new file mode 100644
14f8ab
index 0000000..94b4651
14f8ab
--- /dev/null
14f8ab
+++ b/tests/bugs/replicate/bug-1801624-entry-heal.t
14f8ab
@@ -0,0 +1,58 @@
14f8ab
+#!/bin/bash
14f8ab
+
14f8ab
+. $(dirname $0)/../../include.rc
14f8ab
+. $(dirname $0)/../../volume.rc
14f8ab
+cleanup;
14f8ab
+
14f8ab
+TEST glusterd
14f8ab
+TEST pidof glusterd
14f8ab
+TEST $CLI volume create $V0 replica 3 $H0:$B0/brick{0,1,2}
14f8ab
+TEST $CLI volume set $V0 heal-timeout 5
14f8ab
+TEST $CLI volume start $V0
14f8ab
+EXPECT_WITHIN $CHILD_UP_TIMEOUT "1" afr_child_up_status_in_shd $V0 0
14f8ab
+EXPECT_WITHIN $CHILD_UP_TIMEOUT "1" afr_child_up_status_in_shd $V0 1
14f8ab
+EXPECT_WITHIN $CHILD_UP_TIMEOUT "1" afr_child_up_status_in_shd $V0 2
14f8ab
+TEST $CLI volume heal $V0 granular-entry-heal enable
14f8ab
+
14f8ab
+TEST glusterfs --volfile-id=/$V0 --volfile-server=$H0 $M0 --attribute-timeout=0 --entry-timeout=0
14f8ab
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" afr_child_up_status $V0 0
14f8ab
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" afr_child_up_status $V0 1
14f8ab
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" afr_child_up_status $V0 2
14f8ab
+echo "Data">$M0/FILE
14f8ab
+ret=$?
14f8ab
+TEST [ $ret -eq 0 ]
14f8ab
+
14f8ab
+# Re-create the file when a brick is down.
14f8ab
+TEST kill_brick $V0 $H0 $B0/brick1
14f8ab
+TEST rm $M0/FILE
14f8ab
+echo "New Data">$M0/FILE
14f8ab
+ret=$?
14f8ab
+TEST [ $ret -eq 0 ]
14f8ab
+EXPECT_WITHIN $HEAL_TIMEOUT "4" get_pending_heal_count $V0
14f8ab
+
14f8ab
+# Launching index heal must not reset parent dir afr xattrs or remove granular entry indices.
14f8ab
+$CLI volume heal $V0 # CLI will fail but heal is launched anyway.
14f8ab
+TEST sleep 5 # give index heal a chance to do one run.
14f8ab
+brick0_pending=$(get_hex_xattr trusted.afr.$V0-client-1 $B0/brick0/)
14f8ab
+brick2_pending=$(get_hex_xattr trusted.afr.$V0-client-1 $B0/brick2/)
14f8ab
+TEST [ $brick0_pending -eq "000000000000000000000002" ]
14f8ab
+TEST [ $brick2_pending -eq "000000000000000000000002" ]
14f8ab
+EXPECT "FILE" ls $B0/brick0/.glusterfs/indices/entry-changes/00000000-0000-0000-0000-000000000001/
14f8ab
+EXPECT "FILE" ls $B0/brick2/.glusterfs/indices/entry-changes/00000000-0000-0000-0000-000000000001/
14f8ab
+
14f8ab
+TEST $CLI volume start $V0 force
14f8ab
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V0 $H0 $B0/brick1
14f8ab
+EXPECT_WITHIN $CHILD_UP_TIMEOUT "1" afr_child_up_status_in_shd $V0 1
14f8ab
+$CLI volume heal $V0
14f8ab
+EXPECT_WITHIN $HEAL_TIMEOUT "0" get_pending_heal_count $V0
14f8ab
+
14f8ab
+# No gfid-split-brain (i.e. EIO) must be seen. Try on fresh mount to avoid cached values.
14f8ab
+EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" force_umount $M0
14f8ab
+TEST glusterfs --volfile-id=/$V0 --volfile-server=$H0 $M0 --attribute-timeout=0 --entry-timeout=0
14f8ab
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" afr_child_up_status $V0 0
14f8ab
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" afr_child_up_status $V0 1
14f8ab
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" afr_child_up_status $V0 2
14f8ab
+TEST cat $M0/FILE
14f8ab
+
14f8ab
+EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" force_umount $M0
14f8ab
+cleanup;
14f8ab
diff --git a/xlators/cluster/afr/src/afr-common.c b/xlators/cluster/afr/src/afr-common.c
14f8ab
index 32127c6..5806556 100644
14f8ab
--- a/xlators/cluster/afr/src/afr-common.c
14f8ab
+++ b/xlators/cluster/afr/src/afr-common.c
14f8ab
@@ -6629,7 +6629,7 @@ afr_fav_child_reset_sink_xattrs(void *opaque)
14f8ab
         ret = afr_selfheal_inodelk(heal_frame, this, inode, this->name, 0, 0,
14f8ab
                                    locked_on);
14f8ab
         {
14f8ab
-            if (ret < AFR_SH_MIN_PARTICIPANTS)
14f8ab
+            if (ret < priv->child_count)
14f8ab
                 goto data_unlock;
14f8ab
             ret = __afr_selfheal_data_prepare(
14f8ab
                 heal_frame, this, inode, locked_on, sources, sinks,
14f8ab
@@ -6646,7 +6646,7 @@ afr_fav_child_reset_sink_xattrs(void *opaque)
14f8ab
         ret = afr_selfheal_inodelk(heal_frame, this, inode, this->name,
14f8ab
                                    LLONG_MAX - 1, 0, locked_on);
14f8ab
         {
14f8ab
-            if (ret < AFR_SH_MIN_PARTICIPANTS)
14f8ab
+            if (ret < priv->child_count)
14f8ab
                 goto mdata_unlock;
14f8ab
             ret = __afr_selfheal_metadata_prepare(
14f8ab
                 heal_frame, this, inode, locked_on, sources, sinks,
14f8ab
diff --git a/xlators/cluster/afr/src/afr-self-heal-common.c b/xlators/cluster/afr/src/afr-self-heal-common.c
14f8ab
index 81ef38a..ce1ea50 100644
14f8ab
--- a/xlators/cluster/afr/src/afr-self-heal-common.c
14f8ab
+++ b/xlators/cluster/afr/src/afr-self-heal-common.c
14f8ab
@@ -1575,7 +1575,6 @@ afr_selfheal_find_direction(call_frame_t *frame, xlator_t *this,
14f8ab
     char *accused = NULL;      /* Accused others without any self-accusal */
14f8ab
     char *pending = NULL;      /* Have pending operations on others */
14f8ab
     char *self_accused = NULL; /* Accused itself */
14f8ab
-    int min_participants = -1;
14f8ab
 
14f8ab
     priv = this->private;
14f8ab
 
14f8ab
@@ -1599,12 +1598,7 @@ afr_selfheal_find_direction(call_frame_t *frame, xlator_t *this,
14f8ab
         }
14f8ab
     }
14f8ab
 
14f8ab
-    if (type == AFR_DATA_TRANSACTION || type == AFR_METADATA_TRANSACTION) {
14f8ab
-        min_participants = priv->child_count;
14f8ab
-    } else {
14f8ab
-        min_participants = AFR_SH_MIN_PARTICIPANTS;
14f8ab
-    }
14f8ab
-    if (afr_success_count(replies, priv->child_count) < min_participants) {
14f8ab
+    if (afr_success_count(replies, priv->child_count) < priv->child_count) {
14f8ab
         /* Treat this just like locks not being acquired */
14f8ab
         return -ENOTCONN;
14f8ab
     }
14f8ab
diff --git a/xlators/cluster/afr/src/afr-self-heal-entry.c b/xlators/cluster/afr/src/afr-self-heal-entry.c
14f8ab
index 3ce882e..40be898 100644
14f8ab
--- a/xlators/cluster/afr/src/afr-self-heal-entry.c
14f8ab
+++ b/xlators/cluster/afr/src/afr-self-heal-entry.c
14f8ab
@@ -597,7 +597,7 @@ afr_selfheal_entry_dirent(call_frame_t *frame, xlator_t *this, fd_t *fd,
14f8ab
     ret = afr_selfheal_entrylk(frame, this, fd->inode, this->name, NULL,
14f8ab
                                locked_on);
14f8ab
     {
14f8ab
-        if (ret < AFR_SH_MIN_PARTICIPANTS) {
14f8ab
+        if (ret < priv->child_count) {
14f8ab
             gf_msg_debug(this->name, 0,
14f8ab
                          "%s: Skipping "
14f8ab
                          "entry self-heal as only %d sub-volumes "
14f8ab
@@ -991,7 +991,7 @@ __afr_selfheal_entry(call_frame_t *frame, xlator_t *this, fd_t *fd,
14f8ab
     ret = afr_selfheal_entrylk(frame, this, fd->inode, this->name, NULL,
14f8ab
                                data_lock);
14f8ab
     {
14f8ab
-        if (ret < AFR_SH_MIN_PARTICIPANTS) {
14f8ab
+        if (ret < priv->child_count) {
14f8ab
             gf_msg_debug(this->name, 0,
14f8ab
                          "%s: Skipping "
14f8ab
                          "entry self-heal as only %d sub-volumes could "
14f8ab
@@ -1115,7 +1115,7 @@ afr_selfheal_entry(call_frame_t *frame, xlator_t *this, inode_t *inode)
14f8ab
     ret = afr_selfheal_tie_breaker_entrylk(frame, this, inode, priv->sh_domain,
14f8ab
                                            NULL, locked_on);
14f8ab
     {
14f8ab
-        if (ret < AFR_SH_MIN_PARTICIPANTS) {
14f8ab
+        if (ret < priv->child_count) {
14f8ab
             gf_msg_debug(this->name, 0,
14f8ab
                          "%s: Skipping "
14f8ab
                          "entry self-heal as only %d sub-volumes could "
14f8ab
diff --git a/xlators/cluster/afr/src/afr-self-heal-name.c b/xlators/cluster/afr/src/afr-self-heal-name.c
14f8ab
index 36640b5..7d4f208 100644
14f8ab
--- a/xlators/cluster/afr/src/afr-self-heal-name.c
14f8ab
+++ b/xlators/cluster/afr/src/afr-self-heal-name.c
14f8ab
@@ -514,7 +514,7 @@ afr_selfheal_name_do(call_frame_t *frame, xlator_t *this, inode_t *parent,
14f8ab
     ret = afr_selfheal_entrylk(frame, this, parent, this->name, bname,
14f8ab
                                locked_on);
14f8ab
     {
14f8ab
-        if (ret < AFR_SH_MIN_PARTICIPANTS) {
14f8ab
+        if (ret < priv->child_count) {
14f8ab
             ret = -ENOTCONN;
14f8ab
             goto unlock;
14f8ab
         }
14f8ab
diff --git a/xlators/cluster/afr/src/afr-self-heal.h b/xlators/cluster/afr/src/afr-self-heal.h
14f8ab
index 6555ec5..8234cec 100644
14f8ab
--- a/xlators/cluster/afr/src/afr-self-heal.h
14f8ab
+++ b/xlators/cluster/afr/src/afr-self-heal.h
14f8ab
@@ -11,8 +11,6 @@
14f8ab
 #ifndef _AFR_SELFHEAL_H
14f8ab
 #define _AFR_SELFHEAL_H
14f8ab
 
14f8ab
-#define AFR_SH_MIN_PARTICIPANTS 2
14f8ab
-
14f8ab
 /* Perform fop on all UP subvolumes and wait for all callbacks to return */
14f8ab
 
14f8ab
 #define AFR_ONALL(frame, rfn, fop, args...)                                    \
14f8ab
-- 
14f8ab
1.8.3.1
14f8ab