Blob Blame History Raw
From d93905382b198c3a8bb4b47302519e195d168b5d Mon Sep 17 00:00:00 2001
From: hari gowtham <hgowtham@redhat.com>
Date: Tue, 19 Apr 2016 14:01:09 +0530
Subject: [PATCH 368/369] TIER: watermark check during low watermark reset

	backport of : https://review.gluster.org/#/c/14028/8

PROBLEM: during a low watermark reset, checking of whether
the low watermark is lower than hi watermark is not done.

FIX: This patch checks if the hi watermark value is higher
the default low watermark. Else throws an failure of the reset
command

>Change-Id: I8b49090c6bccce6d45c2e8076ab766047a2a6162
>BUG: 1328342
>Signed-off-by: hari gowtham <hgowtham@redhat.com>
>Reviewed-on: https://review.gluster.org/14028
>Smoke: Gluster Build System <jenkins@build.gluster.org>
>Tested-by: hari gowtham <hari.gowtham005@gmail.com>
>NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
>CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
>Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
>Signed-off-by: hari gowtham <hgowtham@redhat.com>

Change-Id: If6d0688653d6681e1a6da42988dd74aea6f5df16
BUG: 1315583
Signed-off-by: hari gowtham <hgowtham@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/102301
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
---
 tests/basic/tier/tier.t                       |  6 ++
 xlators/mgmt/glusterd/src/glusterd-messages.h | 10 +++-
 xlators/mgmt/glusterd/src/glusterd-op-sm.c    | 86 +++++++++++++++++++++++++++
 3 files changed, 101 insertions(+), 1 deletion(-)

diff --git a/tests/basic/tier/tier.t b/tests/basic/tier/tier.t
index 7bac2dd..75b834d 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 6e7e27d..4728810 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 */
@@ -4781,6 +4781,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 dae6c1e..c78a7a4 100644
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
@@ -1442,6 +1442,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)
@@ -1518,6 +1594,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) {
-- 
1.8.3.1