com.alibaba.otter.canal.store.CanalStoreException Java Examples

The following examples show how to use com.alibaba.otter.canal.store.CanalStoreException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DummyEventStore.java    From canal-1.1.3 with Apache License 2.0 6 votes vote down vote up
public void put(List<Event> datas) throws InterruptedException, CanalStoreException {
    for (Event data : datas) {
        Date date = new Date(data.getExecuteTime());
        SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
        if (data.getEntryType() == EntryType.TRANSACTIONBEGIN || data.getEntryType() == EntryType.TRANSACTIONEND) {
            // System.out.println(MessageFormat.format(messgae, new Object[]
            // { Thread.currentThread().getName(),
            // header.getLogfilename(), header.getLogfileoffset(),
            // format.format(date),
            // data.getEntry().getEntryType(), "" }));
            System.out.println(data.getEntryType());

        } else {
            System.out.println(MessageFormat.format(messgae,
                new Object[] { Thread.currentThread().getName(), data.getJournalName(),
                        String.valueOf(data.getPosition()), format.format(date) }));
        }
    }
}
 
Example #2
Source File: DummyEventStore.java    From canal-1.1.3 with Apache License 2.0 6 votes vote down vote up
public boolean put(List<Event> datas, long timeout, TimeUnit unit) throws InterruptedException, CanalStoreException {
    for (Event data : datas) {
        Date date = new Date(data.getExecuteTime());
        SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
        if (data.getEntryType() == EntryType.TRANSACTIONBEGIN || data.getEntryType() == EntryType.TRANSACTIONEND) {
            // System.out.println(MessageFormat.format(messgae, new Object[]
            // { Thread.currentThread().getName(),
            // header.getLogfilename(), header.getLogfileoffset(),
            // format.format(date),
            // data.getEntry().getEntryType(), "" }));
            System.out.println(data.getEntryType());

        } else {
            System.out.println(MessageFormat.format(messgae,
                new Object[] { Thread.currentThread().getName(), data.getJournalName(),
                        String.valueOf(data.getPosition()), format.format(date) }));
        }
    }
    return true;
}
 
