summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src/glusterd-volgen.c
diff options
context:
space:
mode:
authorRavishankar N <ravishankar@redhat.com>2015-05-01 08:57:28 +0530
committerVijay Bellur <vbellur@redhat.com>2015-05-03 22:07:52 -0700
commit7e0a74a55ab44da04eed8d63efe9376aac49fab7 (patch)
tree5b1fa36ebe0d9c9ddb7e0d74983d9653f85b4193 /xlators/mgmt/glusterd/src/glusterd-volgen.c
parent40407afb529f6e5fa2f79e9778c2f527122d75eb (diff)
arbiter: load arbiter xlator on every 3rd brick of a replica 3 AFR subvol
Backport of http://review.gluster.org/10257 Logic for adding the 'glusterd_brickinfo->group' member and using it to find the brick positon has been taken from http://review.gluster.org/#/c/9919. Thanks to Jeff Darcy for that. This patch is a part of the arbiter logic implementation for 3 way AFR details of which can be found at http://review.gluster.org/#/c/9656/ Change-Id: Idbfe4f29ee8e098e0102def8f38b32314316b188 BUG: 1217689 Signed-off-by: Ravishankar N <ravishankar@redhat.com> Reviewed-on: http://review.gluster.org/10479 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com> Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-volgen.c')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-volgen.c86
1 files changed, 72 insertions, 14 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c
index f38f07e0672..109e7c214d4 100644
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.c
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c
@@ -1502,12 +1502,26 @@ brick_graph_add_arbiter (volgen_graph_t *graph, glusterd_volinfo_t *volinfo,
dict_t *set_dict, glusterd_brickinfo_t *brickinfo)
{
xlator_t *xl = NULL;
+ glusterd_brickinfo_t *next = NULL;
+ glusterd_brickinfo_t *last = NULL;
int ret = -1;
if (volinfo->arbiter_count != 1)
return 0;
- /*TODO: Parse brickinfo and add the arbiter xlator only if brick is the
- * last brick (i.e. 3rd brick) of the replcia pair.*/
+
+ /* Find the last brick in the same group. */
+ last = brickinfo;
+ for (;;) {
+ next = list_next (last, &volinfo->bricks,
+ glusterd_brickinfo_t, brick_list);
+ if (!next || (next->group != brickinfo->group)) {
+ break;
+ }
+ last = next;
+ }
+ if (last != brickinfo)
+ return 0;
+
xl = volgen_graph_add (graph, "features/arbiter", volinfo->volname);
if (!xl)
goto out;
@@ -1571,6 +1585,22 @@ out:
return ret;
}
+void
+assign_brick_groups (glusterd_volinfo_t *volinfo)
+{
+ glusterd_brickinfo_t *brickinfo = NULL;
+ uint16_t group_num = 0;
+ int in_group = 0;
+
+ list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) {
+ brickinfo->group = group_num;
+ if (++in_group >= volinfo->replica_count) {
+ in_group = 0;
+ ++group_num;
+ }
+ }
+}
+
static int
brick_graph_add_changelog (volgen_graph_t *graph, glusterd_volinfo_t *volinfo,
dict_t *set_dict, glusterd_brickinfo_t *brickinfo)
@@ -3082,6 +3112,43 @@ out:
}
static int
+volgen_graph_build_afr_clusters (volgen_graph_t *graph,
+ glusterd_volinfo_t *volinfo)
+{
+ int i = 0;
+ int ret = 0;
+ int clusters = 0;
+ char *replicate_args[] = {"cluster/replicate",
+ "%s-replicate-%d"};
+ xlator_t *afr = NULL;
+ char option[32] = {0};
+
+ clusters = volgen_link_bricks_from_list_tail (graph, volinfo,
+ replicate_args[0],
+ replicate_args[1],
+ volinfo->brick_count,
+ volinfo->replica_count);
+ if (clusters < 0)
+ goto out;
+
+ if (!volinfo->arbiter_count)
+ goto out;
+
+ afr = first_of (graph);
+ sprintf(option, "%d", volinfo->arbiter_count);
+ for (i = 0; i < clusters; i++) {
+ ret = xlator_set_option (afr, "arbiter-count", option);
+ if (ret) {
+ clusters = -1;
+ goto out;
+ }
+ afr = afr->next;
+ }
+out:
+ return clusters;
+}
+
+static int
volume_volgen_graph_build_clusters (volgen_graph_t *graph,
glusterd_volinfo_t *volinfo,
gf_boolean_t is_quotad)
@@ -3111,13 +3178,7 @@ volume_volgen_graph_build_clusters (volgen_graph_t *graph,
/* All other cases, it will have one or the other cluster type */
switch (volinfo->type) {
case GF_CLUSTER_TYPE_REPLICATE:
- clusters = volgen_link_bricks_from_list_tail
- (graph, volinfo,
- replicate_args[0],
- replicate_args[1],
- volinfo->brick_count,
- volinfo->replica_count);
-
+ clusters = volgen_graph_build_afr_clusters (graph, volinfo);
if (clusters < 0)
goto out;
break;
@@ -3141,11 +3202,7 @@ volume_volgen_graph_build_clusters (volgen_graph_t *graph,
/* Replicate after the clients, then stripe */
if (volinfo->replica_count == 0)
goto out;
- clusters = volgen_link_bricks_from_list_tail (graph, volinfo,
- replicate_args[0],
- replicate_args[1],
- volinfo->brick_count,
- volinfo->replica_count);
+ clusters = volgen_graph_build_afr_clusters (graph, volinfo);
if (clusters < 0)
goto out;
@@ -4456,6 +4513,7 @@ generate_brick_volfiles (glusterd_volinfo_t *volinfo)
if (ret == -1)
return -1;
+ assign_brick_groups (volinfo);
get_vol_tstamp_file (tstamp_file, volinfo);
if (ret) {