Merge branch 'develop' into mon_script_test

This commit is contained in:
Markus Makela
2015-04-06 16:15:37 +03:00
21 changed files with 620 additions and 129 deletions

View File

@ -374,9 +374,14 @@ int query_len;
else if (strcasecmp(word, "@master_binlog_checksum") == 0)
{
word = strtok_r(NULL, sep, &brkb);
if (word && (strcasecmp(word, "@@global.biglog_checksum'") == 0))
if (word && (strcasecmp(word, "'none'") == 0))
slave->nocrc = 1;
else if (word && (strcasecmp(word, "@@global.binlog_checksum") == 0))
slave->nocrc = !router->master_chksum;
else
slave->nocrc = 0;
free(query_text);
return blr_slave_replay(router, slave, router->saved_master.chksum1);
}
@ -1196,7 +1201,7 @@ uint32_t chksum;
LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG,
"%s: COM_BINLOG_DUMP: binlog name '%s', length %d, "
"from position %d.", router->service->name,
"from position %lu.", router->service->name,
slave->binlogfile, binlognamelen,
slave->binlog_pos)));
@ -1524,7 +1529,7 @@ if (hkheartbeat - beat1 > 1) LOGIF(LE, (skygw_log_write(
if (slave->stats.n_caughtup == 1)
{
LOGIF(LM, (skygw_log_write(LOGFILE_MESSAGE,
"%s: Slave %s is up to date %s, %u.",
"%s: Slave %s is up to date %s, %lu.",
router->service->name,
slave->dcb->remote,
slave->binlogfile, slave->binlog_pos)));
@ -1532,7 +1537,7 @@ if (hkheartbeat - beat1 > 1) LOGIF(LE, (skygw_log_write(
else if ((slave->stats.n_caughtup % 50) == 0)
{
LOGIF(LM, (skygw_log_write(LOGFILE_MESSAGE,
"%s: Slave %s is up to date %s, %u.",
"%s: Slave %s is up to date %s, %lu.",
router->service->name,
slave->dcb->remote,
slave->binlogfile, slave->binlog_pos)));
@ -1556,7 +1561,7 @@ if (hkheartbeat - beat1 > 1) LOGIF(LE, (skygw_log_write(
* we ignore these issues during the rotate processing.
*/
LOGIF(LE, (skygw_log_write(LOGFILE_ERROR,
"Slave reached end of file for binlog file %s at %u "
"Slave reached end of file for binlog file %s at %lu "
"which is not the file currently being downloaded. "
"Master binlog is %s, %lu. This may be caused by a "
"previous failure of the master.",
@ -1956,7 +1961,7 @@ blr_slave_disconnect_server(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, int se
{
/* server_id found */
server_found = 1;
LOGIF(LT, (skygw_log_write(LOGFILE_TRACE, "%s: Slave %s, server id %d, disconnected by %s@%s",
LOGIF(LM, (skygw_log_write(LOGFILE_MESSAGE, "%s: Slave %s, server id %d, disconnected by %s@%s",
router->service->name,
sptr->dcb->remote,
server_id,
@ -2048,7 +2053,7 @@ blr_slave_disconnect_all(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave)
return 1;
}
LOGIF(LT, (skygw_log_write(LOGFILE_TRACE, "%s: Slave %s, server id %d, disconnected by %s@%s",
LOGIF(LM, (skygw_log_write(LOGFILE_MESSAGE, "%s: Slave %s, server id %d, disconnected by %s@%s",
router->service->name,
sptr->dcb->remote, sptr->serverid, slave->dcb->user, slave->dcb->remote)));

View File

@ -692,7 +692,15 @@ createInstance(SERVICE *service, char **options)
/** Calculate number of servers */
server = service->dbref;
nservers = 0;
conf = service->svc_config_param;
if((config_get_param(conf,"auth_all_servers")) == NULL)
{
skygw_log_write(LOGFILE_MESSAGE,"Schemarouter: Authentication data is fetched from all servers. To disable this "
"add 'auth_all_servers=0' to the service.");
service->users_from_all = true;
}
while (server != NULL)
{
nservers++;
@ -803,14 +811,16 @@ static void* newSession(
MySQLProtocol* protocol = session->client->protocol;
MYSQL_session* data = session->data;
bool using_db = false;
bool have_db = false;
memset(db,0,MYSQL_DATABASE_MAXLEN+1);
spinlock_acquire(&protocol->protocol_lock);
/* To enable connecting directly to a sharded database we first need
* to disable it for the client DCB's protocol so that we can connect to them*/
if(protocol->client_capabilities & GW_MYSQL_CAPABILITIES_CONNECT_WITH_DB)
if(protocol->client_capabilities & GW_MYSQL_CAPABILITIES_CONNECT_WITH_DB &&
(have_db = strnlen(data->db,MYSQL_DATABASE_MAXLEN) > 0))
{
protocol->client_capabilities &= ~GW_MYSQL_CAPABILITIES_CONNECT_WITH_DB;
@ -820,7 +830,12 @@ static void* newSession(
skygw_log_write(LOGFILE_TRACE,"schemarouter: Client logging in directly to a database '%s', "
"postponing until databases have been mapped.",db);
}
if(!have_db)
{
LOGIF(LT,(skygw_log_write(LT,"schemarouter: Client'%s' connecting with empty database.",data->user)));
}
spinlock_release(&protocol->protocol_lock);
client_rses = (ROUTER_CLIENT_SES *)calloc(1, sizeof(ROUTER_CLIENT_SES));
@ -1004,7 +1019,7 @@ static void closeSession(
backend_ref_t* backend_ref;
LOGIF(LD, (skygw_log_write(LOGFILE_DEBUG,
"%lu [RWSplit:closeSession]",
"%lu [schemarouter:closeSession]",
pthread_self())));
/**
@ -1854,8 +1869,11 @@ static int routeQuery(
* Find out whether the query should be routed to single server or to
* all of them.
*/
if (packet_type == MYSQL_COM_INIT_DB)
skygw_query_op_t op = query_classifier_get_operation(querybuf);
if (packet_type == MYSQL_COM_INIT_DB ||
op == QUERY_OP_CHANGE_DB)
{
if (!(change_successful = change_current_db(inst, router_cli_ses, querybuf)))
{
@ -1882,7 +1900,8 @@ static int routeQuery(
router_cli_ses->rses_transaction_active,
querybuf->hint);
if (packet_type == MYSQL_COM_INIT_DB)
if (packet_type == MYSQL_COM_INIT_DB ||
op == QUERY_OP_CHANGE_DB)
{
route_target = TARGET_UNDEFINED;
tname = hashtable_fetch(router_cli_ses->dbhash,router_cli_ses->rses_mysql_session->db);
@ -2329,15 +2348,20 @@ static void clientReply (
if((target = hashtable_fetch(router_cli_ses->dbhash,
router_cli_ses->connect_db)) == NULL)
{
/** Unknown database, hang up on the client*/
skygw_log_write_flush(LOGFILE_TRACE,"schemarouter: Connecting to a non-existent database '%s'",
router_cli_ses->connect_db);
router_cli_ses->rses_closed = true;
char errmsg[128 + MYSQL_DATABASE_MAXLEN+1];
sprintf(errmsg,"Unknown database '%s'",router_cli_ses->connect_db);
GWBUF* errbuff = modutil_create_mysql_err_msg(1,0,1049,"42000",errmsg);
router_cli_ses->rses_client_dcb->func.write(router_cli_ses->rses_client_dcb,errbuff);
if(router_cli_ses->queue)
{
while((router_cli_ses->queue = gwbuf_consume(
router_cli_ses->queue,gwbuf_length(router_cli_ses->queue))));
}
rses_end_locked_router_action(router_cli_ses);
router_cli_ses->rses_client_dcb->func.hangup(router_cli_ses->rses_client_dcb);
return;
}
@ -4106,10 +4130,53 @@ static bool change_current_db(
plen = gw_mysql_get_byte3(packet) - 1;
/** Copy database name from MySQL packet to session */
if(query_classifier_get_operation(buf) == QUERY_OP_CHANGE_DB)
{
char* query = modutil_get_SQL(buf);
char *saved,*tok;
memcpy(rses->rses_mysql_session->db,packet + 5,plen);
memset(rses->rses_mysql_session->db + plen,0,1);
tok = strtok_r(query," ;",&saved);
if(tok == NULL || strcasecmp(tok,"use") != 0)
{
skygw_log_write(LOGFILE_ERROR,"Schemarouter: Malformed chage database packet.");
free(query);
message_len = 25 + MYSQL_DATABASE_MAXLEN;
fail_str = calloc(1, message_len+1);
snprintf(fail_str,
message_len,
"Unknown database '%s'",
(char*)rses->rses_mysql_session->db);
rses->rses_mysql_session->db[0] = '\0';
succp = false;
goto reply_error;
}
tok = strtok_r(NULL," ;",&saved);
if(tok == NULL)
{
skygw_log_write(LOGFILE_ERROR,"Schemarouter: Malformed chage database packet.");
free(query);
message_len = 25 + MYSQL_DATABASE_MAXLEN;
fail_str = calloc(1, message_len+1);
snprintf(fail_str,
message_len,
"Unknown database '%s'",
(char*)rses->rses_mysql_session->db);
rses->rses_mysql_session->db[0] = '\0';
succp = false;
goto reply_error;
}
strncpy(rses->rses_mysql_session->db,tok,MYSQL_DATABASE_MAXLEN);
free(query);
query = NULL;
}
else
{
memcpy(rses->rses_mysql_session->db,packet + 5,plen);
memset(rses->rses_mysql_session->db + plen,0,1);
}
skygw_log_write(LOGFILE_TRACE,"schemarouter: INIT_DB with database '%s'",
rses->rses_mysql_session->db);
/**

View File

@ -122,7 +122,8 @@ int main(int argc, char** argv)
sprintf(query,"CREATE DATABASE %s",databases[i]);
if(mysql_real_query(server,query,strlen(query)))
{
fprintf(stderr, "Failed to create table in %d: %s.\n",
fprintf(stderr, "Failed to create database '%s' in %d: %s.\n",
databases[i],
ports[i],
mysql_error(server));
rval = 1;
@ -132,7 +133,8 @@ int main(int argc, char** argv)
sprintf(query,"DROP TABLE IF EXISTS %s.t1",databases[i]);
if(mysql_real_query(server,query,strlen(query)))
{
fprintf(stderr, "Failed to drop table in %d: %s.\n",
fprintf(stderr, "Failed to drop table '%s.t1' in %d: %s.\n",
databases[i],
ports[i],
mysql_error(server));
}
@ -141,14 +143,26 @@ int main(int argc, char** argv)
sprintf(query,"CREATE TABLE %s.t1 (id int)",databases[i]);
if(mysql_real_query(server,query,strlen(query)))
{
fprintf(stderr, "Failed to create table in %d: %s.\n",
fprintf(stderr, "Failed to create table '%s.t1' in %d: %s.\n",
databases[i],
ports[i],
mysql_error(server));
rval = 1;
goto report;
}
sprintf(query,"INSERT INTO %s.t1 values (%s)",databases[i],srv_id[i]);
if(mysql_select_db(server,databases[i]))
{
fprintf(stderr, "Failed to use database %s in %d: %s.\n",
databases[i],
ports[i],
mysql_error(server));
rval = 1;
goto report;
}
sprintf(query,"INSERT INTO t1 values (%s)",srv_id[i]);
if(mysql_real_query(server,query,strlen(query)))
{
fprintf(stderr, "Failed to insert values in %d: %s.\n",
@ -161,10 +175,14 @@ int main(int argc, char** argv)
mysql_close(server);
}
/** Test 1 - With default database */
printf("Testing with default database.\n");
for(i = 0;i<4;i++)
{
printf("Testing server on port %d through MaxScale.\n",ports[i]);
printf("Testing database %s through MaxScale.\n",databases[i]);
if((server = mysql_init(NULL)) == NULL){
fprintf(stderr,"Error : Initialization of MySQL client failed.\n");
rval = 1;
@ -179,6 +197,66 @@ int main(int argc, char** argv)
rval = 1;
goto report;
}
if(mysql_real_query(server,"SELECT id FROM t1",strlen("SELECT id FROM t1")))
{
fprintf(stderr, "Failed to execute query in %d: %s.\n",
ports[i],
mysql_error(server));
rval = 1;
goto report;
}
result = mysql_store_result(server);
while((row = mysql_fetch_row(result)))
{
if(strcmp(row[0],srv_id[i]))
{
fprintf(stderr, "Test failed in %d: Was expecting %s but got %s instead.\n",
ports[i],srv_id[i],row[0]);
rval = 1;
}
}
mysql_free_result(result);
mysql_close(server);
}
printf("Testing without default database and USE ... query.\n");
for(i = 0;i<4;i++)
{
printf("Testing server on port %d through MaxScale.\n",ports[i]);
if((server = mysql_init(NULL)) == NULL){
fprintf(stderr,"Error : Initialization of MySQL client failed.\n");
rval = 1;
goto report;
}
if(mysql_real_connect(server,host,username,password,NULL,port,NULL,0) == NULL){
fprintf(stderr, "Failed to connect to port %d using database %s: %s\n",
port,
databases[i],
mysql_error(server));
rval = 1;
goto report;
}
sprintf(query,"USE %s",databases[i]);
if(mysql_select_db(server,databases[i]))
{
fprintf(stderr, "Failed to use database %s in %d: %s.\n",
databases[i],
ports[i],
mysql_error(server));
rval = 1;
goto report;
}
if(mysql_real_query(server,"SELECT id FROM t1",strlen("SELECT id FROM t1")))
{
@ -204,6 +282,29 @@ int main(int argc, char** argv)
mysql_free_result(result);
mysql_close(server);
}
/** Cleanup and START SLAVE */
for(i = 0;i<4;i++)
{
if((server = mysql_init(NULL)) == NULL){
fprintf(stderr,"Error : Initialization of MySQL client failed.\n");
rval = 1;
goto report;
}
if(mysql_real_connect(server,host,username,password,NULL,port,NULL,0) == NULL){
fprintf(stderr, "Failed to connect to port %d using database %s: %s\n",
port,
databases[i],
mysql_error(server));
rval = 1;
goto report;
}
if(i > 0 && mysql_real_query(server,"START SLAVE",strlen("START SLAVE")))
{
fprintf(stderr, "Failed to start slave in %d: %s.\n",