Example #3
Source File: DummyEventStore.java    From canal-1.1.3 with Apache License 2.0 6 votes vote down vote up
public boolean tryPut(List<Event> datas) throws CanalStoreException {
    System.out.println("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
    for (Event data : datas) {

        Date date = new Date(data.getExecuteTime());
        SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
        if (data.getEntryType() == EntryType.TRANSACTIONBEGIN || data.getEntryType() == EntryType.TRANSACTIONEND) {
            // System.out.println(MessageFormat.format(messgae, new Object[]
            // { Thread.currentThread().getName(),
            // header.getLogfilename(), header.getLogfileoffset(),
            // format.format(date),
            // data.getEntry().getEntryType(), "" }));
            System.out.println(data.getEntryType());

        } else {
            System.out.println(MessageFormat.format(messgae,
                new Object[] { Thread.currentThread().getName(), data.getJournalName(),
                        String.valueOf(data.getPosition()), format.format(date) }));
        }

    }
    System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
    return true;
}
 
Example #4
Source File: MemoryEventStoreWithBuffer.java    From canal with Apache License 2.0 6 votes vote down vote up
public void cleanAll() throws CanalStoreException {
    final ReentrantLock lock = this.lock;
    lock.lock();
    try {
        putSequence.set(INIT_SEQUENCE);
        getSequence.set(INIT_SEQUENCE);
        ackSequence.set(INIT_SEQUENCE);

        putMemSize.set(0);
        getMemSize.set(0);
        ackMemSize.set(0);
        entries = null;
        // for (int i = 0; i < entries.length; i++) {
        // entries[i] = null;
        // }
    } finally {
        lock.unlock();
    }
}
 
Example #5
Source File: MemoryEventStoreWithBuffer.java    From canal-1.1.3 with Apache License 2.0 6 votes vote down vote up
public boolean tryPut(List<Event> data) throws CanalStoreException {
    if (data == null || data.isEmpty()) {
        return true;
    }

    final ReentrantLock lock = this.lock;
    lock.lock();
    try {
        if (!checkFreeSlotAt(putSequence.get() + data.size())) {
            return false;
        } else {
            doPut(data);
            return true;
        }
    } finally {
        lock.unlock();
    }
}
 
Example #6
Source File: DummyEventStore.java    From canal with Apache License 2.0 6 votes vote down vote up
public void put(List<Event> datas) throws InterruptedException, CanalStoreException {
    for (Event data : datas) {
        Date date = new Date(data.getExecuteTime());
        SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
        if (data.getEntryType() == EntryType.TRANSACTIONBEGIN || data.getEntryType() == EntryType.TRANSACTIONEND) {
            // System.out.println(MessageFormat.format(messgae, new Object[]
            // { Thread.currentThread().getName(),
            // header.getLogfilename(), header.getLogfileoffset(),
            // format.format(date),
            // data.getEntry().getEntryType(), "" }));
            System.out.println(data.getEntryType());

        } else {
            System.out.println(MessageFormat.format(messgae,
                new Object[] { Thread.currentThread().getName(), data.getJournalName(),
                        String.valueOf(data.getPosition()), format.format(date) }));
        }
    }
}
 
Example #7
Source File: DummyEventStore.java    From canal with Apache License 2.0 6 votes vote down vote up
public boolean put(List<Event> datas, long timeout, TimeUnit unit) throws InterruptedException, CanalStoreException {
    for (Event data : datas) {
        Date date = new Date(data.getExecuteTime());
        SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
        if (data.getEntryType() == EntryType.TRANSACTIONBEGIN || data.getEntryType() == EntryType.TRANSACTIONEND) {
            // System.out.println(MessageFormat.format(messgae, new Object[]
            // { Thread.currentThread().getName(),
            // header.getLogfilename(), header.getLogfileoffset(),
            // format.format(date),
            // data.getEntry().getEntryType(), "" }));
            System.out.println(data.getEntryType());

        } else {
            System.out.println(MessageFormat.format(messgae,
                new Object[] { Thread.currentThread().getName(), data.getJournalName(),
                        String.valueOf(data.getPosition()), format.format(date) }));
        }
    }
    return true;
}
 
Example #8
Source File: DummyEventStore.java    From canal with Apache License 2.0 6 votes vote down vote up
public boolean tryPut(List<Event> datas) throws CanalStoreException {
    System.out.println("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
    for (Event data : datas) {

        Date date = new Date(data.getExecuteTime());
        SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
        if (data.getEntryType() == EntryType.TRANSACTIONBEGIN || data.getEntryType() == EntryType.TRANSACTIONEND) {
            // System.out.println(MessageFormat.format(messgae, new Object[]
            // { Thread.currentThread().getName(),
            // header.getLogfilename(), header.getLogfileoffset(),
            // format.format(date),
            // data.getEntry().getEntryType(), "" }));
            System.out.println(data.getEntryType());

        } else {
            System.out.println(MessageFormat.format(messgae,
                new Object[] { Thread.currentThread().getName(), data.getJournalName(),
                        String.valueOf(data.getPosition()), format.format(date) }));
        }

    }
    System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
    return true;
}
 
Example #9
Source File: MemoryEventStoreWithBuffer.java    From canal with Apache License 2.0 6 votes vote down vote up
public boolean tryPut(List<Event> data) throws CanalStoreException {
    if (data == null || data.isEmpty()) {
        return true;
    }

    final ReentrantLock lock = this.lock;
    lock.lock();
    try {
        if (!checkFreeSlotAt(putSequence.get() + data.size())) {
            return false;
        } else {
            doPut(data);
            return true;
        }
    } finally {
        lock.unlock();
    }
}
 
Example #10
Source File: EventTransactionBuffer.java    From canal with Apache License 2.0 5 votes vote down vote up
public void start() throws CanalStoreException {
    super.start();
    if (Integer.bitCount(bufferSize) != 1) {
        throw new IllegalArgumentException("bufferSize must be a power of 2");
    }

    Assert.notNull(flushCallback, "flush callback is null!");
    indexMask = bufferSize - 1;
    entries = new CanalEntry.Entry[bufferSize];
}
 
Example #11
Source File: MemoryEventStoreWithBuffer.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
public void start() throws CanalStoreException {
    super.start();
    if (Integer.bitCount(bufferSize) != 1) {
        throw new IllegalArgumentException("bufferSize must be a power of 2");
    }

    indexMask = bufferSize - 1;
    entries = new Event[bufferSize];
}
 
Example #12
Source File: EventTransactionBuffer.java    From canal with Apache License 2.0 5 votes vote down vote up
public void stop() throws CanalStoreException {
    putSequence.set(INIT_SQEUENCE);
    flushSequence.set(INIT_SQEUENCE);

    entries = null;
    super.stop();
}
 
Example #13
Source File: MemoryEventStoreWithBuffer.java    From canal with Apache License 2.0 5 votes vote down vote up
public Events<Event> tryGet(Position start, int batchSize) throws CanalStoreException {
    final ReentrantLock lock = this.lock;
    lock.lock();
    try {
        return doGet(start, batchSize);
    } finally {
        lock.unlock();
    }
}
 
Example #14
Source File: MemoryEventStoreWithBuffer.java    From canal with Apache License 2.0 5 votes vote down vote up
public void start() throws CanalStoreException {
    super.start();
    if (Integer.bitCount(bufferSize) != 1) {
        throw new IllegalArgumentException("bufferSize must be a power of 2");
    }

    indexMask = bufferSize - 1;
    entries = new Event[bufferSize];
}
 
Example #15
Source File: EventTransactionBuffer.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
public void stop() throws CanalStoreException {
    putSequence.set(INIT_SQEUENCE);
    flushSequence.set(INIT_SQEUENCE);

    entries = null;
    super.stop();
}
 
Example #16
Source File: EventTransactionBuffer.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
public void start() throws CanalStoreException {
    super.start();
    if (Integer.bitCount(bufferSize) != 1) {
        throw new IllegalArgumentException("bufferSize must be a power of 2");
    }

    Assert.notNull(flushCallback, "flush callback is null!");
    indexMask = bufferSize - 1;
    entries = new CanalEntry.Entry[bufferSize];
}
 
Example #17
Source File: MemoryEventStoreWithBuffer.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
public Events<Event> get(Position start, int batchSize, long timeout, TimeUnit unit) throws InterruptedException,
                                                                                    CanalStoreException {
    long nanos = unit.toNanos(timeout);
    final ReentrantLock lock = this.lock;
    lock.lockInterruptibly();
    try {
        for (;;) {
            if (checkUnGetSlotAt((LogPosition) start, batchSize)) {
                return doGet(start, batchSize);
            }

            if (nanos <= 0) {
                // 如果时间到了,有多少取多少
                return doGet(start, batchSize);
            }

            try {
                nanos = notEmpty.awaitNanos(nanos);
            } catch (InterruptedException ie) {
                notEmpty.signal(); // propagate to non-interrupted thread
                throw ie;
            }

        }
    } finally {
        lock.unlock();
    }
}
 
Example #18
Source File: MemoryEventStoreWithBuffer.java    From canal with Apache License 2.0 5 votes vote down vote up
public Events<Event> get(Position start, int batchSize, long timeout, TimeUnit unit) throws InterruptedException,
                                                                                    CanalStoreException {
    long nanos = unit.toNanos(timeout);
    final ReentrantLock lock = this.lock;
    lock.lockInterruptibly();
    try {
        for (;;) {
            if (checkUnGetSlotAt((LogPosition) start, batchSize)) {
                return doGet(start, batchSize);
            }

            if (nanos <= 0) {
                // 如果时间到了,有多少取多少
                return doGet(start, batchSize);
            }

            try {
                nanos = notEmpty.awaitNanos(nanos);
            } catch (InterruptedException ie) {
                notEmpty.signal(); // propagate to non-interrupted thread
                throw ie;
            }

        }
    } finally {
        lock.unlock();
    }
}
 
Example #19
Source File: MemoryEventStoreWithBuffer.java    From canal with Apache License 2.0 5 votes vote down vote up
public boolean put(List<Event> data, long timeout, TimeUnit unit) throws InterruptedException, CanalStoreException {
    if (data == null || data.isEmpty()) {
        return true;
    }

    long nanos = unit.toNanos(timeout);
    final ReentrantLock lock = this.lock;
    lock.lockInterruptibly();
    try {
        for (;;) {
            if (checkFreeSlotAt(putSequence.get() + data.size())) {
                doPut(data);
                return true;
            }
            if (nanos <= 0) {
                return false;
            }

            try {
                nanos = notFull.awaitNanos(nanos);
            } catch (InterruptedException ie) {
                notFull.signal(); // propagate to non-interrupted thread
                throw ie;
            }
        }
    } finally {
        lock.unlock();
    }
}
 
Example #20
Source File: MemoryEventStoreWithBuffer.java    From canal with Apache License 2.0 5 votes vote down vote up
public void rollback() throws CanalStoreException {
    final ReentrantLock lock = this.lock;
    lock.lock();
    try {
        getSequence.set(ackSequence.get());
        getMemSize.set(ackMemSize.get());
    } finally {
        lock.unlock();
    }
}
 
Example #21
Source File: GatewayEventStore.java    From DataLink with Apache License 2.0 5 votes vote down vote up
/**
 * 必须所有store都put成功之后再返回,避免外部重试导致单个store一直重复put
 */
@SuppressWarnings("unchecked")
private boolean doPut(List data) throws CanalStoreException {
    succeededStores.clear();
    isSuspend = false;
    startTime = System.currentTimeMillis();

    while (running && !interrupted) {
        if (!isSuspend) {
            Map<String, CanalEventStore> stores = Maps.newHashMap(attachedEventStores);
            if (stores.isEmpty()) {
                return false;
            }

            boolean result = true;
            for (String key : stores.keySet()) {
                if (!succeededStores.containsKey(key)) {
                    boolean putResult = stores.get(key).tryPut(data);
                    if (putResult) {
                        succeededStores.put(key, stores.get(key));
                    }
                    result &= putResult;
                }
            }
            if (result) {
                return true;
            }
            if (System.currentTimeMillis() - startTime > 1000 * 60 * 1) {
                isSuspend = true;
            }
        }

        //100ms
        LockSupport.parkNanos(1000 * 1000L * 100);
    }

    return false;
}
 
Example #22
Source File: GatewayEventStore.java    From DataLink with Apache License 2.0 5 votes vote down vote up
@Override
public boolean tryPut(List data) throws CanalStoreException {
    /*
     * 对类加一个全局锁,以避免上一轮的instanc和本轮的instance,同时执行tryput方法,而出现线程安全问题
     * 为什么会出现此种情况呢?因为上一轮的instance关闭时,只是把running的状态置为了false,tryput方法不一定立刻退出,而下一轮的
     * instance此时可能已经启动起来了,这样就可能出现同一个EnpointInstance的CanalEventStore被两个GatewayEventStore持有的情况。
     */
    synchronized (GatewayEventStore.class) {
        return doPut(data);
    }
}
 
Example #23
Source File: GatewayEventStore.java    From DataLink with Apache License 2.0 4 votes vote down vote up
@Override
public void put(Object data) throws InterruptedException, CanalStoreException {
    throw new UnsupportedOperationException("this method is not support.");
}
 
Example #24
Source File: GatewayEventStore.java    From DataLink with Apache License 2.0 4 votes vote down vote up
@Override
public boolean put(List data, long timeout, TimeUnit unit) throws InterruptedException, CanalStoreException {
    throw new UnsupportedOperationException("this method is not support.");
}
 
Example #25
Source File: GatewayEventStore.java    From DataLink with Apache License 2.0 4 votes vote down vote up
@Override
public void put(List data) throws InterruptedException, CanalStoreException {
    throw new UnsupportedOperationException("this method is not support.");
}
 
Example #26
Source File: MemoryEventStoreWithBuffer.java    From canal with Apache License 2.0 4 votes vote down vote up
public void cleanUntil(Position position, Long seqId) throws CanalStoreException {
    final ReentrantLock lock = this.lock;
    lock.lock();
    try {
        long sequence = ackSequence.get();
        long maxSequence = getSequence.get();

        boolean hasMatch = false;
        long memsize = 0;
        // ack没有list,但有已存在的foreach,还是节省一下list的开销
        long localExecTime = 0L;
        int deltaRows = 0;
        if (seqId > 0) {
            maxSequence = seqId;
        }
        for (long next = sequence + 1; next <= maxSequence; next++) {
            Event event = entries[getIndex(next)];
            if (localExecTime == 0 && event.getExecuteTime() > 0) {
                localExecTime = event.getExecuteTime();
            }
            deltaRows += event.getRowsCount();
            memsize += calculateSize(event);
            if ((seqId < 0 || next == seqId) && CanalEventUtils.checkPosition(event, (LogPosition) position)) {
                // 找到对应的position,更新ack seq
                hasMatch = true;

                if (batchMode.isMemSize()) {
                    ackMemSize.addAndGet(memsize);
                    // 尝试清空buffer中的内存,将ack之前的内存全部释放掉
                    for (long index = sequence + 1; index < next; index++) {
                        entries[getIndex(index)] = null;// 设置为null
                    }

                    // 考虑getFirstPosition/getLastPosition会获取最后一次ack的position信息
                    // ack清理的时候只处理entry=null,释放内存
                    Event lastEvent = entries[getIndex(next)];
                    lastEvent.setEntry(null);
                    lastEvent.setRawEntry(null);
                }

                if (ackSequence.compareAndSet(sequence, next)) {// 避免并发ack
                    notFull.signal();
                    ackTableRows.addAndGet(deltaRows);
                    if (localExecTime > 0) {
                        ackExecTime.lazySet(localExecTime);
                    }
                    return;
                }
            }
        }
        if (!hasMatch) {// 找不到对应需要ack的position
            throw new CanalStoreException("no match ack position" + position.toString());
        }
    } finally {
        lock.unlock();
    }
}
 
Example #27
Source File: MemoryEventStoreWithBuffer.java    From canal with Apache License 2.0 4 votes vote down vote up
public void put(Event data) throws InterruptedException, CanalStoreException {
    put(Arrays.asList(data));
}
 
Example #28
Source File: MemoryEventStoreWithBuffer.java    From canal with Apache License 2.0 4 votes vote down vote up
public boolean tryPut(Event data) throws CanalStoreException {
    return tryPut(Arrays.asList(data));
}
 
Example #29
Source File: DummyEventStore.java    From canal with Apache License 2.0 4 votes vote down vote up
public Events get(Position start, int batchSize, long timeout, TimeUnit unit) throws InterruptedException,
                                                                             CanalStoreException {
    return null;
}
 
Example #30
Source File: DummyEventStore.java    From canal with Apache License 2.0 4 votes vote down vote up
public Position getLatestPosition() throws CanalStoreException {
    return null;
}