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

The following examples show how to use com.alibaba.otter.canal.store.CanalEventStore. 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: CanalServerWithEmbedded.java    From canal-1.1.3 with Apache License 2.0 6 votes vote down vote up
/**
 * 根据不同的参数,选择不同的方式获取数据
 */
private Events<Event> getEvents(CanalEventStore eventStore, Position start, int batchSize, Long timeout,
                                TimeUnit unit) {
    if (timeout == null) {
        return eventStore.tryGet(start, batchSize);
    } else {
        try {
            if (timeout <= 0) {
                return eventStore.get(start, batchSize);
            } else {
                return eventStore.get(start, batchSize, timeout, unit);
            }
        } catch (Exception e) {
            throw new CanalServerException(e);
        }
    }
}
 
Example #2
Source File: CanalServerWithEmbedded.java    From canal with Apache License 2.0 6 votes vote down vote up
/**
 * 根据不同的参数,选择不同的方式获取数据
 */
private Events<Event> getEvents(CanalEventStore eventStore, Position start, int batchSize, Long timeout,
                                TimeUnit unit) {
    if (timeout == null) {
        return eventStore.tryGet(start, batchSize);
    } else {
        try {
            if (timeout <= 0) {
                return eventStore.get(start, batchSize);
            } else {
                return eventStore.get(start, batchSize, timeout, unit);
            }
        } catch (Exception e) {
            throw new CanalServerException(e);
        }
    }
}
 
Example #3
Source File: CanalServerWithEmbedded.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
private boolean isRaw(CanalEventStore eventStore) {
    if (eventStore instanceof MemoryEventStoreWithBuffer) {
        return ((MemoryEventStoreWithBuffer) eventStore).isRaw();
    }

    return true;
}
 
Example #4
Source File: StoreCollector.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
@Override
public void register(CanalInstance instance) {
    final String destination = instance.getDestination();
    StoreMetricsHolder holder = new StoreMetricsHolder();
    CanalEventStore store = instance.getEventStore();
    if (!(store instanceof MemoryEventStoreWithBuffer)) {
        throw new IllegalArgumentException("EventStore must be MemoryEventStoreWithBuffer");
    }
    MemoryEventStoreWithBuffer memStore = (MemoryEventStoreWithBuffer) store;
    holder.batchMode = memStore.getBatchMode();
    holder.putSeq = memStore.getPutSequence();
    holder.ackSeq = memStore.getAckSequence();
    holder.destLabelValues = Collections.singletonList(destination);
    holder.size = memStore.getBufferSize();
    holder.storeLabelValues = Arrays.asList(destination, holder.batchMode.name(), Integer.toString(holder.size));
    holder.putExecTime = memStore.getPutExecTime();
    holder.getExecTime = memStore.getGetExecTime();
    holder.ackExecTime = memStore.getAckExecTime();
    holder.putTableRows = memStore.getPutTableRows();
    holder.getTableRows = memStore.getGetTableRows();
    holder.ackTableRows = memStore.getAckTableRows();
    Preconditions.checkNotNull(holder.batchMode);
    Preconditions.checkNotNull(holder.putSeq);
    Preconditions.checkNotNull(holder.ackSeq);
    if (holder.batchMode.isMemSize()) {
        holder.putMemSize = memStore.getPutMemSize();
        holder.ackMemSize = memStore.getAckMemSize();
        Preconditions.checkNotNull(holder.putMemSize);
        Preconditions.checkNotNull(holder.ackMemSize);
    }
    StoreMetricsHolder old = instances.putIfAbsent(destination, holder);
    if (old != null) {
        logger.warn("Remote stale StoreCollector for instance {}.", destination);
    }
}
 
Example #5
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 #6
Source File: CanalServerWithEmbedded.java    From canal with Apache License 2.0 5 votes vote down vote up
private boolean isRaw(CanalEventStore eventStore) {
    if (eventStore instanceof MemoryEventStoreWithBuffer) {
        return ((MemoryEventStoreWithBuffer) eventStore).isRaw();
    }

    return true;
}
 
