Modifications to galera monitor to control whether selection of master is wanted.

This commit is contained in:
counterpoint
2015-04-24 15:35:10 +01:00
parent 8bc004db26
commit 03badb9b7b
7 changed files with 53 additions and 38 deletions

1
.gitignore vendored
View File

@ -34,3 +34,4 @@ depend.mk
# Vi swap files # Vi swap files
.*.swp .*.swp
/build/

View File

@ -440,6 +440,7 @@ backend_write_timeout=2
# galeramon specific options # galeramon specific options
disable_master_failback=0 disable_master_failback=0
available_when_donor=0 available_when_donor=0
disable_master_role_setting=0
``` ```
#### `module` #### `module`
@ -510,6 +511,13 @@ This option if set to 1 will allow Galera monitor to keep a node in `Donor` stat
As xtrabackup is a non-locking SST method, a node in `Donor` status can still be considered in sync. This option is not enabled by default and should be used as the administrator's discretion. As xtrabackup is a non-locking SST method, a node in `Donor` status can still be considered in sync. This option is not enabled by default and should be used as the administrator's discretion.
#### `disable_master_role_setting`
This option if set to 1 will stop the Galera monitor from setting the status of
backend servers to master or slave. It is applicable when the Galera router is
being used to spread writes across multiple nodes, so that no server is to be
nominated as the master.
#### `backend_connect_timeout` #### `backend_connect_timeout`
This option, with default value of `3` sets the monitor connect timeout to backends. This option, with default value of `3` sets the monitor connect timeout to backends.
@ -1367,11 +1375,11 @@ Example:
``` ```
[Galera Listener] [Galera Listener]
type=listener type=listener
address=192.1681.3.33 address=192.168.3.33
port=4408 port=4408
socket=/servers/maxscale/galera.sock socket=/servers/maxscale/galera.sock
``` ```
TCP/IP Traffic must be permitted to 192.1681.3.33 port 4408 TCP/IP Traffic must be permitted to 192.168.3.33 port 4408
For Unix socket, the socket file path (example: `/servers/maxscale/galera.sock`) must be writable by the Unix user MaxScale runs as. For Unix socket, the socket file path (example: `/servers/maxscale/galera.sock`) must be writable by the Unix user MaxScale runs as.

View File

@ -43,6 +43,7 @@
* 20/02/15 Markus Mäkelä Added connection_timeout parameter for services * 20/02/15 Markus Mäkelä Added connection_timeout parameter for services
* 05/03/15 Massimiliano Pinto Added notification_feedback support * 05/03/15 Massimiliano Pinto Added notification_feedback support
* 20/04/15 Guillaume Lefranc Added available_when_donor parameter * 20/04/15 Guillaume Lefranc Added available_when_donor parameter
* 22/04/15 Martin Brampton Added disable_master_role_setting parameter
* *
* @endverbatim * @endverbatim
*/ */
@ -1895,6 +1896,7 @@ static char *monitor_params[] =
"backend_read_timeout", "backend_read_timeout",
"backend_write_timeout", "backend_write_timeout",
"available_when_donor", "available_when_donor",
"disable_master_role_setting",
NULL NULL
}; };
/** /**

View File

@ -160,6 +160,7 @@ CONFIG_PARAMETER* params = (CONFIG_PARAMETER*)opt;
handle->interval = MONITOR_INTERVAL; handle->interval = MONITOR_INTERVAL;
handle->disableMasterFailback = 0; handle->disableMasterFailback = 0;
handle->availableWhenDonor = 0; handle->availableWhenDonor = 0;
handle->disableMasterRoleSetting = 0;
handle->master = NULL; handle->master = NULL;
handle->connect_timeout=DEFAULT_CONNECT_TIMEOUT; handle->connect_timeout=DEFAULT_CONNECT_TIMEOUT;
handle->read_timeout=DEFAULT_READ_TIMEOUT; handle->read_timeout=DEFAULT_READ_TIMEOUT;
@ -172,8 +173,10 @@ CONFIG_PARAMETER* params = (CONFIG_PARAMETER*)opt;
{ {
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);
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"))
handle->disableMasterRoleSetting = config_truth_value(params->value);
params = params->next; params = params->next;
} }
@ -294,6 +297,7 @@ char *sep;
dcb_printf(dcb,"\tSampling interval:\t%lu milliseconds\n", handle->interval); dcb_printf(dcb,"\tSampling interval:\t%lu milliseconds\n", handle->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,"\tConnect Timeout:\t%i seconds\n", handle->connect_timeout); dcb_printf(dcb,"\tConnect Timeout:\t%i seconds\n", handle->connect_timeout);
dcb_printf(dcb,"\tRead Timeout:\t\t%i seconds\n", handle->read_timeout); dcb_printf(dcb,"\tRead Timeout:\t\t%i seconds\n", handle->read_timeout);
dcb_printf(dcb,"\tWrite Timeout:\t\t%i seconds\n", handle->write_timeout); dcb_printf(dcb,"\tWrite Timeout:\t\t%i seconds\n", handle->write_timeout);
@ -596,40 +600,47 @@ int log_no_members = 1;
* Decision depends on master_stickiness value set in configuration * Decision depends on master_stickiness value set in configuration
*/ */
/* get the candidate master, followinf MIN(node_id) rule */ /* get the candidate master, following MIN(node_id) rule */
candidate_master = get_candidate_master(handle->databases); candidate_master = get_candidate_master(handle->databases);
/* Select the master, based on master_stickiness */ /* Select the master, based on master_stickiness */
handle->master = set_cluster_master(handle->master, candidate_master, master_stickiness); if (1 == handle->disableMasterRoleSetting) {
handle->master = NULL;
}
else {
handle->master = set_cluster_master(handle->master, candidate_master, master_stickiness);
}
ptr = handle->databases; ptr = handle->databases;
while (ptr && handle->master) { 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 (ptr != handle->master) { if (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 stickyness */ /* 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 stickyness */ /* 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 stickyness */ /* clear master stickiness */
server_clear_status(ptr->server, SERVER_MASTER_STICKINESS); server_clear_status(ptr->server, SERVER_MASTER_STICKINESS);
} }
} }
}
is_cluster++; is_cluster++;

