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