use of io.cdap.cdap.messaging.store.MessageTableKey in project cdap by caskdata.
the class HBaseMessageTable method scan.
@Override
protected CloseableIterator<RawMessageTableEntry> scan(ScanRequest scanRequest) throws IOException {
Scan scan = tableUtil.buildScan().setStartRow(scanRequest.getStartRow()).setStopRow(scanRequest.getStopRow()).setCaching(scanCacheRows).build();
TopicMetadata topicMetadata = scanRequest.getTopicMetadata();
byte[] topic = MessagingUtils.toDataKeyPrefix(topicMetadata.getTopicId(), topicMetadata.getGeneration());
MessageTableKey messageTableKey = MessageTableKey.fromTopic(topic);
try {
final ResultScanner scanner = DistributedScanner.create(table, scan, rowKeyDistributor, scanExecutor);
final RawMessageTableEntry tableEntry = new RawMessageTableEntry();
return new AbstractCloseableIterator<RawMessageTableEntry>() {
private boolean closed = false;
@Override
protected RawMessageTableEntry computeNext() {
if (closed) {
return endOfData();
}
Result result;
try {
result = scanner.next();
} catch (IOException e) {
throw exceptionHandler.handleAndWrap(e);
}
if (result == null) {
return endOfData();
}
byte[] originalKey = rowKeyDistributor.getOriginalKey(result.getRow());
messageTableKey.setFromRowKey(originalKey);
return tableEntry.set(messageTableKey, result.getValue(columnFamily, TX_COL), result.getValue(columnFamily, PAYLOAD_COL));
}
@Override
public void close() {
try {
scanner.close();
} finally {
endOfData();
closed = true;
}
}
};
} catch (IOException e) {
throw exceptionHandler.handle(e);
}
}
use of io.cdap.cdap.messaging.store.MessageTableKey in project cdap by caskdata.
the class LevelDBMessageTable method scan.
@Override
protected CloseableIterator<RawMessageTableEntry> scan(ScanRequest scanRequest) throws IOException {
Collection<LevelDBPartition> partitions = partitionManager.getPartitions(scanRequest.getStartTime());
if (partitions.isEmpty()) {
return CloseableIterator.empty();
}
RawMessageTableEntry tableEntry = new RawMessageTableEntry();
TopicMetadata topicMetadata = scanRequest.getTopicMetadata();
byte[] topic = MessagingUtils.toDataKeyPrefix(topicMetadata.getTopicId(), topicMetadata.getGeneration());
MessageTableKey messageTableKey = MessageTableKey.fromTopic(topic);
BiFunction<byte[], byte[], RawMessageTableEntry> decodeFunction = (key, value) -> {
Map<String, byte[]> columns = decodeValue(value);
messageTableKey.setFromRowKey(key);
return tableEntry.set(messageTableKey, columns.get(TX_COL), columns.get(PAYLOAD_COL));
};
return new PartitionedDBScanIterator<>(partitions.iterator(), scanRequest.getStartRow(), scanRequest.getStopRow(), decodeFunction);
}
Aggregations