Search in sources :

Example 16 with NamespacedEntityId

use of co.cask.cdap.proto.id.NamespacedEntityId in project cdap by caskdata.

the class MetadataDataset method setMetadata.

@VisibleForTesting
void setMetadata(MetadataEntry metadataEntry, Set<Indexer> indexers) {
    NamespacedEntityId targetId = metadataEntry.getTargetId();
    write(targetId, metadataEntry, indexers);
}
Also used : NamespacedEntityId(co.cask.cdap.proto.id.NamespacedEntityId) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 17 with NamespacedEntityId

use of co.cask.cdap.proto.id.NamespacedEntityId in project cdap by caskdata.

the class MetadataDataset method rebuildIndexes.

/**
   * Rebuilds all the indexes in the {@link MetadataDataset} in batches.
   *
   * @param startRowKey the key of the row to start the scan for the current batch with
   * @param limit the batch size
   * @return the row key of the last row scanned in the current batch, {@code null} if there are no more rows to scan.
   */
@Nullable
public byte[] rebuildIndexes(@Nullable byte[] startRowKey, int limit) {
    // Now rebuild indexes for all values in the metadata dataset
    byte[] valueRowPrefix = MdsKey.getValueRowPrefix();
    // If startRow is null, start at the beginning, else start at the provided start row
    startRowKey = startRowKey == null ? valueRowPrefix : startRowKey;
    // stopRowKey will always be the last row key with the valueRowPrefix
    byte[] stopRowKey = Bytes.stopKeyForPrefix(valueRowPrefix);
    Row row;
    try (Scanner scanner = indexedTable.scan(startRowKey, stopRowKey)) {
        while ((limit > 0) && (row = scanner.next()) != null) {
            byte[] rowKey = row.getRow();
            String targetType = MdsKey.getTargetType(rowKey);
            NamespacedEntityId namespacedEntityId = MdsKey.getNamespacedIdFromKey(targetType, rowKey);
            String metadataKey = MdsKey.getMetadataKey(targetType, rowKey);
            Set<Indexer> indexers = getIndexersForKey(metadataKey);
            MetadataEntry metadataEntry = getMetadata(namespacedEntityId, metadataKey);
            if (metadataEntry == null) {
                LOG.warn("Found null metadata entry for a known metadata key {} for entity {} which has an index stored. " + "Ignoring.", metadataKey, namespacedEntityId);
                continue;
            }
            // storeIndexes deletes old indexes
            storeIndexes(namespacedEntityId, metadataKey, indexers, metadataEntry);
            limit--;
        }
        Row startRowForNextBatch = scanner.next();
        if (startRowForNextBatch == null) {
            return null;
        }
        return startRowForNextBatch.getRow();
    }
}
Also used : Scanner(co.cask.cdap.api.dataset.table.Scanner) NamespacedEntityId(co.cask.cdap.proto.id.NamespacedEntityId) ValueOnlyIndexer(co.cask.cdap.data2.metadata.indexer.ValueOnlyIndexer) DefaultValueIndexer(co.cask.cdap.data2.metadata.indexer.DefaultValueIndexer) InvertedValueIndexer(co.cask.cdap.data2.metadata.indexer.InvertedValueIndexer) SchemaIndexer(co.cask.cdap.data2.metadata.indexer.SchemaIndexer) Indexer(co.cask.cdap.data2.metadata.indexer.Indexer) InvertedTimeIndexer(co.cask.cdap.data2.metadata.indexer.InvertedTimeIndexer) Row(co.cask.cdap.api.dataset.table.Row) Nullable(javax.annotation.Nullable)

Example 18 with NamespacedEntityId

use of co.cask.cdap.proto.id.NamespacedEntityId in project cdap by caskdata.

the class MetadataDataset method convertRow.

@Nullable
private MetadataEntry convertRow(Row row) {
    byte[] rowKey = row.getRow();
    String targetType = MdsKey.getTargetType(rowKey);
    NamespacedEntityId namespacedEntityId = MdsKey.getNamespacedIdFromKey(targetType, rowKey);
    String key = MdsKey.getMetadataKey(targetType, rowKey);
    byte[] value = row.get(VALUE_COLUMN);
    if (key == null || value == null) {
        return null;
    }
    return new MetadataEntry(namespacedEntityId, key, Bytes.toString(value));
}
Also used : NamespacedEntityId(co.cask.cdap.proto.id.NamespacedEntityId) Nullable(javax.annotation.Nullable)

