From 67bc3775685198b9ab10c1f2a0d957b157bb4acd Mon Sep 17 00:00:00 2001 From: Iraj Jamali Date: Fri, 30 Nov 2018 17:23:57 +0530 Subject: afr: not resolve splitbrains when copies are of same size Automatic Splitbrain with size as policy must not resolve splitbrains when the copies are of same size. Determining if the sizes of copies are same and returning -1 in that case. updates: bz#1655052 Change-Id: I3d8e8b4d7962b070ed16c3ee02a1e5a926fd5eab Signed-off-by: Iraj Jamali --- xlators/cluster/afr/src/afr-self-heal-common.c | 43 +++++++++++++++----------- 1 file changed, 25 insertions(+), 18 deletions(-) (limited to 'xlators/cluster') diff --git a/xlators/cluster/afr/src/afr-self-heal-common.c b/xlators/cluster/afr/src/afr-self-heal-common.c index ccbaca37784..226876154d7 100644 --- a/xlators/cluster/afr/src/afr-self-heal-common.c +++ b/xlators/cluster/afr/src/afr-self-heal-common.c @@ -1163,7 +1163,8 @@ afr_sh_fav_by_ctime(xlator_t *this, struct afr_reply *replies, inode_t *inode) } /* - * afr_sh_fav_by_size: Choose favorite child by size. + * afr_sh_fav_by_size: Choose favorite child by size + * when not all files are of zero size. */ int afr_sh_fav_by_size(xlator_t *this, struct afr_reply *replies, inode_t *inode) @@ -1175,25 +1176,31 @@ afr_sh_fav_by_size(xlator_t *this, struct afr_reply *replies, inode_t *inode) priv = this->private; for (i = 0; i < priv->child_count; i++) { - if (replies[i].valid == 1) { - gf_msg_debug(this->name, 0, - "Child:%s file size = %" PRIu64 " for gfid %s", - priv->children[i]->name, replies[i].poststat.ia_size, - uuid_utoa(inode->gfid)); - if (replies[i].poststat.ia_type == IA_IFDIR) { - gf_msg(this->name, GF_LOG_ERROR, 0, - AFR_MSG_SBRAIN_FAV_CHILD_POLICY, - "Cannot perform selfheal on %s. " - "Size policy is not applicable to directories.", - uuid_utoa(inode->gfid)); - break; - } - if (replies[i].poststat.ia_size > cmp_sz) { - cmp_sz = replies[i].poststat.ia_size; - fav_child = i; - } + if (!replies[i].valid) { + continue; + } + gf_msg_debug(this->name, 0, + "Child:%s file size = %" PRIu64 " for gfid %s", + priv->children[i]->name, replies[i].poststat.ia_size, + uuid_utoa(inode->gfid)); + if (replies[i].poststat.ia_type == IA_IFDIR) { + gf_msg(this->name, GF_LOG_ERROR, 0, AFR_MSG_SBRAIN_FAV_CHILD_POLICY, + "Cannot perform selfheal on %s. " + "Size policy is not applicable to directories.", + uuid_utoa(inode->gfid)); + break; + } + if (replies[i].poststat.ia_size > cmp_sz) { + cmp_sz = replies[i].poststat.ia_size; + fav_child = i; + } else if (replies[i].poststat.ia_size == cmp_sz) { + fav_child = -1; } } + if (fav_child == -1) { + gf_msg(this->name, GF_LOG_ERROR, 0, AFR_MSG_SPLIT_BRAIN, + "No bigger file"); + } return fav_child; } -- cgit