Merge branch 'release-1.0beta-refresh' of github.com:skysql/MaxScale into release-1.0beta-refresh

This commit is contained in:
Mark Riddoch
2014-09-23 12:04:37 +01:00
8 changed files with 112 additions and 38 deletions

View File

@ -1688,8 +1688,13 @@ static void log_flush_cb(
static void unlink_pidfile(void) static void unlink_pidfile(void)
{ {
if (strlen(pidfile)) { if (strlen(pidfile)) {
if (unlink(pidfile)) { if (unlink(pidfile))
fprintf(stderr, "MaxScale failed to remove pidfile %s: error %d, %s\n", pidfile, errno, strerror(errno)); {
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 <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <hint.h> #include <hint.h>
/** /**

View File

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

View File

@ -667,7 +667,7 @@ DCB *zombies = NULL;
#endif #endif
} /*< for */ } /*< for */
no_op = FALSE; no_op = FALSE;
} } /*< if (nfds > 0) */
process_zombies: process_zombies:
if (thread_data) if (thread_data)
{ {
@ -690,6 +690,8 @@ process_zombies:
thread_data[thread_id].state = THREAD_STOPPED; thread_data[thread_id].state = THREAD_STOPPED;
} }
bitmask_clear(&poll_mask, thread_id); bitmask_clear(&poll_mask, thread_id);
/** Release mysql thread context */
mysql_thread_end();
return; return;
} }
if (thread_data) if (thread_data)
@ -697,8 +699,6 @@ process_zombies:
thread_data[thread_id].state = THREAD_IDLE; thread_data[thread_id].state = THREAD_IDLE;
} }
} /*< while(1) */ } /*< while(1) */
/** Release mysql thread context */
mysql_thread_end();
} }
/** /**

View File

@ -69,7 +69,7 @@ typedef struct {
void (*unregisterServer)(void *, SERVER *); void (*unregisterServer)(void *, SERVER *);
void (*defaultUser)(void *, char *, char *); void (*defaultUser)(void *, char *, char *);
void (*diagnostics)(DCB *, void *); void (*diagnostics)(DCB *, void *);
void (*setInterval)(void *, unsigned long); void (*setInterval)(void *, size_t);
void (*defaultId)(void *, unsigned long); void (*defaultId)(void *, unsigned long);
void (*replicationHeartbeat)(void *, int); void (*replicationHeartbeat)(void *, int);
void (*detectStaleMaster)(void *, int); void (*detectStaleMaster)(void *, int);
@ -81,21 +81,30 @@ typedef struct {
*/ */
#define MONITOR_VERSION {1, 0, 0} #define MONITOR_VERSION {1, 0, 0}
/** Monitor's poll frequency */
#define MON_BASE_INTERVAL_MS 100
/** /**
* Monitor state bit mask values * 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. * Representation of the running monitor.
*/ */
typedef struct monitor { typedef struct monitor {
char *name; /**< The name of the monitor module */ 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" */ MONITOR_OBJECT *module; /**< The "monitor object" */
void *handle; /**< Handle returned from startMonitor */ 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 */ struct monitor *next; /**< Next monitor in the linked list */
} MONITOR; } MONITOR;

View File

