Ndbclustermon formatting changes
Fixed indentation, bracket alignment and other minor things.
This commit is contained in:
@ -44,7 +44,7 @@ MODULE_INFO info = {
|
|||||||
"A MySQL cluster SQL node monitor"
|
"A MySQL cluster SQL node monitor"
|
||||||
};
|
};
|
||||||
|
|
||||||
static void *startMonitor(void *,void*);
|
static void *startMonitor(void *, void*);
|
||||||
static void stopMonitor(void *);
|
static void stopMonitor(void *);
|
||||||
static void diagnostics(DCB *, void *);
|
static void diagnostics(DCB *, void *);
|
||||||
bool isNdbEvent(monitor_event_t event);
|
bool isNdbEvent(monitor_event_t event);
|
||||||
@ -101,12 +101,12 @@ GetModuleObject()
|
|||||||
* @return A handle to use when interacting with the monitor
|
* @return A handle to use when interacting with the monitor
|
||||||
*/
|
*/
|
||||||
static void *
|
static void *
|
||||||
startMonitor(void *arg,void* opt)
|
startMonitor(void *arg, void* opt)
|
||||||
{
|
{
|
||||||
MONITOR* mon = (MONITOR*)arg;
|
MONITOR* mon = (MONITOR*) arg;
|
||||||
MYSQL_MONITOR *handle = mon->handle;
|
MYSQL_MONITOR *handle = mon->handle;
|
||||||
CONFIG_PARAMETER* params = (CONFIG_PARAMETER*)opt;
|
CONFIG_PARAMETER* params = (CONFIG_PARAMETER*) opt;
|
||||||
bool have_events = false,script_error = false;
|
bool have_events = false, script_error = false;
|
||||||
|
|
||||||
if (handle != NULL)
|
if (handle != NULL)
|
||||||
{
|
{
|
||||||
@ -114,18 +114,20 @@ startMonitor(void *arg,void* opt)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ((handle = (MYSQL_MONITOR *)malloc(sizeof(MYSQL_MONITOR))) == NULL)
|
if ((handle = (MYSQL_MONITOR *) malloc(sizeof(MYSQL_MONITOR))) == NULL)
|
||||||
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
handle->shutdown = 0;
|
handle->shutdown = 0;
|
||||||
handle->id = MONITOR_DEFAULT_ID;
|
handle->id = MONITOR_DEFAULT_ID;
|
||||||
handle->script = NULL;
|
handle->script = NULL;
|
||||||
handle->master = NULL;
|
handle->master = NULL;
|
||||||
memset(handle->events,false,sizeof(handle->events));
|
memset(handle->events, false, sizeof(handle->events));
|
||||||
spinlock_init(&handle->lock);
|
spinlock_init(&handle->lock);
|
||||||
}
|
}
|
||||||
while(params)
|
while (params)
|
||||||
{
|
{
|
||||||
if(!strcmp(params->name,"script"))
|
if (!strcmp(params->name, "script"))
|
||||||
{
|
{
|
||||||
if (externcmd_can_execute(params->value))
|
if (externcmd_can_execute(params->value))
|
||||||
{
|
{
|
||||||
@ -137,28 +139,33 @@ startMonitor(void *arg,void* opt)
|
|||||||
script_error = true;
|
script_error = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(!strcmp(params->name,"events"))
|
else if (!strcmp(params->name, "events"))
|
||||||
|
{
|
||||||
|
if (mon_parse_event_string((bool*) &handle->events,
|
||||||
|
sizeof(handle->events), params->value) != 0)
|
||||||
{
|
{
|
||||||
if(mon_parse_event_string((bool*)&handle->events,sizeof(handle->events),params->value) != 0)
|
|
||||||
script_error = true;
|
script_error = true;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
have_events = true;
|
have_events = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
params = params->next;
|
params = params->next;
|
||||||
}
|
}
|
||||||
if(script_error)
|
if (script_error)
|
||||||
{
|
{
|
||||||
skygw_log_write(LE,"Error: Errors were found in the script configuration parameters "
|
skygw_log_write(LE, "Error: Errors were found in the script configuration parameters "
|
||||||
"for the monitor '%s'. The script will not be used.",mon->name);
|
"for the monitor '%s'. The script will not be used.", mon->name);
|
||||||
free(handle->script);
|
free(handle->script);
|
||||||
handle->script = NULL;
|
handle->script = NULL;
|
||||||
}
|
}
|
||||||
/** If no specific events are given, enable them all */
|
/** If no specific events are given, enable them all */
|
||||||
if(!have_events)
|
if (!have_events)
|
||||||
{
|
{
|
||||||
memset(handle->events,true,sizeof(handle->events));
|
memset(handle->events, true, sizeof(handle->events));
|
||||||
}
|
}
|
||||||
handle->tid = (THREAD)thread_start(monitorMain, mon);
|
handle->tid = (THREAD) thread_start(monitorMain, mon);
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,11 +177,11 @@ startMonitor(void *arg,void* opt)
|
|||||||
static void
|
static void
|
||||||
stopMonitor(void *arg)
|
stopMonitor(void *arg)
|
||||||
{
|
{
|
||||||
MONITOR* mon = (MONITOR*)arg;
|
MONITOR* mon = (MONITOR*) arg;
|
||||||
MYSQL_MONITOR *handle = (MYSQL_MONITOR *)mon->handle;
|
MYSQL_MONITOR *handle = (MYSQL_MONITOR *) mon->handle;
|
||||||
|
|
||||||
handle->shutdown = 1;
|
handle->shutdown = 1;
|
||||||
thread_wait((void *)handle->tid);
|
thread_wait((void *) handle->tid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -187,9 +194,9 @@ static void
|
|||||||
diagnostics(DCB *dcb, void *arg)
|
diagnostics(DCB *dcb, void *arg)
|
||||||
{
|
{
|
||||||
MONITOR* mon = arg;
|
MONITOR* mon = arg;
|
||||||
MYSQL_MONITOR *handle = (MYSQL_MONITOR *)mon->handle;
|
MYSQL_MONITOR *handle = (MYSQL_MONITOR *) mon->handle;
|
||||||
MONITOR_SERVERS *db;
|
MONITOR_SERVERS *db;
|
||||||
char *sep;
|
char *sep;
|
||||||
|
|
||||||
switch (handle->status)
|
switch (handle->status)
|
||||||
{
|
{
|
||||||
@ -204,10 +211,10 @@ char *sep;
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
dcb_printf(dcb,"\tSampling interval:\t%lu milliseconds\n", mon->interval);
|
dcb_printf(dcb, "\tSampling interval:\t%lu milliseconds\n", mon->interval);
|
||||||
dcb_printf(dcb,"\tConnect Timeout:\t%i seconds\n", mon->connect_timeout);
|
dcb_printf(dcb, "\tConnect Timeout:\t%i seconds\n", mon->connect_timeout);
|
||||||
dcb_printf(dcb,"\tRead Timeout:\t\t%i seconds\n", mon->read_timeout);
|
dcb_printf(dcb, "\tRead Timeout:\t\t%i seconds\n", mon->read_timeout);
|
||||||
dcb_printf(dcb,"\tWrite Timeout:\t\t%i seconds\n", mon->write_timeout);
|
dcb_printf(dcb, "\tWrite Timeout:\t\t%i seconds\n", mon->write_timeout);
|
||||||
dcb_printf(dcb, "\tMonitored servers: ");
|
dcb_printf(dcb, "\tMonitored servers: ");
|
||||||
|
|
||||||
db = mon->databases;
|
db = mon->databases;
|
||||||
@ -229,14 +236,16 @@ char *sep;
|
|||||||
static void
|
static void
|
||||||
monitorDatabase(MONITOR_SERVERS *database, char *defaultUser, char *defaultPasswd, MONITOR *mon)
|
monitorDatabase(MONITOR_SERVERS *database, char *defaultUser, char *defaultPasswd, MONITOR *mon)
|
||||||
{
|
{
|
||||||
MYSQL_ROW row;
|
MYSQL_ROW row;
|
||||||
MYSQL_RES *result;
|
MYSQL_RES *result;
|
||||||
int isjoined = 0;
|
int isjoined = 0;
|
||||||
char *server_string;
|
char *server_string;
|
||||||
|
|
||||||
/* Don't even probe server flagged as in maintenance */
|
/* Don't even probe server flagged as in maintenance */
|
||||||
if (SERVER_IN_MAINT(database->server))
|
if (SERVER_IN_MAINT(database->server))
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
connect_result_t rval = mon_connect_to_db(mon, database);
|
connect_result_t rval = mon_connect_to_db(mon, database);
|
||||||
if (rval != MONITOR_CONN_OK)
|
if (rval != MONITOR_CONN_OK)
|
||||||
@ -262,7 +271,7 @@ char *server_string;
|
|||||||
server_set_status(database->server, SERVER_RUNNING);
|
server_set_status(database->server, SERVER_RUNNING);
|
||||||
|
|
||||||
/* get server version string */
|
/* get server version string */
|
||||||
server_string = (char *)mysql_get_server_info(database->con);
|
server_string = (char *) mysql_get_server_info(database->con);
|
||||||
if (server_string)
|
if (server_string)
|
||||||
{
|
{
|
||||||
server_set_version_string(database->server, server_string);
|
server_set_version_string(database->server, server_string);
|
||||||
@ -272,11 +281,11 @@ char *server_string;
|
|||||||
if (mysql_query(database->con, "SHOW STATUS LIKE 'Ndb_number_of_ready_data_nodes'") == 0
|
if (mysql_query(database->con, "SHOW STATUS LIKE 'Ndb_number_of_ready_data_nodes'") == 0
|
||||||
&& (result = mysql_store_result(database->con)) != NULL)
|
&& (result = mysql_store_result(database->con)) != NULL)
|
||||||
{
|
{
|
||||||
if(mysql_field_count(database->con) < 2)
|
if (mysql_field_count(database->con) < 2)
|
||||||
{
|
{
|
||||||
mysql_free_result(result);
|
mysql_free_result(result);
|
||||||
skygw_log_write(LE,"Error: Unexpected result for \"SHOW STATUS LIKE 'Ndb_number_of_ready_data_nodes'\". Expected 2 columns."
|
skygw_log_write(LE, "Error: Unexpected result for \"SHOW STATUS LIKE 'Ndb_number_of_ready_data_nodes'\". Expected 2 columns."
|
||||||
" MySQL Version: %s",version_str);
|
" MySQL Version: %s", version_str);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,11 +301,11 @@ char *server_string;
|
|||||||
if (mysql_query(database->con, "SHOW STATUS LIKE 'Ndb_cluster_node_id'") == 0
|
if (mysql_query(database->con, "SHOW STATUS LIKE 'Ndb_cluster_node_id'") == 0
|
||||||
&& (result = mysql_store_result(database->con)) != NULL)
|
&& (result = mysql_store_result(database->con)) != NULL)
|
||||||
{
|
{
|
||||||
if(mysql_field_count(database->con) < 2)
|
if (mysql_field_count(database->con) < 2)
|
||||||
{
|
{
|
||||||
mysql_free_result(result);
|
mysql_free_result(result);
|
||||||
skygw_log_write(LE,"Error: Unexpected result for \"SHOW STATUS LIKE 'Ndb_cluster_node_id'\". Expected 2 columns."
|
skygw_log_write(LE, "Error: Unexpected result for \"SHOW STATUS LIKE 'Ndb_cluster_node_id'\". Expected 2 columns."
|
||||||
" MySQL Version: %s",version_str);
|
" MySQL Version: %s", version_str);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,10 +323,13 @@ char *server_string;
|
|||||||
mysql_free_result(result);
|
mysql_free_result(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isjoined) {
|
if (isjoined)
|
||||||
|
{
|
||||||
server_set_status(database->server, SERVER_NDB);
|
server_set_status(database->server, SERVER_NDB);
|
||||||
database->server->depth = 0;
|
database->server->depth = 0;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
server_clear_status(database->server, SERVER_NDB);
|
server_clear_status(database->server, SERVER_NDB);
|
||||||
database->server->depth = -1;
|
database->server->depth = -1;
|
||||||
}
|
}
|
||||||
@ -332,13 +344,13 @@ static void
|
|||||||
monitorMain(void *arg)
|
monitorMain(void *arg)
|
||||||
{
|
{
|
||||||
MONITOR* mon = arg;
|
MONITOR* mon = arg;
|
||||||
MYSQL_MONITOR *handle;
|
MYSQL_MONITOR *handle;
|
||||||
MONITOR_SERVERS *ptr;
|
MONITOR_SERVERS *ptr;
|
||||||
size_t nrounds = 0;
|
size_t nrounds = 0;
|
||||||
|
|
||||||
spinlock_acquire(&mon->lock);
|
spinlock_acquire(&mon->lock);
|
||||||
handle = (MYSQL_MONITOR *)mon->handle;
|
handle = (MYSQL_MONITOR *) mon->handle;
|
||||||
spinlock_release(&mon->lock);
|
spinlock_release(&mon->lock);
|
||||||
|
|
||||||
if (mysql_thread_init())
|
if (mysql_thread_init())
|
||||||
{
|
{
|
||||||
@ -369,7 +381,7 @@ spinlock_release(&mon->lock);
|
|||||||
* round.
|
* round.
|
||||||
*/
|
*/
|
||||||
if (nrounds != 0 &&
|
if (nrounds != 0 &&
|
||||||
((nrounds*MON_BASE_INTERVAL_MS)%mon->interval) >=
|
((nrounds * MON_BASE_INTERVAL_MS) % mon->interval) >=
|
||||||
MON_BASE_INTERVAL_MS)
|
MON_BASE_INTERVAL_MS)
|
||||||
{
|
{
|
||||||
nrounds += 1;
|
nrounds += 1;
|
||||||
@ -381,7 +393,7 @@ spinlock_release(&mon->lock);
|
|||||||
while (ptr)
|
while (ptr)
|
||||||
{
|
{
|
||||||
ptr->mon_prev_status = ptr->server->status;
|
ptr->mon_prev_status = ptr->server->status;
|
||||||
monitorDatabase(ptr, mon->user, mon->password,mon);
|
monitorDatabase(ptr, mon->user, mon->password, mon);
|
||||||
|
|
||||||
if (ptr->server->status != ptr->mon_prev_status ||
|
if (ptr->server->status != ptr->mon_prev_status ||
|
||||||
SERVER_IS_DOWN(ptr->server))
|
SERVER_IS_DOWN(ptr->server))
|
||||||
@ -400,21 +412,21 @@ spinlock_release(&mon->lock);
|
|||||||
ptr = mon->databases;
|
ptr = mon->databases;
|
||||||
monitor_event_t evtype;
|
monitor_event_t evtype;
|
||||||
|
|
||||||
while(ptr)
|
while (ptr)
|
||||||
{
|
{
|
||||||
/** Execute monitor script if a server state has changed */
|
/** Execute monitor script if a server state has changed */
|
||||||
if(mon_status_changed(ptr))
|
if (mon_status_changed(ptr))
|
||||||
{
|
{
|
||||||
evtype = mon_get_event_type(ptr);
|
evtype = mon_get_event_type(ptr);
|
||||||
if(isNdbEvent(evtype))
|
if (isNdbEvent(evtype))
|
||||||
{
|
{
|
||||||
skygw_log_write(LOGFILE_TRACE,"Server changed state: %s[%s:%u]: %s",
|
skygw_log_write(LOGFILE_TRACE, "Server changed state: %s[%s:%u]: %s",
|
||||||
ptr->server->unique_name,
|
ptr->server->unique_name,
|
||||||
ptr->server->name,ptr->server->port,
|
ptr->server->name, ptr->server->port,
|
||||||
mon_get_event_name(ptr));
|
mon_get_event_name(ptr));
|
||||||
if(handle->script && handle->events[evtype])
|
if (handle->script && handle->events[evtype])
|
||||||
{
|
{
|
||||||
monitor_launch_script(mon,ptr,handle->script);
|
monitor_launch_script(mon, ptr, handle->script);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -450,9 +462,9 @@ static monitor_event_t ndb_events[] = {
|
|||||||
bool isNdbEvent(monitor_event_t event)
|
bool isNdbEvent(monitor_event_t event)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for(i = 0;ndb_events[i] != MAX_MONITOR_EVENT;i++)
|
for (i = 0; ndb_events[i] != MAX_MONITOR_EVENT; i++)
|
||||||
{
|
{
|
||||||
if(event == ndb_events[i])
|
if (event == ndb_events[i])
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user