Reindent server/core/monitor.c
This commit is contained in:
@ -73,7 +73,7 @@ static SPINLOCK monLock = SPINLOCK_INIT;
|
||||
MONITOR *
|
||||
monitor_alloc(char *name, char *module)
|
||||
{
|
||||
MONITOR *mon;
|
||||
MONITOR *mon;
|
||||
|
||||
if ((mon = (MONITOR *)malloc(sizeof(MONITOR))) == NULL)
|
||||
{
|
||||
@ -116,21 +116,27 @@ MONITOR *mon;
|
||||
void
|
||||
monitor_free(MONITOR *mon)
|
||||
{
|
||||
MONITOR *ptr;
|
||||
MONITOR *ptr;
|
||||
|
||||
mon->module->stopMonitor(mon);
|
||||
mon->state = MONITOR_STATE_FREED;
|
||||
spinlock_acquire(&monLock);
|
||||
if (allMonitors == mon)
|
||||
{
|
||||
allMonitors = mon->next;
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr = allMonitors;
|
||||
while (ptr->next && ptr->next != mon)
|
||||
{
|
||||
ptr = ptr->next;
|
||||
}
|
||||
if (ptr->next)
|
||||
{
|
||||
ptr->next = mon->next;
|
||||
}
|
||||
}
|
||||
spinlock_release(&monLock);
|
||||
free_config_parameter(mon->parameters);
|
||||
free(mon->name);
|
||||
@ -177,7 +183,7 @@ void monitorStartAll()
|
||||
void
|
||||
monitorStop(MONITOR *monitor)
|
||||
{
|
||||
if(monitor->state != MONITOR_STATE_STOPPED)
|
||||
if (monitor->state != MONITOR_STATE_STOPPED)
|
||||
{
|
||||
monitor->state = MONITOR_STATE_STOPPING;
|
||||
monitor->module->stopMonitor(monitor);
|
||||
@ -191,7 +197,7 @@ monitorStop(MONITOR *monitor)
|
||||
void
|
||||
monitorStopAll()
|
||||
{
|
||||
MONITOR *ptr;
|
||||
MONITOR *ptr;
|
||||
|
||||
spinlock_acquire(&monLock);
|
||||
ptr = allMonitors;
|
||||
@ -216,7 +222,9 @@ monitorAddServer(MONITOR *mon, SERVER *server)
|
||||
MONITOR_SERVERS *ptr, *db;
|
||||
|
||||
if ((db = (MONITOR_SERVERS *)malloc(sizeof(MONITOR_SERVERS))) == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
db->server = server;
|
||||
db->con = NULL;
|
||||
db->next = NULL;
|
||||
@ -230,12 +238,16 @@ monitorAddServer(MONITOR *mon, SERVER *server)
|
||||
spinlock_acquire(&mon->lock);
|
||||
|
||||
if (mon->databases == NULL)
|
||||
{
|
||||
mon->databases = db;
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr = mon->databases;
|
||||
while (ptr->next != NULL)
|
||||
{
|
||||
ptr = ptr->next;
|
||||
}
|
||||
ptr->next = db;
|
||||
}
|
||||
spinlock_release(&mon->lock);
|
||||
@ -264,7 +276,7 @@ monitorAddUser(MONITOR *mon, char *user, char *passwd)
|
||||
void
|
||||
monitorShowAll(DCB *dcb)
|
||||
{
|
||||
MONITOR *ptr;
|
||||
MONITOR *ptr;
|
||||
|
||||
spinlock_acquire(&monLock);
|
||||
ptr = allMonitors;
|
||||
@ -273,7 +285,9 @@ MONITOR *ptr;
|
||||
dcb_printf(dcb, "Monitor: %p\n", ptr);
|
||||
dcb_printf(dcb, "\tName: %s\n", ptr->name);
|
||||
if (ptr->module->diagnostics)
|
||||
{
|
||||
ptr->module->diagnostics(dcb, ptr);
|
||||
}
|
||||
ptr = ptr->next;
|
||||
}
|
||||
spinlock_release(&monLock);
|
||||
@ -291,7 +305,9 @@ monitorShow(DCB *dcb, MONITOR *monitor)
|
||||
dcb_printf(dcb, "Monitor: %p\n", monitor);
|
||||
dcb_printf(dcb, "\tName: %s\n", monitor->name);
|
||||
if (monitor->module->diagnostics)
|
||||
{
|
||||
monitor->module->diagnostics(dcb, monitor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -302,7 +318,7 @@ monitorShow(DCB *dcb, MONITOR *monitor)
|
||||
void
|
||||
monitorList(DCB *dcb)
|
||||
{
|
||||
MONITOR *ptr;
|
||||
MONITOR *ptr;
|
||||
|
||||
spinlock_acquire(&monLock);
|
||||
ptr = allMonitors;
|
||||
@ -329,14 +345,16 @@ MONITOR *ptr;
|
||||
MONITOR *
|
||||
monitor_find(char *name)
|
||||
{
|
||||
MONITOR *ptr;
|
||||
MONITOR *ptr;
|
||||
|
||||
spinlock_acquire(&monLock);
|
||||
ptr = allMonitors;
|
||||
while (ptr)
|
||||
{
|
||||
if (!strcmp(ptr->name, name))
|
||||
{
|
||||
break;
|
||||
}
|
||||
ptr = ptr->next;
|
||||
}
|
||||
spinlock_release(&monLock);
|
||||
@ -350,7 +368,7 @@ MONITOR *ptr;
|
||||
* @param interval The sampling interval in milliseconds
|
||||
*/
|
||||
void
|
||||
monitorSetInterval (MONITOR *mon, unsigned long interval)
|
||||
monitorSetInterval(MONITOR *mon, unsigned long interval)
|
||||
{
|
||||
mon->interval = interval;
|
||||
}
|
||||
@ -369,13 +387,18 @@ monitorSetNetworkTimeout(MONITOR *mon, int type, int value) {
|
||||
int new_timeout = max_timeout -1;
|
||||
|
||||
if (new_timeout <= 0)
|
||||
{
|
||||
new_timeout = DEFAULT_CONNECT_TIMEOUT;
|
||||
}
|
||||
|
||||
switch(type) {
|
||||
case MONITOR_CONNECT_TIMEOUT:
|
||||
if (value < max_timeout) {
|
||||
if (value < max_timeout)
|
||||
{
|
||||
memcpy(&mon->connect_timeout, &value, sizeof(int));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(&mon->connect_timeout, &new_timeout, sizeof(int));
|
||||
MXS_WARNING("Monitor Connect Timeout %i is greater than monitor interval ~%i seconds"
|
||||
", lowering to %i seconds", value, max_timeout, new_timeout);
|
||||
@ -383,9 +406,12 @@ monitorSetNetworkTimeout(MONITOR *mon, int type, int value) {
|
||||
break;
|
||||
|
||||
case MONITOR_READ_TIMEOUT:
|
||||
if (value < max_timeout) {
|
||||
if (value < max_timeout)
|
||||
{
|
||||
memcpy(&mon->read_timeout, &value, sizeof(int));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(&mon->read_timeout, &new_timeout, sizeof(int));
|
||||
MXS_WARNING("Monitor Read Timeout %i is greater than monitor interval ~%i seconds"
|
||||
", lowering to %i seconds", value, max_timeout, new_timeout);
|
||||
@ -393,9 +419,12 @@ monitorSetNetworkTimeout(MONITOR *mon, int type, int value) {
|
||||
break;
|
||||
|
||||
case MONITOR_WRITE_TIMEOUT:
|
||||
if (value < max_timeout) {
|
||||
if (value < max_timeout)
|
||||
{
|
||||
memcpy(&mon->write_timeout, &value, sizeof(int));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(&mon->write_timeout, &new_timeout, sizeof(int));
|
||||
MXS_WARNING("Monitor Write Timeout %i is greater than monitor interval ~%i seconds"
|
||||
", lowering to %i seconds", value, max_timeout, new_timeout);
|
||||
@ -417,11 +446,11 @@ monitorSetNetworkTimeout(MONITOR *mon, int type, int value) {
|
||||
static RESULT_ROW *
|
||||
monitorRowCallback(RESULTSET *set, void *data)
|
||||
{
|
||||
int *rowno = (int *)data;
|
||||
int i = 0;;
|
||||
char buf[20];
|
||||
RESULT_ROW *row;
|
||||
MONITOR *ptr;
|
||||
int *rowno = (int *)data;
|
||||
int i = 0;;
|
||||
char buf[20];
|
||||
RESULT_ROW *row;
|
||||
MONITOR *ptr;
|
||||
|
||||
spinlock_acquire(&monLock);
|
||||
ptr = allMonitors;
|
||||
@ -453,11 +482,13 @@ MONITOR *ptr;
|
||||
RESULTSET *
|
||||
monitorGetList()
|
||||
{
|
||||
RESULTSET *set;
|
||||
int *data;
|
||||
RESULTSET *set;
|
||||
int *data;
|
||||
|
||||
if ((data = (int *)malloc(sizeof(int))) == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
*data = 0;
|
||||
if ((set = resultset_create(monitorRowCallback, data)) == NULL)
|
||||
{
|
||||
@ -489,7 +520,7 @@ bool check_monitor_permissions(MONITOR* monitor)
|
||||
user = monitor->user;
|
||||
dpasswd = decryptPassword(monitor->password);
|
||||
|
||||
if((mysql = mysql_init(NULL)) == NULL)
|
||||
if ((mysql = mysql_init(NULL)) == NULL)
|
||||
{
|
||||
MXS_ERROR("[%s] Error: MySQL connection initialization failed.", __FUNCTION__);
|
||||
free(dpasswd);
|
||||
@ -502,7 +533,7 @@ bool check_monitor_permissions(MONITOR* monitor)
|
||||
|
||||
/** Connect to the first server. This assumes all servers have identical
|
||||
* user permissions. */
|
||||
if(mysql_real_connect(mysql,server->name,user,dpasswd,NULL,server->port,NULL,0) == NULL)
|
||||
if (mysql_real_connect(mysql, server->name, user, dpasswd, NULL, server->port, NULL, 0) == NULL)
|
||||
{
|
||||
MXS_ERROR("%s: Failed to connect to server %s(%s:%d) when"
|
||||
" checking monitor user credentials and permissions.",
|
||||
@ -515,9 +546,9 @@ bool check_monitor_permissions(MONITOR* monitor)
|
||||
return false;
|
||||
}
|
||||
|
||||
if(mysql_query(mysql,"show slave status") != 0)
|
||||
if (mysql_query(mysql,"show slave status") != 0)
|
||||
{
|
||||
if(mysql_errno(mysql) == ER_SPECIFIC_ACCESS_DENIED_ERROR)
|
||||
if (mysql_errno(mysql) == ER_SPECIFIC_ACCESS_DENIED_ERROR)
|
||||
{
|
||||
MXS_ERROR("%s: User '%s' is missing REPLICATION CLIENT privileges. MySQL error message: %s",
|
||||
monitor->name,user,mysql_error(mysql));
|
||||
@ -531,7 +562,7 @@ bool check_monitor_permissions(MONITOR* monitor)
|
||||
}
|
||||
else
|
||||
{
|
||||
if((res = mysql_use_result(mysql)) == NULL)
|
||||
if ((res = mysql_use_result(mysql)) == NULL)
|
||||
{
|
||||
MXS_ERROR("%s: Result retrieval failed when checking for REPLICATION CLIENT permissions: %s",
|
||||
monitor->name,mysql_error(mysql));
|
||||
@ -600,13 +631,15 @@ monitor_clear_pending_status(MONITOR_SERVERS *ptr, int bit)
|
||||
monitor_event_t
|
||||
mon_get_event_type(MONITOR_SERVERS* node)
|
||||
{
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
DOWN_EVENT,
|
||||
UP_EVENT,
|
||||
LOSS_EVENT,
|
||||
NEW_EVENT,
|
||||
UNSUPPORTED_EVENT
|
||||
} general_event_type;
|
||||
|
||||
general_event_type event_type = UNSUPPORTED_EVENT;
|
||||
|
||||
unsigned int prev = node->mon_prev_status
|
||||
@ -700,7 +733,7 @@ mon_get_event_name(MONITOR_SERVERS* node)
|
||||
* @result monitor_event_t Monitor event corresponding to name
|
||||
*/
|
||||
monitor_event_t
|
||||
mon_name_to_event (const char *event_name)
|
||||
mon_name_to_event(const char *event_name)
|
||||
{
|
||||
monitor_event_t event;
|
||||
|
||||
|
||||
@ -73,7 +73,8 @@
|
||||
* unregisterServer is called to remove a server from the set of servers that need to be
|
||||
* monitored.
|
||||
*/
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
void *(*startMonitor)(void *, void*);
|
||||
void (*stopMonitor)(void *);
|
||||
void (*diagnostics)(DCB *, void *);
|
||||
@ -158,34 +159,37 @@ extern const monitor_def_t monitor_event_definitions[];
|
||||
/**
|
||||
* 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 */
|
||||
MYSQL *con; /**< The MySQL connection */
|
||||
bool log_version_err;
|
||||
int mon_err_count;
|
||||
unsigned int mon_prev_status;
|
||||
unsigned int pending_status; /**< Pending Status flag bitmap */
|
||||
struct monitor_servers
|
||||
*next; /**< The next server in the list */
|
||||
struct monitor_servers *next; /**< The next server in the list */
|
||||
} MONITOR_SERVERS;
|
||||
|
||||
/**
|
||||
* Representation of the running monitor.
|
||||
*/
|
||||
typedef struct monitor {
|
||||
typedef struct monitor
|
||||
{
|
||||
char *name; /**< The name of the monitor module */
|
||||
char* user; /*< Monitor username */
|
||||
char* password; /*< Monitor password */
|
||||
char *user; /*< Monitor username */
|
||||
char *password; /*< Monitor password */
|
||||
SPINLOCK lock;
|
||||
CONFIG_PARAMETER* parameters; /*< configuration parameters */
|
||||
MONITOR_SERVERS* databases; /*< List of databases the monitor monitors */
|
||||
monitor_state_t state; /**< The state of the monitor */
|
||||
int connect_timeout; /**< Connect timeout in seconds for mysql_real_connect */
|
||||
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.
|
||||
* 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" */
|
||||
void *handle; /**< Handle returned from startMonitor */
|
||||
|
||||
Reference in New Issue
Block a user