use of co.cask.cdap.messaging.store.RawMessageTableEntry in project cdap by caskdata.
the class LevelDBMessageTable method persist.
@Override
protected void persist(Iterator<RawMessageTableEntry> entries) throws IOException {
try (WriteBatch writeBatch = levelDB.createWriteBatch()) {
while (entries.hasNext()) {
RawMessageTableEntry entry = entries.next();
byte[] rowKey = entry.getKey();
// LevelDB doesn't make copies, and since we reuse RawMessageTableEntry object, we need to create copies.
writeBatch.put(Arrays.copyOf(rowKey, rowKey.length), encodeValue(entry.getTxPtr(), entry.getPayload()));
}
levelDB.write(writeBatch, WRITE_OPTIONS);
} catch (DBException ex) {
throw new IOException(ex);
}
}
use of co.cask.cdap.messaging.store.RawMessageTableEntry in project cdap by caskdata.
the class LevelDBMessageTable method read.
@Override
protected CloseableIterator<RawMessageTableEntry> read(byte[] startRow, byte[] stopRow) throws IOException {
final DBScanIterator iterator = new DBScanIterator(levelDB, startRow, stopRow);
final RawMessageTableEntry tableEntry = new RawMessageTableEntry();
return new AbstractCloseableIterator<RawMessageTableEntry>() {
private boolean closed = false;
@Override
protected RawMessageTableEntry computeNext() {
if (closed || (!iterator.hasNext())) {
return endOfData();
}
Map.Entry<byte[], byte[]> row = iterator.next();
Map<String, byte[]> columns = decodeValue(row.getValue());
return tableEntry.set(row.getKey(), columns.get(TX_COL), columns.get(PAYLOAD_COL));
}
@Override
public void close() {
try {
iterator.close();
} finally {
endOfData();
closed = true;
}
}
};
}
use of co.cask.cdap.messaging.store.RawMessageTableEntry in project cdap by caskdata.
the class HBaseMessageTable method persist.
@Override
protected void persist(Iterator<RawMessageTableEntry> entries) throws IOException {
List<Put> batchPuts = new ArrayList<>();
while (entries.hasNext()) {
RawMessageTableEntry entry = entries.next();
PutBuilder putBuilder = tableUtil.buildPut(rowKeyDistributor.getDistributedKey(entry.getKey()));
if (entry.getTxPtr() != null) {
putBuilder.add(columnFamily, TX_COL, entry.getTxPtr());
}
if (entry.getPayload() != null) {
putBuilder.add(columnFamily, PAYLOAD_COL, entry.getPayload());
}
batchPuts.add(putBuilder.build());
}
try {
if (!batchPuts.isEmpty()) {
hTable.put(batchPuts);
if (!hTable.isAutoFlush()) {
hTable.flushCommits();
}
}
} catch (IOException e) {
throw exceptionHandler.handle(e);
}
}
use of co.cask.cdap.messaging.store.RawMessageTableEntry in project cdap by caskdata.
the class HBaseMessageTable method read.
@Override
protected CloseableIterator<RawMessageTableEntry> read(byte[] startRow, byte[] stopRow) throws IOException {
Scan scan = tableUtil.buildScan().setStartRow(startRow).setStopRow(stopRow).setCaching(scanCacheRows).build();
try {
final ResultScanner scanner = DistributedScanner.create(hTable, 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();
}
return tableEntry.set(rowKeyDistributor.getOriginalKey(result.getRow()), 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);
}
}
Aggregations