Merge branch 'release-1.0beta-refresh' into query_classifier_test

This commit is contained in:
Markus Makela
2014-09-24 09:58:30 +03:00
9 changed files with 148 additions and 55 deletions

View File

@ -108,15 +108,10 @@ char *hostname = "localhost";
char *port = "6603";
char *user = "admin";
char *passwd = NULL;
int so, cmdlen;
char *cmd;
int so;
int option_index = 0;
char c;
cmd = malloc(1);
*cmd = 0;
cmdlen = 1;
while ((c = getopt_long(argc, argv, "h:p:P:u:v?",
long_options, &option_index))
>= 0)
@ -180,14 +175,28 @@ char c;
exit(1);
}
if (cmdlen > 1)
{
cmd[cmdlen - 2] = '\0'; /* Remove trailing space */
if (access(cmd, R_OK) == 0)
DoSource(so, cmd);
else
sendCommand(so, cmd);
exit(0);
if (optind < argc) {
int i, len = 0;
char *cmd;
for (i = optind; i < argc; i++) {
len += strlen(argv[i]) + 1;
}
cmd = malloc(len);
strcpy(cmd, argv[optind]);
for (i = optind +1; i < argc; i++) {
strcat(cmd, " ");
strcat(cmd, argv[i]);
}
if (access(cmd, R_OK) == 0)
DoSource(so, cmd);
else
sendCommand(so, cmd);
free(cmd);
exit(0);
}
(void) setlocale(LC_CTYPE, "");
@ -391,7 +400,7 @@ char buf[20];
* Send a comamnd using the MaxScaled protocol, display the return data
* on standard output.
*
* Input terminates with a lien containing jsut the text OK
* Input terminates with a lien containing just the text OK
*
* @param so The socket connect to MaxScale
* @param cmd The command to send
@ -401,7 +410,7 @@ static int
sendCommand(int so, char *cmd)
{
char buf[80];
int i, j, newline = 0;
int i, j, newline = 1;
write(so, cmd, strlen(cmd));
while (1)

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

@ -45,6 +45,8 @@ extern int lm_enabled_logfiles_bitmask;
* zombie management
* 29/08/14 Mark Riddoch Addition of thread status data, load average
* etc.
* 23/09/14 Mark Riddoch Make use of RDHUP conditional to allow CentOS 5
* builds.
*
* @endverbatim
*/
@ -191,8 +193,12 @@ poll_add_dcb(DCB *dcb)
struct epoll_event ev;
CHK_DCB(dcb);
#ifdef EPOLLRDHUP
ev.events = EPOLLIN | EPOLLOUT | EPOLLRDHUP | EPOLLHUP | EPOLLET;
#else
ev.events = EPOLLIN | EPOLLOUT | EPOLLHUP | EPOLLET;
#endif
ev.data.ptr = dcb;
/*<
@ -631,6 +637,7 @@ DCB *zombies = NULL;
spinlock_release(&dcb->dcb_initlock);
}
#ifdef EPOLLRDHUP
if (ev & EPOLLRDHUP)
{
int eno = 0;
@ -657,9 +664,10 @@ DCB *zombies = NULL;
else
spinlock_release(&dcb->dcb_initlock);
}
#endif
} /*< for */
no_op = FALSE;
}
} /*< if (nfds > 0) */
process_zombies:
if (thread_data)
{
@ -682,6 +690,8 @@ process_zombies:
thread_data[thread_id].state = THREAD_STOPPED;
}
bitmask_clear(&poll_mask, thread_id);
/** Release mysql thread context */
mysql_thread_end();
return;
}
if (thread_data)
@ -689,8 +699,6 @@ process_zombies:
thread_data[thread_id].state = THREAD_IDLE;
}
} /*< while(1) */
/** Release mysql thread context */
mysql_thread_end();
}
/**
@ -785,12 +793,14 @@ char *str;
strcat(str, "|");
strcat(str, "HUP");
}
#ifdef EPOLLRDHUP
if (event & EPOLLRDHUP)
{
if (*str)
strcat(str, "|");
strcat(str, "RDHUP");
}
#endif
return str;
}

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));