Added default heartbeat set via define and blr_last_event_description
Added default heartbeat set via define and blr_last_event_description()
This commit is contained in:
@ -151,6 +151,12 @@
|
||||
/* max size for error message returned to client */
|
||||
#define BINLOG_ERROR_MSG_LEN 385
|
||||
|
||||
/* network latency extra wait tme for heartbeat check */
|
||||
#define BLR_NET_LATENCY_WAIT_TIME 1
|
||||
|
||||
/* default heartbeat interval in seconds */
|
||||
#define BLR_HEARTBEAT_DEFAULT_INTERVAL 300
|
||||
|
||||
/**
|
||||
* Some useful macros for examining the MySQL Response packets
|
||||
*/
|
||||
@ -353,7 +359,7 @@ typedef struct router_instance {
|
||||
DCB *client; /*< DCB for dummy client */
|
||||
SESSION *session; /*< Fake session for master connection */
|
||||
unsigned int master_state; /*< State of the master FSM */
|
||||
uint8_t lastEventReceived;
|
||||
uint8_t lastEventReceived; /*< Last even received */
|
||||
uint32_t lastEventTimestamp; /*< Timestamp from last event */
|
||||
GWBUF *residual; /*< Any residual binlog event */
|
||||
MASTER_RESPONSES saved_master; /*< Saved master responses */
|
||||
|
@ -106,7 +106,7 @@ extern char *decryptPassword(char *crypt);
|
||||
extern char *create_hex_sha1_sha1_passwd(char *passwd);
|
||||
extern int blr_read_events_all_events(ROUTER_INSTANCE *router, int fix, int debug);
|
||||
void blr_master_close(ROUTER_INSTANCE *);
|
||||
int blr_check_heartbeat(ROUTER_INSTANCE *router);
|
||||
char * blr_last_event_description(ROUTER_INSTANCE *router);
|
||||
|
||||
/** The module object definition */
|
||||
static ROUTER_OBJECT MyObject = {
|
||||
@ -264,7 +264,7 @@ int rc = 0;
|
||||
inst->burst_size = DEF_BURST_SIZE;
|
||||
inst->retry_backoff = 1;
|
||||
inst->binlogdir = NULL;
|
||||
inst->heartbeat = 300; // Default is every 5 minutes
|
||||
inst->heartbeat = BLR_HEARTBEAT_DEFAULT_INTERVAL;
|
||||
inst->mariadb10_compat = false;
|
||||
|
||||
inst->user = strdup(service->credentials.name);
|
||||
@ -404,6 +404,16 @@ int rc = 0;
|
||||
else if (strcmp(options[i], "heartbeat") == 0)
|
||||
{
|
||||
inst->heartbeat = atoi(value);
|
||||
if (inst->heartbeat <= 0) {
|
||||
/* set default value */
|
||||
inst->heartbeat = BLR_HEARTBEAT_DEFAULT_INTERVAL;
|
||||
|
||||
LOGIF(LE, (skygw_log_write_flush(
|
||||
LOGFILE_ERROR,
|
||||
"Warning : invalid heartbeat period %s."
|
||||
" Setting it to default value %d.",
|
||||
value, inst->heartbeat )));
|
||||
}
|
||||
}
|
||||
else if (strcmp(options[i], "binlogdir") == 0)
|
||||
{
|
||||
@ -1897,26 +1907,22 @@ static int blr_check_binlog(ROUTER_INSTANCE *router) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks last heartbeat or last received event against router->heartbeat time interval
|
||||
* Return last event description
|
||||
*
|
||||
* @param router Current router instance
|
||||
* @return 0 if master connection must be closed and opened again, 1 otherwise
|
||||
* @param router The router instance
|
||||
* @return The event description or NULL
|
||||
*/
|
||||
|
||||
int
|
||||
blr_check_heartbeat(ROUTER_INSTANCE *router) {
|
||||
time_t t_now = time(0);
|
||||
char *event_desc = NULL;
|
||||
|
||||
if (router->master_state != BLRM_BINLOGDUMP) {
|
||||
return 1;
|
||||
}
|
||||
char *
|
||||
blr_last_event_description(ROUTER_INSTANCE *router) {
|
||||
char *event_desc = NULL;
|
||||
|
||||
if (!router->mariadb10_compat) {
|
||||
event_desc = (router->lastEventReceived >= 0 &&
|
||||
router->lastEventReceived <= MAX_EVENT_TYPE) ?
|
||||
event_names[router->lastEventReceived] : "unknown";
|
||||
if (router->lastEventReceived >= 0 &&
|
||||
router->lastEventReceived <= MAX_EVENT_TYPE) {
|
||||
event_desc = event_names[router->lastEventReceived];
|
||||
}
|
||||
} else {
|
||||
if (router->lastEventReceived >= 0 &&
|
||||
router->lastEventReceived <= MAX_EVENT_TYPE) {
|
||||
@ -1931,21 +1937,6 @@ char *event_desc = NULL;
|
||||
|
||||
}
|
||||
|
||||
if (router->master_state == BLRM_BINLOGDUMP && router->lastEventReceived > 0) {
|
||||
if ((t_now - router->stats.lastReply) > (router->heartbeat + 1)) {
|
||||
LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,
|
||||
"ERROR: No event received from master %s:%d in heartbeat period (%d seconds), last event (%s %d) received %lu seconds ago. Assuming connection is dead and reconnecting.",
|
||||
router->service->dbref->server->name,
|
||||
router->service->dbref->server->port,
|
||||
router->heartbeat,
|
||||
event_desc,
|
||||
router->lastEventReceived,
|
||||
t_now - router->stats.lastReply)));
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
return event_desc;
|
||||
}
|
||||
|
||||
|
@ -92,6 +92,8 @@ void poll_fake_write_event(DCB *dcb);
|
||||
GWBUF *blr_read_events_from_pos(ROUTER_INSTANCE *router, unsigned long long pos, REP_HEADER *hdr);
|
||||
static void blr_check_last_master_event(void *inst);
|
||||
extern int blr_check_heartbeat(ROUTER_INSTANCE *router);
|
||||
extern char * blr_last_event_description(ROUTER_INSTANCE *router);
|
||||
|
||||
static int keepalive = 1;
|
||||
|
||||
/**
|
||||
@ -1991,3 +1993,42 @@ char *name = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check last heartbeat or last received event against router->heartbeat time interval
|
||||
*
|
||||
* checked interval is againts (router->heartbeat + BLR_NET_LATENCY_WAIT_TIME)
|
||||
* that is currently set to 1
|
||||
*
|
||||
* @param router Current router instance
|
||||
* @return 0 if master connection must be closed and opened again, 1 otherwise
|
||||
*/
|
||||
|
||||
int
|
||||
blr_check_heartbeat(ROUTER_INSTANCE *router) {
|
||||
time_t t_now = time(0);
|
||||
char *event_desc = NULL;
|
||||
|
||||
if (router->master_state != BLRM_BINLOGDUMP) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
event_desc = blr_last_event_description(router);
|
||||
|
||||
if (router->master_state == BLRM_BINLOGDUMP && router->lastEventReceived > 0) {
|
||||
if ((t_now - router->stats.lastReply) > (router->heartbeat + BLR_NET_LATENCY_WAIT_TIME)) {
|
||||
LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,
|
||||
"ERROR: No event received from master %s:%d in heartbeat period (%d seconds), last event (%s %d) received %lu seconds ago. Assuming connection is dead and reconnecting.",
|
||||
router->service->dbref->server->name,
|
||||
router->service->dbref->server->port,
|
||||
router->heartbeat,
|
||||
event_desc != NULL ? event_desc : "unknown",
|
||||
router->lastEventReceived,
|
||||
t_now - router->stats.lastReply)));
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user