Improvements to debug interface & blr updates

This commit is contained in:
Mark Riddoch
2014-05-21 17:25:21 +01:00
parent 8b3ea0c4d9
commit c1d39999ff
9 changed files with 158 additions and 25 deletions

View File

@ -540,7 +540,7 @@ int i = 0;
dcb_printf(dcb, "\t\tServer-id: %d\n", session->serverid);
if (session->hostname)
dcb_printf(dcb, "\t\tHostname: %s\n", session->hostname);
dcb_printf(dcb, "\t\tSlave DCB: %x\n", session->dcb);
dcb_printf(dcb, "\t\tSlave DCB: %p\n", session->dcb);
dcb_printf(dcb, "\t\tNext Sequence No: %d\n", session->seqno);
dcb_printf(dcb, "\t\tState: %s\n", blrs_states[session->state]);
dcb_printf(dcb, "\t\tBinlog file: %s\n", session->binlogfile);

View File

@ -423,21 +423,39 @@ int no_residual = 1;
len = extract_field(pdata, 24) + 4;
}
if (reslen < len && gwbuf_length(pkt) >= len) // Message straddles buffers
if (reslen < len && gwbuf_length(pkt) >= len)
{
/* Allocate a contiguous buffer for the binlog message */
/*
* The message is contianed in more than the current
* buffer, however we have the complete messasge in
* this buffer and the chain of remaining buffers.
*
* Allocate a contiguous buffer for the binlog message
* and copy the complete message into this buffer.
*/
msg = malloc(len);
if (GWBUF_LENGTH(pkt->next) < len - reslen)
printf("Packet (length %d) spans more than 2 buffers\n", len);
memcpy(msg, pdata, reslen);
memcpy(&msg[reslen], GWBUF_DATA(pkt->next), len - reslen);
ptr = msg;
}
else if (reslen < len) // Message straddles buffers
else if (reslen < len)
{
/*
* The message is not fully contained in the current
* and we do not have the complete message in the
* buffer chain. Therefore we must stop processing until
* we receive the next buffer.
*/
break;
}
else
{
/*
* The message is fully contained in the current buffer
*/
ptr = pdata;
msg = NULL;
}
@ -474,10 +492,6 @@ int no_residual = 1;
}
else
{
if (hdr.event_type == ROTATE_EVENT)
{
blr_rotate_event(router, ptr, &hdr);
}
if (hdr.event_type == HEARTBEAT_EVENT)
{
#ifdef SHOW_EVENTS
@ -490,8 +504,20 @@ int no_residual = 1;
ptr = ptr + 5; // We don't put the first byte of the payload
// into the binlog file
blr_write_binlog_record(router, &hdr, ptr);
if (hdr.event_type == ROTATE_EVENT)
{
blr_rotate_event(router, ptr, &hdr);
}
blr_distribute_binlog_record(router, &hdr, ptr);
}
else
{
ptr += 5;
if (hdr.event_type == ROTATE_EVENT)
{
blr_rotate_event(router, ptr, &hdr);
}
}
}
}
else
@ -508,7 +534,7 @@ int no_residual = 1;
}
else
{
pkt = gwbuf_consume(pkt, 4 + hdr.payload_len);
pkt = gwbuf_consume(pkt, len);
}
}
@ -578,8 +604,6 @@ int len;
uint64_t pos;
char file[BINLOG_FNAMELEN+1];
ptr += 4; // Skip packet header
ptr++; // Skip the OK
ptr += 19; // Skip event header
len = hdr->event_size - 19; // Event size minus header
pos = extract_field(ptr, 32) + (extract_field(ptr+4, 32) << 32);
@ -649,6 +673,10 @@ ROUTER_SLAVE *slave;
memcpy(buf, ptr, hdr->event_size);
slave->dcb->func.write(slave->dcb, pkt);
slave->binlog_pos = hdr->next_pos;
if (hdr->event_type == ROTATE_EVENT)
{
blr_slave_rotate(slave, ptr);
}
}
slave = slave->next;

View File

@ -719,10 +719,36 @@ struct timespec req;
*ptr++ = slave->seqno++;
*ptr++ = 0; // OK
head = gwbuf_append(head, record);
if (hdr.event_type == ROTATE_EVENT)
{
close(fd);
blr_slave_rotate(slave, GWBUF_DATA(record));
if ((fd = blr_open_binlog(router, slave->binlogfile)) == -1)
{
LOGIF(LE, (skygw_log_write(
LOGFILE_ERROR,
"blr_slave_catchup failed to open binlog file %s\n",
slave->binlogfile)));
break;
}
}
written = slave->dcb->func.write(slave->dcb, head);
if (written)
slave->binlog_pos = hdr.next_pos;
rval = written;
if (hdr.event_type == ROTATE_EVENT)
{
close(fd);
blr_slave_rotate(slave, GWBUF_DATA(record));
if ((fd = blr_open_binlog(router, slave->binlogfile)) == -1)
{
LOGIF(LE, (skygw_log_write(
LOGFILE_ERROR,
"blr_slave_catchup failed to open binlog file %s\n",
slave->binlogfile)));
break;
}
}
atomic_add(&slave->stats.n_events, 1);
burst++;
}
@ -765,3 +791,18 @@ ROUTER_INSTANCE *router = slave->router;
blr_slave_catchup(router, slave);
}
}
/**
* Rotate the slave to the new binlog file
*
* @param slave The slave instance
* @param ptr The rotate event (minux header and OK byte)
*/
void
blr_slave_rotate(ROUTER_SLAVE *slave, uint8_t *ptr)
{
ptr += 19; // Skip header
slave->binlog_pos = extract_field(ptr, 32) + (extract_field(ptr+4, 32) << 32);
memcpy(slave->binlogfile, ptr + 8, BINLOG_FNAMELEN);
slave->binlogfile[BINLOG_FNAMELEN] = 0;
}