summaryrefslogtreecommitdiff
path: root/sql/wsrep_var.cc
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2014-09-28 12:41:51 +0200
committerSergei Golubchik <serg@mariadb.org>2014-10-01 23:48:35 +0200
commiteaec266eb16c8f02835f76ac987fca5de4debd51 (patch)
tree9cca42f62ebe463f1ac8600f2b6cfde5356d2056 /sql/wsrep_var.cc
parent13af416a82796648dffdffbda0da6d60513d7ddf (diff)
downloadmariadb-git-eaec266eb16c8f02835f76ac987fca5de4debd51.tar.gz
restore and fix wsrep status variables
Diffstat (limited to 'sql/wsrep_var.cc')
-rw-r--r--sql/wsrep_var.cc132
1 files changed, 49 insertions, 83 deletions
diff --git a/sql/wsrep_var.cc b/sql/wsrep_var.cc
index 3f4b163281b..c6e9b89ca55 100644
--- a/sql/wsrep_var.cc
+++ b/sql/wsrep_var.cc
@@ -15,9 +15,9 @@
#include "wsrep_var.h"
+#include <sql_plugin.h>
#include <mysqld.h>
#include <sql_class.h>
-#include <sql_plugin.h>
#include <set_var.h>
#include <sql_acl.h>
#include "wsrep_priv.h"
@@ -507,99 +507,65 @@ bool wsrep_desync_update (sys_var *self, THD* thd, enum_var_type type)
return false;
}
-/*
- * Status variables stuff below
- */
-static inline void
-wsrep_assign_to_mysql (SHOW_VAR* mysql, wsrep_stats_var* wsrep)
-{
- mysql->name = wsrep->name;
- switch (wsrep->type) {
- case WSREP_VAR_INT64:
- mysql->value = (char*) &wsrep->value._int64;
- mysql->type = SHOW_LONGLONG;
- break;
- case WSREP_VAR_STRING:
- mysql->value = (char*) &wsrep->value._string;
- mysql->type = SHOW_CHAR_PTR;
- break;
- case WSREP_VAR_DOUBLE:
- mysql->value = (char*) &wsrep->value._double;
- mysql->type = SHOW_DOUBLE;
- break;
- }
-}
-
-#if DYNAMIC
-// somehow this mysql status thing works only with statically allocated arrays.
-static SHOW_VAR* mysql_status_vars = NULL;
-static int mysql_status_len = -1;
-#else
-static SHOW_VAR mysql_status_vars[512 + 1];
-static const int mysql_status_len = 512;
-#endif
+static SHOW_VAR wsrep_status_vars[]=
+{
+ {"connected", (char*) &wsrep_connected, SHOW_BOOL},
+ {"ready", (char*) &wsrep_ready, SHOW_BOOL},
+ {"cluster_state_uuid",(char*) &wsrep_cluster_state_uuid,SHOW_CHAR_PTR},
+ {"cluster_conf_id", (char*) &wsrep_cluster_conf_id, SHOW_LONGLONG},
+ {"cluster_status", (char*) &wsrep_cluster_status, SHOW_CHAR_PTR},
+ {"cluster_size", (char*) &wsrep_cluster_size, SHOW_LONG_NOFLUSH},
+ {"local_index", (char*) &wsrep_local_index, SHOW_LONG_NOFLUSH},
+ {"local_bf_aborts", (char*) &wsrep_show_bf_aborts, SHOW_SIMPLE_FUNC},
+ {"provider_name", (char*) &wsrep_provider_name, SHOW_CHAR_PTR},
+ {"provider_version", (char*) &wsrep_provider_version, SHOW_CHAR_PTR},
+ {"provider_vendor", (char*) &wsrep_provider_vendor, SHOW_CHAR_PTR},
+ {"thread_count", (char*) &wsrep_running_threads, SHOW_LONG_NOFLUSH}
+};
-static void export_wsrep_status_to_mysql(THD* thd)
+static int show_var_cmp(const void *var1, const void *var2)
{
- int wsrep_status_len, i;
+ return strcasecmp(((SHOW_VAR*)var1)->name, ((SHOW_VAR*)var2)->name);
+}
- thd->wsrep_status_vars = wsrep->stats_get(wsrep);
+int wsrep_show_status (THD *thd, SHOW_VAR *var, char *buff)
+{
+ uint i, maxi= SHOW_VAR_FUNC_BUFF_SIZE / sizeof(*var) - 1;
+ SHOW_VAR *v= (SHOW_VAR *)buff;
- if (!thd->wsrep_status_vars) {
- return;
- }
+ var->type= SHOW_ARRAY;
+ var->value= buff;
- for (wsrep_status_len = 0;
- thd->wsrep_status_vars[wsrep_status_len].name != NULL;
- wsrep_status_len++);
+ for (i=0; i < array_elements(wsrep_status_vars); i++)
+ *v++= wsrep_status_vars[i];
-#if DYNAMIC
- if (wsrep_status_len != mysql_status_len) {
- void* tmp = realloc (mysql_status_vars,
- (wsrep_status_len + 1) * sizeof(SHOW_VAR));
- if (!tmp) {
+ DBUG_ASSERT(i < maxi);
- sql_print_error ("Out of memory for wsrep status variables."
- "Number of variables: %d", wsrep_status_len);
- return;
+ wsrep_stats_var* stats= wsrep->stats_get(wsrep);
+ for (wsrep_stats_var *sv= stats; i < maxi && sv && sv->name; i++, sv++, v++)
+ {
+ v->name = thd->strdup(sv->name);
+ switch (sv->type) {
+ case WSREP_VAR_INT64:
+ v->value = (char*)thd->memdup(&sv->value._int64, sizeof(longlong));
+ v->type = SHOW_LONGLONG;
+ break;
+ case WSREP_VAR_STRING:
+ v->value = thd->strdup(sv->value._string);
+ v->type = SHOW_CHAR;
+ break;
+ case WSREP_VAR_DOUBLE:
+ v->value = (char*)thd->memdup(&sv->value._double, sizeof(double));
+ v->type = SHOW_DOUBLE;
+ break;
}
-
- mysql_status_len = wsrep_status_len;
- mysql_status_vars = (SHOW_VAR*)tmp;
+ DBUG_ASSERT(i < maxi);
}
- /* @TODO: fix this: */
-#else
- if (mysql_status_len < wsrep_status_len) wsrep_status_len= mysql_status_len;
-#endif
+ wsrep->stats_free(wsrep, stats);
- for (i = 0; i < wsrep_status_len; i++)
- wsrep_assign_to_mysql (mysql_status_vars + i, thd->wsrep_status_vars + i);
+ my_qsort(buff, i, sizeof(*v), show_var_cmp);
- mysql_status_vars[wsrep_status_len].name = NullS;
- mysql_status_vars[wsrep_status_len].value = NullS;
- mysql_status_vars[wsrep_status_len].type = SHOW_LONG;
-}
-
-int wsrep_show_status (THD *thd, SHOW_VAR *var, char *buff)
-{
- export_wsrep_status_to_mysql(thd);
- var->type= SHOW_ARRAY;
- var->value= (char *) &mysql_status_vars;
-#if 0
- {"wsrep_connected", (char*) &wsrep_connected, SHOW_BOOL},
- {"wsrep_ready", (char*) &wsrep_ready, SHOW_BOOL},
- {"wsrep_cluster_state_uuid", (char*) &wsrep_cluster_state_uuid,SHOW_CHAR_PTR},
- {"wsrep_cluster_conf_id", (char*) &wsrep_cluster_conf_id, SHOW_LONGLONG},
- {"wsrep_cluster_status", (char*) &wsrep_cluster_status, SHOW_CHAR_PTR},
- {"wsrep_cluster_size", (char*) &wsrep_cluster_size, SHOW_LONG_NOFLUSH},
- {"wsrep_local_index", (char*) &wsrep_local_index, SHOW_LONG_NOFLUSH},
- {"wsrep_local_bf_aborts", (char*) &wsrep_show_bf_aborts, SHOW_SIMPLE_FUNC},
- {"wsrep_provider_name", (char*) &wsrep_provider_name, SHOW_CHAR_PTR},
- {"wsrep_provider_version", (char*) &wsrep_provider_version, SHOW_CHAR_PTR},
- {"wsrep_provider_vendor", (char*) &wsrep_provider_vendor, SHOW_CHAR_PTR},
- {"wsrep_thread_count", (char*) &wsrep_running_threads, SHOW_LONG_NOFLUSH},
- {"wsrep", (char*) &wsrep_show_status, SHOW_FUNC},
-#endif
+ v->name= 0; // terminator
return 0;
}