From f67dbab74a3d0a13a8f7ed31b8cc840c05042913 Mon Sep 17 00:00:00 2001 From: Susant Palai Date: Wed, 21 Jun 2017 17:52:45 +0530 Subject: cluster/rebalance: Use GF_XATTR_LIST_NODE_UUIDS_KEY to figure out local subvols. Afr has introduced a new key GF_XATTR_LIST_NODE_UUIDS_KEY, through which rebalance will figure out its local subvolumes.(Reference bugid=1463250) key: GF_XATTR_NODE_UUID_KEY will continue to serve it's old purpose of returning the first afr chiild. test: prove tests/basic/distribute/rebal-all-nodes-migrate.t > BUG: 1463648 > Signed-off-by: Susant Palai Change-Id: I4d602feda2a05b29d2210c712a07a4ac6b8bc112 BUG: 1463250 Signed-off-by: N Balachandran Reviewed-on: https://review.gluster.org/17627 Smoke: Gluster Build System CentOS-regression: Gluster Build System Reviewed-by: Shyamsundar Ranganathan --- libglusterfs/src/glusterfs.h | 1 + xlators/cluster/dht/src/dht-common.c | 31 ++++++++++++++++++-- xlators/cluster/dht/src/dht-rebalance.c | 29 +++++++++++++++---- xlators/cluster/dht/src/tier.c | 50 +-------------------------------- 4 files changed, 55 insertions(+), 56 deletions(-) diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h index 4db6a8b29a7..90473734b42 100644 --- a/libglusterfs/src/glusterfs.h +++ b/libglusterfs/src/glusterfs.h @@ -85,6 +85,7 @@ #define GF_XATTR_NODE_UUID_KEY "trusted.glusterfs.node-uuid" #define GF_XATTR_LIST_NODE_UUIDS_KEY "trusted.glusterfs.list-node-uuids" #define GF_REBAL_FIND_LOCAL_SUBVOL "glusterfs.find-local-subvol" +#define GF_REBAL_OLD_FIND_LOCAL_SUBVOL "glusterfs.old-find-local-subvol" #define GF_XATTR_VOL_ID_KEY "trusted.glusterfs.volume-id" #define GF_XATTR_LOCKINFO_KEY "trusted.glusterfs.lockinfo" #define GF_META_LOCK_KEY "glusterfs.lock-migration-meta-lock" diff --git a/xlators/cluster/dht/src/dht-common.c b/xlators/cluster/dht/src/dht-common.c index cb63d0ad13b..87cd55d216c 100644 --- a/xlators/cluster/dht/src/dht-common.c +++ b/xlators/cluster/dht/src/dht-common.c @@ -2982,7 +2982,8 @@ dht_vgetxattr_fill_and_set (dht_local_t *local, dict_t **dict, xlator_t *this, (void) dht_fill_pathinfo_xattr (this, local, xattr_buf, local->alloc_len, flag, layout_buf); - } else if (XATTR_IS_NODE_UUID (local->xsel)) { + } else if ((XATTR_IS_NODE_UUID (local->xsel)) + || (XATTR_IS_NODE_UUID_LIST (local->xsel))) { (void) snprintf (xattr_buf, local->alloc_len, "%s", local->xattr_val); } else { @@ -3573,6 +3574,31 @@ dht_getxattr (call_frame_t *frame, xlator_t *this, if (key && DHT_IS_DIR(layout) && (!strcmp (key, GF_REBAL_FIND_LOCAL_SUBVOL))) { + ret = gf_asprintf + (&node_uuid_key, "%s", GF_XATTR_LIST_NODE_UUIDS_KEY); + if (ret == -1 || !node_uuid_key) { + gf_msg (this->name, GF_LOG_ERROR, 0, + DHT_MSG_NO_MEMORY, + "Failed to copy key"); + op_errno = ENOMEM; + goto err; + } + (void) strncpy (local->xsel, node_uuid_key, 256); + cnt = local->call_cnt = conf->subvolume_cnt; + for (i = 0; i < cnt; i++) { + STACK_WIND_COOKIE (frame, dht_find_local_subvol_cbk, + conf->subvolumes[i], + conf->subvolumes[i], + conf->subvolumes[i]->fops->getxattr, + loc, node_uuid_key, xdata); + } + if (node_uuid_key) + GF_FREE (node_uuid_key); + return 0; + } + + if (key && DHT_IS_DIR(layout) && + (!strcmp (key, GF_REBAL_OLD_FIND_LOCAL_SUBVOL))) { ret = gf_asprintf (&node_uuid_key, "%s", GF_XATTR_NODE_UUID_KEY); if (ret == -1 || !node_uuid_key) { @@ -3608,7 +3634,8 @@ dht_getxattr (call_frame_t *frame, xlator_t *this, if (key && DHT_IS_DIR(layout) && (XATTR_IS_PATHINFO (key) - || (strcmp (key, GF_XATTR_NODE_UUID_KEY) == 0))) { + || (strcmp (key, GF_XATTR_NODE_UUID_KEY) == 0) + || (strcmp (key, GF_XATTR_LIST_NODE_UUIDS_KEY) == 0))) { (void) strncpy (local->xsel, key, 256); cnt = local->call_cnt = layout->cnt; for (i = 0; i < cnt; i++) { diff --git a/xlators/cluster/dht/src/dht-rebalance.c b/xlators/cluster/dht/src/dht-rebalance.c index 4653ae798c1..087d67ad891 100644 --- a/xlators/cluster/dht/src/dht-rebalance.c +++ b/xlators/cluster/dht/src/dht-rebalance.c @@ -4091,21 +4091,40 @@ dht_get_local_subvols_and_nodeuuids (xlator_t *this, dht_conf_t *conf, loc_t *loc) { - dict_t *dict = NULL; - int ret = -1; + dict_t *dict = NULL; + gf_defrag_info_t *defrag = NULL; + int ret = -1; + + defrag = conf->defrag; + if (defrag->cmd != GF_DEFRAG_CMD_START_TIER) { /* Find local subvolumes */ + ret = syncop_getxattr (this, loc, &dict, + GF_REBAL_FIND_LOCAL_SUBVOL, + NULL, NULL); + if (ret && (ret != -ENODATA)) { + + gf_msg (this->name, GF_LOG_ERROR, -ret, 0, "local " + "subvolume determination failed with error: %d", + -ret); + ret = -1; + goto out; + } + + if (!ret) + goto out; + } + ret = syncop_getxattr (this, loc, &dict, - GF_REBAL_FIND_LOCAL_SUBVOL, + GF_REBAL_OLD_FIND_LOCAL_SUBVOL, NULL, NULL); if (ret) { - gf_msg (this->name, GF_LOG_ERROR, 0, 0, "local " + gf_msg (this->name, GF_LOG_ERROR, -ret, 0, "local " "subvolume determination failed with error: %d", -ret); ret = -1; goto out; } - ret = 0; out: return ret; diff --git a/xlators/cluster/dht/src/tier.c b/xlators/cluster/dht/src/tier.c index e4b910eb0e6..ebe3ccbbd0f 100644 --- a/xlators/cluster/dht/src/tier.c +++ b/xlators/cluster/dht/src/tier.c @@ -202,13 +202,6 @@ tier_check_same_node (xlator_t *this, loc_t *loc, gf_defrag_info_t *defrag) dict_t *dict = NULL; char *uuid_str = NULL; uuid_t node_uuid = {0,}; - char *dup_str = NULL; - char *str = NULL; - char *save_ptr = NULL; - int count = 0; - uint32_t hashval = 0; - int32_t index = 0; - char buf[GF_UUID_BUF_SIZE] = {0,}; GF_VALIDATE_OR_GOTO ("tier", this, out); GF_VALIDATE_OR_GOTO (this->name, loc, out); @@ -222,56 +215,16 @@ tier_check_same_node (xlator_t *this, loc_t *loc, gf_defrag_info_t *defrag) goto out; } - - /* This returns multiple node-uuids now - one for each brick - * of the subvol. - */ - if (dict_get_str (dict, GF_XATTR_NODE_UUID_KEY, &uuid_str) < 0) { gf_msg (this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "Failed to get node-uuid for %s", loc->path); + "Failed to get node-uuids for %s", loc->path); goto out; } - dup_str = gf_strdup (uuid_str); - str = dup_str; - - /* How many uuids returned? - * No need to check if one of these is that of the current node. - */ - - count = 1; - while ((str = strchr (str, ' '))) { - count++; - str++; - } - - /* Only one node-uuid - pure distribute? */ - if (count == 1) - goto check_node; - - uuid_utoa_r (loc->gfid, buf); - ret = dht_hash_compute (this, 0, buf, &hashval); - if (ret == 0) { - index = (hashval % count); - } - - count = 0; - str = dup_str; - while ((uuid_str = strtok_r (str, " ", &save_ptr))) { - if (count == index) - break; - count++; - str = NULL; - } - - -check_node: if (gf_uuid_parse (uuid_str, node_uuid)) { gf_msg (this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, "uuid_parse failed for %s", loc->path); - ret = -1; goto out; } @@ -287,7 +240,6 @@ out: if (dict) dict_unref(dict); - GF_FREE (dup_str); return ret; } -- cgit