diff options
author | Mohit Agrawal <moagrawal@redhat.com> | 2019-11-06 10:32:04 +0530 |
---|---|---|
committer | Atin Mukherjee <amukherj@redhat.com> | 2019-11-12 06:17:40 +0000 |
commit | e3d97f57c8e25e8b44d3c96b09d69336ff6edb4b (patch) | |
tree | 9b22c40e9a1abd0e06c0e87b043506af535e476f /xlators/mgmt/glusterd/src/glusterd-handshake.c | |
parent | 50b6806bb2697246bdc1b9ac5ef19af61584e010 (diff) |
glusterd: Client Handling of Elastic Clusters
Configure the list of gluster servers in the key
GLUSTERD_BRICK_SERVERS at the time of GETSPEC RPC CALL
and access the value in client side to update volfile
serve list so that client would be able to connect
next volfile server in case of current volfile server
is down
Updates #741
Signed-off-by: Mohit Agrawal <moagrawa@redhat.com>
Change-Id: I23f36ddb92982bb02ffd83937a8bd8a2c97e8104
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-handshake.c')
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-handshake.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-handshake.c b/xlators/mgmt/glusterd/src/glusterd-handshake.c index 1671c2481dc..1cbdc304916 100644 --- a/xlators/mgmt/glusterd/src/glusterd-handshake.c +++ b/xlators/mgmt/glusterd/src/glusterd-handshake.c @@ -907,10 +907,20 @@ __server_getspec(rpcsvc_request_t *req) peer_info_t *peerinfo = NULL; xlator_t *this = NULL; dict_t *dict = NULL; + glusterd_peerinfo_t *peer = NULL; + glusterd_conf_t *conf = NULL; + int peer_cnt = 0; + char *peer_hosts = NULL; + char *tmp_str = NULL; + char portstr[10] = { + 0, + }; + int len = 0; this = THIS; GF_ASSERT(this); + conf = this->private; ret = xdr_to_generic(req->msg[0], &args, (xdrproc_t)xdr_gf_getspec_req); if (ret < 0) { // failed to decode msg; @@ -998,6 +1008,43 @@ __server_getspec(rpcsvc_request_t *req) dict); } + RCU_READ_LOCK; + cds_list_for_each_entry_rcu(peer, &conf->peers, uuid_list) + { + if (!peer->connected) + continue; + if (!peer_hosts) { + if (peer->port) { + snprintf(portstr, sizeof(portstr), "%d", peer->port); + } else { + snprintf(portstr, sizeof(portstr), "%d", GLUSTERD_DEFAULT_PORT); + } + len = strlen(peer->hostname) + strlen(portstr) + 3; + tmp_str = GF_CALLOC(1, len, gf_gld_mt_char); + snprintf(tmp_str, len, "%s%s%s%s", peer->hostname, ":", portstr, + " "); + peer_hosts = tmp_str; + } else { + len = strlen(peer_hosts) + strlen(peer->hostname) + + strlen(portstr) + 3; + tmp_str = GF_CALLOC(1, len, gf_gld_mt_char); + snprintf(tmp_str, len, "%s%s%s%s%s", peer_hosts, peer->hostname, + ":", portstr, " "); + GF_FREE(peer_hosts); + peer_hosts = tmp_str; + } + peer_cnt++; + } + RCU_READ_UNLOCK; + if (peer_cnt) { + ret = dict_set_str(dict, GLUSTERD_BRICK_SERVERS, peer_hosts); + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, + "failed to set peer_host in dict"); + goto fail; + } + } + if (ret == 0) { if (dict->count > 0) { ret = dict_allocate_and_serialize(dict, &rsp.xdata.xdata_val, @@ -1076,6 +1123,8 @@ fail: free(args.key); // malloced by xdr free(rsp.spec); + if (peer_hosts) + GF_FREE(peer_hosts); if (dict) dict_unref(dict); |