From f52dd9bf2005449f49acd5666a02594fb4c5ac6f Mon Sep 17 00:00:00 2001 From: Pranith Kumar K Date: Sun, 20 Nov 2011 09:13:14 +0530 Subject: cluster/afr: Update read-child if it becomes stale Change-Id: I00c714a89575023f6dbdd3430dcbf191e5d08019 BUG: 3650 Reviewed-on: http://review.gluster.com/740 Tested-by: Gluster Build System Reviewed-by: Vijay Bellur --- xlators/cluster/afr/src/afr-common.c | 20 +++++++------- xlators/cluster/afr/src/afr-transaction.c | 44 +++++++++++++------------------ xlators/cluster/afr/src/afr.h | 2 +- 3 files changed, 30 insertions(+), 36 deletions(-) diff --git a/xlators/cluster/afr/src/afr-common.c b/xlators/cluster/afr/src/afr-common.c index 108b021b3..9512f6a54 100644 --- a/xlators/cluster/afr/src/afr-common.c +++ b/xlators/cluster/afr/src/afr-common.c @@ -325,7 +325,6 @@ afr_inode_ctx_set_read_child (afr_inode_ctx_t *ctx, int32_t read_child) uint64_t remaining_mask = 0; uint64_t mask = 0; - GF_ASSERT (read_child >= 0); remaining_mask = (~AFR_ICTX_READ_CHILD_MASK & ctx->masks); mask = (AFR_ICTX_READ_CHILD_MASK & read_child); ctx->masks = remaining_mask | mask; @@ -347,19 +346,23 @@ afr_inode_ctx_set_read_ctx (afr_inode_ctx_t *ctx, int32_t read_child, } void -afr_inode_ctx_rm_stale_children (afr_inode_ctx_t *ctx, int32_t read_child, - int32_t *stale_children, int32_t child_count) +afr_inode_ctx_rm_stale_children (afr_inode_ctx_t *ctx, int32_t *stale_children, + int32_t child_count) { int i = 0; + int32_t read_child = -1; GF_ASSERT (stale_children); - afr_inode_ctx_set_read_child (ctx, read_child); for (i = 0; i < child_count; i++) { - if ((ctx->fresh_children[i] == -1) || (stale_children[i] == -1)) + if (stale_children[i] == -1) break; afr_children_rm_child (ctx->fresh_children, stale_children[i], child_count); } + read_child = (int32_t)(ctx->masks & AFR_ICTX_READ_CHILD_MASK); + if (!afr_is_child_present (ctx->fresh_children, child_count, + read_child)) + afr_inode_ctx_set_read_child (ctx, ctx->fresh_children[0]); } void @@ -421,9 +424,8 @@ afr_inode_set_ctx (xlator_t *this, inode_t *inode, afr_inode_params_t *params) priv->child_count); break; case AFR_INODE_RM_STALE_CHILDREN: - read_child = params->u.read_ctx.read_child; stale_children = params->u.read_ctx.children; - afr_inode_ctx_rm_stale_children (ctx, read_child, + afr_inode_ctx_rm_stale_children (ctx, stale_children, priv->child_count); break; @@ -488,16 +490,14 @@ afr_inode_set_read_ctx (xlator_t *this, inode_t *inode, int32_t read_child, } void -afr_inode_rm_stale_children (xlator_t *this, inode_t *inode, int32_t read_child, +afr_inode_rm_stale_children (xlator_t *this, inode_t *inode, int32_t *stale_children) { afr_inode_params_t params = {0}; - GF_ASSERT (read_child >= 0); GF_ASSERT (stale_children); params.op = AFR_INODE_RM_STALE_CHILDREN; - params.u.read_ctx.read_child = read_child; params.u.read_ctx.children = stale_children; afr_inode_set_ctx (this, inode, ¶ms); } diff --git a/xlators/cluster/afr/src/afr-transaction.c b/xlators/cluster/afr/src/afr-transaction.c index d3960dcff..89fbd9ec7 100644 --- a/xlators/cluster/afr/src/afr-transaction.c +++ b/xlators/cluster/afr/src/afr-transaction.c @@ -382,44 +382,38 @@ afr_transaction_rm_stale_children (call_frame_t *frame, xlator_t *this, local = frame->local; pending = local->pending; - stale_children = afr_children_create (priv->child_count); - if (!stale_children) + if (local->op_ret < 0) goto out; - fresh_children = local->fresh_children; read_child = afr_inode_get_read_ctx (this, inode, fresh_children); - - GF_ASSERT (read_child >= 0); - - if (pending[read_child][idx] == 0) - read_child = -1; + if (read_child < 0) { + gf_log (this->name, GF_LOG_DEBUG, "Possible split-brain " + "for %s", uuid_utoa (inode->gfid)); + goto out; + } for (i = 0; i < priv->child_count; i++) { if (!afr_is_child_present (fresh_children, priv->child_count, i)) continue; - if (pending[i][idx] == 0) { - /* child is down or op failed on it */ - rm_stale_children = _gf_true; - afr_children_rm_child (fresh_children, i, - priv->child_count); - stale_children[count++] = i; - } - } + if (pending[i][idx]) + continue; + /* child is down or op failed on it */ + if (!stale_children) + stale_children = afr_children_create (priv->child_count); + if (!stale_children) + goto out; - if (!rm_stale_children) { - GF_ASSERT (read_child >= 0); - goto out; + rm_stale_children = _gf_true; + stale_children[count++] = i; + gf_log (this->name, GF_LOG_DEBUG, "Removing stale child " + "%d for %s", i, uuid_utoa (inode->gfid)); } - if (fresh_children[0] == -1) { - //All children failed. leave as-is + if (!rm_stale_children) goto out; - } - if (read_child == -1) - read_child = fresh_children[0]; - afr_inode_rm_stale_children (this, inode, read_child, stale_children); + afr_inode_rm_stale_children (this, inode, stale_children); out: if (stale_children) GF_FREE (stale_children); diff --git a/xlators/cluster/afr/src/afr.h b/xlators/cluster/afr/src/afr.h index e7c948dba..0566495fe 100644 --- a/xlators/cluster/afr/src/afr.h +++ b/xlators/cluster/afr/src/afr.h @@ -970,7 +970,7 @@ int32_t afr_resultant_errno_get (int32_t *children, int *child_errno, unsigned int child_count); void -afr_inode_rm_stale_children (xlator_t *this, inode_t *inode, int32_t read_child, +afr_inode_rm_stale_children (xlator_t *this, inode_t *inode, int32_t *stale_children); void afr_launch_self_heal (call_frame_t *frame, xlator_t *this, inode_t *inode, -- cgit