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);
}
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();
}
}
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));
}
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);
}
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;
}
Aggregations