Search in sources :

Example 36 with StructuredRow

use of io.cdap.cdap.spi.data.StructuredRow in project cdap by caskdata.

the class AbstractCheckpointManager method getCheckpoint.

@Override
public Map<Integer, Checkpoint<T>> getCheckpoint(Set<Integer> partitions) throws IOException {
    return TransactionRunners.run(transactionRunner, context -> {
        Map<Integer, Checkpoint<T>> checkpoints = new HashMap<>();
        StructuredTable table = context.getTable(StoreDefinition.LogCheckpointStore.LOG_CHECKPOINT_TABLE);
        for (int partition : partitions) {
            Optional<StructuredRow> optionalRow = table.read(getKeyFields(rowKeyPrefix, partition));
            StructuredRow row = optionalRow.orElse(null);
            checkpoints.put(partition, fromRow(row));
        }
        return checkpoints;
    }, IOException.class);
}
Also used : HashMap(java.util.HashMap) StructuredTable(io.cdap.cdap.spi.data.StructuredTable) StructuredRow(io.cdap.cdap.spi.data.StructuredRow)

Example 37 with StructuredRow

use of io.cdap.cdap.spi.data.StructuredRow in project cdap by caskdata.

the class AbstractCheckpointManager method getCheckpoint.

@Override
public Checkpoint<T> getCheckpoint(int partition) throws IOException {
    Checkpoint<T> checkpoint = TransactionRunners.run(transactionRunner, context -> {
        StructuredTable table = context.getTable(StoreDefinition.LogCheckpointStore.LOG_CHECKPOINT_TABLE);
        Optional<StructuredRow> optionalRow = table.read(getKeyFields(rowKeyPrefix, partition));
        StructuredRow row = optionalRow.orElse(null);
        return fromRow(row);
    }, IOException.class);
    LOG.trace("Read checkpoint {} for partition {}", checkpoint, partition);
    return checkpoint;
}
Also used : StructuredTable(io.cdap.cdap.spi.data.StructuredTable) StructuredRow(io.cdap.cdap.spi.data.StructuredRow)

Example 38 with StructuredRow

use of io.cdap.cdap.spi.data.StructuredRow in project cdap by caskdata.

the class FileMetaDataReader method getFiles.

private List<LogLocation> getFiles(StructuredTable metaTable, LogPathIdentifier logPathIdentifier, long endTimestampMs) throws IOException {
    // create scanner with
    // start rowkey prefix:context:event-time(0):create-time(0)
    // end rowkey  prefix:context:event-time(endTimestamp):0(create-time doesn't matter for get files)
    // add these files to the list
    List<LogLocation> files = new ArrayList<>();
    Range scanRange = Range.create(getKeyFields(logPathIdentifier.getRowkey(), 0L, 0L), Range.Bound.INCLUSIVE, getPartialKey(logPathIdentifier.getRowkey(), endTimestampMs), Range.Bound.INCLUSIVE);
    try (CloseableIterator<StructuredRow> iter = metaTable.scan(scanRange, Integer.MAX_VALUE)) {
        while (iter.hasNext()) {
            StructuredRow row = iter.next();
            files.add(fromRow(row, logPathIdentifier.getNamespaceId()));
        }
    }
    return files;
}
Also used : LogLocation(io.cdap.cdap.logging.write.LogLocation) ArrayList(java.util.ArrayList) StructuredRow(io.cdap.cdap.spi.data.StructuredRow) Range(io.cdap.cdap.spi.data.table.field.Range)

Example 39 with StructuredRow

use of io.cdap.cdap.spi.data.StructuredRow in project cdap by caskdata.

the class FileMetadataCleaner method scanFilesToDelete.

