use of co.cask.cdap.data2.transaction.TxCallable in project cdap by caskdata.
the class DefaultCheckpointManager method saveCheckpoints.
@Override
public void saveCheckpoints(final Map<Integer, ? extends Checkpoint> checkpoints) throws Exception {
// if the checkpoints have not changed, we skip writing to table and return.
if (lastCheckpoint.equals(checkpoints)) {
return;
}
try {
lastCheckpoint = Transactions.execute(transactional, new TxCallable<Map<Integer, Checkpoint>>() {
@Override
public Map<Integer, Checkpoint> call(DatasetContext context) throws Exception {
Map<Integer, Checkpoint> result = new HashMap<>();
Table table = getCheckpointTable(context);
for (Map.Entry<Integer, ? extends Checkpoint> entry : checkpoints.entrySet()) {
byte[] key = Bytes.add(rowKeyPrefix, Bytes.toBytes(entry.getKey()));
Checkpoint checkpoint = entry.getValue();
table.put(key, OFFSET_COL_NAME, Bytes.toBytes(checkpoint.getNextOffset()));
table.put(key, NEXT_TIME_COL_NAME, Bytes.toBytes(checkpoint.getNextEventTime()));
table.put(key, MAX_TIME_COL_NAME, Bytes.toBytes(checkpoint.getMaxEventTime()));
result.put(entry.getKey(), new Checkpoint(checkpoint.getNextOffset(), checkpoint.getNextEventTime(), checkpoint.getMaxEventTime()));
}
return result;
}
});
} catch (TransactionFailureException e) {
throw Transactions.propagate(e, ServiceUnavailableException.class);
}
LOG.trace("Saved checkpoints for partitions {}", checkpoints);
}
Aggregations