21ab4e
From f330d80bf821fee47572d7d640a4a3aa41f4875c Mon Sep 17 00:00:00 2001
21ab4e
From: Jeff Darcy <jdarcy@redhat.com>
21ab4e
Date: Tue, 26 Jul 2016 08:49:36 -0400
21ab4e
Subject: [PATCH 367/369] io-stats: fix translator names
21ab4e
21ab4e
We use the first name of the xlator as brick name to
21ab4e
find the right graph from many multiplexed graphs.
21ab4e
21ab4e
And then we search any specific xlator on the graph
21ab4e
Backport of >
21ab4e
>Change-Id: Icf5afaee8b7c704aecab7f8a8a1df9f1bc9288ce
21ab4e
>BUG: 1360401
21ab4e
>Signed-off-by: Jeff Darcy <jdarcy@redhat.com>
21ab4e
>Reviewed-on: http://review.gluster.org/15016
21ab4e
>Smoke: Gluster Build System <jenkins@build.gluster.org>
21ab4e
>NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
21ab4e
>CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
21ab4e
>Reviewed-by: Vijay Bellur <vbellur@redhat.com>
21ab4e
21ab4e
Change-Id: I8ea78e497b9729a8cdbd90a26f7747365d976547
21ab4e
BUG: 1438378
21ab4e
Signed-off-by: Mohammed Rafi KC <rkavunga@redhat.com>
21ab4e
Reviewed-on: https://code.engineering.redhat.com/gerrit/102371
21ab4e
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
21ab4e
---
21ab4e
 glusterfsd/src/glusterfsd-mgmt.c            |  9 +++++++++
21ab4e
 xlators/debug/io-stats/src/io-stats.c       | 30 +++++++++++++++++++++++++----
21ab4e
 xlators/mgmt/glusterd/src/glusterd-volgen.c |  9 +++++++--
21ab4e
 3 files changed, 42 insertions(+), 6 deletions(-)
21ab4e
21ab4e
diff --git a/glusterfsd/src/glusterfsd-mgmt.c b/glusterfsd/src/glusterfsd-mgmt.c
21ab4e
index 9a7ed0d..36a658f 100644
21ab4e
--- a/glusterfsd/src/glusterfsd-mgmt.c
21ab4e
+++ b/glusterfsd/src/glusterfsd-mgmt.c
21ab4e
@@ -407,6 +407,15 @@ cont:
21ab4e
                 goto out;
21ab4e
         }
21ab4e
 
21ab4e
+        /*
21ab4e
+         * Searching by name will only get us to the decompounder translator,
21ab4e
+         * but we really want io-stats.  Since we know the exact relationship
21ab4e
+         * between these two, it's easy to get from one to the other.
21ab4e
+         *
21ab4e
+         * TBD: should this even be notify, or something else?
21ab4e
+         */
21ab4e
+        xlator = FIRST_CHILD(xlator);
21ab4e
+
21ab4e
         output = dict_new ();
21ab4e
         ret = xlator->notify (xlator, GF_EVENT_TRANSLATOR_INFO, dict, output);
21ab4e
 
21ab4e
diff --git a/xlators/debug/io-stats/src/io-stats.c b/xlators/debug/io-stats/src/io-stats.c
21ab4e
index c2375d9..5875616 100644
21ab4e
--- a/xlators/debug/io-stats/src/io-stats.c
21ab4e
+++ b/xlators/debug/io-stats/src/io-stats.c
21ab4e
@@ -147,6 +147,18 @@ struct ios_conf {
21ab4e
         ios_sample_buf_t          *ios_sample_buf;
21ab4e
         struct dnscache           *dnscache;
21ab4e
         int32_t                   ios_dnscache_ttl_sec;
21ab4e
+        /*
21ab4e
+         * What we really need here is just a unique value to keep files
21ab4e
+         * created by this instance distinct from those created by any other.
21ab4e
+         * On the client side this isn't a problem, so we just use the
21ab4e
+         * translator name.  On the server side conflicts can occur, so the
21ab4e
+         * volfile-generation code automatically sets this (via an option)
21ab4e
+         * to be the brick path.
21ab4e
+         *
21ab4e
+         * NB While the *field* name has changed, it didn't seem worth changing
21ab4e
+         * all of the cases where "xlator_name" is used as a *variable* name.
21ab4e
+         */
21ab4e
+        char                      *unique_id;
21ab4e
 };
21ab4e
 
21ab4e
 
