From c0d9bb7828fcecb3cba27ed8708c69c90a13e07d Mon Sep 17 00:00:00 2001 From: Pranith Kumar K Date: Wed, 2 Mar 2016 22:09:44 +0530 Subject: cluster/afr: Choose local child as source if possible It is better to choose local brick as source if possible to prevent over the wire read thus saving on bandwidth. Also changed code to not attempt data-heal if 'source' is selected as arbiter. >Change-Id: I9a328d0198422280b13a30ab99545370a301dfea >BUG: 1314150 >Signed-off-by: Pranith Kumar K >Reviewed-on: http://review.gluster.org/13585 >Smoke: Gluster Build System >NetBSD-regression: NetBSD Build System >Reviewed-by: Krutika Dhananjay >Tested-by: Krutika Dhananjay >CentOS-regression: Gluster Build System >Reviewed-by: Jeff Darcy >(cherry picked from commit 2807e3fc005630213ab7ad251fef13d61c07ac6b) Change-Id: I24ea66683f81e238a6c1850664a49fe554011a0a BUG: 1322521 Signed-off-by: Pranith Kumar K Reviewed-on: http://review.gluster.org/13860 Smoke: Gluster Build System NetBSD-regression: NetBSD Build System CentOS-regression: Gluster Build System Reviewed-by: Ravishankar N --- xlators/cluster/afr/src/afr-self-heal-common.c | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'xlators/cluster/afr/src/afr-self-heal-common.c') diff --git a/xlators/cluster/afr/src/afr-self-heal-common.c b/xlators/cluster/afr/src/afr-self-heal-common.c index 73d7e94b5cf..fff2a06f927 100644 --- a/xlators/cluster/afr/src/afr-self-heal-common.c +++ b/xlators/cluster/afr/src/afr-self-heal-common.c @@ -1533,3 +1533,32 @@ afr_throttled_selfheal (call_frame_t *frame, xlator_t *this) "pending, background self-heal rejected."); } } + +int +afr_choose_source_by_policy (afr_private_t *priv, unsigned char *sources, + afr_transaction_type type) +{ + int source = -1; + int i = 0; + + /* Give preference to local child to save on bandwidth */ + for (i = 0; i < priv->child_count; i++) { + if (priv->local[i] && sources[i]) { + if ((type == AFR_DATA_TRANSACTION) && + AFR_IS_ARBITER_BRICK (priv, i)) + continue; + + source = i; + goto out; + } + } + + for (i = 0; i < priv->child_count; i++) { + if (sources[i]) { + source = i; + goto out; + } + } +out: + return source; +} -- cgit