glusterd/snapshot : Barrier code integration with snapshot codebase.

As we have new barrier translator in place, we are making use of
that during snapshot phase.

During snapshot create (pre-commit), we enable the barrier feature
and after the commit we disable it.

Change-Id: I94212b1c06b0d9b12255ee98313e2d8549b34b17
BUG: 1061685
Signed-off-by: Sachin Pandit <spandit@redhat.com>
Reviewed-on: http://review.gluster.org/7561
Reviewed-by: Kaushal M <kaushal@redhat.com>
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Vijay Bellur <vbellur@redhat.com>
This commit is contained in:
Sachin Pandit 2014-04-30 00:41:56 +05:30 committed by Vijay Bellur
parent 9934033030
commit 12f1fab930
4 changed files with 125 additions and 9 deletions

View File

@ -19,6 +19,8 @@
#include "glusterd-locks.h"
#include "glusterd-mgmt.h"
#include "glusterd-op-sm.h"
#include "glusterd-volgen.h"
#include "glusterd-store.h"
extern struct rpc_clnt_program gd_mgmt_v3_prog;
@ -1686,6 +1688,68 @@ out:
return 0;
}
int32_t
glusterd_set_barrier_value (dict_t *dict, char *option)
{
int32_t ret = -1;
xlator_t *this = NULL;
glusterd_volinfo_t *vol = NULL;
char *volname = NULL;
this = THIS;
GF_ASSERT (this);
GF_ASSERT (dict);
GF_ASSERT (option);
/* TODO : Change this when we support multiple volume.
* As of now only snapshot of single volume is supported,
* Hence volname1 is directly fetched
*/
ret = dict_get_str (dict, "volname1", &volname);
if (ret) {
gf_log (this->name, GF_LOG_ERROR, "Volname not present in "
"dict");
goto out;
}
ret = glusterd_volinfo_find (volname, &vol);
if (ret) {
gf_log (this->name, GF_LOG_ERROR, "Volume %s not found ",
volname);
goto out;
}
ret = dict_set_dynstr_with_alloc (dict, "barrier", option);
if (ret) {
gf_log (this->name, GF_LOG_ERROR, "Failed to set barrier op "
"in request dictionary");
goto out;
}
ret = dict_set_dynstr_with_alloc (vol->dict, "features.barrier",
option);
if (ret) {
gf_log (this->name, GF_LOG_ERROR, "Failed to set barrier op "
"in volume option dict");
goto out;
}
gd_update_volume_op_versions (vol);
ret = glusterd_create_volfiles (vol);
if (ret) {
gf_log (this->name, GF_LOG_ERROR, "Failed to create volfiles");
goto out;
}
ret = glusterd_store_volinfo (vol, GLUSTERD_VOLINFO_VER_AC_INCREMENT);
out:
gf_log (this->name, GF_LOG_DEBUG, "Returning %d", ret);
return ret;
}
int32_t
glusterd_mgmt_v3_initiate_snap_phases (rpcsvc_request_t *req, glusterd_op_t op,
dict_t *dict)
@ -1776,10 +1840,16 @@ glusterd_mgmt_v3_initiate_snap_phases (rpcsvc_request_t *req, glusterd_op_t op,
goto out;
}
/* BRICK OP PHASE for initiating barrier*/
ret = dict_set_int32 (req_dict, "barrier", 1);
if (ret)
/* Set the operation type as pre, so that differentiation can be
* made whether the brickop is sent during pre-commit or post-commit
*/
ret = dict_set_dynstr_with_alloc (req_dict, "operation-type", "pre");
if (ret) {
gf_log (this->name, GF_LOG_ERROR, "Failed to set "
"operation-type in dictionary");
goto out;
}
ret = glusterd_mgmt_v3_brick_op (conf, op, req_dict,
&op_errstr, npeers);
if (ret) {
@ -1821,10 +1891,16 @@ glusterd_mgmt_v3_initiate_snap_phases (rpcsvc_request_t *req, glusterd_op_t op,
success = _gf_true;
unbarrier:
/* BRICK OP PHASE for removing the barrier*/
ret = dict_set_int32 (req_dict, "barrier", 0);
if (ret)
/* Set the operation type as post, so that differentiation can be
* made whether the brickop is sent during pre-commit or post-commit
*/
ret = dict_set_dynstr_with_alloc (req_dict, "operation-type", "post");
if (ret) {
gf_log (this->name, GF_LOG_ERROR, "Failed to set "
"operation-type in dictionary");
goto out;
}
ret = glusterd_mgmt_v3_brick_op (conf, op, req_dict,
&op_errstr, npeers);

View File

@ -42,4 +42,6 @@ glusterd_mgmt_v3_initiate_snap_phases (rpcsvc_request_t *req, glusterd_op_t op,
int
glusterd_snap_pre_validate_use_rsp_dict (dict_t *dst, dict_t *src);
int32_t
glusterd_set_barrier_value (dict_t *dict, char *option);
#endif /* _GLUSTERD_MGMT_H_ */

View File

@ -523,12 +523,11 @@ glusterd_brick_op_build_payload (glusterd_op_t op, glusterd_brickinfo_t *brickin
if (!brick_req)
goto out;
brick_req->op = GLUSTERD_VOLUME_BARRIER_OP;
brick_req->op = GLUSTERD_BRICK_BARRIER;
ret = dict_get_str (dict, "volname", &volname);
if (ret)
goto out;
snprintf (name, 1024, "%s-server",volname);
brick_req->name = gf_strdup (name);
brick_req->name = gf_strdup (volname);
break;
case GD_OP_BARRIER:

View File

@ -5043,6 +5043,7 @@ glusterd_snapshot_brickop (dict_t *dict, char **op_errstr, dict_t *rsp_dict)
char *volname = NULL;
int32_t snap_command = 0;
xlator_t *this = NULL;
char *op_type = NULL;
this = THIS;
@ -5059,6 +5060,44 @@ glusterd_snapshot_brickop (dict_t *dict, char **op_errstr, dict_t *rsp_dict)
switch (snap_command) {
case GF_SNAP_OPTION_TYPE_CREATE:
/* op_type with tell us whether its pre-commit operation
* or post-commit
*/
ret = dict_get_str (dict, "operation-type", &op_type);
if (ret) {
gf_log (this->name, GF_LOG_ERROR, "Failed to fetch "
"operation type");
goto out;
}
if (strcmp (op_type, "pre") == 0) {
/* BRICK OP PHASE for enabling barrier, Enable barrier
* if its a pre-commit operation
*/
ret = glusterd_set_barrier_value (dict, "enable");
if (ret) {
gf_log (this->name, GF_LOG_ERROR, "Failed to "
"set barrier value as enable in dict");
goto out;
}
} else if (strcmp (op_type, "post") == 0) {
/* BRICK OP PHASE for disabling barrier, Disable barrier
* if its a post-commit operation
*/
ret = glusterd_set_barrier_value (dict, "disable");
if (ret) {
gf_log (this->name, GF_LOG_ERROR, "Failed to "
"set barrier value as disable in "
"dict");
goto out;
}
} else {
ret = -1;
gf_log (this->name, GF_LOG_ERROR, "Invalid op_type");
goto out;
}
ret = dict_get_int64 (dict, "volcount", &vol_count);
if (ret)
goto out;