Added ndbclustermon and mmmon headers.

This commit is contained in:
Markus Makela
2015-05-11 19:12:45 +03:00
parent 8f019b4514
commit 1aba13177b
10 changed files with 127 additions and 79 deletions

View File

@ -141,6 +141,7 @@ int externcmd_execute(EXTERNCMD* cmd)
}
else
{
cmd->child = pid;
cmd->n_exec++;
LOGIF(LD,skygw_log_write(LD,"[monitor_exec_cmd] Forked child process %d : %s.",pid,cmd));
}

View File

@ -11,6 +11,7 @@
typedef struct extern_cmd_t{
char* parameters[MAXSCALE_EXTCMD_ARG_MAX]; /*< Command arguments */
int n_exec; /*< Number of times executed */
pid_t child; /*< PID of the child process */
}EXTERNCMD;
EXTERNCMD* externcmd_allocate(char* argstr);

View File

@ -6,11 +6,11 @@ add_library(galeramon SHARED galeramon.c monitor_common.c)
target_link_libraries(galeramon log_manager utils)
install(TARGETS galeramon DESTINATION modules)
add_library(ndbclustermon SHARED ndbcluster_mon.c monitor_common.c)
add_library(ndbclustermon SHARED ndbclustermon.c monitor_common.c)
target_link_libraries(ndbclustermon log_manager utils)
install(TARGETS ndbclustermon DESTINATION modules)
if(BUILD_MMMON)
add_library(mmmon SHARED mm_mon.c monitor_common.c)
add_library(mmmon SHARED mmmon.c monitor_common.c)
target_link_libraries(mmmon log_manager utils)
install(TARGETS mmmon DESTINATION modules)
endif()

View File

@ -34,6 +34,7 @@
* 10/11/14 Massimiliano Pinto Added setNetworkTimeout for connect,read,write
* 20/04/15 Guillaume Lefranc Added availableWhenDonor feature
* 22/04/15 Martin Brampton Addition of disableMasterRoleSetting
* 08/05/15 Markus Makela Addition of launchable scripts
*
* @endverbatim
*/

View File

