use of org.apache.ignite.cdc.CdcEvent in project ignite by apache.
the class WalRecordsConsumer method onRecords.
/**
* Handles record from the WAL.
* If this method return {@code true} then current offset in WAL will be stored and WAL iteration will be
* started from it on CDC application fail/restart.
*
* @param recs WAL records iterator.
* @return {@code True} if current offset in WAL should be commited.
*/
public boolean onRecords(Iterator<DataRecord> recs) {
Iterator<CdcEvent> evts = new Iterator<CdcEvent>() {
/**
*/
private Iterator<CdcEvent> entries;
@Override
public boolean hasNext() {
advance();
return hasCurrent();
}
@Override
public CdcEvent next() {
advance();
if (!hasCurrent())
throw new NoSuchElementException();
evtsCnt.increment();
lastEvtTs.value(System.currentTimeMillis());
return entries.next();
}
private void advance() {
if (hasCurrent())
return;
while (recs.hasNext()) {
entries = F.iterator(recs.next().writeEntries().iterator(), this::transform, true, OPERATIONS_FILTER);
if (entries.hasNext())
break;
entries = null;
}
}
private boolean hasCurrent() {
return entries != null && entries.hasNext();
}
/**
*/
private CdcEvent transform(DataEntry e) {
UnwrappedDataEntry ue = (UnwrappedDataEntry) e;
return new CdcEventImpl(ue.unwrappedKey(), ue.unwrappedValue(), (e.flags() & DataEntry.PRIMARY_FLAG) != 0, e.partitionId(), e.writeVersion(), e.cacheId());
}
};
return consumer.onEvents(evts);
}
Aggregations