use of co.cask.cdap.api.dataset.table.Row in project cdap by caskdata.
the class HBaseConsumerStateStore method fetchAllStartRows.
private com.google.common.collect.Table<Long, Integer, byte[]> fetchAllStartRows() {
com.google.common.collect.Table<Long, Integer, byte[]> result = HashBasedTable.create();
Row row = table.get(queueName.toBytes());
for (Map.Entry<byte[], byte[]> entry : row.getColumns().entrySet()) {
long groupId = getGroupIdFromColumn(entry.getKey());
int instanceId = getInstanceIdFromColumn(entry.getKey());
result.put(groupId, instanceId, entry.getValue());
}
return result;
}
use of co.cask.cdap.api.dataset.table.Row in project cdap by caskdata.
the class HBaseQueueAdmin method deleteFlowConfigs.
private void deleteFlowConfigs(FlowId flowId) throws Exception {
// It's a bit hacky here since we know how the HBaseConsumerStateStore works.
// Maybe we need another Dataset set that works across all queues.
final QueueName prefixName = QueueName.from(URI.create(QueueName.prefixForFlow(flowId)));
DatasetId stateStoreId = getStateStoreId(flowId.getNamespace());
Map<String, String> args = ImmutableMap.of(HBaseQueueDatasetModule.PROPERTY_QUEUE_NAME, prefixName.toString());
HBaseConsumerStateStore stateStore = datasetFramework.getDataset(stateStoreId, args, null);
if (stateStore == null) {
// If the state store doesn't exists, meaning there is no queue, hence nothing to do.
return;
}
try {
final Table table = stateStore.getInternalTable();
Transactions.createTransactionExecutor(txExecutorFactory, (TransactionAware) table).execute(new TransactionExecutor.Subroutine() {
@Override
public void apply() throws Exception {
// Prefix name is "/" terminated ("queue:///namespace/app/flow/"), hence the scan is unique for the flow
byte[] startRow = Bytes.toBytes(prefixName.toString());
try (Scanner scanner = table.scan(startRow, Bytes.stopKeyForPrefix(startRow))) {
Row row = scanner.next();
while (row != null) {
table.delete(row.getRow());
row = scanner.next();
}
}
}
});
} finally {
stateStore.close();
}
}
use of co.cask.cdap.api.dataset.table.Row in project cdap by caskdata.
the class HBaseConsumerStateStore method completed.
/**
* Called by consumer to signal process completion up to the current barrier that the consumer is in.
*/
void completed(long groupId, int instanceId) {
// Get the current consumer state to get the end barrier info
ConsumerState consumerState = getConsumerState(groupId, instanceId);
QueueBarrier nextBarrier = consumerState.getNextBarrier();
if (nextBarrier == null) {
// End row shouldn't be null if this method is called
throw new IllegalArgumentException(String.format("No end barrier information for consumer. Queue: %s, GroupId: %d, InstanceId: %d", queueName, groupId, instanceId));
}
byte[] stateColumn = getConsumerStateColumn(groupId, instanceId);
// If the instance exists in the next barrier, set the start row to the barrier start
if (instanceId < nextBarrier.getGroupConfig().getGroupSize()) {
table.put(queueName.toBytes(), stateColumn, nextBarrier.getStartRow());
return;
}
// find the next start barrier that this instance needs to consume from
try (Scanner scanner = table.scan(Bytes.add(queueName.toBytes(), nextBarrier.getStartRow()), barrierScanEndRow)) {
Row row;
boolean found = false;
while (!found && (row = scanner.next()) != null) {
QueueBarrier queueBarrier = decodeBarrierInfo(row, groupId);
if (queueBarrier == null || instanceId >= queueBarrier.getGroupConfig().getGroupSize()) {
continue;
}
table.put(queueName.toBytes(), stateColumn, queueBarrier.getStartRow());
found = true;
}
if (!found) {
// Remove the state since this consumer instance is not longer active
table.delete(queueName.toBytes(), stateColumn);
}
}
}
use of co.cask.cdap.api.dataset.table.Row in project cdap by caskdata.
the class HBaseConsumerStateStore method fetchStartRows.
/**
* Fetches start row states of all instances for a given consumer group.
*
* @param groupId consumer group Id
* @param instances number of instances in the consumer group
* @return a map from instanceId to start row state
*/
private Map<Integer, byte[]> fetchStartRows(long groupId, int instances) {
// Gets all columns with the groupId as prefix
int stopInstanceId = (instances == Integer.MAX_VALUE) ? Integer.MAX_VALUE : instances + 1;
Row row = table.get(queueName.toBytes(), getConsumerStateColumn(groupId, 0), getConsumerStateColumn(groupId, stopInstanceId), instances);
return getStartRowsFromColumns(row.getColumns());
}
use of co.cask.cdap.api.dataset.table.Row in project cdap by caskdata.
the class WorkflowDataset method getRecord.
@Nullable
WorkflowRunRecord getRecord(WorkflowId id, String pid) {
RunId runId = RunIds.fromString(pid);
long startTime = RunIds.getTime(runId, TimeUnit.SECONDS);
MDSKey mdsKey = getRowKeyBuilder(id, startTime).build();
byte[] startRowKey = mdsKey.getKey();
Row indexRow = table.get(startRowKey);
if (indexRow.isEmpty()) {
return null;
}
Map<byte[], byte[]> columns = indexRow.getColumns();
String workflowRunId = Bytes.toString(columns.get(RUNID));
long timeTaken = Bytes.toLong(columns.get(TIME_TAKEN));
List<ProgramRun> actionRunsList = GSON.fromJson(Bytes.toString(columns.get(NODES)), PROGRAM_RUNS_TYPE);
return new WorkflowRunRecord(workflowRunId, timeTaken, actionRunsList);
}
Aggregations