From 03badb9b7bd1caf97fb4cc1621f6ed22a5a91305 Mon Sep 17 00:00:00 2001 From: counterpoint Date: Fri, 24 Apr 2015 15:35:10 +0100 Subject: [PATCH 1/2] Modifications to galera monitor to control whether selection of master is wanted. --- .gitignore | 1 + .../Getting-Started/Configuration-Guide.md | 12 +++++-- server/core/config.c | 2 ++ server/modules/monitor/galera_mon.c | 31 +++++++++++++------ server/modules/monitor/mysqlmon.h | 4 ++- .../routing/schemarouter/schemarouter.c | 20 +++++------- .../routing/schemarouter/shardrouter.c | 21 +++++-------- 7 files changed, 53 insertions(+), 38 deletions(-) diff --git a/.gitignore b/.gitignore index c761d00c4..7fe302bd3 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,4 @@ depend.mk # Vi swap files .*.swp +/build/ \ No newline at end of file diff --git a/Documentation/Getting-Started/Configuration-Guide.md b/Documentation/Getting-Started/Configuration-Guide.md index 8b3fdc301..9bf75aa2f 100644 --- a/Documentation/Getting-Started/Configuration-Guide.md +++ b/Documentation/Getting-Started/Configuration-Guide.md @@ -440,6 +440,7 @@ backend_write_timeout=2 # galeramon specific options disable_master_failback=0 available_when_donor=0 +disable_master_role_setting=0 ``` #### `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. +#### `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` This option, with default value of `3` sets the monitor connect timeout to backends. @@ -1367,11 +1375,11 @@ Example: ``` [Galera Listener] type=listener -address=192.1681.3.33 +address=192.168.3.33 port=4408 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. diff --git a/server/core/config.c b/server/core/config.c index aef540e9c..c063958da 100644 --- a/server/core/config.c +++ b/server/core/config.c @@ -43,6 +43,7 @@ * 20/02/15 Markus Mäkelä Added connection_timeout parameter for services * 05/03/15 Massimiliano Pinto Added notification_feedback support * 20/04/15 Guillaume Lefranc Added available_when_donor parameter + * 22/04/15 Martin Brampton Added disable_master_role_setting parameter * * @endverbatim */ @@ -1895,6 +1896,7 @@ static char *monitor_params[] = "backend_read_timeout", "backend_write_timeout", "available_when_donor", + "disable_master_role_setting", NULL }; /** diff --git a/server/modules/monitor/galera_mon.c b/server/modules/monitor/galera_mon.c index ee93eb3bf..b5309d9fb 100644 --- a/server/modules/monitor/galera_mon.c +++ b/server/modules/monitor/galera_mon.c @@ -160,6 +160,7 @@ CONFIG_PARAMETER* params = (CONFIG_PARAMETER*)opt; handle->interval = MONITOR_INTERVAL; handle->disableMasterFailback = 0; handle->availableWhenDonor = 0; + handle->disableMasterRoleSetting = 0; handle->master = NULL; handle->connect_timeout=DEFAULT_CONNECT_TIMEOUT; handle->read_timeout=DEFAULT_READ_TIMEOUT; @@ -172,8 +173,10 @@ CONFIG_PARAMETER* params = (CONFIG_PARAMETER*)opt; { if(!strcmp(params->name,"disable_master_failback")) 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); + else if(!strcmp(params->name,"disable_master_role_setting")) + handle->disableMasterRoleSetting = config_truth_value(params->value); params = params->next; } @@ -294,6 +297,7 @@ char *sep; 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,"\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,"\tRead Timeout:\t\t%i seconds\n", handle->read_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 */ - /* 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); /* 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; - while (ptr && handle->master) { + while (ptr) { if (!SERVER_IS_JOINED(ptr->server) || SERVER_IN_MAINT(ptr->server)) { ptr = ptr->next; continue; } - if (ptr != handle->master) { + if (handle->master) { + if (ptr != handle->master) { /* set the Slave role */ server_set_status(ptr->server, SERVER_SLAVE); server_clear_status(ptr->server, SERVER_MASTER); - /* clear master stickyness */ + /* clear master stickiness */ server_clear_status(ptr->server, SERVER_MASTER_STICKINESS); - } else { + } else { /* set the Master role */ server_set_status(handle->master->server, SERVER_MASTER); server_clear_status(handle->master->server, SERVER_SLAVE); 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); } else { - /* clear master stickyness */ + /* clear master stickiness */ server_clear_status(ptr->server, SERVER_MASTER_STICKINESS); } - } + } + } is_cluster++; diff --git a/server/modules/monitor/mysqlmon.h b/server/modules/monitor/mysqlmon.h index f3deb56f8..11de7e0f4 100644 --- a/server/modules/monitor/mysqlmon.h +++ b/server/modules/monitor/mysqlmon.h @@ -35,7 +35,8 @@ * 28/08/14 Massimiliano Pinto Addition of detectStaleMaster * 30/10/14 Massimiliano Pinto Addition of disableMasterFailback * 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 */ @@ -70,6 +71,7 @@ typedef struct { int detectStaleMaster; /**< Monitor flag for MySQL replication Stale Master detection */ int disableMasterFailback; /**< Monitor flag for Galera Cluster Master failback */ 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 *databases; /**< Linked list of servers to monitor */ int connect_timeout; /**< Connect timeout in seconds for mysql_real_connect */ diff --git a/server/modules/routing/schemarouter/schemarouter.c b/server/modules/routing/schemarouter/schemarouter.c index 6852f9d14..f9c44ac4e 100644 --- a/server/modules/routing/schemarouter/schemarouter.c +++ b/server/modules/routing/schemarouter/schemarouter.c @@ -243,24 +243,23 @@ static int hashcmpfun( /** * Convert a length encoded string into a C 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 */ -char* get_lenenc_str(void* data, int* len) +char* get_lenenc_str(void* data) { unsigned char* ptr = (unsigned char*)data; char* rval; - long size, offset; + uintptr_t size; + long offset; - if(data == NULL || len == NULL) + if(data == NULL) { - *len = -1; return NULL; } if(*ptr < 251) { - size = *ptr; + size = (uintptr_t)*ptr; offset = 1; } else @@ -268,7 +267,6 @@ char* get_lenenc_str(void* data, int* len) switch(*(ptr)) { case 0xfb: - *len = 1; return NULL; case 0xfc: size = *(ptr + 1) + (*(ptr + 2) << 8); @@ -280,8 +278,8 @@ char* get_lenenc_str(void* data, int* len) break; case 0xfe: size = *ptr + ((*(ptr + 2) << 8)) + (*(ptr + 3) << 16) + - (*(ptr + 4) << 24) + (*(ptr + 5) << 32) + (*(ptr + 6) << 40) + - (*(ptr + 7) << 48) + (*(ptr + 8) << 56); + (*(ptr + 4) << 24) + ((uintptr_t)*(ptr + 5) << 32) + ((uintptr_t)*(ptr + 6) << 40) + + ((uintptr_t)*(ptr + 7) << 48) + ((uintptr_t)*(ptr + 8) << 56); offset = 8; break; default: @@ -297,7 +295,6 @@ char* get_lenenc_str(void* data, int* len) memset(rval + size,0,1); } - *len = size + offset; 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 packetlen = payloadlen + 4; - int len = 0; - char* data = get_lenenc_str(ptr+4,&len); + char* data = get_lenenc_str(ptr+4); if(data) { diff --git a/server/modules/routing/schemarouter/shardrouter.c b/server/modules/routing/schemarouter/shardrouter.c index a3c9da3c4..b9e480c67 100644 --- a/server/modules/routing/schemarouter/shardrouter.c +++ b/server/modules/routing/schemarouter/shardrouter.c @@ -262,25 +262,23 @@ hashcmpfun( /** * Convert a length encoded string into a C 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 */ -char* get_lenenc_str(void* data, int* len) +char* get_lenenc_str(void* data) { unsigned char* ptr = (unsigned char*)data; char* rval; - long size, offset; + uintptr_t size; + long offset; - if(data == NULL || len == NULL) + if(data == NULL) { - if(len) - *len = -1; return NULL; } if(*ptr < 251) { - size = *ptr; + size = (uintptr_t)*ptr; offset = 1; } else @@ -288,7 +286,6 @@ char* get_lenenc_str(void* data, int* len) switch(*(ptr)) { case 0xfb: - *len = 1; return NULL; case 0xfc: size = *(ptr + 1) + (*(ptr + 2) << 8); @@ -300,8 +297,8 @@ char* get_lenenc_str(void* data, int* len) break; case 0xfe: size = *ptr + ((*(ptr + 2) << 8)) + (*(ptr + 3) << 16) + - (*(ptr + 4) << 24) + ((long)*(ptr + 5) << 32) + ((long)*(ptr + 6) << 40) + - ((long)*(ptr + 7) << 48) + ((long)*(ptr + 8) << 56); + (*(ptr + 4) << 24) + ((uintptr_t)*(ptr + 5) << 32) + ((uintptr_t)*(ptr + 6) << 40) + + ((uintptr_t)*(ptr + 7) << 48) + ((uintptr_t)*(ptr + 8) << 56); offset = 8; break; default: @@ -317,7 +314,6 @@ char* get_lenenc_str(void* data, int* len) memset(rval + size,0,1); } - *len = size + offset; 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 packetlen = payloadlen + 4; - int len = 0; - char* data = get_lenenc_str(ptr+4,&len); + char* data = get_lenenc_str(ptr+4); if(data) { From 9d9ebc5f67c211d361645055b122cfaaabfc011f Mon Sep 17 00:00:00 2001 From: counterpoint Date: Tue, 5 May 2015 11:07:23 +0100 Subject: [PATCH 2/2] Correct date in revision history, add to revision history for disableMasterRoleSetting. --- server/modules/monitor/galera_mon.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/modules/monitor/galera_mon.c b/server/modules/monitor/galera_mon.c index b5309d9fb..ec9e46a61 100644 --- a/server/modules/monitor/galera_mon.c +++ b/server/modules/monitor/galera_mon.c @@ -32,7 +32,8 @@ * 24/06/14 Massimiliano Pinto Added depth level 0 for each node * 30/10/14 Massimiliano Pinto Added disableMasterFailback feature * 10/11/14 Massimiliano Pinto Added setNetworkTimeout for connect,read,write - * 20/05/15 Guillaume Lefranc Added availableWhenDonor feature + * 20/04/15 Guillaume Lefranc Added availableWhenDonor feature + * 22/04/15 Martin Brampton Addition of disableMasterRoleSetting * * @endverbatim */