From 8beaf169e39b262416e2274a028292379d39b310 Mon Sep 17 00:00:00 2001 From: Ravishankar N Date: Fri, 9 Jan 2015 14:43:22 +0000 Subject: cluster/afr: split-brain resolution CLI Extend the AFR heal command to include automated split-brain resolution. This patch [3/3] is the final patch for afr automated split-brain resolution implementation. "gluster volume heal [full | statistics [heal-count [replica ]] |info [healed | heal-failed | split-brain]| split-brain {bigger-file |source-brick []}]" The new additions being: 1.gluster volume heal split-brain bigger-file Locates the replica containing the FILE, selects bigger-file as source and completes heal. 2.gluster volume heal split-brain source-brick Selects present in as source and completes heal. 3.gluster volume heal split-brain Selects all split-brained files in as source and completes heal. Note: can be either the full file name as seen from the root of the volume (or) the gfid-string representation of the file, which sometimes gets displayed in the heal info command's output. Entry/gfid split-brain resolution is not supported. Example can be found in the test case. Change-Id: I4649733922d406f14f28ee9033a5cb627b9538b3 BUG: 1136769 Signed-off-by: Ravishankar N Reviewed-on: http://review.gluster.org/9377 Reviewed-by: Pranith Kumar Karampuri Tested-by: Pranith Kumar Karampuri Tested-by: Gluster Build System --- cli/src/cli-cmd-parser.c | 91 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 80 insertions(+), 11 deletions(-) (limited to 'cli/src/cli-cmd-parser.c') diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 28888ba656..53b14d2770 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -2929,6 +2929,43 @@ out: return ret; } +static int +set_hostname_path_in_dict (const char *token, dict_t *dict, int heal_op) +{ + char *hostname = NULL; + char *path = NULL; + int ret = 0; + + ret = extract_hostname_path_from_token (token, &hostname, &path); + if (ret) + goto out; + + switch (heal_op) { + case GF_AFR_OP_SBRAIN_HEAL_FROM_BRICK: + ret = dict_set_dynstr (dict, "heal-source-hostname", + hostname); + if (ret) + goto out; + ret = dict_set_dynstr (dict, "heal-source-brickpath", + path); + break; + case GF_AFR_OP_STATISTICS_HEAL_COUNT_PER_REPLICA: + ret = dict_set_dynstr (dict, "per-replica-cmd-hostname", + hostname); + if (ret) + goto out; + ret = dict_set_dynstr (dict, "per-replica-cmd-path", + path); + break; + default: + ret = -1; + break; + } + +out: + return ret; + +} int cli_cmd_volume_heal_options_parse (const char **words, int wordcount, @@ -2936,8 +2973,6 @@ cli_cmd_volume_heal_options_parse (const char **words, int wordcount, { int ret = 0; dict_t *dict = NULL; - char *hostname = NULL; - char *path = NULL; dict = dict_new (); if (!dict) @@ -3008,6 +3043,35 @@ cli_cmd_volume_heal_options_parse (const char **words, int wordcount, ret = -1; goto out; } + if (wordcount == 6) { + if (strcmp (words[3], "split-brain")) { + ret = -1; + goto out; + } + if (!strcmp (words[4], "bigger-file")) { + ret = dict_set_int32 (dict, "heal-op", + GF_AFR_OP_SBRAIN_HEAL_FROM_BIGGER_FILE); + if (ret) + goto out; + ret = dict_set_str (dict, "file", (char *)words[5]); + if (ret) + goto out; + goto done; + } + if (!strcmp (words[4], "source-brick")) { + ret = dict_set_int32 (dict, "heal-op", + GF_AFR_OP_SBRAIN_HEAL_FROM_BRICK); + if (ret) + goto out; + ret = set_hostname_path_in_dict (words[5], dict, + GF_AFR_OP_SBRAIN_HEAL_FROM_BRICK); + if (ret) + goto out; + goto done; + } + ret = -1; + goto out; + } if (wordcount == 7) { if (!strcmp (words[3], "statistics") && !strcmp (words[4], "heal-count") @@ -3017,21 +3081,26 @@ cli_cmd_volume_heal_options_parse (const char **words, int wordcount, GF_AFR_OP_STATISTICS_HEAL_COUNT_PER_REPLICA); if (ret) goto out; - ret = extract_hostname_path_from_token (words[6], - &hostname, &path); + ret = set_hostname_path_in_dict (words[6], dict, + GF_AFR_OP_STATISTICS_HEAL_COUNT_PER_REPLICA); if (ret) goto out; - ret = dict_set_dynstr (dict, "per-replica-cmd-hostname", - hostname); + goto done; + + } + if (!strcmp (words[3], "split-brain") && + !strcmp (words[4], "source-brick")) { + ret = dict_set_int32 (dict, "heal-op", + GF_AFR_OP_SBRAIN_HEAL_FROM_BRICK); + ret = set_hostname_path_in_dict (words[5], dict, + GF_AFR_OP_SBRAIN_HEAL_FROM_BRICK); if (ret) goto out; - ret = dict_set_dynstr (dict, "per-replica-cmd-path", - path); + ret = dict_set_str (dict, "file", + (char *) words[6]); if (ret) goto out; - else - goto done; - + goto done; } } ret = -1; -- cgit