use of com.google.common.cache.LoadingCache in project presto by prestodb.
the class HivePageSourceProvider method createSelectivePageSource.
private static Optional<ConnectorPageSource> createSelectivePageSource(Set<HiveSelectivePageSourceFactory> selectivePageSourceFactories, Configuration configuration, ConnectorSession session, HiveSplit split, HiveTableLayoutHandle layout, List<HiveColumnHandle> columns, DateTimeZone hiveStorageTimeZone, TypeManager typeManager, LoadingCache<RowExpressionCacheKey, RowExpression> rowExpressionCache, SplitContext splitContext, Optional<EncryptionInformation> encryptionInformation) {
Set<HiveColumnHandle> interimColumns = ImmutableSet.<HiveColumnHandle>builder().addAll(layout.getPredicateColumns().values()).addAll(split.getBucketConversion().map(BucketConversion::getBucketColumnHandles).orElse(ImmutableList.of())).build();
Set<String> columnNames = columns.stream().map(HiveColumnHandle::getName).collect(toImmutableSet());
List<HiveColumnHandle> allColumns = ImmutableList.<HiveColumnHandle>builder().addAll(columns).addAll(interimColumns.stream().filter(column -> !columnNames.contains(column.getName())).collect(toImmutableList())).build();
Path path = new Path(split.getPath());
List<ColumnMapping> columnMappings = ColumnMapping.buildColumnMappings(split.getPartitionKeys(), allColumns, ImmutableList.of(), split.getTableToPartitionMapping(), path, split.getTableBucketNumber(), split.getFileSize(), split.getFileModifiedTime());
Optional<BucketAdaptation> bucketAdaptation = split.getBucketConversion().map(conversion -> toBucketAdaptation(conversion, columnMappings, split.getTableBucketNumber(), mapping -> mapping.getHiveColumnHandle().getHiveColumnIndex()));
Map<Integer, String> prefilledValues = columnMappings.stream().filter(mapping -> mapping.getKind() == ColumnMappingKind.PREFILLED).collect(toImmutableMap(mapping -> mapping.getHiveColumnHandle().getHiveColumnIndex(), ColumnMapping::getPrefilledValue));
Map<Integer, HiveCoercer> coercers = columnMappings.stream().filter(mapping -> mapping.getCoercionFrom().isPresent()).collect(toImmutableMap(mapping -> mapping.getHiveColumnHandle().getHiveColumnIndex(), mapping -> createCoercer(typeManager, mapping.getCoercionFrom().get(), mapping.getHiveColumnHandle().getHiveType())));
List<Integer> outputColumns = columns.stream().map(HiveColumnHandle::getHiveColumnIndex).collect(toImmutableList());
RowExpression optimizedRemainingPredicate = rowExpressionCache.getUnchecked(new RowExpressionCacheKey(layout.getRemainingPredicate(), session));
if (shouldSkipBucket(layout, split, splitContext)) {
return Optional.of(new HiveEmptySplitPageSource());
}
if (shouldSkipPartition(typeManager, layout, hiveStorageTimeZone, split, splitContext)) {
return Optional.of(new HiveEmptySplitPageSource());
}
CacheQuota cacheQuota = generateCacheQuota(split);
for (HiveSelectivePageSourceFactory pageSourceFactory : selectivePageSourceFactories) {
Optional<? extends ConnectorPageSource> pageSource = pageSourceFactory.createPageSource(configuration, session, path, split.getStart(), split.getLength(), split.getFileSize(), split.getStorage(), toColumnHandles(columnMappings, true), prefilledValues, coercers, bucketAdaptation, outputColumns, splitContext.getDynamicFilterPredicate().map(filter -> filter.transform(handle -> new Subfield(((HiveColumnHandle) handle).getName())).intersect(layout.getDomainPredicate())).orElse(layout.getDomainPredicate()), optimizedRemainingPredicate, hiveStorageTimeZone, new HiveFileContext(splitContext.isCacheable(), cacheQuota, split.getExtraFileInfo().map(BinaryExtraHiveFileInfo::new), Optional.of(split.getFileSize()), split.getFileModifiedTime(), HiveSessionProperties.isVerboseRuntimeStatsEnabled(session)), encryptionInformation);
if (pageSource.isPresent()) {
return Optional.of(pageSource.get());
}
}
return Optional.empty();
}
use of com.google.common.cache.LoadingCache in project buck by facebook.
the class PrebuiltCxxLibraryDescription method createBuildRule.
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, final BuildRuleParams params, final BuildRuleResolver ruleResolver, final A args) throws NoSuchBuildTargetException {
// See if we're building a particular "type" of this library, and if so, extract
// it as an enum.
Optional<Map.Entry<Flavor, Type>> type = LIBRARY_TYPE.getFlavorAndValue(params.getBuildTarget());
Optional<Map.Entry<Flavor, CxxPlatform>> platform = cxxPlatforms.getFlavorAndValue(params.getBuildTarget());
Optional<ImmutableMap<BuildTarget, Version>> selectedVersions = targetGraph.get(params.getBuildTarget()).getSelectedVersions();
final Optional<String> versionSubdir = selectedVersions.isPresent() && args.versionedSubDir.isPresent() ? Optional.of(args.versionedSubDir.get().getOnlyMatchingValue(selectedVersions.get())) : Optional.empty();
// pre-existing static lib, which we do here.
if (type.isPresent()) {
Preconditions.checkState(platform.isPresent());
BuildTarget baseTarget = params.getBuildTarget().withoutFlavors(type.get().getKey(), platform.get().getKey());
if (type.get().getValue() == Type.EXPORTED_HEADERS) {
return createExportedHeaderSymlinkTreeBuildRule(params, ruleResolver, platform.get().getValue(), args);
} else if (type.get().getValue() == Type.SHARED) {
return createSharedLibraryBuildRule(params, ruleResolver, platform.get().getValue(), selectedVersions, args);
} else if (type.get().getValue() == Type.SHARED_INTERFACE) {
return createSharedLibraryInterface(baseTarget, params, ruleResolver, platform.get().getValue(), versionSubdir, args);
}
}
if (selectedVersions.isPresent() && args.versionedSubDir.isPresent()) {
ImmutableList<String> versionSubDirs = args.versionedSubDir.orElse(VersionMatchedCollection.<String>of()).getMatchingValues(selectedVersions.get());
if (versionSubDirs.size() != 1) {
throw new HumanReadableException("%s: could not get a single version sub dir: %s, %s, %s", params.getBuildTarget(), args.versionedSubDir, versionSubDirs, selectedVersions);
}
}
// Otherwise, we return the generic placeholder of this library, that dependents can use
// get the real build rules via querying the action graph.
final SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(ruleResolver));
final boolean headerOnly = args.headerOnly.orElse(false);
final boolean forceStatic = args.forceStatic.orElse(false);
return new PrebuiltCxxLibrary(params) {
private final Map<Pair<Flavor, Linker.LinkableDepType>, NativeLinkableInput> nativeLinkableCache = new HashMap<>();
private final LoadingCache<CxxPreprocessables.CxxPreprocessorInputCacheKey, ImmutableMap<BuildTarget, CxxPreprocessorInput>> transitiveCxxPreprocessorInputCache = CxxPreprocessables.getTransitiveCxxPreprocessorInputCache(this);
private boolean hasHeaders(CxxPlatform cxxPlatform) {
if (!args.exportedHeaders.isEmpty()) {
return true;
}
for (SourceList sourceList : args.exportedPlatformHeaders.getMatchingValues(cxxPlatform.getFlavor().toString())) {
if (!sourceList.isEmpty()) {
return true;
}
}
return false;
}
private ImmutableListMultimap<CxxSource.Type, String> getExportedPreprocessorFlags(CxxPlatform cxxPlatform) {
return CxxFlags.getLanguageFlags(args.exportedPreprocessorFlags, args.exportedPlatformPreprocessorFlags, args.exportedLangPreprocessorFlags, cxxPlatform);
}
@Override
public ImmutableList<String> getExportedLinkerFlags(CxxPlatform cxxPlatform) {
return CxxFlags.getFlagsWithPlatformMacroExpansion(args.exportedLinkerFlags, args.exportedPlatformLinkerFlags, cxxPlatform);
}
private String getSoname(CxxPlatform cxxPlatform) {
return PrebuiltCxxLibraryDescription.getSoname(getBuildTarget(), params.getCellRoots(), ruleResolver, cxxPlatform, args.soname, args.libName);
}
private boolean isPlatformSupported(CxxPlatform cxxPlatform) {
return !args.supportedPlatformsRegex.isPresent() || args.supportedPlatformsRegex.get().matcher(cxxPlatform.getFlavor().toString()).find();
}
/**
* Makes sure all build rules needed to produce the shared library are added to the action
* graph.
*
* @return the {@link SourcePath} representing the actual shared library.
*/
private SourcePath requireSharedLibrary(CxxPlatform cxxPlatform, boolean link) throws NoSuchBuildTargetException {
if (link && args.supportsSharedLibraryInterface && cxxPlatform.getSharedLibraryInterfaceFactory().isPresent()) {
BuildTarget target = params.getBuildTarget().withAppendedFlavors(cxxPlatform.getFlavor(), Type.SHARED_INTERFACE.getFlavor());
BuildRule rule = ruleResolver.requireRule(target);
return Preconditions.checkNotNull(rule.getSourcePathToOutput());
}
return PrebuiltCxxLibraryDescription.this.requireSharedLibrary(params.getBuildTarget(), ruleResolver, pathResolver, params.getCellRoots(), params.getProjectFilesystem(), cxxPlatform, versionSubdir, args);
}
/**
* @return the {@link Optional} containing a {@link SourcePath} representing the actual
* static PIC library.
*/
private Optional<SourcePath> getStaticPicLibrary(CxxPlatform cxxPlatform) {
SourcePath staticPicLibraryPath = PrebuiltCxxLibraryDescription.getStaticPicLibraryPath(getBuildTarget(), params.getCellRoots(), params.getProjectFilesystem(), ruleResolver, cxxPlatform, versionSubdir, args.libDir, args.libName);
if (params.getProjectFilesystem().exists(pathResolver.getAbsolutePath(staticPicLibraryPath))) {
return Optional.of(staticPicLibraryPath);
}
// If a specific static-pic variant isn't available, then just use the static variant.
SourcePath staticLibraryPath = PrebuiltCxxLibraryDescription.getStaticLibraryPath(getBuildTarget(), params.getCellRoots(), getProjectFilesystem(), ruleResolver, cxxPlatform, versionSubdir, args.libDir, args.libName);
if (params.getProjectFilesystem().exists(pathResolver.getAbsolutePath(staticLibraryPath))) {
return Optional.of(staticLibraryPath);
}
return Optional.empty();
}
@Override
public Iterable<? extends CxxPreprocessorDep> getCxxPreprocessorDeps(CxxPlatform cxxPlatform) {
if (!isPlatformSupported(cxxPlatform)) {
return ImmutableList.of();
}
return FluentIterable.from(getDeps()).filter(CxxPreprocessorDep.class);
}
@Override
public CxxPreprocessorInput getCxxPreprocessorInput(final CxxPlatform cxxPlatform, HeaderVisibility headerVisibility) throws NoSuchBuildTargetException {
CxxPreprocessorInput.Builder builder = CxxPreprocessorInput.builder();
switch(headerVisibility) {
case PUBLIC:
if (hasHeaders(cxxPlatform)) {
CxxPreprocessables.addHeaderSymlinkTree(builder, getBuildTarget(), ruleResolver, cxxPlatform, headerVisibility, CxxPreprocessables.IncludeType.SYSTEM);
}
builder.putAllPreprocessorFlags(Preconditions.checkNotNull(getExportedPreprocessorFlags(cxxPlatform)));
builder.addAllFrameworks(args.frameworks);
final Iterable<SourcePath> includePaths = args.includeDirs.stream().map(input -> PrebuiltCxxLibraryDescription.getApplicableSourcePath(params.getBuildTarget(), params.getCellRoots(), params.getProjectFilesystem(), ruleResolver, cxxPlatform, versionSubdir, input, Optional.empty())).collect(MoreCollectors.toImmutableList());
for (SourcePath includePath : includePaths) {
builder.addIncludes(CxxHeadersDir.of(CxxPreprocessables.IncludeType.SYSTEM, includePath));
}
return builder.build();
case PRIVATE:
return builder.build();
}
// want the compiler to warn if someone modifies the HeaderVisibility enum.
throw new RuntimeException("Invalid header visibility: " + headerVisibility);
}
@Override
public Optional<HeaderSymlinkTree> getExportedHeaderSymlinkTree(CxxPlatform cxxPlatform) {
if (hasHeaders(cxxPlatform)) {
return Optional.of(CxxPreprocessables.requireHeaderSymlinkTreeForLibraryTarget(ruleResolver, getBuildTarget(), cxxPlatform.getFlavor()));
} else {
return Optional.empty();
}
}
@Override
public ImmutableMap<BuildTarget, CxxPreprocessorInput> getTransitiveCxxPreprocessorInput(CxxPlatform cxxPlatform, HeaderVisibility headerVisibility) throws NoSuchBuildTargetException {
return transitiveCxxPreprocessorInputCache.getUnchecked(ImmutableCxxPreprocessorInputCacheKey.of(cxxPlatform, headerVisibility));
}
@Override
public Iterable<NativeLinkable> getNativeLinkableDeps() {
return getDeclaredDeps().stream().filter(r -> r instanceof NativeLinkable).map(r -> (NativeLinkable) r).collect(MoreCollectors.toImmutableList());
}
@Override
public Iterable<NativeLinkable> getNativeLinkableDepsForPlatform(CxxPlatform cxxPlatform) {
if (!isPlatformSupported(cxxPlatform)) {
return ImmutableList.of();
}
return getNativeLinkableDeps();
}
@Override
public Iterable<? extends NativeLinkable> getNativeLinkableExportedDeps() {
return args.exportedDeps.stream().map(ruleResolver::getRule).filter(r -> r instanceof NativeLinkable).map(r -> (NativeLinkable) r).collect(MoreCollectors.toImmutableList());
}
@Override
public Iterable<? extends NativeLinkable> getNativeLinkableExportedDepsForPlatform(CxxPlatform cxxPlatform) {
if (!isPlatformSupported(cxxPlatform)) {
return ImmutableList.of();
}
return getNativeLinkableExportedDeps();
}
private NativeLinkableInput getNativeLinkableInputUncached(CxxPlatform cxxPlatform, Linker.LinkableDepType type) throws NoSuchBuildTargetException {
if (!isPlatformSupported(cxxPlatform)) {
return NativeLinkableInput.of();
}
// Build the library path and linker arguments that we pass through the
// {@link NativeLinkable} interface for linking.
ImmutableList.Builder<com.facebook.buck.rules.args.Arg> linkerArgsBuilder = ImmutableList.builder();
linkerArgsBuilder.addAll(StringArg.from(Preconditions.checkNotNull(getExportedLinkerFlags(cxxPlatform))));
if (!headerOnly) {
if (type == Linker.LinkableDepType.SHARED) {
Preconditions.checkState(getPreferredLinkage(cxxPlatform) != Linkage.STATIC);
final SourcePath sharedLibrary = requireSharedLibrary(cxxPlatform, true);
if (args.linkWithoutSoname) {
if (!(sharedLibrary instanceof PathSourcePath)) {
throw new HumanReadableException("%s: can only link prebuilt DSOs without sonames", getBuildTarget());
}
linkerArgsBuilder.add(new RelativeLinkArg((PathSourcePath) sharedLibrary));
} else {
linkerArgsBuilder.add(SourcePathArg.of(requireSharedLibrary(cxxPlatform, true)));
}
} else {
Preconditions.checkState(getPreferredLinkage(cxxPlatform) != Linkage.SHARED);
SourcePath staticLibraryPath = type == Linker.LinkableDepType.STATIC_PIC ? getStaticPicLibrary(cxxPlatform).get() : PrebuiltCxxLibraryDescription.getStaticLibraryPath(getBuildTarget(), params.getCellRoots(), params.getProjectFilesystem(), ruleResolver, cxxPlatform, versionSubdir, args.libDir, args.libName);
SourcePathArg staticLibrary = SourcePathArg.of(staticLibraryPath);
if (args.linkWhole) {
Linker linker = cxxPlatform.getLd().resolve(ruleResolver);
linkerArgsBuilder.addAll(linker.linkWhole(staticLibrary));
} else {
linkerArgsBuilder.add(FileListableLinkerInputArg.withSourcePathArg(staticLibrary));
}
}
}
final ImmutableList<com.facebook.buck.rules.args.Arg> linkerArgs = linkerArgsBuilder.build();
return NativeLinkableInput.of(linkerArgs, args.frameworks, args.libraries);
}
@Override
public NativeLinkableInput getNativeLinkableInput(CxxPlatform cxxPlatform, Linker.LinkableDepType type) throws NoSuchBuildTargetException {
Pair<Flavor, Linker.LinkableDepType> key = new Pair<>(cxxPlatform.getFlavor(), type);
NativeLinkableInput input = nativeLinkableCache.get(key);
if (input == null) {
input = getNativeLinkableInputUncached(cxxPlatform, type);
nativeLinkableCache.put(key, input);
}
return input;
}
@Override
public NativeLinkable.Linkage getPreferredLinkage(CxxPlatform cxxPlatform) {
if (headerOnly) {
return Linkage.ANY;
}
if (forceStatic) {
return Linkage.STATIC;
}
if (args.provided || !getStaticPicLibrary(cxxPlatform).isPresent()) {
return Linkage.SHARED;
}
return Linkage.ANY;
}
@Override
public Iterable<AndroidPackageable> getRequiredPackageables() {
return AndroidPackageableCollector.getPackageableRules(params.getDeps());
}
@Override
public void addToCollector(AndroidPackageableCollector collector) {
if (args.canBeAsset) {
collector.addNativeLinkableAsset(this);
} else {
collector.addNativeLinkable(this);
}
}
@Override
public ImmutableMap<String, SourcePath> getSharedLibraries(CxxPlatform cxxPlatform) throws NoSuchBuildTargetException {
if (!isPlatformSupported(cxxPlatform)) {
return ImmutableMap.of();
}
String resolvedSoname = getSoname(cxxPlatform);
ImmutableMap.Builder<String, SourcePath> solibs = ImmutableMap.builder();
if (!headerOnly && !args.provided) {
SourcePath sharedLibrary = requireSharedLibrary(cxxPlatform, false);
solibs.put(resolvedSoname, sharedLibrary);
}
return solibs.build();
}
@Override
public Optional<NativeLinkTarget> getNativeLinkTarget(CxxPlatform cxxPlatform) {
if (getPreferredLinkage(cxxPlatform) == Linkage.SHARED) {
return Optional.empty();
}
return Optional.of(new NativeLinkTarget() {
@Override
public BuildTarget getBuildTarget() {
return params.getBuildTarget();
}
@Override
public NativeLinkTargetMode getNativeLinkTargetMode(CxxPlatform cxxPlatform) {
return NativeLinkTargetMode.library(getSoname(cxxPlatform));
}
@Override
public Iterable<? extends NativeLinkable> getNativeLinkTargetDeps(CxxPlatform cxxPlatform) {
return Iterables.concat(getNativeLinkableDepsForPlatform(cxxPlatform), getNativeLinkableExportedDepsForPlatform(cxxPlatform));
}
@Override
public NativeLinkableInput getNativeLinkTargetInput(CxxPlatform cxxPlatform) throws NoSuchBuildTargetException {
return NativeLinkableInput.builder().addAllArgs(StringArg.from(getExportedLinkerFlags(cxxPlatform))).addAllArgs(cxxPlatform.getLd().resolve(ruleResolver).linkWhole(SourcePathArg.of(getStaticPicLibrary(cxxPlatform).get()))).build();
}
@Override
public Optional<Path> getNativeLinkTargetOutputPath(CxxPlatform cxxPlatform) {
return Optional.empty();
}
});
}
};
}
use of com.google.common.cache.LoadingCache in project hadoop by apache.
the class TestKMS method testKMSProviderCaching.
@Test
public void testKMSProviderCaching() throws Exception {
Configuration conf = new Configuration();
File confDir = getTestDir();
conf = createBaseKMSConf(confDir, conf);
conf.set(KeyAuthorizationKeyProvider.KEY_ACL + "k1.ALL", "*");
writeConf(confDir, conf);
runServer(null, null, confDir, new KMSCallable<Void>() {
@Override
public Void call() throws Exception {
final String keyName = "k1";
final String mockVersionName = "mock";
final Configuration conf = new Configuration();
final URI uri = createKMSUri(getKMSUrl());
KMSClientProvider kmscp = createKMSClientProvider(uri, conf);
// get the reference to the internal cache, to test invalidation.
ValueQueue vq = (ValueQueue) Whitebox.getInternalState(kmscp, "encKeyVersionQueue");
LoadingCache<String, LinkedBlockingQueue<EncryptedKeyVersion>> kq = ((LoadingCache<String, LinkedBlockingQueue<EncryptedKeyVersion>>) Whitebox.getInternalState(vq, "keyQueues"));
EncryptedKeyVersion mockEKV = Mockito.mock(EncryptedKeyVersion.class);
when(mockEKV.getEncryptionKeyName()).thenReturn(keyName);
when(mockEKV.getEncryptionKeyVersionName()).thenReturn(mockVersionName);
// createKey()
KeyProvider.Options options = new KeyProvider.Options(conf);
options.setCipher("AES/CTR/NoPadding");
options.setBitLength(128);
options.setDescription("l1");
KeyProvider.KeyVersion kv0 = kmscp.createKey(keyName, options);
assertNotNull(kv0.getVersionName());
assertEquals("Default key version name is incorrect.", "k1@0", kmscp.generateEncryptedKey(keyName).getEncryptionKeyVersionName());
kmscp.invalidateCache(keyName);
kq.get(keyName).put(mockEKV);
assertEquals("Key version incorrect after invalidating cache + putting" + " mock key.", mockVersionName, kmscp.generateEncryptedKey(keyName).getEncryptionKeyVersionName());
// test new version is returned after invalidation.
for (int i = 0; i < 100; ++i) {
kq.get(keyName).put(mockEKV);
kmscp.invalidateCache(keyName);
assertEquals("Cache invalidation guarantee failed.", "k1@0", kmscp.generateEncryptedKey(keyName).getEncryptionKeyVersionName());
}
return null;
}
});
}
use of com.google.common.cache.LoadingCache in project molgenis by molgenis.
the class L2Cache method get.
/**
* Retrieves an entity from the cache or the underlying repository.
*
* @param repository the underlying repository
* @param id the ID of the entity to retrieve
* @return the retrieved Entity, or null if the entity is not present.
* @throws com.google.common.util.concurrent.UncheckedExecutionException if the repository throws an error when
* loading the entity
*/
public Entity get(Repository<Entity> repository, Object id) {
LoadingCache<Object, Optional<Map<String, Object>>> cache = getEntityCache(repository);
EntityType entityType = repository.getEntityType();
return cache.getUnchecked(id).map(e -> entityHydration.hydrate(e, entityType)).orElse(null);
}
use of com.google.common.cache.LoadingCache in project cdap by caskdata.
the class FlowletProcessDriver method processMethodCallback.
private <T> ProcessMethodCallback processMethodCallback(final PriorityQueue<FlowletProcessEntry<?>> processQueue, final FlowletProcessEntry<T> processEntry, final InputDatum<T> input) {
// If it is generator flowlet, processCount is 1.
final int processedCount = processEntry.getProcessSpec().getProcessMethod().needsInput() ? input.size() : 1;
return new ProcessMethodCallback() {
private final LoadingCache<String, MetricsContext> queueMetricsCollectors = CacheBuilder.newBuilder().expireAfterAccess(1, TimeUnit.HOURS).build(new CacheLoader<String, MetricsContext>() {
@Override
public MetricsContext load(String key) throws Exception {
return flowletContext.getProgramMetrics().childContext(Constants.Metrics.Tag.FLOWLET_QUEUE, key);
}
});
@Override
public void onSuccess(Object object, InputContext inputContext) {
try {
gaugeEventProcessed(input.getQueueName());
txCallback.onSuccess(object, inputContext);
} catch (Throwable t) {
LOG.error("Exception on onSuccess call: {}", flowletContext, t);
} finally {
enqueueEntry();
}
}
@Override
public void onFailure(Object inputObject, InputContext inputContext, FailureReason reason, InputAcknowledger inputAcknowledger) {
LOG.warn("Process failure: {}, {}, input: {}", flowletContext, reason.getMessage(), input, reason.getCause());
FailurePolicy failurePolicy;
try {
flowletContext.getProgramMetrics().increment("process.errors", 1);
failurePolicy = txCallback.onFailure(inputObject, inputContext, reason);
if (failurePolicy == null) {
failurePolicy = FailurePolicy.RETRY;
LOG.info("Callback returns null for failure policy. Default to {}.", failurePolicy);
}
} catch (Throwable t) {
LOG.error("Exception on onFailure call: {}", flowletContext, t);
failurePolicy = FailurePolicy.RETRY;
}
if (input.getRetry() >= processEntry.getProcessSpec().getProcessMethod().getMaxRetries()) {
LOG.info("Too many retries, ignores the input: {}", input);
failurePolicy = FailurePolicy.IGNORE;
}
if (failurePolicy == FailurePolicy.RETRY) {
FlowletProcessEntry retryEntry = processEntry.isRetry() ? processEntry : FlowletProcessEntry.create(processEntry.getProcessSpec(), new ProcessSpecification<>(new SingleItemQueueReader<>(input), processEntry.getProcessSpec().getProcessMethod(), null));
processQueue.offer(retryEntry);
} else if (failurePolicy == FailurePolicy.IGNORE) {
try {
gaugeEventProcessed(input.getQueueName());
inputAcknowledger.ack();
} catch (Throwable t) {
LOG.error("Fatal problem, fail to ack an input: {}", flowletContext, t);
} finally {
enqueueEntry();
}
}
}
private void enqueueEntry() {
processQueue.offer(processEntry.resetRetry());
}
private void gaugeEventProcessed(QueueName inputQueueName) {
if (processEntry.isTick()) {
flowletContext.getProgramMetrics().increment("process.ticks.processed", processedCount);
} else if (inputQueueName == null) {
flowletContext.getProgramMetrics().increment("process.events.processed", processedCount);
} else {
queueMetricsCollectors.getUnchecked(inputQueueName.getSimpleName()).increment("process.events.processed", processedCount);
}
}
};
}
Aggregations