Search in sources :

Example 1 with LogIdentity

use of com.alibaba.otter.canal.protocol.position.LogIdentity in project otter by alibaba.

the class OtterDownStreamHandlerIntergration method buildEvent.

private Event buildEvent() {
    Header.Builder headBuilder = Header.newBuilder();
    headBuilder.setEventLength(1000L);
    headBuilder.setExecuteTime(new Date().getTime());
    headBuilder.setLogfileName("mysql-bin.000001");
    headBuilder.setLogfileOffset(1000L);
    headBuilder.setSchemaName("test");
    headBuilder.setTableName("ljh");
    Entry.Builder entryBuilder = Entry.newBuilder();
    entryBuilder.setHeader(headBuilder.build());
    entryBuilder.setEntryType(EntryType.ROWDATA);
    RowChange.Builder rowChangeBuilder = RowChange.newBuilder();
    RowData.Builder rowDataBuilder = RowData.newBuilder();
    rowChangeBuilder.addRowDatas(rowDataBuilder.build());
    entryBuilder.setStoreValue(rowChangeBuilder.build().toByteString());
    Entry entry = entryBuilder.build();
    Event event = new Event(new LogIdentity(), entry);
    return event;
}
Also used : Entry(com.alibaba.otter.canal.protocol.CanalEntry.Entry) RowData(com.alibaba.otter.canal.protocol.CanalEntry.RowData) Header(com.alibaba.otter.canal.protocol.CanalEntry.Header) RowChange(com.alibaba.otter.canal.protocol.CanalEntry.RowChange) Event(com.alibaba.otter.canal.store.model.Event) LogIdentity(com.alibaba.otter.canal.protocol.position.LogIdentity) Date(java.util.Date)

Example 2 with LogIdentity

use of com.alibaba.otter.canal.protocol.position.LogIdentity in project canal by alibaba.

the class AbstractLogPositionManagerTest method buildPosition.

protected LogPosition buildPosition(int number) {
    LogPosition position = new LogPosition();
    position.setIdentity(new LogIdentity(new InetSocketAddress(MYSQL_ADDRESS, 3306), 1234L));
    position.setPostion(new EntryPosition("mysql-bin.000000" + number, 106L, new Date().getTime()));
    return position;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) LogIdentity(com.alibaba.otter.canal.protocol.position.LogIdentity) EntryPosition(com.alibaba.otter.canal.protocol.position.EntryPosition) Date(java.util.Date) LogPosition(com.alibaba.otter.canal.protocol.position.LogPosition)

Example 3 with LogIdentity

use of com.alibaba.otter.canal.protocol.position.LogIdentity in project canal by alibaba.

the class AbstractMetaManagerTest method buildRange.

private PositionRange<LogPosition> buildRange(int number) {
    LogPosition start = new LogPosition();
    start.setIdentity(new LogIdentity(new InetSocketAddress(MYSQL_ADDRESS, 3306), 1234L));
    start.setPostion(new EntryPosition("mysql-bin.000000" + number, 106L, new Date().getTime()));
    LogPosition end = new LogPosition();
    end.setIdentity(new LogIdentity(new InetSocketAddress(MYSQL_ADDRESS, 3306), 1234L));
    end.setPostion(new EntryPosition("mysql-bin.000000" + (number + 1), 106L, (new Date().getTime()) + 1000 * 1000L));
    return new PositionRange<>(start, end);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) PositionRange(com.alibaba.otter.canal.protocol.position.PositionRange) LogIdentity(com.alibaba.otter.canal.protocol.position.LogIdentity) EntryPosition(com.alibaba.otter.canal.protocol.position.EntryPosition) Date(java.util.Date) LogPosition(com.alibaba.otter.canal.protocol.position.LogPosition)

Example 4 with LogIdentity

use of com.alibaba.otter.canal.protocol.position.LogIdentity in project canal by alibaba.

the class MemoryEventStoreBase method buildEvent.

protected Event buildEvent(String binlogFile, long offset, long timestamp) {
    Header.Builder headerBuilder = Header.newBuilder();
    headerBuilder.setLogfileName(binlogFile);
    headerBuilder.setLogfileOffset(offset);
    headerBuilder.setExecuteTime(timestamp);
    headerBuilder.setEventLength(1024);
    Entry.Builder entryBuilder = Entry.newBuilder();
    entryBuilder.setHeader(headerBuilder.build());
    Entry entry = entryBuilder.build();
    return new Event(new LogIdentity(new InetSocketAddress(MYSQL_ADDRESS, 3306), 1234L), entry);
}
Also used : Entry(com.alibaba.otter.canal.protocol.CanalEntry.Entry) Header(com.alibaba.otter.canal.protocol.CanalEntry.Header) InetSocketAddress(java.net.InetSocketAddress) Event(com.alibaba.otter.canal.store.model.Event) LogIdentity(com.alibaba.otter.canal.protocol.position.LogIdentity)

Example 5 with LogIdentity

