From 4175d3e8e2ca1afc0e9f3404ca04fe29d522c81f Mon Sep 17 00:00:00 2001 From: Amar Tumballi Date: Tue, 1 Mar 2011 03:37:12 +0000 Subject: gluster rebalance: give option to split the command the 'gluster volume rebalance start' is enhanced with two more options: * 'gluster volume rebalance fix-layout start' (for fixing layout only) * 'gluster volume rebalance migrate-data start' (for migrating data only) Also the old way of running rebalance in one shot will still work fine * 'gluster volume rebalance start' Signed-off-by: Amar Tumballi Signed-off-by: Anand V. Avati BUG: 2258 (enhance gluster volume rebalance) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2258 --- xlators/mgmt/glusterd/src/glusterd-rebalance.c | 119 ++++++++++++------------- xlators/mgmt/glusterd/src/glusterd-utils.c | 4 +- xlators/mgmt/glusterd/src/glusterd.h | 7 +- 3 files changed, 65 insertions(+), 65 deletions(-) (limited to 'xlators/mgmt/glusterd') diff --git a/xlators/mgmt/glusterd/src/glusterd-rebalance.c b/xlators/mgmt/glusterd/src/glusterd-rebalance.c index c1dbead2eed..58c12c19385 100644 --- a/xlators/mgmt/glusterd/src/glusterd-rebalance.c +++ b/xlators/mgmt/glusterd/src/glusterd-rebalance.c @@ -184,8 +184,7 @@ gf_glusterd_rebalance_move_data (glusterd_volinfo_t *volinfo, const char *dir) if (!S_ISDIR (stbuf.st_mode)) continue; - ret = gf_glusterd_rebalance_move_data (volinfo, - full_path); + ret = gf_glusterd_rebalance_move_data (volinfo, full_path); if (ret) break; } @@ -289,32 +288,44 @@ glusterd_defrag_start (void *data) sys_lgetxattr (defrag->mount, "trusted.distribute.fix.layout", &value, 128); - /* root's layout got fixed */ - defrag->total_files = 1; + if ((defrag->cmd == GF_DEFRAG_CMD_START) || + (defrag->cmd == GF_DEFRAG_CMD_START_LAYOUT_FIX)) { + /* root's layout got fixed */ + defrag->total_files = 1; - /* Step 1: Fix layout of all the directories */ - ret = gf_glusterd_rebalance_fix_layout (volinfo, defrag->mount); - if (ret) { - volinfo->defrag_status = GF_DEFRAG_STATUS_FAILED; - goto out; + /* Step 1: Fix layout of all the directories */ + ret = gf_glusterd_rebalance_fix_layout (volinfo, defrag->mount); + if (ret) { + volinfo->defrag_status = GF_DEFRAG_STATUS_FAILED; + goto out; + } + + /* Completed first step */ + volinfo->defrag_status = GF_DEFRAG_STATUS_LAYOUT_FIX_COMPLETE; } - /* Completed first step */ - volinfo->defrag_status = GF_DEFRAG_STATUS_LAYOUT_FIX_COMPLETE; + if ((defrag->cmd == GF_DEFRAG_CMD_START) || + (defrag->cmd == GF_DEFRAG_CMD_START_MIGRATE_DATA)) { + /* It was used by number of layout fixes on directories */ + defrag->total_files = 0; - /* It was used by number of layout fixes on directories */ - defrag->total_files = 0; + volinfo->defrag_status = GF_DEFRAG_STATUS_MIGRATE_DATA_STARTED; - /* Step 2: Iterate over directories to move data */ - ret = gf_glusterd_rebalance_move_data (volinfo, defrag->mount); - if (ret) { - volinfo->defrag_status = GF_DEFRAG_STATUS_FAILED; + /* Step 2: Iterate over directories to move data */ + ret = gf_glusterd_rebalance_move_data (volinfo, defrag->mount); + if (ret) { + volinfo->defrag_status = GF_DEFRAG_STATUS_FAILED; + goto out; + } + + /* Completed second step */ + volinfo->defrag_status = GF_DEFRAG_STATUS_MIGRATE_DATA_COMPLETE; } /* Completed whole process */ - if (!ret) { - volinfo->defrag_status = GF_DEFRAG_STATUS_COMPLETE; - } + if (defrag->cmd == GF_DEFRAG_CMD_START) + volinfo->defrag_status = GF_DEFRAG_STATUS_COMPLETE; + volinfo->rebalance_files = defrag->total_files; volinfo->rebalance_data = defrag->total_data; volinfo->lookedup_files = defrag->num_files_lookedup; @@ -441,6 +452,16 @@ void glusterd_rebalance_cmd_attempted_log (int cmd, char *volname) { switch (cmd) { + case GF_DEFRAG_CMD_START_LAYOUT_FIX: + gf_cmd_log ("Volume rebalance"," on volname: %s " + "cmd: start fix layout , attempted", + volname); + break; + case GF_DEFRAG_CMD_START_MIGRATE_DATA: + gf_cmd_log ("Volume rebalance"," on volname: %s " + "cmd: start data migrate attempted", + volname); + break; case GF_DEFRAG_CMD_START: gf_cmd_log ("Volume rebalance"," on volname: %s " "cmd: start, attempted", volname); @@ -452,9 +473,9 @@ glusterd_rebalance_cmd_attempted_log (int cmd, char *volname) default: break; } - gf_log ("glusterd", GF_LOG_NORMAL, "Received rebalance volume %s on %s", - (cmd == GF_DEFRAG_CMD_START)?"start":(cmd == GF_DEFRAG_CMD_STOP)?"stop":"status" - , volname); + + gf_log ("glusterd", GF_LOG_NORMAL, "Received rebalance volume %d on %s", + cmd, volname); } void @@ -498,7 +519,7 @@ out: int glusterd_handle_defrag_start (glusterd_volinfo_t *volinfo, char *op_errstr, - size_t len) + size_t len, int cmd) { int ret = -1; glusterd_defrag_info_t *defrag = NULL; @@ -521,6 +542,8 @@ glusterd_handle_defrag_start (glusterd_volinfo_t *volinfo, char *op_errstr, defrag = volinfo->defrag; + defrag->cmd = cmd; + LOCK_INIT (&defrag->lock); snprintf (defrag->mount, 1024, "%s/mount/%s", priv->workdir, volinfo->volname); @@ -546,7 +569,7 @@ glusterd_handle_defrag_start (glusterd_volinfo_t *volinfo, char *op_errstr, goto out; } - volinfo->defrag_status = GF_DEFRAG_STATUS_STARTED; + volinfo->defrag_status = GF_DEFRAG_STATUS_LAYOUT_FIX_STARTED; ret = pthread_create (&defrag->th, NULL, glusterd_defrag_start, volinfo); @@ -608,24 +631,6 @@ glusterd_handle_defrag_volume_v2 (rpcsvc_request_t *req) goto out; } - switch (cli_req.cmd) { - case GF_DEFRAG_CMD_START: - gf_cmd_log ("Volume rebalance"," on volname: %s " - "cmd: start, attempted", cli_req.volname); - break; - case GF_DEFRAG_CMD_STOP: - gf_cmd_log ("Volume rebalance"," on volname: %s " - "cmd: stop, attempted", cli_req.volname); - break; - default: - break; - } - - gf_log ("glusterd", GF_LOG_NORMAL, "Received rebalance volume %s on %s", - ((cli_req.cmd == GF_DEFRAG_CMD_START) ? "start" : - (cli_req.cmd == GF_DEFRAG_CMD_STOP) ? "stop" : "status"), - cli_req.volname); - glusterd_rebalance_cmd_attempted_log (cli_req.cmd, cli_req.volname); rsp.volname = cli_req.volname; @@ -636,9 +641,13 @@ glusterd_handle_defrag_volume_v2 (rpcsvc_request_t *req) &volinfo, msg, sizeof (msg)); if (ret) goto out; + switch (cli_req.cmd) { case GF_DEFRAG_CMD_START: - ret = glusterd_handle_defrag_start (volinfo, msg, sizeof (msg)); + case GF_DEFRAG_CMD_START_LAYOUT_FIX: + case GF_DEFRAG_CMD_START_MIGRATE_DATA: + ret = glusterd_handle_defrag_start (volinfo, msg, sizeof (msg), + cli_req.cmd); rsp.op_ret = ret; break; case GF_DEFRAG_CMD_STOP: @@ -684,22 +693,7 @@ glusterd_handle_defrag_volume (rpcsvc_request_t *req) goto out; } - switch (cli_req.cmd) { - case GF_DEFRAG_CMD_START: - gf_cmd_log ("Volume rebalance"," on volname: %s " - "cmd: start, attempted", cli_req.volname); - break; - case GF_DEFRAG_CMD_STOP: - gf_cmd_log ("Volume rebalance"," on volname: %s " - "cmd: stop, attempted", cli_req.volname); - break; - default: - break; - } - gf_log ("glusterd", GF_LOG_NORMAL, "Received rebalance volume %s on %s", - ((cli_req.cmd == GF_DEFRAG_CMD_START) ? "start" : - (cli_req.cmd == GF_DEFRAG_CMD_STOP) ? "stop" : "status"), - cli_req.volname); + glusterd_rebalance_cmd_attempted_log (cli_req.cmd, cli_req.volname); rsp.volname = cli_req.volname; rsp.op_ret = -1; @@ -710,8 +704,11 @@ glusterd_handle_defrag_volume (rpcsvc_request_t *req) goto out; switch (cli_req.cmd) { case GF_DEFRAG_CMD_START: + case GF_DEFRAG_CMD_START_LAYOUT_FIX: + case GF_DEFRAG_CMD_START_MIGRATE_DATA: { - ret = glusterd_handle_defrag_start (volinfo, msg, sizeof (msg)); + ret = glusterd_handle_defrag_start (volinfo, msg, sizeof (msg), + cli_req.cmd); rsp.op_ret = ret; break; } diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index 0c910477635..cb38ddf88f6 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -2240,8 +2240,8 @@ out: int glusterd_is_defrag_on (glusterd_volinfo_t *volinfo) { - return ((volinfo->defrag_status == GF_DEFRAG_STATUS_STARTED) || - (volinfo->defrag_status == GF_DEFRAG_STATUS_LAYOUT_FIX_COMPLETE)); + return ((volinfo->defrag_status == GF_DEFRAG_STATUS_LAYOUT_FIX_STARTED) || + (volinfo->defrag_status == GF_DEFRAG_STATUS_MIGRATE_DATA_STARTED)); } int diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h index 06f35479c35..2b02a513981 100644 --- a/xlators/mgmt/glusterd/src/glusterd.h +++ b/xlators/mgmt/glusterd/src/glusterd.h @@ -133,11 +133,13 @@ struct gf_defrag_brickinfo_ { typedef enum gf_defrag_status_ { GF_DEFRAG_STATUS_NOT_STARTED, - GF_DEFRAG_STATUS_STARTED, - GF_DEFRAG_STATUS_LAYOUT_FIX_COMPLETE, + GF_DEFRAG_STATUS_LAYOUT_FIX_STARTED, + GF_DEFRAG_STATUS_MIGRATE_DATA_STARTED, GF_DEFRAG_STATUS_STOPED, GF_DEFRAG_STATUS_COMPLETE, GF_DEFRAG_STATUS_FAILED, + GF_DEFRAG_STATUS_LAYOUT_FIX_COMPLETE, + GF_DEFRAG_STATUS_MIGRATE_DATA_COMPLETE, } gf_defrag_status_t; struct glusterd_defrag_info_ { @@ -145,6 +147,7 @@ struct glusterd_defrag_info_ { uint64_t total_data; uint64_t num_files_lookedup; gf_lock_t lock; + int cmd; pthread_t th; char mount[1024]; char databuf[131072]; -- cgit