All changes 2.0.0...develop
973b983 Merge branch 'release-2.0.0' into develop 255dd23 Make spinlock functions take const argument 6e23bab Fix bitmask reallocation 338c189 Rename and clean up slavelag filter 3ea8f28 Fix possible NULL pointer dereference bfe6738 MXS-830: Add module information to logged messages 1fad962 Fix strncat usage d38997a Adjust log throttling policy 0be4e4b Add hashtable_item_strcasecmp 726100e Take hashtable convenience functions into use 5e7744a Fix typo in maxadmin.md c5778c8 Merge branch 'release-2.0.0' into develop b5762af Move from tmpnam to mkstemp d6f2c71 Add convenience functions to hashtable 359058a MXS-825: Add support for --execdir 636347c Enable runtime reconfiguration of log throttling ef9fba9 Improve log throttling documentation aef917a Implement log throttling e3a5349 Remove shardrouter.c 8051e80 Remove custom qc_sqlite allocation functions fd34d60 Initial implementation of the learning firewall a8752a8 Removed "filestem option" from example 1ef2519 Removed "filestem option" from example 0815cc8 Cleanup spinlock.h ab4dc99 Clean up hashtable.h ef2c078 Add prototypes for hashtable copy and free functions fb5cfaf Add 'log_throttling' configuration entry 300d823 Add proper prototypes for hashtable hash and cmp functions 1c649aa qc_mysqlembedded: Include skygw_...h without path. d276160 Add missing RPM scripts e70e644 Fix HTTPAuth installation 1b2b389 Combine utils into the server directory 3ff9913 Add missing utils headers to devel package 407efb2 Fix minor packaging problems 99aa6ad Split MaxScale into core, experimental and devel packages 1290386 Merge branch 'develop' of ssh://github.com/mariadb-corporation/maxscale-new into develop e59f148 Make scripts POSIX sh compatible 7319266 Fixed SHOW SLAVE STATUS in bonlog router f8d760a Update Binlogrouter.md 0a904ed Update Replication-Proxy-Binlog-Router-Tutorial.md 75d4202 Update Replication-Proxy-Binlog-Router-Tutorial.md b8651fc Add missing newline in listmanager.h c7ad047 Add note about user data caches to release notes 70ccc2b Merge branch 'release-2.0.0' into develop 575d1b6 Mistake - dummy session needs list markers set. 8364508 Merge branch 'develop' into binlog_server_semisync 868b902 Update MaxScale limitations 2c8b327 Store listener caches in separate directories 6e183ec Create unique user data caches for each listeners f643685 Don't free orphaned tee filter sessions 4179afa Allow binlogrouter to be used without a listener 7ad79af Add function for freeing a listener 677a0a2 Move authentication data from services to listeners 4f12af7 Merge remote-tracking branch 'origin/MXS-677' into develop 1419b81 Semi-Sync support to binlog server: code review updtate 0ea0f01 Semi-Sync support to binlog server: added missing routine 4aad909 Semi-Sync support to binlog server b824e1e Add authenticator support to httpd.c 705a688 Change tabs to spaces d0c419e Change method of adding list fields to e.g. DCB 25504fc Document the changed routing priority of hints 41666d1 Remove use_ssl_if_enabled global option a3584e9 Make routing hints have highest priority 34a1d24 Updated document with new binlog router option 01eedc5 Updated documentation with SSL usage 8a4c0f6 Update Replication-Proxy-Binlog-Router-Tutorial.md 4e374aa Update Replication-Proxy-Binlog-Router-Tutorial.md f3f3c57 Update Replication-Proxy-Binlog-Router-Tutorial.md 617b79f Binlog Server: error messages typo fix fa8dfae Binlog Server: error messages review 1b8819c Fix freeing of schemarouter session memory 07f49e1 MXS-788: new code review fix 1fd3b09 MXS-788: show services now displays SSL info 6ca2584 MXS-788 code review fix ae6a7d0 MXS-788 code review 43d3474 Master server SSL connection 90b2377 Use correct variable in listmanager pre-allocation 9a5b238 Fix listmanager pre-allocation 9c78625 Fix a memory leak when backend authentication fails e59a966 Fix hang in list_find_free ff30223 Fix freeing of shared data in schemarouter fc8f9d3 Add missing include in luafilter ecf7f53 Add missing NULL value to filter parameter array 636d849 Update memory allocation approach f0d1d38 Add new allocation functions 97d00a0 Fix writing of uninitialized data to logs e72c9b2 Merge branch 'release-2.0.0' into develop cf2b712 Merge branch 'release-2.0.0' into develop 8917c5c Change the logic behind valid list entry checks c10deff Improve documentation about version_string f59f1f7 Merge branch 'develop' of ssh://github.com/mariadb-corporation/maxscale-new into develop c88edb3 Backend authentication failure improvement abd5bee Revert "Backend authentication failure improvement" 5bb3107 Backend authentication failure improvement b7f434a Add new allocation functions 3f022fa Fix stupid mistake 99c4317 Merge remote-tracking branch 'origin/MXS-677' into develop 3c1ded6 Added connection/authentication failure error reporting in SHOW SLAVE STATUS 0a60f7b Tidy up and deal with review points. ba103ff blr_slave.c: Update strncpy usage 467331e blr_master.c: Strncpy usage updates d2b7c0c Merge remote-tracking branch 'origin/develop-nullauth-merge' into develop 5a8c1d0 qc: Measure execution time at the right place. bccdb93 Merge branch 'NullAuthDeny' into develop 2e6511c Add 5.5.5 prefix to all version strings that lack it 314655a Improve DCB and session initialization and list handling e1c43f0 MXS-655: Make MaxScale logging logrotate(8) compatible ce36afd MXS-626: Don't log a header unless maxlog enabled dcd47a7 blr_file.c: Replace uses of strncpy 6b8f576 bls_slave.c: Replace strncpy with memcpy 68a0039 Add list preallocation, tidy up, simplify init. cb37d1b Fix copyright etc headers. 11a400d Tidy; comment; fix bad copies and mistakes. 7e36ec4 Add list manager files. c4794e3 Initial code for list manager. 1b42e25 Merge remote-tracking branch 'origin/MXS-765' into develop d50f617 Fix problems, extend tests, respond to review. dcb4a91 Filter test folder removed 0b60dbe Add a couple of comments. 83cdba0 Fix overwriting problem. ba5d353 Fix overwriting problem. 53671cb Small fixes in response to review. 173d049 blr.c: Review strncpy usage 4ff6ef2 binlog_common.c: Replace strncpy with memcpy f238e03 maxbinlogcheck.s: Replace strncpy 9807f8d harness: Replace unnecessary use of strncpy 8c7fe6a avro: Modify strncpy usage 9b8008e Small improvements. b7f784f Fix mistakes in testqueuemanager.c cc26962 Restore missing poll.c code; add testqueuemanager.c. 2e91806 Format the filter harness 22059e6 Initial implementation connection queueing. c604dc2 readwritesplit.c: Improve COM_INIT_DB handling 454d920 schemarouter.c: Replace strncpy with strcpy 8e85d66 sharding_common.c: Too long a database name handled explicitly 77f4446 Astyle schemarouter 491f7c2 maxinfo.c: Replace strncpy with memcpy 6b98105 maxinfo: Reformat with astyle c1dbf08 Handle oversize user and database names 5fa4a0f Merge branch 'develop' of ssh://github.com/mariadb-corporation/maxscale-new into develop 706963b BLR_DBUSERS_TAIL new var in blr.h d75b9af Tweak comments, remove trailing blanks. ab2400a Optimise statistics gathering by inline & simpler fns. fb59ddc Remove unnecessary strncpy/strncat usage in Binlog Server bdcd551 resultset.c: Change strncpy to memcpy c6b1c5e Reject rather than cut too long a path 6d8f112 Remove unnecessary strncpy/strncat usage 18bf5ed Remove unnecessary strncpy usage dc0e2db Make maxpasswd more userfriendly c9c8695 Fix calculation of padded_len in encryptPassword 2cfd2c6 dbusers.c: Check strncpy usage 7ab9342 Make more thorough checks in secrets_readKeys be7d593 Format cli.c debugcli.c testroute.c webserver.c 1ee5efb config.c: Check usage of strncpy 3043b12 gq_utils.c: Unnecessary use of strncpy removed 77874ac Add help to maxkeys 38392a3 Update secrets_writeKeys documentation 2d1325c Make SSL optional in MaxScale's own communication bda00da Fix avro build failures b2cb31a Add more OOM macros 41ccf17 Fix strdup usage a48f732 Fix realloc calls 20771f6 Add forgotten extern "C" block 8faf35a Add maxscale allocation functions bb47890 Add macros for OOM logging afea388 Fix silly mistakes. 6dafd22 Make deny default for null auth; move code from common to auth.
This commit is contained in:
@ -7,7 +7,7 @@
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file and at www.mariadb.com/bsl.
|
||||
*
|
||||
* Change Date: 2019-01-01
|
||||
* Change Date: 2019-07-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
@ -47,6 +47,7 @@
|
||||
* 25/09/2015 Massimiliano Pinto Addition of lastEventReceived for slaves
|
||||
* 23/10/2015 Markus Makela Added current_safe_event
|
||||
* 26/04/2016 Massimiliano Pinto Added MariaDB 10.0 and 10.1 GTID event flags detection
|
||||
* 22/07/2016 Massimiliano Pinto Added semi_sync replication support
|
||||
*
|
||||
* @endverbatim
|
||||
*/
|
||||
@ -76,6 +77,8 @@
|
||||
|
||||
/* Temporary requirement for auth data */
|
||||
#include <mysql_client_server_protocol.h>
|
||||
#include <maxscale/alloc.h>
|
||||
|
||||
|
||||
|
||||
static GWBUF *blr_make_query(char *statement);
|
||||
@ -99,6 +102,9 @@ extern int blr_check_heartbeat(ROUTER_INSTANCE *router);
|
||||
static void blr_log_identity(ROUTER_INSTANCE *router);
|
||||
static void blr_distribute_error_message(ROUTER_INSTANCE *router, char *message, char *state,
|
||||
unsigned int err_code);
|
||||
static void blr_extract_header_semisync(uint8_t *pkt, REP_HEADER *hdr);
|
||||
static int blr_send_semisync_ack (ROUTER_INSTANCE *router, uint64_t pos);
|
||||
static int blr_get_master_semisync(GWBUF *buf);
|
||||
|
||||
int blr_write_data_into_binlog(ROUTER_INSTANCE *router, uint32_t data_len, uint8_t *buf);
|
||||
void extract_checksum(ROUTER_INSTANCE* router, uint8_t *cksumptr, uint8_t len);
|
||||
@ -106,6 +112,30 @@ static void blr_terminate_master_replication(ROUTER_INSTANCE *router, uint8_t* p
|
||||
|
||||
static int keepalive = 1;
|
||||
|
||||
/** Transactio-Safety feature */
|
||||
typedef enum
|
||||
{
|
||||
BLRM_NO_TRANSACTION, /*< No transaction */
|
||||
BLRM_TRANSACTION_START, /*< A transaction is open*/
|
||||
BLRM_COMMIT_SEEN, /*< Received COMMIT event in the current transaction */
|
||||
BLRM_XID_EVENT_SEEN /*< Received XID event of current transaction */
|
||||
} master_transaction_t;
|
||||
|
||||
/** Master Semi-Sync capability */
|
||||
typedef enum
|
||||
{
|
||||
MASTER_SEMISYNC_NOT_AVAILABLE, /*< Semi-Sync replication not available */
|
||||
MASTER_SEMISYNC_DISABLED, /*< Semi-Sync is disabled */
|
||||
MASTER_SEMISYNC_ENABLED /*< Semi-Sync is enabled */
|
||||
} master_semisync_capability_t;
|
||||
|
||||
#define MASTER_BYTES_BEFORE_EVENT 5
|
||||
#define MASTER_BYTES_BEFORE_EVENT_SEMI_SYNC MASTER_BYTES_BEFORE_EVENT + 2
|
||||
/* Semi-Sync indicator in network packet (byte 6) */
|
||||
#define BLR_MASTER_SEMI_SYNC_INDICATOR 0xef
|
||||
/* Semi-Sync flag ACK_REQ in network packet (byte 7) */
|
||||
#define BLR_MASTER_SEMI_SYNC_ACK_REQ 0x01
|
||||
|
||||
/**
|
||||
* blr_start_master - controls the connection of the binlog router to the
|
||||
* master MySQL server and triggers the slave registration process for
|
||||
@ -162,13 +192,14 @@ blr_start_master(void* data)
|
||||
client->session = router->session;
|
||||
if ((router->master = dcb_connect(router->service->dbref->server, router->session, BLR_PROTOCOL)) == NULL)
|
||||
{
|
||||
char *name;
|
||||
if ((name = malloc(strlen(router->service->name) + strlen(" Master") + 1)) != NULL)
|
||||
char *name = MXS_MALLOC(strlen(router->service->name) + strlen(" Master") + 1);
|
||||
|
||||
if (name)
|
||||
{
|
||||
sprintf(name, "%s Master", router->service->name);
|
||||
hktask_oneshot(name, blr_start_master, router,
|
||||
BLR_MASTER_BACKOFF_TIME * router->retry_backoff++);
|
||||
free(name);
|
||||
MXS_FREE(name);
|
||||
}
|
||||
if (router->retry_backoff > BLR_MAX_BACKOFF)
|
||||
{
|
||||
@ -178,7 +209,7 @@ blr_start_master(void* data)
|
||||
router->service->dbref->server->unique_name);
|
||||
return;
|
||||
}
|
||||
router->master->remote = strdup(router->service->dbref->server->name);
|
||||
router->master->remote = MXS_STRDUP_A(router->service->dbref->server->name);
|
||||
|
||||
MXS_NOTICE("%s: attempting to connect to master server %s:%d, binlog %s, pos %lu",
|
||||
router->service->name, router->service->dbref->server->name,
|
||||
@ -225,16 +256,16 @@ blr_restart_master(ROUTER_INSTANCE *router)
|
||||
spinlock_release(&router->lock);
|
||||
if (router->master_state < BLRM_BINLOGDUMP)
|
||||
{
|
||||
char *name;
|
||||
|
||||
router->master_state = BLRM_UNCONNECTED;
|
||||
|
||||
if ((name = malloc(strlen(router->service->name) + strlen(" Master") + 1)) != NULL)
|
||||
char *name = (char*)MXS_MALLOC(strlen(router->service->name) + strlen(" Master") + 1);
|
||||
|
||||
if (name)
|
||||
{
|
||||
sprintf(name, "%s Master", router->service->name);
|
||||
hktask_oneshot(name, blr_start_master, router,
|
||||
BLR_MASTER_BACKOFF_TIME * router->retry_backoff++);
|
||||
free(name);
|
||||
MXS_FREE(name);
|
||||
}
|
||||
if (router->retry_backoff > BLR_MAX_BACKOFF)
|
||||
{
|
||||
@ -315,13 +346,13 @@ blr_master_close(ROUTER_INSTANCE *router)
|
||||
void
|
||||
blr_master_delayed_connect(ROUTER_INSTANCE *router)
|
||||
{
|
||||
char *name;
|
||||
char *name = (char*)MXS_MALLOC(strlen(router->service->name) + strlen(" Master Recovery") + 1);
|
||||
|
||||
if ((name = malloc(strlen(router->service->name) + strlen(" Master Recovery") + 1)) != NULL)
|
||||
if (name)
|
||||
{
|
||||
sprintf(name, "%s Master Recovery", router->service->name);
|
||||
hktask_oneshot(name, blr_start_master, router, 60);
|
||||
free(name);
|
||||
MXS_FREE(name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -349,7 +380,7 @@ blr_master_response(ROUTER_INSTANCE *router, GWBUF *buf)
|
||||
{
|
||||
MXS_ERROR("Invalid master state machine state (%d) for binlog router.",
|
||||
router->master_state);
|
||||
gwbuf_consume(buf, gwbuf_length(buf));
|
||||
gwbuf_free(buf);
|
||||
|
||||
spinlock_acquire(&router->lock);
|
||||
if (router->reconnect_pending)
|
||||
@ -388,12 +419,12 @@ blr_master_response(ROUTER_INSTANCE *router, GWBUF *buf)
|
||||
unsigned long mysql_errno = extract_field(MYSQL_ERROR_CODE(buf), 16);
|
||||
|
||||
msg_len = len - 7 - 6; // +7 is where msg starts, 6 is skipped the status message (#42000)
|
||||
msg_err = (char *)malloc(msg_len + 1);
|
||||
msg_err = (char *)MXS_MALLOC(msg_len + 1);
|
||||
|
||||
if (msg_err)
|
||||
{
|
||||
// skip status message only as MYSQL_RESPONSE_ERR(buf) points to GWBUF_DATA(buf) +7
|
||||
strncpy(msg_err, (char *)(MYSQL_ERROR_MSG(buf) + 6), msg_len);
|
||||
memcpy(msg_err, (char *)(MYSQL_ERROR_MSG(buf) + 6), msg_len);
|
||||
|
||||
/* NULL terminated error string */
|
||||
*(msg_err + msg_len) = '\0';
|
||||
@ -405,7 +436,7 @@ blr_master_response(ROUTER_INSTANCE *router, GWBUF *buf)
|
||||
mysql_errno,
|
||||
msg_err ? msg_err : "(memory failure)",
|
||||
blrm_states[router->master_state]);
|
||||
gwbuf_consume(buf, gwbuf_length(buf));
|
||||
gwbuf_free(buf);
|
||||
|
||||
spinlock_acquire(&router->lock);
|
||||
|
||||
@ -415,7 +446,7 @@ blr_master_response(ROUTER_INSTANCE *router, GWBUF *buf)
|
||||
/* set mysql error message */
|
||||
if (router->m_errmsg)
|
||||
{
|
||||
free(router->m_errmsg);
|
||||
MXS_FREE(router->m_errmsg);
|
||||
}
|
||||
router->m_errmsg = msg_err ? msg_err : "(memory failure)";
|
||||
|
||||
@ -435,7 +466,7 @@ blr_master_response(ROUTER_INSTANCE *router, GWBUF *buf)
|
||||
{
|
||||
case BLRM_TIMESTAMP:
|
||||
// Response to a timestamp message, no need to save this.
|
||||
gwbuf_consume(buf, GWBUF_LENGTH(buf));
|
||||
gwbuf_free(buf);
|
||||
buf = blr_make_query("SHOW VARIABLES LIKE 'SERVER_ID'");
|
||||
router->master_state = BLRM_SERVERID;
|
||||
router->master->func.write(router->master, buf);
|
||||
@ -466,7 +497,7 @@ blr_master_response(ROUTER_INSTANCE *router, GWBUF *buf)
|
||||
}
|
||||
router->master_state = BLRM_HBPERIOD;
|
||||
router->master->func.write(router->master, buf);
|
||||
free(val);
|
||||
MXS_FREE(val);
|
||||
break;
|
||||
}
|
||||
case BLRM_HBPERIOD:
|
||||
@ -503,7 +534,7 @@ blr_master_response(ROUTER_INSTANCE *router, GWBUF *buf)
|
||||
}
|
||||
if (val)
|
||||
{
|
||||
free(val);
|
||||
MXS_FREE(val);
|
||||
}
|
||||
// Response to the master_binlog_checksum, should be stored
|
||||
if (router->saved_master.chksum2)
|
||||
@ -562,13 +593,13 @@ blr_master_response(ROUTER_INSTANCE *router, GWBUF *buf)
|
||||
}
|
||||
if (key)
|
||||
{
|
||||
free(key);
|
||||
MXS_FREE(key);
|
||||
}
|
||||
|
||||
/* set the master_uuid from master if not set by the option */
|
||||
if (router->set_master_uuid == NULL)
|
||||
{
|
||||
free(router->master_uuid);
|
||||
MXS_FREE(router->master_uuid);
|
||||
router->master_uuid = val;
|
||||
}
|
||||
else
|
||||
@ -686,9 +717,107 @@ blr_master_response(ROUTER_INSTANCE *router, GWBUF *buf)
|
||||
router->master->func.write(router->master, buf);
|
||||
break;
|
||||
case BLRM_REGISTER:
|
||||
// Request a dump of the binlog file
|
||||
/* discard master reply to COM_REGISTER_SLAVE */
|
||||
gwbuf_free(buf);
|
||||
|
||||
/* if semisync option is set, check for master semi-sync availability */
|
||||
if (router->request_semi_sync)
|
||||
{
|
||||
MXS_NOTICE("%s: checking Semi-Sync replication capability for master server %s:%d",
|
||||
router->service->name,
|
||||
router->service->dbref->server->name,
|
||||
router->service->dbref->server->port);
|
||||
|
||||
buf = blr_make_query("SHOW VARIABLES LIKE 'rpl_semi_sync_master_enabled'");
|
||||
router->master_state = BLRM_CHECK_SEMISYNC;
|
||||
router->master->func.write(router->master, buf);
|
||||
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Continue */
|
||||
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);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
buf = blr_make_query("SET @rpl_semi_sync_slave = 1");
|
||||
router->master_state = BLRM_REQUEST_SEMISYNC;
|
||||
router->master->func.write(router->master, buf);
|
||||
|
||||
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);
|
||||
|
||||
/* Continue */
|
||||
router->master_state = BLRM_REQUEST_BINLOGDUMP;
|
||||
}
|
||||
|
||||
case BLRM_REQUEST_BINLOGDUMP:
|
||||
/**
|
||||
* This branch is reached after semi-sync check/request or
|
||||
* just after sending COM_REGISTER_SLAVE if request_semi_sync option is false
|
||||
*/
|
||||
|
||||
/* Request now a dump of the binlog file */
|
||||
buf = blr_make_binlog_dump(router);
|
||||
|
||||
router->master_state = BLRM_BINLOGDUMP;
|
||||
|
||||
router->master->func.write(router->master, buf);
|
||||
MXS_NOTICE("%s: Request binlog records from %s at "
|
||||
"position %lu from master server %s:%d",
|
||||
@ -701,6 +830,7 @@ blr_master_response(ROUTER_INSTANCE *router, GWBUF *buf)
|
||||
blr_log_identity(router);
|
||||
|
||||
break;
|
||||
|
||||
case BLRM_BINLOGDUMP:
|
||||
/**
|
||||
* Main body, we have received a binlog record from the master
|
||||
@ -864,6 +994,9 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt)
|
||||
int preslen = -1;
|
||||
int prev_length = -1;
|
||||
int n_bufs = -1, pn_bufs = -1;
|
||||
int check_packet_len;
|
||||
int semisync_bytes;
|
||||
int semi_sync_send_ack = 0;
|
||||
|
||||
/*
|
||||
* Prepend any residual buffer to the buffer chain we have
|
||||
@ -924,12 +1057,8 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt)
|
||||
int msg_remainder = len;
|
||||
GWBUF *p = pkt;
|
||||
|
||||
if ((msg = malloc(len)) == NULL)
|
||||
if ((msg = MXS_MALLOC(len)) == NULL)
|
||||
{
|
||||
MXS_ERROR("Insufficient memory to buffer event "
|
||||
"of %d bytes. Binlog %s @ %lu.",
|
||||
len, router->binlog_name,
|
||||
router->current_pos);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -955,7 +1084,7 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt)
|
||||
"message as expected. %s @ %lu",
|
||||
router->binlog_name,
|
||||
router->current_pos);
|
||||
free(msg);
|
||||
MXS_FREE(msg);
|
||||
/* msg = NULL; Not needed unless msg will be referred to again */
|
||||
break;
|
||||
}
|
||||
@ -985,6 +1114,8 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt)
|
||||
n_bufs = 1;
|
||||
}
|
||||
|
||||
semisync_bytes = 0;
|
||||
|
||||
/*
|
||||
* ptr now points at the current message in a contiguous buffer,
|
||||
* this buffer is either within the GWBUF or in a malloc'd
|
||||
@ -1015,12 +1146,38 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt)
|
||||
router->stats.n_binlogs_ses++;
|
||||
spinlock_release(&router->lock);
|
||||
|
||||
blr_extract_header(ptr, &hdr);
|
||||
/* Check for semi-sync in event with OK byte[4]:
|
||||
* move pointer 2 bytes ahead and set check_packet_len accordingly
|
||||
*/
|
||||
if (ptr[4] == 0 && router->master_semi_sync != MASTER_SEMISYNC_NOT_AVAILABLE &&
|
||||
ptr[5] == BLR_MASTER_SEMI_SYNC_INDICATOR)
|
||||
{
|
||||
|
||||
check_packet_len = MASTER_BYTES_BEFORE_EVENT_SEMI_SYNC;
|
||||
semi_sync_send_ack = ptr[6];
|
||||
|
||||
/* Extract header from the semi-sync event */
|
||||
blr_extract_header_semisync(ptr, &hdr);
|
||||
|
||||
/** Remove the semi-sync bytes */
|
||||
memmove(ptr, ptr + 2, 5);
|
||||
ptr += 2;
|
||||
semisync_bytes = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
semi_sync_send_ack = 0;
|
||||
check_packet_len = MASTER_BYTES_BEFORE_EVENT;
|
||||
|
||||
/* Extract header from thr event */
|
||||
blr_extract_header(ptr, &hdr);
|
||||
}
|
||||
|
||||
/* Sanity check */
|
||||
if (hdr.ok == 0)
|
||||
{
|
||||
if (hdr.event_size != len - 5 && (hdr.event_size + 1) < MYSQL_PACKET_LENGTH_MAX)
|
||||
if (hdr.event_size != len - check_packet_len &&
|
||||
(hdr.event_size + (check_packet_len - MYSQL_HEADER_LEN)) < MYSQL_PACKET_LENGTH_MAX)
|
||||
{
|
||||
MXS_ERROR("Packet length is %d, but event size is %d, "
|
||||
"binlog file %s position %lu "
|
||||
@ -1042,13 +1199,13 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt)
|
||||
|
||||
if (msg)
|
||||
{
|
||||
free(msg);
|
||||
MXS_FREE(msg);
|
||||
/* msg = NULL; Not needed unless msg will be referred to again */
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
else if ((hdr.event_size + 1) >= MYSQL_PACKET_LENGTH_MAX)
|
||||
else if (hdr.event_size + (check_packet_len - MYSQL_HEADER_LEN) >= MYSQL_PACKET_LENGTH_MAX)
|
||||
{
|
||||
router->master_event_state = BLR_EVENT_STARTED;
|
||||
|
||||
@ -1076,7 +1233,7 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt)
|
||||
/* Remove error message */
|
||||
if (router->m_errmsg)
|
||||
{
|
||||
free(router->m_errmsg);
|
||||
MXS_FREE(router->m_errmsg);
|
||||
}
|
||||
router->m_errmsg = NULL;
|
||||
|
||||
@ -1118,22 +1275,28 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt)
|
||||
extra_bytes = MYSQL_HEADER_LEN + 1;
|
||||
}
|
||||
|
||||
ss_dassert(len - extra_bytes - semisync_bytes > 0);
|
||||
uint32_t bytes_available = len - extra_bytes - semisync_bytes;
|
||||
|
||||
if (router->master_chksum)
|
||||
{
|
||||
uint32_t size = (len - extra_bytes) < router->checksum_size ?
|
||||
len - extra_bytes : router->checksum_size;
|
||||
uint32_t size = MIN(len - extra_bytes - semisync_bytes,
|
||||
router->checksum_size);
|
||||
|
||||
router->stored_checksum = crc32(router->stored_checksum,
|
||||
ptr + offset,
|
||||
size);
|
||||
router->checksum_size -= size;
|
||||
|
||||
if (router->checksum_size == 0 && size < len - offset)
|
||||
if (router->checksum_size == 0 && size < bytes_available)
|
||||
{
|
||||
extract_checksum(router, ptr + offset + size, len - offset - size);
|
||||
extract_checksum(router, ptr + offset + size,
|
||||
bytes_available - size);
|
||||
}
|
||||
}
|
||||
|
||||
if (blr_write_data_into_binlog(router, len - offset, ptr + offset) == 0)
|
||||
if (blr_write_data_into_binlog(router, bytes_available,
|
||||
ptr + offset) == 0)
|
||||
{
|
||||
/** Failed to write to the binlog file, destroy the buffer
|
||||
* chain and close the connection with the master */
|
||||
@ -1157,7 +1320,7 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt)
|
||||
*/
|
||||
if (router->master_chksum)
|
||||
{
|
||||
uint32_t pktsum, offset = MYSQL_HEADER_LEN;
|
||||
uint32_t offset = MYSQL_HEADER_LEN;
|
||||
uint32_t size = len - MYSQL_HEADER_LEN - MYSQL_CHECKSUM_LEN;
|
||||
|
||||
if (router->master_event_state == BLR_EVENT_DONE)
|
||||
@ -1165,7 +1328,7 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt)
|
||||
/** Set the pointer offset to the first byte after
|
||||
* the header and OK byte */
|
||||
offset = MYSQL_HEADER_LEN + 1;
|
||||
size = len - MYSQL_HEADER_LEN - MYSQL_CHECKSUM_LEN - 1;
|
||||
size = len - (check_packet_len + MYSQL_CHECKSUM_LEN);
|
||||
}
|
||||
|
||||
size = MIN(size, router->checksum_size);
|
||||
@ -1173,23 +1336,23 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt)
|
||||
if (router->checksum_size > 0)
|
||||
{
|
||||
router->stored_checksum = crc32(router->stored_checksum,
|
||||
ptr + offset,
|
||||
size);
|
||||
ptr + offset, size);
|
||||
router->checksum_size -= size;
|
||||
}
|
||||
|
||||
if (router->checksum_size == 0 && size < len - offset)
|
||||
if(router->checksum_size == 0 && size < (len - offset - semisync_bytes))
|
||||
{
|
||||
extract_checksum(router, ptr + offset + size, len - offset - size);
|
||||
extract_checksum(router, ptr + offset + size,
|
||||
len - offset - size - semisync_bytes);
|
||||
}
|
||||
|
||||
if (router->partial_checksum_bytes == MYSQL_CHECKSUM_LEN)
|
||||
{
|
||||
pktsum = EXTRACT32(router->partial_checksum);
|
||||
uint32_t pktsum = EXTRACT32(router->partial_checksum);
|
||||
if (pktsum != router->stored_checksum)
|
||||
{
|
||||
router->stats.n_badcrc++;
|
||||
free(msg);
|
||||
MXS_FREE(msg);
|
||||
/* msg = NULL; Not needed unless msg will be referred to again */
|
||||
MXS_ERROR("%s: Checksum error in event from master, "
|
||||
"binlog %s @ %lu. Closing master connection.",
|
||||
@ -1222,7 +1385,7 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt)
|
||||
*/
|
||||
|
||||
spinlock_acquire(&router->binlog_lock);
|
||||
if (router->trx_safe == 0 || (router->trx_safe && router->pending_transaction == 0))
|
||||
if (router->trx_safe == 0 || (router->trx_safe && router->pending_transaction == BLRM_NO_TRANSACTION))
|
||||
{
|
||||
/* no pending transaction: set current_pos to binlog_position */
|
||||
router->binlog_position = router->current_pos;
|
||||
@ -1271,7 +1434,7 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt)
|
||||
// An action should be taken here
|
||||
}
|
||||
|
||||
router->pending_transaction = 1;
|
||||
router->pending_transaction = BLRM_TRANSACTION_START;
|
||||
|
||||
spinlock_release(&router->binlog_lock);
|
||||
}
|
||||
@ -1289,18 +1452,19 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt)
|
||||
db_name_len = ptr[4 + 20 + 4 + 4];
|
||||
var_block_len = ptr[4 + 20 + 4 + 4 + 1 + 2];
|
||||
|
||||
statement_len = len - (4 + 20 + 4 + 4 + 1 + 2 + 2 + var_block_len + 1 + db_name_len);
|
||||
statement_sql = calloc(1, statement_len + 1);
|
||||
strncpy(statement_sql,
|
||||
(char *)ptr + 4 + 20 + 4 + 4 + 1 + 2 + 2 + var_block_len + 1 + db_name_len,
|
||||
statement_len);
|
||||
statement_len = len - (4 + 20 + 4 + 4 + 1 + 2 + 2 + var_block_len + 1 + db_name_len) - semisync_bytes;
|
||||
statement_sql = MXS_CALLOC(1, statement_len + 1);
|
||||
MXS_ABORT_IF_NULL(statement_sql);
|
||||
memcpy(statement_sql,
|
||||
(char *)ptr + 4 + 20 + 4 + 4 + 1 + 2 + 2 + var_block_len + 1 + db_name_len,
|
||||
statement_len);
|
||||
|
||||
spinlock_acquire(&router->binlog_lock);
|
||||
|
||||
/* Check for BEGIN (it comes for START TRANSACTION too) */
|
||||
if (strncmp(statement_sql, "BEGIN", 5) == 0)
|
||||
{
|
||||
if (router->pending_transaction > 0)
|
||||
if (router->pending_transaction > BLRM_NO_TRANSACTION)
|
||||
{
|
||||
MXS_ERROR("A transaction is already open "
|
||||
"@ %lu and a new one starts @ %lu",
|
||||
@ -1310,18 +1474,18 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt)
|
||||
// An action should be taken here
|
||||
}
|
||||
|
||||
router->pending_transaction = 1;
|
||||
router->pending_transaction = BLRM_TRANSACTION_START;
|
||||
}
|
||||
|
||||
/* Check for COMMIT in non transactional store engines */
|
||||
if (strncmp(statement_sql, "COMMIT", 6) == 0)
|
||||
{
|
||||
router->pending_transaction = 2;
|
||||
router->pending_transaction = BLRM_COMMIT_SEEN;
|
||||
}
|
||||
|
||||
spinlock_release(&router->binlog_lock);
|
||||
|
||||
free(statement_sql);
|
||||
MXS_FREE(statement_sql);
|
||||
}
|
||||
|
||||
/* Check for COMMIT in Transactional engines, i.e InnoDB */
|
||||
@ -1331,7 +1495,7 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt)
|
||||
|
||||
if (router->pending_transaction)
|
||||
{
|
||||
router->pending_transaction = 3;
|
||||
router->pending_transaction = BLRM_XID_EVENT_SEEN;
|
||||
}
|
||||
spinlock_release(&router->binlog_lock);
|
||||
}
|
||||
@ -1364,27 +1528,18 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt)
|
||||
* slaves that attach later.
|
||||
*/
|
||||
new_fde_len = hdr.event_size;
|
||||
new_fde = malloc(hdr.event_size);
|
||||
new_fde = MXS_MALLOC(hdr.event_size);
|
||||
|
||||
if (new_fde)
|
||||
{
|
||||
memcpy(new_fde, ptr + 5, hdr.event_size);
|
||||
if (router->saved_master.fde_event)
|
||||
{
|
||||
free(router->saved_master.fde_event);
|
||||
MXS_FREE(router->saved_master.fde_event);
|
||||
}
|
||||
router->saved_master.fde_event = new_fde;
|
||||
router->saved_master.fde_len = new_fde_len;
|
||||
}
|
||||
else
|
||||
{
|
||||
MXS_ERROR("%s: Received a format description "
|
||||
"event that MaxScale was unable to "
|
||||
"record. Event length is %d.",
|
||||
router->service->name,
|
||||
hdr.event_size);
|
||||
blr_log_packet(LOG_ERR,
|
||||
"Format Description Event:", ptr, len);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -1429,9 +1584,8 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt)
|
||||
* It is possible for an empty packet to be sent if an
|
||||
* event is exactly 2^24 bytes long. In this case the
|
||||
* empty packet should be discarded. */
|
||||
|
||||
if (len > MYSQL_HEADER_LEN &&
|
||||
blr_write_binlog_record(router, &hdr, len - offset, ptr) == 0)
|
||||
blr_write_binlog_record(router, &hdr, len - offset - semisync_bytes, ptr) == 0)
|
||||
{
|
||||
/*
|
||||
* Failed to write to the
|
||||
@ -1469,6 +1623,28 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt)
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle semi-sync request fom master */
|
||||
if (router->master_semi_sync != MASTER_SEMISYNC_NOT_AVAILABLE &&
|
||||
semi_sync_send_ack == BLR_MASTER_SEMI_SYNC_ACK_REQ &&
|
||||
(router->master_event_state == BLR_EVENT_COMPLETE ||
|
||||
router->master_event_state == BLR_EVENT_DONE))
|
||||
{
|
||||
|
||||
MXS_DEBUG("%s: binlog record in file %s, pos %lu has "
|
||||
"SEMI_SYNC_ACK_REQ and needs a Semi-Sync ACK packet to "
|
||||
"be sent to the master server %s:%d",
|
||||
router->service->name, router->binlog_name,
|
||||
router->current_pos,
|
||||
router->service->dbref->server->name,
|
||||
router->service->dbref->server->port);
|
||||
|
||||
/* Send Semi-Sync ACK packet to master server */
|
||||
blr_send_semisync_ack(router, hdr.next_pos);
|
||||
|
||||
/* Reset ACK sending */
|
||||
semi_sync_send_ack = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Distributing binlog events to slaves
|
||||
* may depend on pending transaction
|
||||
@ -1476,7 +1652,7 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt)
|
||||
|
||||
spinlock_acquire(&router->binlog_lock);
|
||||
|
||||
if (router->trx_safe == 0 || (router->trx_safe && router->pending_transaction == 0))
|
||||
if (router->trx_safe == 0 || (router->trx_safe && router->pending_transaction == BLRM_NO_TRANSACTION))
|
||||
{
|
||||
router->binlog_position = router->current_pos;
|
||||
router->current_safe_event = router->last_event_pos;
|
||||
@ -1525,7 +1701,7 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt)
|
||||
*
|
||||
*/
|
||||
|
||||
if (router->pending_transaction > 1)
|
||||
if (router->pending_transaction > BLRM_TRANSACTION_START)
|
||||
{
|
||||
unsigned long long pos;
|
||||
unsigned long long end_pos;
|
||||
@ -1592,8 +1768,9 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt)
|
||||
router->binlog_position,
|
||||
router->current_pos);
|
||||
|
||||
strncpy(err_message,
|
||||
"No transaction events sent", BINLOG_ERROR_MSG_LEN);
|
||||
static const char MESSAGE[] = "No transaction events sent";
|
||||
ss_dassert(sizeof(MESSAGE) <= BINLOG_ERROR_MSG_LEN);
|
||||
strcpy(err_message, MESSAGE);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1606,8 +1783,9 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt)
|
||||
pos,
|
||||
router->current_pos);
|
||||
|
||||
strncpy(err_message,
|
||||
"Incomplete transaction events sent", BINLOG_ERROR_MSG_LEN);
|
||||
static const char MESSAGE[] = "Incomplete transaction events sent";
|
||||
ss_dassert(sizeof(MESSAGE) <= BINLOG_ERROR_MSG_LEN);
|
||||
strcpy(err_message, MESSAGE);
|
||||
}
|
||||
|
||||
/* distribute error message to registered slaves */
|
||||
@ -1618,7 +1796,7 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt)
|
||||
spinlock_acquire(&router->binlog_lock);
|
||||
|
||||
router->binlog_position = router->current_pos;
|
||||
router->pending_transaction = 0;
|
||||
router->pending_transaction = BLRM_NO_TRANSACTION;
|
||||
|
||||
spinlock_release(&router->binlog_lock);
|
||||
}
|
||||
@ -1679,7 +1857,7 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt)
|
||||
|
||||
if (msg)
|
||||
{
|
||||
free(msg);
|
||||
MXS_FREE(msg);
|
||||
msg = NULL;
|
||||
}
|
||||
prev_length = len;
|
||||
@ -1805,16 +1983,31 @@ CreateMySQLAuthData(char *username, char *password, char *database)
|
||||
|
||||
if (username == NULL || password == NULL)
|
||||
{
|
||||
MXS_ERROR("You must specify both username and password for the binlog router.\n");
|
||||
MXS_ERROR("You must specify both username and password for the binlog router.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((auth_info = calloc(1, sizeof(MYSQL_session))) == NULL)
|
||||
if (strlen(username) > MYSQL_USER_MAXLEN)
|
||||
{
|
||||
MXS_ERROR("Provided user name %s is longer than maximum length %d.",
|
||||
username, MYSQL_USER_MAXLEN);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (strlen(database) > MYSQL_DATABASE_MAXLEN)
|
||||
{
|
||||
MXS_ERROR("Provided database %s is longer than maximum length %d.",
|
||||
database, MYSQL_DATABASE_MAXLEN);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((auth_info = MXS_CALLOC(1, sizeof(MYSQL_session))) == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
strncpy(auth_info->user, username, MYSQL_USER_MAXLEN);
|
||||
strncpy(auth_info->db, database, MYSQL_DATABASE_MAXLEN);
|
||||
|
||||
strcpy(auth_info->user, username);
|
||||
strcpy(auth_info->db, database);
|
||||
gw_sha1_str((const uint8_t *)password, strlen(password), auth_info->client_sha1);
|
||||
|
||||
return auth_info;
|
||||
@ -2191,7 +2384,7 @@ blr_extract_column(GWBUF *buf, int col)
|
||||
ptr += collen;
|
||||
}
|
||||
collen = *ptr++;
|
||||
if ((rval = malloc(collen + 1)) == NULL)
|
||||
if ((rval = MXS_MALLOC(collen + 1)) == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@ -2370,7 +2563,7 @@ blr_stop_start_master(ROUTER_INSTANCE *router)
|
||||
|
||||
if (strcmp(router->binlog_name, router->prevbinlog) != 0)
|
||||
{
|
||||
strncpy(router->prevbinlog, router->binlog_name, BINLOG_FNAMELEN);
|
||||
strcpy(router->prevbinlog, router->binlog_name); // Same size
|
||||
}
|
||||
|
||||
if (router->client)
|
||||
@ -2584,6 +2777,16 @@ blr_distribute_error_message(ROUTER_INSTANCE *router, char *message, char *state
|
||||
spinlock_release(&router->lock);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write data into binlogs (incomplete event)
|
||||
*
|
||||
* Writes @c data_len bytes of data from @c buf into the current binlog being processed.
|
||||
*
|
||||
* @param router Router instance
|
||||
* @param data_len Number of bytes to write
|
||||
* @param buf Pointer where the data is read
|
||||
* @return Number of bytes written or 0 on error
|
||||
*/
|
||||
int
|
||||
blr_write_data_into_binlog(ROUTER_INSTANCE *router, uint32_t data_len, uint8_t *buf)
|
||||
{
|
||||
@ -2773,7 +2976,7 @@ bool blr_send_event(blr_thread_role_t role,
|
||||
void extract_checksum(ROUTER_INSTANCE* router, uint8_t *cksumptr, uint8_t len)
|
||||
{
|
||||
uint8_t *ptr = cksumptr;
|
||||
while (ptr - cksumptr < len)
|
||||
while (ptr - cksumptr < len && router->partial_checksum_bytes < MYSQL_CHECKSUM_LEN)
|
||||
{
|
||||
router->partial_checksum[router->partial_checksum_bytes] = *ptr;
|
||||
ptr++;
|
||||
@ -2792,9 +2995,10 @@ static void blr_terminate_master_replication(ROUTER_INSTANCE* router, uint8_t* p
|
||||
{
|
||||
unsigned long mysql_errno = extract_field(ptr + 5, 16);
|
||||
int msg_len = len - 7 - 6; // msg len is decreased by 7 and 6
|
||||
char *msg_err = (char *)malloc(msg_len + 1);
|
||||
char *msg_err = (char *)MXS_MALLOC(msg_len + 1);
|
||||
MXS_ABORT_IF_NULL(msg_err);
|
||||
|
||||
strncpy(msg_err, (char *)ptr + 7 + 6, msg_len);
|
||||
memcpy(msg_err, (char *)ptr + 7 + 6, msg_len);
|
||||
*(msg_err + msg_len) = '\0';
|
||||
|
||||
spinlock_acquire(&router->lock);
|
||||
@ -2807,8 +3011,110 @@ static void blr_terminate_master_replication(ROUTER_INSTANCE* router, uint8_t* p
|
||||
|
||||
spinlock_release(&router->lock);
|
||||
|
||||
free(old_errmsg);
|
||||
MXS_FREE(old_errmsg);
|
||||
MXS_ERROR("Error packet in binlog stream.%s @ %lu.",
|
||||
router->binlog_name, router->current_pos);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate a header structure for a replication message from a GWBUF structure with semi-sync enabled.
|
||||
*
|
||||
* @param pkt The incoming packet in a GWBUF chain
|
||||
* @param hdr The packet header to populate
|
||||
*/
|
||||
static void
|
||||
blr_extract_header_semisync(register uint8_t *ptr, register REP_HEADER *hdr)
|
||||
{
|
||||
|
||||
hdr->payload_len = EXTRACT24(ptr);
|
||||
hdr->seqno = ptr[3];
|
||||
hdr->ok = ptr[4];
|
||||
/* Data available after 2 bytes (the 2 semisync bytes) */
|
||||
hdr->timestamp = EXTRACT32(&ptr[5 + 2]);
|
||||
hdr->event_type = ptr[9 + 2];
|
||||
hdr->serverid = EXTRACT32(&ptr[10 + 2]);
|
||||
hdr->event_size = EXTRACT32(&ptr[14 + 2]);
|
||||
hdr->next_pos = EXTRACT32(&ptr[18 + 2]);
|
||||
hdr->flags = EXTRACT16(&ptr[22 + 2]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a MySQL Replication Semi-Sync ACK to the master server.
|
||||
*
|
||||
* @param router The router instance.
|
||||
* @param pos The binlog position for the ACK reply.
|
||||
* @return 1 if the packect is sent, 0 on errors
|
||||
*/
|
||||
|
||||
static int
|
||||
blr_send_semisync_ack(ROUTER_INSTANCE *router, uint64_t pos)
|
||||
{
|
||||
int seqno = 0;
|
||||
int semi_sync_flag = BLR_MASTER_SEMI_SYNC_INDICATOR;
|
||||
GWBUF *buf;
|
||||
int len;
|
||||
uint8_t *data;
|
||||
int binlog_file_len = strlen(router->binlog_name);
|
||||
|
||||
/* payload is: 1 byte semi-sync indicator + 8 bytes position + binlog name len */
|
||||
len = 1 + 8 + binlog_file_len;
|
||||
|
||||
/* add network header to size */
|
||||
if ((buf = gwbuf_alloc(len + 4)) == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
data = GWBUF_DATA(buf);
|
||||
|
||||
encode_value(&data[0], len, 24); // Payload length
|
||||
data[3] = 0; // Sequence ID
|
||||
data[4] = semi_sync_flag; // Semi-sync indicator
|
||||
|
||||
/**
|
||||
* Next Bytes are: 8 bytes log position + len bin_log filename
|
||||
*/
|
||||
|
||||
/* Position */
|
||||
encode_value(&data[5], pos, 64);
|
||||
|
||||
/* Binlog filename */
|
||||
memcpy((char *)&data[13], router->binlog_name, binlog_file_len);
|
||||
|
||||
router->master->func.write(router->master, buf);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the master semisync capability.
|
||||
*
|
||||
* @param buf The GWBUF data with master reply.
|
||||
* @return Semisync value: non available, enabled, disabled
|
||||
*/
|
||||
static int
|
||||
blr_get_master_semisync(GWBUF *buf)
|
||||
{
|
||||
char *key;
|
||||
char *val = NULL;
|
||||
int master_semisync = MASTER_SEMISYNC_NOT_AVAILABLE;
|
||||
|
||||
key = blr_extract_column(buf, 1);
|
||||
|
||||
if (key && strlen(key))
|
||||
{
|
||||
val = blr_extract_column(buf, 2);
|
||||
}
|
||||
free(key);
|
||||
|
||||
if (val) {
|
||||
if (strncasecmp(val, "ON", 4) == 0)
|
||||
master_semisync = MASTER_SEMISYNC_ENABLED;
|
||||
else
|
||||
master_semisync = MASTER_SEMISYNC_DISABLED;
|
||||
}
|
||||
free(val);
|
||||
|
||||
return master_semisync;
|
||||
}
|
||||
|
Reference in New Issue
Block a user