@Nullable
@SuppressWarnings("ConstantConditions")
private Range scanFilesToDelete(StructuredTable table, int fileCleanupBatchSize, long tillTime, List<DeletedEntry> toDelete, AtomicReference<Range> range) throws IOException {
    try (CloseableIterator<StructuredRow> iter = table.scan(range.get(), fileCleanupBatchSize)) {
        while (iter.hasNext()) {
            if (toDelete.size() >= fileCleanupBatchSize) {
                return null;
            }
            StructuredRow row = iter.next();
            long creationTime = row.getLong(StoreDefinition.LogFileMetaStore.CREATION_TIME_FIELD);
            if (creationTime <= tillTime) {
                // expired - can be deleted
                toDelete.add(new DeletedEntry(row.getString(StoreDefinition.LogFileMetaStore.LOGGING_CONTEXT_FIELD), row.getLong(StoreDefinition.LogFileMetaStore.EVENT_TIME_FIELD), row.getLong(StoreDefinition.LogFileMetaStore.CREATION_TIME_FIELD), row.getString(StoreDefinition.LogFileMetaStore.FILE_FIELD)));
            } else {
                // return range to skip this logging context and move to next one.
                return Range.from(ImmutableList.of(Fields.stringField(StoreDefinition.LogFileMetaStore.LOGGING_CONTEXT_FIELD, row.getString(StoreDefinition.LogFileMetaStore.LOGGING_CONTEXT_FIELD))), Range.Bound.EXCLUSIVE);
            }
        }
        // if there are no more files to delete, return next range as null.
        return null;
    }
}
Also used : StructuredRow(io.cdap.cdap.spi.data.StructuredRow) Nullable(javax.annotation.Nullable)

Example 40 with StructuredRow

use of io.cdap.cdap.spi.data.StructuredRow in project cdap by cdapio.

the class CapabilityStatusStore method checkAllEnabled.

@Override
public void checkAllEnabled(Collection<String> capabilities) throws IOException, CapabilityNotAvailableException {
    List<List<Field<?>>> multiKeys = new ArrayList<>();
    capabilities.forEach(capability -> multiKeys.add(Collections.singletonList(Fields.stringField(StoreDefinition.CapabilitiesStore.NAME_FIELD, capability))));
    Map<String, String> capabilityMap = TransactionRunners.run(transactionRunner, context -> {
        StructuredTable capabilityTable = context.getTable(StoreDefinition.CapabilitiesStore.CAPABILITIES);
        return capabilityTable.multiRead(multiKeys).stream().collect(Collectors.toMap(structuredRow -> structuredRow.getString(StoreDefinition.CapabilitiesStore.NAME_FIELD), structuredRow -> structuredRow.getString(StoreDefinition.CapabilitiesStore.STATUS_FIELD)));
    }, IOException.class);
    for (String capability : capabilities) {
        if (!capabilityMap.containsKey(capability) || CapabilityStatus.valueOf(capabilityMap.get(capability).toUpperCase()) != CapabilityStatus.ENABLED) {
            throw new CapabilityNotAvailableException(capability);
        }
    }
}
Also used : TransactionRunners(io.cdap.cdap.spi.data.transaction.TransactionRunners) StoreDefinition(io.cdap.cdap.store.StoreDefinition) Inject(com.google.inject.Inject) StructuredRow(io.cdap.cdap.spi.data.StructuredRow) Collection(java.util.Collection) Fields(io.cdap.cdap.spi.data.table.field.Fields) IOException(java.io.IOException) HashMap(java.util.HashMap) CloseableIterator(io.cdap.cdap.api.dataset.lib.CloseableIterator) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) Gson(com.google.gson.Gson) StructuredTable(io.cdap.cdap.spi.data.StructuredTable) Range(io.cdap.cdap.spi.data.table.field.Range) Map(java.util.Map) Field(io.cdap.cdap.spi.data.table.field.Field) TransactionRunner(io.cdap.cdap.spi.data.transaction.TransactionRunner) Collections(java.util.Collections) StructuredTable(io.cdap.cdap.spi.data.StructuredTable) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

StructuredRow (io.cdap.cdap.spi.data.StructuredRow)142 StructuredTable (io.cdap.cdap.spi.data.StructuredTable)68 Field (io.cdap.cdap.spi.data.table.field.Field)66 ArrayList (java.util.ArrayList)54 Range (io.cdap.cdap.spi.data.table.field.Range)36 HashSet (java.util.HashSet)28 IOException (java.io.IOException)22 HashMap (java.util.HashMap)22 LinkedHashSet (java.util.LinkedHashSet)22 List (java.util.List)20 LinkedHashMap (java.util.LinkedHashMap)18 Map (java.util.Map)18 ArtifactNotFoundException (io.cdap.cdap.common.ArtifactNotFoundException)16 Collection (java.util.Collection)16 Set (java.util.Set)16 Nullable (javax.annotation.Nullable)16 ImmutableList (com.google.common.collect.ImmutableList)14 CloseableIterator (io.cdap.cdap.api.dataset.lib.CloseableIterator)14 TableNotFoundException (io.cdap.cdap.spi.data.TableNotFoundException)14 Fields (io.cdap.cdap.spi.data.table.field.Fields)14