diff options
-rwxr-xr-x | tests/basic/tier/tier.t | 6 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-messages.h | 10 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-op-sm.c | 86 |
3 files changed, 101 insertions, 1 deletions
diff --git a/tests/basic/tier/tier.t b/tests/basic/tier/tier.t index a5bd09f8028..308e22c74db 100755 --- a/tests/basic/tier/tier.t +++ b/tests/basic/tier/tier.t @@ -113,6 +113,12 @@ TEST ! $CLI volume set $V0 cluster.watermark-low 90 TEST ! $CLI volume set $V0 cluster.read-freq-threshold -12 TEST ! $CLI volume set $V0 cluster.write-freq-threshold -12 +#check for watermark reset +TEST $CLI volume set $V0 cluster.watermark-low 10 +TEST $CLI volume set $V0 cluster.watermark-hi 30 +TEST ! $CLI volume reset $V0 cluster.watermark-low +TEST $CLI volume reset $V0 cluster.watermark-hi +TEST $CLI volume reset $V0 cluster.watermark-low # stop the volume and restart it. The rebalance daemon should restart. cd /tmp diff --git a/xlators/mgmt/glusterd/src/glusterd-messages.h b/xlators/mgmt/glusterd/src/glusterd-messages.h index 28c73d23d82..d185db0d2e5 100644 --- a/xlators/mgmt/glusterd/src/glusterd-messages.h +++ b/xlators/mgmt/glusterd/src/glusterd-messages.h @@ -41,7 +41,7 @@ #define GLUSTERD_COMP_BASE GLFS_MSGID_GLUSTERD -#define GLFS_NUM_MESSAGES 597 +#define GLFS_NUM_MESSAGES 598 #define GLFS_MSGID_END (GLUSTERD_COMP_BASE + GLFS_NUM_MESSAGES + 1) /* Messaged with message IDs */ @@ -4835,6 +4835,14 @@ */ #define GD_MSG_NO_SIG_TO_PID_ZERO (GLUSTERD_COMP_BASE + 597) +/*! + * @messageid + * @diagnosis + * @recommendedaction + * + */ + +#define GD_MSG_TIER_WATERMARK_RESET_FAIL (GLUSTERD_COMP_BASE + 598) /*------------*/ diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c index 5169f414e94..75469d68e26 100644 --- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c +++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c @@ -1449,6 +1449,82 @@ out: } return ret; } +static int +glusterd_water_limit_check (glusterd_volinfo_t *volinfo, gf_boolean_t is_hi, + char **op_errstr) +{ + + int ret = -1; + char *default_value = NULL; + char *temp = NULL; + uint64_t wm = 0; + uint64_t default_wm = 0; + struct volopt_map_entry *vmap = NULL; + xlator_t *this = NULL; + extern struct volopt_map_entry glusterd_volopt_map[]; + char msg[2048] = {0}; + + this = THIS; + GF_ASSERT (this); + + if (is_hi) + ret = glusterd_volinfo_get (volinfo, + "cluster.watermark-low", &temp); + else + ret = glusterd_volinfo_get (volinfo, + "cluster.watermark-hi", &temp); + if (ret) { + gf_msg (this->name, GF_LOG_ERROR, 0, + GD_MSG_VOLINFO_GET_FAIL, "failed to get watermark"); + goto out; + } + + gf_string2bytesize_uint64 (temp, &wm); + + if (is_hi) + for (vmap = glusterd_volopt_map; vmap->key; vmap++) { + if (strcmp (vmap->key, "cluster.watermark-hi") == 0) + default_value = vmap->value; + } + else + for (vmap = glusterd_volopt_map; vmap->key; vmap++) { + if (strcmp (vmap->key, "cluster.watermark-low") == 0) + default_value = vmap->value; + } + + gf_string2bytesize_uint64 (default_value, &default_wm); + + if (is_hi) { + if (default_wm <= wm) { + snprintf (msg, sizeof (msg), "Resetting hi-watermark " + "to default will make it lower or equal to " + "the low-watermark, which is an invalid " + "configuration state. Please lower the " + "low-watermark first to the desired value " + "and then reset the hi-watermark."); + ret = -1; + goto out; + } + } else { + if (default_wm >= wm) { + snprintf (msg, sizeof (msg), "Resetting low-watermark " + "to default will make it higher or equal to " + "the hi-watermark, which is an invalid " + "configuration state. Please raise the " + "hi-watermark first to the desired value " + "and then reset the low-watermark."); + ret = -1; + goto out; + } + } +out: + if (msg[0] != '\0') { + gf_msg (THIS->name, GF_LOG_ERROR, 0, + GD_MSG_TIER_WATERMARK_RESET_FAIL, "%s", msg); + *op_errstr = gf_strdup (msg); + } + return ret; +} static int glusterd_op_stage_reset_volume (dict_t *dict, char **op_errstr) @@ -1525,6 +1601,16 @@ glusterd_op_stage_reset_volume (dict_t *dict, char **op_errstr) if (exists == -1) { ret = -1; goto out; + } else if (strcmp (key, "cluster.watermark-low") == 0) { + ret = glusterd_water_limit_check (volinfo, _gf_false, + op_errstr); + if (ret) + return ret; + } else if (strcmp (key, "cluster.watermark-hi") == 0) { + ret = glusterd_water_limit_check (volinfo, _gf_true, + op_errstr); + if (ret) + return ret; } if (!exists) { |