Example #7
Source File: StoreCollector.java    From canal with Apache License 2.0 5 votes vote down vote up
@Override
public void register(CanalInstance instance) {
    final String destination = instance.getDestination();
    StoreMetricsHolder holder = new StoreMetricsHolder();
    CanalEventStore store = instance.getEventStore();
    if (!(store instanceof MemoryEventStoreWithBuffer)) {
        throw new IllegalArgumentException("EventStore must be MemoryEventStoreWithBuffer");
    }
    MemoryEventStoreWithBuffer memStore = (MemoryEventStoreWithBuffer) store;
    holder.batchMode = memStore.getBatchMode();
    holder.putSeq = memStore.getPutSequence();
    holder.ackSeq = memStore.getAckSequence();
    holder.destLabelValues = Collections.singletonList(destination);
    holder.size = memStore.getBufferSize();
    holder.storeLabelValues = Arrays.asList(destination, holder.batchMode.name(), Integer.toString(holder.size));
    holder.putExecTime = memStore.getPutExecTime();
    holder.getExecTime = memStore.getGetExecTime();
    holder.ackExecTime = memStore.getAckExecTime();
    holder.putTableRows = memStore.getPutTableRows();
    holder.getTableRows = memStore.getGetTableRows();
    holder.ackTableRows = memStore.getAckTableRows();
    Preconditions.checkNotNull(holder.batchMode);
    Preconditions.checkNotNull(holder.putSeq);
    Preconditions.checkNotNull(holder.ackSeq);
    if (holder.batchMode.isMemSize()) {
        holder.putMemSize = memStore.getPutMemSize();
        holder.ackMemSize = memStore.getAckMemSize();
        Preconditions.checkNotNull(holder.putMemSize);
        Preconditions.checkNotNull(holder.ackMemSize);
    }
    StoreMetricsHolder old = instances.putIfAbsent(destination, holder);
    if (old != null) {
        logger.warn("Remote stale StoreCollector for instance {}.", destination);
    }
}
 
Example #8
Source File: CanalInstanceWithSpring.java    From canal-1.1.3 with Apache License 2.0 4 votes vote down vote up
public void setEventStore(CanalEventStore<Event> eventStore) {
    this.eventStore = eventStore;
}
 
Example #9
Source File: AbstractCanalInstance.java    From canal-1.1.3 with Apache License 2.0 4 votes vote down vote up
@Override
public CanalEventStore getEventStore() {
    return eventStore;
}
 
Example #10
Source File: EntryEventSink.java    From canal-1.1.3 with Apache License 2.0 4 votes vote down vote up
public void setEventStore(CanalEventStore<Event> eventStore) {
    this.eventStore = eventStore;
}
 
Example #11
Source File: GatewayEventStore.java    From DataLink with Apache License 2.0 4 votes vote down vote up
public void registerEventStore(String destination, CanalEventStore eventStore) {
    attachedEventStores.put(destination, eventStore);
    logger.info("registered an event store from endpoint instance {}.", destination);
}
 
Example #12
Source File: CanalInstanceWithSpring.java    From canal with Apache License 2.0 4 votes vote down vote up
public void setEventStore(CanalEventStore<Event> eventStore) {
    this.eventStore = eventStore;
}
 
Example #13
Source File: AbstractCanalInstance.java    From canal with Apache License 2.0 4 votes vote down vote up
@Override
public CanalEventStore getEventStore() {
    return eventStore;
}
 
Example #14
Source File: EntryEventSink.java    From canal with Apache License 2.0 4 votes vote down vote up
public void setEventStore(CanalEventStore<Event> eventStore) {
    this.eventStore = eventStore;
}
 
Example #15
Source File: CanalInstance.java    From canal-1.1.3 with Apache License 2.0 votes vote down vote up
CanalEventStore getEventStore(); 
Example #16
Source File: CanalInstance.java    From canal with Apache License 2.0 votes vote down vote up
CanalEventStore getEventStore();