Galeramon formatting changes
Fixed indentation, bracket alignment and other minor things.
This commit is contained in:
@ -55,7 +55,7 @@ MODULE_INFO info = {
|
|||||||
"A Galera cluster monitor"
|
"A Galera cluster 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 *);
|
||||||
static MONITOR_SERVERS *get_candidate_master(MONITOR*);
|
static MONITOR_SERVERS *get_candidate_master(MONITOR*);
|
||||||
@ -87,8 +87,7 @@ version()
|
|||||||
void
|
void
|
||||||
ModuleInit()
|
ModuleInit()
|
||||||
{
|
{
|
||||||
LOGIF(LM, (skygw_log_write(
|
LOGIF(LM, (skygw_log_write(LOGFILE_MESSAGE,
|
||||||
LOGFILE_MESSAGE,
|
|
||||||
"Initialise the MySQL Galera Monitor module %s.\n",
|
"Initialise the MySQL Galera Monitor module %s.\n",
|
||||||
version_str)));
|
version_str)));
|
||||||
}
|
}
|
||||||
@ -115,20 +114,22 @@ 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 = arg;
|
MONITOR* mon = arg;
|
||||||
GALERA_MONITOR *handle = mon->handle;
|
GALERA_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)
|
||||||
{
|
{
|
||||||
handle->shutdown = 0;
|
handle->shutdown = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ((handle = (GALERA_MONITOR *)malloc(sizeof(GALERA_MONITOR))) == NULL)
|
if ((handle = (GALERA_MONITOR *) malloc(sizeof(GALERA_MONITOR))) == NULL)
|
||||||
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
handle->shutdown = 0;
|
handle->shutdown = 0;
|
||||||
handle->id = MONITOR_DEFAULT_ID;
|
handle->id = MONITOR_DEFAULT_ID;
|
||||||
handle->disableMasterFailback = 0;
|
handle->disableMasterFailback = 0;
|
||||||
@ -137,22 +138,30 @@ startMonitor(void *arg,void* opt)
|
|||||||
handle->master = NULL;
|
handle->master = NULL;
|
||||||
handle->script = NULL;
|
handle->script = NULL;
|
||||||
handle->use_priority = false;
|
handle->use_priority = false;
|
||||||
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, "disable_master_failback"))
|
||||||
{
|
{
|
||||||
if(!strcmp(params->name,"disable_master_failback"))
|
|
||||||
handle->disableMasterFailback = config_truth_value(params->value);
|
handle->disableMasterFailback = config_truth_value(params->value);
|
||||||
else if(!strcmp(params->name,"available_when_donor"))
|
}
|
||||||
|
else if (!strcmp(params->name, "available_when_donor"))
|
||||||
|
{
|
||||||
handle->availableWhenDonor = config_truth_value(params->value);
|
handle->availableWhenDonor = config_truth_value(params->value);
|
||||||
else if(!strcmp(params->name,"disable_master_role_setting"))
|
}
|
||||||
|
else if (!strcmp(params->name, "disable_master_role_setting"))
|
||||||
|
{
|
||||||
handle->disableMasterRoleSetting = config_truth_value(params->value);
|
handle->disableMasterRoleSetting = config_truth_value(params->value);
|
||||||
else if(!strcmp(params->name,"use_priority"))
|
}
|
||||||
|
else if (!strcmp(params->name, "use_priority"))
|
||||||
|
{
|
||||||
handle->use_priority = config_truth_value(params->value);
|
handle->use_priority = config_truth_value(params->value);
|
||||||
else if(!strcmp(params->name,"script"))
|
}
|
||||||
|
else if (!strcmp(params->name, "script"))
|
||||||
{
|
{
|
||||||
if (externcmd_can_execute(params->value))
|
if (externcmd_can_execute(params->value))
|
||||||
{
|
{
|
||||||
@ -164,29 +173,34 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,11 +212,11 @@ startMonitor(void *arg,void* opt)
|
|||||||
static void
|
static void
|
||||||
stopMonitor(void *arg)
|
stopMonitor(void *arg)
|
||||||
{
|
{
|
||||||
MONITOR* mon = (MONITOR*)arg;
|
MONITOR* mon = (MONITOR*) arg;
|
||||||
GALERA_MONITOR *handle = (GALERA_MONITOR *)mon->handle;
|
GALERA_MONITOR *handle = (GALERA_MONITOR *) mon->handle;
|
||||||
|
|
||||||
handle->shutdown = 1;
|
handle->shutdown = 1;
|
||||||
thread_wait((void *)handle->tid);
|
thread_wait((void *) handle->tid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -214,10 +228,10 @@ GALERA_MONITOR *handle = (GALERA_MONITOR *)mon->handle;
|
|||||||
static void
|
static void
|
||||||
diagnostics(DCB *dcb, void *arg)
|
diagnostics(DCB *dcb, void *arg)
|
||||||
{
|
{
|
||||||
MONITOR* mon = (MONITOR*)arg;
|
MONITOR* mon = (MONITOR*) arg;
|
||||||
GALERA_MONITOR *handle = (GALERA_MONITOR *)mon->handle;
|
GALERA_MONITOR *handle = (GALERA_MONITOR *) mon->handle;
|
||||||
MONITOR_SERVERS *db;
|
MONITOR_SERVERS *db;
|
||||||
char *sep;
|
char *sep;
|
||||||
|
|
||||||
switch (handle->status)
|
switch (handle->status)
|
||||||
{
|
{
|
||||||
@ -232,13 +246,13 @@ 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,"\tMaster Failback:\t%s\n", (handle->disableMasterFailback == 1) ? "off" : "on");
|
dcb_printf(dcb, "\tMaster Failback:\t%s\n", (handle->disableMasterFailback == 1) ? "off" : "on");
|
||||||
dcb_printf(dcb,"\tAvailable when Donor:\t%s\n", (handle->availableWhenDonor == 1) ? "on" : "off");
|
dcb_printf(dcb, "\tAvailable when Donor:\t%s\n", (handle->availableWhenDonor == 1) ? "on" : "off");
|
||||||
dcb_printf(dcb,"\tMaster Role Setting Disabled:\t%s\n", (handle->disableMasterRoleSetting == 1) ? "on" : "off");
|
dcb_printf(dcb, "\tMaster Role Setting Disabled:\t%s\n", (handle->disableMasterRoleSetting == 1) ? "on" : "off");
|
||||||
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;
|
||||||
@ -261,12 +275,12 @@ char *sep;
|
|||||||
static void
|
static void
|
||||||
monitorDatabase(MONITOR *mon, MONITOR_SERVERS *database)
|
monitorDatabase(MONITOR *mon, MONITOR_SERVERS *database)
|
||||||
{
|
{
|
||||||
GALERA_MONITOR* handle = (GALERA_MONITOR*)mon->handle;
|
GALERA_MONITOR* handle = (GALERA_MONITOR*) mon->handle;
|
||||||
MYSQL_ROW row;
|
MYSQL_ROW row;
|
||||||
MYSQL_RES *result,*result2;
|
MYSQL_RES *result, *result2;
|
||||||
int isjoined = 0;
|
int isjoined = 0;
|
||||||
unsigned long int server_version = 0;
|
unsigned long int server_version = 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))
|
||||||
@ -309,7 +323,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);
|
||||||
@ -319,11 +333,11 @@ char *server_string;
|
|||||||
if (mysql_query(database->con, "SHOW STATUS LIKE 'wsrep_local_state'") == 0
|
if (mysql_query(database->con, "SHOW STATUS LIKE 'wsrep_local_state'") == 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 'wsrep_local_state'\". Expected 2 columns."
|
skygw_log_write(LE, "Error: Unexpected result for \"SHOW STATUS LIKE 'wsrep_local_state'\". Expected 2 columns."
|
||||||
" MySQL Version: %s",version_str);
|
" MySQL Version: %s", version_str);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -333,16 +347,17 @@ char *server_string;
|
|||||||
isjoined = 1;
|
isjoined = 1;
|
||||||
|
|
||||||
/* Check if the node is a donor and is using xtrabackup, in this case it can stay alive */
|
/* Check if the node is a donor and is using xtrabackup, in this case it can stay alive */
|
||||||
else if (strcmp(row[1], "2") == 0 && handle->availableWhenDonor == 1) {
|
else if (strcmp(row[1], "2") == 0 && handle->availableWhenDonor == 1)
|
||||||
|
{
|
||||||
if (mysql_query(database->con, "SHOW VARIABLES LIKE 'wsrep_sst_method'") == 0
|
if (mysql_query(database->con, "SHOW VARIABLES LIKE 'wsrep_sst_method'") == 0
|
||||||
&& (result2 = mysql_store_result(database->con)) != NULL)
|
&& (result2 = 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);
|
||||||
mysql_free_result(result2);
|
mysql_free_result(result2);
|
||||||
skygw_log_write(LE,"Error: Unexpected result for \"SHOW VARIABLES LIKE 'wsrep_sst_method'\". Expected 2 columns."
|
skygw_log_write(LE, "Error: Unexpected result for \"SHOW VARIABLES LIKE 'wsrep_sst_method'\". Expected 2 columns."
|
||||||
" MySQL Version: %s",version_str);
|
" MySQL Version: %s", version_str);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while ((row = mysql_fetch_row(result2)))
|
while ((row = mysql_fetch_row(result2)))
|
||||||
@ -363,11 +378,11 @@ char *server_string;
|
|||||||
{
|
{
|
||||||
long local_index = -1;
|
long local_index = -1;
|
||||||
|
|
||||||
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 'wsrep_local_index'\". Expected 2 columns."
|
skygw_log_write(LE, "Error: Unexpected result for \"SHOW STATUS LIKE 'wsrep_local_index'\". Expected 2 columns."
|
||||||
" MySQL Version: %s",version_str);
|
" MySQL Version: %s", version_str);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -385,9 +400,13 @@ char *server_string;
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isjoined)
|
if (isjoined)
|
||||||
|
{
|
||||||
server_set_status(database->server, SERVER_JOINED);
|
server_set_status(database->server, SERVER_JOINED);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
server_clear_status(database->server, SERVER_JOINED);
|
server_clear_status(database->server, SERVER_JOINED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -398,24 +417,23 @@ char *server_string;
|
|||||||
static void
|
static void
|
||||||
monitorMain(void *arg)
|
monitorMain(void *arg)
|
||||||
{
|
{
|
||||||
MONITOR* mon = (MONITOR*)arg;
|
MONITOR* mon = (MONITOR*) arg;
|
||||||
GALERA_MONITOR *handle;
|
GALERA_MONITOR *handle;
|
||||||
MONITOR_SERVERS *ptr;
|
MONITOR_SERVERS *ptr;
|
||||||
size_t nrounds = 0;
|
size_t nrounds = 0;
|
||||||
MONITOR_SERVERS *candidate_master = NULL;
|
MONITOR_SERVERS *candidate_master = NULL;
|
||||||
int master_stickiness;
|
int master_stickiness;
|
||||||
int is_cluster=0;
|
int is_cluster = 0;
|
||||||
int log_no_members = 1;
|
int log_no_members = 1;
|
||||||
monitor_event_t evtype;
|
monitor_event_t evtype;
|
||||||
|
|
||||||
spinlock_acquire(&mon->lock);
|
spinlock_acquire(&mon->lock);
|
||||||
handle = (GALERA_MONITOR *)mon->handle;
|
handle = (GALERA_MONITOR *) mon->handle;
|
||||||
spinlock_release(&mon->lock);
|
spinlock_release(&mon->lock);
|
||||||
master_stickiness = handle->disableMasterFailback;
|
master_stickiness = handle->disableMasterFailback;
|
||||||
if (mysql_thread_init())
|
if (mysql_thread_init())
|
||||||
{
|
{
|
||||||
LOGIF(LE, (skygw_log_write_flush(
|
LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,
|
||||||
LOGFILE_ERROR,
|
|
||||||
"Fatal : mysql_thread_init failed in monitor "
|
"Fatal : mysql_thread_init failed in monitor "
|
||||||
"module. Exiting.\n")));
|
"module. Exiting.\n")));
|
||||||
return;
|
return;
|
||||||
@ -440,7 +458,7 @@ monitor_event_t evtype;
|
|||||||
* round.
|
* round.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (nrounds != 0 && ((nrounds*MON_BASE_INTERVAL_MS)%mon->interval) >= MON_BASE_INTERVAL_MS)
|
if (nrounds != 0 && ((nrounds * MON_BASE_INTERVAL_MS) % mon->interval) >= MON_BASE_INTERVAL_MS)
|
||||||
{
|
{
|
||||||
nrounds += 1;
|
nrounds += 1;
|
||||||
continue;
|
continue;
|
||||||
@ -449,7 +467,7 @@ monitor_event_t evtype;
|
|||||||
nrounds += 1;
|
nrounds += 1;
|
||||||
|
|
||||||
/* reset cluster members counter */
|
/* reset cluster members counter */
|
||||||
is_cluster=0;
|
is_cluster = 0;
|
||||||
|
|
||||||
ptr = mon->databases;
|
ptr = mon->databases;
|
||||||
|
|
||||||
@ -460,7 +478,8 @@ monitor_event_t evtype;
|
|||||||
monitorDatabase(mon, ptr);
|
monitorDatabase(mon, ptr);
|
||||||
|
|
||||||
/* clear bits for non member nodes */
|
/* clear bits for non member nodes */
|
||||||
if ( ! SERVER_IN_MAINT(ptr->server) && (! SERVER_IS_JOINED(ptr->server))) {
|
if (!SERVER_IN_MAINT(ptr->server) && (!SERVER_IS_JOINED(ptr->server)))
|
||||||
|
{
|
||||||
ptr->server->depth = -1;
|
ptr->server->depth = -1;
|
||||||
|
|
||||||
/* clear M/S status */
|
/* clear M/S status */
|
||||||
@ -474,8 +493,7 @@ monitor_event_t evtype;
|
|||||||
/* Log server status change */
|
/* Log server status change */
|
||||||
if (mon_status_changed(ptr))
|
if (mon_status_changed(ptr))
|
||||||
{
|
{
|
||||||
LOGIF(LD, (skygw_log_write_flush(
|
LOGIF(LD, (skygw_log_write_flush(LOGFILE_DEBUG,
|
||||||
LOGFILE_DEBUG,
|
|
||||||
"Backend server %s:%d state : %s",
|
"Backend server %s:%d state : %s",
|
||||||
ptr->server->name,
|
ptr->server->name,
|
||||||
ptr->server->port,
|
ptr->server->port,
|
||||||
@ -515,38 +533,49 @@ monitor_event_t evtype;
|
|||||||
candidate_master = get_candidate_master(mon);
|
candidate_master = get_candidate_master(mon);
|
||||||
|
|
||||||
/* Select the master, based on master_stickiness */
|
/* Select the master, based on master_stickiness */
|
||||||
if (1 == handle->disableMasterRoleSetting) {
|
if (1 == handle->disableMasterRoleSetting)
|
||||||
|
{
|
||||||
handle->master = NULL;
|
handle->master = NULL;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
handle->master = set_cluster_master(handle->master, candidate_master, master_stickiness);
|
handle->master = set_cluster_master(handle->master, candidate_master, master_stickiness);
|
||||||
}
|
}
|
||||||
|
|
||||||
ptr = mon->databases;
|
ptr = mon->databases;
|
||||||
|
|
||||||
while (ptr) {
|
while (ptr)
|
||||||
if (!SERVER_IS_JOINED(ptr->server) || SERVER_IN_MAINT(ptr->server)) {
|
{
|
||||||
|
if (!SERVER_IS_JOINED(ptr->server) || SERVER_IN_MAINT(ptr->server))
|
||||||
|
{
|
||||||
ptr = ptr->next;
|
ptr = ptr->next;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (handle->master) {
|
if (handle->master)
|
||||||
if (ptr != handle->master) {
|
{
|
||||||
|
if (ptr != handle->master)
|
||||||
|
{
|
||||||
/* set the Slave role */
|
/* set the Slave role */
|
||||||
server_set_status(ptr->server, SERVER_SLAVE);
|
server_set_status(ptr->server, SERVER_SLAVE);
|
||||||
server_clear_status(ptr->server, SERVER_MASTER);
|
server_clear_status(ptr->server, SERVER_MASTER);
|
||||||
|
|
||||||
/* clear master stickiness */
|
/* clear master stickiness */
|
||||||
server_clear_status(ptr->server, SERVER_MASTER_STICKINESS);
|
server_clear_status(ptr->server, SERVER_MASTER_STICKINESS);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
/* set the Master role */
|
/* set the Master role */
|
||||||
server_set_status(handle->master->server, SERVER_MASTER);
|
server_set_status(handle->master->server, SERVER_MASTER);
|
||||||
server_clear_status(handle->master->server, SERVER_SLAVE);
|
server_clear_status(handle->master->server, SERVER_SLAVE);
|
||||||
|
|
||||||
if (candidate_master && handle->master->server->node_id != candidate_master->server->node_id) {
|
if (candidate_master && handle->master->server->node_id != candidate_master->server->node_id)
|
||||||
|
{
|
||||||
/* set master stickiness */
|
/* set master stickiness */
|
||||||
server_set_status(handle->master->server, SERVER_MASTER_STICKINESS);
|
server_set_status(handle->master->server, SERVER_MASTER_STICKINESS);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
/* clear master stickiness */
|
/* clear master stickiness */
|
||||||
server_clear_status(ptr->server, SERVER_MASTER_STICKINESS);
|
server_clear_status(ptr->server, SERVER_MASTER_STICKINESS);
|
||||||
}
|
}
|
||||||
@ -558,15 +587,17 @@ monitor_event_t evtype;
|
|||||||
ptr = ptr->next;
|
ptr = ptr->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_cluster == 0 && log_no_members) {
|
if (is_cluster == 0 && log_no_members)
|
||||||
LOGIF(LE, (skygw_log_write_flush(
|
{
|
||||||
LOGFILE_ERROR,
|
LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,
|
||||||
"Error: there are no cluster members")));
|
"Error: there are no cluster members")));
|
||||||
log_no_members = 0;
|
log_no_members = 0;
|
||||||
} else {
|
}
|
||||||
if (is_cluster > 0 && log_no_members == 0) {
|
else
|
||||||
LOGIF(LE, (skygw_log_write_flush(
|
{
|
||||||
LOGFILE_ERROR,
|
if (is_cluster > 0 && log_no_members == 0)
|
||||||
|
{
|
||||||
|
LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,
|
||||||
"Info: found cluster members")));
|
"Info: found cluster members")));
|
||||||
log_no_members = 1;
|
log_no_members = 1;
|
||||||
}
|
}
|
||||||
@ -575,22 +606,22 @@ monitor_event_t evtype;
|
|||||||
|
|
||||||
ptr = mon->databases;
|
ptr = mon->databases;
|
||||||
|
|
||||||
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(isGaleraEvent(evtype))
|
if (isGaleraEvent(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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -608,7 +639,8 @@ monitor_event_t evtype;
|
|||||||
* @param servers The monitored servers list
|
* @param servers The monitored servers list
|
||||||
* @return The candidate master on success, NULL on failure
|
* @return The candidate master on success, NULL on failure
|
||||||
*/
|
*/
|
||||||
static MONITOR_SERVERS *get_candidate_master(MONITOR* mon) {
|
static MONITOR_SERVERS *get_candidate_master(MONITOR* mon)
|
||||||
|
{
|
||||||
MONITOR_SERVERS *moitor_servers = mon->databases;
|
MONITOR_SERVERS *moitor_servers = mon->databases;
|
||||||
MONITOR_SERVERS *candidate_master = NULL;
|
MONITOR_SERVERS *candidate_master = NULL;
|
||||||
GALERA_MONITOR* handle = mon->handle;
|
GALERA_MONITOR* handle = mon->handle;
|
||||||
@ -617,26 +649,29 @@ static MONITOR_SERVERS *get_candidate_master(MONITOR* mon) {
|
|||||||
int currval;
|
int currval;
|
||||||
char* value;
|
char* value;
|
||||||
/* set min_id to the lowest value of moitor_servers->server->node_id */
|
/* set min_id to the lowest value of moitor_servers->server->node_id */
|
||||||
while(moitor_servers) {
|
while (moitor_servers)
|
||||||
if (!SERVER_IN_MAINT(moitor_servers->server) && SERVER_IS_JOINED(moitor_servers->server)) {
|
{
|
||||||
|
if (!SERVER_IN_MAINT(moitor_servers->server) && SERVER_IS_JOINED(moitor_servers->server))
|
||||||
|
{
|
||||||
|
|
||||||
moitor_servers->server->depth = 0;
|
moitor_servers->server->depth = 0;
|
||||||
|
|
||||||
if(handle->use_priority && (value = serverGetParameter(moitor_servers->server,"priority")) != NULL)
|
if (handle->use_priority && (value = serverGetParameter(moitor_servers->server, "priority")) != NULL)
|
||||||
{
|
{
|
||||||
currval = atoi(value);
|
currval = atoi(value);
|
||||||
if(currval < minval && currval > 0)
|
if (currval < minval && currval > 0)
|
||||||
{
|
{
|
||||||
minval = currval;
|
minval = currval;
|
||||||
candidate_master = moitor_servers;
|
candidate_master = moitor_servers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(moitor_servers->server->node_id >= 0 &&
|
else if (moitor_servers->server->node_id >= 0 &&
|
||||||
(!handle->use_priority || /** Server priority disabled*/
|
(!handle->use_priority || /** Server priority disabled*/
|
||||||
candidate_master == NULL || /** No candidate chosen */
|
candidate_master == NULL || /** No candidate chosen */
|
||||||
serverGetParameter(candidate_master->server,"priority") == NULL)) /** Candidate has no priority */
|
serverGetParameter(candidate_master->server, "priority") == NULL)) /** Candidate has no priority */
|
||||||
|
{
|
||||||
|
if (min_id < 0 || moitor_servers->server->node_id < min_id)
|
||||||
{
|
{
|
||||||
if (min_id < 0 || moitor_servers->server->node_id < min_id) {
|
|
||||||
min_id = moitor_servers->server->node_id;
|
min_id = moitor_servers->server->node_id;
|
||||||
candidate_master = moitor_servers;
|
candidate_master = moitor_servers;
|
||||||
}
|
}
|
||||||
@ -647,6 +682,7 @@ static MONITOR_SERVERS *get_candidate_master(MONITOR* mon) {
|
|||||||
|
|
||||||
return candidate_master;
|
return candidate_master;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set the master server in the cluster
|
* set the master server in the cluster
|
||||||
*
|
*
|
||||||
@ -661,23 +697,31 @@ static MONITOR_SERVERS *get_candidate_master(MONITOR* mon) {
|
|||||||
* @param candidate_master The candidate master server accordingly to the selection rule
|
* @param candidate_master The candidate master server accordingly to the selection rule
|
||||||
* @return The master node pointer (could be NULL)
|
* @return The master node pointer (could be NULL)
|
||||||
*/
|
*/
|
||||||
static MONITOR_SERVERS *set_cluster_master(MONITOR_SERVERS *current_master, MONITOR_SERVERS *candidate_master, int master_stickiness) {
|
static MONITOR_SERVERS *set_cluster_master(MONITOR_SERVERS *current_master, MONITOR_SERVERS *candidate_master, int master_stickiness)
|
||||||
|
{
|
||||||
/*
|
/*
|
||||||
* if current master is not set or master_stickiness is not enable
|
* if current master is not set or master_stickiness is not enable
|
||||||
* just return candidate_master.
|
* just return candidate_master.
|
||||||
*/
|
*/
|
||||||
if (current_master == NULL || master_stickiness == 0) {
|
if (current_master == NULL || master_stickiness == 0)
|
||||||
|
{
|
||||||
return candidate_master;
|
return candidate_master;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
/*
|
/*
|
||||||
* if current_master is still a cluster member use it
|
* if current_master is still a cluster member use it
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
if (SERVER_IS_JOINED(current_master->server) && (! SERVER_IN_MAINT(current_master->server))) {
|
if (SERVER_IS_JOINED(current_master->server) && (!SERVER_IN_MAINT(current_master->server)))
|
||||||
|
{
|
||||||
return current_master;
|
return current_master;
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
return candidate_master;
|
return candidate_master;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -694,7 +738,7 @@ static MONITOR_SERVERS *set_cluster_master(MONITOR_SERVERS *current_master, MONI
|
|||||||
static void
|
static void
|
||||||
disableMasterFailback(void *arg, int disable)
|
disableMasterFailback(void *arg, int disable)
|
||||||
{
|
{
|
||||||
GALERA_MONITOR *handle = (GALERA_MONITOR *)arg;
|
GALERA_MONITOR *handle = (GALERA_MONITOR *) arg;
|
||||||
memcpy(&handle->disableMasterFailback, &disable, sizeof(int));
|
memcpy(&handle->disableMasterFailback, &disable, sizeof(int));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -710,7 +754,7 @@ GALERA_MONITOR *handle = (GALERA_MONITOR *)arg;
|
|||||||
static void
|
static void
|
||||||
availableWhenDonor(void *arg, int disable)
|
availableWhenDonor(void *arg, int disable)
|
||||||
{
|
{
|
||||||
GALERA_MONITOR *handle = (GALERA_MONITOR *)arg;
|
GALERA_MONITOR *handle = (GALERA_MONITOR *) arg;
|
||||||
memcpy(&handle->availableWhenDonor, &disable, sizeof(int));
|
memcpy(&handle->availableWhenDonor, &disable, sizeof(int));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -735,6 +779,7 @@ static monitor_event_t galera_events[] = {
|
|||||||
NEW_DONOR_EVENT,
|
NEW_DONOR_EVENT,
|
||||||
MAX_MONITOR_EVENT
|
MAX_MONITOR_EVENT
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the Galera monitor is monitoring this event type.
|
* Check if the Galera monitor is monitoring this event type.
|
||||||
* @param event Event to check
|
* @param event Event to check
|
||||||
@ -743,10 +788,12 @@ static monitor_event_t galera_events[] = {
|
|||||||
bool isGaleraEvent(monitor_event_t event)
|
bool isGaleraEvent(monitor_event_t event)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for(i = 0;galera_events[i] != MAX_MONITOR_EVENT;i++)
|
for (i = 0; galera_events[i] != MAX_MONITOR_EVENT; i++)
|
||||||
|
{
|
||||||
|
if (event == galera_events[i])
|
||||||
{
|
{
|
||||||
if(event == galera_events[i])
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user