Skip to content

Commit

Permalink
glusterd: Added volume-id to 'op' dictionary
Browse files Browse the repository at this point in the history
Volume-id passed in op dictionary would help detect possible split brains
among peers in a cluster. The idea is to check if the volume's id and
the vol-id that was passed are equal.
ie, same volume name, but different volume id indicate that glusterd
'metadata' of one of the participating peers is stale or there is
a split brain.

This is over and above the existing checksum based validation of peer
supplied cluster 'metadata' (ie, volume info file).

Change-Id: I1049ef249e417e540ccb4243e450f92fcd0f46f9
BUG: 797734
Signed-off-by: Krishnan Parthasarathi <kp@gluster.com>
Reviewed-on: http://review.gluster.com/3083
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Jeff Darcy <jdarcy@redhat.com>
Reviewed-by: Vijay Bellur <vijay@gluster.com>
  • Loading branch information
Krishnan Parthasarathi authored and vbellur committed Apr 13, 2012
1 parent b337b75 commit 8a45a0e
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 0 deletions.
8 changes: 8 additions & 0 deletions xlators/mgmt/glusterd/src/glusterd-brick-ops.c
Expand Up @@ -1065,6 +1065,10 @@ glusterd_op_stage_add_brick (dict_t *dict, char **op_errstr)
goto out;
}

ret = glusterd_validate_volume_id (dict, volinfo);
if (ret)
goto out;