use of com.alibaba.otter.canal.protocol.position.LogIdentity in project canal by alibaba.

the class MysqlEventParserTest method test_ha.

@Test
public void test_ha() throws InterruptedException {
    final TimeoutChecker timeoutChecker = new TimeoutChecker(30 * 1000);
    final AtomicLong entryCount = new AtomicLong(0);
    final EntryPosition entryPosition = new EntryPosition();
    final MysqlEventParser controller = new MysqlEventParser();
    final EntryPosition defaultPosition = buildPosition("mysql-bin.000001", 6163L, 1322803601000L);
    controller.setSlaveId(3344L);
    controller.setDetectingEnable(false);
    controller.setMasterInfo(buildAuthentication());
    controller.setMasterPosition(defaultPosition);
    controller.setEventSink(new AbstractCanalEventSinkTest<List<Entry>>() {

        @Override
        public boolean sink(List<Entry> entrys, InetSocketAddress remoteAddress, String destination) throws CanalSinkException {
            for (Entry entry : entrys) {
                if (entry.getEntryType() != EntryType.HEARTBEAT) {
                    entryCount.incrementAndGet();
                    String logfilename = entry.getHeader().getLogfileName();
                    long logfileoffset = entry.getHeader().getLogfileOffset();
                    long executeTime = entry.getHeader().getExecuteTime();
                    entryPosition.setJournalName(logfilename);
                    entryPosition.setPosition(logfileoffset);
                    entryPosition.setTimestamp(executeTime);
                    break;
                }
            }
            if (entryCount.get() > 0) {
                controller.stop();
                timeoutChecker.stop();
                timeoutChecker.touch();
            }
            return true;
        }
    });
    controller.setLogPositionManager(new AbstractLogPositionManager() {

        public void persistLogPosition(String destination, LogPosition logPosition) {
            System.out.println(logPosition);
        }

        public LogPosition getLatestIndexBy(String destination) {
            LogPosition masterLogPosition = new LogPosition();
            masterLogPosition.setIdentity(new LogIdentity(new InetSocketAddress("127.0.0.1", 3306), 1234L));
            masterLogPosition.setPostion(new EntryPosition(1322803601000L));
            return masterLogPosition;
        }
    });
    controller.start();
    timeoutChecker.waitForIdle();
    if (controller.isStart()) {
        controller.stop();
    }
    // check
    Assert.assertTrue(entryCount.get() > 0);
    // 对比第一条数据和起始的position相同
    Assert.assertEquals(entryPosition.getJournalName(), "mysql-bin.000001");
    Assert.assertTrue(entryPosition.getPosition() <= 6163L);
    Assert.assertTrue(entryPosition.getTimestamp() <= defaultPosition.getTimestamp());
}
Also used : InetSocketAddress(java.net.InetSocketAddress) LogIdentity(com.alibaba.otter.canal.protocol.position.LogIdentity) AbstractLogPositionManager(com.alibaba.otter.canal.parse.index.AbstractLogPositionManager) AtomicLong(java.util.concurrent.atomic.AtomicLong) Entry(com.alibaba.otter.canal.protocol.CanalEntry.Entry) TimeoutChecker(com.alibaba.otter.canal.parse.helper.TimeoutChecker) List(java.util.List) EntryPosition(com.alibaba.otter.canal.protocol.position.EntryPosition) CanalSinkException(com.alibaba.otter.canal.sink.exception.CanalSinkException) LogPosition(com.alibaba.otter.canal.protocol.position.LogPosition) Test(org.junit.Test) AbstractCanalEventSinkTest(com.alibaba.otter.canal.parse.stub.AbstractCanalEventSinkTest)

Aggregations

LogIdentity (com.alibaba.otter.canal.protocol.position.LogIdentity)9 InetSocketAddress (java.net.InetSocketAddress)6 Entry (com.alibaba.otter.canal.protocol.CanalEntry.Entry)5 EntryPosition (com.alibaba.otter.canal.protocol.position.EntryPosition)5 LogPosition (com.alibaba.otter.canal.protocol.position.LogPosition)5 Event (com.alibaba.otter.canal.store.model.Event)4 Date (java.util.Date)4 Header (com.alibaba.otter.canal.protocol.CanalEntry.Header)3 PositionRange (com.alibaba.otter.canal.protocol.position.PositionRange)2 TimeoutChecker (com.alibaba.otter.canal.parse.helper.TimeoutChecker)1 AbstractLogPositionManager (com.alibaba.otter.canal.parse.index.AbstractLogPositionManager)1 AbstractCanalEventSinkTest (com.alibaba.otter.canal.parse.stub.AbstractCanalEventSinkTest)1 CanalEntry (com.alibaba.otter.canal.protocol.CanalEntry)1 RowChange (com.alibaba.otter.canal.protocol.CanalEntry.RowChange)1 RowData (com.alibaba.otter.canal.protocol.CanalEntry.RowData)1 CanalSinkException (com.alibaba.otter.canal.sink.exception.CanalSinkException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Test (org.junit.Test)1