MariaDB 10 Replication support

MariaDB 10 Replication support
This commit is contained in:
MassimilianoPinto
2014-05-26 10:09:01 +02:00
parent a819887b07
commit cde204db47
3 changed files with 69 additions and 18 deletions

View File

@ -22,8 +22,9 @@
* @verbatim * @verbatim
* Revision History * Revision History
* *
* Date Who Description * Date Who Description
* 18/06/13 Mark Riddoch Initial implementation * 18/06/13 Mark Riddoch Initial implementation
* 20/05/14 Massimiliano Pinto Addition of server_string
* *
* @endverbatim * @endverbatim
*/ */
@ -67,6 +68,7 @@ SERVER *server;
server->nextdb = NULL; server->nextdb = NULL;
server->monuser = NULL; server->monuser = NULL;
server->monpw = NULL; server->monpw = NULL;
server->server_string = NULL;
spinlock_acquire(&server_spin); spinlock_acquire(&server_spin);
server->next = allServers; server->next = allServers;
@ -109,6 +111,8 @@ SERVER *ptr;
/* Clean up session and free the memory */ /* Clean up session and free the memory */
free(server->name); free(server->name);
free(server->protocol); free(server->protocol);
if (server->server_string)
free(server->server_string);
free(server); free(server);
return 1; return 1;
} }
@ -197,6 +201,8 @@ char *stat;
free(stat); free(stat);
dcb_printf(dcb, "\tProtocol: %s\n", ptr->protocol); dcb_printf(dcb, "\tProtocol: %s\n", ptr->protocol);
dcb_printf(dcb, "\tPort: %d\n", ptr->port); dcb_printf(dcb, "\tPort: %d\n", ptr->port);
if (ptr->server_string)
dcb_printf(dcb, "\tServer Version:\t\t%s\n", ptr->server_string);
dcb_printf(dcb, "\tNumber of connections: %d\n", ptr->stats.n_connections); dcb_printf(dcb, "\tNumber of connections: %d\n", ptr->stats.n_connections);
dcb_printf(dcb, "\tCurrent no. of connections: %d\n", ptr->stats.n_current); dcb_printf(dcb, "\tCurrent no. of connections: %d\n", ptr->stats.n_current);
ptr = ptr->next; ptr = ptr->next;
@ -222,6 +228,8 @@ char *stat;
free(stat); free(stat);
dcb_printf(dcb, "\tProtocol: %s\n", server->protocol); dcb_printf(dcb, "\tProtocol: %s\n", server->protocol);
dcb_printf(dcb, "\tPort: %d\n", server->port); dcb_printf(dcb, "\tPort: %d\n", server->port);
if (server->server_string)
dcb_printf(dcb, "\tServer Version:\t\t%s\n", server->server_string);
dcb_printf(dcb, "\tNumber of connections: %d\n", server->stats.n_connections); dcb_printf(dcb, "\tNumber of connections: %d\n", server->stats.n_connections);
dcb_printf(dcb, "\tCurrent No. of connections: %d\n", server->stats.n_current); dcb_printf(dcb, "\tCurrent No. of connections: %d\n", server->stats.n_current);
} }

View File

