summaryrefslogtreecommitdiffstats
path: root/xlators/cluster/afr/src/afr.c
diff options
context:
space:
mode:
authorRavishankar N <ravishankar@redhat.com>2016-05-02 18:45:44 +0530
committerJeff Darcy <jdarcy@redhat.com>2016-05-25 11:55:08 -0700
commit2f29065ae4715c9c4a9d20c4d15311bebd3ddb0e (patch)
tree163497880075bfcc2b97f92be2d2fb86ed95ab51 /xlators/cluster/afr/src/afr.c
parentf8f16595d8dd8c8a869630bb77b7fd1b42b97e08 (diff)
afr: Automagic unsplit-brain by [ctime|mtime|size|majority]
Introduce cluster.favorite-child-policy which when enabled with [ctime|mtime|size|majority], automatically heals files that are in split-brian. The majority policy will not pick a source if there is no majority. The other three policies pick the first brick with a valid reply and non-zero ctime/mtime/size as source. Change-Id: I3c099a0404082213860f74f2c9b4d207cfaedb76 BUG: 1328224 Original-author: Richard Wareing <rwareing@fb.com> Signed-off-by: Ravishankar N <ravishankar@redhat.com> Reviewed-on: http://review.gluster.org/14026 Smoke: Gluster Build System <jenkins@build.gluster.com> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org> CentOS-regression: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Anuradha Talur <atalur@redhat.com> Reviewed-by: Jeff Darcy <jdarcy@redhat.com>
Diffstat (limited to 'xlators/cluster/afr/src/afr.c')
-rw-r--r--xlators/cluster/afr/src/afr.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/xlators/cluster/afr/src/afr.c b/xlators/cluster/afr/src/afr.c
index d01a806fe86..f2cb7dd7fb2 100644
--- a/xlators/cluster/afr/src/afr.c
+++ b/xlators/cluster/afr/src/afr.c
@@ -20,6 +20,15 @@
struct volume_options options[];
+static char *afr_favorite_child_policies[AFR_FAV_CHILD_POLICY_MAX + 1] = {
+ [AFR_FAV_CHILD_NONE] = "none",
+ [AFR_FAV_CHILD_BY_SIZE] = "size",
+ [AFR_FAV_CHILD_BY_CTIME] = "ctime",
+ [AFR_FAV_CHILD_BY_MTIME] = "mtime",
+ [AFR_FAV_CHILD_BY_MAJORITY] = "majority",
+ [AFR_FAV_CHILD_POLICY_MAX] = NULL,
+};
+
int32_t
notify (xlator_t *this, int32_t event,
void *data, ...)
@@ -101,6 +110,19 @@ fix_quorum_options (xlator_t *this, afr_private_t *priv, char *qtype,
}
int
+afr_set_favorite_child_policy (afr_private_t *priv, char *policy)
+{
+ int index = -1;
+
+ index = gf_get_index_by_elem (afr_favorite_child_policies, policy);
+ if (index < 0 || index >= AFR_FAV_CHILD_POLICY_MAX)
+ return -1;
+
+ priv->fav_child_policy = index;
+
+ return 0;
+}
+int
reconfigure (xlator_t *this, dict_t *options)
{
afr_private_t *priv = NULL;
@@ -109,6 +131,7 @@ reconfigure (xlator_t *this, dict_t *options)
int ret = -1;
int index = -1;
char *qtype = NULL;
+ char *fav_child_policy = NULL;
priv = this->private;
@@ -228,6 +251,11 @@ reconfigure (xlator_t *this, dict_t *options)
GF_OPTION_RECONF ("shd-wait-qlength", priv->shd.wait_qlength,
options, uint32, out);
+ GF_OPTION_RECONF ("favorite-child-policy", fav_child_policy, options,
+ str, out);
+ if (afr_set_favorite_child_policy (priv, fav_child_policy) == -1)
+ goto out;
+
priv->did_discovery = _gf_false;
ret = 0;
@@ -261,6 +289,7 @@ init (xlator_t *this)
char *qtype = NULL;
char *xattrs_list = NULL;
char *ptr = NULL;
+ char *fav_child_policy = NULL;
if (!this->children) {
gf_msg (this->name, GF_LOG_ERROR, 0,
@@ -340,6 +369,10 @@ init (xlator_t *this)
fav_child->name, fav_child->name);
}
+ GF_OPTION_INIT ("favorite-child-policy", fav_child_policy, str, out);
+ if (afr_set_favorite_child_policy(priv, fav_child_policy) == -1)
+ goto out;
+
GF_OPTION_INIT ("shd-max-threads", priv->shd.max_threads,
uint32, out);
@@ -907,5 +940,18 @@ struct volume_options options[] = {
"granular way of recording changelogs and doing entry "
"self-heal.",
},
+ { .key = {"favorite-child-policy"},
+ .type = GF_OPTION_TYPE_STR,
+ .value = {"none", "size", "ctime", "mtime", "majority"},
+ .default_value = "none",
+ .description = "This option can be used to automatically resolve "
+ "split-brains using various policies without user "
+ "intervention. \"size\" picks the file with the "
+ "biggest size as the source. \"ctime\" and \"mtime\" "
+ "pick the file with the latest ctime and mtime "
+ "respectively as the source. \"majority\" picks a file"
+ " with identical mtime and size in more than half the "
+ "number of bricks in the replica.",
+ },
{ .key = {NULL} },
};