diff --git a/server/modules/include/blr.h b/server/modules/include/blr.h index 84623d053..7d694f071 100644 --- a/server/modules/include/blr.h +++ b/server/modules/include/blr.h @@ -37,6 +37,7 @@ #include #include +#include #define BINLOG_FNAMELEN 16 #define BLR_PROTOCOL "MySQLBackend" diff --git a/server/modules/routing/binlog/blr_file.c b/server/modules/routing/binlog/blr_file.c index 926ac61a6..228486318 100644 --- a/server/modules/routing/binlog/blr_file.c +++ b/server/modules/routing/binlog/blr_file.c @@ -218,9 +218,8 @@ int fd; close(router->binlog_fd); spinlock_acquire(&router->binlog_lock); strncpy(router->binlog_name, file,BINLOG_FNAMELEN); - blr_file_add_magic(router, fd); - spinlock_release(&router->binlog_lock); router->binlog_fd = fd; + spinlock_release(&router->binlog_lock); return 1; } @@ -262,12 +261,13 @@ int fd; LOGIF(LE, (skygw_log_write(LOGFILE_ERROR, "%s: binlog file %s has an invalid length %d.", router->service->name, path, router->binlog_position))); - close(fd); + close(fd); + spinlock_release(&router->binlog_lock); return; } } - spinlock_release(&router->binlog_lock); router->binlog_fd = fd; + spinlock_release(&router->binlog_lock); } /** diff --git a/server/modules/routing/binlog/blr_master.c b/server/modules/routing/binlog/blr_master.c index 804ff9f23..c371dafa4 100644 --- a/server/modules/routing/binlog/blr_master.c +++ b/server/modules/routing/binlog/blr_master.c @@ -246,6 +246,9 @@ blr_master_reconnect(ROUTER_INSTANCE *router) { int do_reconnect = 0; + if (router->master_state == BLRM_SLAVE_STOPPED) + return; + spinlock_acquire(&router->lock); if (router->active_logs) { @@ -914,7 +917,8 @@ static REP_HEADER phdr; blr_extract_header(ptr, &hdr); - if (hdr.event_size != len - 5) /* Sanity check */ + /* Sanity check */ + if (hdr.ok == 0 && hdr.event_size != len - 5) { LOGIF(LE,(skygw_log_write( LOGFILE_ERROR, @@ -1146,6 +1150,9 @@ static REP_HEADER phdr; free(router->m_errmsg); router->m_errmsg = msg_err; + /* Force stopped state */ + router->master_state = BLRM_SLAVE_STOPPED; + spinlock_release(&router->lock); LOGIF(LE,(skygw_log_write(LOGFILE_ERROR,