@NotThreadSafe public abstract class AbstractStreamFileConsumer extends Object implements StreamConsumer
StreamConsumer that read events from stream file and uses a table to store consumer states.
State table ROW key schema:
row_key = <group_id> <stream_file_offset>
group_id = 8 bytes consumer group id
stream_file_offset = <partition_start> <partition_end> <name_prefix> <sequence_id> <offset>
partition_start = 8 bytes timestamp of partition start time
partition_end = 8 bytes timestamp of partition end time
name_prefix = DataOutput UTF-8 output.
sequence_id = 4 bytes stream file sequence id
offset = 8 bytes offset inside the stream file
The state table has single column
(QueueEntryRow.COLUMN_FAMILY:QueueEntryRow.STATE_COLUMN_PREFIX) to store state.
The state value:
state_value = <write_pointer> <instance_id> <state>
write_pointer = 8 bytes Transaction write point of the consumer who update this state.
instance_id = 4 bytes Instance id of the consumer who update this state.
state = ConsumerEntryState.getState(), either CLAIMED or PROCESSED
| Modifier and Type | Class and Description |
|---|---|
protected static interface |
AbstractStreamFileConsumer.StateScanner
Scanner for scanning state table.
|
| Modifier and Type | Field and Description |
|---|---|
protected static int |
MAX_SCAN_ROWS |
protected byte[] |
stateColumnName |
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractStreamFileConsumer(CConfiguration cConf,
StreamConfig streamConfig,
ConsumerConfig consumerConfig,
FileReader<StreamEventOffset,Iterable<StreamFileOffset>> reader,
StreamConsumerStateStore consumerStateStore,
StreamConsumerState beginConsumerState,
ReadFilter extraFilter) |
| Modifier and Type | Method and Description |
|---|---|
protected abstract boolean |
claimFifoEntry(byte[] row,
byte[] value,
byte[] oldValue) |
void |
close() |
boolean |
commitTx() |
protected void |
doClose() |
ConsumerConfig |
getConsumerConfig() |
Id.Stream |
getStreamId() |
String |
getTransactionAwareName() |
Collection<byte[]> |
getTxChanges() |
DequeueResult<co.cask.cdap.api.flow.flowlet.StreamEvent> |
poll(int maxEvents,
long timeout,
TimeUnit timeoutUnit)
Retrieves up to
maxEvents of StreamEvent from the stream. |
void |
postTxCommit() |
boolean |
rollbackTx() |
protected abstract AbstractStreamFileConsumer.StateScanner |
scanStates(byte[] startRow,
byte[] endRow) |
void |
startTx(co.cask.tephra.Transaction tx) |
String |
toString() |
protected abstract void |
undoState(Iterable<byte[]> rows,
int size) |
protected abstract void |
updateState(Iterable<byte[]> rows,
int size,
byte[] value) |
void |
updateTx(co.cask.tephra.Transaction tx) |
protected static final int MAX_SCAN_ROWS
protected final byte[] stateColumnName
protected AbstractStreamFileConsumer(CConfiguration cConf, StreamConfig streamConfig, ConsumerConfig consumerConfig, FileReader<StreamEventOffset,Iterable<StreamFileOffset>> reader, StreamConsumerStateStore consumerStateStore, StreamConsumerState beginConsumerState, @Nullable ReadFilter extraFilter)
streamConfig - Stream configuration.consumerConfig - Consumer configuration.reader - For reading stream events. This class is responsible for closing the reader.consumerStateStore - The state store for saving consumer statebeginConsumerState - Consumer state to begin with.extraFilter - Extra ReadFilter that is ANDed with default read filter and applied first.protected void doClose()
throws IOException
IOExceptionprotected abstract boolean claimFifoEntry(byte[] row,
byte[] value,
byte[] oldValue)
throws IOException
IOExceptionprotected abstract void updateState(Iterable<byte[]> rows, int size, byte[] value) throws IOException
IOExceptionprotected abstract void undoState(Iterable<byte[]> rows, int size) throws IOException
IOExceptionprotected abstract AbstractStreamFileConsumer.StateScanner scanStates(byte[] startRow, byte[] endRow) throws IOException
IOExceptionpublic final Id.Stream getStreamId()
getStreamId in interface StreamConsumerpublic final ConsumerConfig getConsumerConfig()
getConsumerConfig in interface StreamConsumerpublic final DequeueResult<co.cask.cdap.api.flow.flowlet.StreamEvent> poll(int maxEvents, long timeout, TimeUnit timeoutUnit) throws IOException, InterruptedException
StreamConsumermaxEvents of StreamEvent from the stream.poll in interface StreamConsumermaxEvents - Maximum number of events to retrievetimeout - Maximum of time to spend on trying to read up to maxEventstimeoutUnit - Unit for the timeoutDequeueResult which carries StreamEvents inside.IOException - If there is error while reading eventsInterruptedException - If interrupted while waitingpublic final void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionpublic final void startTx(co.cask.tephra.Transaction tx)
startTx in interface co.cask.tephra.TransactionAwarepublic final void updateTx(co.cask.tephra.Transaction tx)
updateTx in interface co.cask.tephra.TransactionAwarepublic final Collection<byte[]> getTxChanges()
getTxChanges in interface co.cask.tephra.TransactionAwarepublic final boolean commitTx()
throws Exception
commitTx in interface co.cask.tephra.TransactionAwareExceptionpublic void postTxCommit()
postTxCommit in interface co.cask.tephra.TransactionAwarepublic boolean rollbackTx()
throws Exception
rollbackTx in interface co.cask.tephra.TransactionAwareExceptionpublic String getTransactionAwareName()
getTransactionAwareName in interface co.cask.tephra.TransactionAwareCopyright © 2016 Cask Data, Inc. Licensed under the Apache License, Version 2.0.