Merge branch 'Z2' of https://github.com/skysql/MaxScale into Z2
Conflicts: server/core/modutil.c
This commit is contained in:
Binary file not shown.
Binary file not shown.
BIN
Documentation/MySQLClustersetup.pdf
Normal file
BIN
Documentation/MySQLClustersetup.pdf
Normal file
Binary file not shown.
@ -18,10 +18,15 @@ Group: Development/Tools
|
|||||||
%if 0%{?suse_version}
|
%if 0%{?suse_version}
|
||||||
BuildRequires: gcc gcc-c++ ncurses-devel bison glibc-devel cmake libgcc_s1 perl make libtool libopenssl-devel libaio libaio-devel mariadb libedit-devel
|
BuildRequires: gcc gcc-c++ ncurses-devel bison glibc-devel cmake libgcc_s1 perl make libtool libopenssl-devel libaio libaio-devel mariadb libedit-devel
|
||||||
%else
|
%else
|
||||||
BuildRequires: gcc gcc-c++ ncurses-devel bison glibc-devel cmake libgcc perl make libtool openssl-devel libaio libaio-devel MariaDB-devel MariaDB-server
|
BuildRequires: gcc gcc-c++ ncurses-devel bison glibc-devel cmake libgcc perl make libtool openssl-devel libaio libaio-devel
|
||||||
%if 0%{?rhel} == 6
|
%if 0%{?rhel} == 6
|
||||||
BuildRequires: libedit-devel
|
BuildRequires: libedit-devel
|
||||||
%endif
|
%endif
|
||||||
|
%if 0%{?rhel} == 7
|
||||||
|
BuildRequires: mariadb-devel mariadb-embedded-devel libedit-devel
|
||||||
|
%else
|
||||||
|
BuildRequires: MariaDB-devel MariaDB-server
|
||||||
|
%endif
|
||||||
%endif
|
%endif
|
||||||
|
|
||||||
%description
|
%description
|
||||||
|
|||||||
@ -61,7 +61,7 @@ servers=server1,server2,server3
|
|||||||
user=maxuser
|
user=maxuser
|
||||||
passwd=maxpwd
|
passwd=maxpwd
|
||||||
max_slave_connections=50%
|
max_slave_connections=50%
|
||||||
max_slave_replication_lag=10
|
max_slave_replication_lag=30
|
||||||
router_options=slave_selection_criteria=LEAST_BEHIND_MASTER
|
router_options=slave_selection_criteria=LEAST_BEHIND_MASTER
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -417,6 +417,8 @@ char *status = NULL;
|
|||||||
strcat(status, "Slave, ");
|
strcat(status, "Slave, ");
|
||||||
if (server->status & SERVER_JOINED)
|
if (server->status & SERVER_JOINED)
|
||||||
strcat(status, "Synced, ");
|
strcat(status, "Synced, ");
|
||||||
|
if (server->status & SERVER_NDB)
|
||||||
|
strcat(status, "NDB, ");
|
||||||
if (server->status & SERVER_RUNNING)
|
if (server->status & SERVER_RUNNING)
|
||||||
strcat(status, "Running");
|
strcat(status, "Running");
|
||||||
else
|
else
|
||||||
|
|||||||
@ -38,6 +38,7 @@
|
|||||||
* 03/06/14 Mark Riddoch Addition of maintainance mode
|
* 03/06/14 Mark Riddoch Addition of maintainance mode
|
||||||
* 20/06/14 Massimiliano Pinto Addition of master_id, depth, slaves fields
|
* 20/06/14 Massimiliano Pinto Addition of master_id, depth, slaves fields
|
||||||
* 26/06/14 Mark Riddoch Adidtion of server parameters
|
* 26/06/14 Mark Riddoch Adidtion of server parameters
|
||||||
|
* 30/07/14 Massimiliano Pinto Addition of NDB status for MySQL Cluster
|
||||||
*
|
*
|
||||||
* @endverbatim
|
* @endverbatim
|
||||||
*/
|
*/
|
||||||
@ -99,8 +100,9 @@ typedef struct server {
|
|||||||
#define SERVER_MASTER 0x0002 /**<< The server is a master, i.e. can handle writes */
|
#define SERVER_MASTER 0x0002 /**<< The server is a master, i.e. can handle writes */
|
||||||
#define SERVER_SLAVE 0x0004 /**<< The server is a slave, i.e. can handle reads */
|
#define SERVER_SLAVE 0x0004 /**<< The server is a slave, i.e. can handle reads */
|
||||||
#define SERVER_JOINED 0x0008 /**<< The server is joined in a Galera cluster */
|
#define SERVER_JOINED 0x0008 /**<< The server is joined in a Galera cluster */
|
||||||
|
#define SERVER_NDB 0x0010 /**<< The server is part of a MySQL cluster setup */
|
||||||
#define SERVER_MAINT 0x1000 /**<< Server is in maintenance mode */
|
#define SERVER_MAINT 0x1000 /**<< Server is in maintenance mode */
|
||||||
#define SERVER_SLAVE_OF_EXTERNAL_MASTER 0x0016 /**<< Server is slave of a Master outside the provided replication topology */
|
#define SERVER_SLAVE_OF_EXTERNAL_MASTER 0x0080 /**<< Server is slave of a Master outside the provided replication topology */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is the server running - the macro returns true if the server is marked as running
|
* Is the server running - the macro returns true if the server is marked as running
|
||||||
@ -131,15 +133,21 @@ typedef struct server {
|
|||||||
#define SERVER_IS_JOINED(server) \
|
#define SERVER_IS_JOINED(server) \
|
||||||
(((server)->status & (SERVER_RUNNING|SERVER_JOINED|SERVER_MAINT)) == (SERVER_RUNNING|SERVER_JOINED))
|
(((server)->status & (SERVER_RUNNING|SERVER_JOINED|SERVER_MAINT)) == (SERVER_RUNNING|SERVER_JOINED))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is the server a SQL node in MySQL Cluster? The server must be running and with NDB status
|
||||||
|
*/
|
||||||
|
#define SERVER_IS_NDB(server) \
|
||||||
|
(((server)->status & (SERVER_RUNNING|SERVER_NDB|SERVER_MAINT)) == (SERVER_RUNNING|SERVER_NDB))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is the server in maintenance mode.
|
* Is the server in maintenance mode.
|
||||||
*/
|
*/
|
||||||
#define SERVER_IN_MAINT(server) ((server)->status & SERVER_MAINT)
|
#define SERVER_IN_MAINT(server) ((server)->status & SERVER_MAINT)
|
||||||
|
|
||||||
/** server is not master, slave or joined */
|
/** server is not master, slave or joined */
|
||||||
#define SERVER_NOT_IN_CLUSTER(s) (((s)->status & (SERVER_MASTER|SERVER_SLAVE|SERVER_JOINED)) == 0)
|
#define SERVER_NOT_IN_CLUSTER(s) (((s)->status & (SERVER_MASTER|SERVER_SLAVE|SERVER_JOINED|SERVER_NDB)) == 0)
|
||||||
|
|
||||||
#define SERVER_IS_IN_CLUSTER(s) (((s)->status & (SERVER_MASTER|SERVER_SLAVE|SERVER_JOINED)) != 0)
|
#define SERVER_IS_IN_CLUSTER(s) (((s)->status & (SERVER_MASTER|SERVER_SLAVE|SERVER_JOINED|SERVER_NDB)) != 0)
|
||||||
|
|
||||||
#define SERVER_IS_RELAY_SERVER(server) \
|
#define SERVER_IS_RELAY_SERVER(server) \
|
||||||
(((server)->status & (SERVER_RUNNING|SERVER_MASTER|SERVER_SLAVE|SERVER_MAINT)) == (SERVER_RUNNING|SERVER_MASTER|SERVER_SLAVE))
|
(((server)->status & (SERVER_RUNNING|SERVER_MASTER|SERVER_SLAVE|SERVER_MAINT)) == (SERVER_RUNNING|SERVER_MASTER|SERVER_SLAVE))
|
||||||
|
|||||||
@ -17,6 +17,7 @@
|
|||||||
# Revision History
|
# Revision History
|
||||||
# Date Who Description
|
# Date Who Description
|
||||||
# 08/07/13 Mark Riddoch Initial implementation
|
# 08/07/13 Mark Riddoch Initial implementation
|
||||||
|
# 28/07/14 Massimiliano Pinto new monitor ndbcluster added
|
||||||
|
|
||||||
include ../../../build_gateway.inc
|
include ../../../build_gateway.inc
|
||||||
LOGPATH := $(ROOT_PATH)/log_manager
|
LOGPATH := $(ROOT_PATH)/log_manager
|
||||||
@ -36,11 +37,13 @@ MYSQLSRCS=mysql_mon.c
|
|||||||
MYSQLOBJ=$(MYSQLSRCS:.c=.o)
|
MYSQLOBJ=$(MYSQLSRCS:.c=.o)
|
||||||
GALERASRCS=galera_mon.c
|
GALERASRCS=galera_mon.c
|
||||||
GALERAOBJ=$(GALERASRCS:.c=.o)
|
GALERAOBJ=$(GALERASRCS:.c=.o)
|
||||||
SRCS=$(MYSQLSRCS)
|
NDBCLUSTERSRCS=ndbcluster_mon.c
|
||||||
|
NDBCLUSTEROBJ=$(NDBCLUSTERSRCS:.c=.o)
|
||||||
|
SRCS=$(MYSQLSRCS) $(GALERASRCS) $(NDBCLUSTERSRCS)
|
||||||
OBJ=$(SRCS:.c=.o)
|
OBJ=$(SRCS:.c=.o)
|
||||||
LIBS=$(UTILSPATH)/skygw_utils.o -llog_manager \
|
LIBS=$(UTILSPATH)/skygw_utils.o -llog_manager \
|
||||||
-L$(EMBEDDED_LIB) -lmysqld
|
-L$(EMBEDDED_LIB) -lmysqld
|
||||||
MODULES=libmysqlmon.so libgaleramon.so
|
MODULES=libmysqlmon.so libgaleramon.so libndbclustermon.so
|
||||||
|
|
||||||
|
|
||||||
all: $(MODULES)
|
all: $(MODULES)
|
||||||
@ -51,6 +54,9 @@ libmysqlmon.so: $(MYSQLOBJ)
|
|||||||
libgaleramon.so: $(GALERAOBJ)
|
libgaleramon.so: $(GALERAOBJ)
|
||||||
$(CC) $(LDFLAGS) $(GALERAOBJ) $(LIBS) -o $@
|
$(CC) $(LDFLAGS) $(GALERAOBJ) $(LIBS) -o $@
|
||||||
|
|
||||||
|
libndbclustermon.so: $(NDBCLUSTEROBJ)
|
||||||
|
$(CC) $(LDFLAGS) $(NDBCLUSTEROBJ) $(LIBS) -o $@
|
||||||
|
|
||||||
.c.o:
|
.c.o:
|
||||||
$(CC) $(CFLAGS) $< -o $@
|
$(CC) $(CFLAGS) $< -o $@
|
||||||
|
|
||||||
|
|||||||
461
server/modules/monitor/ndbcluster_mon.c
Normal file
461
server/modules/monitor/ndbcluster_mon.c
Normal file
@ -0,0 +1,461 @@
|
|||||||
|
/*
|
||||||
|
* This file is distributed as part of the SkySQL Gateway. It is free
|
||||||
|
* software: you can redistribute it and/or modify it under the terms of the
|
||||||
|
* GNU General Public License as published by the Free Software Foundation,
|
||||||
|
* version 2.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
* details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with
|
||||||
|
* this program; if not, write to the Free Software Foundation, Inc., 51
|
||||||
|
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Copyright SkySQL Ab 2013
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file ndbcluster_mon.c - A MySQL cluster SQL node monitor
|
||||||
|
*
|
||||||
|
* @verbatim
|
||||||
|
* Revision History
|
||||||
|
*
|
||||||
|
* Date Who Description
|
||||||
|
* 25/07/14 Massimiliano Pinto Initial implementation
|
||||||
|
*
|
||||||
|
* @endverbatim
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <monitor.h>
|
||||||
|
#include <mysqlmon.h>
|
||||||
|
#include <thread.h>
|
||||||
|
#include <mysql.h>
|
||||||
|
#include <mysqld_error.h>
|
||||||
|
#include <skygw_utils.h>
|
||||||
|
#include <log_manager.h>
|
||||||
|
#include <secrets.h>
|
||||||
|
#include <dcb.h>
|
||||||
|
#include <modinfo.h>
|
||||||
|
|
||||||
|
extern int lm_enabled_logfiles_bitmask;
|
||||||
|
|
||||||
|
static void monitorMain(void *);
|
||||||
|
|
||||||
|
static char *version_str = "V1.0.0";
|
||||||
|
|
||||||
|
MODULE_INFO info = {
|
||||||
|
MODULE_API_MONITOR,
|
||||||
|
MODULE_BETA_RELEASE,
|
||||||
|
MONITOR_VERSION,
|
||||||
|
"A MySQL cluster SQL node monitor"
|
||||||
|
};
|
||||||
|
|
||||||
|
static void *startMonitor(void *);
|
||||||
|
static void stopMonitor(void *);
|
||||||
|
static void registerServer(void *, SERVER *);
|
||||||
|
static void unregisterServer(void *, SERVER *);
|
||||||
|
static void defaultUsers(void *, char *, char *);
|
||||||
|
static void diagnostics(DCB *, void *);
|
||||||
|
static void setInterval(void *, unsigned long);
|
||||||
|
|
||||||
|
static MONITOR_OBJECT MyObject = { startMonitor, stopMonitor, registerServer, unregisterServer, defaultUsers, diagnostics, setInterval, NULL, NULL };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of the mandatory version entry point
|
||||||
|
*
|
||||||
|
* @return version string of the module
|
||||||
|
*/
|
||||||
|
char *
|
||||||
|
version()
|
||||||
|
{
|
||||||
|
return version_str;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The module initialisation routine, called when the module
|
||||||
|
* is first loaded.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
ModuleInit()
|
||||||
|
{
|
||||||
|
LOGIF(LM, (skygw_log_write(
|
||||||
|
LOGFILE_MESSAGE,
|
||||||
|
"Initialise the MySQL Cluster Monitor module %s.\n",
|
||||||
|
version_str)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The module entry point routine. It is this routine that
|
||||||
|
* must populate the structure that is referred to as the
|
||||||
|
* "module object", this is a structure with the set of
|
||||||
|
* external entry points for this module.
|
||||||
|
*
|
||||||
|
* @return The module object
|
||||||
|
*/
|
||||||
|
MONITOR_OBJECT *
|
||||||
|
GetModuleObject()
|
||||||
|
{
|
||||||
|
return &MyObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start the instance of the monitor, returning a handle on the monitor.
|
||||||
|
*
|
||||||
|
* This function creates a thread to execute the actual monitoring.
|
||||||
|
*
|
||||||
|
* @return A handle to use when interacting with the monitor
|
||||||
|
*/
|
||||||
|
static void *
|
||||||
|
startMonitor(void *arg)
|
||||||
|
{
|
||||||
|
MYSQL_MONITOR *handle;
|
||||||
|
|
||||||
|
if (arg != NULL)
|
||||||
|
{
|
||||||
|
handle = (MYSQL_MONITOR *)arg;
|
||||||
|
handle->shutdown = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ((handle = (MYSQL_MONITOR *)malloc(sizeof(MYSQL_MONITOR))) == NULL)
|
||||||
|
return NULL;
|
||||||
|
handle->databases = NULL;
|
||||||
|
handle->shutdown = 0;
|
||||||
|
handle->defaultUser = NULL;
|
||||||
|
handle->defaultPasswd = NULL;
|
||||||
|
handle->id = MONITOR_DEFAULT_ID;
|
||||||
|
handle->interval = MONITOR_INTERVAL;
|
||||||
|
spinlock_init(&handle->lock);
|
||||||
|
}
|
||||||
|
handle->tid = (THREAD)thread_start(monitorMain, handle);
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop a running monitor
|
||||||
|
*
|
||||||
|
* @param arg Handle on thr running monior
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
stopMonitor(void *arg)
|
||||||
|
{
|
||||||
|
MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg;
|
||||||
|
|
||||||
|
handle->shutdown = 1;
|
||||||
|
thread_wait((void *)handle->tid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a server that must be added to the monitored servers for
|
||||||
|
* a monitoring module.
|
||||||
|
*
|
||||||
|
* @param arg A handle on the running monitor module
|
||||||
|
* @param server The server to add
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
registerServer(void *arg, SERVER *server)
|
||||||
|
{
|
||||||
|
MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg;
|
||||||
|
MONITOR_SERVERS *ptr, *db;
|
||||||
|
|
||||||
|
if ((db = (MONITOR_SERVERS *)malloc(sizeof(MONITOR_SERVERS))) == NULL)
|
||||||
|
return;
|
||||||
|
db->server = server;
|
||||||
|
db->con = NULL;
|
||||||
|
db->next = NULL;
|
||||||
|
spinlock_acquire(&handle->lock);
|
||||||
|
if (handle->databases == NULL)
|
||||||
|
handle->databases = db;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ptr = handle->databases;
|
||||||
|
while (ptr->next != NULL)
|
||||||
|
ptr = ptr->next;
|
||||||
|
ptr->next = db;
|
||||||
|
}
|
||||||
|
spinlock_release(&handle->lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a server from those being monitored by a monitoring module
|
||||||
|
*
|
||||||
|
* @param arg A handle on the running monitor module
|
||||||
|
* @param server The server to remove
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
unregisterServer(void *arg, SERVER *server)
|
||||||
|
{
|
||||||
|
MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg;
|
||||||
|
MONITOR_SERVERS *ptr, *lptr;
|
||||||
|
|
||||||
|
spinlock_acquire(&handle->lock);
|
||||||
|
if (handle->databases == NULL)
|
||||||
|
{
|
||||||
|
spinlock_release(&handle->lock);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (handle->databases->server == server)
|
||||||
|
{
|
||||||
|
ptr = handle->databases;
|
||||||
|
handle->databases = handle->databases->next;
|
||||||
|
free(ptr);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ptr = handle->databases;
|
||||||
|
while (ptr->next != NULL && ptr->next->server != server)
|
||||||
|
ptr = ptr->next;
|
||||||
|
if (ptr->next)
|
||||||
|
{
|
||||||
|
lptr = ptr->next;
|
||||||
|
ptr->next = ptr->next->next;
|
||||||
|
free(lptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
spinlock_release(&handle->lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Diagnostic interface
|
||||||
|
*
|
||||||
|
* @param dcb DCB to send output
|
||||||
|
* @param arg The monitor handle
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
diagnostics(DCB *dcb, void *arg)
|
||||||
|
{
|
||||||
|
MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg;
|
||||||
|
MONITOR_SERVERS *db;
|
||||||
|
char *sep;
|
||||||
|
|
||||||
|
switch (handle->status)
|
||||||
|
{
|
||||||
|
case MONITOR_RUNNING:
|
||||||
|
dcb_printf(dcb, "\tMonitor running\n");
|
||||||
|
break;
|
||||||
|
case MONITOR_STOPPING:
|
||||||
|
dcb_printf(dcb, "\tMonitor stopping\n");
|
||||||
|
break;
|
||||||
|
case MONITOR_STOPPED:
|
||||||
|
dcb_printf(dcb, "\tMonitor stopped\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
dcb_printf(dcb,"\tSampling interval:\t%lu milliseconds\n", handle->interval);
|
||||||
|
dcb_printf(dcb, "\tMonitored servers: ");
|
||||||
|
|
||||||
|
db = handle->databases;
|
||||||
|
sep = "";
|
||||||
|
while (db)
|
||||||
|
{
|
||||||
|
dcb_printf(dcb, "%s%s:%d", sep, db->server->name, db->server->port);
|
||||||
|
sep = ", ";
|
||||||
|
db = db->next;
|
||||||
|
}
|
||||||
|
dcb_printf(dcb, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the default username and password to use to monitor if the server does not
|
||||||
|
* override this.
|
||||||
|
*
|
||||||
|
* @param arg The handle allocated by startMonitor
|
||||||
|
* @param uname The default user name
|
||||||
|
* @param passwd The default password
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
defaultUsers(void *arg, char *uname, char *passwd)
|
||||||
|
{
|
||||||
|
MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg;
|
||||||
|
|
||||||
|
if (handle->defaultUser)
|
||||||
|
free(handle->defaultUser);
|
||||||
|
if (handle->defaultPasswd)
|
||||||
|
free(handle->defaultPasswd);
|
||||||
|
handle->defaultUser = strdup(uname);
|
||||||
|
handle->defaultPasswd = strdup(passwd);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Monitor an individual server
|
||||||
|
*
|
||||||
|
* @param database The database to probe
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
monitorDatabase(MONITOR_SERVERS *database, char *defaultUser, char *defaultPasswd)
|
||||||
|
{
|
||||||
|
MYSQL_ROW row;
|
||||||
|
MYSQL_RES *result;
|
||||||
|
int num_fields;
|
||||||
|
int isjoined = 0;
|
||||||
|
char *uname = defaultUser, *passwd = defaultPasswd;
|
||||||
|
unsigned long int server_version = 0;
|
||||||
|
char *server_string;
|
||||||
|
|
||||||
|
if (database->server->monuser != NULL)
|
||||||
|
{
|
||||||
|
uname = database->server->monuser;
|
||||||
|
passwd = database->server->monpw;
|
||||||
|
}
|
||||||
|
if (uname == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* Don't even probe server flagged as in maintenance */
|
||||||
|
if (SERVER_IN_MAINT(database->server))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (database->con == NULL || mysql_ping(database->con) != 0)
|
||||||
|
{
|
||||||
|
char *dpwd = decryptPassword(passwd);
|
||||||
|
int rc;
|
||||||
|
int read_timeout = 1;
|
||||||
|
|
||||||
|
database->con = mysql_init(NULL);
|
||||||
|
rc = mysql_options(database->con, MYSQL_OPT_READ_TIMEOUT, (void *)&read_timeout);
|
||||||
|
|
||||||
|
if (mysql_real_connect(database->con, database->server->name,
|
||||||
|
uname, dpwd, NULL, database->server->port, NULL, 0) == NULL)
|
||||||
|
{
|
||||||
|
LOGIF(LE, (skygw_log_write_flush(
|
||||||
|
LOGFILE_ERROR,
|
||||||
|
"Error : Monitor was unable to connect to "
|
||||||
|
"server %s:%d : \"%s\"",
|
||||||
|
database->server->name,
|
||||||
|
database->server->port,
|
||||||
|
mysql_error(database->con))));
|
||||||
|
server_clear_status(database->server, SERVER_RUNNING);
|
||||||
|
database->server->node_id = -1;
|
||||||
|
free(dpwd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
free(dpwd);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If we get this far then we have a working connection */
|
||||||
|
server_set_status(database->server, SERVER_RUNNING);
|
||||||
|
|
||||||
|
/* get server version from current server */
|
||||||
|
server_version = mysql_get_server_version(database->con);
|
||||||
|
|
||||||
|
/* get server version string */
|
||||||
|
server_string = (char *)mysql_get_server_info(database->con);
|
||||||
|
if (server_string) {
|
||||||
|
database->server->server_string = strdup(server_string);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check if the the SQL node is able to contact one or more data nodes */
|
||||||
|
if (mysql_query(database->con, "SHOW STATUS LIKE 'Ndb_number_of_ready_data_nodes'") == 0
|
||||||
|
&& (result = mysql_store_result(database->con)) != NULL)
|
||||||
|
{
|
||||||
|
num_fields = mysql_num_fields(result);
|
||||||
|
while ((row = mysql_fetch_row(result)))
|
||||||
|
{
|
||||||
|
if (atoi(row[1]) > 0)
|
||||||
|
isjoined = 1;
|
||||||
|
}
|
||||||
|
mysql_free_result(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check the the SQL node id in the MySQL cluster */
|
||||||
|
if (mysql_query(database->con, "SHOW STATUS LIKE 'Ndb_cluster_node_id'") == 0
|
||||||
|
&& (result = mysql_store_result(database->con)) != NULL)
|
||||||
|
{
|
||||||
|
long cluster_node_id = -1;
|
||||||
|
num_fields = mysql_num_fields(result);
|
||||||
|
while ((row = mysql_fetch_row(result)))
|
||||||
|
{
|
||||||
|
cluster_node_id = strtol(row[1], NULL, 10);
|
||||||
|
if ((errno == ERANGE && (cluster_node_id == LONG_MAX
|
||||||
|
|| cluster_node_id == LONG_MIN)) || (errno != 0 && cluster_node_id == 0))
|
||||||
|
{
|
||||||
|
cluster_node_id = -1;
|
||||||
|
}
|
||||||
|
database->server->node_id = cluster_node_id;
|
||||||
|
}
|
||||||
|
mysql_free_result(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isjoined) {
|
||||||
|
server_set_status(database->server, SERVER_NDB);
|
||||||
|
database->server->depth = 0;
|
||||||
|
} else {
|
||||||
|
server_clear_status(database->server, SERVER_NDB);
|
||||||
|
database->server->depth = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The entry point for the monitoring module thread
|
||||||
|
*
|
||||||
|
* @param arg The handle of the monitor
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
monitorMain(void *arg)
|
||||||
|
{
|
||||||
|
MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg;
|
||||||
|
MONITOR_SERVERS *ptr;
|
||||||
|
long master_id;
|
||||||
|
|
||||||
|
if (mysql_thread_init())
|
||||||
|
{
|
||||||
|
LOGIF(LE, (skygw_log_write_flush(
|
||||||
|
LOGFILE_ERROR,
|
||||||
|
"Fatal : mysql_thread_init failed in monitor "
|
||||||
|
"module. Exiting.\n")));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
handle->status = MONITOR_RUNNING;
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
master_id = -1;
|
||||||
|
|
||||||
|
if (handle->shutdown)
|
||||||
|
{
|
||||||
|
handle->status = MONITOR_STOPPING;
|
||||||
|
mysql_thread_end();
|
||||||
|
handle->status = MONITOR_STOPPED;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ptr = handle->databases;
|
||||||
|
|
||||||
|
while (ptr)
|
||||||
|
{
|
||||||
|
unsigned int prev_status = ptr->server->status;
|
||||||
|
monitorDatabase(ptr, handle->defaultUser, handle->defaultPasswd);
|
||||||
|
|
||||||
|
if (ptr->server->status != prev_status ||
|
||||||
|
SERVER_IS_DOWN(ptr->server))
|
||||||
|
{
|
||||||
|
LOGIF(LM, (skygw_log_write_flush(
|
||||||
|
LOGFILE_MESSAGE,
|
||||||
|
"Backend server %s:%d state : %s",
|
||||||
|
ptr->server->name,
|
||||||
|
ptr->server->port,
|
||||||
|
STRSRVSTATUS(ptr->server))));
|
||||||
|
}
|
||||||
|
|
||||||
|
ptr = ptr->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
thread_millisleep(handle->interval);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the monitor sampling interval.
|
||||||
|
*
|
||||||
|
* @param arg The handle allocated by startMonitor
|
||||||
|
* @param interval The interval to set in monitor struct, in milliseconds
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
setInterval(void *arg, unsigned long interval)
|
||||||
|
{
|
||||||
|
MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg;
|
||||||
|
memcpy(&handle->interval, &interval, sizeof(unsigned long));
|
||||||
|
}
|
||||||
@ -502,7 +502,10 @@ static int gw_read_backend_event(DCB *dcb) {
|
|||||||
goto return_rc;
|
goto return_rc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/** If protocol has command set it is session command */
|
/**
|
||||||
|
* If protocol has session command set, concatenate whole
|
||||||
|
* response into one buffer.
|
||||||
|
*/
|
||||||
if (protocol_get_srv_command((MySQLProtocol *)dcb->protocol, false) !=
|
if (protocol_get_srv_command((MySQLProtocol *)dcb->protocol, false) !=
|
||||||
MYSQL_COM_UNDEFINED)
|
MYSQL_COM_UNDEFINED)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -831,6 +831,7 @@ static struct {
|
|||||||
{ "master", SERVER_MASTER },
|
{ "master", SERVER_MASTER },
|
||||||
{ "slave", SERVER_SLAVE },
|
{ "slave", SERVER_SLAVE },
|
||||||
{ "synced", SERVER_JOINED },
|
{ "synced", SERVER_JOINED },
|
||||||
|
{ "ndb", SERVER_NDB },
|
||||||
{ "maintenance", SERVER_MAINT },
|
{ "maintenance", SERVER_MAINT },
|
||||||
{ "maint", SERVER_MAINT },
|
{ "maint", SERVER_MAINT },
|
||||||
{ NULL, 0 }
|
{ NULL, 0 }
|
||||||
|
|||||||
@ -311,6 +311,11 @@ char *weightby;
|
|||||||
inst->bitmask |= (SERVER_JOINED);
|
inst->bitmask |= (SERVER_JOINED);
|
||||||
inst->bitvalue |= SERVER_JOINED;
|
inst->bitvalue |= SERVER_JOINED;
|
||||||
}
|
}
|
||||||
|
else if (!strcasecmp(options[i], "ndb"))
|
||||||
|
{
|
||||||
|
inst->bitmask |= (SERVER_NDB);
|
||||||
|
inst->bitvalue |= SERVER_NDB;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOGIF(LM, (skygw_log_write(
|
LOGIF(LM, (skygw_log_write(
|
||||||
@ -318,7 +323,7 @@ char *weightby;
|
|||||||
"* Warning : Unsupported router "
|
"* Warning : Unsupported router "
|
||||||
"option \'%s\' for readconnroute. "
|
"option \'%s\' for readconnroute. "
|
||||||
"Expected router options are "
|
"Expected router options are "
|
||||||
"[slave|master|synced]",
|
"[slave|master|synced|ndb]",
|
||||||
options[i])));
|
options[i])));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -235,8 +235,9 @@ typedef enum skygw_chk_t {
|
|||||||
#define STRSRVSTATUS(s) ((SERVER_IS_RUNNING(s) && SERVER_IS_MASTER(s)) ? "RUNNING MASTER" : \
|
#define STRSRVSTATUS(s) ((SERVER_IS_RUNNING(s) && SERVER_IS_MASTER(s)) ? "RUNNING MASTER" : \
|
||||||
((SERVER_IS_RUNNING(s) && SERVER_IS_SLAVE(s)) ? "RUNNING SLAVE" : \
|
((SERVER_IS_RUNNING(s) && SERVER_IS_SLAVE(s)) ? "RUNNING SLAVE" : \
|
||||||
((SERVER_IS_RUNNING(s) && SERVER_IS_JOINED(s)) ? "RUNNING JOINED" : \
|
((SERVER_IS_RUNNING(s) && SERVER_IS_JOINED(s)) ? "RUNNING JOINED" : \
|
||||||
|
((SERVER_IS_RUNNING(s) && SERVER_IS_NDB(s)) ? "RUNNING NDB" : \
|
||||||
((SERVER_IS_RUNNING(s) && SERVER_IN_MAINT(s)) ? "RUNNING MAINTENANCE" : \
|
((SERVER_IS_RUNNING(s) && SERVER_IN_MAINT(s)) ? "RUNNING MAINTENANCE" : \
|
||||||
(SERVER_IS_RUNNING(s) ? "RUNNING (only)" : "NO STATUS")))))
|
(SERVER_IS_RUNNING(s) ? "RUNNING (only)" : "NO STATUS"))))))
|
||||||
|
|
||||||
#define CHK_MLIST(l) { \
|
#define CHK_MLIST(l) { \
|
||||||
ss_info_dassert((l->mlist_chk_top == CHK_NUM_MLIST && \
|
ss_info_dassert((l->mlist_chk_top == CHK_NUM_MLIST && \
|
||||||
|
|||||||
Reference in New Issue
Block a user