Example 19 with NamespacedEntityId

use of co.cask.cdap.proto.id.NamespacedEntityId in project cdap by caskdata.

the class MetadataDataset method parseRow.

// there may not be a MetadataEntry in the row or it may for a different targetType (entityFilter),
// so return an Optional
private Optional<MetadataEntry> parseRow(Row rowToProcess, String indexColumn, Set<EntityTypeSimpleName> entityFilter, boolean showHidden) {
    String rowValue = rowToProcess.getString(indexColumn);
    if (rowValue == null) {
        return Optional.absent();
    }
    final byte[] rowKey = rowToProcess.getRow();
    String targetType = MdsKey.getTargetType(rowKey);
    // Filter on target type if not set to include all types
    boolean includeAllTypes = entityFilter.isEmpty() || entityFilter.contains(EntityTypeSimpleName.ALL);
    if (!includeAllTypes && !entityFilter.contains(EntityTypeSimpleName.valueOfSerializedForm(targetType))) {
        return Optional.absent();
    }
    NamespacedEntityId targetId = MdsKey.getNamespacedIdFromKey(targetType, rowKey);
    // This is done to hide entities from Tracker. See: CDAP-7910
    if (!showHidden && targetId.getEntityName().startsWith("_")) {
        return Optional.absent();
    }
    String key = MdsKey.getMetadataKey(targetType, rowKey);
    MetadataEntry entry = getMetadata(targetId, key);
    return Optional.fromNullable(entry);
}
Also used : NamespacedEntityId(co.cask.cdap.proto.id.NamespacedEntityId)

Example 20 with NamespacedEntityId

use of co.cask.cdap.proto.id.NamespacedEntityId in project cdap by caskdata.

the class DefaultMetadataStore method fetchMetadata.

private Map<NamespacedEntityId, Metadata> fetchMetadata(final Set<NamespacedEntityId> namespacedEntityIds, MetadataScope scope) {
    Set<Metadata> metadataSet = execute(new TransactionExecutor.Function<MetadataDataset, Set<Metadata>>() {

        @Override
        public Set<Metadata> apply(MetadataDataset input) throws Exception {
            return input.getMetadata(namespacedEntityIds);
        }
    }, scope);
    Map<NamespacedEntityId, Metadata> metadataMap = new HashMap<>();
    for (Metadata m : metadataSet) {
        metadataMap.put(m.getEntityId(), m);
    }
    return metadataMap;
}
Also used : NamespacedEntityId(co.cask.cdap.proto.id.NamespacedEntityId) MetadataDataset(co.cask.cdap.data2.metadata.dataset.MetadataDataset) EnumSet(java.util.EnumSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) Metadata(co.cask.cdap.data2.metadata.dataset.Metadata) TransactionExecutor(org.apache.tephra.TransactionExecutor) BadRequestException(co.cask.cdap.common.BadRequestException) DatasetManagementException(co.cask.cdap.api.dataset.DatasetManagementException) IOException(java.io.IOException)

Aggregations

NamespacedEntityId (co.cask.cdap.proto.id.NamespacedEntityId)23 ProgramRunId (co.cask.cdap.proto.id.ProgramRunId)9 ProgramId (co.cask.cdap.proto.id.ProgramId)6 HashMap (java.util.HashMap)6 StreamId (co.cask.cdap.proto.id.StreamId)5 HashSet (java.util.HashSet)5 RunId (org.apache.twill.api.RunId)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 Row (co.cask.cdap.api.dataset.table.Row)3 Scanner (co.cask.cdap.api.dataset.table.Scanner)3 Metadata (co.cask.cdap.data2.metadata.dataset.Metadata)3 AuditMessage (co.cask.cdap.proto.audit.AuditMessage)3 DatasetId (co.cask.cdap.proto.id.DatasetId)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Collection (java.util.Collection)3 LinkedHashSet (java.util.LinkedHashSet)3 Test (org.junit.Test)3 MethodArgument (co.cask.cdap.common.internal.remote.MethodArgument)2 MDSKey (co.cask.cdap.data2.dataset2.lib.table.MDSKey)2