Search in sources :

Example 6 with HeaderPacket

use of com.alibaba.otter.canal.parse.driver.mysql.packets.HeaderPacket in project canal by alibaba.

the class DirectLogFetcherTest method sendBinlogDump.

private void sendBinlogDump(MysqlConnector connector, String binlogfilename, Long binlogPosition, int slaveId) throws IOException {
    BinlogDumpCommandPacket binlogDumpCmd = new BinlogDumpCommandPacket();
    binlogDumpCmd.binlogFileName = binlogfilename;
    binlogDumpCmd.binlogPosition = binlogPosition;
    binlogDumpCmd.slaveServerId = slaveId;
    byte[] cmdBody = binlogDumpCmd.toBytes();
    HeaderPacket binlogDumpHeader = new HeaderPacket();
    binlogDumpHeader.setPacketBodyLength(cmdBody.length);
    binlogDumpHeader.setPacketSequenceNumber((byte) 0x00);
    PacketManager.write(connector.getChannel(), new ByteBuffer[] { ByteBuffer.wrap(binlogDumpHeader.toBytes()), ByteBuffer.wrap(cmdBody) });
}
Also used : BinlogDumpCommandPacket(com.alibaba.otter.canal.parse.driver.mysql.packets.client.BinlogDumpCommandPacket) HeaderPacket(com.alibaba.otter.canal.parse.driver.mysql.packets.HeaderPacket)

Example 7 with HeaderPacket

use of com.alibaba.otter.canal.parse.driver.mysql.packets.HeaderPacket in project canal by alibaba.

the class MysqlConnection method sendBinlogDump.

private void sendBinlogDump(String binlogfilename, Long binlogPosition) throws IOException {
    BinlogDumpCommandPacket binlogDumpCmd = new BinlogDumpCommandPacket();
    binlogDumpCmd.binlogFileName = binlogfilename;
    binlogDumpCmd.binlogPosition = binlogPosition;
    binlogDumpCmd.slaveServerId = this.slaveId;
    byte[] cmdBody = binlogDumpCmd.toBytes();
    logger.info("COM_BINLOG_DUMP with position:{}", binlogDumpCmd);
    HeaderPacket binlogDumpHeader = new HeaderPacket();
    binlogDumpHeader.setPacketBodyLength(cmdBody.length);
    binlogDumpHeader.setPacketSequenceNumber((byte) 0x00);
    PacketManager.write(connector.getChannel(), new ByteBuffer[] { ByteBuffer.wrap(binlogDumpHeader.toBytes()), ByteBuffer.wrap(cmdBody) });
    connector.setDumping(true);
}
Also used : BinlogDumpCommandPacket(com.alibaba.otter.canal.parse.driver.mysql.packets.client.BinlogDumpCommandPacket) HeaderPacket(com.alibaba.otter.canal.parse.driver.mysql.packets.HeaderPacket)

Example 8 with HeaderPacket

use of com.alibaba.otter.canal.parse.driver.mysql.packets.HeaderPacket in project canal by alibaba.

the class ChannelBufferHelper method createHeader.

public final ChannelBuffer createHeader(int bodyLength, byte packetNumber) {
    HeaderPacket header = new HeaderPacket();
    header.setPacketBodyLength(bodyLength);
    header.setPacketSequenceNumber(packetNumber);
    return ChannelBuffers.wrappedBuffer(header.toBytes());
}
Also used : HeaderPacket(com.alibaba.otter.canal.parse.driver.mysql.packets.HeaderPacket) PacketWithHeaderPacket(com.alibaba.otter.canal.parse.driver.mysql.packets.PacketWithHeaderPacket)

Example 9 with HeaderPacket

use of com.alibaba.otter.canal.parse.driver.mysql.packets.HeaderPacket in project canal by alibaba.

the class MysqlConnector method auth323.

private void auth323(SocketChannel channel, byte packetSequenceNumber, byte[] seed) throws IOException {
    // auth 323
    Reply323Packet r323 = new Reply323Packet();
    if (password != null && password.length() > 0) {
        r323.seed = MySQLPasswordEncrypter.scramble323(password, new String(seed)).getBytes();
    }
    byte[] b323Body = r323.toBytes();
    HeaderPacket h323 = new HeaderPacket();
    h323.setPacketBodyLength(b323Body.length);
    h323.setPacketSequenceNumber((byte) (packetSequenceNumber + 1));
    PacketManager.write(channel, new ByteBuffer[] { ByteBuffer.wrap(h323.toBytes()), ByteBuffer.wrap(b323Body) });
    logger.info("client 323 authentication packet is sent out.");
    // check auth result
    HeaderPacket header = PacketManager.readHeader(channel, 4);
    byte[] body = PacketManager.readBytes(channel, header.getPacketBodyLength());
    assert body != null;
    switch(body[0]) {
        case 0:
            break;
        case -1:
            ErrorPacket err = new ErrorPacket();
            err.fromBytes(body);
            throw new IOException("Error When doing Client Authentication:" + err.toString());
        default:
            throw new IOException("unpexpected packet with field_count=" + body[0]);
    }
}
Also used : HeaderPacket(com.alibaba.otter.canal.parse.driver.mysql.packets.HeaderPacket) ErrorPacket(com.alibaba.otter.canal.parse.driver.mysql.packets.server.ErrorPacket) Reply323Packet(com.alibaba.otter.canal.parse.driver.mysql.packets.server.Reply323Packet) IOException(java.io.IOException)

Example 10 with HeaderPacket

use of com.alibaba.otter.canal.parse.driver.mysql.packets.HeaderPacket in project canal by alibaba.

the class MysqlConnector method quit.

public void quit() throws IOException {
    QuitCommandPacket quit = new QuitCommandPacket();
    byte[] cmdBody = quit.toBytes();
    HeaderPacket quitHeader = new HeaderPacket();
    quitHeader.setPacketBodyLength(cmdBody.length);
    quitHeader.setPacketSequenceNumber((byte) 0x00);
    PacketManager.write(channel, new ByteBuffer[] { ByteBuffer.wrap(quitHeader.toBytes()), ByteBuffer.wrap(cmdBody) });
}
Also used : QuitCommandPacket(com.alibaba.otter.canal.parse.driver.mysql.packets.client.QuitCommandPacket) HeaderPacket(com.alibaba.otter.canal.parse.driver.mysql.packets.HeaderPacket)

Aggregations

HeaderPacket (com.alibaba.otter.canal.parse.driver.mysql.packets.HeaderPacket)11 PacketWithHeaderPacket (com.alibaba.otter.canal.parse.driver.mysql.packets.PacketWithHeaderPacket)3 BinlogDumpCommandPacket (com.alibaba.otter.canal.parse.driver.mysql.packets.client.BinlogDumpCommandPacket)2 ErrorPacket (com.alibaba.otter.canal.parse.driver.mysql.packets.server.ErrorPacket)2 IOException (java.io.IOException)2 ClientAuthenticationPacket (com.alibaba.otter.canal.parse.driver.mysql.packets.client.ClientAuthenticationPacket)1 QuitCommandPacket (com.alibaba.otter.canal.parse.driver.mysql.packets.client.QuitCommandPacket)1 HandshakeInitializationPacket (com.alibaba.otter.canal.parse.driver.mysql.packets.server.HandshakeInitializationPacket)1 Reply323Packet (com.alibaba.otter.canal.parse.driver.mysql.packets.server.Reply323Packet)1