@ -56,7 +56,6 @@ typedef struct {
int shutdown; /**< Flag to shutdown the monitor thread */
int status; /**< Monitor status */
unsigned long id; /**< Monitor ID */
int detectStaleMaster; /**< Monitor flag for MySQL replication Stale Master detection */
int disableMasterFailback; /**< Monitor flag for Galera Cluster Master failback */
int availableWhenDonor; /**< Monitor flag for Galera Cluster Donor availability */
int disableMasterRoleSetting; /**< Monitor flag to disable setting master role */

View File

@ -17,19 +17,20 @@
*/
/**
* @file mysql_mon.c - A MySQL Multi Muster cluster monitor
* @file mm_mon.c - A Multi-Master Multi Muster cluster monitor
*
* @verbatim
* Revision History
*
* Date Who Description
* 08/09/14 Massimiliano Pinto Initial implementation
* 08/05/15 Markus Makela Addition of launchable scripts
*
* @endverbatim
*/
#include <mysqlmon.h>
#include <mmmon.h>
/** Defined in log_manager.cc */
extern int lm_enabled_logfiles_bitmask;
@ -44,7 +45,7 @@ MODULE_INFO info = {
MODULE_API_MONITOR,
MODULE_BETA_RELEASE,
MONITOR_VERSION,
"A MySQL Multi Master monitor"
"A Multi-Master Multi Master monitor"
};
static void *startMonitor(void *,void*);
@ -79,7 +80,7 @@ ModuleInit()
{
LOGIF(LM, (skygw_log_write(
LOGFILE_MESSAGE,
"Initialise the MySQL Monitor module %s.",
"Initialise the Multi-Master Monitor module %s.",
version_str)));
}
@ -109,7 +110,7 @@ static void *
startMonitor(void *arg,void* opt)
{
MONITOR* mon = (MONITOR*)arg;
MYSQL_MONITOR *handle = mon->handle;
MM_MONITOR *handle = mon->handle;
CONFIG_PARAMETER* params = (CONFIG_PARAMETER*)opt;
if (handle)
{
@ -117,12 +118,10 @@ startMonitor(void *arg,void* opt)
}
else
{
if ((handle = (MYSQL_MONITOR *)malloc(sizeof(MYSQL_MONITOR))) == NULL)
if ((handle = (MM_MONITOR *)malloc(sizeof(MM_MONITOR))) == NULL)
return NULL;
handle->shutdown = 0;
handle->id = MONITOR_DEFAULT_ID;
handle->replicationHeartbeat = 0;
handle->detectStaleMaster = 0;
handle->master = NULL;
spinlock_init(&handle->lock);
}
@ -157,7 +156,7 @@ startMonitor(void *arg,void* opt)
static void
stopMonitor(void *arg)
{
MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg;
MM_MONITOR *handle = (MM_MONITOR *)arg;
handle->shutdown = 1;
thread_wait((void *)handle->tid);
@ -172,7 +171,7 @@ MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg;
static void diagnostics(DCB *dcb, void *arg)
{
MONITOR* mon = (MONITOR*)arg;
MYSQL_MONITOR *handle = (MYSQL_MONITOR *)mon->handle;
MM_MONITOR *handle = (MM_MONITOR *)mon->handle;
MONITOR_SERVERS *db;
char *sep;
@ -217,7 +216,7 @@ char *sep;
static void
monitorDatabase(MONITOR* mon, MONITOR_SERVERS *database)
{
MYSQL_MONITOR *handle = mon->handle;
MM_MONITOR *handle = mon->handle;
MYSQL_ROW row;
MYSQL_RES *result;
int isslave = 0;
@ -240,7 +239,7 @@ char *server_string;
if (SERVER_IN_MAINT(database->server))
return;
/** Store prevous status */
/** Store previous status */
database->mon_prev_status = database->server->status;
if (database->con == NULL || mysql_ping(database->con) != 0)
@ -473,7 +472,7 @@ static void
monitorMain(void *arg)
{
MONITOR* mon = (MONITOR*)arg;
MYSQL_MONITOR *handle = (MYSQL_MONITOR *)mon->handle;
MM_MONITOR *handle = (MM_MONITOR *)mon->handle;
MONITOR_SERVERS *ptr;
int detect_stale_master = handle->detectStaleMaster;
MONITOR_SERVERS *root_master;
@ -612,70 +611,10 @@ static void
detectStaleMaster(void *arg, int enable)
{
MONITOR* mon = (MONITOR*)arg;
MYSQL_MONITOR *handle = (MYSQL_MONITOR *)mon->handle;
MM_MONITOR *handle = (MM_MONITOR *)mon->handle;
memcpy(&handle->detectStaleMaster, &enable, sizeof(int));
}
static bool mon_status_changed(
MONITOR_SERVERS* mon_srv)
{
bool succp;
if (mon_srv->mon_prev_status != mon_srv->server->status)
{
succp = true;
}
else
{
succp = false;
}
return succp;
}
static bool mon_print_fail_status(
MONITOR_SERVERS* mon_srv)
{
bool succp;
int errcount = mon_srv->mon_err_count;
uint8_t modval;
modval = 1<<(MIN(errcount/10, 7));
if (SERVER_IS_DOWN(mon_srv->server) && errcount%modval == 0)
{
succp = true;
}
else
{
succp = false;
}
return succp;
}
/**
* Set a pending status bit in the monior server
*
* @param server The server to update
* @param bit The bit to clear for the server
*/
static void
monitor_set_pending_status(MONITOR_SERVERS *ptr, int bit)
{
ptr->pending_status |= bit;
}
/**
* Clear a pending status bit in the monior server
*
* @param server The server to update
* @param bit The bit to clear for the server
*/
static void
monitor_clear_pending_status(MONITOR_SERVERS *ptr, int bit)
{
ptr->pending_status &= ~bit;
}
/*******
* This function returns the master server
* from a set of MySQL Multi Master monitored servers
@ -687,7 +626,7 @@ monitor_clear_pending_status(MONITOR_SERVERS *ptr, int bit)
*/
static MONITOR_SERVERS *get_current_master(MONITOR *mon) {
MYSQL_MONITOR* handle = mon->handle;
MM_MONITOR* handle = mon->handle;
MONITOR_SERVERS *ptr;
ptr = mon->databases;

View File

@ -0,0 +1,51 @@
#ifndef _MMMON_H
#define _MMMON_H
/*
* This file is distributed as part of the MariaDB Corporation MaxScale. 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 MariaDB Corporation Ab 2015
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <monitor.h>
#include <spinlock.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>
#include <maxconfig.h>
#include <monitor_common.h>
#include <mon_exec.h>
/**
* The handle for an instance of a Multi-Master Monitor module
*/
typedef struct {
SPINLOCK lock; /**< The monitor spinlock */
pthread_t tid; /**< id of monitor thread */
int shutdown; /**< Flag to shutdown the monitor thread */
int status; /**< Monitor status */
unsigned long id; /**< Monitor ID */
int detectStaleMaster; /**< Monitor flag for Stale Master detection */
MONITOR_SERVERS *master; /**< Master server for Master/Slave replication */
char* script; /*< Script to call when state changes occur on servers */
} MM_MONITOR;
#endif

View File

@ -49,7 +49,7 @@
* 07/11/14 Massimiliano Pinto Addition of NetworkTimeout: connect, read, write
* 20/04/15 Guillaume Lefranc Addition of availableWhenDonor
* 22/04/15 Martin Brampton Addition of disableMasterRoleSetting
* 07/05/15 Markus Makela Addition of command execution on Master server failure
* 07/05/15 Markus Makela Addition of command execution on Master server failure
* @endverbatim
*/

View File

@ -25,6 +25,7 @@
* Date Who Description
* 25/07/14 Massimiliano Pinto Initial implementation
* 10/11/14 Massimiliano Pinto Added setNetworkTimeout for connect,read,write
* 08/05/15 Markus Makela Addition of launchable scripts
*
* @endverbatim
*/

View File

@ -0,0 +1,55 @@
#ifndef _MYSQLMON_H
#define _MYSQLMON_H
/*
* This file is distributed as part of the MariaDB Corporation MaxScale. 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 MariaDB Corporation Ab 2013-2014
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <monitor.h>
#include <spinlock.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>
#include <maxconfig.h>
#include <monitor_common.h>
#include <mon_exec.h>
/**
* @file ndbclustermon.h - The NDB Cluster monitor
*
*/
/**
* The handle for an instance of a NDB Cluster Monitor module
*/
typedef struct {
SPINLOCK lock; /**< The monitor spinlock */
pthread_t tid; /**< id of monitor thread */
int shutdown; /**< Flag to shutdown the monitor thread */
int status; /**< Monitor status */
unsigned long id; /**< Monitor ID */
MONITOR_SERVERS *master; /**< Master server for MySQL Master/Slave replication */
char* script; /*< Script to call when state changes occur on servers */
} MYSQL_MONITOR;
#endif