21ab4e
@@ -716,8 +728,9 @@ _io_stats_get_key_prefix (xlator_t *this, char **key_prefix) {
21ab4e
         int                   bytes_written = 0;
21ab4e
         int                   i = 0;
21ab4e
         int                   ret = 0;
21ab4e
+        struct ios_conf       *conf = this->private;
21ab4e
 
21ab4e
-        xlator_name = strdupa (this->name);
21ab4e
+        xlator_name = strdupa (conf->unique_id);
21ab4e
         for (i = 0; i < strlen (xlator_name); i++) {
21ab4e
                 if (xlator_name[i] == '/')
21ab4e
                         xlator_name[i] = '_';
21ab4e
@@ -1070,7 +1083,7 @@ _io_stats_write_latency_sample (xlator_t *this, ios_sample_t *sample,
21ab4e
                         hostname = "Unknown";
21ab4e
         }
21ab4e
 
21ab4e
-        xlator_name = this->name;
21ab4e
+        xlator_name = conf->unique_id;
21ab4e
         if (!xlator_name || strlen (xlator_name) == 0)
21ab4e
                 xlator_name = "Unknown";
21ab4e
 
21ab4e
@@ -2959,7 +2972,7 @@ _ios_dump_thread (xlator_t *this) {
21ab4e
         conf = this->private;
21ab4e
         gf_log (this->name, GF_LOG_INFO, "IO stats dump thread started, "
21ab4e
                 "polling IO stats every %d seconds", conf->ios_dump_interval);
21ab4e
-        xlator_name = strdupa (this->name);
21ab4e
+        xlator_name = strdupa (conf->unique_id);
21ab4e
         for (i = 0; i < strlen (xlator_name); i++) {
21ab4e
                 if (xlator_name[i] == '/')
21ab4e
                         xlator_name[i] = '_';
21ab4e
@@ -3720,6 +3733,11 @@ init (xlator_t *this)
21ab4e
         if (!conf)
21ab4e
                 goto out;
21ab4e
 
21ab4e
+        if (dict_get_str (this->options, "unique-id", &conf->unique_id) != 0) {
21ab4e
+                /* This is always set on servers, so we must be a client. */
21ab4e
+                conf->unique_id = this->name;
21ab4e
+        }
21ab4e
+
21ab4e
         /*
21ab4e
          * Init it just after calloc, so that we are sure the lock is inited
21ab4e
          * in case of error paths.
21ab4e
@@ -3790,7 +3808,6 @@ init (xlator_t *this)
21ab4e
         GF_OPTION_INIT ("log-flush-timeout", log_flush_timeout, time, out);
21ab4e
         gf_log_set_log_flush_timeout (log_flush_timeout);
21ab4e
 
21ab4e
-
21ab4e
         this->private = conf;
21ab4e
         if (conf->ios_dump_interval > 0) {
21ab4e
                 pthread_create (&conf->dump_thread, NULL,
21ab4e
@@ -4184,6 +4201,11 @@ struct volume_options options[] = {
21ab4e
                          "log messages that can be buffered for a time equal to"
21ab4e
                          " the value of the option brick-log-flush-timeout."
21ab4e
         },
21ab4e
+        { .key = {"unique-id"},
21ab4e
+          .type = GF_OPTION_TYPE_STR,
21ab4e
+          .default_value = "/no/such/path",
21ab4e
+          .description = "Unique ID for our files."
21ab4e
+        },
21ab4e
         { .key  = {NULL} },
21ab4e
 
21ab4e
 };
21ab4e
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c
21ab4e
index d5ea166..c906306 100644
21ab4e
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.c
21ab4e
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c
21ab4e
@@ -1543,7 +1543,8 @@ brick_graph_add_decompounder (volgen_graph_t *graph, glusterd_volinfo_t *volinfo
21ab4e
         conf = this->private;
21ab4e
         GF_VALIDATE_OR_GOTO (this->name, conf, out);
21ab4e
 
21ab4e
-        xl = volgen_graph_add (graph, "performance/decompounder", volinfo->volname);
21ab4e
+        xl = volgen_graph_add_as (graph, "performance/decompounder",
21ab4e
+                                  brickinfo->path);
21ab4e
         if (xl)
21ab4e
                 ret = 0;
21ab4e
 out:
21ab4e
@@ -2057,10 +2058,14 @@ brick_graph_add_io_stats (volgen_graph_t *graph, glusterd_volinfo_t *volinfo,
21ab4e
         if (!graph || !volinfo || !set_dict || !brickinfo)
21ab4e
                 goto out;
21ab4e
 
21ab4e
-        xl = volgen_graph_add_as (graph, "debug/io-stats", brickinfo->path);
21ab4e
+        xl = volgen_graph_add (graph, "debug/io-stats", volinfo->volname);
21ab4e
         if (!xl)
21ab4e
                 goto out;
21ab4e
 
21ab4e
+        ret = xlator_set_option (xl, "unique-id", brickinfo->path);
21ab4e
+        if (ret)
21ab4e
+                goto out;
21ab4e
+
21ab4e
         ret = 0;
21ab4e
 out:
21ab4e
         return ret;
21ab4e
-- 
21ab4e
1.8.3.1
21ab4e