@ -67,9 +67,20 @@ static void registerServer(void *, SERVER *);
static void unregisterServer(void *, SERVER *); static void unregisterServer(void *, SERVER *);
static void defaultUsers(void *, char *, char *); static void defaultUsers(void *, char *, char *);
static void diagnostics(DCB *, void *); 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 * Implementation of the mandatory version entry point
@ -413,6 +424,7 @@ monitorMain(void *arg)
MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg; MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg;
MONITOR_SERVERS *ptr; MONITOR_SERVERS *ptr;
long master_id; long master_id;
size_t nrounds = 0;
if (mysql_thread_init()) if (mysql_thread_init())
{ {
@ -423,10 +435,9 @@ long master_id;
return; return;
} }
handle->status = MONITOR_RUNNING; handle->status = MONITOR_RUNNING;
while (1) while (1)
{ {
master_id = -1;
if (handle->shutdown) if (handle->shutdown)
{ {
handle->status = MONITOR_STOPPING; handle->status = MONITOR_STOPPING;
@ -434,7 +445,16 @@ long master_id;
handle->status = MONITOR_STOPPED; handle->status = MONITOR_STOPPED;
return; 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; ptr = handle->databases;
while (ptr) while (ptr)
@ -491,7 +511,6 @@ long master_id;
ptr = ptr->next; 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 * @param interval The interval to set in monitor struct, in milliseconds
*/ */
static void static void
setInterval(void *arg, unsigned long interval) setInterval(void *arg, size_t interval)
{ {
MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg; MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg;
memcpy(&handle->interval, &interval, sizeof(unsigned long)); 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 unregisterServer(void *, SERVER *);
static void defaultUser(void *, char *, char *); static void defaultUser(void *, char *, char *);
static void diagnostics(DCB *, void *); 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 defaultId(void *, unsigned long);
static void replicationHeartbeat(void *, int); static void replicationHeartbeat(void *, int);
static void detectStaleMaster(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_set_pending_status(MONITOR_SERVERS *, int);
static void monitor_clear_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 * Implementation of the mandatory version entry point
@ -577,6 +588,7 @@ int replication_heartbeat = handle->replicationHeartbeat;
int detect_stale_master = handle->detectStaleMaster; int detect_stale_master = handle->detectStaleMaster;
int num_servers=0; int num_servers=0;
MONITOR_SERVERS *root_master; MONITOR_SERVERS *root_master;
size_t nrounds = 0;
if (mysql_thread_init()) if (mysql_thread_init())
{ {
@ -586,8 +598,8 @@ MONITOR_SERVERS *root_master;
"module. Exiting.\n"))); "module. Exiting.\n")));
return; return;
} }
handle->status = MONITOR_RUNNING; handle->status = MONITOR_RUNNING;
while (1) while (1)
{ {
if (handle->shutdown) if (handle->shutdown)
@ -597,6 +609,15 @@ MONITOR_SERVERS *root_master;
handle->status = MONITOR_STOPPED; handle->status = MONITOR_STOPPED;
return; 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 */ /* reset num_servers */
num_servers = 0; num_servers = 0;
@ -686,10 +707,7 @@ MONITOR_SERVERS *root_master;
ptr = ptr->next; ptr = ptr->next;
} }
} }
} /*< while (1) */
/* wait for the configured interval */
thread_millisleep(handle->interval);
}
} }
/** /**
@ -712,7 +730,7 @@ MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg;
* @param interval The interval to set in monitor struct, in milliseconds * @param interval The interval to set in monitor struct, in milliseconds
*/ */
static void static void
setInterval(void *arg, unsigned long interval) setInterval(void *arg, size_t interval)
{ {
MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg; MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg;
memcpy(&handle->interval, &interval, sizeof(unsigned long)); 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 unregisterServer(void *, SERVER *);
static void defaultUsers(void *, char *, char *); static void defaultUsers(void *, char *, char *);
static void diagnostics(DCB *, void *); 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 * Implementation of the mandatory version entry point
@ -410,6 +421,7 @@ monitorMain(void *arg)
MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg; MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg;
MONITOR_SERVERS *ptr; MONITOR_SERVERS *ptr;
long master_id; long master_id;
size_t nrounds = 0;
if (mysql_thread_init()) if (mysql_thread_init())
{ {
@ -420,10 +432,9 @@ long master_id;
return; return;
} }
handle->status = MONITOR_RUNNING; handle->status = MONITOR_RUNNING;
while (1) while (1)
{ {
master_id = -1;
if (handle->shutdown) if (handle->shutdown)
{ {
handle->status = MONITOR_STOPPING; handle->status = MONITOR_STOPPING;
@ -432,6 +443,16 @@ long master_id;
return; 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; ptr = handle->databases;
while (ptr) while (ptr)
@ -452,8 +473,6 @@ long master_id;
ptr = ptr->next; 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 * @param interval The interval to set in monitor struct, in milliseconds
*/ */
static void static void
setInterval(void *arg, unsigned long interval) setInterval(void *arg, size_t interval)
{ {
MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg; MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg;
memcpy(&handle->interval, &interval, sizeof(unsigned long)); memcpy(&handle->interval, &interval, sizeof(unsigned long));