Reindent server/core/monitor.c
This commit is contained in:
@ -122,15 +122,21 @@ MONITOR *ptr;
|
|||||||
mon->state = MONITOR_STATE_FREED;
|
mon->state = MONITOR_STATE_FREED;
|
||||||
spinlock_acquire(&monLock);
|
spinlock_acquire(&monLock);
|
||||||
if (allMonitors == mon)
|
if (allMonitors == mon)
|
||||||
|
{
|
||||||
allMonitors = mon->next;
|
allMonitors = mon->next;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ptr = allMonitors;
|
ptr = allMonitors;
|
||||||
while (ptr->next && ptr->next != mon)
|
while (ptr->next && ptr->next != mon)
|
||||||
|
{
|
||||||
ptr = ptr->next;
|
ptr = ptr->next;
|
||||||
|
}
|
||||||
if (ptr->next)
|
if (ptr->next)
|
||||||
|
{
|
||||||
ptr->next = mon->next;
|
ptr->next = mon->next;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
spinlock_release(&monLock);
|
spinlock_release(&monLock);
|
||||||
free_config_parameter(mon->parameters);
|
free_config_parameter(mon->parameters);
|
||||||
free(mon->name);
|
free(mon->name);
|
||||||
@ -216,7 +222,9 @@ monitorAddServer(MONITOR *mon, SERVER *server)
|
|||||||
MONITOR_SERVERS *ptr, *db;
|
MONITOR_SERVERS *ptr, *db;
|
||||||
|
|
||||||
if ((db = (MONITOR_SERVERS *)malloc(sizeof(MONITOR_SERVERS))) == NULL)
|
if ((db = (MONITOR_SERVERS *)malloc(sizeof(MONITOR_SERVERS))) == NULL)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
db->server = server;
|
db->server = server;
|
||||||
db->con = NULL;
|
db->con = NULL;
|
||||||
db->next = NULL;
|
db->next = NULL;
|
||||||
@ -230,12 +238,16 @@ monitorAddServer(MONITOR *mon, SERVER *server)
|
|||||||
spinlock_acquire(&mon->lock);
|
spinlock_acquire(&mon->lock);
|
||||||
|
|
||||||
if (mon->databases == NULL)
|
if (mon->databases == NULL)
|
||||||
|
{
|
||||||
mon->databases = db;
|
mon->databases = db;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ptr = mon->databases;
|
ptr = mon->databases;
|
||||||
while (ptr->next != NULL)
|
while (ptr->next != NULL)
|
||||||
|
{
|
||||||
ptr = ptr->next;
|
ptr = ptr->next;
|
||||||
|
}
|
||||||
ptr->next = db;
|
ptr->next = db;
|
||||||
}
|
}
|
||||||
spinlock_release(&mon->lock);
|
spinlock_release(&mon->lock);
|
||||||
@ -273,7 +285,9 @@ MONITOR *ptr;
|
|||||||
dcb_printf(dcb, "Monitor: %p\n", ptr);
|
dcb_printf(dcb, "Monitor: %p\n", ptr);
|
||||||
dcb_printf(dcb, "\tName: %s\n", ptr->name);
|
dcb_printf(dcb, "\tName: %s\n", ptr->name);
|
||||||
if (ptr->module->diagnostics)
|
if (ptr->module->diagnostics)
|
||||||
|
{
|
||||||
ptr->module->diagnostics(dcb, ptr);
|
ptr->module->diagnostics(dcb, ptr);
|
||||||
|
}
|
||||||
ptr = ptr->next;
|
ptr = ptr->next;
|
||||||
}
|
}
|
||||||
spinlock_release(&monLock);
|
spinlock_release(&monLock);
|
||||||
@ -291,8 +305,10 @@ monitorShow(DCB *dcb, MONITOR *monitor)
|
|||||||
dcb_printf(dcb, "Monitor: %p\n", monitor);
|
dcb_printf(dcb, "Monitor: %p\n", monitor);
|
||||||
dcb_printf(dcb, "\tName: %s\n", monitor->name);
|
dcb_printf(dcb, "\tName: %s\n", monitor->name);
|
||||||
if (monitor->module->diagnostics)
|
if (monitor->module->diagnostics)
|
||||||
|
{
|
||||||
monitor->module->diagnostics(dcb, monitor);
|
monitor->module->diagnostics(dcb, monitor);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List all the monitors
|
* List all the monitors
|
||||||
@ -336,7 +352,9 @@ MONITOR *ptr;
|
|||||||
while (ptr)
|
while (ptr)
|
||||||
{
|
{
|
||||||
if (!strcmp(ptr->name, name))
|
if (!strcmp(ptr->name, name))
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
ptr = ptr->next;
|
ptr = ptr->next;
|
||||||
}
|
}
|
||||||
spinlock_release(&monLock);
|
spinlock_release(&monLock);
|
||||||
@ -369,13 +387,18 @@ monitorSetNetworkTimeout(MONITOR *mon, int type, int value) {
|
|||||||
int new_timeout = max_timeout -1;
|
int new_timeout = max_timeout -1;
|
||||||
|
|
||||||
if (new_timeout <= 0)
|
if (new_timeout <= 0)
|
||||||
|
{
|
||||||
new_timeout = DEFAULT_CONNECT_TIMEOUT;
|
new_timeout = DEFAULT_CONNECT_TIMEOUT;
|
||||||
|
}
|
||||||
|
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case MONITOR_CONNECT_TIMEOUT:
|
case MONITOR_CONNECT_TIMEOUT:
|
||||||
if (value < max_timeout) {
|
if (value < max_timeout)
|
||||||
|
{
|
||||||
memcpy(&mon->connect_timeout, &value, sizeof(int));
|
memcpy(&mon->connect_timeout, &value, sizeof(int));
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
memcpy(&mon->connect_timeout, &new_timeout, sizeof(int));
|
memcpy(&mon->connect_timeout, &new_timeout, sizeof(int));
|
||||||
MXS_WARNING("Monitor Connect Timeout %i is greater than monitor interval ~%i seconds"
|
MXS_WARNING("Monitor Connect Timeout %i is greater than monitor interval ~%i seconds"
|
||||||
", lowering to %i seconds", value, max_timeout, new_timeout);
|
", lowering to %i seconds", value, max_timeout, new_timeout);
|
||||||
@ -383,9 +406,12 @@ monitorSetNetworkTimeout(MONITOR *mon, int type, int value) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case MONITOR_READ_TIMEOUT:
|
case MONITOR_READ_TIMEOUT:
|
||||||
if (value < max_timeout) {
|
if (value < max_timeout)
|
||||||
|
{
|
||||||
memcpy(&mon->read_timeout, &value, sizeof(int));
|
memcpy(&mon->read_timeout, &value, sizeof(int));
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
memcpy(&mon->read_timeout, &new_timeout, sizeof(int));
|
memcpy(&mon->read_timeout, &new_timeout, sizeof(int));
|
||||||
MXS_WARNING("Monitor Read Timeout %i is greater than monitor interval ~%i seconds"
|
MXS_WARNING("Monitor Read Timeout %i is greater than monitor interval ~%i seconds"
|
||||||
", lowering to %i seconds", value, max_timeout, new_timeout);
|
", lowering to %i seconds", value, max_timeout, new_timeout);
|
||||||
@ -393,9 +419,12 @@ monitorSetNetworkTimeout(MONITOR *mon, int type, int value) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case MONITOR_WRITE_TIMEOUT:
|
case MONITOR_WRITE_TIMEOUT:
|
||||||
if (value < max_timeout) {
|
if (value < max_timeout)
|
||||||
|
{
|
||||||
memcpy(&mon->write_timeout, &value, sizeof(int));
|
memcpy(&mon->write_timeout, &value, sizeof(int));
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
memcpy(&mon->write_timeout, &new_timeout, sizeof(int));
|
memcpy(&mon->write_timeout, &new_timeout, sizeof(int));
|
||||||
MXS_WARNING("Monitor Write Timeout %i is greater than monitor interval ~%i seconds"
|
MXS_WARNING("Monitor Write Timeout %i is greater than monitor interval ~%i seconds"
|
||||||
", lowering to %i seconds", value, max_timeout, new_timeout);
|
", lowering to %i seconds", value, max_timeout, new_timeout);
|
||||||
@ -457,7 +486,9 @@ RESULTSET *set;
|
|||||||
int *data;
|
int *data;
|
||||||
|
|
||||||
if ((data = (int *)malloc(sizeof(int))) == NULL)
|
if ((data = (int *)malloc(sizeof(int))) == NULL)
|
||||||
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
*data = 0;
|
*data = 0;
|
||||||
if ((set = resultset_create(monitorRowCallback, data)) == NULL)
|
if ((set = resultset_create(monitorRowCallback, data)) == NULL)
|
||||||
{
|
{
|
||||||
@ -600,13 +631,15 @@ monitor_clear_pending_status(MONITOR_SERVERS *ptr, int bit)
|
|||||||
monitor_event_t
|
monitor_event_t
|
||||||
mon_get_event_type(MONITOR_SERVERS* node)
|
mon_get_event_type(MONITOR_SERVERS* node)
|
||||||
{
|
{
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
DOWN_EVENT,
|
DOWN_EVENT,
|
||||||
UP_EVENT,
|
UP_EVENT,
|
||||||
LOSS_EVENT,
|
LOSS_EVENT,
|
||||||
NEW_EVENT,
|
NEW_EVENT,
|
||||||
UNSUPPORTED_EVENT
|
UNSUPPORTED_EVENT
|
||||||
} general_event_type;
|
} general_event_type;
|
||||||
|
|
||||||
general_event_type event_type = UNSUPPORTED_EVENT;
|
general_event_type event_type = UNSUPPORTED_EVENT;
|
||||||
|
|
||||||
unsigned int prev = node->mon_prev_status
|
unsigned int prev = node->mon_prev_status
|
||||||
|
|||||||
@ -73,7 +73,8 @@
|
|||||||
* unregisterServer is called to remove a server from the set of servers that need to be
|
* unregisterServer is called to remove a server from the set of servers that need to be
|
||||||
* monitored.
|
* monitored.
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct
|
||||||
|
{
|
||||||
void *(*startMonitor)(void *, void*);
|
void *(*startMonitor)(void *, void*);
|
||||||
void (*stopMonitor)(void *);
|
void (*stopMonitor)(void *);
|
||||||
void (*diagnostics)(DCB *, void *);
|
void (*diagnostics)(DCB *, void *);
|
||||||
@ -158,21 +159,22 @@ extern const monitor_def_t monitor_event_definitions[];
|
|||||||
/**
|
/**
|
||||||
* The linked list of servers that are being monitored by the monitor module.
|
* The linked list of servers that are being monitored by the monitor module.
|
||||||
*/
|
*/
|
||||||
typedef struct monitor_servers {
|
typedef struct monitor_servers
|
||||||
|
{
|
||||||
SERVER *server; /**< The server being monitored */
|
SERVER *server; /**< The server being monitored */
|
||||||
MYSQL *con; /**< The MySQL connection */
|
MYSQL *con; /**< The MySQL connection */
|
||||||
bool log_version_err;
|
bool log_version_err;
|
||||||
int mon_err_count;
|
int mon_err_count;
|
||||||
unsigned int mon_prev_status;
|
unsigned int mon_prev_status;
|
||||||
unsigned int pending_status; /**< Pending Status flag bitmap */
|
unsigned int pending_status; /**< Pending Status flag bitmap */
|
||||||
struct monitor_servers
|
struct monitor_servers *next; /**< The next server in the list */
|
||||||
*next; /**< The next server in the list */
|
|
||||||
} MONITOR_SERVERS;
|
} MONITOR_SERVERS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 */
|
||||||
char *user; /*< Monitor username */
|
char *user; /*< Monitor username */
|
||||||
char *password; /*< Monitor password */
|
char *password; /*< Monitor password */
|
||||||
@ -182,10 +184,12 @@ typedef struct monitor {
|
|||||||
monitor_state_t state; /**< The state of the monitor */
|
monitor_state_t state; /**< The state of the monitor */
|
||||||
int connect_timeout; /**< Connect timeout in seconds for mysql_real_connect */
|
int connect_timeout; /**< Connect timeout in seconds for mysql_real_connect */
|
||||||
int read_timeout; /**< Timeout in seconds to read from the server.
|
int read_timeout; /**< Timeout in seconds to read from the server.
|
||||||
* There are retries and the total effective timeout value is three times the option value.
|
* There are retries and the total effective timeout
|
||||||
|
* value is three times the option value.
|
||||||
*/
|
*/
|
||||||
int write_timeout; /**< Timeout in seconds for each attempt to write to the server.
|
int write_timeout; /**< Timeout in seconds for each attempt to write to the server.
|
||||||
* There are retries and the total effective timeout value is two times the option value.
|
* There are retries and the total effective timeout value is
|
||||||
|
* two times the option value.
|
||||||
*/
|
*/
|
||||||
MONITOR_OBJECT *module; /**< The "monitor object" */
|
MONITOR_OBJECT *module; /**< The "monitor object" */
|
||||||
void *handle; /**< Handle returned from startMonitor */
|
void *handle; /**< Handle returned from startMonitor */
|
||||||
|
|||||||
Reference in New Issue
Block a user