use of io.cdap.cdap.spi.data.table.field.Range in project cdap by cdapio.
the class NoSqlStructuredTable method count.
@Override
public long count(Collection<Range> keyRanges) throws IOException {
LOG.trace("Table {}: count with ranges {}", schema.getTableId(), keyRanges);
long count = 0;
for (Range keyRange : keyRanges) {
try (Scanner scanner = getScanner(keyRange)) {
while (scanner.next() != null) {
count++;
}
}
}
return count;
}
use of io.cdap.cdap.spi.data.table.field.Range in project cdap by cdapio.
the class ProgramScheduleStoreDataset method deleteSchedules.
/**
* Removes all schedules for a specific application from the store.
*
* @param appId the application id for which to delete the schedules
* @return the IDs of the schedules that were deleted
*/
// TODO: fix the bug that this method will return fake schedule id https://issues.cask.co/browse/CDAP-13626
public List<ScheduleId> deleteSchedules(ApplicationId appId, long deleteTime) throws IOException {
List<ScheduleId> deleted = new ArrayList<>();
Collection<Field<?>> scanKeys = getScheduleKeysForApplicationScan(appId);
Range range = Range.singleton(scanKeys);
// First collect all the schedules that are going to be deleted
try (CloseableIterator<StructuredRow> iterator = scheduleStore.scan(range, Integer.MAX_VALUE)) {
while (iterator.hasNext()) {
StructuredRow row = iterator.next();
if (row.getString(StoreDefinition.ProgramScheduleStore.SCHEDULE) != null) {
markScheduleAsDeleted(row, deleteTime);
deleted.add(rowToScheduleId(row));
}
}
}
// Then delete all triggers for the app
triggerStore.deleteAll(range);
return deleted;
}
use of io.cdap.cdap.spi.data.table.field.Range in project cdap by cdapio.
the class ProgramScheduleStoreDataset method deleteSchedules.
/**
* Removes all schedules for a specific program from the store.
*
* @param programId the program id for which to delete the schedules
* @return the IDs of the schedules that were deleted
*/
// TODO: fix the bug that this method will return fake schedule id https://issues.cask.co/browse/CDAP-13626
public List<ScheduleId> deleteSchedules(ProgramId programId, long deleteTime) throws IOException {
List<ScheduleId> deleted = new ArrayList<>();
Collection<Field<?>> scanKeys = getScheduleKeysForApplicationScan(programId.getParent());
Range range = Range.singleton(scanKeys);
// First collect all the schedules that are going to be deleted
try (CloseableIterator<StructuredRow> iterator = scheduleStore.scan(range, Integer.MAX_VALUE)) {
while (iterator.hasNext()) {
StructuredRow row = iterator.next();
String serializedSchedule = row.getString(StoreDefinition.ProgramScheduleStore.SCHEDULE);
if (serializedSchedule != null) {
ProgramSchedule schedule = GSON.fromJson(serializedSchedule, ProgramSchedule.class);
if (programId.equals(schedule.getProgramId())) {
markScheduleAsDeleted(row, deleteTime);
Collection<Field<?>> deleteKeys = getScheduleKeys(row);
triggerStore.deleteAll(Range.singleton(deleteKeys));
deleted.add(rowToScheduleId(row));
}
}
}
}
return deleted;
}
use of io.cdap.cdap.spi.data.table.field.Range in project cdap by cdapio.
the class FileMetadataCleaner method scanAndGetFilesToDelete.
/**
* scans for meta data in new format which has expired the log retention.
* @param tillTime time till which files will be deleted
* @param fileCleanupBatchSize transaction clean up batch size.
* @return list of DeleteEntry - used to get files to delete for which metadata has already been deleted
*/
public List<DeletedEntry> scanAndGetFilesToDelete(final long tillTime, final int fileCleanupBatchSize) {
final List<DeletedEntry> toDelete = new ArrayList<>(fileCleanupBatchSize);
try {
final AtomicReference<Range> range = new AtomicReference<>(Range.all());
// stop cleaning up if there are no files to delete or if we have reached batch size
while (range.get() != null) {
TransactionRunners.run(transactionRunner, context -> {
StructuredTable table = context.getTable(StoreDefinition.LogFileMetaStore.LOG_FILE_META);
range.set(scanFilesToDelete(table, fileCleanupBatchSize, tillTime, toDelete, range));
}, IOException.class);
}
} catch (IOException e) {
LOG.warn("Got Exception while scanning metadata table", e);
// if there is an exception, no metadata, so delete file should be skipped.
return new ArrayList<>();
}
if (!toDelete.isEmpty()) {
// delete meta data entries in toDelete and get the file location list
return deleteNewMetadataEntries(toDelete);
}
// toDelete is empty, safe to return that
return toDelete;
}
use of io.cdap.cdap.spi.data.table.field.Range in project cdap by cdapio.
the class AppMetadataStore method getActiveRuns.
/**
* Get active runs for the given programs. Active runs means program run with status STARTING, PENDING,
* RUNNING or SUSPENDED.
*
* @param ids set of program ids to fetch for active run records
* @return a map from {@link ProgramId} to a {@link Collection} of {@link RunRecordDetail}. It is guaranteed to have
* an entry for each of the given program id.
* @throws IOException if failed to fetch the run records.
*/
public Map<ProgramId, Collection<RunRecordDetail>> getActiveRuns(Collection<ProgramId> ids) throws IOException {
Collection<Range> ranges = new ArrayList<>();
Map<ProgramId, Collection<RunRecordDetail>> result = new LinkedHashMap<>();
for (ProgramId programId : ids) {
ranges.add(Range.singleton(getRunRecordProgramPrefix(TYPE_RUN_RECORD_ACTIVE, programId)));
result.put(programId, new LinkedHashSet<>());
}
try (CloseableIterator<StructuredRow> iterator = getRunRecordsTable().multiScan(ranges, Integer.MAX_VALUE)) {
while (iterator.hasNext()) {
StructuredRow row = iterator.next();
RunRecordDetail meta = deserializeRunRecordMeta(row);
result.get(meta.getProgramRunId().getParent()).add(meta);
}
}
return result;
}
Aggregations