9ae3f9
From a75bb15fbe64f14580c44b8a33314c8bbeffdede Mon Sep 17 00:00:00 2001
9ae3f9
From: Ravishankar N <ravishankar@redhat.com>
9ae3f9
Date: Thu, 4 Jun 2020 18:54:46 +0530
9ae3f9
Subject: [PATCH 406/449] afr: support split-brain CLI for replica 3
9ae3f9
9ae3f9
Patch in upstream master: https://review.gluster.org/#/c/glusterfs/+/23502/
9ae3f9
9ae3f9
Ever since we added quorum checks for lookups in afr via commit
9ae3f9
bd44d59741bb8c0f5d7a62c5b1094179dd0ce8a4, the split-brain resolution
9ae3f9
commands would not work for replica 3 because there would be no
9ae3f9
readables for the lookup fop.
9ae3f9
9ae3f9
The argument was that split-brains do not occur in replica 3 but we do
9ae3f9
see (data/metadata) split-brain cases once in a while which indicate that there are
9ae3f9
a few bugs/corner cases yet to be discovered and fixed.
9ae3f9
9ae3f9
Fortunately, commit  8016d51a3bbd410b0b927ed66be50a09574b7982 added
9ae3f9
GF_CLIENT_PID_GLFS_HEALD as the pid for all fops made by glfsheal. If we
9ae3f9
leverage this and allow lookups in afr when pid is GF_CLIENT_PID_GLFS_HEALD,
9ae3f9
split-brain resolution commands will work for replica 3 volumes too.
9ae3f9
9ae3f9
Likewise, the check is added in shard_lookup as well to permit resolving
9ae3f9
split-brains by specifying "/.shard/shard-file.xx" as the file name
9ae3f9
(which previously used to fail with EPERM).
9ae3f9
9ae3f9
BUG: 1759875
9ae3f9
Change-Id: I203735b909c7d30fc4faaf3ecd4f5b6b379ab266
9ae3f9
Signed-off-by: Ravishankar N <ravishankar@redhat.com>
9ae3f9
Reviewed-on: https://code.engineering.redhat.com/gerrit/202375
9ae3f9
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
9ae3f9
---
9ae3f9
 .../replicate/bug-1756938-replica-3-sbrain-cli.t   | 111 +++++++++++++++++++++
9ae3f9
 xlators/cluster/afr/src/afr-common.c               |   3 +-
9ae3f9
 xlators/features/shard/src/shard.c                 |   3 +-
9ae3f9
 3 files changed, 115 insertions(+), 2 deletions(-)
9ae3f9
 create mode 100644 tests/bugs/replicate/bug-1756938-replica-3-sbrain-cli.t