@ -27,10 +27,11 @@
* @verbatim * @verbatim
* Revision History * Revision History
* *
* Date Who Description * Date Who Description
* 14/06/13 Mark Riddoch Initial implementation * 14/06/13 Mark Riddoch Initial implementation
* 21/06/13 Mark Riddoch Addition of server status flags * 21/06/13 Mark Riddoch Addition of server status flags
* 22/07/13 Mark Riddoch Addition of JOINED status for Galera * 22/07/13 Mark Riddoch Addition of JOINED status for Galera
* 20/05/14 Massimiliano Pinto Addition of server_string field
* *
* @endverbatim * @endverbatim
*/ */
@ -60,6 +61,7 @@ typedef struct server {
SERVER_STATS stats; /**< The server statistics */ SERVER_STATS stats; /**< The server statistics */
struct server *next; /**< Next server */ struct server *next; /**< Next server */
struct server *nextdb; /**< Next server in list attached to a service */ struct server *nextdb; /**< Next server in list attached to a service */
char *server_string; /**< Server version string, i.e. MySQL server version */
} SERVER; } SERVER;
/** /**

View File

@ -22,12 +22,14 @@
* @verbatim * @verbatim
* Revision History * Revision History
* *
* Date Who Description * Date Who Description
* 08/07/13 Mark Riddoch Initial implementation * 08/07/13 Mark Riddoch Initial implementation
* 11/07/13 Mark Riddoch Addition of code to check replication * 11/07/13 Mark Riddoch Addition of code to check replication
* status * status
* 25/07/13 Mark Riddoch Addition of decrypt for passwords and * 25/07/13 Mark Riddoch Addition of decrypt for passwords and
* diagnostic interface * diagnostic interface
* 20/05/14 Massimiliano Pinto Addition of support for MariadDB multimaster replication setup.
* New server field version_string is updated.
* *
* @endverbatim * @endverbatim
*/ */
@ -290,6 +292,8 @@ MYSQL_RES *result;
int num_fields; int num_fields;
int ismaster = 0, isslave = 0; int ismaster = 0, isslave = 0;
char *uname = defaultUser, *passwd = defaultPasswd; char *uname = defaultUser, *passwd = defaultPasswd;
unsigned long int server_version = 0;
char *server_string;
if (database->server->monuser != NULL) if (database->server->monuser != NULL)
{ {
@ -321,6 +325,15 @@ char *uname = defaultUser, *passwd = defaultPasswd;
/* If we get this far then we have a working connection */ /* If we get this far then we have a working connection */
server_set_status(database->server, SERVER_RUNNING); server_set_status(database->server, SERVER_RUNNING);
/* get server version from current server */
server_version = mysql_get_server_version(database->con);
/* get server version string */
server_string = (char *)mysql_get_server_info(database->con);
if (server_string) {
database->server->server_string = strdup(server_string);
}
/* Check SHOW SLAVE HOSTS - if we get rows then we are a master */ /* Check SHOW SLAVE HOSTS - if we get rows then we are a master */
if (mysql_query(database->con, "SHOW SLAVE HOSTS")) if (mysql_query(database->con, "SHOW SLAVE HOSTS"))
{ {
@ -342,17 +355,45 @@ char *uname = defaultUser, *passwd = defaultPasswd;
/* Check if the Slave_SQL_Running and Slave_IO_Running status is /* Check if the Slave_SQL_Running and Slave_IO_Running status is
* set to Yes * set to Yes
*/ */
if (mysql_query(database->con, "SHOW SLAVE STATUS") == 0
&& (result = mysql_store_result(database->con)) != NULL) /* Check first for MariaDB 10.x.x and get status for multimaster replication */
{ if (server_version >= 100000) {
num_fields = mysql_num_fields(result);
while ((row = mysql_fetch_row(result))) if (mysql_query(database->con, "SHOW ALL SLAVES STATUS") == 0
&& (result = mysql_store_result(database->con)) != NULL)
{ {
if (strncmp(row[10], "Yes", 3) == 0 if (strncmp(row[10], "Yes", 3) == 0
&& strncmp(row[11], "Yes", 3) == 0) && strncmp(row[11], "Yes", 3) == 0)
int i = 0;
num_fields = mysql_num_fields(result);
while ((row = mysql_fetch_row(result)))
{
if (strncmp(row[12], "Yes", 3) == 0
&& strncmp(row[13], "Yes", 3) == 0) {
isslave += 1;
}
i++;
}
mysql_free_result(result);
if (isslave == i)
isslave = 1; isslave = 1;
else
isslave = 0;
}
} else {
if (mysql_query(database->con, "SHOW SLAVE STATUS") == 0
&& (result = mysql_store_result(database->con)) != NULL)
{
num_fields = mysql_num_fields(result);
while ((row = mysql_fetch_row(result)))
{
if (strncmp(row[10], "Yes", 3) == 0
&& strncmp(row[11], "Yes", 3) == 0)
isslave = 1;
}
mysql_free_result(result);
} }
mysql_free_result(result);
} }
if (ismaster) if (ismaster)