Search in sources :

Example 11 with Range

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;
}
Also used : Scanner(io.cdap.cdap.api.dataset.table.Scanner) Range(io.cdap.cdap.spi.data.table.field.Range)

Example 12 with Range

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;
}
Also used : Field(io.cdap.cdap.spi.data.table.field.Field) ArrayList(java.util.ArrayList) StructuredRow(io.cdap.cdap.spi.data.StructuredRow) ScheduleId(io.cdap.cdap.proto.id.ScheduleId) Range(io.cdap.cdap.spi.data.table.field.Range)

Example 13 with Range

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;
}
Also used : Field(io.cdap.cdap.spi.data.table.field.Field) ProgramSchedule(io.cdap.cdap.internal.app.runtime.schedule.ProgramSchedule) ArrayList(java.util.ArrayList) StructuredRow(io.cdap.cdap.spi.data.StructuredRow) ScheduleId(io.cdap.cdap.proto.id.ScheduleId) Range(io.cdap.cdap.spi.data.table.field.Range)

Example 14 with Range

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;
}
Also used : StructuredTable(io.cdap.cdap.spi.data.StructuredTable) ArrayList(java.util.ArrayList) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) Range(io.cdap.cdap.spi.data.table.field.Range)

Example 15 with Range

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;
}
Also used : ArrayList(java.util.ArrayList) StructuredRow(io.cdap.cdap.spi.data.StructuredRow) Collection(java.util.Collection) Range(io.cdap.cdap.spi.data.table.field.Range) ProgramId(io.cdap.cdap.proto.id.ProgramId) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

Range (io.cdap.cdap.spi.data.table.field.Range)46 StructuredRow (io.cdap.cdap.spi.data.StructuredRow)28 ArrayList (java.util.ArrayList)28 Field (io.cdap.cdap.spi.data.table.field.Field)24 StructuredTable (io.cdap.cdap.spi.data.StructuredTable)18 HashSet (java.util.HashSet)12 LinkedHashSet (java.util.LinkedHashSet)12 Set (java.util.Set)12 IOException (java.io.IOException)10 Collection (java.util.Collection)10 LinkedHashMap (java.util.LinkedHashMap)10 ArtifactRange (io.cdap.cdap.api.artifact.ArtifactRange)8 Map (java.util.Map)8 Nullable (javax.annotation.Nullable)8 VisibleForTesting (com.google.common.annotations.VisibleForTesting)6 ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)6 CloseableIterator (io.cdap.cdap.api.dataset.lib.CloseableIterator)6 Fields (io.cdap.cdap.spi.data.table.field.Fields)6 Collections (java.util.Collections)6 List (java.util.List)6