summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src/glusterd-rebalance.c
diff options
context:
space:
mode:
authorAmar Tumballi <amar@gluster.com>2011-09-09 09:42:51 +0530
committerVijay Bellur <vijay@gluster.com>2011-09-13 02:10:12 -0700
commit25daa42911d2ff697880ee29c591cac5f2abebed (patch)
tree9555284c052e1e205909e91f578a8b46b522ec56 /xlators/mgmt/glusterd/src/glusterd-rebalance.c
parent17e57f27c714c94dd5d9fa91650f83d069f2f4e4 (diff)
support for de-commissioning a node using 'remove-brick'
to achieve this, we now create volume-file with 'decommissioned-nodes' option in distribute volume, then just perform the rebalance set of operations (with 'force' flag set). now onwards, the 'remove-brick' (with 'start' option) operation tries to migrate data from removed bricks to existing bricks. 'remove-brick' also supports similar options as of replace-brick. * (no options) -> works as 'force', will have the current behavior of remove-brick, ie., no data-migration, volume changes. * start (starts remove-brick with data-migration/draining process, which takes care of migrating data and once complete, will commit the changes to volume file) * pause (stop data migration, but keep the volume file intact with extra options whatever is set) * abort (stop data-migration, and fall back to old configuration) * commit (if volume is stopped, commits the changes to volumefile) * force (stops the data-migration and commits the changes to volume file) Change-Id: I3952bcfbe604a0952e68b6accace7014d5e401d3 BUG: 1952 Reviewed-on: http://review.gluster.com/118 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Vijay Bellur <vijay@gluster.com>
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-rebalance.c')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-rebalance.c46
1 files changed, 33 insertions, 13 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-rebalance.c b/xlators/mgmt/glusterd/src/glusterd-rebalance.c
index a013d0ad..defaf947 100644
--- a/xlators/mgmt/glusterd/src/glusterd-rebalance.c
+++ b/xlators/mgmt/glusterd/src/glusterd-rebalance.c
@@ -46,6 +46,7 @@
#include "cli1-xdr.h"
#include "xdr-generic.h"
+/* return values - 0: success, +ve: stopped, -ve: failure */
int
gf_glusterd_rebalance_move_data (glusterd_volinfo_t *volinfo, const char *dir)
{
@@ -66,7 +67,8 @@ gf_glusterd_rebalance_move_data (glusterd_volinfo_t *volinfo, const char *dir)
if (!fd)
goto out;
- if (defrag->cmd == GF_DEFRAG_CMD_START_MIGRATE_DATA_FORCE) {
+ if ((defrag->cmd == GF_DEFRAG_CMD_START_MIGRATE_DATA_FORCE) ||
+ (defrag->cmd == GF_DEFRAG_CMD_START_FORCE)) {
strcpy (force_string, "force");
} else {
strcpy (force_string, "not-force");
@@ -105,9 +107,11 @@ gf_glusterd_rebalance_move_data (glusterd_volinfo_t *volinfo, const char *dir)
}
UNLOCK (&defrag->lock);
- if (volinfo->defrag_status == GF_DEFRAG_STATUS_STOPED) {
+ if (volinfo->defrag_status !=
+ GF_DEFRAG_STATUS_MIGRATE_DATA_STARTED) {
+ /* It can be one of 'stopped|paused|commit' etc */
closedir (fd);
- ret = -1;
+ ret = 1;
goto out;
}
}
@@ -144,6 +148,7 @@ out:
return ret;
}
+/* return values - 0: success, +ve: stopped, -ve: failure */
int
gf_glusterd_rebalance_fix_layout (glusterd_volinfo_t *volinfo, const char *dir)
{
@@ -187,9 +192,11 @@ gf_glusterd_rebalance_fix_layout (glusterd_volinfo_t *volinfo, const char *dir)
break;
}
- if (volinfo->defrag_status == GF_DEFRAG_STATUS_STOPED) {
+ if (volinfo->defrag_status !=
+ GF_DEFRAG_STATUS_LAYOUT_FIX_STARTED) {
+ /* It can be one of 'stopped|paused|commit' etc */
closedir (fd);
- ret = -1;
+ ret = 1;
goto out;
}
}
@@ -210,6 +217,7 @@ glusterd_defrag_start (void *data)
int ret = -1;
struct stat stbuf = {0,};
+ THIS = volinfo->xl;
defrag = volinfo->defrag;
if (!defrag)
goto out;
@@ -240,8 +248,10 @@ glusterd_defrag_start (void *data)
/* Step 1: Fix layout of all the directories */
ret = gf_glusterd_rebalance_fix_layout (volinfo, defrag->mount);
+ if (ret < 0)
+ volinfo->defrag_status = GF_DEFRAG_STATUS_FAILED;
+ /* in both 'stopped' or 'failure' cases goto out */
if (ret) {
- volinfo->defrag_status = GF_DEFRAG_STATUS_FAILED;
goto out;
}
@@ -257,8 +267,10 @@ glusterd_defrag_start (void *data)
/* Step 2: Iterate over directories to move data */
ret = gf_glusterd_rebalance_move_data (volinfo, defrag->mount);
+ if (ret < 0)
+ volinfo->defrag_status = GF_DEFRAG_STATUS_FAILED;
+ /* in both 'stopped' or 'failure' cases goto out */
if (ret) {
- volinfo->defrag_status = GF_DEFRAG_STATUS_FAILED;
goto out;
}
@@ -267,7 +279,8 @@ glusterd_defrag_start (void *data)
}
/* Completed whole process */
- if (defrag->cmd == GF_DEFRAG_CMD_START)
+ if ((defrag->cmd == GF_DEFRAG_CMD_START) ||
+ (defrag->cmd == GF_DEFRAG_CMD_START_FORCE))
volinfo->defrag_status = GF_DEFRAG_STATUS_COMPLETE;
volinfo->rebalance_files = defrag->total_files;
@@ -281,9 +294,13 @@ out:
ret = runcmd ("umount", "-l", defrag->mount, NULL);
LOCK_DESTROY (&defrag->lock);
+
+ if (defrag->cbk_fn) {
+ defrag->cbk_fn (volinfo, volinfo->defrag_status);
+ }
+
GF_FREE (defrag);
}
-
return NULL;
}
@@ -332,7 +349,7 @@ glusterd_defrag_stop (glusterd_volinfo_t *volinfo, u_quad_t *files,
LOCK (&volinfo->defrag->lock);
{
- volinfo->defrag_status = GF_DEFRAG_STATUS_STOPED;
+ volinfo->defrag_status = GF_DEFRAG_STATUS_STOPPED;
*files = volinfo->defrag->total_files;
*size = volinfo->defrag->total_data;
}
@@ -497,7 +514,7 @@ out:
int
glusterd_handle_defrag_start (glusterd_volinfo_t *volinfo, char *op_errstr,
- size_t len, int cmd)
+ size_t len, int cmd, defrag_cbk_fn_t cbk)
{
int ret = -1;
glusterd_defrag_info_t *defrag = NULL;
@@ -552,6 +569,9 @@ glusterd_handle_defrag_start (glusterd_volinfo_t *volinfo, char *op_errstr,
volinfo->defrag_status = GF_DEFRAG_STATUS_LAYOUT_FIX_STARTED;
+ if (cbk)
+ defrag->cbk_fn = cbk;
+
ret = pthread_create (&defrag->th, NULL, glusterd_defrag_start,
volinfo);
if (ret) {
@@ -635,7 +655,7 @@ glusterd_handle_defrag_volume (rpcsvc_request_t *req)
case GF_DEFRAG_CMD_START_MIGRATE_DATA_FORCE:
{
ret = glusterd_handle_defrag_start (volinfo, msg, sizeof (msg),
- cli_req.cmd);
+ cli_req.cmd, NULL);
rsp.op_ret = ret;
break;
}
@@ -845,7 +865,7 @@ glusterd_op_rebalance (dict_t *dict, char **op_errstr, dict_t *rsp_dict)
case GF_DEFRAG_CMD_START_MIGRATE_DATA:
case GF_DEFRAG_CMD_START_MIGRATE_DATA_FORCE:
ret = glusterd_handle_defrag_start (volinfo, msg, sizeof (msg),
- cmd);
+ cmd, NULL);
break;
case GF_DEFRAG_CMD_STOP:
ret = glusterd_defrag_stop (volinfo, &files, &size,