Java Code Examples for com.alibaba.otter.canal.store.model.Event#getRowsCount()

The following examples show how to use com.alibaba.otter.canal.store.model.Event#getRowsCount() . 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: MemoryEventStoreWithBuffer.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
private void profiling(List<Event> events, OP op) {
    long localExecTime = 0L;
    int deltaRows = 0;
    if (events != null && !events.isEmpty()) {
        for (Event e : events) {
            if (localExecTime == 0 && e.getExecuteTime() > 0) {
                localExecTime = e.getExecuteTime();
            }
            deltaRows += e.getRowsCount();
        }
    }
    switch (op) {
        case PUT:
            putTableRows.addAndGet(deltaRows);
            if (localExecTime > 0) {
                putExecTime.lazySet(localExecTime);
            }
            break;
        case GET:
            getTableRows.addAndGet(deltaRows);
            if (localExecTime > 0) {
                getExecTime.lazySet(localExecTime);
            }
            break;
        case ACK:
            ackTableRows.addAndGet(deltaRows);
            if (localExecTime > 0) {
                ackExecTime.lazySet(localExecTime);
            }
            break;
        default:
            break;
    }
}
 
Example 2
Source File: MemoryEventStoreWithBuffer.java    From canal with Apache License 2.0 5 votes vote down vote up
private void profiling(List<Event> events, OP op) {
    long localExecTime = 0L;
    int deltaRows = 0;
    if (events != null && !events.isEmpty()) {
        for (Event e : events) {
            if (localExecTime == 0 && e.getExecuteTime() > 0) {
                localExecTime = e.getExecuteTime();
            }
            deltaRows += e.getRowsCount();
        }
    }
    switch (op) {
        case PUT:
            putTableRows.addAndGet(deltaRows);
            if (localExecTime > 0) {
                putExecTime.lazySet(localExecTime);
            }
            break;
        case GET:
            getTableRows.addAndGet(deltaRows);
            if (localExecTime > 0) {
                getExecTime.lazySet(localExecTime);
            }
            break;
        case ACK:
            ackTableRows.addAndGet(deltaRows);
            if (localExecTime > 0) {
                ackExecTime.lazySet(localExecTime);
            }
            break;
        default:
            break;
    }
}
 
Example 3
Source File: MemoryEventStoreWithBuffer.java    From canal-1.1.3 with Apache License 2.0 4 votes vote down vote up
public void cleanUntil(Position position) 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;
        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);
            boolean match = CanalEventUtils.checkPosition(event, (LogPosition) position);
            if (match) {// 找到对应的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
                    }
                }

                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 4
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();
    }
}