View File

@ -35,7 +35,8 @@
* 28/08/14 Massimiliano Pinto Addition of detectStaleMaster * 28/08/14 Massimiliano Pinto Addition of detectStaleMaster
* 30/10/14 Massimiliano Pinto Addition of disableMasterFailback * 30/10/14 Massimiliano Pinto Addition of disableMasterFailback
* 07/11/14 Massimiliano Pinto Addition of NetworkTimeout: connect, read, write * 07/11/14 Massimiliano Pinto Addition of NetworkTimeout: connect, read, write
* 20/05/15 Guillaume Lefranc Addition of availableWhenDonor * 20/04/15 Guillaume Lefranc Addition of availableWhenDonor
* 22/04/15 Martin Brampton Addition of disableMasterRoleSetting
* *
* @endverbatim * @endverbatim
*/ */
@ -70,6 +71,7 @@ typedef struct {
int detectStaleMaster; /**< Monitor flag for MySQL replication Stale Master detection */ int detectStaleMaster; /**< Monitor flag for MySQL replication Stale Master detection */
int disableMasterFailback; /**< Monitor flag for Galera Cluster Master failback */ int disableMasterFailback; /**< Monitor flag for Galera Cluster Master failback */
int availableWhenDonor; /**< Monitor flag for Galera Cluster Donor availability */ int availableWhenDonor; /**< Monitor flag for Galera Cluster Donor availability */
int disableMasterRoleSetting; /**< Monitor flag to disable setting master role */
MONITOR_SERVERS *master; /**< Master server for MySQL Master/Slave replication */ MONITOR_SERVERS *master; /**< Master server for MySQL Master/Slave replication */
MONITOR_SERVERS *databases; /**< Linked list of servers to monitor */ MONITOR_SERVERS *databases; /**< Linked list of servers to monitor */
int connect_timeout; /**< Connect timeout in seconds for mysql_real_connect */ int connect_timeout; /**< Connect timeout in seconds for mysql_real_connect */

View File

@ -243,24 +243,23 @@ static int hashcmpfun(
/** /**
* Convert a length encoded string into a C string. * Convert a length encoded string into a C string.
* @param data Pointer to the first byte of the string * @param data Pointer to the first byte of the string
* @param len Pointer to an integer where the length of the string will be stored. On errors this will be set to -1.
* @return Pointer to the newly allocated string or NULL if the value is NULL or an error occurred * @return Pointer to the newly allocated string or NULL if the value is NULL or an error occurred
*/ */
char* get_lenenc_str(void* data, int* len) char* get_lenenc_str(void* data)
{ {
unsigned char* ptr = (unsigned char*)data; unsigned char* ptr = (unsigned char*)data;
char* rval; char* rval;
long size, offset; uintptr_t size;
long offset;
if(data == NULL || len == NULL) if(data == NULL)
{ {
*len = -1;
return NULL; return NULL;
} }
if(*ptr < 251) if(*ptr < 251)
{ {
size = *ptr; size = (uintptr_t)*ptr;
offset = 1; offset = 1;
} }
else else
@ -268,7 +267,6 @@ char* get_lenenc_str(void* data, int* len)
switch(*(ptr)) switch(*(ptr))
{ {
case 0xfb: case 0xfb:
*len = 1;
return NULL; return NULL;
case 0xfc: case 0xfc:
size = *(ptr + 1) + (*(ptr + 2) << 8); size = *(ptr + 1) + (*(ptr + 2) << 8);
@ -280,8 +278,8 @@ char* get_lenenc_str(void* data, int* len)
break; break;
case 0xfe: case 0xfe:
size = *ptr + ((*(ptr + 2) << 8)) + (*(ptr + 3) << 16) + size = *ptr + ((*(ptr + 2) << 8)) + (*(ptr + 3) << 16) +
(*(ptr + 4) << 24) + (*(ptr + 5) << 32) + (*(ptr + 6) << 40) + (*(ptr + 4) << 24) + ((uintptr_t)*(ptr + 5) << 32) + ((uintptr_t)*(ptr + 6) << 40) +
(*(ptr + 7) << 48) + (*(ptr + 8) << 56); ((uintptr_t)*(ptr + 7) << 48) + ((uintptr_t)*(ptr + 8) << 56);
offset = 8; offset = 8;
break; break;
default: default:
@ -297,7 +295,6 @@ char* get_lenenc_str(void* data, int* len)
memset(rval + size,0,1); memset(rval + size,0,1);
} }
*len = size + offset;
return rval; return rval;
} }
@ -360,8 +357,7 @@ bool parse_showdb_response(ROUTER_CLIENT_SES* rses, backend_ref_t* bref, GWBUF**
{ {
int payloadlen = gw_mysql_get_byte3(ptr); int payloadlen = gw_mysql_get_byte3(ptr);
int packetlen = payloadlen + 4; int packetlen = payloadlen + 4;
int len = 0; char* data = get_lenenc_str(ptr+4);
char* data = get_lenenc_str(ptr+4,&len);
if(data) if(data)
{ {

View File

@ -262,25 +262,23 @@ hashcmpfun(
/** /**
* Convert a length encoded string into a C string. * Convert a length encoded string into a C string.
* @param data Pointer to the first byte of the string * @param data Pointer to the first byte of the string
* @param len Pointer to an integer where the length of the string will be stored. On errors this will be set to -1.
* @return Pointer to the newly allocated string or NULL if the value is NULL or an error occurred * @return Pointer to the newly allocated string or NULL if the value is NULL or an error occurred
*/ */
char* get_lenenc_str(void* data, int* len) char* get_lenenc_str(void* data)
{ {
unsigned char* ptr = (unsigned char*)data; unsigned char* ptr = (unsigned char*)data;
char* rval; char* rval;
long size, offset; uintptr_t size;
long offset;
if(data == NULL || len == NULL) if(data == NULL)
{ {
if(len)
*len = -1;
return NULL; return NULL;
} }
if(*ptr < 251) if(*ptr < 251)
{ {
size = *ptr; size = (uintptr_t)*ptr;
offset = 1; offset = 1;
} }
else else
@ -288,7 +286,6 @@ char* get_lenenc_str(void* data, int* len)
switch(*(ptr)) switch(*(ptr))
{ {
case 0xfb: case 0xfb:
*len = 1;
return NULL; return NULL;
case 0xfc: case 0xfc:
size = *(ptr + 1) + (*(ptr + 2) << 8); size = *(ptr + 1) + (*(ptr + 2) << 8);
@ -300,8 +297,8 @@ char* get_lenenc_str(void* data, int* len)
break; break;
case 0xfe: case 0xfe:
size = *ptr + ((*(ptr + 2) << 8)) + (*(ptr + 3) << 16) + size = *ptr + ((*(ptr + 2) << 8)) + (*(ptr + 3) << 16) +
(*(ptr + 4) << 24) + ((long)*(ptr + 5) << 32) + ((long)*(ptr + 6) << 40) + (*(ptr + 4) << 24) + ((uintptr_t)*(ptr + 5) << 32) + ((uintptr_t)*(ptr + 6) << 40) +
((long)*(ptr + 7) << 48) + ((long)*(ptr + 8) << 56); ((uintptr_t)*(ptr + 7) << 48) + ((uintptr_t)*(ptr + 8) << 56);
offset = 8; offset = 8;
break; break;
default: default:
@ -317,7 +314,6 @@ char* get_lenenc_str(void* data, int* len)
memset(rval + size,0,1); memset(rval + size,0,1);
} }
*len = size + offset;
return rval; return rval;
} }
@ -360,8 +356,7 @@ parse_mapping_response(ROUTER_CLIENT_SES* rses, char* target, GWBUF* buf)
{ {
int payloadlen = gw_mysql_get_byte3(ptr); int payloadlen = gw_mysql_get_byte3(ptr);
int packetlen = payloadlen + 4; int packetlen = payloadlen + 4;
int len = 0; char* data = get_lenenc_str(ptr+4);
char* data = get_lenenc_str(ptr+4,&len);
if(data) if(data)
{ {