Each monitor loops 10 times/second (sleep 100ms) and perform monitoring checks only when monitor's interval is spent. Monitors notice faster if the shutdown flag is set and thus overall shutdown is faster.
hint.c:added missing header
Changed interval from unsigned long to size_t which is guaranteed to be of same size also in windows (if possible).
This commit is contained in:
VilhoRaatikka 2014-09-23 11:26:15 +03:00
parent 503b942b5c
commit 45f8585804
8 changed files with 110 additions and 36 deletions

View File

@ -1688,8 +1688,13 @@ static void log_flush_cb(
static void unlink_pidfile(void)
{
if (strlen(pidfile)) {
if (unlink(pidfile)) {
fprintf(stderr, "MaxScale failed to remove pidfile %s: error %d, %s\n", pidfile, errno, strerror(errno));
if (unlink(pidfile))
{
fprintf(stderr,
"MaxScale failed to remove pidfile %s: error %d, %s\n",
pidfile,
errno,
strerror(errno));
}
}
}

View File

@ -17,6 +17,7 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <hint.h>
/**

View File

@ -60,8 +60,9 @@ MONITOR *mon;
{
return NULL;
}
mon->state = MONITOR_STATE_ALLOC;
mon->name = strdup(name);
if ((mon->module = load_module(module, MODULE_MONITOR)) == NULL)
{
LOGIF(LE, (skygw_log_write_flush(
@ -73,7 +74,8 @@ MONITOR *mon;
return NULL;
}
mon->handle = (*mon->module->startMonitor)(NULL);
mon->state |= MONITOR_STATE_RUNNING;
mon->state = MONITOR_STATE_RUNNING;
spinlock_acquire(&monLock);
mon->next = allMonitors;
allMonitors = mon;
@ -94,7 +96,7 @@ monitor_free(MONITOR *mon)
MONITOR *ptr;
mon->module->stopMonitor(mon->handle);
mon->state &= ~MONITOR_STATE_RUNNING;
mon->state = MONITOR_STATE_FREED;
spinlock_acquire(&monLock);
if (allMonitors == mon)
allMonitors = mon->next;
@ -121,7 +123,7 @@ void
monitorStart(MONITOR *monitor)
{
monitor->handle = (*monitor->module->startMonitor)(monitor->handle);
monitor->state |= MONITOR_STATE_RUNNING;
monitor->state = MONITOR_STATE_RUNNING;
}
/**
@ -132,8 +134,9 @@ monitorStart(MONITOR *monitor)
void
monitorStop(MONITOR *monitor)
{
monitor->state = MONITOR_STATE_STOPPING;
monitor->module->stopMonitor(monitor->handle);
monitor->state &= ~MONITOR_STATE_RUNNING;
monitor->state = MONITOR_STATE_STOPPED;
}
/**

View File

@ -659,7 +659,7 @@ DCB *zombies = NULL;
}
} /*< for */
no_op = FALSE;
}
} /*< if (nfds > 0) */
process_zombies:
if (thread_data)
{

View File

@ -69,7 +69,7 @@ typedef struct {
void (*unregisterServer)(void *, SERVER *);
void (*defaultUser)(void *, char *, char *);
void (*diagnostics)(DCB *, void *);
void (*setInterval)(void *, unsigned long);
void (*setInterval)(void *, size_t);
void (*defaultId)(void *, unsigned long);
void (*replicationHeartbeat)(void *, int);
void (*detectStaleMaster)(void *, int);
@ -81,21 +81,30 @@ typedef struct {
*/
#define MONITOR_VERSION {1, 0, 0}
/** Monitor's poll frequency */
#define MON_BASE_INTERVAL_MS 100
/**
* Monitor state bit mask values
*/
#define MONITOR_STATE_RUNNING 0x0001
typedef enum
{
MONITOR_STATE_ALLOC = 0x00,
MONITOR_STATE_RUNNING = 0x01,
MONITOR_STATE_STOPPING = 0x02,
MONITOR_STATE_STOPPED = 0x04,
MONITOR_STATE_FREED = 0x08
} monitor_state_t;
/**
* Representation of the running monitor.
*/
typedef struct monitor {
char *name; /**< The name of the monitor module */
unsigned int state; /**< The monitor status */
monitor_state_t state; /**< The state of the monitor */
MONITOR_OBJECT *module; /**< The "monitor object" */
void *handle; /**< Handle returned from startMonitor */
int interval; /**< The monitor interval */
size_t interval; /**< The monitor interval */
struct monitor *next; /**< Next monitor in the linked list */
} MONITOR;

View File

@ -67,9 +67,20 @@ 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 void setInterval(void *, size_t);
static MONITOR_OBJECT MyObject = { startMonitor, stopMonitor, registerServer, unregisterServer, defaultUsers, diagnostics, setInterval, NULL, NULL, NULL };
static MONITOR_OBJECT MyObject = {
startMonitor,
stopMonitor,
registerServer,
unregisterServer,
defaultUsers,
diagnostics,
setInterval,
NULL,
NULL,
NULL,
};
/**
* Implementation of the mandatory version entry point
@ -413,6 +424,7 @@ monitorMain(void *arg)
MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg;
MONITOR_SERVERS *ptr;
long master_id;
size_t nrounds = 0;
if (mysql_thread_init())
{
@ -423,10 +435,9 @@ long master_id;
return;
}
handle->status = MONITOR_RUNNING;
while (1)
{
master_id = -1;
if (handle->shutdown)
{
handle->status = MONITOR_STOPPING;
@ -434,7 +445,16 @@ long master_id;
handle->status = MONITOR_STOPPED;
return;
}
/** Wait base interval */
thread_millisleep(MON_BASE_INTERVAL_MS);
nrounds += 1;
/** If monitor interval time isn't consumed skip checks */
if ((nrounds*MON_BASE_INTERVAL_MS)%handle->interval != 0)
{
continue;
}
master_id = -1;
ptr = handle->databases;
while (ptr)
@ -491,7 +511,6 @@ long master_id;
ptr = ptr->next;
}
thread_millisleep(handle->interval);
}
}
@ -502,7 +521,7 @@ long master_id;
* @param interval The interval to set in monitor struct, in milliseconds
*/
static void
setInterval(void *arg, unsigned long interval)
setInterval(void *arg, size_t interval)
{
MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg;
memcpy(&handle->interval, &interval, sizeof(unsigned long));

View File

@ -80,7 +80,7 @@ static void registerServer(void *, SERVER *);
static void unregisterServer(void *, SERVER *);
static void defaultUser(void *, char *, char *);
static void diagnostics(DCB *, void *);
static void setInterval(void *, unsigned long);
static void setInterval(void *, size_t);
static void defaultId(void *, unsigned long);
static void replicationHeartbeat(void *, int);
static void detectStaleMaster(void *, int);
@ -95,7 +95,18 @@ static int add_slave_to_master(long *, int, long);
static void monitor_set_pending_status(MONITOR_SERVERS *, int);
static void monitor_clear_pending_status(MONITOR_SERVERS *, int);
static MONITOR_OBJECT MyObject = { startMonitor, stopMonitor, registerServer, unregisterServer, defaultUser, diagnostics, setInterval, defaultId, replicationHeartbeat, detectStaleMaster };
static MONITOR_OBJECT MyObject = {
startMonitor,
stopMonitor,
registerServer,
unregisterServer,
defaultUser,
diagnostics,
setInterval,
defaultId,
replicationHeartbeat,
detectStaleMaster
};
/**
* Implementation of the mandatory version entry point
@ -577,6 +588,7 @@ int replication_heartbeat = handle->replicationHeartbeat;
int detect_stale_master = handle->detectStaleMaster;
int num_servers=0;
MONITOR_SERVERS *root_master;
size_t nrounds = 0;
if (mysql_thread_init())
{
@ -586,8 +598,8 @@ MONITOR_SERVERS *root_master;
"module. Exiting.\n")));
return;
}
handle->status = MONITOR_RUNNING;
while (1)
{
if (handle->shutdown)
@ -597,6 +609,15 @@ MONITOR_SERVERS *root_master;
handle->status = MONITOR_STOPPED;
return;
}
/** Wait base interval */
thread_millisleep(MON_BASE_INTERVAL_MS);
nrounds += 1;
/** If monitor interval time isn't consumed skip checks */
if ((nrounds*MON_BASE_INTERVAL_MS)%handle->interval != 0)
{
continue;
}
/* reset num_servers */
num_servers = 0;
@ -686,10 +707,7 @@ MONITOR_SERVERS *root_master;
ptr = ptr->next;
}
}
/* wait for the configured interval */
thread_millisleep(handle->interval);
}
} /*< while (1) */
}
/**
@ -704,7 +722,7 @@ defaultId(void *arg, unsigned long id)
MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg;
memcpy(&handle->id, &id, sizeof(unsigned long));
}
/**
* Set the monitor sampling interval.
*
@ -712,7 +730,7 @@ MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg;
* @param interval The interval to set in monitor struct, in milliseconds
*/
static void
setInterval(void *arg, unsigned long interval)
setInterval(void *arg, size_t interval)
{
MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg;
memcpy(&handle->interval, &interval, sizeof(unsigned long));

View File

@ -61,9 +61,20 @@ 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 void setInterval(void *, size_t);
static MONITOR_OBJECT MyObject = { startMonitor, stopMonitor, registerServer, unregisterServer, defaultUsers, diagnostics, setInterval, NULL, NULL, NULL };
static MONITOR_OBJECT MyObject = {
startMonitor,
stopMonitor,
registerServer,
unregisterServer,
defaultUsers,
diagnostics,
setInterval,
NULL,
NULL,
NULL
};
/**
* Implementation of the mandatory version entry point
@ -410,6 +421,7 @@ monitorMain(void *arg)
MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg;
MONITOR_SERVERS *ptr;
long master_id;
size_t nrounds = 0;
if (mysql_thread_init())
{
@ -420,10 +432,9 @@ long master_id;
return;
}
handle->status = MONITOR_RUNNING;
while (1)
{
master_id = -1;
if (handle->shutdown)
{
handle->status = MONITOR_STOPPING;
@ -432,6 +443,16 @@ long master_id;
return;
}
/** Wait base interval */
thread_millisleep(MON_BASE_INTERVAL_MS);
nrounds += 1;
/** If monitor interval time isn't consumed skip checks */
if ((nrounds*MON_BASE_INTERVAL_MS)%handle->interval != 0)
{
continue;
}
master_id = -1;
ptr = handle->databases;
while (ptr)
@ -452,8 +473,6 @@ long master_id;
ptr = ptr->next;
}
thread_millisleep(handle->interval);
}
}
@ -464,7 +483,7 @@ long master_id;
* @param interval The interval to set in monitor struct, in milliseconds
*/
static void
setInterval(void *arg, unsigned long interval)
setInterval(void *arg, size_t interval)
{
MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg;
memcpy(&handle->interval, &interval, sizeof(unsigned long));