if (glusterd_is_rb_ongoing (volinfo)) {
snprintf (msg, sizeof (msg), "Replace brick is in progress on "
"volume %s. Please retry after replace-brick "
Expand Down Expand Up @@ -1201,6 +1205,10 @@ glusterd_op_stage_remove_brick (dict_t *dict, char **op_errstr)
goto out;
}

ret = glusterd_validate_volume_id (dict, volinfo);
if (ret)
goto out;

if (glusterd_is_rb_ongoing (volinfo)) {
snprintf (msg, sizeof (msg), "Replace brick is in progress on "
"volume %s. Please retry after replace-brick "
Expand Down
53 changes: 53 additions & 0 deletions xlators/mgmt/glusterd/src/glusterd-op-sm.c
Expand Up @@ -504,6 +504,7 @@ glusterd_op_stage_reset_volume (dict_t *dict, char **op_errstr)
char msg[2048] = {0};
char *key = NULL;
char *key_fixed = NULL;
glusterd_volinfo_t *volinfo = NULL;

ret = dict_get_str (dict, "volname", &volname);

Expand All @@ -522,6 +523,13 @@ glusterd_op_stage_reset_volume (dict_t *dict, char **op_errstr)
ret = -1;
goto out;
}
ret = glusterd_volinfo_find (volname, &volinfo);
if (ret)
goto out;

ret = glusterd_validate_volume_id (dict, volinfo);
if (ret)
goto out;

ret = dict_get_str (dict, "key", &key);
if (ret) {
Expand Down Expand Up @@ -568,6 +576,7 @@ glusterd_op_stage_sync_volume (dict_t *dict, char **op_errstr)
gf_boolean_t exists = _gf_false;
glusterd_peerinfo_t *peerinfo = NULL;
char msg[2048] = {0,};
glusterd_volinfo_t *volinfo = NULL;

ret = dict_get_str (dict, "hostname", &hostname);
if (ret) {
Expand Down Expand Up @@ -607,6 +616,13 @@ glusterd_op_stage_sync_volume (dict_t *dict, char **op_errstr)
ret = -1;
goto out;
}
ret = glusterd_volinfo_find (volname, &volinfo);
if (ret)
goto out;

ret = glusterd_validate_volume_id (dict, volinfo);
if (ret)
goto out;
} else {
ret = 0;
}
Expand Down Expand Up @@ -664,6 +680,10 @@ glusterd_op_stage_status_volume (dict_t *dict, char **op_errstr)
goto out;
}

ret = glusterd_validate_volume_id (dict, volinfo);
if (ret)
goto out;

ret = glusterd_is_volume_started (volinfo);
if (!ret) {
snprintf (msg, sizeof (msg), "Volume %s is not started",
Expand Down Expand Up @@ -799,6 +819,10 @@ glusterd_op_stage_stats_volume (dict_t *dict, char **op_errstr)
goto out;
}

ret = glusterd_validate_volume_id (dict, volinfo);
if (ret)
goto out;

ret = dict_get_int32 (dict, "op", &stats_op);
if (ret) {
snprintf (msg, sizeof (msg), "Volume profile op get failed");
Expand Down Expand Up @@ -1771,6 +1795,9 @@ glusterd_op_build_payload (dict_t **req)
void *ctx = NULL;
dict_t *req_dict = NULL;
glusterd_op_t op = GD_OP_NONE;
char *volname = NULL;
char *volid = NULL;
glusterd_volinfo_t *volinfo = NULL;

GF_ASSERT (req);

Expand Down Expand Up @@ -1820,6 +1847,32 @@ glusterd_op_build_payload (dict_t **req)
case GD_OP_DEFRAG_BRICK_VOLUME:
{
dict_t *dict = ctx;
ret = dict_get_str (dict, "volname", &volname);
if (ret) {
gf_log (THIS->name, GF_LOG_CRITICAL,
"volname is not present in "
"operation ctx");
goto out;
}
ret = glusterd_volinfo_find (volname, &volinfo);
if (ret) {
gf_log (THIS->name, GF_LOG_ERROR,
"volume %s not present in "
"the cluster", volname);
goto out;
}
volid = gf_strdup (uuid_utoa (volinfo->volume_id));
if (!volid) {
ret = -1;
goto out;
}
ret = dict_set_dynstr (dict, "vol-id", volid);
if (ret) {
gf_log (THIS->name, GF_LOG_ERROR,
"Failed to set volume id in "
"dictionary");
goto out;
}
dict_copy (dict, req_dict);
}
break;
Expand Down
28 changes: 28 additions & 0 deletions xlators/mgmt/glusterd/src/glusterd-utils.c
Expand Up @@ -5328,3 +5328,31 @@ glusterd_is_local_brick (xlator_t *this, glusterd_volinfo_t *volinfo,
out:
return local;
}
int
glusterd_validate_volume_id (dict_t *op_dict, glusterd_volinfo_t *volinfo)
{
int ret = -1;
char *volid_str = NULL;
uuid_t vol_uid = {0, };

ret = dict_get_str (op_dict, "vol-id", &volid_str);
if (ret) {
gf_log (THIS->name, GF_LOG_ERROR, "Failed to get volume id");
goto out;
}
ret = uuid_parse (volid_str, vol_uid);
if (ret) {
gf_log (THIS->name, GF_LOG_ERROR, "Failed to parse uuid");
goto out;
}

if (uuid_compare (vol_uid, volinfo->volume_id)) {
gf_log (THIS->name, GF_LOG_ERROR, "Volume ids are different. "
"Possibly a split brain among peers.");
ret = -1;
goto out;
}

out:
return ret;
}
2 changes: 2 additions & 0 deletions xlators/mgmt/glusterd/src/glusterd-utils.h
Expand Up @@ -432,4 +432,6 @@ glusterd_get_brickinfo_by_position (glusterd_volinfo_t *volinfo, uint32_t pos);
gf_boolean_t
glusterd_is_local_brick (xlator_t *this, glusterd_volinfo_t *volinfo,
glusterd_brickinfo_t *brickinfo);
int
glusterd_validate_volume_id (dict_t *op_dict, glusterd_volinfo_t *volinfo);
#endif
24 changes: 24 additions & 0 deletions xlators/mgmt/glusterd/src/glusterd-volume-ops.c
Expand Up @@ -830,6 +830,10 @@ glusterd_op_stage_start_volume (dict_t *dict, char **op_errstr)
if (ret)
goto out;

ret = glusterd_validate_volume_id (dict, volinfo);
if (ret)
goto out;

list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) {
ret = glusterd_resolve_brick (brickinfo);
if (ret) {
Expand Down Expand Up @@ -905,6 +909,10 @@ glusterd_op_stage_stop_volume (dict_t *dict, char **op_errstr)
if (ret)
goto out;

ret = glusterd_validate_volume_id (dict, volinfo);
if (ret)
goto out;

/* If 'force' flag is given, no check is required */
if (flags & GF_CLI_FLAG_OP_FORCE)
goto out;
Expand Down Expand Up @@ -1000,6 +1008,10 @@ glusterd_op_stage_delete_volume (dict_t *dict, char **op_errstr)

ret = glusterd_volinfo_find (volname, &volinfo);

if (ret)
goto out;

ret = glusterd_validate_volume_id (dict, volinfo);
if (ret)
goto out;

Expand Down Expand Up @@ -1056,6 +1068,10 @@ glusterd_op_stage_heal_volume (dict_t *dict, char **op_errstr)
goto out;
}

ret = glusterd_validate_volume_id (dict, volinfo);
if (ret)
goto out;

if (!glusterd_is_volume_replicate (volinfo)) {
ret = -1;
snprintf (msg, sizeof (msg), "Volume %s is not of type "
Expand Down Expand Up @@ -1142,6 +1158,10 @@ glusterd_op_stage_statedump_volume (dict_t *dict, char **op_errstr)
goto out;
}

ret = glusterd_validate_volume_id (dict, volinfo);
if (ret)
goto out;

is_running = glusterd_is_volume_started (volinfo);
if (!is_running) {
snprintf (msg, sizeof(msg), "Volume %s is not in a started"
Expand Down Expand Up @@ -1209,6 +1229,10 @@ glusterd_op_stage_clearlocks_volume (dict_t *dict, char **op_errstr)
goto out;
}

ret = glusterd_validate_volume_id (dict, volinfo);
if (ret)
goto out;

if (!glusterd_is_volume_started (volinfo)) {
snprintf (msg, sizeof(msg), "Volume %s is not started",
volname);
Expand Down

0 comments on commit 8a45a0e

Please sign in to comment.