9ae3f9
9ae3f9
diff --git a/tests/bugs/replicate/bug-1756938-replica-3-sbrain-cli.t b/tests/bugs/replicate/bug-1756938-replica-3-sbrain-cli.t
9ae3f9
new file mode 100644
9ae3f9
index 0000000..c1bdf34
9ae3f9
--- /dev/null
9ae3f9
+++ b/tests/bugs/replicate/bug-1756938-replica-3-sbrain-cli.t
9ae3f9
@@ -0,0 +1,111 @@
9ae3f9
+#!/bin/bash
9ae3f9
+
9ae3f9
+. $(dirname $0)/../../include.rc
9ae3f9
+. $(dirname $0)/../../volume.rc
9ae3f9
+. $(dirname $0)/../../afr.rc
9ae3f9
+
9ae3f9
+cleanup;
9ae3f9
+
9ae3f9
+TEST glusterd;
9ae3f9
+TEST pidof glusterd;
9ae3f9
+TEST $CLI volume create $V0 replica 3 $H0:$B0/${V0}{0,1,2}
9ae3f9
+TEST $CLI volume set $V0 features.shard enable
9ae3f9
+TEST $CLI volume set $V0 features.shard-block-size 4MB
9ae3f9
+
9ae3f9
+TEST $CLI volume start $V0
9ae3f9
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V0 $H0 $B0/${V0}0
9ae3f9
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V0 $H0 $B0/${V0}1
9ae3f9
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V0 $H0 $B0/${V0}2
9ae3f9
+TEST glusterfs --volfile-server=$H0 --volfile-id=/$V0 $M0
9ae3f9
+EXPECT_WITHIN $CHILD_UP_TIMEOUT "1" afr_child_up_status $V0 0
9ae3f9
+EXPECT_WITHIN $CHILD_UP_TIMEOUT "1" afr_child_up_status $V0 1
9ae3f9
+EXPECT_WITHIN $CHILD_UP_TIMEOUT "1" afr_child_up_status $V0 2
9ae3f9
+
9ae3f9
+#Create split-brain by setting afr xattrs/gfids manually.
9ae3f9
+#file1 is non-sharded and will be in data split-brain.
9ae3f9
+#file2 will have one shard which will be in data split-brain.
9ae3f9
+#file3 will have one shard which will be in gfid split-brain.
9ae3f9
+#file4 will have one shard which will be in data & metadata split-brain.
9ae3f9
+TEST dd if=/dev/zero of=$M0/file1 bs=1024 count=1024 oflag=direct
9ae3f9
+TEST dd if=/dev/zero of=$M0/file2 bs=1M count=6 oflag=direct
9ae3f9
+TEST dd if=/dev/zero of=$M0/file3 bs=1M count=6 oflag=direct
9ae3f9
+TEST dd if=/dev/zero of=$M0/file4 bs=1M count=6 oflag=direct
9ae3f9
+EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" force_umount $M0
9ae3f9
+
9ae3f9
+#-------------------------------------------------------------------------------
9ae3f9
+TEST setfattr -n trusted.afr.$V0-client-1 -v 0x000000010000000000000000 $B0/${V0}0/file1
9ae3f9
+TEST setfattr -n trusted.afr.$V0-client-2 -v 0x000000010000000000000000 $B0/${V0}0/file1
9ae3f9
+TEST setfattr -n trusted.afr.$V0-client-0 -v 0x000000010000000000000000 $B0/${V0}1/file1
9ae3f9
+TEST setfattr -n trusted.afr.$V0-client-2 -v 0x000000010000000000000000 $B0/${V0}1/file1
9ae3f9
+TEST setfattr -n trusted.afr.$V0-client-0 -v 0x000000010000000000000000 $B0/${V0}2/file1
9ae3f9
+TEST setfattr -n trusted.afr.$V0-client-1 -v 0x000000010000000000000000 $B0/${V0}2/file1
9ae3f9
+
9ae3f9
+#-------------------------------------------------------------------------------
9ae3f9
+gfid_f2=$(gf_gfid_xattr_to_str $(gf_get_gfid_xattr $B0/${V0}0/file2))
9ae3f9
+TEST setfattr -n trusted.afr.$V0-client-1 -v 0x000000010000000000000000 $B0/${V0}0/.shard/$gfid_f2.1
9ae3f9
+TEST setfattr -n trusted.afr.$V0-client-2 -v 0x000000010000000000000000 $B0/${V0}0/.shard/$gfid_f2.1
9ae3f9
+TEST setfattr -n trusted.afr.$V0-client-0 -v 0x000000010000000000000000 $B0/${V0}1/.shard/$gfid_f2.1
9ae3f9
+TEST setfattr -n trusted.afr.$V0-client-2 -v 0x000000010000000000000000 $B0/${V0}1/.shard/$gfid_f2.1
9ae3f9
+TEST setfattr -n trusted.afr.$V0-client-0 -v 0x000000010000000000000000 $B0/${V0}2/.shard/$gfid_f2.1
9ae3f9
+TEST setfattr -n trusted.afr.$V0-client-1 -v 0x000000010000000000000000 $B0/${V0}2/.shard/$gfid_f2.1
9ae3f9
+
9ae3f9
+#-------------------------------------------------------------------------------
9ae3f9
+TESTS_EXPECTED_IN_LOOP=5
9ae3f9
+function assign_new_gfid {
9ae3f9
+    brickpath=$1
9ae3f9
+    filename=$2
9ae3f9
+    gfid=$(gf_gfid_xattr_to_str $(gf_get_gfid_xattr $brickpath/$filename))
9ae3f9
+    gfid_shard=$(gf_gfid_xattr_to_str $(gf_get_gfid_xattr $brickpath/.shard/$gfid.1))
9ae3f9
+
9ae3f9
+    TEST rm $brickpath/.glusterfs/${gfid_shard:0:2}/${gfid_shard:2:2}/$gfid_shard
9ae3f9
+    TEST setfattr -x trusted.gfid $brickpath/.shard/$gfid.1
9ae3f9
+    new_gfid=$(get_random_gfid)
9ae3f9
+    new_gfid_str=$(gf_gfid_xattr_to_str $new_gfid)
9ae3f9
+    TEST setfattr -n trusted.gfid -v $new_gfid $brickpath/.shard/$gfid.1
9ae3f9
+    TEST mkdir -p $brickpath/.glusterfs/${new_gfid_str:0:2}/${new_gfid_str:2:2}
9ae3f9
+    TEST ln $brickpath/.shard/$gfid.1 $brickpath/.glusterfs/${new_gfid_str:0:2}/${new_gfid_str:2:2}/$new_gfid_str
9ae3f9
+}
9ae3f9
+assign_new_gfid $B0/$V0"1" file3
9ae3f9
+assign_new_gfid $B0/$V0"2" file3
9ae3f9
+
9ae3f9
+#-------------------------------------------------------------------------------
9ae3f9
+gfid_f4=$(gf_gfid_xattr_to_str $(gf_get_gfid_xattr $B0/${V0}0/file4))
9ae3f9
+TEST setfattr -n trusted.afr.$V0-client-1 -v 0x000000010000000100000000 $B0/${V0}0/.shard/$gfid_f4.1
9ae3f9
+TEST setfattr -n trusted.afr.$V0-client-2 -v 0x000000010000000100000000 $B0/${V0}0/.shard/$gfid_f4.1
9ae3f9
+TEST setfattr -n trusted.afr.$V0-client-0 -v 0x000000010000000100000000 $B0/${V0}1/.shard/$gfid_f4.1
9ae3f9
+TEST setfattr -n trusted.afr.$V0-client-2 -v 0x000000010000000100000000 $B0/${V0}1/.shard/$gfid_f4.1
9ae3f9
+TEST setfattr -n trusted.afr.$V0-client-0 -v 0x000000010000000100000000 $B0/${V0}2/.shard/$gfid_f4.1
9ae3f9
+TEST setfattr -n trusted.afr.$V0-client-1 -v 0x000000010000000100000000 $B0/${V0}2/.shard/$gfid_f4.1
9ae3f9
+
9ae3f9
+#-------------------------------------------------------------------------------
9ae3f9
+#Add entry to xattrop dir on first brick and check for split-brain.
9ae3f9
+xattrop_dir0=$(afr_get_index_path $B0/$V0"0")
9ae3f9
+base_entry_b0=`ls $xattrop_dir0`
9ae3f9
+
9ae3f9
+gfid_f1=$(gf_gfid_xattr_to_str $(gf_get_gfid_xattr $B0/$V0"0"/file1))
9ae3f9
+TEST ln  $xattrop_dir0/$base_entry_b0 $xattrop_dir0/$gfid_f1
9ae3f9
+
9ae3f9
+gfid_f2_shard1=$(gf_gfid_xattr_to_str $(gf_get_gfid_xattr $B0/$V0"0"/.shard/$gfid_f2.1))
9ae3f9
+TEST ln  $xattrop_dir0/$base_entry_b0 $xattrop_dir0/$gfid_f2_shard1
9ae3f9
+
9ae3f9
+gfid_f3=$(gf_gfid_xattr_to_str $(gf_get_gfid_xattr $B0/${V0}0/file3))
9ae3f9
+gfid_f3_shard1=$(gf_gfid_xattr_to_str $(gf_get_gfid_xattr $B0/$V0"0"/.shard/$gfid_f3.1))
9ae3f9
+TEST ln $xattrop_dir0/$base_entry_b0 $xattrop_dir0/$gfid_f3_shard1
9ae3f9
+
9ae3f9
+gfid_f4_shard1=$(gf_gfid_xattr_to_str $(gf_get_gfid_xattr $B0/$V0"0"/.shard/$gfid_f4.1))
9ae3f9
+TEST ln  $xattrop_dir0/$base_entry_b0 $xattrop_dir0/$gfid_f4_shard1
9ae3f9
+
9ae3f9
+#-------------------------------------------------------------------------------
9ae3f9
+#gfid split-brain won't show up in split-brain count.
9ae3f9
+EXPECT "3" afr_get_split_brain_count $V0
9ae3f9
+EXPECT_NOT "^0$" get_pending_heal_count $V0
9ae3f9
+
9ae3f9
+#Resolve split-brains
9ae3f9
+TEST $CLI volume heal $V0 split-brain source-brick $H0:$B0/${V0}1 /file1
9ae3f9
+GFIDSTR="gfid:$gfid_f2_shard1"
9ae3f9
+TEST $CLI volume heal $V0 split-brain source-brick $H0:$B0/${V0}1 $GFIDSTR
9ae3f9
+TEST $CLI volume heal $V0 split-brain source-brick $H0:$B0/${V0}1 /.shard/$gfid_f3.1
9ae3f9
+TEST $CLI volume heal $V0 split-brain source-brick $H0:$B0/${V0}1 /.shard/$gfid_f4.1
9ae3f9
+TEST $CLI volume heal $V0
9ae3f9
+EXPECT_WITHIN $HEAL_TIMEOUT "^0$" get_pending_heal_count $V0
9ae3f9
+cleanup;
9ae3f9
diff --git a/xlators/cluster/afr/src/afr-common.c b/xlators/cluster/afr/src/afr-common.c
9ae3f9
index eef7fd2..32127c6 100644
9ae3f9
--- a/xlators/cluster/afr/src/afr-common.c
9ae3f9
+++ b/xlators/cluster/afr/src/afr-common.c
9ae3f9
@@ -2250,7 +2250,8 @@ afr_attempt_readsubvol_set(call_frame_t *frame, xlator_t *this,
9ae3f9
     if ((spb_choice >= 0) &&
9ae3f9
         (AFR_COUNT(success_replies, child_count) == child_count)) {
9ae3f9
         *read_subvol = spb_choice;
9ae3f9
-    } else if (!priv->quorum_count) {
9ae3f9
+    } else if (!priv->quorum_count ||
9ae3f9
+               frame->root->pid == GF_CLIENT_PID_GLFS_HEAL) {
9ae3f9
         *read_subvol = afr_first_up_child(frame, this);
9ae3f9
     } else if (priv->quorum_count &&
9ae3f9
                afr_has_quorum(data_readable, this, NULL)) {
9ae3f9
diff --git a/xlators/features/shard/src/shard.c b/xlators/features/shard/src/shard.c
9ae3f9
index 2e2ef5d..16d557b 100644
9ae3f9
--- a/xlators/features/shard/src/shard.c
9ae3f9
+++ b/xlators/features/shard/src/shard.c
9ae3f9
@@ -1472,7 +1472,8 @@ int shard_lookup(call_frame_t *frame, xlator_t *this, loc_t *loc,
9ae3f9
   shard_local_t *local = NULL;
9ae3f9
 
9ae3f9
   this->itable = loc->inode->table;
9ae3f9
-  if (frame->root->pid != GF_CLIENT_PID_GSYNCD) {
9ae3f9
+  if ((frame->root->pid != GF_CLIENT_PID_GSYNCD) &&
9ae3f9
+      (frame->root->pid != GF_CLIENT_PID_GLFS_HEAL)) {
9ae3f9
     SHARD_ENTRY_FOP_CHECK(loc, op_errno, err);
9ae3f9
   }
9ae3f9
 
9ae3f9
-- 
9ae3f9
1.8.3.1
9ae3f9