From a48be9badf0ef4571ac8c237ae769af905a991f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Tue, 17 Jan 2017 13:48:47 +0200 Subject: [PATCH] Format router modules Formatted router modules with Astyle. --- .../modules/routing/avrorouter/avro_client.c | 140 +- server/modules/routing/avrorouter/avro_file.c | 68 +- server/modules/routing/avrorouter/avro_rbr.c | 126 +- .../modules/routing/avrorouter/avro_schema.c | 60 +- .../routing/binlogrouter/binlog_common.c | 160 +-- server/modules/routing/binlogrouter/blr.c | 132 +- server/modules/routing/binlogrouter/blr.h | 15 +- .../modules/routing/binlogrouter/blr_file.c | 393 +++--- .../modules/routing/binlogrouter/blr_master.c | 113 +- .../modules/routing/binlogrouter/blr_slave.c | 113 +- .../routing/binlogrouter/maxbinlogcheck.c | 54 +- .../routing/binlogrouter/test/testbinlog.c | 1168 +++++++++-------- server/modules/routing/debugcli/debugcmd.c | 220 ++-- server/modules/routing/maxinfo/maxinfo.c | 24 +- .../modules/routing/maxinfo/maxinfo_error.c | 24 +- server/modules/routing/maxinfo/maxinfo_exec.c | 102 +- .../modules/routing/maxinfo/maxinfo_parse.c | 224 ++-- .../routing/readconnroute/readconnroute.c | 162 +-- .../routing/readwritesplit/readwritesplit.c | 52 +- .../routing/readwritesplit/rwsplit_internal.h | 70 +- .../routing/readwritesplit/rwsplit_mysql.c | 184 +-- .../readwritesplit/rwsplit_route_stmt.c | 218 +-- .../readwritesplit/rwsplit_select_backends.c | 68 +- .../readwritesplit/rwsplit_session_cmd.c | 14 +- .../readwritesplit/rwsplit_tmp_table_multi.c | 86 +- .../routing/schemarouter/schemarouter.c | 200 +-- 26 files changed, 2181 insertions(+), 2009 deletions(-) diff --git a/server/modules/routing/avrorouter/avro_client.c b/server/modules/routing/avrorouter/avro_client.c index 56e4d0015..f1fd61e16 100644 --- a/server/modules/routing/avrorouter/avro_client.c +++ b/server/modules/routing/avrorouter/avro_client.c @@ -71,45 +71,45 @@ avro_client_handle_request(AVRO_INSTANCE *router, AVRO_CLIENT *client, GWBUF *qu switch (client->state) { - case AVRO_CLIENT_ERRORED: - /* force disconnection */ - return 0; - break; - case AVRO_CLIENT_UNREGISTERED: - if (avro_client_do_registration(router, client, queue) == 0) - { - client->state = AVRO_CLIENT_ERRORED; - dcb_printf(client->dcb, "ERR, code 12, msg: Registration failed\n"); - /* force disconnection */ - dcb_close(client->dcb); - rval = 0; - } - else - { - /* Send OK ack to client */ - dcb_printf(client->dcb, "OK\n"); - - client->state = AVRO_CLIENT_REGISTERED; - MXS_INFO("%s: Client [%s] has completed REGISTRATION action", - client->dcb->service->name, - client->dcb->remote != NULL ? client->dcb->remote : ""); - } - break; - case AVRO_CLIENT_REGISTERED: - case AVRO_CLIENT_REQUEST_DATA: - if (client->state == AVRO_CLIENT_REGISTERED) - { - client->state = AVRO_CLIENT_REQUEST_DATA; - } - - /* Process command from client */ - avro_client_process_command(router, client, queue); - - break; - default: + case AVRO_CLIENT_ERRORED: + /* force disconnection */ + return 0; + break; + case AVRO_CLIENT_UNREGISTERED: + if (avro_client_do_registration(router, client, queue) == 0) + { client->state = AVRO_CLIENT_ERRORED; + dcb_printf(client->dcb, "ERR, code 12, msg: Registration failed\n"); + /* force disconnection */ + dcb_close(client->dcb); rval = 0; - break; + } + else + { + /* Send OK ack to client */ + dcb_printf(client->dcb, "OK\n"); + + client->state = AVRO_CLIENT_REGISTERED; + MXS_INFO("%s: Client [%s] has completed REGISTRATION action", + client->dcb->service->name, + client->dcb->remote != NULL ? client->dcb->remote : ""); + } + break; + case AVRO_CLIENT_REGISTERED: + case AVRO_CLIENT_REQUEST_DATA: + if (client->state == AVRO_CLIENT_REGISTERED) + { + client->state = AVRO_CLIENT_REQUEST_DATA; + } + + /* Process command from client */ + avro_client_process_command(router, client, queue); + + break; + default: + client->state = AVRO_CLIENT_ERRORED; + rval = 0; + break; } gwbuf_free(queue); @@ -223,15 +223,15 @@ void extract_gtid_request(gtid_pos_t *gtid, const char *start, int len) char *end; switch (read) { - case 0: - gtid->domain = strtol(ptr, &end, 10); - break; - case 1: - gtid->server_id = strtol(ptr, &end, 10); - break; - case 2: - gtid->seq = strtol(ptr, &end, 10); - break; + case 0: + gtid->domain = strtol(ptr, &end, 10); + break; + case 1: + gtid->server_id = strtol(ptr, &end, 10); + break; + case 2: + gtid->seq = strtol(ptr, &end, 10); + break; } read++; ptr = end; @@ -783,25 +783,25 @@ static bool avro_client_stream_data(AVRO_CLIENT *client) switch (client->format) { - case AVRO_FORMAT_JSON: - /** Currently only JSON format supports seeking to a GTID */ - if (client->requested_gtid && - seek_to_index_pos(client, client->file_handle) && - seek_to_gtid(client, client->file_handle)) - { - client->requested_gtid = false; - } + case AVRO_FORMAT_JSON: + /** Currently only JSON format supports seeking to a GTID */ + if (client->requested_gtid && + seek_to_index_pos(client, client->file_handle) && + seek_to_gtid(client, client->file_handle)) + { + client->requested_gtid = false; + } - read_more = stream_json(client); - break; + read_more = stream_json(client); + break; - case AVRO_FORMAT_AVRO: - read_more = stream_binary(client); - break; + case AVRO_FORMAT_AVRO: + read_more = stream_binary(client); + break; - default: - MXS_ERROR("Unexpected format: %d", client->format); - break; + default: + MXS_ERROR("Unexpected format: %d", client->format); + break; } @@ -986,16 +986,16 @@ int avro_client_callback(DCB *dcb, DCB_REASON reason, void *userdata) switch (client->format) { - case AVRO_FORMAT_JSON: - schema = read_avro_json_schema(client->avro_binfile, client->router->avrodir); - break; + case AVRO_FORMAT_JSON: + schema = read_avro_json_schema(client->avro_binfile, client->router->avrodir); + break; - case AVRO_FORMAT_AVRO: - schema = read_avro_binary_schema(client->avro_binfile, client->router->avrodir); - break; + case AVRO_FORMAT_AVRO: + schema = read_avro_binary_schema(client->avro_binfile, client->router->avrodir); + break; - default: - MXS_ERROR("Unknown client format: %d", client->format); + default: + MXS_ERROR("Unknown client format: %d", client->format); } if (schema) diff --git a/server/modules/routing/avrorouter/avro_file.c b/server/modules/routing/avrorouter/avro_file.c index 44dff6654..570a81031 100644 --- a/server/modules/routing/avrorouter/avro_file.c +++ b/server/modules/routing/avrorouter/avro_file.c @@ -279,25 +279,25 @@ bool avro_load_conversion_state(AVRO_INSTANCE *router) switch (rc) { - case 0: - rval = true; - MXS_NOTICE("Loaded stored binary log conversion state: File: [%s] Position: [%ld] GTID: [%lu-%lu-%lu:%lu]", - router->binlog_name, router->current_pos, router->gtid.domain, - router->gtid.server_id, router->gtid.seq, router->gtid.event_num); - break; + case 0: + rval = true; + MXS_NOTICE("Loaded stored binary log conversion state: File: [%s] Position: [%ld] GTID: [%lu-%lu-%lu:%lu]", + router->binlog_name, router->current_pos, router->gtid.domain, + router->gtid.server_id, router->gtid.seq, router->gtid.event_num); + break; - case -1: - MXS_ERROR("Failed to open file '%s'. ", filename); - break; + case -1: + MXS_ERROR("Failed to open file '%s'. ", filename); + break; - case -2: - MXS_ERROR("Failed to allocate enough memory when parsing file '%s'. ", filename); - break; + case -2: + MXS_ERROR("Failed to allocate enough memory when parsing file '%s'. ", filename); + break; - default: - MXS_ERROR("Failed to parse stored conversion state '%s', error " - "on line %d. ", filename, rc); - break; + default: + MXS_ERROR("Failed to parse stored conversion state '%s', error " + "on line %d. ", filename, rc); + break; } return rval; @@ -509,9 +509,9 @@ avro_binlog_end_t avro_read_all_events(AVRO_INSTANCE *router) { switch (n) { - case 0: - break; - case -1: + case 0: + break; + case -1: { char err_msg[BLRM_STRERROR_R_MSG_SIZE + 1] = ""; strerror_r(errno, err_msg, BLRM_STRERROR_R_MSG_SIZE); @@ -525,12 +525,12 @@ avro_binlog_end_t avro_read_all_events(AVRO_INSTANCE *router) router->binlog_name, router->binlog_fd); break; } - default: - MXS_ERROR("Short read when reading the header. " - "Expected 19 bytes but got %d bytes. " - "Binlog file is %s, position %llu", - n, router->binlog_name, pos); - break; + default: + MXS_ERROR("Short read when reading the header. " + "Expected 19 bytes but got %d bytes. " + "Binlog file is %s, position %llu", + n, router->binlog_name, pos); + break; } router->current_pos = pos; @@ -635,17 +635,17 @@ avro_binlog_end_t avro_read_all_events(AVRO_INSTANCE *router) switch (event_header_ntypes) { - case 168: /* mariadb 10 LOG_EVENT_TYPES*/ - event_header_ntypes -= 163; - break; + case 168: /* mariadb 10 LOG_EVENT_TYPES*/ + event_header_ntypes -= 163; + break; - case 165: /* mariadb 5 LOG_EVENT_TYPES*/ - event_header_ntypes -= 160; - break; + case 165: /* mariadb 5 LOG_EVENT_TYPES*/ + event_header_ntypes -= 160; + break; - default: /* mysql 5.6 LOG_EVENT_TYPES = 35 */ - event_header_ntypes -= 35; - break; + default: /* mysql 5.6 LOG_EVENT_TYPES = 35 */ + event_header_ntypes -= 35; + break; } n_events = hdr.event_size - event_header_length - (2 + 50 + 4 + 1); diff --git a/server/modules/routing/avrorouter/avro_rbr.c b/server/modules/routing/avrorouter/avro_rbr.c index f9adc9bab..e0aa5337c 100644 --- a/server/modules/routing/avrorouter/avro_rbr.c +++ b/server/modules/routing/avrorouter/avro_rbr.c @@ -44,24 +44,24 @@ static int get_event_type(uint8_t event) switch (event) { - case WRITE_ROWS_EVENTv0: - case WRITE_ROWS_EVENTv1: - case WRITE_ROWS_EVENTv2: - return WRITE_EVENT; + case WRITE_ROWS_EVENTv0: + case WRITE_ROWS_EVENTv1: + case WRITE_ROWS_EVENTv2: + return WRITE_EVENT; - case UPDATE_ROWS_EVENTv0: - case UPDATE_ROWS_EVENTv1: - case UPDATE_ROWS_EVENTv2: - return UPDATE_EVENT; + case UPDATE_ROWS_EVENTv0: + case UPDATE_ROWS_EVENTv1: + case UPDATE_ROWS_EVENTv2: + return UPDATE_EVENT; - case DELETE_ROWS_EVENTv0: - case DELETE_ROWS_EVENTv1: - case DELETE_ROWS_EVENTv2: - return DELETE_EVENT; + case DELETE_ROWS_EVENTv0: + case DELETE_ROWS_EVENTv1: + case DELETE_ROWS_EVENTv2: + return DELETE_EVENT; - default: - MXS_ERROR("Unexpected event type: %d (%0x)", event, event); - return -1; + default: + MXS_ERROR("Unexpected event type: %d (%0x)", event, event); + return -1; } } @@ -357,43 +357,43 @@ void set_numeric_field_value(avro_value_t *field, uint8_t type, uint8_t *metadat switch (type) { - case TABLE_COL_TYPE_TINY: - i = *value; - avro_value_set_int(field, i); - break; + case TABLE_COL_TYPE_TINY: + i = *value; + avro_value_set_int(field, i); + break; - case TABLE_COL_TYPE_SHORT: - memcpy(&i, value, 2); - avro_value_set_int(field, i); - break; + case TABLE_COL_TYPE_SHORT: + memcpy(&i, value, 2); + avro_value_set_int(field, i); + break; - case TABLE_COL_TYPE_INT24: - memcpy(&i, value, 3); - avro_value_set_int(field, i); - break; + case TABLE_COL_TYPE_INT24: + memcpy(&i, value, 3); + avro_value_set_int(field, i); + break; - case TABLE_COL_TYPE_LONG: - memcpy(&i, value, 4); - avro_value_set_int(field, i); - break; + case TABLE_COL_TYPE_LONG: + memcpy(&i, value, 4); + avro_value_set_int(field, i); + break; - case TABLE_COL_TYPE_LONGLONG: - memcpy(&i, value, 8); - avro_value_set_int(field, i); - break; + case TABLE_COL_TYPE_LONGLONG: + memcpy(&i, value, 8); + avro_value_set_int(field, i); + break; - case TABLE_COL_TYPE_FLOAT: - memcpy(&i, value, 4); - avro_value_set_float(field, (float)i); - break; + case TABLE_COL_TYPE_FLOAT: + memcpy(&i, value, 4); + avro_value_set_float(field, (float)i); + break; - case TABLE_COL_TYPE_DOUBLE: - memcpy(&i, value, 8); - avro_value_set_float(field, (double)i); - break; + case TABLE_COL_TYPE_DOUBLE: + memcpy(&i, value, 8); + avro_value_set_float(field, (double)i); + break; - default: - break; + default: + break; } } @@ -426,26 +426,26 @@ int get_metadata_len(uint8_t type) { switch (type) { - case TABLE_COL_TYPE_STRING: - case TABLE_COL_TYPE_VAR_STRING: - case TABLE_COL_TYPE_VARCHAR: - case TABLE_COL_TYPE_DECIMAL: - case TABLE_COL_TYPE_NEWDECIMAL: - case TABLE_COL_TYPE_ENUM: - case TABLE_COL_TYPE_SET: - case TABLE_COL_TYPE_BIT: - return 2; + case TABLE_COL_TYPE_STRING: + case TABLE_COL_TYPE_VAR_STRING: + case TABLE_COL_TYPE_VARCHAR: + case TABLE_COL_TYPE_DECIMAL: + case TABLE_COL_TYPE_NEWDECIMAL: + case TABLE_COL_TYPE_ENUM: + case TABLE_COL_TYPE_SET: + case TABLE_COL_TYPE_BIT: + return 2; - case TABLE_COL_TYPE_BLOB: - case TABLE_COL_TYPE_FLOAT: - case TABLE_COL_TYPE_DOUBLE: - case TABLE_COL_TYPE_DATETIME2: - case TABLE_COL_TYPE_TIMESTAMP2: - case TABLE_COL_TYPE_TIME2: - return 1; + case TABLE_COL_TYPE_BLOB: + case TABLE_COL_TYPE_FLOAT: + case TABLE_COL_TYPE_DOUBLE: + case TABLE_COL_TYPE_DATETIME2: + case TABLE_COL_TYPE_TIMESTAMP2: + case TABLE_COL_TYPE_TIME2: + return 1; - default: - return 0; + default: + return 0; } } diff --git a/server/modules/routing/avrorouter/avro_schema.c b/server/modules/routing/avrorouter/avro_schema.c index 596ae5bff..c58a0bcab 100644 --- a/server/modules/routing/avrorouter/avro_schema.c +++ b/server/modules/routing/avrorouter/avro_schema.c @@ -42,34 +42,34 @@ static const char* column_type_to_avro_type(uint8_t type) { switch (type) { - case TABLE_COL_TYPE_TINY: - case TABLE_COL_TYPE_SHORT: - case TABLE_COL_TYPE_LONG: - case TABLE_COL_TYPE_INT24: - case TABLE_COL_TYPE_BIT: - return "int"; + case TABLE_COL_TYPE_TINY: + case TABLE_COL_TYPE_SHORT: + case TABLE_COL_TYPE_LONG: + case TABLE_COL_TYPE_INT24: + case TABLE_COL_TYPE_BIT: + return "int"; - case TABLE_COL_TYPE_FLOAT: - return "float"; + case TABLE_COL_TYPE_FLOAT: + return "float"; - case TABLE_COL_TYPE_DOUBLE: - case TABLE_COL_TYPE_NEWDECIMAL: - return "double"; + case TABLE_COL_TYPE_DOUBLE: + case TABLE_COL_TYPE_NEWDECIMAL: + return "double"; - case TABLE_COL_TYPE_NULL: - return "null"; + case TABLE_COL_TYPE_NULL: + return "null"; - case TABLE_COL_TYPE_LONGLONG: - return "long"; + case TABLE_COL_TYPE_LONGLONG: + return "long"; - case TABLE_COL_TYPE_TINY_BLOB: - case TABLE_COL_TYPE_MEDIUM_BLOB: - case TABLE_COL_TYPE_LONG_BLOB: - case TABLE_COL_TYPE_BLOB: - return "bytes"; + case TABLE_COL_TYPE_TINY_BLOB: + case TABLE_COL_TYPE_MEDIUM_BLOB: + case TABLE_COL_TYPE_LONG_BLOB: + case TABLE_COL_TYPE_BLOB: + return "bytes"; - default: - return "string"; + default: + return "string"; } } @@ -284,16 +284,16 @@ static const char* get_table_definition(const char *sql, int* size) { switch (*ptr) { - case '(': - depth++; - break; + case '(': + depth++; + break; - case ')': - depth--; - break; + case ')': + depth--; + break; - default: - break; + default: + break; } /** We found the last closing parenthesis */ diff --git a/server/modules/routing/binlogrouter/binlog_common.c b/server/modules/routing/binlogrouter/binlog_common.c index f17929fcf..37bae6b64 100644 --- a/server/modules/routing/binlogrouter/binlog_common.c +++ b/server/modules/routing/binlogrouter/binlog_common.c @@ -129,85 +129,85 @@ const char* binlog_event_name(int type) { switch (type) { - case START_EVENT_V3: - return "START_EVENT_V3"; - case QUERY_EVENT: - return "QUERY_EVENT"; - case STOP_EVENT: - return "STOP_EVENT"; - case ROTATE_EVENT: - return "ROTATE_EVENT"; - case INTVAR_EVENT: - return "INTVAR_EVENT"; - case LOAD_EVENT: - return "LOAD_EVENT"; - case SLAVE_EVENT: - return "SLAVE_EVENT"; - case CREATE_FILE_EVENT: - return "CREATE_FILE_EVENT"; - case APPEND_BLOCK_EVENT: - return "APPEND_BLOCK_EVENT"; - case EXEC_LOAD_EVENT: - return "EXEC_LOAD_EVENT"; - case DELETE_FILE_EVENT: - return "DELETE_FILE_EVENT"; - case NEW_LOAD_EVENT: - return "NEW_LOAD_EVENT"; - case RAND_EVENT: - return "RAND_EVENT"; - case USER_VAR_EVENT: - return "USER_VAR_EVENT"; - case FORMAT_DESCRIPTION_EVENT: - return "FORMAT_DESCRIPTION_EVENT"; - case XID_EVENT: - return "XID_EVENT"; - case BEGIN_LOAD_QUERY_EVENT: - return "BEGIN_LOAD_QUERY_EVENT"; - case EXECUTE_LOAD_QUERY_EVENT: - return "EXECUTE_LOAD_QUERY_EVENT"; - case TABLE_MAP_EVENT: - return "TABLE_MAP_EVENT"; - case WRITE_ROWS_EVENTv0: - return "WRITE_ROWS_EVENTv0"; - case UPDATE_ROWS_EVENTv0: - return "UPDATE_ROWS_EVENTv0"; - case DELETE_ROWS_EVENTv0: - return "DELETE_ROWS_EVENTv0"; - case WRITE_ROWS_EVENTv1: - return "WRITE_ROWS_EVENTv1"; - case UPDATE_ROWS_EVENTv1: - return "UPDATE_ROWS_EVENTv1"; - case DELETE_ROWS_EVENTv1: - return "DELETE_ROWS_EVENTv1"; - case INCIDENT_EVENT: - return "INCIDENT_EVENT"; - case HEARTBEAT_EVENT: - return "HEARTBEAT_EVENT"; - case IGNORABLE_EVENT: - return "IGNORABLE_EVENT"; - case ROWS_QUERY_EVENT: - return "ROWS_QUERY_EVENT"; - case WRITE_ROWS_EVENTv2: - return "WRITE_ROWS_EVENTv2"; - case UPDATE_ROWS_EVENTv2: - return "UPDATE_ROWS_EVENTv2"; - case DELETE_ROWS_EVENTv2: - return "DELETE_ROWS_EVENTv2"; - case GTID_EVENT: - return "GTID_EVENT"; - case ANONYMOUS_GTID_EVENT: - return "ANONYMOUS_GTID_EVENT"; - case PREVIOUS_GTIDS_EVENT: - return "PREVIOUS_GTIDS_EVENT"; - case MARIADB_ANNOTATE_ROWS_EVENT: - return "MARIADB_ANNOTATE_ROWS_EVENT"; - case MARIADB10_BINLOG_CHECKPOINT_EVENT: - return "MARIADB10_BINLOG_CHECKPOINT_EVENT"; - case MARIADB10_GTID_EVENT: - return "MARIADB10_GTID_EVENT"; - case MARIADB10_GTID_GTID_LIST_EVENT: - return "MARIADB10_GTID_GTID_LIST_EVENT"; - default: - return "UNKNOWN_EVENT"; + case START_EVENT_V3: + return "START_EVENT_V3"; + case QUERY_EVENT: + return "QUERY_EVENT"; + case STOP_EVENT: + return "STOP_EVENT"; + case ROTATE_EVENT: + return "ROTATE_EVENT"; + case INTVAR_EVENT: + return "INTVAR_EVENT"; + case LOAD_EVENT: + return "LOAD_EVENT"; + case SLAVE_EVENT: + return "SLAVE_EVENT"; + case CREATE_FILE_EVENT: + return "CREATE_FILE_EVENT"; + case APPEND_BLOCK_EVENT: + return "APPEND_BLOCK_EVENT"; + case EXEC_LOAD_EVENT: + return "EXEC_LOAD_EVENT"; + case DELETE_FILE_EVENT: + return "DELETE_FILE_EVENT"; + case NEW_LOAD_EVENT: + return "NEW_LOAD_EVENT"; + case RAND_EVENT: + return "RAND_EVENT"; + case USER_VAR_EVENT: + return "USER_VAR_EVENT"; + case FORMAT_DESCRIPTION_EVENT: + return "FORMAT_DESCRIPTION_EVENT"; + case XID_EVENT: + return "XID_EVENT"; + case BEGIN_LOAD_QUERY_EVENT: + return "BEGIN_LOAD_QUERY_EVENT"; + case EXECUTE_LOAD_QUERY_EVENT: + return "EXECUTE_LOAD_QUERY_EVENT"; + case TABLE_MAP_EVENT: + return "TABLE_MAP_EVENT"; + case WRITE_ROWS_EVENTv0: + return "WRITE_ROWS_EVENTv0"; + case UPDATE_ROWS_EVENTv0: + return "UPDATE_ROWS_EVENTv0"; + case DELETE_ROWS_EVENTv0: + return "DELETE_ROWS_EVENTv0"; + case WRITE_ROWS_EVENTv1: + return "WRITE_ROWS_EVENTv1"; + case UPDATE_ROWS_EVENTv1: + return "UPDATE_ROWS_EVENTv1"; + case DELETE_ROWS_EVENTv1: + return "DELETE_ROWS_EVENTv1"; + case INCIDENT_EVENT: + return "INCIDENT_EVENT"; + case HEARTBEAT_EVENT: + return "HEARTBEAT_EVENT"; + case IGNORABLE_EVENT: + return "IGNORABLE_EVENT"; + case ROWS_QUERY_EVENT: + return "ROWS_QUERY_EVENT"; + case WRITE_ROWS_EVENTv2: + return "WRITE_ROWS_EVENTv2"; + case UPDATE_ROWS_EVENTv2: + return "UPDATE_ROWS_EVENTv2"; + case DELETE_ROWS_EVENTv2: + return "DELETE_ROWS_EVENTv2"; + case GTID_EVENT: + return "GTID_EVENT"; + case ANONYMOUS_GTID_EVENT: + return "ANONYMOUS_GTID_EVENT"; + case PREVIOUS_GTIDS_EVENT: + return "PREVIOUS_GTIDS_EVENT"; + case MARIADB_ANNOTATE_ROWS_EVENT: + return "MARIADB_ANNOTATE_ROWS_EVENT"; + case MARIADB10_BINLOG_CHECKPOINT_EVENT: + return "MARIADB10_BINLOG_CHECKPOINT_EVENT"; + case MARIADB10_GTID_EVENT: + return "MARIADB10_GTID_EVENT"; + case MARIADB10_GTID_GTID_LIST_EVENT: + return "MARIADB10_GTID_GTID_LIST_EVENT"; + default: + return "UNKNOWN_EVENT"; } } diff --git a/server/modules/routing/binlogrouter/blr.c b/server/modules/routing/binlogrouter/blr.c index fb7daf7ee..f46fb6fc8 100644 --- a/server/modules/routing/binlogrouter/blr.c +++ b/server/modules/routing/binlogrouter/blr.c @@ -132,7 +132,7 @@ static const MXS_ENUM_VALUE enc_algo_values[] = { {"aes_cbc", BLR_AES_CBC}, #if OPENSSL_VERSION_NUMBER > 0x10000000L - {"aes_ctr",BLR_AES_CTR}, + {"aes_ctr", BLR_AES_CTR}, #endif {NULL} }; @@ -864,7 +864,7 @@ createInstance(SERVICE *service, char **options) if (inst->trx_safe) { MXS_NOTICE("%s: Service has transaction safety option set to ON", - service->name); + service->name); } /* Log whether the binlog encryption option value is on */ @@ -1652,9 +1652,9 @@ diagnostics(ROUTER *router, DCB *dcb) { dcb_printf(dcb, "\t\tSlave_mode: catchup. %s%s\n", ((session->cstate & CS_EXPECTCB) == 0 ? "" : - "Waiting for DCB queue to drain."), + "Waiting for DCB queue to drain."), ((session->cstate & CS_BUSY) == 0 ? "" : - " Busy in slave catchup.")); + " Busy in slave catchup.")); } } #if SPINLOCK_PROFILE @@ -2469,11 +2469,11 @@ destroyInstance(ROUTER *instance) } MXS_INFO("%s is being stopped by MaxScale shudown. Disconnecting from master %s:%d, " - "read up to log %s, pos %lu, transaction safe pos %lu", - inst->service->name, - inst->service->dbref->server->name, - inst->service->dbref->server->port, - inst->binlog_name, inst->current_pos, inst->binlog_position); + "read up to log %s, pos %lu, transaction safe pos %lu", + inst->service->name, + inst->service->dbref->server->name, + inst->service->dbref->server->port, + inst->binlog_name, inst->current_pos, inst->binlog_position); if (inst->trx_safe && inst->pending_transaction) { @@ -2509,71 +2509,71 @@ unsigned int from_hex(char c) */ bool blr_extract_key(const char *buffer, int nline, ROUTER_INSTANCE *router) { - char *p = (char *)buffer; - int length = 0; - uint8_t *key = (uint8_t *)router->encryption.key_value; + char *p = (char *)buffer; + int length = 0; + uint8_t *key = (uint8_t *)router->encryption.key_value; - while (isspace(*p) && *p != '\n') - { - p++; - } + while (isspace(*p) && *p != '\n') + { + p++; + } - /* Skip comments */ - if (*p == '#') - { - return false; - } + /* Skip comments */ + if (*p == '#') + { + return false; + } - unsigned int id = strtoll(p, &p, 10); + unsigned int id = strtoll(p, &p, 10); - /* key range is 1 .. 255 */ - if (id < 1 || id > 255) - { - MXS_WARNING("Invalid Key Id (values 1..255) found in file %s. Line %d, index 0.", - router->encryption.key_management_filename, - nline); - return false; - } + /* key range is 1 .. 255 */ + if (id < 1 || id > 255) + { + MXS_WARNING("Invalid Key Id (values 1..255) found in file %s. Line %d, index 0.", + router->encryption.key_management_filename, + nline); + return false; + } - /* Continue only if read id is BINLOG_SYSTEM_DATA_CRYPTO_SCHEME (value is 1) */ - if (id != BINLOG_SYSTEM_DATA_CRYPTO_SCHEME) - { - return false; - } + /* Continue only if read id is BINLOG_SYSTEM_DATA_CRYPTO_SCHEME (value is 1) */ + if (id != BINLOG_SYSTEM_DATA_CRYPTO_SCHEME) + { + return false; + } - /* Look for ';' separator */ - if (*p != ';') - { - MXS_ERROR("Syntax error in Encryption Key file at line %d, index %lu. File %s", - nline, - p - buffer, - router->encryption.key_management_filename); - return false; - } + /* Look for ';' separator */ + if (*p != ';') + { + MXS_ERROR("Syntax error in Encryption Key file at line %d, index %lu. File %s", + nline, + p - buffer, + router->encryption.key_management_filename); + return false; + } - p++; + p++; - /* Now read the hex data */ + /* Now read the hex data */ - while (isxdigit(p[0]) && isxdigit(p[1]) && length <= BINLOG_AES_MAX_KEY_LEN) - { - key[length++] = from_hex(p[0]) * 16 + from_hex(p[1]); - p += 2; - } + while (isxdigit(p[0]) && isxdigit(p[1]) && length <= BINLOG_AES_MAX_KEY_LEN) + { + key[length++] = from_hex(p[0]) * 16 + from_hex(p[1]); + p += 2; + } - if (isxdigit(*p) || - (length != 16 && length != 24 && length != 32)) - { - MXS_ERROR("Found invalid Encryption Key at line %d, index %lu. File %s", - nline, - p - buffer, - router->encryption.key_management_filename); - return false; - } + if (isxdigit(*p) || + (length != 16 && length != 24 && length != 32)) + { + MXS_ERROR("Found invalid Encryption Key at line %d, index %lu. File %s", + nline, + p - buffer, + router->encryption.key_management_filename); + return false; + } - router->encryption.key_len = length; + router->encryption.key_len = length; - return true; + return true; } /** @@ -2589,8 +2589,8 @@ bool blr_get_encryption_key(ROUTER_INSTANCE *router) if (router->encryption.key_management_filename == NULL) { MXS_ERROR("Service %s, encryption key is not set. " - "Please specify key filename with 'encryption_key_file'", - router->service->name); + "Please specify key filename with 'encryption_key_file'", + router->service->name); return false; } else @@ -2668,8 +2668,8 @@ int blr_parse_key_file(ROUTER_INSTANCE *router) if (!found_keyid) { MXS_ERROR("No Key with Id = 1 has been found in file %s. Read %d lines.", - router->encryption.key_management_filename, - n_lines); + router->encryption.key_management_filename, + n_lines); return n_lines; } else diff --git a/server/modules/routing/binlogrouter/blr.h b/server/modules/routing/binlogrouter/blr.h index 8f6c76c92..852574dda 100644 --- a/server/modules/routing/binlogrouter/blr.h +++ b/server/modules/routing/binlogrouter/blr.h @@ -501,12 +501,12 @@ typedef struct */ typedef struct binlog_encryption_setup { - bool enabled; - int encryption_algorithm; - char *key_management_filename; - uint8_t key_value[BINLOG_AES_MAX_KEY_LEN]; - unsigned long key_len; - uint8_t key_id; + bool enabled; + int encryption_algorithm; + char *key_management_filename; + uint8_t key_value[BINLOG_AES_MAX_KEY_LEN]; + unsigned long key_len; + uint8_t key_id; } BINLOG_ENCRYPTION_SETUP; /** @@ -756,7 +756,8 @@ extern int blr_write_binlog_record(ROUTER_INSTANCE *, REP_HEADER *, uint32_t po extern int blr_file_rotate(ROUTER_INSTANCE *, char *, uint64_t); extern void blr_file_flush(ROUTER_INSTANCE *); extern BLFILE *blr_open_binlog(ROUTER_INSTANCE *, char *); -extern GWBUF *blr_read_binlog(ROUTER_INSTANCE *, BLFILE *, unsigned long, REP_HEADER *, char *, const SLAVE_ENCRYPTION_CTX *); +extern GWBUF *blr_read_binlog(ROUTER_INSTANCE *, BLFILE *, unsigned long, REP_HEADER *, char *, + const SLAVE_ENCRYPTION_CTX *); extern void blr_close_binlog(ROUTER_INSTANCE *, BLFILE *); extern unsigned long blr_file_size(BLFILE *); extern int blr_statistics(ROUTER_INSTANCE *, ROUTER_SLAVE *, GWBUF *); diff --git a/server/modules/routing/binlogrouter/blr_file.c b/server/modules/routing/binlogrouter/blr_file.c index 6a0d5a5d8..2fb2c4067 100644 --- a/server/modules/routing/binlogrouter/blr_file.c +++ b/server/modules/routing/binlogrouter/blr_file.c @@ -85,10 +85,14 @@ static inline const EVP_CIPHER *aes_ctr(unsigned int klen) { switch (klen) { - case 16: return EVP_aes_128_ctr(); - case 24: return EVP_aes_192_ctr(); - case 32: return EVP_aes_256_ctr(); - default: return 0; + case 16: + return EVP_aes_128_ctr(); + case 24: + return EVP_aes_192_ctr(); + case 32: + return EVP_aes_256_ctr(); + default: + return 0; } } #endif @@ -103,10 +107,14 @@ static inline const EVP_CIPHER *aes_cbc(uint klen) { switch (klen) { - case 16: return EVP_aes_128_cbc(); - case 24: return EVP_aes_192_cbc(); - case 32: return EVP_aes_256_cbc(); - default: return 0; + case 16: + return EVP_aes_128_cbc(); + case 24: + return EVP_aes_192_cbc(); + case 32: + return EVP_aes_256_cbc(); + default: + return 0; } } @@ -120,10 +128,14 @@ static inline const EVP_CIPHER *aes_ecb(uint klen) { switch (klen) { - case 16: return EVP_aes_128_ecb(); - case 24: return EVP_aes_192_ecb(); - case 32: return EVP_aes_256_ecb(); - default: return 0; + case 16: + return EVP_aes_128_ecb(); + case 24: + return EVP_aes_192_ecb(); + case 32: + return EVP_aes_256_ecb(); + default: + return 0; } } @@ -184,11 +196,11 @@ static uint8_t *blr_create_start_encryption_event(ROUTER_INSTANCE *router, uint32_t event_pos, bool do_checksum); static GWBUF *blr_prepare_encrypted_event(ROUTER_INSTANCE *router, - uint8_t *event, - uint32_t event_size, - uint32_t pos, - const uint8_t *nonce, - int action); + uint8_t *event, + uint32_t event_size, + uint32_t pos, + const uint8_t *nonce, + int action); static GWBUF *blr_aes_crypt(ROUTER_INSTANCE *router, uint8_t *event, uint32_t event_size, @@ -555,7 +567,9 @@ blr_write_binlog_record(ROUTER_INSTANCE *router, REP_HEADER *hdr, uint32_t size, gwbuf_free(encrypted); encrypted = NULL; - } else { + } + else + { /* Write current received event form master */ n = pwrite(router->binlog_fd, buf, size, router->last_written); } @@ -814,7 +828,7 @@ blr_read_binlog(ROUTER_INSTANCE *router, { case 0: MXS_INFO("Reached end of binlog file '%s' at %lu.", - file->binlogname, pos); + file->binlogname, pos); /* set ok indicator */ hdr->ok = SLAVE_POS_READ_OK; @@ -878,7 +892,7 @@ blr_read_binlog(ROUTER_INSTANCE *router, { case 0: MXS_INFO("Reached end of binlog file at %lu.", - pos); + pos); /* set ok indicator */ hdr->ok = SLAVE_POS_READ_OK; @@ -959,7 +973,7 @@ blr_read_binlog(ROUTER_INSTANCE *router, if (n == 0) { MXS_INFO("Reached end of binlog file at %lu while reading remaining bytes.", - pos); + pos); /* set ok indicator */ hdr->ok = SLAVE_POS_READ_OK; @@ -1484,37 +1498,37 @@ blr_read_events_all_events(ROUTER_INSTANCE *router, int fix, int debug) if (start_encryption_seen) { - uint8_t iv[AES_BLOCK_SIZE + 1] = ""; - char iv_hex[AES_BLOCK_SIZE * 2 + 1] = ""; - /* The event size, 4 bytes, is written in clear: use it */ - uint32_t event_size = EXTRACT32(hdbuf + BINLOG_EVENT_LEN_OFFSET); + uint8_t iv[AES_BLOCK_SIZE + 1] = ""; + char iv_hex[AES_BLOCK_SIZE * 2 + 1] = ""; + /* The event size, 4 bytes, is written in clear: use it */ + uint32_t event_size = EXTRACT32(hdbuf + BINLOG_EVENT_LEN_OFFSET); - /** - * Events are encrypted. - * - * Print the IV for the current encrypted event. - */ + /** + * Events are encrypted. + * + * Print the IV for the current encrypted event. + */ - if (debug & BLR_REPORT_REP_HEADER) - { - /* Get binlog file "nonce" and other data from router encryption_ctx */ - BINLOG_ENCRYPTION_CTX *enc_ctx = router->encryption_ctx; + if (debug & BLR_REPORT_REP_HEADER) + { + /* Get binlog file "nonce" and other data from router encryption_ctx */ + BINLOG_ENCRYPTION_CTX *enc_ctx = router->encryption_ctx; - /* Encryption IV is 12 bytes nonce + 4 bytes event position */ - memcpy(iv, enc_ctx->nonce, BLRM_NONCE_LENGTH); - gw_mysql_set_byte4(iv + BLRM_NONCE_LENGTH, (unsigned long)pos); + /* Encryption IV is 12 bytes nonce + 4 bytes event position */ + memcpy(iv, enc_ctx->nonce, BLRM_NONCE_LENGTH); + gw_mysql_set_byte4(iv + BLRM_NONCE_LENGTH, (unsigned long)pos); - /* Human readable version */ - gw_bin2hex(iv_hex, iv, BLRM_IV_LENGTH); + /* Human readable version */ + gw_bin2hex(iv_hex, iv, BLRM_IV_LENGTH); - MXS_DEBUG("** Encrypted Event @ %lu: the IV is %s, size is %lu, next pos is %lu\n", - (unsigned long)pos, - iv_hex, (unsigned long)event_size, - (unsigned long)(pos + event_size)); - } + MXS_DEBUG("** Encrypted Event @ %lu: the IV is %s, size is %lu, next pos is %lu\n", + (unsigned long)pos, + iv_hex, (unsigned long)event_size, + (unsigned long)(pos + event_size)); + } - /* Set event size only in hdr struct, before decryption */ - hdr.event_size = event_size; + /* Set event size only in hdr struct, before decryption */ + hdr.event_size = event_size; } else @@ -1690,16 +1704,16 @@ blr_read_events_all_events(ROUTER_INSTANCE *router, int fix, int debug) /* decrypt events */ if (start_encryption_seen) { - uint8_t iv[AES_BLOCK_SIZE + 1] = ""; - char iv_hex[AES_BLOCK_SIZE * 2 + 1] = ""; - uint32_t event_size = EXTRACT32(hdbuf + BINLOG_EVENT_LEN_OFFSET); - uint8_t *decrypt_ptr; - unsigned long next_pos; - char errmsg[BLRM_STRERROR_R_MSG_SIZE + 1] = ""; + uint8_t iv[AES_BLOCK_SIZE + 1] = ""; + char iv_hex[AES_BLOCK_SIZE * 2 + 1] = ""; + uint32_t event_size = EXTRACT32(hdbuf + BINLOG_EVENT_LEN_OFFSET); + uint8_t *decrypt_ptr; + unsigned long next_pos; + char errmsg[BLRM_STRERROR_R_MSG_SIZE + 1] = ""; - /** - * Events are encrypted. - */ + /** + * Events are encrypted. + */ if ((decrypted_event = blr_prepare_encrypted_event(router, data, @@ -2403,11 +2417,13 @@ blr_file_write_master_config(ROUTER_INSTANCE *router, char *error) { fprintf(config_file, "master_ssl=%d\n", router->ssl_enabled); fprintf(config_file, "master_ssl_key=%s\n", ssl_key); - fprintf(config_file, "master_ssl_cert=%s\n",ssl_cert); + fprintf(config_file, "master_ssl_cert=%s\n", ssl_cert); fprintf(config_file, "master_ssl_ca=%s\n", ssl_ca); } if (ssl_version && strlen(ssl_version)) + { fprintf(config_file, "master_tls_version=%s\n", ssl_version); + } fclose(config_file); @@ -2525,12 +2541,12 @@ blr_create_ignorable_event(uint32_t event_size, * The algorithm is first to compute the checksum of an empty buffer * and then the checksum of the real event: 4 byte less than event_size */ - uint32_t chksum; - chksum = crc32(0L, NULL, 0); - chksum = crc32(chksum, new_event, event_size - BINLOG_EVENT_CRC_SIZE); + uint32_t chksum; + chksum = crc32(0L, NULL, 0); + chksum = crc32(chksum, new_event, event_size - BINLOG_EVENT_CRC_SIZE); - // checksum is stored after current event data using 4 bytes - encode_value(new_event + event_size - BINLOG_EVENT_CRC_SIZE, chksum, 32); + // checksum is stored after current event data using 4 bytes + encode_value(new_event + event_size - BINLOG_EVENT_CRC_SIZE, chksum, 32); } return new_event; } @@ -2546,7 +2562,8 @@ blr_create_ignorable_event(uint32_t event_size, * @return 1 on success, 0 on error */ static int -blr_write_special_event(ROUTER_INSTANCE *router, uint32_t file_offset, uint32_t event_size, REP_HEADER *hdr, int type) +blr_write_special_event(ROUTER_INSTANCE *router, uint32_t file_offset, uint32_t event_size, REP_HEADER *hdr, + int type) { int n; uint8_t *new_event; @@ -2554,92 +2571,92 @@ blr_write_special_event(ROUTER_INSTANCE *router, uint32_t file_offset, uint32_t switch (type) { - case BLRM_IGNORABLE: - new_event_desc = "IGNORABLE"; - MXS_INFO("Hole detected while writing in binlog '%s' @ %lu: an %s event " - "of %lu bytes will be written at pos %lu", - router->binlog_name, - router->current_pos, - new_event_desc, - (unsigned long)event_size, - (unsigned long)file_offset); + case BLRM_IGNORABLE: + new_event_desc = "IGNORABLE"; + MXS_INFO("Hole detected while writing in binlog '%s' @ %lu: an %s event " + "of %lu bytes will be written at pos %lu", + router->binlog_name, + router->current_pos, + new_event_desc, + (unsigned long)event_size, + (unsigned long)file_offset); - /* Create the Ignorable event */ - if ((new_event = blr_create_ignorable_event(event_size, - hdr, - file_offset, - router->master_chksum)) == NULL) - { - return 0; - } - if (router->encryption.enabled && router->encryption_ctx != NULL) - { - GWBUF *encrypted; - uint8_t *encr_ptr; - if ((encrypted = blr_prepare_encrypted_event(router, - new_event, - event_size, - router->current_pos, - NULL, - BINLOG_FLAG_ENCRYPT)) == NULL) - { - return 0; - } - - memcpy(new_event, GWBUF_DATA(encrypted), event_size); - gwbuf_free(encrypted); - } - break; - case BLRM_START_ENCRYPTION: - new_event_desc = "MARIADB10_START_ENCRYPTION"; - MXS_INFO("New event %s is being added in binlog '%s' @ %lu: " - "%lu bytes will be written at pos %lu", - new_event_desc, - router->binlog_name, - router->current_pos, - (unsigned long)event_size, - (unsigned long)file_offset); - - /* Create the MARIADB10_START_ENCRYPTION event */ - if ((new_event = blr_create_start_encryption_event(router, - file_offset, - router->master_chksum)) == NULL) - { - return 0; - } - break; - default: - new_event_desc = "UNKNOWN"; - MXS_ERROR("Cannot create special binlog event of %s type and size %lu " - "in binlog file '%s' @ %lu", - new_event_desc, - (unsigned long)event_size, - router->binlog_name, - router->current_pos); + /* Create the Ignorable event */ + if ((new_event = blr_create_ignorable_event(event_size, + hdr, + file_offset, + router->master_chksum)) == NULL) + { return 0; - break; + } + if (router->encryption.enabled && router->encryption_ctx != NULL) + { + GWBUF *encrypted; + uint8_t *encr_ptr; + if ((encrypted = blr_prepare_encrypted_event(router, + new_event, + event_size, + router->current_pos, + NULL, + BINLOG_FLAG_ENCRYPT)) == NULL) + { + return 0; + } + + memcpy(new_event, GWBUF_DATA(encrypted), event_size); + gwbuf_free(encrypted); + } + break; + case BLRM_START_ENCRYPTION: + new_event_desc = "MARIADB10_START_ENCRYPTION"; + MXS_INFO("New event %s is being added in binlog '%s' @ %lu: " + "%lu bytes will be written at pos %lu", + new_event_desc, + router->binlog_name, + router->current_pos, + (unsigned long)event_size, + (unsigned long)file_offset); + + /* Create the MARIADB10_START_ENCRYPTION event */ + if ((new_event = blr_create_start_encryption_event(router, + file_offset, + router->master_chksum)) == NULL) + { + return 0; + } + break; + default: + new_event_desc = "UNKNOWN"; + MXS_ERROR("Cannot create special binlog event of %s type and size %lu " + "in binlog file '%s' @ %lu", + new_event_desc, + (unsigned long)event_size, + router->binlog_name, + router->current_pos); + return 0; + break; } /* Write the event */ if ((n = pwrite(router->binlog_fd, new_event, event_size, router->last_written)) != event_size) { - char err_msg[MXS_STRERROR_BUFLEN]; - MXS_ERROR("%s: Failed to write %s special binlog record at %lu of %s, %s. " - "Truncating to previous record.", - router->service->name, new_event_desc, (unsigned long)file_offset, - router->binlog_name, - strerror_r(errno, err_msg, sizeof(err_msg))); + char err_msg[MXS_STRERROR_BUFLEN]; + MXS_ERROR("%s: Failed to write %s special binlog record at %lu of %s, %s. " + "Truncating to previous record.", + router->service->name, new_event_desc, (unsigned long)file_offset, + router->binlog_name, + strerror_r(errno, err_msg, sizeof(err_msg))); - /* Remove any partial event that was written */ - if (ftruncate(router->binlog_fd, router->binlog_position)) - { - MXS_ERROR("%s: Failed to truncate %s special binlog record at %lu of %s, %s. ", - router->service->name, new_event_desc, (unsigned long)file_offset, - router->binlog_name, - strerror_r(errno, err_msg, sizeof(err_msg))); - } - MXS_FREE(new_event); - return 0; + /* Remove any partial event that was written */ + if (ftruncate(router->binlog_fd, router->binlog_position)) + { + MXS_ERROR("%s: Failed to truncate %s special binlog record at %lu of %s, %s. ", + router->service->name, new_event_desc, (unsigned long)file_offset, + router->binlog_name, + strerror_r(errno, err_msg, sizeof(err_msg))); + } + MXS_FREE(new_event); + return 0; } MXS_FREE(new_event); @@ -2688,7 +2705,7 @@ blr_create_start_encryption_event(ROUTER_INSTANCE *router, uint32_t event_pos, b event_size += BINLOG_EVENT_CRC_SIZE; } - new_event= MXS_CALLOC(1, event_size); + new_event = MXS_CALLOC(1, event_size); if (new_event == NULL) { return NULL; @@ -2813,11 +2830,11 @@ static GWBUF *blr_aes_crypt(ROUTER_INSTANCE *router, EVP_CIPHER_CTX_set_padding(&ctx, 0); /* Encryt/Decrypt the input data */ - if(!EVP_CipherUpdate(&ctx, - out_ptr + 4, - &outlen, - buffer, - size)) + if (!EVP_CipherUpdate(&ctx, + out_ptr + 4, + &outlen, + buffer, + size)) { MXS_ERROR("Error in EVP_CipherUpdate"); EVP_CIPHER_CTX_cleanup(&ctx); @@ -2835,8 +2852,8 @@ static GWBUF *blr_aes_crypt(ROUTER_INSTANCE *router, (out_ptr + 4 + outlen), (int*)&flen)) { - MXS_ERROR("Error in EVP_CipherFinal_ex"); - finale_ret = 0; + MXS_ERROR("Error in EVP_CipherFinal_ex"); + finale_ret = 0; } } else @@ -2854,16 +2871,16 @@ static GWBUF *blr_aes_crypt(ROUTER_INSTANCE *router, router->encryption.key_value, router->encryption.key_len)) { - MXS_ERROR("Error in blr_aes_create_tail_for_cbc"); - finale_ret = 0; + MXS_ERROR("Error in blr_aes_create_tail_for_cbc"); + finale_ret = 0; } } } if (!finale_ret) { - MXS_FREE(outbuf); - outbuf = NULL; + MXS_FREE(outbuf); + outbuf = NULL; } EVP_CIPHER_CTX_cleanup(&ctx); @@ -2919,10 +2936,10 @@ static GWBUF *blr_prepare_encrypted_event(ROUTER_INSTANCE *router, * 5: Copy saved_event_size 4 bytes into encrypted_data + 9 */ - /* (1): Save event size (buf + 9, 4 bytes) */ - memcpy(&event_size, buf + BINLOG_EVENT_LEN_OFFSET, 4); - /* (2): move first 4 bytes of buf to buf + 9 */ - memmove(buf + BINLOG_EVENT_LEN_OFFSET, buf, 4); + /* (1): Save event size (buf + 9, 4 bytes) */ + memcpy(&event_size, buf + BINLOG_EVENT_LEN_OFFSET, 4); + /* (2): move first 4 bytes of buf to buf + 9 */ + memmove(buf + BINLOG_EVENT_LEN_OFFSET, buf, 4); #ifdef SS_DEBUG char iv_hex[AES_BLOCK_SIZE * 2 + 1] = ""; @@ -2938,30 +2955,30 @@ static GWBUF *blr_prepare_encrypted_event(ROUTER_INSTANCE *router, (unsigned long)(pos + size)); #endif - /** - * (3): encrypt the event stored in buf starting from (buf + 4): - * with len (event_size - 4) - * - * NOTE: the encrypted_data buffer returned by blr_aes_encrypt() contains: - * (size - 4) encrypted bytes + (4) bytes event size in clear - * - * The encrypted buffer has same size of the original event (size variable) - */ + /** + * (3): encrypt the event stored in buf starting from (buf + 4): + * with len (event_size - 4) + * + * NOTE: the encrypted_data buffer returned by blr_aes_encrypt() contains: + * (size - 4) encrypted bytes + (4) bytes event size in clear + * + * The encrypted buffer has same size of the original event (size variable) + */ - if ((encrypted = blr_aes_crypt(router, buf + 4, size - 4, iv, action)) == NULL) - { - return NULL; - } + if ((encrypted = blr_aes_crypt(router, buf + 4, size - 4, iv, action)) == NULL) + { + return NULL; + } - enc_ptr = GWBUF_DATA(encrypted); + enc_ptr = GWBUF_DATA(encrypted); - /* (4): move encrypted_data + 9 (4 bytes) to encrypted_data[0] */ - memmove(enc_ptr, enc_ptr + BINLOG_EVENT_LEN_OFFSET, 4); + /* (4): move encrypted_data + 9 (4 bytes) to encrypted_data[0] */ + memmove(enc_ptr, enc_ptr + BINLOG_EVENT_LEN_OFFSET, 4); - /* (5): Copy saved_event_size 4 bytes into encrypted_data + 9 */ - memcpy(enc_ptr + BINLOG_EVENT_LEN_OFFSET, &event_size, 4); + /* (5): Copy saved_event_size 4 bytes into encrypted_data + 9 */ + memcpy(enc_ptr + BINLOG_EVENT_LEN_OFFSET, &event_size, 4); - return encrypted; + return encrypted; } /** @@ -3052,11 +3069,11 @@ static int blr_aes_create_tail_for_cbc(uint8_t *output, /* Initialise with AES_ECB and NULL iv */ if (!EVP_CipherInit_ex(&t_ctx, - ciphers[BLR_AES_ECB](key_len), - NULL, - key, - NULL, /* NULL iv */ - BINLOG_FLAG_ENCRYPT)) + ciphers[BLR_AES_ECB](key_len), + NULL, + key, + NULL, /* NULL iv */ + BINLOG_FLAG_ENCRYPT)) { MXS_ERROR("Error in EVP_CipherInit_ex CBC for last block (ECB)"); EVP_CIPHER_CTX_cleanup(&t_ctx); @@ -3113,13 +3130,13 @@ static int blr_binlog_event_check(ROUTER_INSTANCE *router, { /* event pos & size checks */ if (hdr->event_size == 0 || ((hdr->next_pos != (pos + hdr->event_size)) && - (hdr->event_type != ROTATE_EVENT))) + (hdr->event_type != ROTATE_EVENT))) { snprintf(errmsg, BINLOG_ERROR_MSG_LEN, - "Client requested master to start replication from invalid " - "position %lu in binlog file '%s'", pos, - binlogname); - return 0; + "Client requested master to start replication from invalid " + "position %lu in binlog file '%s'", pos, + binlogname); + return 0; } /* event type checks */ @@ -3132,9 +3149,9 @@ static int blr_binlog_event_check(ROUTER_INSTANCE *router, hdr->event_type, pos, binlogname); return 0; } - } - else - { + } + else + { if (hdr->event_type > MAX_EVENT_TYPE) { snprintf(errmsg, BINLOG_ERROR_MSG_LEN, diff --git a/server/modules/routing/binlogrouter/blr_master.c b/server/modules/routing/binlogrouter/blr_master.c index dd4f56aa6..6d832f395 100644 --- a/server/modules/routing/binlogrouter/blr_master.c +++ b/server/modules/routing/binlogrouter/blr_master.c @@ -724,72 +724,72 @@ blr_master_response(ROUTER_INSTANCE *router, GWBUF *buf) router->master_state = BLRM_REQUEST_BINLOGDUMP; } case BLRM_CHECK_SEMISYNC: - { - /** - * This branch could be reached as fallthrough from BLRM_REGISTER - * if request_semi_sync option is false - */ - if (router->master_state == BLRM_CHECK_SEMISYNC) - { - /* Get master semi-sync installed, enabled, disabled */ - router->master_semi_sync = blr_get_master_semisync(buf); + { + /** + * This branch could be reached as fallthrough from BLRM_REGISTER + * if request_semi_sync option is false + */ + if (router->master_state == BLRM_CHECK_SEMISYNC) + { + /* Get master semi-sync installed, enabled, disabled */ + router->master_semi_sync = blr_get_master_semisync(buf); - /* Discard buffer */ - gwbuf_free(buf); + /* Discard buffer */ + gwbuf_free(buf); - if (router->master_semi_sync == MASTER_SEMISYNC_NOT_AVAILABLE) - { - /* not installed */ - MXS_NOTICE("%s: master server %s:%d doesn't have semi_sync capability", - router->service->name, - router->service->dbref->server->name, - router->service->dbref->server->port); + if (router->master_semi_sync == MASTER_SEMISYNC_NOT_AVAILABLE) + { + /* not installed */ + MXS_NOTICE("%s: master server %s:%d doesn't have semi_sync capability", + router->service->name, + router->service->dbref->server->name, + router->service->dbref->server->port); - /* Continue */ - router->master_state = BLRM_REQUEST_BINLOGDUMP; + /* Continue */ + router->master_state = BLRM_REQUEST_BINLOGDUMP; - } - else - { - if (router->master_semi_sync == MASTER_SEMISYNC_DISABLED) - { - /* Installed but not enabled, right now */ - MXS_NOTICE("%s: master server %s:%d doesn't have semi_sync enabled right now, " - "Requesting Semi-Sync Replication", - router->service->name, - router->service->dbref->server->name, - router->service->dbref->server->port); - } - else - { - /* Installed and enabled */ - MXS_NOTICE("%s: master server %s:%d has semi_sync enabled, Requesting Semi-Sync Replication", - router->service->name, - router->service->dbref->server->name, - router->service->dbref->server->port); - } + } + else + { + if (router->master_semi_sync == MASTER_SEMISYNC_DISABLED) + { + /* Installed but not enabled, right now */ + MXS_NOTICE("%s: master server %s:%d doesn't have semi_sync enabled right now, " + "Requesting Semi-Sync Replication", + router->service->name, + router->service->dbref->server->name, + router->service->dbref->server->port); + } + else + { + /* Installed and enabled */ + MXS_NOTICE("%s: master server %s:%d has semi_sync enabled, Requesting Semi-Sync Replication", + router->service->name, + router->service->dbref->server->name, + router->service->dbref->server->port); + } - buf = blr_make_query(router->master, "SET @rpl_semi_sync_slave = 1"); - router->master_state = BLRM_REQUEST_SEMISYNC; - router->master->func.write(router->master, buf); + buf = blr_make_query(router->master, "SET @rpl_semi_sync_slave = 1"); + router->master_state = BLRM_REQUEST_SEMISYNC; + router->master->func.write(router->master, buf); - break; + break; + } } } - } case BLRM_REQUEST_SEMISYNC: /** * This branch could be reached as fallthrough from BLRM_REGISTER or BLRM_CHECK_SEMISYNC * if request_semi_sync option is false or master doesn't support semisync or it's not enabled */ - if (router->master_state == BLRM_REQUEST_SEMISYNC) - { - /* discard master reply */ - gwbuf_free(buf); + if (router->master_state == BLRM_REQUEST_SEMISYNC) + { + /* discard master reply */ + gwbuf_free(buf); - /* Continue */ - router->master_state = BLRM_REQUEST_BINLOGDUMP; - } + /* Continue */ + router->master_state = BLRM_REQUEST_BINLOGDUMP; + } case BLRM_REQUEST_BINLOGDUMP: /** @@ -1361,7 +1361,7 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt) var_block_len = ptr[MYSQL_HEADER_LEN + 1 + BINLOG_EVENT_HDR_LEN + 4 + 4 + 1 + 2]; statement_len = len - (MYSQL_HEADER_LEN + 1 + BINLOG_EVENT_HDR_LEN + 4 + 4 + 1 + 2 + 2 \ - + var_block_len + 1 + db_name_len); + + var_block_len + 1 + db_name_len); statement_sql = MXS_CALLOC(1, statement_len + 1); MXS_ABORT_IF_NULL(statement_sql); memcpy(statement_sql, @@ -2540,11 +2540,16 @@ blr_get_master_semisync(GWBUF *buf) } free(key); - if (val) { + if (val) + { if (strncasecmp(val, "ON", 4) == 0) + { master_semisync = MASTER_SEMISYNC_ENABLED; + } else + { master_semisync = MASTER_SEMISYNC_DISABLED; + } } free(val); diff --git a/server/modules/routing/binlogrouter/blr_slave.c b/server/modules/routing/binlogrouter/blr_slave.c index 8a9b597d6..7c72215dc 100644 --- a/server/modules/routing/binlogrouter/blr_slave.c +++ b/server/modules/routing/binlogrouter/blr_slave.c @@ -203,7 +203,7 @@ blr_slave_request(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, GWBUF *queue) slave->stats.n_queries++; return blr_slave_query(router, slave, queue); - case COM_REGISTER_SLAVE: + case COM_REGISTER_SLAVE: if (router->master_state == BLRM_UNCONFIGURED) { slave->state = BLRS_ERRORED; @@ -242,7 +242,7 @@ blr_slave_request(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, GWBUF *queue) return blr_slave_register(router, slave, queue); } - case COM_BINLOG_DUMP: + case COM_BINLOG_DUMP: { char task_name[BLRM_TASK_NAME_LEN + 1] = ""; int rc = 0; @@ -826,8 +826,8 @@ blr_slave_query(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, GWBUF *queue) } else { - MXS_FREE(query_text); - return blr_slave_send_ok(router, slave); + MXS_FREE(query_text); + return blr_slave_send_ok(router, slave); } } } /* RESET current configured master */ @@ -1092,8 +1092,8 @@ blr_slave_query(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, GWBUF *queue) MXS_INFO("%s: created new binlog file '%s' by 'CHANGE MASTER TO' command", router->service->name, router->binlog_name); } - } - return blr_slave_send_ok(router, slave); + } + return blr_slave_send_ok(router, slave); } } } @@ -1506,7 +1506,8 @@ blr_slave_send_slave_status(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave) memcpy((char *)ptr, column, col_len); // Result string ptr += col_len; - snprintf(column, max_column_size, "%s", router->service->dbref->server->name ? router->service->dbref->server->name : ""); + snprintf(column, max_column_size, "%s", + router->service->dbref->server->name ? router->service->dbref->server->name : ""); col_len = strlen(column); *ptr++ = col_len; // Length of result string memcpy((char *)ptr, column, col_len); // Result string @@ -2384,48 +2385,48 @@ blr_slave_catchup(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, bool large) * * Read it if slave->encryption_ctx is NULL and set the slave->encryption_ctx accordingly */ - spinlock_acquire(&slave->catch_lock); + spinlock_acquire(&slave->catch_lock); - if (hdr.event_type == MARIADB10_START_ENCRYPTION_EVENT && !slave->encryption_ctx) - { - /* read it, set slave & file context */ - uint8_t *record_ptr = GWBUF_DATA(record); - SLAVE_ENCRYPTION_CTX *encryption_ctx = MXS_CALLOC(1, sizeof(SLAVE_ENCRYPTION_CTX)); + if (hdr.event_type == MARIADB10_START_ENCRYPTION_EVENT && !slave->encryption_ctx) + { + /* read it, set slave & file context */ + uint8_t *record_ptr = GWBUF_DATA(record); + SLAVE_ENCRYPTION_CTX *encryption_ctx = MXS_CALLOC(1, sizeof(SLAVE_ENCRYPTION_CTX)); - MXS_ABORT_IF_NULL(encryption_ctx); - record_ptr += BINLOG_EVENT_HDR_LEN; - encryption_ctx->binlog_crypto_scheme = record_ptr[0]; - memcpy(&encryption_ctx->binlog_key_version, record_ptr + 1, BLRM_KEY_VERSION_LENGTH); - memcpy(encryption_ctx->nonce, record_ptr + 1 + BLRM_KEY_VERSION_LENGTH, BLRM_NONCE_LENGTH); + MXS_ABORT_IF_NULL(encryption_ctx); + record_ptr += BINLOG_EVENT_HDR_LEN; + encryption_ctx->binlog_crypto_scheme = record_ptr[0]; + memcpy(&encryption_ctx->binlog_key_version, record_ptr + 1, BLRM_KEY_VERSION_LENGTH); + memcpy(encryption_ctx->nonce, record_ptr + 1 + BLRM_KEY_VERSION_LENGTH, BLRM_NONCE_LENGTH); - /* Save current first_enc_event_pos */ - encryption_ctx->first_enc_event_pos = hdr.next_pos; + /* Save current first_enc_event_pos */ + encryption_ctx->first_enc_event_pos = hdr.next_pos; - /* set the encryption ctx into slave */ - slave->encryption_ctx = encryption_ctx; + /* set the encryption ctx into slave */ + slave->encryption_ctx = encryption_ctx; - MXS_INFO("Start Encryption event found while reading. Binlog %s is encrypted. First event at %lu", - slave->binlogfile, - (unsigned long) hdr.next_pos); - } - else - { - MXS_INFO("Found ignorable event [%s] of size %lu while reading binlog %s at %lu", - blr_get_event_description(router, hdr.event_type), - (unsigned long)hdr.event_size, - slave->binlogfile, - (unsigned long) slave->binlog_pos); - } + MXS_INFO("Start Encryption event found while reading. Binlog %s is encrypted. First event at %lu", + slave->binlogfile, + (unsigned long) hdr.next_pos); + } + else + { + MXS_INFO("Found ignorable event [%s] of size %lu while reading binlog %s at %lu", + blr_get_event_description(router, hdr.event_type), + (unsigned long)hdr.event_size, + slave->binlogfile, + (unsigned long) slave->binlog_pos); + } - /* set next pos */ - slave->binlog_pos = hdr.next_pos; + /* set next pos */ + slave->binlog_pos = hdr.next_pos; - spinlock_release(&slave->catch_lock); + spinlock_release(&slave->catch_lock); - gwbuf_free(record); - record = NULL; + gwbuf_free(record); + record = NULL; - break; + break; } if (hdr.event_type == ROTATE_EVENT) @@ -2527,7 +2528,7 @@ blr_slave_catchup(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, bool large) /** * End of while reading * Checking last buffer first - */ + */ if (record == NULL) { slave->stats.n_failed_read++; @@ -3333,7 +3334,8 @@ static int blr_slave_send_ok(ROUTER_INSTANCE* router, ROUTER_SLAVE* slave) { GWBUF *pkt; - uint8_t ok_packet[] = { + uint8_t ok_packet[] = + { 7, 0, 0, // Payload length 1, // Seqno, 0, // OK, @@ -3616,7 +3618,7 @@ blr_start_slave(ROUTER_INSTANCE* router, ROUTER_SLAVE* slave) } } - /** Start replication from master */ + /** Start replication from master */ blr_start_master(router); MXS_NOTICE("%s: START SLAVE executed by %s@%s. Trying connection to master %s:%d, " @@ -3726,7 +3728,7 @@ int blr_handle_change_master(ROUTER_INSTANCE* router, char *command, char *error if ((cmd_string = MXS_STRDUP(cmd_ptr + 2)) == NULL) { - static const char MESSAGE[] ="error allocating memory for statement parsing"; + static const char MESSAGE[] = "error allocating memory for statement parsing"; ss_dassert(sizeof(MESSAGE) <= BINLOG_ERROR_MSG_LEN); strcpy(error, MESSAGE); @@ -3807,23 +3809,24 @@ int blr_handle_change_master(ROUTER_INSTANCE* router, char *command, char *error { if (change_master.ssl_enabled && atoi(change_master.ssl_enabled)) { - snprintf(error, BINLOG_ERROR_MSG_LEN, "MASTER_SSL=1 but some required options are missing: check MASTER_SSL_CERT, MASTER_SSL_KEY, MASTER_SSL_CA"); + snprintf(error, BINLOG_ERROR_MSG_LEN, + "MASTER_SSL=1 but some required options are missing: check MASTER_SSL_CERT, MASTER_SSL_KEY, MASTER_SSL_CA"); ssl_error = -1; } } if (ssl_error == -1) { - MXS_ERROR("%s: %s", router->service->name, error); + MXS_ERROR("%s: %s", router->service->name, error); - /* restore previous master_host and master_port */ - blr_master_restore_config(router, current_master); + /* restore previous master_host and master_port */ + blr_master_restore_config(router, current_master); - blr_master_free_parsed_options(&change_master); + blr_master_free_parsed_options(&change_master); - spinlock_release(&router->lock); + spinlock_release(&router->lock); - return -1; + return -1; } /** @@ -5680,7 +5683,7 @@ blr_escape_config_string(char *input) } else { - if (ptr+1) + if (ptr + 1) { ptr++; } @@ -5814,16 +5817,20 @@ blr_set_master_ssl(ROUTER_INSTANCE *router, CHANGE_MASTER_OPTIONS config, char * } if (updated) + { return 1; + } else + { return 0; + } } /** * Notify a waiting slave that new events are stored in binlog file * * @param slave Current connected slave - * @return true if slave has been notified + * @return true if slave has been notified * */ bool blr_notify_waiting_slave(ROUTER_SLAVE *slave) diff --git a/server/modules/routing/binlogrouter/maxbinlogcheck.c b/server/modules/routing/binlogrouter/maxbinlogcheck.c index 73b805cb8..ddaaac5d2 100644 --- a/server/modules/routing/binlogrouter/maxbinlogcheck.c +++ b/server/modules/routing/binlogrouter/maxbinlogcheck.c @@ -252,7 +252,7 @@ printUsage(const char *progname) * * @param inst The current binlog instance * @param key_file The AES Key filename - * @param aes_algo The AES algorithm + * @param aes_algo The AES algorithm * @return 1 on failure, 0 on success */ static int set_encryption_options(ROUTER_INSTANCE *inst, char *key_file, char *aes_algo) @@ -273,34 +273,34 @@ static int set_encryption_options(ROUTER_INSTANCE *inst, char *key_file, char *a } else { - /* Check aes algorithm */ - if (aes_algo) - { - int ret = blr_check_encryption_algorithm(aes_algo); - if (ret > -1) - { - inst->encryption.encryption_algorithm = ret; - } - else - { - MXS_ERROR("Invalid encryption_algorithm '%s'. " - "Supported algorithms: %s", - aes_algo, - blr_encryption_algorithm_list()); - return 1; - } - } - else - { - inst->encryption.encryption_algorithm = BINLOG_DEFAULT_ENC_ALGO; - } + /* Check aes algorithm */ + if (aes_algo) + { + int ret = blr_check_encryption_algorithm(aes_algo); + if (ret > -1) + { + inst->encryption.encryption_algorithm = ret; + } + else + { + MXS_ERROR("Invalid encryption_algorithm '%s'. " + "Supported algorithms: %s", + aes_algo, + blr_encryption_algorithm_list()); + return 1; + } + } + else + { + inst->encryption.encryption_algorithm = BINLOG_DEFAULT_ENC_ALGO; + } - MXS_NOTICE("Decrypting binlog file with algorithm: %s," - " KEY len %lu bits", - blr_get_encryption_algorithm(inst->encryption.encryption_algorithm), - 8 * inst->encryption.key_len); + MXS_NOTICE("Decrypting binlog file with algorithm: %s," + " KEY len %lu bits", + blr_get_encryption_algorithm(inst->encryption.encryption_algorithm), + 8 * inst->encryption.key_len); - return 0; + return 0; } } else diff --git a/server/modules/routing/binlogrouter/test/testbinlog.c b/server/modules/routing/binlogrouter/test/testbinlog.c index bf1100202..c9b936ae0 100644 --- a/server/modules/routing/binlogrouter/test/testbinlog.c +++ b/server/modules/routing/binlogrouter/test/testbinlog.c @@ -16,8 +16,8 @@ * * Revision History * - * Date Who Description - * 24/08/2015 Massimiliano Pinto Initial implementation + * Date Who Description + * 24/08/2015 Massimiliano Pinto Initial implementation * * @endverbatim */ @@ -53,525 +53,657 @@ static void printVersion(const char *progname); static void printUsage(const char *progname); -extern int blr_test_parse_change_master_command(char *input, char *error_string, CHANGE_MASTER_OPTIONS *config); +extern int blr_test_parse_change_master_command(char *input, char *error_string, + CHANGE_MASTER_OPTIONS *config); extern char *blr_test_set_master_logfile(ROUTER_INSTANCE *router, char *filename, char *error); extern int blr_test_handle_change_master(ROUTER_INSTANCE* router, char *command, char *error); -static struct option long_options[] = { - {"debug", no_argument, 0, 'd'}, - {"verbose", no_argument, 0, 'v'}, - {"version", no_argument, 0, 'V'}, - {"fix", no_argument, 0, 'f'}, - {"help", no_argument, 0, '?'}, - {0, 0, 0, 0} +static struct option long_options[] = +{ + {"debug", no_argument, 0, 'd'}, + {"verbose", no_argument, 0, 'v'}, + {"version", no_argument, 0, 'V'}, + {"fix", no_argument, 0, 'f'}, + {"help", no_argument, 0, '?'}, + {0, 0, 0, 0} }; -int main(int argc, char **argv) { - ROUTER_INSTANCE *inst; - int ret; - int rc; - char error_string[BINLOG_ERROR_MSG_LEN + 1] = ""; - CHANGE_MASTER_OPTIONS change_master; - char query[255+1]=""; - char saved_query[255+1]=""; - int command_offset = strlen("CHANGE MASTER TO"); - char *master_log_file = NULL; - char *master_log_pos = NULL; - SERVICE *service; - char *roptions; - int tests = 1; - - roptions = MXS_STRDUP_A("server-id=3,heartbeat=200,binlogdir=/not_exists/my_dir," - "transaction_safety=1,master_version=5.6.99-common," - "master_hostname=common_server,master_uuid=xxx-fff-cccc-fff,master-id=999"); - - mxs_log_init(NULL, NULL, MXS_LOG_TARGET_DEFAULT); - - mxs_log_set_priority_enabled(LOG_DEBUG, false); - mxs_log_set_priority_enabled(LOG_INFO, false); - mxs_log_set_priority_enabled(LOG_NOTICE, false); - mxs_log_set_priority_enabled(LOG_ERR, false); - - set_libdir(MXS_STRDUP_A("..")); - service = service_alloc("test_service", "binlogrouter"); - service->credentials.name = MXS_STRDUP_A("foo"); - service->credentials.authdata = MXS_STRDUP_A("bar"); - - { - char *lasts; - SERVER *server; - char *s = strtok_r(roptions, ",", &lasts); - while (s) - { - serviceAddRouterOption(service, s); - s = strtok_r(NULL, ",", &lasts); - } - set_libdir(MXS_STRDUP_A("../../../authenticator/")); - server = server_alloc("binlog_router_master_host", "_none_", 3306, - "MySQLBackend", "MySQLBackendAuth", NULL); - if (server == NULL) { - return 1; - } - - serviceAddBackend(service, server); - } - - if ((inst = MXS_CALLOC(1, sizeof(ROUTER_INSTANCE))) == NULL) { - mxs_log_flush_sync(); - mxs_log_finish(); - - return 1; - } - - inst->service = service; - inst->user = service->credentials.name; - inst->password = service->credentials.authdata; - - MXS_NOTICE("testbinlog v1.0"); - - if (inst->fileroot == NULL) - inst->fileroot = MXS_STRDUP_A(BINLOG_NAME_ROOT); - if (!inst->current_pos) - inst->current_pos = 4; - - /******************************************** - * - * First test suite is about syntax parsing - * - ********************************************/ - - printf("--------- CHANGE MASTER TO parsing tests ---------\n"); - /** - * Test 1: no given options - * - * Expected rc is 1, if 0 test fails - */ - strcpy(error_string, ""); - strcpy(query, "CHANGE MASTER TO" + command_offset); - /* Expected rc is 1, if 0 test fails */ - rc = blr_test_parse_change_master_command(query, error_string, &change_master); - if (rc == 0) { - printf("Test %d: no options for [%s] FAILED\n", tests, query); - return 1; - } else printf("Test %d PASSED, no given options for [%s]\n", tests, query); - - tests++; - - /** - * Test 2: 1 wrong option without value - * - * Expected rc is 1, if 0 test fails - */ - strcpy(error_string, ""); - strcpy(query, "CHANGE MASTER TO X" + command_offset); - /* Expected rc is 1, if 0 test fails */ - rc = blr_test_parse_change_master_command(query, error_string, &change_master); - if (rc == 0) { - printf("Test %d: wrong options for [%s] FAILED\n", tests, query); - return 1; - } else printf("Test %d PASSED, wrong options for [%s]\n", tests, query); - - tests++; - - /** - * Test 3: 1 wrong option with missing value after = - * - * Expected rc is 1, if 0 test fails - */ - strcpy(error_string, ""); - strcpy(query, "CHANGE MASTER TO X=" + command_offset); - strcpy(saved_query, query); - rc = blr_test_parse_change_master_command(query, error_string, &change_master); - if (rc == 0) { - printf("Test %d: wrong options for [%s] FAILED\n", tests, saved_query); - return 1; - } else printf("Test %d PASSED, wrong options for [%s]\n", tests, saved_query); - - tests++; - - /** - * Test 4: 1 wrong option with missing value after = - * - * Expected rc is 1, if 0 test fails - */ - strcpy(error_string, ""); - strcpy(query, "CHANGE MASTER TO X =" + command_offset); - strcpy(saved_query, query); - rc = blr_test_parse_change_master_command(query, error_string, &change_master); - if (rc == 0) { - printf("Test %d: wrong options for [%s] FAILED\n", tests, saved_query); - return 1; - } else printf("Test %d PASSED, wrong options for [%s]\n", tests, saved_query); - - tests++; - - /** - * Test 5: 1 wrong option with missing value after = - * - * Expected rc is 1, if 0 test fails - */ - strcpy(error_string, ""); - strcpy(query, "CHANGE MASTER TO X= " + command_offset); - strcpy(saved_query, query); - rc = blr_test_parse_change_master_command(query, error_string, &change_master); - if (rc == 0) { - printf("Test %d: wrong options for [%s] FAILED\n", tests, saved_query); - return 1; - } else printf("Test %d PASSED, wrong options for [%s]\n", tests, saved_query); - - tests++; - - /** - * Test 6: 1 wrong option with missing value after = - * - * Expected rc is 1, if 0 test fails - */ - strcpy(error_string, ""); - strcpy(query, "CHANGE MASTER TO X = " + command_offset); - strcpy(saved_query, query); - rc = blr_test_parse_change_master_command(query, error_string, &change_master); - if (rc == 0) { - printf("Test %d: wrong options for [%s] FAILED\n", tests, saved_query); - return 1; - } else printf("Test %d PASSED, wrong options for [%s]\n", tests, saved_query); - - tests++; - - /** - * Test 7: 1 valid option with missing value - * - * Expected rc is 1, if 0 test fails - */ - strcpy(error_string, ""); - strcpy(query, "CHANGE MASTER TO MasTER_hoST" + command_offset); - strcpy(saved_query, query); - rc = blr_test_parse_change_master_command(query, error_string, &change_master); - if (rc == 0) { - printf("Test %d: wrong options for [%s] FAILED\n", tests, saved_query); - return 1; - } else printf("Test %d PASSED, wrong options for [%s]\n", tests, saved_query); - - tests++; - - /** - * Test 8: 1 valid option with missing value - * - * Expected rc is 1, if 0 test fails - */ - strcpy(error_string, ""); - strcpy(query, "CHANGE MASTER TO MasTER_hoST = " + command_offset); - strcpy(saved_query, query); - rc = blr_test_parse_change_master_command(query, error_string, &change_master); - if (rc == 0) { - printf("Test %d: wrong options for [%s] FAILED\n", tests, saved_query); - return 1; - } else printf("Test %d PASSED, wrong options for [%s]\n", tests, saved_query); - - tests++; - - /** - * Test 9: 1 valid option with value - * - * Expected rc is 0, if 1 test fails - */ - strcpy(error_string, ""); - strcpy(query, "CHANGE MASTER TO MasTER_hoST = '127.0.0.1'" + command_offset); - strcpy(saved_query, query); - rc = blr_test_parse_change_master_command(query, error_string, &change_master); - if (rc == 1) { - printf("Test %d: valid option for [%s] FAILED\n", tests, saved_query); - return 1; - } else printf("Test %d PASSED, valid options for [%s]\n", tests, saved_query); - - tests++; - - /** - * Test 10: 1 valid option and 2 invalid ones - * - * Expected rc is 1, if 0 test fails - */ - strcpy(error_string, ""); - strcpy(query, "CHANGE MASTER TO MasTER_hoST = '127.0.0.1', Y, X" + command_offset); - strcpy(saved_query, query); - rc = blr_test_parse_change_master_command(query, error_string, &change_master); - if (rc == 0) { - printf("Test %d: valid / not valid options for [%s] FAILED\n", tests, saved_query); - return 1; - } else printf("Test %d PASSED, valid / not valid options for [%s]\n", tests, saved_query); - - tests++; - - /** - * Test 11: 1 valid option and 1 with missing value - * - * Expected rc is 1, if 0 test fails - */ - strcpy(error_string, ""); - strcpy(query, "CHANGE MASTER TO MasTER_hoST = '127.0.0.1', MASTER_PORT=" + command_offset); - strcpy(saved_query, query); - rc = blr_test_parse_change_master_command(query, error_string, &change_master); - if (rc == 0) { - printf("Test %d: valid / not valid options for [%s] FAILED\n", tests, saved_query); - return 1; - } else printf("Test %d PASSED, valid / not valid options for [%s]\n", tests, saved_query); - - tests++; - - /** - * Test 12: 2 valid options - * - * Expected rc is 0, if 1 test fails - */ - strcpy(error_string, ""); - strcpy(query, "CHANGE MASTER TO MasTER_hoST = '127.0.0.1', MASTER_PORT=9999" + command_offset); - strcpy(saved_query, query); - rc = blr_test_parse_change_master_command(query, error_string, &change_master); - if (rc == 1) { - printf("Test %d: valid options for [%s] FAILED\n", tests, saved_query); - return 1; - } else printf("Test %d PASSED, valid options for [%s]\n", tests, saved_query); - - tests++; - - /** - * Test 13: 2 valid options and 1 invalid - * - * Expected rc is 1, if 0 test fails - */ - strcpy(error_string, ""); - strcpy(query, "CHANGE MASTER TO MasTER_hoST = '127.0.0.1', MASTER_PORT=9999, MASTER_PASSWD='massi'" + command_offset); - strcpy(saved_query, query); - rc = blr_test_parse_change_master_command(query, error_string, &change_master); - if (rc == 0) { - printf("Test %d: valid / not valid options for [%s] FAILED\n", tests, saved_query); - return 1; - } else printf("Test %d PASSED, valid / not valid options for [%s]\n", tests, saved_query); - - tests++; - - /** - * Test 14: 3 valid options - * - * Expected rc is 0, if 1 test fails - */ - strcpy(error_string, ""); - strcpy(query, "CHANGE MASTER TO MasTER_hoST = '127.0.0.1', MASTER_PORT=9999, MASTER_PASSWORD='massi'" + command_offset); - strcpy(saved_query, query); - rc = blr_test_parse_change_master_command(query, error_string, &change_master); - if (rc == 1) { - printf("Test %d: valid options [%s] FAILED\n", tests, saved_query); - return 1; - } else printf("Test %d PASSED, valid options for [%s]\n", tests, saved_query); - - tests++; - - /** - * Test 15: 5 valid options and 1 invalid - * - * Expected rc is 1, if 0 test fails - */ - strcpy(error_string, ""); - strcpy(query, "CHANGE MASTER TO MasTER_hoST = '127.0.0.1', MASTER_PORT=9999, MASTER_PASSWORD='massi', MAster_user='eee', master_log_fil= 'fffff', master_log_pos= 55" + command_offset); - strcpy(saved_query, query); - rc = blr_test_parse_change_master_command(query, error_string, &change_master); - if (rc == 0) { - printf("Test %d: valid / not valid options for [%s] FAILED\n", tests, saved_query); - return 1; - } else printf("Test %d PASSED, valid / not valid options for [%s]\n", tests, saved_query); - - tests++; - - /** - * Test 16: 6 valid options - * - * Expected rc is 0, if 1 test fails - */ - strcpy(error_string, ""); - memset(&change_master, 0, sizeof(change_master)); - strcpy(query, "CHANGE MASTER TO MasTER_hoST = '127.0.0.1', MASTER_PORT=9999, MASTER_PASSWORD='massi', MAster_user='eee', master_log_file= 'fffff', master_log_pos= 55" + command_offset); - strcpy(saved_query, query); - rc = blr_test_parse_change_master_command(query, error_string, &change_master); - if (rc == 1) { - printf("Test %d: valid options [%s] FAILED\n", tests, saved_query); - return 1; - } else printf("Test %d PASSED, valid options for [%s]\n", tests, saved_query); - - tests++; - - printf("--------- MASTER_LOG_FILE tests ---------\n"); - - /** - * Test 17: use current binlog filename in master_state != BLRM_UNCONFIGURED - * and try to set a new filename with wront format from previous test - * - * Expected master_log_file is NULL and error_string is not empty - */ - inst->master_state = BLRM_SLAVE_STOPPED; - strcpy(error_string, ""); - - master_log_file = blr_test_set_master_logfile(inst, change_master.binlog_file, error_string); - - if (master_log_file == NULL) { - if (strlen(error_string)) { - printf("Test %d PASSED, MASTER_LOG_FILE [%s]: [%s]\n", tests, change_master.binlog_file, error_string); - } else { - printf("Test %d: set MASTER_LOG_FILE [%s] FAILED, an error message was expected\n", tests, change_master.binlog_file); - return 1; - } - } else { - printf("Test %d: set MASTER_LOG_FILE [%s] FAILED, NULL was expected from blr_test_set_master_logfile()\n", tests, change_master.binlog_file); - return 1; - } - - tests++; - - printf("--- MASTER_LOG_POS and MASTER_LOG_FILE rule/constraints checks ---\n"); - - /******************************************** - * - * Second part of test suite is for checking - * rules and constraints once syntax is OK - * - ********************************************/ - - /** - * Test 18: change master without MASTER_LOG_FILE in BLRM_UNCONFIGURED state - * - * Expected rc = -1 and master_state still set to BLRM_UNCONFIGURED - */ - inst->master_state = BLRM_UNCONFIGURED; - strcpy(error_string, ""); - strcpy(query, "CHANGE MASTER TO MasTER_hoST = '127.0.0.1', MASTER_PORT=9999, MASTER_PASSWORD='massi', MAster_user='eee', master_log_pos= 55"); - - rc = blr_test_handle_change_master(inst, query, error_string); - - if (rc == -1 && inst->master_state == BLRM_UNCONFIGURED) { - printf("Test %d PASSED, in BLRM_UNCONFIGURED state. Message [%s]\n", tests, error_string); - } else { - printf("Test %d: an error message was expected from blr_test_handle_change_master(), Master State is %s. Message [%s]\n", tests, blrm_states[inst->master_state], error_string); - return 1; - } - - tests++; - - /** - * Test 19: use selected binlog filename in BLRM_UNCONFIGURED state - * - * Expected rc = -1 and master_state still set to BLRM_UNCONFIGURED - */ - - inst->master_state = BLRM_UNCONFIGURED; - strcpy(error_string, ""); - strcpy(query, "CHANGE MASTER TO MasTER_hoST = '127.0.0.1', MASTER_PORT=9999, MASTER_PASSWORD='massi', MAster_user='eee', master_log_file= 'file.000053', master_log_pos= 1855"); - - rc = blr_test_handle_change_master(inst, query, error_string); - - if (rc == -1 && inst->master_state == BLRM_UNCONFIGURED) { - printf("Test %d PASSED, cannot set MASTER_LOG_FILE in BLRM_UNCONFIGURED state for [%s]. Message [%s]\n", tests, query, error_string); - } else { - printf("Test %d: set MASTER_LOG_FILE in BLRM_UNCONFIGURED state FAILED, an error message was expected from blr_test_handle_change_master(), Master State is %s. Message [%s]\n", tests, blrm_states[inst->master_state], error_string); - return 1; - } - - tests++; - - /** - * Test 20: use selected binlog filename and pos in state != BLRM_UNCONFIGURED - * Current binlog and pos are same specified in the change master command - * - * Expected rc = 0 - */ - inst->master_state = BLRM_UNCONNECTED; - strcpy(error_string, ""); - strncpy(inst->binlog_name, "file-bin.00008", BINLOG_FNAMELEN); - inst->current_pos = 55; - strcpy(query, "CHANGE MASTER TO MasTER_hoST = '127.0.0.1', MASTER_PORT=9999, MASTER_PASSWORD='massi', MAster_user='eee', master_log_file= 'file-bin.00008', master_log_pos= 55"); - - rc = blr_test_handle_change_master(inst, query, error_string); - - if (rc == 0) { - printf("Test %d PASSED, set MASTER_LOG_FILE and MASTER_LOG_POS for [%s]\n", tests, query); - } else { - printf("Test %d: set MASTER_LOG_FILE and MASTER_LOG_POS FAILED, Master State is %s. Message [%s]\n", tests, blrm_states[inst->master_state], error_string); - return 1; - } - - tests++; - - /** - * Test 21: use selected binlog filename and pos in state != BLRM_UNCONFIGURED - * Current binlog is not the one specified in the change master command - * - * Expected rc = -1 - */ - - strncpy(inst->binlog_name, "file.000006", BINLOG_FNAMELEN); - inst->current_pos = 10348; - strcpy(inst->fileroot, "file"); - strcpy(error_string, ""); - inst->master_state = BLRM_UNCONNECTED; - strcpy(query, "CHANGE MASTER TO MasTER_hoST = '127.0.0.1', MASTER_PORT=9999, MASTER_PASSWORD='massi', MAster_user='eee', MASTER_LOG_file ='mmmm.098777', master_log_pos= 55"); - - rc = blr_test_handle_change_master(inst, query, error_string); - - if (rc == -1) { - printf("Test %d PASSED, cannot set MASTER_LOG_FILE for [%s], Message [%s]\n", tests, query, error_string); - } else { - printf("Test %d: set MASTER_LOG_FILE, Master State is %s Failed, Message [%s]\n", tests, blrm_states[inst->master_state], error_string); - return 1; - } - - tests++; - - /** - * Test 22: use selected binlog filename is next one in sequence and specified pos is 4 - * in any state - * - * Expected rc >= 0 - */ - strcpy(error_string, ""); - strncpy(inst->binlog_name, "file.100506", BINLOG_FNAMELEN); - inst->current_pos = 1348; - strcpy(inst->fileroot, "file"); - strcpy(query, "CHANGE MASTER TO master_log_pos= 4 , master_log_file='file.100507'"); - - rc = blr_test_handle_change_master(inst, query, error_string); - - if (rc >= 0) { - printf("Test %d PASSED, set MASTER_LOG_FILE for [%s]\n", tests, query); - } else { - printf("Test %d: set MASTER_LOG_FILE FAILED, Master State is %s. Message [%s]\n", tests, blrm_states[inst->master_state], error_string); - return 1; - } - - tests++; - - /** - * Test 23: use selected pos that's not the current one - * in state != BLRM_UNCONFIGURED - * - * Expected rc = -1 - */ - inst->master_state = BLRM_UNCONNECTED; - strcpy(error_string, ""); - strncpy(inst->binlog_name, "file.100506", BINLOG_FNAMELEN); - inst->current_pos = 138; - strcpy(inst->fileroot, "file"); - strcpy(query, "CHANGE MASTER TO master_log_pos= 49 "); - - rc = blr_test_handle_change_master(inst, query, error_string); - - if (rc == -1) { - printf("Test %d PASSED, cannot set MASTER_LOG_POS for [%s], Message [%s]\n", tests, query, error_string); - } else { - printf("Test %d: set MASTER_LOG_POS FAILED, Master State is %s. Message [%s]\n", tests, blrm_states[inst->master_state], error_string); - return 1; - } - - mxs_log_flush_sync(); - mxs_log_finish(); - - MXS_FREE(inst); - - return 0; +int main(int argc, char **argv) +{ + ROUTER_INSTANCE *inst; + int ret; + int rc; + char error_string[BINLOG_ERROR_MSG_LEN + 1] = ""; + CHANGE_MASTER_OPTIONS change_master; + char query[255 + 1] = ""; + char saved_query[255 + 1] = ""; + int command_offset = strlen("CHANGE MASTER TO"); + char *master_log_file = NULL; + char *master_log_pos = NULL; + SERVICE *service; + char *roptions; + int tests = 1; + + roptions = MXS_STRDUP_A("server-id=3,heartbeat=200,binlogdir=/not_exists/my_dir," + "transaction_safety=1,master_version=5.6.99-common," + "master_hostname=common_server,master_uuid=xxx-fff-cccc-fff,master-id=999"); + + mxs_log_init(NULL, NULL, MXS_LOG_TARGET_DEFAULT); + + mxs_log_set_priority_enabled(LOG_DEBUG, false); + mxs_log_set_priority_enabled(LOG_INFO, false); + mxs_log_set_priority_enabled(LOG_NOTICE, false); + mxs_log_set_priority_enabled(LOG_ERR, false); + + set_libdir(MXS_STRDUP_A("..")); + service = service_alloc("test_service", "binlogrouter"); + service->credentials.name = MXS_STRDUP_A("foo"); + service->credentials.authdata = MXS_STRDUP_A("bar"); + + { + char *lasts; + SERVER *server; + char *s = strtok_r(roptions, ",", &lasts); + while (s) + { + serviceAddRouterOption(service, s); + s = strtok_r(NULL, ",", &lasts); + } + set_libdir(MXS_STRDUP_A("../../../authenticator/")); + server = server_alloc("binlog_router_master_host", "_none_", 3306, + "MySQLBackend", "MySQLBackendAuth", NULL); + if (server == NULL) + { + return 1; + } + + serviceAddBackend(service, server); + } + + if ((inst = MXS_CALLOC(1, sizeof(ROUTER_INSTANCE))) == NULL) + { + mxs_log_flush_sync(); + mxs_log_finish(); + + return 1; + } + + inst->service = service; + inst->user = service->credentials.name; + inst->password = service->credentials.authdata; + + MXS_NOTICE("testbinlog v1.0"); + + if (inst->fileroot == NULL) + { + inst->fileroot = MXS_STRDUP_A(BINLOG_NAME_ROOT); + } + if (!inst->current_pos) + { + inst->current_pos = 4; + } + + /******************************************** + * + * First test suite is about syntax parsing + * + ********************************************/ + + printf("--------- CHANGE MASTER TO parsing tests ---------\n"); + /** + * Test 1: no given options + * + * Expected rc is 1, if 0 test fails + */ + strcpy(error_string, ""); + strcpy(query, "CHANGE MASTER TO" + command_offset); + /* Expected rc is 1, if 0 test fails */ + rc = blr_test_parse_change_master_command(query, error_string, &change_master); + if (rc == 0) + { + printf("Test %d: no options for [%s] FAILED\n", tests, query); + return 1; + } + else + { + printf("Test %d PASSED, no given options for [%s]\n", tests, query); + } + + tests++; + + /** + * Test 2: 1 wrong option without value + * + * Expected rc is 1, if 0 test fails + */ + strcpy(error_string, ""); + strcpy(query, "CHANGE MASTER TO X" + command_offset); + /* Expected rc is 1, if 0 test fails */ + rc = blr_test_parse_change_master_command(query, error_string, &change_master); + if (rc == 0) + { + printf("Test %d: wrong options for [%s] FAILED\n", tests, query); + return 1; + } + else + { + printf("Test %d PASSED, wrong options for [%s]\n", tests, query); + } + + tests++; + + /** + * Test 3: 1 wrong option with missing value after = + * + * Expected rc is 1, if 0 test fails + */ + strcpy(error_string, ""); + strcpy(query, "CHANGE MASTER TO X=" + command_offset); + strcpy(saved_query, query); + rc = blr_test_parse_change_master_command(query, error_string, &change_master); + if (rc == 0) + { + printf("Test %d: wrong options for [%s] FAILED\n", tests, saved_query); + return 1; + } + else + { + printf("Test %d PASSED, wrong options for [%s]\n", tests, saved_query); + } + + tests++; + + /** + * Test 4: 1 wrong option with missing value after = + * + * Expected rc is 1, if 0 test fails + */ + strcpy(error_string, ""); + strcpy(query, "CHANGE MASTER TO X =" + command_offset); + strcpy(saved_query, query); + rc = blr_test_parse_change_master_command(query, error_string, &change_master); + if (rc == 0) + { + printf("Test %d: wrong options for [%s] FAILED\n", tests, saved_query); + return 1; + } + else + { + printf("Test %d PASSED, wrong options for [%s]\n", tests, saved_query); + } + + tests++; + + /** + * Test 5: 1 wrong option with missing value after = + * + * Expected rc is 1, if 0 test fails + */ + strcpy(error_string, ""); + strcpy(query, "CHANGE MASTER TO X= " + command_offset); + strcpy(saved_query, query); + rc = blr_test_parse_change_master_command(query, error_string, &change_master); + if (rc == 0) + { + printf("Test %d: wrong options for [%s] FAILED\n", tests, saved_query); + return 1; + } + else + { + printf("Test %d PASSED, wrong options for [%s]\n", tests, saved_query); + } + + tests++; + + /** + * Test 6: 1 wrong option with missing value after = + * + * Expected rc is 1, if 0 test fails + */ + strcpy(error_string, ""); + strcpy(query, "CHANGE MASTER TO X = " + command_offset); + strcpy(saved_query, query); + rc = blr_test_parse_change_master_command(query, error_string, &change_master); + if (rc == 0) + { + printf("Test %d: wrong options for [%s] FAILED\n", tests, saved_query); + return 1; + } + else + { + printf("Test %d PASSED, wrong options for [%s]\n", tests, saved_query); + } + + tests++; + + /** + * Test 7: 1 valid option with missing value + * + * Expected rc is 1, if 0 test fails + */ + strcpy(error_string, ""); + strcpy(query, "CHANGE MASTER TO MasTER_hoST" + command_offset); + strcpy(saved_query, query); + rc = blr_test_parse_change_master_command(query, error_string, &change_master); + if (rc == 0) + { + printf("Test %d: wrong options for [%s] FAILED\n", tests, saved_query); + return 1; + } + else + { + printf("Test %d PASSED, wrong options for [%s]\n", tests, saved_query); + } + + tests++; + + /** + * Test 8: 1 valid option with missing value + * + * Expected rc is 1, if 0 test fails + */ + strcpy(error_string, ""); + strcpy(query, "CHANGE MASTER TO MasTER_hoST = " + command_offset); + strcpy(saved_query, query); + rc = blr_test_parse_change_master_command(query, error_string, &change_master); + if (rc == 0) + { + printf("Test %d: wrong options for [%s] FAILED\n", tests, saved_query); + return 1; + } + else + { + printf("Test %d PASSED, wrong options for [%s]\n", tests, saved_query); + } + + tests++; + + /** + * Test 9: 1 valid option with value + * + * Expected rc is 0, if 1 test fails + */ + strcpy(error_string, ""); + strcpy(query, "CHANGE MASTER TO MasTER_hoST = '127.0.0.1'" + command_offset); + strcpy(saved_query, query); + rc = blr_test_parse_change_master_command(query, error_string, &change_master); + if (rc == 1) + { + printf("Test %d: valid option for [%s] FAILED\n", tests, saved_query); + return 1; + } + else + { + printf("Test %d PASSED, valid options for [%s]\n", tests, saved_query); + } + + tests++; + + /** + * Test 10: 1 valid option and 2 invalid ones + * + * Expected rc is 1, if 0 test fails + */ + strcpy(error_string, ""); + strcpy(query, "CHANGE MASTER TO MasTER_hoST = '127.0.0.1', Y, X" + command_offset); + strcpy(saved_query, query); + rc = blr_test_parse_change_master_command(query, error_string, &change_master); + if (rc == 0) + { + printf("Test %d: valid / not valid options for [%s] FAILED\n", tests, saved_query); + return 1; + } + else + { + printf("Test %d PASSED, valid / not valid options for [%s]\n", tests, saved_query); + } + + tests++; + + /** + * Test 11: 1 valid option and 1 with missing value + * + * Expected rc is 1, if 0 test fails + */ + strcpy(error_string, ""); + strcpy(query, "CHANGE MASTER TO MasTER_hoST = '127.0.0.1', MASTER_PORT=" + command_offset); + strcpy(saved_query, query); + rc = blr_test_parse_change_master_command(query, error_string, &change_master); + if (rc == 0) + { + printf("Test %d: valid / not valid options for [%s] FAILED\n", tests, saved_query); + return 1; + } + else + { + printf("Test %d PASSED, valid / not valid options for [%s]\n", tests, saved_query); + } + + tests++; + + /** + * Test 12: 2 valid options + * + * Expected rc is 0, if 1 test fails + */ + strcpy(error_string, ""); + strcpy(query, "CHANGE MASTER TO MasTER_hoST = '127.0.0.1', MASTER_PORT=9999" + command_offset); + strcpy(saved_query, query); + rc = blr_test_parse_change_master_command(query, error_string, &change_master); + if (rc == 1) + { + printf("Test %d: valid options for [%s] FAILED\n", tests, saved_query); + return 1; + } + else + { + printf("Test %d PASSED, valid options for [%s]\n", tests, saved_query); + } + + tests++; + + /** + * Test 13: 2 valid options and 1 invalid + * + * Expected rc is 1, if 0 test fails + */ + strcpy(error_string, ""); + strcpy(query, "CHANGE MASTER TO MasTER_hoST = '127.0.0.1', MASTER_PORT=9999, MASTER_PASSWD='massi'" + + command_offset); + strcpy(saved_query, query); + rc = blr_test_parse_change_master_command(query, error_string, &change_master); + if (rc == 0) + { + printf("Test %d: valid / not valid options for [%s] FAILED\n", tests, saved_query); + return 1; + } + else + { + printf("Test %d PASSED, valid / not valid options for [%s]\n", tests, saved_query); + } + + tests++; + + /** + * Test 14: 3 valid options + * + * Expected rc is 0, if 1 test fails + */ + strcpy(error_string, ""); + strcpy(query, "CHANGE MASTER TO MasTER_hoST = '127.0.0.1', MASTER_PORT=9999, MASTER_PASSWORD='massi'" + + command_offset); + strcpy(saved_query, query); + rc = blr_test_parse_change_master_command(query, error_string, &change_master); + if (rc == 1) + { + printf("Test %d: valid options [%s] FAILED\n", tests, saved_query); + return 1; + } + else + { + printf("Test %d PASSED, valid options for [%s]\n", tests, saved_query); + } + + tests++; + + /** + * Test 15: 5 valid options and 1 invalid + * + * Expected rc is 1, if 0 test fails + */ + strcpy(error_string, ""); + strcpy(query, + "CHANGE MASTER TO MasTER_hoST = '127.0.0.1', MASTER_PORT=9999, MASTER_PASSWORD='massi', MAster_user='eee', master_log_fil= 'fffff', master_log_pos= 55" + + command_offset); + strcpy(saved_query, query); + rc = blr_test_parse_change_master_command(query, error_string, &change_master); + if (rc == 0) + { + printf("Test %d: valid / not valid options for [%s] FAILED\n", tests, saved_query); + return 1; + } + else + { + printf("Test %d PASSED, valid / not valid options for [%s]\n", tests, saved_query); + } + + tests++; + + /** + * Test 16: 6 valid options + * + * Expected rc is 0, if 1 test fails + */ + strcpy(error_string, ""); + memset(&change_master, 0, sizeof(change_master)); + strcpy(query, + "CHANGE MASTER TO MasTER_hoST = '127.0.0.1', MASTER_PORT=9999, MASTER_PASSWORD='massi', MAster_user='eee', master_log_file= 'fffff', master_log_pos= 55" + + command_offset); + strcpy(saved_query, query); + rc = blr_test_parse_change_master_command(query, error_string, &change_master); + if (rc == 1) + { + printf("Test %d: valid options [%s] FAILED\n", tests, saved_query); + return 1; + } + else + { + printf("Test %d PASSED, valid options for [%s]\n", tests, saved_query); + } + + tests++; + + printf("--------- MASTER_LOG_FILE tests ---------\n"); + + /** + * Test 17: use current binlog filename in master_state != BLRM_UNCONFIGURED + * and try to set a new filename with wront format from previous test + * + * Expected master_log_file is NULL and error_string is not empty + */ + inst->master_state = BLRM_SLAVE_STOPPED; + strcpy(error_string, ""); + + master_log_file = blr_test_set_master_logfile(inst, change_master.binlog_file, error_string); + + if (master_log_file == NULL) + { + if (strlen(error_string)) + { + printf("Test %d PASSED, MASTER_LOG_FILE [%s]: [%s]\n", tests, change_master.binlog_file, error_string); + } + else + { + printf("Test %d: set MASTER_LOG_FILE [%s] FAILED, an error message was expected\n", tests, + change_master.binlog_file); + return 1; + } + } + else + { + printf("Test %d: set MASTER_LOG_FILE [%s] FAILED, NULL was expected from blr_test_set_master_logfile()\n", + tests, change_master.binlog_file); + return 1; + } + + tests++; + + printf("--- MASTER_LOG_POS and MASTER_LOG_FILE rule/constraints checks ---\n"); + + /******************************************** + * + * Second part of test suite is for checking + * rules and constraints once syntax is OK + * + ********************************************/ + + /** + * Test 18: change master without MASTER_LOG_FILE in BLRM_UNCONFIGURED state + * + * Expected rc = -1 and master_state still set to BLRM_UNCONFIGURED + */ + inst->master_state = BLRM_UNCONFIGURED; + strcpy(error_string, ""); + strcpy(query, + "CHANGE MASTER TO MasTER_hoST = '127.0.0.1', MASTER_PORT=9999, MASTER_PASSWORD='massi', MAster_user='eee', master_log_pos= 55"); + + rc = blr_test_handle_change_master(inst, query, error_string); + + if (rc == -1 && inst->master_state == BLRM_UNCONFIGURED) + { + printf("Test %d PASSED, in BLRM_UNCONFIGURED state. Message [%s]\n", tests, error_string); + } + else + { + printf("Test %d: an error message was expected from blr_test_handle_change_master(), Master State is %s. Message [%s]\n", + tests, blrm_states[inst->master_state], error_string); + return 1; + } + + tests++; + + /** + * Test 19: use selected binlog filename in BLRM_UNCONFIGURED state + * + * Expected rc = -1 and master_state still set to BLRM_UNCONFIGURED + */ + + inst->master_state = BLRM_UNCONFIGURED; + strcpy(error_string, ""); + strcpy(query, + "CHANGE MASTER TO MasTER_hoST = '127.0.0.1', MASTER_PORT=9999, MASTER_PASSWORD='massi', MAster_user='eee', master_log_file= 'file.000053', master_log_pos= 1855"); + + rc = blr_test_handle_change_master(inst, query, error_string); + + if (rc == -1 && inst->master_state == BLRM_UNCONFIGURED) + { + printf("Test %d PASSED, cannot set MASTER_LOG_FILE in BLRM_UNCONFIGURED state for [%s]. Message [%s]\n", + tests, query, error_string); + } + else + { + printf("Test %d: set MASTER_LOG_FILE in BLRM_UNCONFIGURED state FAILED, an error message was expected from blr_test_handle_change_master(), Master State is %s. Message [%s]\n", + tests, blrm_states[inst->master_state], error_string); + return 1; + } + + tests++; + + /** + * Test 20: use selected binlog filename and pos in state != BLRM_UNCONFIGURED + * Current binlog and pos are same specified in the change master command + * + * Expected rc = 0 + */ + inst->master_state = BLRM_UNCONNECTED; + strcpy(error_string, ""); + strncpy(inst->binlog_name, "file-bin.00008", BINLOG_FNAMELEN); + inst->current_pos = 55; + strcpy(query, + "CHANGE MASTER TO MasTER_hoST = '127.0.0.1', MASTER_PORT=9999, MASTER_PASSWORD='massi', MAster_user='eee', master_log_file= 'file-bin.00008', master_log_pos= 55"); + + rc = blr_test_handle_change_master(inst, query, error_string); + + if (rc == 0) + { + printf("Test %d PASSED, set MASTER_LOG_FILE and MASTER_LOG_POS for [%s]\n", tests, query); + } + else + { + printf("Test %d: set MASTER_LOG_FILE and MASTER_LOG_POS FAILED, Master State is %s. Message [%s]\n", tests, + blrm_states[inst->master_state], error_string); + return 1; + } + + tests++; + + /** + * Test 21: use selected binlog filename and pos in state != BLRM_UNCONFIGURED + * Current binlog is not the one specified in the change master command + * + * Expected rc = -1 + */ + + strncpy(inst->binlog_name, "file.000006", BINLOG_FNAMELEN); + inst->current_pos = 10348; + strcpy(inst->fileroot, "file"); + strcpy(error_string, ""); + inst->master_state = BLRM_UNCONNECTED; + strcpy(query, + "CHANGE MASTER TO MasTER_hoST = '127.0.0.1', MASTER_PORT=9999, MASTER_PASSWORD='massi', MAster_user='eee', MASTER_LOG_file ='mmmm.098777', master_log_pos= 55"); + + rc = blr_test_handle_change_master(inst, query, error_string); + + if (rc == -1) + { + printf("Test %d PASSED, cannot set MASTER_LOG_FILE for [%s], Message [%s]\n", tests, query, error_string); + } + else + { + printf("Test %d: set MASTER_LOG_FILE, Master State is %s Failed, Message [%s]\n", tests, + blrm_states[inst->master_state], error_string); + return 1; + } + + tests++; + + /** + * Test 22: use selected binlog filename is next one in sequence and specified pos is 4 + * in any state + * + * Expected rc >= 0 + */ + strcpy(error_string, ""); + strncpy(inst->binlog_name, "file.100506", BINLOG_FNAMELEN); + inst->current_pos = 1348; + strcpy(inst->fileroot, "file"); + strcpy(query, "CHANGE MASTER TO master_log_pos= 4 , master_log_file='file.100507'"); + + rc = blr_test_handle_change_master(inst, query, error_string); + + if (rc >= 0) + { + printf("Test %d PASSED, set MASTER_LOG_FILE for [%s]\n", tests, query); + } + else + { + printf("Test %d: set MASTER_LOG_FILE FAILED, Master State is %s. Message [%s]\n", tests, + blrm_states[inst->master_state], error_string); + return 1; + } + + tests++; + + /** + * Test 23: use selected pos that's not the current one + * in state != BLRM_UNCONFIGURED + * + * Expected rc = -1 + */ + inst->master_state = BLRM_UNCONNECTED; + strcpy(error_string, ""); + strncpy(inst->binlog_name, "file.100506", BINLOG_FNAMELEN); + inst->current_pos = 138; + strcpy(inst->fileroot, "file"); + strcpy(query, "CHANGE MASTER TO master_log_pos= 49 "); + + rc = blr_test_handle_change_master(inst, query, error_string); + + if (rc == -1) + { + printf("Test %d PASSED, cannot set MASTER_LOG_POS for [%s], Message [%s]\n", tests, query, error_string); + } + else + { + printf("Test %d: set MASTER_LOG_POS FAILED, Master State is %s. Message [%s]\n", tests, + blrm_states[inst->master_state], error_string); + return 1; + } + + mxs_log_flush_sync(); + mxs_log_finish(); + + MXS_FREE(inst); + + return 0; } diff --git a/server/modules/routing/debugcli/debugcmd.c b/server/modules/routing/debugcli/debugcmd.c index 3b23f3e6f..ad2fb67b2 100644 --- a/server/modules/routing/debugcli/debugcmd.c +++ b/server/modules/routing/debugcli/debugcmd.c @@ -864,9 +864,11 @@ struct subcommand addoptions[] = "The TARGET must be a list of service and monitor names\n" "e.g. add server my-db my-service 'Cluster Monitor'\n" "A server can be assigned to a maximum of 11 objects in one command", - {ARG_TYPE_SERVER, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, + { + ARG_TYPE_SERVER, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, - ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING} + ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING + } }, { EMPTY_OPTION} }; @@ -915,9 +917,11 @@ struct subcommand removeoptions[] = "The TARGET must be a list of service and monitor names\n" "e.g. remove server my-db my-service 'Cluster Monitor'\n" "A server can be removed from a maximum of 11 objects in one command", - {ARG_TYPE_SERVER, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, + { + ARG_TYPE_SERVER, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, - ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING} + ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING + } }, { EMPTY_OPTION @@ -1309,8 +1313,8 @@ static void alterServer(DCB *dcb, SERVER *server, char *v1, char *v2, char *v3, } static void alterMonitor(DCB *dcb, MONITOR *monitor, char *v1, char *v2, char *v3, - char *v4, char *v5, char *v6, char *v7, char *v8, char *v9, - char *v10, char *v11) + char *v4, char *v5, char *v6, char *v7, char *v8, char *v9, + char *v10, char *v11) { char *values[11] = {v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11}; const int items = sizeof(values) / sizeof(values[0]); @@ -1363,9 +1367,11 @@ struct subcommand alteroptions[] = "ssl_cert_verify_depth Certificate verification depth\n\n" "To configure SSL for a newly created server, the 'ssl', 'ssl_cert',\n" "'ssl_key' and 'ssl_ca_cert' parameters must be given at the same time.\n", - { ARG_TYPE_SERVER, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, + { + ARG_TYPE_SERVER, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, - ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING} + ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING + } }, { "monitor", 2, 12, alterMonitor, @@ -1373,9 +1379,11 @@ struct subcommand alteroptions[] = "Usage: alter monitor NAME KEY=VALUE ...\n\n" "This will alter an existing parameter of a monitor. To remove parameters,\n" "pass an empty value for a key e.g. 'maxadmin alter monitor my-monitor my-key='", - {ARG_TYPE_MONITOR, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, + { + ARG_TYPE_MONITOR, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, - ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING} + ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING + } }, { EMPTY_OPTION @@ -1445,9 +1453,11 @@ struct subcommand calloptions[] = "Call module command", "Usage: call command NAMESPACE COMMAND ARGS...\n\n" "To list all registered commands, run 'list commands'.\n", - { ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, + { ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, - ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING} + ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, + ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING + } }, { EMPTY_OPTION @@ -1499,44 +1509,44 @@ convert_arg(char *arg, int arg_type) switch (arg_type) { - case ARG_TYPE_ADDRESS: - rval = (unsigned long)strtol(arg, NULL, 0); - break; + case ARG_TYPE_ADDRESS: + rval = (unsigned long)strtol(arg, NULL, 0); + break; - case ARG_TYPE_STRING: - rval = (unsigned long)arg; - break; + case ARG_TYPE_STRING: + rval = (unsigned long)arg; + break; - case ARG_TYPE_SERVICE: - rval = (unsigned long)service_find(arg); - break; + case ARG_TYPE_SERVICE: + rval = (unsigned long)service_find(arg); + break; - case ARG_TYPE_SERVER: - rval = (unsigned long)server_find_by_unique_name(arg); - break; + case ARG_TYPE_SERVER: + rval = (unsigned long)server_find_by_unique_name(arg); + break; - case ARG_TYPE_SESSION: - rval = (unsigned long)session_get_by_id(strtol(arg, NULL, 0)); - break; + case ARG_TYPE_SESSION: + rval = (unsigned long)session_get_by_id(strtol(arg, NULL, 0)); + break; - case ARG_TYPE_MONITOR: - rval = (unsigned long)monitor_find(arg); - break; + case ARG_TYPE_MONITOR: + rval = (unsigned long)monitor_find(arg); + break; - case ARG_TYPE_FILTER: - rval = (unsigned long)filter_def_find(arg); - break; + case ARG_TYPE_FILTER: + rval = (unsigned long)filter_def_find(arg); + break; - case ARG_TYPE_NUMERIC: + case ARG_TYPE_NUMERIC: - for (int i = 0; arg[i]; i++) + for (int i = 0; arg[i]; i++) + { + if (isdigit(arg[i])) { - if (isdigit(arg[i])) - { - break; - } + break; } - rval = atoi(arg); + } + rval = atoi(arg); } return rval; @@ -1546,12 +1556,12 @@ static void free_arg(int arg_type, void *value) { switch (arg_type) { - case ARG_TYPE_SESSION: - session_put_ref(value); - break; + case ARG_TYPE_SESSION: + session_put_ref(value); + break; - default: - break; + default: + break; } } @@ -1754,66 +1764,66 @@ execute_cmd(CLI_SESSION *cli) { switch (cmds[i].options[j].argc_max) { - case 0: - cmds[i].options[j].fn(dcb); - break; - case 1: - cmds[i].options[j].fn(dcb, arg_list[0]); - break; - case 2: - cmds[i].options[j].fn(dcb, arg_list[0], arg_list[1]); - break; - case 3: - cmds[i].options[j].fn(dcb, arg_list[0], arg_list[1], arg_list[2]); - break; - case 4: - cmds[i].options[j].fn(dcb, arg_list[0], arg_list[1], arg_list[2], - arg_list[3]); - break; - case 5: - cmds[i].options[j].fn(dcb, arg_list[0], arg_list[1], arg_list[2], - arg_list[3], arg_list[4]); - break; - case 6: - cmds[i].options[j].fn(dcb, arg_list[0], arg_list[1], arg_list[2], - arg_list[3], arg_list[4], arg_list[5]); - break; - case 7: - cmds[i].options[j].fn(dcb, arg_list[0], arg_list[1], arg_list[2], - arg_list[3], arg_list[4], arg_list[5], - arg_list[6]); - break; - case 8: - cmds[i].options[j].fn(dcb, arg_list[0], arg_list[1], arg_list[2], - arg_list[3], arg_list[4], arg_list[5], - arg_list[6], arg_list[7]); - break; - case 9: - cmds[i].options[j].fn(dcb, arg_list[0], arg_list[1], arg_list[2], - arg_list[3], arg_list[4], arg_list[5], - arg_list[6], arg_list[7], arg_list[8]); - break; - case 10: - cmds[i].options[j].fn(dcb, arg_list[0], arg_list[1], arg_list[2], - arg_list[3], arg_list[4], arg_list[5], - arg_list[6], arg_list[7], arg_list[8], - arg_list[9]); - break; - case 11: - cmds[i].options[j].fn(dcb, arg_list[0], arg_list[1], arg_list[2], - arg_list[3], arg_list[4], arg_list[5], - arg_list[6], arg_list[7], arg_list[8], - arg_list[9], arg_list[10]); - break; - case 12: - cmds[i].options[j].fn(dcb, arg_list[0], arg_list[1], arg_list[2], - arg_list[3], arg_list[4], arg_list[5], - arg_list[6], arg_list[7], arg_list[8], - arg_list[9], arg_list[10], arg_list[11]); - break; - default: - dcb_printf(dcb, "Error: Maximum argument count is %d.\n", MAXARGS); - break; + case 0: + cmds[i].options[j].fn(dcb); + break; + case 1: + cmds[i].options[j].fn(dcb, arg_list[0]); + break; + case 2: + cmds[i].options[j].fn(dcb, arg_list[0], arg_list[1]); + break; + case 3: + cmds[i].options[j].fn(dcb, arg_list[0], arg_list[1], arg_list[2]); + break; + case 4: + cmds[i].options[j].fn(dcb, arg_list[0], arg_list[1], arg_list[2], + arg_list[3]); + break; + case 5: + cmds[i].options[j].fn(dcb, arg_list[0], arg_list[1], arg_list[2], + arg_list[3], arg_list[4]); + break; + case 6: + cmds[i].options[j].fn(dcb, arg_list[0], arg_list[1], arg_list[2], + arg_list[3], arg_list[4], arg_list[5]); + break; + case 7: + cmds[i].options[j].fn(dcb, arg_list[0], arg_list[1], arg_list[2], + arg_list[3], arg_list[4], arg_list[5], + arg_list[6]); + break; + case 8: + cmds[i].options[j].fn(dcb, arg_list[0], arg_list[1], arg_list[2], + arg_list[3], arg_list[4], arg_list[5], + arg_list[6], arg_list[7]); + break; + case 9: + cmds[i].options[j].fn(dcb, arg_list[0], arg_list[1], arg_list[2], + arg_list[3], arg_list[4], arg_list[5], + arg_list[6], arg_list[7], arg_list[8]); + break; + case 10: + cmds[i].options[j].fn(dcb, arg_list[0], arg_list[1], arg_list[2], + arg_list[3], arg_list[4], arg_list[5], + arg_list[6], arg_list[7], arg_list[8], + arg_list[9]); + break; + case 11: + cmds[i].options[j].fn(dcb, arg_list[0], arg_list[1], arg_list[2], + arg_list[3], arg_list[4], arg_list[5], + arg_list[6], arg_list[7], arg_list[8], + arg_list[9], arg_list[10]); + break; + case 12: + cmds[i].options[j].fn(dcb, arg_list[0], arg_list[1], arg_list[2], + arg_list[3], arg_list[4], arg_list[5], + arg_list[6], arg_list[7], arg_list[8], + arg_list[9], arg_list[10], arg_list[11]); + break; + default: + dcb_printf(dcb, "Error: Maximum argument count is %d.\n", MAXARGS); + break; } } diff --git a/server/modules/routing/maxinfo/maxinfo.c b/server/modules/routing/maxinfo/maxinfo.c index 469a1a8d2..f22992488 100644 --- a/server/modules/routing/maxinfo/maxinfo.c +++ b/server/modules/routing/maxinfo/maxinfo.c @@ -358,18 +358,18 @@ execute(ROUTER *rinstance, void *router_session, GWBUF *queue) { switch (MYSQL_COMMAND(queue)) { - case COM_PING: - rc = maxinfo_ping(instance, session, queue); - break; - case COM_STATISTICS: - rc = maxinfo_statistics(instance, session, queue); - break; - case COM_QUIT: - break; - default: - MXS_ERROR("Unexpected MySQL command 0x%x", - MYSQL_COMMAND(queue)); - break; + case COM_PING: + rc = maxinfo_ping(instance, session, queue); + break; + case COM_STATISTICS: + rc = maxinfo_statistics(instance, session, queue); + break; + case COM_QUIT: + break; + default: + MXS_ERROR("Unexpected MySQL command 0x%x", + MYSQL_COMMAND(queue)); + break; } } // MaxInfo doesn't route the data forward so it should be freed. diff --git a/server/modules/routing/maxinfo/maxinfo_error.c b/server/modules/routing/maxinfo/maxinfo_error.c index 932646e1e..5a77eced6 100644 --- a/server/modules/routing/maxinfo/maxinfo_error.c +++ b/server/modules/routing/maxinfo/maxinfo_error.c @@ -58,18 +58,18 @@ maxinfo_send_parse_error(DCB *dcb, char *sql, PARSE_ERROR err) switch (err) { - case PARSE_NOERROR: - desc = "No error"; - break; - case PARSE_MALFORMED_SHOW: - desc = "Expected show [like ]"; - break; - case PARSE_EXPECTED_LIKE: - desc = "Expected LIKE "; - break; - case PARSE_SYNTAX_ERROR: - desc = "Syntax error"; - break; + case PARSE_NOERROR: + desc = "No error"; + break; + case PARSE_MALFORMED_SHOW: + desc = "Expected show [like ]"; + break; + case PARSE_EXPECTED_LIKE: + desc = "Expected LIKE "; + break; + case PARSE_SYNTAX_ERROR: + desc = "Syntax error"; + break; } len = strlen(sql) + strlen(desc) + 20; diff --git a/server/modules/routing/maxinfo/maxinfo_exec.c b/server/modules/routing/maxinfo/maxinfo_exec.c index c48b564cb..bffc3c2bc 100644 --- a/server/modules/routing/maxinfo/maxinfo_exec.c +++ b/server/modules/routing/maxinfo/maxinfo_exec.c @@ -69,37 +69,37 @@ maxinfo_execute(DCB *dcb, MAXINFO_TREE *tree) { switch (tree->op) { - case MAXOP_SHOW: - exec_show(dcb, tree); - break; - case MAXOP_SELECT: - exec_select(dcb, tree); - break; + case MAXOP_SHOW: + exec_show(dcb, tree); + break; + case MAXOP_SELECT: + exec_select(dcb, tree); + break; - case MAXOP_FLUSH: - exec_flush(dcb, tree); - break; - case MAXOP_SET: - exec_set(dcb, tree); - break; - case MAXOP_CLEAR: - exec_clear(dcb, tree); - break; - case MAXOP_SHUTDOWN: - exec_shutdown(dcb, tree); - break; - case MAXOP_RESTART: - exec_restart(dcb, tree); - break; + case MAXOP_FLUSH: + exec_flush(dcb, tree); + break; + case MAXOP_SET: + exec_set(dcb, tree); + break; + case MAXOP_CLEAR: + exec_clear(dcb, tree); + break; + case MAXOP_SHUTDOWN: + exec_shutdown(dcb, tree); + break; + case MAXOP_RESTART: + exec_restart(dcb, tree); + break; - case MAXOP_TABLE: - case MAXOP_COLUMNS: - case MAXOP_LITERAL: - case MAXOP_PREDICATE: - case MAXOP_LIKE: - case MAXOP_EQUAL: - default: - maxinfo_send_error(dcb, 0, "Unexpected operator in parse tree"); + case MAXOP_TABLE: + case MAXOP_COLUMNS: + case MAXOP_LITERAL: + case MAXOP_PREDICATE: + case MAXOP_LIKE: + case MAXOP_EQUAL: + default: + maxinfo_send_error(dcb, 0, "Unexpected operator in parse tree"); } } @@ -852,17 +852,17 @@ variable_row(RESULTSET *result, void *data) resultset_row_set(row, 0, variables[context->index].name); switch (variables[context->index].type) { - case VT_STRING: - resultset_row_set(row, 1, - (char *)(*variables[context->index].func)()); - break; - case VT_INT: - snprintf(buf, 80, "%ld", - (long)(*variables[context->index].func)()); - resultset_row_set(row, 1, buf); - break; - default: - ss_dassert(!true); + case VT_STRING: + resultset_row_set(row, 1, + (char *)(*variables[context->index].func)()); + break; + case VT_INT: + snprintf(buf, 80, "%ld", + (long)(*variables[context->index].func)()); + resultset_row_set(row, 1, buf); + break; + default: + ss_dassert(!true); } context->index++; return row; @@ -1134,17 +1134,17 @@ status_row(RESULTSET *result, void *data) resultset_row_set(row, 0, status[context->index].name); switch (status[context->index].type) { - case VT_STRING: - resultset_row_set(row, 1, - (char *)(*status[context->index].func)()); - break; - case VT_INT: - snprintf(buf, 80, "%ld", - (long)(*status[context->index].func)()); - resultset_row_set(row, 1, buf); - break; - default: - ss_dassert(!true); + case VT_STRING: + resultset_row_set(row, 1, + (char *)(*status[context->index].func)()); + break; + case VT_INT: + snprintf(buf, 80, "%ld", + (long)(*status[context->index].func)()); + resultset_row_set(row, 1, buf); + break; + default: + ss_dassert(!true); } context->index++; return row; diff --git a/server/modules/routing/maxinfo/maxinfo_parse.c b/server/modules/routing/maxinfo/maxinfo_parse.c index 2bbf17cc0..de958c610 100644 --- a/server/modules/routing/maxinfo/maxinfo_parse.c +++ b/server/modules/routing/maxinfo/maxinfo_parse.c @@ -70,113 +70,113 @@ maxinfo_parse(char *sql, PARSE_ERROR *parse_error) { switch (token) { - case LT_SHOW: - MXS_FREE(text); // not needed - ptr = fetch_token(ptr, &token, &text); - if (ptr == NULL || token != LT_STRING) - { - // Expected show "name" - *parse_error = PARSE_MALFORMED_SHOW; - return NULL; - } - tree = make_tree_node(MAXOP_SHOW, text, NULL, NULL); - if ((ptr = fetch_token(ptr, &token, &text)) == NULL) - { - return tree; - } - else if (token == LT_LIKE) - { - if ((ptr = fetch_token(ptr, &token, &text)) != NULL) - { - tree->right = make_tree_node(MAXOP_LIKE, - text, NULL, NULL); - return tree; - } - else - { - // Expected expression - *parse_error = PARSE_EXPECTED_LIKE; - maxinfo_free_tree(tree); - return NULL; - } - } - // Malformed show - MXS_FREE(text); - maxinfo_free_tree(tree); + case LT_SHOW: + MXS_FREE(text); // not needed + ptr = fetch_token(ptr, &token, &text); + if (ptr == NULL || token != LT_STRING) + { + // Expected show "name" *parse_error = PARSE_MALFORMED_SHOW; return NULL; -#if 0 - case LT_SELECT: - MXS_FREE(text); // not needed - col = parse_column_list(&ptr); - table = parse_table_name(&ptr); - return make_tree_node(MAXOP_SELECT, NULL, col, table); -#endif - case LT_FLUSH: - MXS_FREE(text); // not needed - ptr = fetch_token(ptr, &token, &text); - return make_tree_node(MAXOP_FLUSH, text, NULL, NULL); - - case LT_SHUTDOWN: - MXS_FREE(text); - ptr = fetch_token(ptr, &token, &text); - tree = make_tree_node(MAXOP_SHUTDOWN, text, NULL, NULL); - - if ((ptr = fetch_token(ptr, &token, &text)) == NULL) + } + tree = make_tree_node(MAXOP_SHOW, text, NULL, NULL); + if ((ptr = fetch_token(ptr, &token, &text)) == NULL) + { + return tree; + } + else if (token == LT_LIKE) + { + if ((ptr = fetch_token(ptr, &token, &text)) != NULL) { - /** Possibly SHUTDOWN MAXSCALE */ + tree->right = make_tree_node(MAXOP_LIKE, + text, NULL, NULL); return tree; } - tree->right = make_tree_node(MAXOP_LITERAL, text, NULL, NULL); - - if ((ptr = fetch_token(ptr, &token, &text)) != NULL) + else { - /** Unknown token after SHUTDOWN MONITOR|SERVICE */ - *parse_error = PARSE_SYNTAX_ERROR; + // Expected expression + *parse_error = PARSE_EXPECTED_LIKE; maxinfo_free_tree(tree); return NULL; } + } + // Malformed show + MXS_FREE(text); + maxinfo_free_tree(tree); + *parse_error = PARSE_MALFORMED_SHOW; + return NULL; +#if 0 + case LT_SELECT: + MXS_FREE(text); // not needed + col = parse_column_list(&ptr); + table = parse_table_name(&ptr); + return make_tree_node(MAXOP_SELECT, NULL, col, table); +#endif + case LT_FLUSH: + MXS_FREE(text); // not needed + ptr = fetch_token(ptr, &token, &text); + return make_tree_node(MAXOP_FLUSH, text, NULL, NULL); + + case LT_SHUTDOWN: + MXS_FREE(text); + ptr = fetch_token(ptr, &token, &text); + tree = make_tree_node(MAXOP_SHUTDOWN, text, NULL, NULL); + + if ((ptr = fetch_token(ptr, &token, &text)) == NULL) + { + /** Possibly SHUTDOWN MAXSCALE */ return tree; + } + tree->right = make_tree_node(MAXOP_LITERAL, text, NULL, NULL); - case LT_RESTART: - MXS_FREE(text); - ptr = fetch_token(ptr, &token, &text); - tree = make_tree_node(MAXOP_RESTART, text, NULL, NULL); - - if ((ptr = fetch_token(ptr, &token, &text)) == NULL) - { - /** Missing token for RESTART MONITOR|SERVICE */ - *parse_error = PARSE_SYNTAX_ERROR; - maxinfo_free_tree(tree); - return NULL; - } - tree->right = make_tree_node(MAXOP_LITERAL, text, NULL, NULL); - - if ((ptr = fetch_token(ptr, &token, &text)) != NULL) - { - /** Unknown token after RESTART MONITOR|SERVICE */ - *parse_error = PARSE_SYNTAX_ERROR; - MXS_FREE(text); - maxinfo_free_tree(tree); - return NULL; - } - return tree; - - case LT_SET: - MXS_FREE(text); // not needed - ptr = fetch_token(ptr, &token, &text); - tree = make_tree_node(MAXOP_SET, text, NULL, NULL); - return maxinfo_parse_literals(tree, 2, ptr, parse_error); - - case LT_CLEAR: - MXS_FREE(text); // not needed - ptr = fetch_token(ptr, &token, &text); - tree = make_tree_node(MAXOP_CLEAR, text, NULL, NULL); - return maxinfo_parse_literals(tree, 2, ptr, parse_error); - break; - default: + if ((ptr = fetch_token(ptr, &token, &text)) != NULL) + { + /** Unknown token after SHUTDOWN MONITOR|SERVICE */ *parse_error = PARSE_SYNTAX_ERROR; + maxinfo_free_tree(tree); return NULL; + } + return tree; + + case LT_RESTART: + MXS_FREE(text); + ptr = fetch_token(ptr, &token, &text); + tree = make_tree_node(MAXOP_RESTART, text, NULL, NULL); + + if ((ptr = fetch_token(ptr, &token, &text)) == NULL) + { + /** Missing token for RESTART MONITOR|SERVICE */ + *parse_error = PARSE_SYNTAX_ERROR; + maxinfo_free_tree(tree); + return NULL; + } + tree->right = make_tree_node(MAXOP_LITERAL, text, NULL, NULL); + + if ((ptr = fetch_token(ptr, &token, &text)) != NULL) + { + /** Unknown token after RESTART MONITOR|SERVICE */ + *parse_error = PARSE_SYNTAX_ERROR; + MXS_FREE(text); + maxinfo_free_tree(tree); + return NULL; + } + return tree; + + case LT_SET: + MXS_FREE(text); // not needed + ptr = fetch_token(ptr, &token, &text); + tree = make_tree_node(MAXOP_SET, text, NULL, NULL); + return maxinfo_parse_literals(tree, 2, ptr, parse_error); + + case LT_CLEAR: + MXS_FREE(text); // not needed + ptr = fetch_token(ptr, &token, &text); + tree = make_tree_node(MAXOP_CLEAR, text, NULL, NULL); + return maxinfo_parse_literals(tree, 2, ptr, parse_error); + break; + default: + *parse_error = PARSE_SYNTAX_ERROR; + return NULL; } } *parse_error = PARSE_SYNTAX_ERROR; @@ -201,28 +201,28 @@ parse_column_list(char **ptr) *ptr = fetch_token(*ptr, &lookahead, &text2); switch (token) { - case LT_STRING: - switch (lookahead) - { - case LT_COMMA: - rval = make_tree_node(MAXOP_COLUMNS, text, NULL, - parse_column_list(ptr)); - break; - case LT_FROM: - rval = make_tree_node(MAXOP_COLUMNS, text, NULL, - NULL); - break; - default: - break; - } + case LT_STRING: + switch (lookahead) + { + case LT_COMMA: + rval = make_tree_node(MAXOP_COLUMNS, text, NULL, + parse_column_list(ptr)); break; - case LT_STAR: - if (lookahead != LT_FROM) - rval = make_tree_node(MAXOP_ALL_COLUMNS, NULL, NULL, - NULL); + case LT_FROM: + rval = make_tree_node(MAXOP_COLUMNS, text, NULL, + NULL); break; default: break; + } + break; + case LT_STAR: + if (lookahead != LT_FROM) + rval = make_tree_node(MAXOP_ALL_COLUMNS, NULL, NULL, + NULL); + break; + default: + break; } MXS_FREE(text); MXS_FREE(text2); diff --git a/server/modules/routing/readconnroute/readconnroute.c b/server/modules/routing/readconnroute/readconnroute.c index c3eb20350..36103d58a 100644 --- a/server/modules/routing/readconnroute/readconnroute.c +++ b/server/modules/routing/readconnroute/readconnroute.c @@ -36,32 +36,32 @@ * @verbatim * Revision History * - * Date Who Description - * 14/06/2013 Mark Riddoch Initial implementation - * 25/06/2013 Mark Riddoch Addition of checks for current server state - * 26/06/2013 Mark Riddoch Use server with least connections since - * startup if the number of current - * connections is the same for two servers - * Addition of master and slave options - * 27/06/2013 Vilho Raatikka Added skygw_log_write command as an example - * and necessary headers. - * 17/07/2013 Massimiliano Pinto Added clientReply routine: - * called by backend server to send data to client - * Included maxscale/protocol/mysql.h - * with macros and MySQL commands with MYSQL_ prefix - * avoiding any conflict with the standard ones - * in mysql.h - * 22/07/2013 Mark Riddoch Addition of joined router option for Galera - * clusters - * 31/07/2013 Massimiliano Pinto Added a check for candidate server, if NULL return - * 12/08/2013 Mark Riddoch Log unsupported router options - * 04/09/2013 Massimiliano Pinto Added client NULL check in clientReply - * 22/10/2013 Massimiliano Pinto errorReply called from backend, for client error reply - * or take different actions such as open a new backend connection - * 20/02/2014 Massimiliano Pinto If router_options=slave, route traffic to master if no slaves available - * 06/03/2014 Massimiliano Pinto Server connection counter is now updated in closeSession - * 24/06/2014 Massimiliano Pinto New rules for selecting the Master server - * 27/06/2014 Mark Riddoch Addition of server weighting + * Date Who Description + * 14/06/2013 Mark Riddoch Initial implementation + * 25/06/2013 Mark Riddoch Addition of checks for current server state + * 26/06/2013 Mark Riddoch Use server with least connections since + * startup if the number of current + * connections is the same for two servers + * Addition of master and slave options + * 27/06/2013 Vilho Raatikka Added skygw_log_write command as an example + * and necessary headers. + * 17/07/2013 Massimiliano Pinto Added clientReply routine: + * called by backend server to send data to client + * Included maxscale/protocol/mysql.h + * with macros and MySQL commands with MYSQL_ prefix + * avoiding any conflict with the standard ones + * in mysql.h + * 22/07/2013 Mark Riddoch Addition of joined router option for Galera + * clusters + * 31/07/2013 Massimiliano Pinto Added a check for candidate server, if NULL return + * 12/08/2013 Mark Riddoch Log unsupported router options + * 04/09/2013 Massimiliano Pinto Added client NULL check in clientReply + * 22/10/2013 Massimiliano Pinto errorReply called from backend, for client error reply + * or take different actions such as open a new backend connection + * 20/02/2014 Massimiliano Pinto If router_options=slave, route traffic to master if no slaves available + * 06/03/2014 Massimiliano Pinto Server connection counter is now updated in closeSession + * 24/06/2014 Massimiliano Pinto New rules for selecting the Master server + * 27/06/2014 Mark Riddoch Addition of server weighting * 11/06/2015 Martin Brampton Remove decrement n_current (moved to dcb.c) * 09/09/2015 Martin Brampton Modify error handler * 25/09/2015 Martin Brampton Block callback processing when no router session in the DCB @@ -168,8 +168,8 @@ static inline void free_readconn_instance(ROUTER_INSTANCE *router) * Create an instance of the router for a particular service * within the gateway. * - * @param service The service this router is being create for - * @param options An array of options for this query router + * @param service The service this router is being create for + * @param options An array of options for this query router * * @return The instance data for this new instance */ @@ -257,14 +257,14 @@ createInstance(SERVICE *service, char **options) instances = inst; spinlock_release(&instlock); - return(ROUTER *) inst; + return (ROUTER *) inst; } /** * Associate a new session with this instance of the router. * - * @param instance The router instance data - * @param session The session itself + * @param instance The router instance data + * @param session The session itself * @return Session specific data for this session */ static void * @@ -445,7 +445,7 @@ newSession(ROUTER *instance, SESSION *session) MXS_INFO("New session for server %s. Connections : %d", candidate->server->unique_name, candidate->connections); - return(void *) client_rses; + return (void *) client_rses; } /** @@ -480,8 +480,8 @@ static void freeSession(ROUTER* router_instance, void* router_client_ses) * Close a session with the router, this is the mechanism * by which a router may cleanup data structure etc. * - * @param instance The router instance data - * @param router_session The session being closed + * @param instance The router instance data + * @param router_session The session being closed */ static void closeSession(ROUTER *instance, void *router_session) @@ -532,7 +532,7 @@ static void log_closed_session(mysql_server_cmd_t mysql_command, bool is_closed, { sprintf(msg, "Server '%s' was removed from the service.", ref->server->unique_name); } - else if(SERVER_IN_MAINT(ref->server)) + else if (SERVER_IN_MAINT(ref->server)) { sprintf(msg, "Server '%s' is in maintenance.", ref->server->unique_name); } @@ -546,9 +546,9 @@ static void log_closed_session(mysql_server_cmd_t mysql_command, bool is_closed, * This is simply a case of sending it to the connection that was * chosen when we started the client session. * - * @param instance The router instance - * @param router_session The router session returned from the newSession call - * @param queue The queue of data buffers to route + * @param instance The router instance + * @param router_session The router session returned from the newSession call + * @param queue The queue of data buffers to route * @return if succeed 1, otherwise 0 */ static int @@ -598,18 +598,18 @@ routeQuery(ROUTER *instance, void *router_session, GWBUF *queue) switch (mysql_command) { - case MYSQL_COM_CHANGE_USER: - rc = backend_dcb->func.auth(backend_dcb, NULL, backend_dcb->session, - queue); - break; - case MYSQL_COM_QUERY: - if (MXS_LOG_PRIORITY_IS_ENABLED(LOG_INFO)) - { - trc = modutil_get_SQL(queue); - } - default: - rc = backend_dcb->func.write(backend_dcb, queue); - break; + case MYSQL_COM_CHANGE_USER: + rc = backend_dcb->func.auth(backend_dcb, NULL, backend_dcb->session, + queue); + break; + case MYSQL_COM_QUERY: + if (MXS_LOG_PRIORITY_IS_ENABLED(LOG_INFO)) + { + trc = modutil_get_SQL(queue); + } + default: + rc = backend_dcb->func.write(backend_dcb, queue); + break; } MXS_INFO("Routed [%s] to '%s'%s%s", @@ -627,8 +627,8 @@ return_rc: /** * Display router diagnostics * - * @param instance Instance of the router - * @param dcb DCB to send diagnostics to + * @param instance Instance of the router + * @param dcb DCB to send diagnostics to */ static void diagnostics(ROUTER *router, DCB *dcb) @@ -686,8 +686,8 @@ clientReply(ROUTER *instance, void *router_session, GWBUF *queue, DCB *backend_d * @param router_session The router session * @param message The error message to reply * @param problem_dcb The DCB related to the error - * @param action The action: ERRACT_NEW_CONNECTION or ERRACT_REPLY_CLIENT - * @param succp Result of action: true if router can continue + * @param action The action: ERRACT_NEW_CONNECTION or ERRACT_REPLY_CLIENT + * @param succp Result of action: true if router can continue * */ static void handleError(ROUTER *instance, void *router_session, GWBUF *errbuf, @@ -812,8 +812,8 @@ static uint64_t getCapabilities(void) * and the SERVER_MASTER bitval * Servers are checked even if they are in 'maintenance' * - * @param servers The list of servers - * @return The Master found + * @param servers The list of servers + * @return The Master found * */ @@ -831,8 +831,8 @@ static SERVER_REF *get_root_master(SERVER_REF *servers) master_host = ref; } else if (ref->server->depth < master_host->server->depth || - (ref->server->depth == master_host->server->depth && - ref->weight > master_host->weight)) + (ref->server->depth == master_host->server->depth && + ref->weight > master_host->weight)) { /** * This master has a lower depth than the candidate master or @@ -863,29 +863,29 @@ static int handle_state_switch(DCB* dcb, DCB_REASON reason, void * routersession } switch (reason) { - case DCB_REASON_CLOSE: - dcb->func.close(dcb); - break; - case DCB_REASON_DRAINED: - /** Do we need to do anything? */ - break; - case DCB_REASON_HIGH_WATER: - /** Do we need to do anything? */ - break; - case DCB_REASON_LOW_WATER: - /** Do we need to do anything? */ - break; - case DCB_REASON_ERROR: - dcb->func.error(dcb); - break; - case DCB_REASON_HUP: - dcb->func.hangup(dcb); - break; - case DCB_REASON_NOT_RESPONDING: - dcb->func.hangup(dcb); - break; - default: - break; + case DCB_REASON_CLOSE: + dcb->func.close(dcb); + break; + case DCB_REASON_DRAINED: + /** Do we need to do anything? */ + break; + case DCB_REASON_HIGH_WATER: + /** Do we need to do anything? */ + break; + case DCB_REASON_LOW_WATER: + /** Do we need to do anything? */ + break; + case DCB_REASON_ERROR: + dcb->func.error(dcb); + break; + case DCB_REASON_HUP: + dcb->func.hangup(dcb); + break; + case DCB_REASON_NOT_RESPONDING: + dcb->func.hangup(dcb); + break; + default: + break; } return 0; diff --git a/server/modules/routing/readwritesplit/readwritesplit.c b/server/modules/routing/readwritesplit/readwritesplit.c index 1af1e6ebc..42848f080 100644 --- a/server/modules/routing/readwritesplit/readwritesplit.c +++ b/server/modules/routing/readwritesplit/readwritesplit.c @@ -264,13 +264,13 @@ static ROUTER *createInstance(SERVICE *service, char **options) CONFIG_PARAMETER *params = service->svc_config_param; router->rwsplit_config.use_sql_variables_in = config_get_enum(params, "use_sql_variables_in", - use_sql_variables_in_values); + use_sql_variables_in_values); router->rwsplit_config.slave_selection_criteria = config_get_enum(params, "slave_selection_criteria", - slave_selection_criteria_values); + slave_selection_criteria_values); router->rwsplit_config.master_failure_mode = config_get_enum(params, "master_failure_mode", - master_failure_mode_values); + master_failure_mode_values); router->rwsplit_config.max_slave_replication_lag = config_get_integer(params, "max_slave_replication_lag"); router->rwsplit_config.retry_failed_reads = config_get_bool(params, "retry_failed_reads"); @@ -1027,20 +1027,20 @@ void rses_property_done(rses_property_t *prop) switch (prop->rses_prop_type) { - case RSES_PROP_TYPE_SESCMD: - mysql_sescmd_done(&prop->rses_prop_data.sescmd); - break; + case RSES_PROP_TYPE_SESCMD: + mysql_sescmd_done(&prop->rses_prop_data.sescmd); + break; - case RSES_PROP_TYPE_TMPTABLES: - hashtable_free(prop->rses_prop_data.temp_tables); - break; + case RSES_PROP_TYPE_TMPTABLES: + hashtable_free(prop->rses_prop_data.temp_tables); + break; - default: - MXS_DEBUG("%lu [rses_property_done] Unknown property type %d " - "in property %p", pthread_self(), prop->rses_prop_type, prop); + default: + MXS_DEBUG("%lu [rses_property_done] Unknown property type %d " + "in property %p", pthread_self(), prop->rses_prop_type, prop); - ss_dassert(false); - break; + ss_dassert(false); + break; } MXS_FREE(prop); } @@ -1187,12 +1187,12 @@ int router_handle_state_switch(DCB *dcb, DCB_REASON reason, void *data) switch (reason) { - case DCB_REASON_NOT_RESPONDING: - dcb->func.hangup(dcb); - break; + case DCB_REASON_NOT_RESPONDING: + dcb->func.hangup(dcb); + break; - default: - break; + default: + break; } return_rc: @@ -1386,7 +1386,7 @@ static void handleError(ROUTER *instance, void *router_session, switch (action) { - case ERRACT_NEW_CONNECTION: + case ERRACT_NEW_CONNECTION: { /** * If master has lost its Master status error can't be @@ -1456,7 +1456,7 @@ static void handleError(ROUTER *instance, void *router_session, else { const char *remote = problem_dcb->state == DCB_STATE_POLLING && - problem_dcb->server ? problem_dcb->server->unique_name : "CLOSED"; + problem_dcb->server ? problem_dcb->server->unique_name : "CLOSED"; MXS_ERROR("DCB connected to '%s' is not in use by the router " "session, not closing it. DCB is in state '%s'", @@ -1465,17 +1465,17 @@ static void handleError(ROUTER *instance, void *router_session, break; } - case ERRACT_REPLY_CLIENT: + case ERRACT_REPLY_CLIENT: { handle_error_reply_client(session, rses, problem_dcb, errmsgbuf); *succp = false; /*< no new backend servers were made available */ break; } - default: - ss_dassert(!true); - *succp = false; - break; + default: + ss_dassert(!true); + *succp = false; + break; } } diff --git a/server/modules/routing/readwritesplit/rwsplit_internal.h b/server/modules/routing/readwritesplit/rwsplit_internal.h index ac3155a41..3961a96bc 100644 --- a/server/modules/routing/readwritesplit/rwsplit_internal.h +++ b/server/modules/routing/readwritesplit/rwsplit_internal.h @@ -14,7 +14,7 @@ * Public License. */ -/* +/* * File: rwsplit_internal.h * Author: mbrampton * @@ -26,7 +26,7 @@ MXS_BEGIN_DECLS -/* This needs to be removed along with dependency on it - see the +/* This needs to be removed along with dependency on it - see the * rwsplit_tmp_table_multi functions */ #include @@ -45,15 +45,15 @@ do{ \ * The following are implemented in rwsplit_mysql.c */ bool route_single_stmt(ROUTER_INSTANCE *inst, ROUTER_CLIENT_SES *rses, - GWBUF *querybuf); + GWBUF *querybuf); void closed_session_reply(GWBUF *querybuf); void live_session_reply(GWBUF **querybuf, ROUTER_CLIENT_SES *rses); void print_error_packet(ROUTER_CLIENT_SES *rses, GWBUF *buf, DCB *dcb); void check_session_command_reply(GWBUF *writebuf, sescmd_cursor_t *scur, backend_ref_t *bref); bool execute_sescmd_in_backend(backend_ref_t *backend_ref); bool handle_target_is_all(route_target_t route_target, - ROUTER_INSTANCE *inst, ROUTER_CLIENT_SES *rses, - GWBUF *querybuf, int packet_type, qc_query_type_t qtype); + ROUTER_INSTANCE *inst, ROUTER_CLIENT_SES *rses, + GWBUF *querybuf, int packet_type, qc_query_type_t qtype); int determine_packet_type(GWBUF *querybuf, bool *non_empty_packet); void log_transaction_status(ROUTER_CLIENT_SES *rses, GWBUF *querybuf, qc_query_type_t qtype); void session_lock_failure_handling(GWBUF *querybuf, int packet_type, qc_query_type_t qtype); @@ -80,74 +80,74 @@ int rses_get_max_replication_lag(ROUTER_CLIENT_SES *rses); */ bool route_single_stmt(ROUTER_INSTANCE *inst, ROUTER_CLIENT_SES *rses, - GWBUF *querybuf); + GWBUF *querybuf); int rwsplit_hashkeyfun(const void *key); int rwsplit_hashcmpfun(const void *v1, const void *v2); void *rwsplit_hstrdup(const void *fval); void rwsplit_hfree(void *fval); bool rwsplit_get_dcb(DCB **p_dcb, ROUTER_CLIENT_SES *rses, backend_type_t btype, - char *name, int max_rlag); + char *name, int max_rlag); route_target_t get_route_target(ROUTER_CLIENT_SES *rses, - qc_query_type_t qtype, HINT *hint); + qc_query_type_t qtype, HINT *hint); rses_property_t *rses_property_init(rses_property_type_t prop_type); int rses_property_add(ROUTER_CLIENT_SES *rses, rses_property_t *prop); void handle_multi_temp_and_load(ROUTER_CLIENT_SES *rses, GWBUF *querybuf, - int packet_type, int *qtype); + int packet_type, int *qtype); bool handle_hinted_target(ROUTER_CLIENT_SES *rses, GWBUF *querybuf, - route_target_t route_target, DCB **target_dcb); + route_target_t route_target, DCB **target_dcb); bool handle_slave_is_target(ROUTER_INSTANCE *inst, ROUTER_CLIENT_SES *rses, - DCB **target_dcb); + DCB **target_dcb); bool handle_master_is_target(ROUTER_INSTANCE *inst, ROUTER_CLIENT_SES *rses, - DCB **target_dcb); + DCB **target_dcb); bool handle_got_target(ROUTER_INSTANCE *inst, ROUTER_CLIENT_SES *rses, - GWBUF *querybuf, DCB *target_dcb, bool store); + GWBUF *querybuf, DCB *target_dcb, bool store); bool route_session_write(ROUTER_CLIENT_SES *router_cli_ses, - GWBUF *querybuf, ROUTER_INSTANCE *inst, - int packet_type, - qc_query_type_t qtype); + GWBUF *querybuf, ROUTER_INSTANCE *inst, + int packet_type, + qc_query_type_t qtype); /* * The following are implemented in rwsplit_session_cmd.c */ mysql_sescmd_t *rses_property_get_sescmd(rses_property_t *prop); mysql_sescmd_t *mysql_sescmd_init(rses_property_t *rses_prop, - GWBUF *sescmd_buf, - unsigned char packet_type, - ROUTER_CLIENT_SES *rses); + GWBUF *sescmd_buf, + unsigned char packet_type, + ROUTER_CLIENT_SES *rses); void mysql_sescmd_done(mysql_sescmd_t *sescmd); mysql_sescmd_t *sescmd_cursor_get_command(sescmd_cursor_t *scur); bool sescmd_cursor_is_active(sescmd_cursor_t *sescmd_cursor); void sescmd_cursor_set_active(sescmd_cursor_t *sescmd_cursor, - bool value); + bool value); bool execute_sescmd_history(backend_ref_t *bref); GWBUF *sescmd_cursor_clone_querybuf(sescmd_cursor_t *scur); GWBUF *sescmd_cursor_process_replies(GWBUF *replybuf, - backend_ref_t *bref, - bool *reconnect); + backend_ref_t *bref, + bool *reconnect); /* * The following are implemented in rwsplit_select_backends.c */ bool select_connect_backend_servers(backend_ref_t **p_master_ref, - backend_ref_t *backend_ref, - int router_nservers, int max_nslaves, - int max_slave_rlag, - select_criteria_t select_criteria, - SESSION *session, - ROUTER_INSTANCE *router, - bool active_session); + backend_ref_t *backend_ref, + int router_nservers, int max_nslaves, + int max_slave_rlag, + select_criteria_t select_criteria, + SESSION *session, + ROUTER_INSTANCE *router, + bool active_session); /* * The following are implemented in rwsplit_tmp_table_multi.c */ -void check_drop_tmp_table(ROUTER_CLIENT_SES *router_cli_ses, - GWBUF *querybuf, - mysql_server_cmd_t packet_type); +void check_drop_tmp_table(ROUTER_CLIENT_SES *router_cli_ses, + GWBUF *querybuf, + mysql_server_cmd_t packet_type); bool is_read_tmp_table(ROUTER_CLIENT_SES *router_cli_ses, - GWBUF *querybuf, - qc_query_type_t type); + GWBUF *querybuf, + qc_query_type_t type); void check_create_tmp_table(ROUTER_CLIENT_SES *router_cli_ses, - GWBUF *querybuf, qc_query_type_t type); + GWBUF *querybuf, qc_query_type_t type); bool check_for_multi_stmt(GWBUF *buf, void *protocol, mysql_server_cmd_t packet_type); qc_query_type_t determine_query_type(GWBUF *querybuf, int packet_type, bool non_empty_packet); void close_failed_bref(backend_ref_t *bref, bool fatal); diff --git a/server/modules/routing/readwritesplit/rwsplit_mysql.c b/server/modules/routing/readwritesplit/rwsplit_mysql.c index 22db1ea88..7d85c96c7 100644 --- a/server/modules/routing/readwritesplit/rwsplit_mysql.c +++ b/server/modules/routing/readwritesplit/rwsplit_mysql.c @@ -64,7 +64,7 @@ * It is certainly MySQL specific. Packet types are DB specific, but can be * assumed to be enums, which can be handled as integers without knowing * which DB is involved until the packet type needs to be interpreted. - * + * */ /** @@ -73,10 +73,10 @@ * Examine the packet in the buffer to extract the type, if possible. At the * same time set the second parameter to indicate whether the packet was * empty. - * + * * It is assumed that the packet length and type are contained within a single * buffer, the one indicated by the first parameter. - * + * * @param querybuf Buffer containing the packet * @param non_empty_packet bool indicating whether the packet is non-empty * @return The packet type, or MYSQL_COM_UNDEFINED; also the second parameter is set @@ -111,7 +111,7 @@ determine_packet_type(GWBUF *querybuf, bool *non_empty_packet) * provided so that code that is not DB specific can find out whether a packet * contains a SQL query. Clearly, to be effective different functions must be * called for different DB types. - * + * * @param packet_type Type of packet (integer) * @return bool indicating whether packet contains a SQL query */ @@ -131,7 +131,7 @@ is_packet_a_query(int packet_type) * provided so that code that is not DB specific can find out whether a packet * contains a one way messsage. Clearly, to be effective different functions must be * called for different DB types. - * + * * @param packet_type Type of packet (integer) * @return bool indicating whether packet contains a one way message */ @@ -139,7 +139,7 @@ bool is_packet_a_one_way_message(int packet_type) { return (packet_type == MYSQL_COM_STMT_SEND_LONG_DATA || - packet_type == MYSQL_COM_QUIT || packet_type == MYSQL_COM_STMT_CLOSE); + packet_type == MYSQL_COM_QUIT || packet_type == MYSQL_COM_STMT_CLOSE); } /* @@ -152,7 +152,7 @@ is_packet_a_one_way_message(int packet_type) * The router session and the query buffer are used to log the transaction * status, along with the query type (which is a generic description that * should be usable across all DB types). - * + * * @param rses Router session * @param querybuf Query buffer * @param qtype Query type @@ -160,30 +160,30 @@ is_packet_a_one_way_message(int packet_type) void log_transaction_status(ROUTER_CLIENT_SES *rses, GWBUF *querybuf, qc_query_type_t qtype) { - if (!rses->rses_load_active) - { - uint8_t *packet = GWBUF_DATA(querybuf); - unsigned char ptype = packet[4]; - size_t len = MXS_MIN(GWBUF_LENGTH(querybuf), - MYSQL_GET_PAYLOAD_LEN((unsigned char *)querybuf->start) - 1); - char *data = (char *)&packet[5]; - char *contentstr = strndup(data, MXS_MIN(len, RWSPLIT_TRACE_MSG_LEN)); - char *qtypestr = qc_typemask_to_string(qtype); - SESSION *ses = rses->client_dcb->session; - MXS_INFO("> Autocommit: %s, trx is %s, cmd: %s, type: %s, stmt: %s%s %s", - (session_is_autocommit(ses) ? "[enabled]" : "[disabled]"), - (session_trx_is_active(ses) ? "[open]" : "[not open]"), - STRPACKETTYPE(ptype), (qtypestr == NULL ? "N/A" : qtypestr), - contentstr, (querybuf->hint == NULL ? "" : ", Hint:"), - (querybuf->hint == NULL ? "" : STRHINTTYPE(querybuf->hint->type))); - MXS_FREE(contentstr); - MXS_FREE(qtypestr); - } - else - { - MXS_INFO("> Processing LOAD DATA LOCAL INFILE: %lu bytes sent.", - rses->rses_load_data_sent); - } + if (!rses->rses_load_active) + { + uint8_t *packet = GWBUF_DATA(querybuf); + unsigned char ptype = packet[4]; + size_t len = MXS_MIN(GWBUF_LENGTH(querybuf), + MYSQL_GET_PAYLOAD_LEN((unsigned char *)querybuf->start) - 1); + char *data = (char *)&packet[5]; + char *contentstr = strndup(data, MXS_MIN(len, RWSPLIT_TRACE_MSG_LEN)); + char *qtypestr = qc_typemask_to_string(qtype); + SESSION *ses = rses->client_dcb->session; + MXS_INFO("> Autocommit: %s, trx is %s, cmd: %s, type: %s, stmt: %s%s %s", + (session_is_autocommit(ses) ? "[enabled]" : "[disabled]"), + (session_trx_is_active(ses) ? "[open]" : "[not open]"), + STRPACKETTYPE(ptype), (qtypestr == NULL ? "N/A" : qtypestr), + contentstr, (querybuf->hint == NULL ? "" : ", Hint:"), + (querybuf->hint == NULL ? "" : STRHINTTYPE(querybuf->hint->type))); + MXS_FREE(contentstr); + MXS_FREE(qtypestr); + } + else + { + MXS_INFO("> Processing LOAD DATA LOCAL INFILE: %lu bytes sent.", + rses->rses_load_data_sent); + } } /* @@ -198,22 +198,22 @@ log_transaction_status(ROUTER_CLIENT_SES *rses, GWBUF *querybuf, qc_query_type_t * * If the choice of sending to all backends is in conflict with other bit * settings in route_target, then error messages are written to the log. - * + * * Otherwise, the function route_session_write is called to carry out the * actual routing. - * + * * @param route_target Bit map indicating where packet should be routed * @param inst Router instance * @param rses Router session * @param querybuf Query buffer containing packet * @param packet_type Integer (enum) indicating type of packet - * @param qtype Query type + * @param qtype Query type * @return bool indicating whether the session can continue */ bool handle_target_is_all(route_target_t route_target, - ROUTER_INSTANCE *inst, ROUTER_CLIENT_SES *rses, - GWBUF *querybuf, int packet_type, qc_query_type_t qtype) + ROUTER_INSTANCE *inst, ROUTER_CLIENT_SES *rses, + GWBUF *querybuf, int packet_type, qc_query_type_t qtype) { bool result; @@ -228,12 +228,12 @@ handle_target_is_all(route_target_t route_target, /* NOTE: packet_type is MySQL specific */ MXS_ERROR("Can't route %s:%s:\"%s\". SELECT with session data " - "modification is not supported if configuration parameter " - "use_sql_variables_in=all .", STRPACKETTYPE(packet_type), - qtype_str, (query_str == NULL ? "(empty)" : query_str)); + "modification is not supported if configuration parameter " + "use_sql_variables_in=all .", STRPACKETTYPE(packet_type), + qtype_str, (query_str == NULL ? "(empty)" : query_str)); MXS_INFO("Unable to route the query without losing session data " - "modification from other servers. <"); + "modification from other servers. <"); while (bref != NULL && !BREF_IS_IN_USE(bref)) { @@ -244,9 +244,9 @@ handle_target_is_all(route_target_t route_target, { /** Create and add MySQL error to eventqueue */ modutil_reply_parse_error(bref->bref_dcb, - MXS_STRDUP_A("Routing query to backend failed. " - "See the error log for further " - "details."), 0); + MXS_STRDUP_A("Routing query to backend failed. " + "See the error log for further " + "details."), 0); result = true; } else @@ -256,9 +256,9 @@ handle_target_is_all(route_target_t route_target, * available return false - session will be closed */ MXS_ERROR("Sending error message to client " - "failed. Router doesn't have any " - "available backends. Session will be " - "closed."); + "failed. Router doesn't have any " + "available backends. Session will be " + "closed."); result = false; } /* Test shouldn't be needed */ @@ -278,7 +278,7 @@ handle_target_is_all(route_target_t route_target, * Router locking is done inside the function. */ result = route_session_write(rses, gwbuf_clone(querybuf), inst, - packet_type, qtype); + packet_type, qtype); if (result) { @@ -290,12 +290,12 @@ handle_target_is_all(route_target_t route_target, /* This is MySQL specific */ /** * @brief Write an error message to the log indicating failure - * + * * Used when an attempt to lock the router session fails. * * @param querybuf Query buffer containing packet * @param packet_type Integer (enum) indicating type of packet - * @param qtype Query type + * @param qtype Query type */ void session_lock_failure_handling(GWBUF *querybuf, int packet_type, qc_query_type_t qtype) @@ -306,9 +306,9 @@ session_lock_failure_handling(GWBUF *querybuf, int packet_type, qc_query_type_t char *query_str = modutil_get_query(querybuf); MXS_ERROR("Can't route %s:%s:\"%s\" to " - "backend server. Router is closed.", - STRPACKETTYPE(packet_type), STRQTYPE(qtype), - (query_str == NULL ? "(empty)" : query_str)); + "backend server. Router is closed.", + STRPACKETTYPE(packet_type), STRQTYPE(qtype), + (query_str == NULL ? "(empty)" : query_str)); MXS_FREE(query_str); } } @@ -318,7 +318,7 @@ session_lock_failure_handling(GWBUF *querybuf, int packet_type, qc_query_type_t */ /** * @brief Write an error message to the log for closed session - * + * * This happens if a request is received for a session that is already * closing down. * @@ -343,8 +343,8 @@ void closed_session_reply(GWBUF *querybuf) */ /** * @brief First step to handle request in a live session - * - * Used when a request is about to be routed. Note that the query buffer is + * + * Used when a request is about to be routed. Note that the query buffer is * passed by name and is likely to be modified by this function. * * @param querybuf Query buffer containing packet @@ -374,7 +374,7 @@ void live_session_reply(GWBUF **querybuf, ROUTER_CLIENT_SES *rses) */ /** * @brief Check the reply from a backend server to a session command - * + * * If the reply is an error, a message may be logged. * * @param writebuf Query buffer containing reply data @@ -383,24 +383,24 @@ void live_session_reply(GWBUF **querybuf, ROUTER_CLIENT_SES *rses) */ void check_session_command_reply(GWBUF *writebuf, sescmd_cursor_t *scur, backend_ref_t *bref) { - if (MXS_LOG_PRIORITY_IS_ENABLED(LOG_ERR) && - MYSQL_IS_ERROR_PACKET(((uint8_t *)GWBUF_DATA(writebuf)))) - { - uint8_t *buf = (uint8_t *)GWBUF_DATA((scur->scmd_cur_cmd->my_sescmd_buf)); - uint8_t *replybuf = (uint8_t *)GWBUF_DATA(writebuf); - size_t len = MYSQL_GET_PAYLOAD_LEN(buf); - size_t replylen = MYSQL_GET_PAYLOAD_LEN(replybuf); - char *err = strndup(&((char *)replybuf)[8], 5); - char *replystr = strndup(&((char *)replybuf)[13], replylen - 4 - 5); + if (MXS_LOG_PRIORITY_IS_ENABLED(LOG_ERR) && + MYSQL_IS_ERROR_PACKET(((uint8_t *)GWBUF_DATA(writebuf)))) + { + uint8_t *buf = (uint8_t *)GWBUF_DATA((scur->scmd_cur_cmd->my_sescmd_buf)); + uint8_t *replybuf = (uint8_t *)GWBUF_DATA(writebuf); + size_t len = MYSQL_GET_PAYLOAD_LEN(buf); + size_t replylen = MYSQL_GET_PAYLOAD_LEN(replybuf); + char *err = strndup(&((char *)replybuf)[8], 5); + char *replystr = strndup(&((char *)replybuf)[13], replylen - 4 - 5); - ss_dassert(len + 4 == GWBUF_LENGTH(scur->scmd_cur_cmd->my_sescmd_buf)); + ss_dassert(len + 4 == GWBUF_LENGTH(scur->scmd_cur_cmd->my_sescmd_buf)); - MXS_ERROR("Failed to execute session command in %s:%d. Error was: %s %s", - bref->ref->server->name, - bref->ref->server->port, err, replystr); - MXS_FREE(err); - MXS_FREE(replystr); - } + MXS_ERROR("Failed to execute session command in %s:%d. Error was: %s %s", + bref->ref->server->name, + bref->ref->server->port, err, replystr); + MXS_FREE(err); + MXS_FREE(replystr); + } } /** @@ -412,7 +412,7 @@ void check_session_command_reply(GWBUF *writebuf, sescmd_cursor_t *scur, backend * commands. * * Router session must be locked. - * + * * @param backend_ref Router session backend database data * @return bool - true for success, false for failure */ @@ -464,14 +464,14 @@ bool execute_sescmd_in_backend(backend_ref_t *backend_ref) switch (scur->scmd_cur_cmd->my_sescmd_packet_type) { - case MYSQL_COM_CHANGE_USER: - /** This makes it possible to handle replies correctly */ - gwbuf_set_type(scur->scmd_cur_cmd->my_sescmd_buf, GWBUF_TYPE_SESCMD); - buf = sescmd_cursor_clone_querybuf(scur); - rc = dcb->func.auth(dcb, NULL, dcb->session, buf); - break; + case MYSQL_COM_CHANGE_USER: + /** This makes it possible to handle replies correctly */ + gwbuf_set_type(scur->scmd_cur_cmd->my_sescmd_buf, GWBUF_TYPE_SESCMD); + buf = sescmd_cursor_clone_querybuf(scur); + rc = dcb->func.auth(dcb, NULL, dcb->session, buf); + break; - case MYSQL_COM_INIT_DB: + case MYSQL_COM_INIT_DB: { /** * Record database name and store to session. @@ -498,18 +498,18 @@ bool execute_sescmd_in_backend(backend_ref_t *backend_ref) data->db[qlen] = 0; } } - /** Fallthrough */ - case MYSQL_COM_QUERY: - default: - /** - * Mark session command buffer, it triggers writing - * MySQL command to protocol - */ + /** Fallthrough */ + case MYSQL_COM_QUERY: + default: + /** + * Mark session command buffer, it triggers writing + * MySQL command to protocol + */ - gwbuf_set_type(scur->scmd_cur_cmd->my_sescmd_buf, GWBUF_TYPE_SESCMD); - buf = sescmd_cursor_clone_querybuf(scur); - rc = dcb->func.write(dcb, buf); - break; + gwbuf_set_type(scur->scmd_cur_cmd->my_sescmd_buf, GWBUF_TYPE_SESCMD); + buf = sescmd_cursor_clone_querybuf(scur); + rc = dcb->func.write(dcb, buf); + break; } if (rc == 1) @@ -582,7 +582,7 @@ bool send_readonly_error(DCB *dcb) { bool succp = false; const char* errmsg = "The MariaDB server is running with the --read-only" - " option so it cannot execute this statement"; + " option so it cannot execute this statement"; GWBUF* err = modutil_create_mysql_err_msg(1, 0, ER_OPTION_PREVENTS_STATEMENT, "HY000", errmsg); diff --git a/server/modules/routing/readwritesplit/rwsplit_route_stmt.c b/server/modules/routing/readwritesplit/rwsplit_route_stmt.c index 3ec81ccbb..7975f29f7 100644 --- a/server/modules/routing/readwritesplit/rwsplit_route_stmt.c +++ b/server/modules/routing/readwritesplit/rwsplit_route_stmt.c @@ -55,7 +55,7 @@ static backend_ref_t *get_root_master_bref(ROUTER_CLIENT_SES *rses); * false if backend failure was encountered. */ bool route_single_stmt(ROUTER_INSTANCE *inst, ROUTER_CLIENT_SES *rses, - GWBUF *querybuf) + GWBUF *querybuf) { qc_query_type_t qtype = QUERY_TYPE_UNKNOWN; int packet_type; @@ -177,9 +177,9 @@ bool route_single_stmt(ROUTER_INSTANCE *inst, ROUTER_CLIENT_SES *rses, * */ bool route_session_write(ROUTER_CLIENT_SES *router_cli_ses, - GWBUF *querybuf, ROUTER_INSTANCE *inst, - int packet_type, - qc_query_type_t qtype) + GWBUF *querybuf, ROUTER_INSTANCE *inst, + int packet_type, + qc_query_type_t qtype) { bool succp; rses_property_t *prop; @@ -394,7 +394,7 @@ return_succp: /** * @brief Function to hash keys in read-write split router - * + * * Used to store information about temporary tables. * * @param key key to be hashed, actually a character string @@ -419,7 +419,7 @@ int rwsplit_hashkeyfun(const void *key) /** * @brief Function to compare hash keys in read-write split router - * + * * Used to manage information about temporary tables. * * @param key first key to be compared, actually a character string @@ -436,7 +436,7 @@ int rwsplit_hashcmpfun(const void *v1, const void *v2) /** * @brief Function to duplicate a hash value in read-write split router - * + * * Used to manage information about temporary tables. * * @param fval value to be duplicated, actually a character string @@ -450,7 +450,7 @@ void *rwsplit_hstrdup(const void *fval) /** * @brief Function to free hash values in read-write split router - * + * * Used to manage information about temporary tables. * * @param key value to be freed @@ -476,7 +476,7 @@ void rwsplit_hfree(void *fval) * @return True if proper DCB was found, false otherwise. */ bool rwsplit_get_dcb(DCB **p_dcb, ROUTER_CLIENT_SES *rses, backend_type_t btype, - char *name, int max_rlag) + char *name, int max_rlag) { backend_ref_t *backend_ref; backend_ref_t *master_bref; @@ -771,9 +771,9 @@ route_target_t get_route_target(ROUTER_CLIENT_SES *rses, } } else if (qc_query_is_type(qtype, QUERY_TYPE_READ) || // Normal read - qc_query_is_type(qtype, QUERY_TYPE_SHOW_TABLES) || // SHOW TABLES - qc_query_is_type(qtype, QUERY_TYPE_SYSVAR_READ) || // System variable - qc_query_is_type(qtype, QUERY_TYPE_GSYSVAR_READ)) // Global system variable + qc_query_is_type(qtype, QUERY_TYPE_SHOW_TABLES) || // SHOW TABLES + qc_query_is_type(qtype, QUERY_TYPE_SYSVAR_READ) || // System variable + qc_query_is_type(qtype, QUERY_TYPE_GSYSVAR_READ)) // Global system variable { target = TARGET_SLAVE; } @@ -809,9 +809,9 @@ route_target_t get_route_target(ROUTER_CLIENT_SES *rses, qc_query_is_type(qtype, QUERY_TYPE_CREATE_TMP_TABLE) || qc_query_is_type(qtype, QUERY_TYPE_READ_TMP_TABLE) || qc_query_is_type(qtype, QUERY_TYPE_UNKNOWN)) || - qc_query_is_type(qtype, QUERY_TYPE_EXEC_STMT) || - qc_query_is_type(qtype, QUERY_TYPE_PREPARE_STMT) || - qc_query_is_type(qtype, QUERY_TYPE_PREPARE_NAMED_STMT)); + qc_query_is_type(qtype, QUERY_TYPE_EXEC_STMT) || + qc_query_is_type(qtype, QUERY_TYPE_PREPARE_STMT) || + qc_query_is_type(qtype, QUERY_TYPE_PREPARE_NAMED_STMT)); target = TARGET_MASTER; } @@ -874,7 +874,7 @@ route_target_t get_route_target(ROUTER_CLIENT_SES *rses, /** * @brief Handle multi statement queries and load statements - * + * * One of the possible types of handling required when a request is routed * * @param ses Router session @@ -884,104 +884,104 @@ route_target_t get_route_target(ROUTER_CLIENT_SES *rses, */ void handle_multi_temp_and_load(ROUTER_CLIENT_SES *rses, GWBUF *querybuf, - int packet_type, int *qtype) + int packet_type, int *qtype) { - /** Check for multi-statement queries. If no master server is available - * and a multi-statement is issued, an error is returned to the client - * when the query is routed. - * - * If we do not have a master node, assigning the forced node is not - * effective since we don't have a node to force queries to. In this - * situation, assigning QUERY_TYPE_WRITE for the query will trigger - * the error processing. */ - if ((rses->forced_node == NULL || rses->forced_node != rses->rses_master_ref) && - check_for_multi_stmt(querybuf, rses->client_dcb->protocol, packet_type)) + /** Check for multi-statement queries. If no master server is available + * and a multi-statement is issued, an error is returned to the client + * when the query is routed. + * + * If we do not have a master node, assigning the forced node is not + * effective since we don't have a node to force queries to. In this + * situation, assigning QUERY_TYPE_WRITE for the query will trigger + * the error processing. */ + if ((rses->forced_node == NULL || rses->forced_node != rses->rses_master_ref) && + check_for_multi_stmt(querybuf, rses->client_dcb->protocol, packet_type)) + { + if (rses->rses_master_ref) { - if (rses->rses_master_ref) - { - rses->forced_node = rses->rses_master_ref; - MXS_INFO("Multi-statement query, routing all future queries to master."); - } - else - { - *qtype |= QUERY_TYPE_WRITE; - } + rses->forced_node = rses->rses_master_ref; + MXS_INFO("Multi-statement query, routing all future queries to master."); } - - /* - * Make checks prior to calling temp tables functions - */ - - if (rses == NULL || querybuf == NULL || - rses->client_dcb == NULL || rses->client_dcb->data == NULL) - { - if (rses == NULL || querybuf == NULL) - { - MXS_ERROR("[%s] Error: NULL variables for temp table checks: %p %p", __FUNCTION__, - rses, querybuf); - } - - if (rses->client_dcb == NULL) - { - MXS_ERROR("[%s] Error: Client DCB is NULL.", __FUNCTION__); - } - - if (rses->client_dcb->data == NULL) - { - MXS_ERROR("[%s] Error: User data in master server DBC is NULL.", - __FUNCTION__); - } - } - else { - /** - * Check if the query has anything to do with temporary tables. - */ - if (rses->have_tmp_tables) - { - check_drop_tmp_table(rses, querybuf, packet_type); - if (is_packet_a_query(packet_type) && is_read_tmp_table(rses, querybuf, *qtype)) - { - *qtype |= QUERY_TYPE_MASTER_READ; - } - } - check_create_tmp_table(rses, querybuf, *qtype); + *qtype |= QUERY_TYPE_WRITE; + } + } + + /* + * Make checks prior to calling temp tables functions + */ + + if (rses == NULL || querybuf == NULL || + rses->client_dcb == NULL || rses->client_dcb->data == NULL) + { + if (rses == NULL || querybuf == NULL) + { + MXS_ERROR("[%s] Error: NULL variables for temp table checks: %p %p", __FUNCTION__, + rses, querybuf); } - /** - * Check if this is a LOAD DATA LOCAL INFILE query. If so, send all queries - * to the master until the last, empty packet arrives. - */ - if (rses->rses_load_active) + if (rses->client_dcb == NULL) { - rses->rses_load_data_sent += gwbuf_length(querybuf); + MXS_ERROR("[%s] Error: Client DCB is NULL.", __FUNCTION__); } - else if (is_packet_a_query(packet_type)) + + if (rses->client_dcb->data == NULL) { - qc_query_op_t queryop = qc_get_operation(querybuf); - if (queryop == QUERY_OP_LOAD) + MXS_ERROR("[%s] Error: User data in master server DBC is NULL.", + __FUNCTION__); + } + } + + else + { + /** + * Check if the query has anything to do with temporary tables. + */ + if (rses->have_tmp_tables) + { + check_drop_tmp_table(rses, querybuf, packet_type); + if (is_packet_a_query(packet_type) && is_read_tmp_table(rses, querybuf, *qtype)) { - rses->rses_load_active = true; - rses->rses_load_data_sent = 0; + *qtype |= QUERY_TYPE_MASTER_READ; } } + check_create_tmp_table(rses, querybuf, *qtype); + } + + /** + * Check if this is a LOAD DATA LOCAL INFILE query. If so, send all queries + * to the master until the last, empty packet arrives. + */ + if (rses->rses_load_active) + { + rses->rses_load_data_sent += gwbuf_length(querybuf); + } + else if (is_packet_a_query(packet_type)) + { + qc_query_op_t queryop = qc_get_operation(querybuf); + if (queryop == QUERY_OP_LOAD) + { + rses->rses_load_active = true; + rses->rses_load_data_sent = 0; + } + } } /** * @brief Handle hinted target query - * + * * One of the possible types of handling required when a request is routed * * @param ses Router session * @param querybuf Buffer containing query to be routed * @param route_target Target for the query * @param target_dcb DCB for the target server - * + * * @return bool - true if succeeded, false otherwise */ bool handle_hinted_target(ROUTER_CLIENT_SES *rses, GWBUF *querybuf, - route_target_t route_target, DCB **target_dcb) + route_target_t route_target, DCB **target_dcb) { HINT *hint; char *named_server = NULL; @@ -1003,8 +1003,8 @@ bool handle_hinted_target(ROUTER_CLIENT_SES *rses, GWBUF *querybuf, MXS_INFO("Hint: route to server '%s'", named_server); } else if (hint->type == HINT_PARAMETER && - (strncasecmp((char *)hint->data, "max_slave_replication_lag", - strlen("max_slave_replication_lag")) == 0)) + (strncasecmp((char *)hint->data, "max_slave_replication_lag", + strlen("max_slave_replication_lag")) == 0)) { int val = (int)strtol((char *)hint->value, (char **)NULL, 10); @@ -1037,14 +1037,14 @@ bool handle_hinted_target(ROUTER_CLIENT_SES *rses, GWBUF *querybuf, if (TARGET_IS_NAMED_SERVER(route_target)) { MXS_INFO("Was supposed to route to named server " - "%s but couldn't find the server in a " - "suitable state.", named_server); + "%s but couldn't find the server in a " + "suitable state.", named_server); } else if (TARGET_IS_RLAG_MAX(route_target)) { MXS_INFO("Was supposed to route to server with " - "replication lag at most %d but couldn't " - "find such a slave.", rlag_max); + "replication lag at most %d but couldn't " + "find such a slave.", rlag_max); } } return succp; @@ -1052,17 +1052,17 @@ bool handle_hinted_target(ROUTER_CLIENT_SES *rses, GWBUF *querybuf, /** * @brief Handle slave is the target - * + * * One of the possible types of handling required when a request is routed * * @param inst Router instance * @param ses Router session * @param target_dcb DCB for the target server - * + * * @return bool - true if succeeded, false otherwise */ bool handle_slave_is_target(ROUTER_INSTANCE *inst, ROUTER_CLIENT_SES *rses, - DCB **target_dcb) + DCB **target_dcb) { int rlag_max = rses_get_max_replication_lag(rses); @@ -1093,7 +1093,7 @@ static void log_master_routing_failure(ROUTER_CLIENT_SES *rses, bool found, if (!found) { - sprintf(errmsg, "Could not find a valid master connection"); + sprintf(errmsg, "Could not find a valid master connection"); } else if (master_dcb && curr_master_dcb) { @@ -1141,13 +1141,13 @@ static void log_master_routing_failure(ROUTER_CLIENT_SES *rses, bool found, /** * @brief Handle master is the target - * + * * One of the possible types of handling required when a request is routed * * @param inst Router instance * @param ses Router session * @param target_dcb DCB for the target server - * + * * @return bool - true if succeeded, false otherwise */ bool handle_master_is_target(ROUTER_INSTANCE *inst, ROUTER_CLIENT_SES *rses, @@ -1197,14 +1197,14 @@ bool handle_master_is_target(ROUTER_INSTANCE *inst, ROUTER_CLIENT_SES *rses, /** * @brief Handle got a target - * + * * One of the possible types of handling required when a request is routed * * @param inst Router instance * @param ses Router session * @param querybuf Buffer containing query to be routed * @param target_dcb DCB for the target server - * + * * @return bool - true if succeeded, false otherwise */ bool @@ -1220,8 +1220,8 @@ handle_got_target(ROUTER_INSTANCE *inst, ROUTER_CLIENT_SES *rses, ss_dassert(target_dcb != NULL); MXS_INFO("Route query to %s \t%s:%d <", - (SERVER_IS_MASTER(bref->ref->server) ? "master" - : "slave"), bref->ref->server->name, bref->ref->server->port); + (SERVER_IS_MASTER(bref->ref->server) ? "master" + : "slave"), bref->ref->server->name, bref->ref->server->port); /** * Store current statement if execution of previous session command is still * active. Since the master server's response is always used, we can safely @@ -1260,9 +1260,9 @@ handle_got_target(ROUTER_INSTANCE *inst, ROUTER_CLIENT_SES *rses, /** * @brief Create a generic router session property structure. - * + * * @param prop_type Property type - * + * * @return property structure of requested type, or NULL if failed */ rses_property_t *rses_property_init(rses_property_type_t prop_type) @@ -1286,16 +1286,16 @@ rses_property_t *rses_property_init(rses_property_type_t prop_type) /** * @brief Add property to the router client session - * + * * Add property to the router_client_ses structure's rses_properties * array. The slot is determined by the type of property. * In each slot there is a list of properties of similar type. * * Router client session must be locked. - * + * * @param rses Router session * @param prop Router session property to be added - * + * * @return -1 on failure, 0 on success */ int rses_property_add(ROUTER_CLIENT_SES *rses, rses_property_t *prop) diff --git a/server/modules/routing/readwritesplit/rwsplit_select_backends.c b/server/modules/routing/readwritesplit/rwsplit_select_backends.c index a3a87e15e..777366dd5 100644 --- a/server/modules/routing/readwritesplit/rwsplit_select_backends.c +++ b/server/modules/routing/readwritesplit/rwsplit_select_backends.c @@ -23,7 +23,7 @@ #include "rwsplit_internal.h" /** * @file rwsplit_select_backends.c The functions that implement back end - * selection for the read write split router. All of these functions are + * selection for the read write split router. All of these functions are * internal to that router and not intended to be called from elsewhere. * * @verbatim @@ -38,7 +38,7 @@ static bool connect_server(backend_ref_t *bref, SESSION *session, bool execute_history); static void log_server_connections(select_criteria_t select_criteria, - backend_ref_t *backend_ref, int router_nservers); + backend_ref_t *backend_ref, int router_nservers); static SERVER_REF *get_root_master(backend_ref_t *servers, int router_nservers); @@ -86,7 +86,7 @@ static bool bref_valid_for_slave(const backend_ref_t *bref, const SERVER *master SERVER *server = bref->ref->server; return (SERVER_IS_SLAVE(server) || SERVER_IS_RELAY_SERVER(server)) && - (master_host == NULL || (server != master_host)); + (master_host == NULL || (server != master_host)); } /** @@ -148,13 +148,13 @@ backend_ref_t* get_slave_candidate(backend_ref_t *bref, int n, const SERVER *mas * @return true, if at least one master and one slave was found. */ bool select_connect_backend_servers(backend_ref_t **p_master_ref, - backend_ref_t *backend_ref, - int router_nservers, int max_nslaves, - int max_slave_rlag, - select_criteria_t select_criteria, - SESSION *session, - ROUTER_INSTANCE *router, - bool active_session) + backend_ref_t *backend_ref, + int router_nservers, int max_nslaves, + int max_slave_rlag, + select_criteria_t select_criteria, + SESSION *session, + ROUTER_INSTANCE *router, + bool active_session) { if (p_master_ref == NULL || backend_ref == NULL) { @@ -285,7 +285,7 @@ bool select_connect_backend_servers(backend_ref_t **p_master_ref, } /* for */ } } - /** Failure cases */ + /** Failure cases */ else { MXS_ERROR("Couldn't establish required amount of slave connections for " @@ -471,7 +471,7 @@ static bool connect_server(backend_ref_t *bref, SESSION *session, bool execute_h * @param router_nservers Number of backends in @p backend_ref */ static void log_server_connections(select_criteria_t select_criteria, - backend_ref_t *backend_ref, int router_nservers) + backend_ref_t *backend_ref, int router_nservers) { if (select_criteria == LEAST_GLOBAL_CONNECTIONS || select_criteria == LEAST_ROUTER_CONNECTIONS || @@ -488,31 +488,31 @@ static void log_server_connections(select_criteria_t select_criteria, switch (select_criteria) { - case LEAST_GLOBAL_CONNECTIONS: - MXS_INFO("MaxScale connections : %d in \t%s:%d %s", - b->server->stats.n_current, b->server->name, - b->server->port, STRSRVSTATUS(b->server)); - break; + case LEAST_GLOBAL_CONNECTIONS: + MXS_INFO("MaxScale connections : %d in \t%s:%d %s", + b->server->stats.n_current, b->server->name, + b->server->port, STRSRVSTATUS(b->server)); + break; - case LEAST_ROUTER_CONNECTIONS: - MXS_INFO("RWSplit connections : %d in \t%s:%d %s", - b->connections, b->server->name, - b->server->port, STRSRVSTATUS(b->server)); - break; + case LEAST_ROUTER_CONNECTIONS: + MXS_INFO("RWSplit connections : %d in \t%s:%d %s", + b->connections, b->server->name, + b->server->port, STRSRVSTATUS(b->server)); + break; - case LEAST_CURRENT_OPERATIONS: - MXS_INFO("current operations : %d in \t%s:%d %s", - b->server->stats.n_current_ops, - b->server->name, b->server->port, - STRSRVSTATUS(b->server)); - break; + case LEAST_CURRENT_OPERATIONS: + MXS_INFO("current operations : %d in \t%s:%d %s", + b->server->stats.n_current_ops, + b->server->name, b->server->port, + STRSRVSTATUS(b->server)); + break; - case LEAST_BEHIND_MASTER: - MXS_INFO("replication lag : %d in \t%s:%d %s", - b->server->rlag, b->server->name, - b->server->port, STRSRVSTATUS(b->server)); - default: - break; + case LEAST_BEHIND_MASTER: + MXS_INFO("replication lag : %d in \t%s:%d %s", + b->server->rlag, b->server->name, + b->server->port, STRSRVSTATUS(b->server)); + default: + break; } } } diff --git a/server/modules/routing/readwritesplit/rwsplit_session_cmd.c b/server/modules/routing/readwritesplit/rwsplit_session_cmd.c index 11b8280f1..41d89894f 100644 --- a/server/modules/routing/readwritesplit/rwsplit_session_cmd.c +++ b/server/modules/routing/readwritesplit/rwsplit_session_cmd.c @@ -76,9 +76,9 @@ mysql_sescmd_t *rses_property_get_sescmd(rses_property_t *prop) * Create session command property. */ mysql_sescmd_t *mysql_sescmd_init(rses_property_t *rses_prop, - GWBUF *sescmd_buf, - unsigned char packet_type, - ROUTER_CLIENT_SES *rses) + GWBUF *sescmd_buf, + unsigned char packet_type, + ROUTER_CLIENT_SES *rses) { mysql_sescmd_t *sescmd; @@ -131,8 +131,8 @@ void mysql_sescmd_done(mysql_sescmd_t *sescmd) * 9. s+q+ */ GWBUF *sescmd_cursor_process_replies(GWBUF *replybuf, - backend_ref_t *bref, - bool *reconnect) + backend_ref_t *bref, + bool *reconnect) { mysql_sescmd_t *scmd; sescmd_cursor_t *scur; @@ -176,7 +176,7 @@ GWBUF *sescmd_cursor_process_replies(GWBUF *replybuf, MXS_ERROR("Slave server '%s': response differs from master's response. " "Closing connection due to inconsistent session state.", bref->ref->server->unique_name); - close_failed_bref(bref, true); + close_failed_bref(bref, true); RW_CHK_DCB(bref, bref->bref_dcb); dcb_close(bref->bref_dcb); @@ -301,7 +301,7 @@ bool sescmd_cursor_is_active(sescmd_cursor_t *sescmd_cursor) /** router must be locked */ void sescmd_cursor_set_active(sescmd_cursor_t *sescmd_cursor, - bool value) + bool value) { ss_dassert(SPINLOCK_IS_LOCKED(&sescmd_cursor->scmd_cur_rses->rses_lock)); /** avoid calling unnecessarily */ diff --git a/server/modules/routing/readwritesplit/rwsplit_tmp_table_multi.c b/server/modules/routing/readwritesplit/rwsplit_tmp_table_multi.c index 4a6bdee14..f3ec8fa63 100644 --- a/server/modules/routing/readwritesplit/rwsplit_tmp_table_multi.c +++ b/server/modules/routing/readwritesplit/rwsplit_tmp_table_multi.c @@ -47,7 +47,7 @@ /** * @brief Check for dropping of temporary tables - * + * * Check if the query is a DROP TABLE... query and * if it targets a temporary table, remove it from the hashtable. * @param router_cli_ses Router client session @@ -55,7 +55,7 @@ * @param type The type of the query resolved so far */ void check_drop_tmp_table(ROUTER_CLIENT_SES *router_cli_ses, GWBUF *querybuf, - mysql_server_cmd_t packet_type) + mysql_server_cmd_t packet_type) { if (packet_type != MYSQL_COM_QUERY && packet_type != MYSQL_COM_DROP_DB) { @@ -112,8 +112,8 @@ void check_drop_tmp_table(ROUTER_CLIENT_SES *router_cli_ses, GWBUF *querybuf, * @return The type of the query */ bool is_read_tmp_table(ROUTER_CLIENT_SES *router_cli_ses, - GWBUF *querybuf, - qc_query_type_t qtype) + GWBUF *querybuf, + qc_query_type_t qtype) { bool target_tmp_table = false; @@ -199,7 +199,7 @@ bool is_read_tmp_table(ROUTER_CLIENT_SES *router_cli_ses, * @param type The type of the query resolved so far */ void check_create_tmp_table(ROUTER_CLIENT_SES *router_cli_ses, - GWBUF *querybuf, qc_query_type_t type) + GWBUF *querybuf, qc_query_type_t type) { if (!qc_query_is_type(type, QUERY_TYPE_CREATE_TMP_TABLE)) { @@ -357,11 +357,11 @@ bool check_for_multi_stmt(GWBUF *buf, void *protocol, mysql_server_cmd_t packet_ /** * @brief Determine the type of a query - * + * * @param querybuf GWBUF containing the query * @param packet_type Integer denoting DB specific enum * @param non_empty_packet Boolean to be set by this function - * + * * @return qc_query_type_t the query type; also the non_empty_packet bool is set */ qc_query_type_t @@ -374,47 +374,47 @@ determine_query_type(GWBUF *querybuf, int packet_type, bool non_empty_packet) mysql_server_cmd_t my_packet_type = (mysql_server_cmd_t)packet_type; switch (my_packet_type) { - case MYSQL_COM_QUIT: /*< 1 QUIT will close all sessions */ - case MYSQL_COM_INIT_DB: /*< 2 DDL must go to the master */ - case MYSQL_COM_REFRESH: /*< 7 - I guess this is session but not sure */ - case MYSQL_COM_DEBUG: /*< 0d all servers dump debug info to stdout */ - case MYSQL_COM_PING: /*< 0e all servers are pinged */ - case MYSQL_COM_CHANGE_USER: /*< 11 all servers change it accordingly */ - qtype = QUERY_TYPE_SESSION_WRITE; - break; + case MYSQL_COM_QUIT: /*< 1 QUIT will close all sessions */ + case MYSQL_COM_INIT_DB: /*< 2 DDL must go to the master */ + case MYSQL_COM_REFRESH: /*< 7 - I guess this is session but not sure */ + case MYSQL_COM_DEBUG: /*< 0d all servers dump debug info to stdout */ + case MYSQL_COM_PING: /*< 0e all servers are pinged */ + case MYSQL_COM_CHANGE_USER: /*< 11 all servers change it accordingly */ + qtype = QUERY_TYPE_SESSION_WRITE; + break; - case MYSQL_COM_CREATE_DB: /**< 5 DDL must go to the master */ - case MYSQL_COM_DROP_DB: /**< 6 DDL must go to the master */ - case MYSQL_COM_STMT_CLOSE: /*< free prepared statement */ - case MYSQL_COM_STMT_SEND_LONG_DATA: /*< send data to column */ - case MYSQL_COM_STMT_RESET: /*< resets the data of a prepared statement */ - qtype = QUERY_TYPE_WRITE; - break; + case MYSQL_COM_CREATE_DB: /**< 5 DDL must go to the master */ + case MYSQL_COM_DROP_DB: /**< 6 DDL must go to the master */ + case MYSQL_COM_STMT_CLOSE: /*< free prepared statement */ + case MYSQL_COM_STMT_SEND_LONG_DATA: /*< send data to column */ + case MYSQL_COM_STMT_RESET: /*< resets the data of a prepared statement */ + qtype = QUERY_TYPE_WRITE; + break; - case MYSQL_COM_QUERY: - qtype = qc_get_type(querybuf); - break; + case MYSQL_COM_QUERY: + qtype = qc_get_type(querybuf); + break; - case MYSQL_COM_STMT_PREPARE: - qtype = qc_get_type(querybuf); - qtype |= QUERY_TYPE_PREPARE_STMT; - break; + case MYSQL_COM_STMT_PREPARE: + qtype = qc_get_type(querybuf); + qtype |= QUERY_TYPE_PREPARE_STMT; + break; - case MYSQL_COM_STMT_EXECUTE: - /** Parsing is not needed for this type of packet */ - qtype = QUERY_TYPE_EXEC_STMT; - break; + case MYSQL_COM_STMT_EXECUTE: + /** Parsing is not needed for this type of packet */ + qtype = QUERY_TYPE_EXEC_STMT; + break; - case MYSQL_COM_SHUTDOWN: /**< 8 where should shutdown be routed ? */ - case MYSQL_COM_STATISTICS: /**< 9 ? */ - case MYSQL_COM_PROCESS_INFO: /**< 0a ? */ - case MYSQL_COM_CONNECT: /**< 0b ? */ - case MYSQL_COM_PROCESS_KILL: /**< 0c ? */ - case MYSQL_COM_TIME: /**< 0f should this be run in gateway ? */ - case MYSQL_COM_DELAYED_INSERT: /**< 10 ? */ - case MYSQL_COM_DAEMON: /**< 1d ? */ - default: - break; + case MYSQL_COM_SHUTDOWN: /**< 8 where should shutdown be routed ? */ + case MYSQL_COM_STATISTICS: /**< 9 ? */ + case MYSQL_COM_PROCESS_INFO: /**< 0a ? */ + case MYSQL_COM_CONNECT: /**< 0b ? */ + case MYSQL_COM_PROCESS_KILL: /**< 0c ? */ + case MYSQL_COM_TIME: /**< 0f should this be run in gateway ? */ + case MYSQL_COM_DELAYED_INSERT: /**< 10 ? */ + case MYSQL_COM_DAEMON: /**< 1d ? */ + default: + break; } /**< switch by packet type */ } return qtype; diff --git a/server/modules/routing/schemarouter/schemarouter.c b/server/modules/routing/schemarouter/schemarouter.c index edeed58d0..6a513d3e8 100644 --- a/server/modules/routing/schemarouter/schemarouter.c +++ b/server/modules/routing/schemarouter/schemarouter.c @@ -236,25 +236,25 @@ char* get_lenenc_str(void* data) { switch (*(ptr)) { - case 0xfb: - return NULL; - case 0xfc: - size = *(ptr + 1) + (*(ptr + 2) << 8); - offset = 2; - break; - case 0xfd: - size = *ptr + (*(ptr + 2) << 8) + (*(ptr + 3) << 16); - offset = 3; - break; - case 0xfe: - size = *ptr + ((*(ptr + 2) << 8)) + (*(ptr + 3) << 16) + - (*(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: - return NULL; + case 0xfb: + return NULL; + case 0xfc: + size = *(ptr + 1) + (*(ptr + 2) << 8); + offset = 2; + break; + case 0xfd: + size = *ptr + (*(ptr + 2) << 8) + (*(ptr + 3) << 16); + offset = 3; + break; + case 0xfe: + size = *ptr + ((*(ptr + 2) << 8)) + (*(ptr + 3) << 16) + + (*(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: + return NULL; } } @@ -1747,48 +1747,48 @@ static int routeQuery(ROUTER* instance, switch (packet_type) { - case MYSQL_COM_QUIT: /*< 1 QUIT will close all sessions */ - case MYSQL_COM_INIT_DB: /*< 2 DDL must go to the master */ - case MYSQL_COM_REFRESH: /*< 7 - I guess this is session but not sure */ - case MYSQL_COM_DEBUG: /*< 0d all servers dump debug info to stdout */ - case MYSQL_COM_PING: /*< 0e all servers are pinged */ - case MYSQL_COM_CHANGE_USER: /*< 11 all servers change it accordingly */ - case MYSQL_COM_STMT_CLOSE: /*< free prepared statement */ - case MYSQL_COM_STMT_SEND_LONG_DATA: /*< send data to column */ - case MYSQL_COM_STMT_RESET: /*< resets the data of a prepared statement */ - qtype = QUERY_TYPE_SESSION_WRITE; - break; + case MYSQL_COM_QUIT: /*< 1 QUIT will close all sessions */ + case MYSQL_COM_INIT_DB: /*< 2 DDL must go to the master */ + case MYSQL_COM_REFRESH: /*< 7 - I guess this is session but not sure */ + case MYSQL_COM_DEBUG: /*< 0d all servers dump debug info to stdout */ + case MYSQL_COM_PING: /*< 0e all servers are pinged */ + case MYSQL_COM_CHANGE_USER: /*< 11 all servers change it accordingly */ + case MYSQL_COM_STMT_CLOSE: /*< free prepared statement */ + case MYSQL_COM_STMT_SEND_LONG_DATA: /*< send data to column */ + case MYSQL_COM_STMT_RESET: /*< resets the data of a prepared statement */ + qtype = QUERY_TYPE_SESSION_WRITE; + break; - case MYSQL_COM_CREATE_DB: /**< 5 DDL must go to the master */ - case MYSQL_COM_DROP_DB: /**< 6 DDL must go to the master */ - qtype = QUERY_TYPE_WRITE; - break; + case MYSQL_COM_CREATE_DB: /**< 5 DDL must go to the master */ + case MYSQL_COM_DROP_DB: /**< 6 DDL must go to the master */ + qtype = QUERY_TYPE_WRITE; + break; - case MYSQL_COM_QUERY: - qtype = qc_get_type(querybuf); - op = qc_get_operation(querybuf); - break; + case MYSQL_COM_QUERY: + qtype = qc_get_type(querybuf); + op = qc_get_operation(querybuf); + break; - case MYSQL_COM_STMT_PREPARE: - qtype = qc_get_type(querybuf); - qtype |= QUERY_TYPE_PREPARE_STMT; - break; + case MYSQL_COM_STMT_PREPARE: + qtype = qc_get_type(querybuf); + qtype |= QUERY_TYPE_PREPARE_STMT; + break; - case MYSQL_COM_STMT_EXECUTE: - /** Parsing is not needed for this type of packet */ - qtype = QUERY_TYPE_EXEC_STMT; - break; + case MYSQL_COM_STMT_EXECUTE: + /** Parsing is not needed for this type of packet */ + qtype = QUERY_TYPE_EXEC_STMT; + break; - case MYSQL_COM_SHUTDOWN: /**< 8 where should shutdown be routed ? */ - case MYSQL_COM_STATISTICS: /**< 9 ? */ - case MYSQL_COM_PROCESS_INFO: /**< 0a ? */ - case MYSQL_COM_CONNECT: /**< 0b ? */ - case MYSQL_COM_PROCESS_KILL: /**< 0c ? */ - case MYSQL_COM_TIME: /**< 0f should this be run in gateway ? */ - case MYSQL_COM_DELAYED_INSERT: /**< 10 ? */ - case MYSQL_COM_DAEMON: /**< 1d ? */ - default: - break; + case MYSQL_COM_SHUTDOWN: /**< 8 where should shutdown be routed ? */ + case MYSQL_COM_STATISTICS: /**< 9 ? */ + case MYSQL_COM_PROCESS_INFO: /**< 0a ? */ + case MYSQL_COM_CONNECT: /**< 0b ? */ + case MYSQL_COM_PROCESS_KILL: /**< 0c ? */ + case MYSQL_COM_TIME: /**< 0f should this be run in gateway ? */ + case MYSQL_COM_DELAYED_INSERT: /**< 10 ? */ + case MYSQL_COM_DAEMON: /**< 1d ? */ + default: + break; } /**< switch by packet type */ @@ -1797,7 +1797,7 @@ static int routeQuery(ROUTER* instance, uint8_t* packet = GWBUF_DATA(querybuf); unsigned char ptype = packet[4]; size_t len = MXS_MIN(GWBUF_LENGTH(querybuf), - MYSQL_GET_PAYLOAD_LEN((unsigned char *)querybuf->start) - 1); + MYSQL_GET_PAYLOAD_LEN((unsigned char *)querybuf->start) - 1); char* data = (char*)&packet[5]; char* contentstr = strndup(data, len); char* qtypestr = qc_typemask_to_string(qtype); @@ -2870,22 +2870,22 @@ static void rses_property_done(rses_property_t* prop) switch (prop->rses_prop_type) { - case RSES_PROP_TYPE_SESCMD: - mysql_sescmd_done(&prop->rses_prop_data.sescmd); - break; + case RSES_PROP_TYPE_SESCMD: + mysql_sescmd_done(&prop->rses_prop_data.sescmd); + break; - case RSES_PROP_TYPE_TMPTABLES: - hashtable_free(prop->rses_prop_data.temp_tables); - break; + case RSES_PROP_TYPE_TMPTABLES: + hashtable_free(prop->rses_prop_data.temp_tables); + break; - default: - MXS_DEBUG("%lu [rses_property_done] Unknown property type %d " - "in property %p", - pthread_self(), - prop->rses_prop_type, - prop); - ss_dassert(false); - break; + default: + MXS_DEBUG("%lu [rses_property_done] Unknown property type %d " + "in property %p", + pthread_self(), + prop->rses_prop_type, + prop); + ss_dassert(false); + break; } MXS_FREE(prop); } @@ -3215,24 +3215,24 @@ static bool execute_sescmd_in_backend(backend_ref_t* backend_ref) switch (scur->scmd_cur_cmd->my_sescmd_packet_type) { - case MYSQL_COM_CHANGE_USER: - /** This makes it possible to handle replies correctly */ - gwbuf_set_type(scur->scmd_cur_cmd->my_sescmd_buf, GWBUF_TYPE_SESCMD); - rc = dcb->func.auth(dcb, - NULL, - dcb->session, - sescmd_cursor_clone_querybuf(scur)); - break; + case MYSQL_COM_CHANGE_USER: + /** This makes it possible to handle replies correctly */ + gwbuf_set_type(scur->scmd_cur_cmd->my_sescmd_buf, GWBUF_TYPE_SESCMD); + rc = dcb->func.auth(dcb, + NULL, + dcb->session, + sescmd_cursor_clone_querybuf(scur)); + break; - case MYSQL_COM_QUERY: - default: - /** - * Mark session command buffer, it triggers writing - * MySQL command to protocol - */ - gwbuf_set_type(scur->scmd_cur_cmd->my_sescmd_buf, GWBUF_TYPE_SESCMD); - rc = dcb->func.write(dcb, sescmd_cursor_clone_querybuf(scur)); - break; + case MYSQL_COM_QUERY: + default: + /** + * Mark session command buffer, it triggers writing + * MySQL command to protocol + */ + gwbuf_set_type(scur->scmd_cur_cmd->my_sescmd_buf, GWBUF_TYPE_SESCMD); + rc = dcb->func.write(dcb, sescmd_cursor_clone_querybuf(scur)); + break; } if (rc == 1) @@ -3600,7 +3600,7 @@ static void handleError(ROUTER* instance, switch (action) { - case ERRACT_NEW_CONNECTION: + case ERRACT_NEW_CONNECTION: { if (!rses_begin_locked_router_action(rses)) { @@ -3619,7 +3619,7 @@ static void handleError(ROUTER* instance, break; } - case ERRACT_REPLY_CLIENT: + case ERRACT_REPLY_CLIENT: { handle_error_reply_client(session, rses, @@ -3629,9 +3629,9 @@ static void handleError(ROUTER* instance, break; } - default: - *succp = false; - break; + default: + *succp = false; + break; } } dcb_close(problem_dcb); @@ -3859,14 +3859,14 @@ static int router_handle_state_switch(DCB* dcb, switch (reason) { - case DCB_REASON_NOT_RESPONDING: - atomic_add(&bref->bref_backend->connections, -1); - MXS_INFO("server %s not responding", srv->unique_name); - dcb->func.hangup(dcb); - break; + case DCB_REASON_NOT_RESPONDING: + atomic_add(&bref->bref_backend->connections, -1); + MXS_INFO("server %s not responding", srv->unique_name); + dcb->func.hangup(dcb); + break; - default: - break; + default: + break; } return_rc: