Search in sources :

Example 1 with TxRunnable

use of io.cdap.cdap.spi.data.transaction.TxRunnable in project cdap by caskdata.

the class MetadataSubscriberService method preProcess.

@Override
protected void preProcess() {
    if (didBackfill) {
        return;
    }
    if (backfillAttempts > 10) {
        LOG.info("Skipping attempt to back-fill plugin metadata after 10 failures.");
        return;
    }
    // Backfill plugin metadata
    backfillAttempts++;
    LOG.info("Starting back-fill process(attempt {}) for plugin metadata", backfillAttempts);
    boolean updateFailed = false;
    NamespaceStore namespaceStore = new DefaultNamespaceStore(this.transactionRunner);
    List<String> namespaces = namespaceStore.list().stream().map(NamespaceMeta::getName).collect(Collectors.toList());
    LOG.debug("Back-filling plugin metadata for {} namespaces", namespaces.size());
    for (String namespace : namespaces) {
        List<ApplicationMeta> apps = TransactionRunners.run(this.transactionRunner, context -> {
            AppMetadataStore appMetadataStore = AppMetadataStore.create(context);
            return appMetadataStore.getAllApplications(namespace);
        });
        LOG.debug("Back-filling plugin metadata for namespace '{}' with {} applications", namespace, apps.size());
        try {
            this.getPluginCounts(namespace, apps);
        } catch (IOException e) {
            updateFailed = true;
            LOG.warn("Failed to write plugin metadata updates for namespace '{}': {}", namespace, e);
        }
    }
    if (!updateFailed) {
        LOG.info("Successfully back-filled plugin metadata for {} namespaces.", namespaces.size());
        didBackfill = true;
        TransactionRunners.run(transactionRunner, (TxRunnable) context -> AppMetadataStore.create(context).persistSubscriberState(getTopicId().getTopic(), BACKFILL_SUBSCRIBER_NAME, "true"));
    }
}
Also used : ImmutablePair(io.cdap.cdap.common.utils.ImmutablePair) TransactionRunners(io.cdap.cdap.spi.data.transaction.TransactionRunners) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) RetryStrategies(io.cdap.cdap.common.service.RetryStrategies) UsageTable(io.cdap.cdap.data2.registry.UsageTable) GsonBuilder(com.google.gson.GsonBuilder) PluginId(io.cdap.cdap.proto.id.PluginId) DataAccessLineage(io.cdap.cdap.data2.metadata.writer.DataAccessLineage) EndPointField(io.cdap.cdap.data2.metadata.lineage.field.EndPointField) MetadataOperationTypeAdapter(io.cdap.cdap.data2.metadata.writer.MetadataOperationTypeAdapter) Gson(com.google.gson.Gson) InvalidMetadataException(io.cdap.cdap.common.InvalidMetadataException) Metadata(io.cdap.cdap.spi.metadata.Metadata) Map(java.util.Map) EntityType(io.cdap.cdap.proto.element.EntityType) MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) MetadataMutation(io.cdap.cdap.spi.metadata.MetadataMutation) MetadataMessage(io.cdap.cdap.data2.metadata.writer.MetadataMessage) BasicWorkflowToken(io.cdap.cdap.internal.app.runtime.workflow.BasicWorkflowToken) DefaultNamespaceStore(io.cdap.cdap.store.DefaultNamespaceStore) ImmutableMap(com.google.common.collect.ImmutableMap) ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) MessagingService(io.cdap.cdap.messaging.MessagingService) Set(java.util.Set) StructuredTableContext(io.cdap.cdap.spi.data.StructuredTableContext) Collectors(java.util.stream.Collectors) NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) List(java.util.List) MultiThreadMessagingContext(io.cdap.cdap.messaging.context.MultiThreadMessagingContext) MetadataScope(io.cdap.cdap.api.metadata.MetadataScope) MetadataOperation(io.cdap.cdap.data2.metadata.writer.MetadataOperation) TransactionRunner(io.cdap.cdap.spi.data.transaction.TransactionRunner) Constants(io.cdap.cdap.common.conf.Constants) MessagingContext(io.cdap.cdap.api.messaging.MessagingContext) TxCallable(io.cdap.cdap.spi.data.transaction.TxCallable) HashMap(java.util.HashMap) ApplicationMeta(io.cdap.cdap.internal.app.store.ApplicationMeta) EntityId(io.cdap.cdap.proto.id.EntityId) Function(java.util.function.Function) MetadataStorage(io.cdap.cdap.spi.metadata.MetadataStorage) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) NamespaceStore(io.cdap.cdap.store.NamespaceStore) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) DatasetUsage(io.cdap.cdap.data2.registry.DatasetUsage) EntityIdTypeAdapter(io.cdap.cdap.proto.codec.EntityIdTypeAdapter) LineageTable(io.cdap.cdap.data2.metadata.lineage.LineageTable) ScopedNameOfKind(io.cdap.cdap.spi.metadata.ScopedNameOfKind) Operation(io.cdap.cdap.api.lineage.field.Operation) Nullable(javax.annotation.Nullable) WorkflowNodeStateDetail(io.cdap.cdap.proto.WorkflowNodeStateDetail) AppMetadataStore(io.cdap.cdap.internal.app.store.AppMetadataStore) ProfileMetadataMessageProcessor(io.cdap.cdap.metadata.profile.ProfileMetadataMessageProcessor) FieldLineageTable(io.cdap.cdap.data2.metadata.lineage.field.FieldLineageTable) Logger(org.slf4j.Logger) Message(io.cdap.cdap.api.messaging.Message) Iterator(java.util.Iterator) ProgramId(io.cdap.cdap.proto.id.ProgramId) TxRunnable(io.cdap.cdap.spi.data.transaction.TxRunnable) TxConstants(org.apache.tephra.TxConstants) IOException(java.io.IOException) ConflictException(io.cdap.cdap.common.ConflictException) EndpointFieldDeserializer(io.cdap.cdap.data2.metadata.lineage.field.EndpointFieldDeserializer) AbstractMessagingSubscriberService(io.cdap.cdap.messaging.subscriber.AbstractMessagingSubscriberService) MetadataKind(io.cdap.cdap.spi.metadata.MetadataKind) OperationTypeAdapter(io.cdap.cdap.proto.codec.OperationTypeAdapter) TableNotFoundException(io.cdap.cdap.spi.data.TableNotFoundException) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) FieldLineageInfo(io.cdap.cdap.data2.metadata.lineage.field.FieldLineageInfo) MutationOptions(io.cdap.cdap.spi.metadata.MutationOptions) Collections(java.util.Collections) AppMetadataStore(io.cdap.cdap.internal.app.store.AppMetadataStore) DefaultNamespaceStore(io.cdap.cdap.store.DefaultNamespaceStore) NamespaceStore(io.cdap.cdap.store.NamespaceStore) DefaultNamespaceStore(io.cdap.cdap.store.DefaultNamespaceStore) IOException(java.io.IOException) ApplicationMeta(io.cdap.cdap.internal.app.store.ApplicationMeta)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 Inject (com.google.inject.Inject)1 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)1 Operation (io.cdap.cdap.api.lineage.field.Operation)1 Message (io.cdap.cdap.api.messaging.Message)1 MessagingContext (io.cdap.cdap.api.messaging.MessagingContext)1 MetadataEntity (io.cdap.cdap.api.metadata.MetadataEntity)1 MetadataScope (io.cdap.cdap.api.metadata.MetadataScope)1 MetricsCollectionService (io.cdap.cdap.api.metrics.MetricsCollectionService)1 ConflictException (io.cdap.cdap.common.ConflictException)1 InvalidMetadataException (io.cdap.cdap.common.InvalidMetadataException)1 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)1 Constants (io.cdap.cdap.common.conf.Constants)1 RetryStrategies (io.cdap.cdap.common.service.RetryStrategies)1 ImmutablePair (io.cdap.cdap.common.utils.ImmutablePair)1 LineageTable (io.cdap.cdap.data2.metadata.lineage.LineageTable)1 EndPointField (io.cdap.cdap.data2.metadata.lineage.field.EndPointField)1 EndpointFieldDeserializer (io.cdap.cdap.data2.metadata.lineage.field.EndpointFieldDeserializer)1