Search in sources :

Example 26 with ImmutableMultimap

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableMultimap in project error-prone by google.

the class WakelockReleasedDangerously method wakelockMayThrow.

/**
 * Whether the given WakeLock may throw an unexpected RuntimeException when released.
 *
 * <p>Returns true if: 1) the given WakeLock was acquired with timeout, and 2) the given WakeLock
 * is reference counted.
 */
private boolean wakelockMayThrow(Symbol wakelockSymbol, VisitorState state) {
    ClassTree enclosingClass = getTopLevelClass(state);
    ImmutableMultimap<String, MethodInvocationTree> map = methodCallsForSymbol(wakelockSymbol, enclosingClass);
    // Was acquired with timeout.
    return map.get("acquire").stream().anyMatch(m -> m.getArguments().size() == 1) && // Is reference counted, i.e., referenceCounted not explicitly set to false.
    map.get("setReferenceCounted").stream().noneMatch(m -> Boolean.FALSE.equals(constValue(m.getArguments().get(0), Boolean.class)));
}
Also used : MethodSymbol(com.sun.tools.javac.code.Symbol.MethodSymbol) ASTHelpers.getType(com.google.errorprone.util.ASTHelpers.getType) Matchers.instanceMethod(com.google.errorprone.matchers.Matchers.instanceMethod) VisitorState(com.google.errorprone.VisitorState) MethodInvocationTree(com.sun.source.tree.MethodInvocationTree) Kind(com.sun.source.tree.Tree.Kind) LambdaExpressionTree(com.sun.source.tree.LambdaExpressionTree) StandardTags(com.google.errorprone.BugPattern.StandardTags) CatchTree(com.sun.source.tree.CatchTree) BugPattern(com.google.errorprone.BugPattern) Category(com.google.errorprone.BugPattern.Category) Matcher(com.google.errorprone.matchers.Matcher) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Tree(com.sun.source.tree.Tree) ClassTree(com.sun.source.tree.ClassTree) MethodInvocationTreeMatcher(com.google.errorprone.bugpatterns.BugChecker.MethodInvocationTreeMatcher) IfTree(com.sun.source.tree.IfTree) UnionClassType(com.sun.tools.javac.code.Type.UnionClassType) ASTHelpers.getReceiver(com.google.errorprone.util.ASTHelpers.getReceiver) ExpressionTree(com.sun.source.tree.ExpressionTree) BugChecker(com.google.errorprone.bugpatterns.BugChecker) ASTHelpers.getSymbol(com.google.errorprone.util.ASTHelpers.getSymbol) Symbol(com.sun.tools.javac.code.Symbol) NO_MATCH(com.google.errorprone.matchers.Description.NO_MATCH) Streams(com.google.common.collect.Streams) ASTHelpers.constValue(com.google.errorprone.util.ASTHelpers.constValue) ASTHelpers.findEnclosingNode(com.google.errorprone.util.ASTHelpers.findEnclosingNode) BodyKind(com.sun.source.tree.LambdaExpressionTree.BodyKind) TreeScanner(com.sun.source.util.TreeScanner) Types(com.sun.tools.javac.code.Types) Description(com.google.errorprone.matchers.Description) MethodMatchers(com.google.errorprone.matchers.method.MethodMatchers) TryTree(com.sun.source.tree.TryTree) ProvidesFix(com.google.errorprone.BugPattern.ProvidesFix) SuggestedFix(com.google.errorprone.fixes.SuggestedFix) Builder(com.google.common.collect.ImmutableMultimap.Builder) SeverityLevel(com.google.errorprone.BugPattern.SeverityLevel) ASTHelpers(com.google.errorprone.util.ASTHelpers) Type(com.sun.tools.javac.code.Type) MethodInvocationTree(com.sun.source.tree.MethodInvocationTree) ClassTree(com.sun.source.tree.ClassTree)

Example 27 with ImmutableMultimap

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableMultimap in project presto by prestodb.

the class SourcePartitionedScheduler method assignSplits.

private Set<RemoteTask> assignSplits(Multimap<InternalNode, Split> splitAssignment, Multimap<InternalNode, Lifespan> noMoreSplitsNotification) {
    ImmutableSet.Builder<RemoteTask> newTasks = ImmutableSet.builder();
    ImmutableSet<InternalNode> nodes = ImmutableSet.<InternalNode>builder().addAll(splitAssignment.keySet()).addAll(noMoreSplitsNotification.keySet()).build();
    for (InternalNode node : nodes) {
        ImmutableMultimap<PlanNodeId, Split> splits = ImmutableMultimap.<PlanNodeId, Split>builder().putAll(partitionedNode, splitAssignment.get(node)).build();
        ImmutableMultimap.Builder<PlanNodeId, Lifespan> noMoreSplits = ImmutableMultimap.builder();
        if (noMoreSplitsNotification.containsKey(node)) {
            noMoreSplits.putAll(partitionedNode, noMoreSplitsNotification.get(node));
        }
        newTasks.addAll(stage.scheduleSplits(node, splits, noMoreSplits.build()));
    }
    return newTasks.build();
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ImmutableSet(com.google.common.collect.ImmutableSet) RemoteTask(com.facebook.presto.execution.RemoteTask) InternalNode(com.facebook.presto.metadata.InternalNode) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) EmptySplit(com.facebook.presto.split.EmptySplit) Split(com.facebook.presto.metadata.Split) Lifespan(com.facebook.presto.execution.Lifespan)

Example 28 with ImmutableMultimap

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableMultimap in project cassandra by apache.

the class NetworkTopologyStrategy method calculateNaturalReplicas.

/**
 * calculate endpoints in one pass through the tokens by tracking our progress in each DC.
 */
@Override
public EndpointsForRange calculateNaturalReplicas(Token searchToken, TokenMetadata tokenMetadata) {
    // we want to preserve insertion order so that the first added endpoint becomes primary
    ArrayList<Token> sortedTokens = tokenMetadata.sortedTokens();
    Token replicaEnd = TokenMetadata.firstToken(sortedTokens, searchToken);
    Token replicaStart = tokenMetadata.getPredecessor(replicaEnd);
    Range<Token> replicatedRange = new Range<>(replicaStart, replicaEnd);
    EndpointsForRange.Builder builder = new EndpointsForRange.Builder(replicatedRange);
    Set<Pair<String, String>> seenRacks = new HashSet<>();
    Topology topology = tokenMetadata.getTopology();
    // all endpoints in each DC, so we can check when we have exhausted all the members of a DC
    Multimap<String, InetAddressAndPort> allEndpoints = topology.getDatacenterEndpoints();
    // all racks in a DC so we can check when we have exhausted all racks in a DC
    Map<String, ImmutableMultimap<String, InetAddressAndPort>> racks = topology.getDatacenterRacks();
    assert !allEndpoints.isEmpty() && !racks.isEmpty() : "not aware of any cluster members";
    int dcsToFill = 0;
    Map<String, DatacenterEndpoints> dcs = new HashMap<>(datacenters.size() * 2);
    // Create a DatacenterEndpoints object for each non-empty DC.
    for (Map.Entry<String, ReplicationFactor> en : datacenters.entrySet()) {
        String dc = en.getKey();
        ReplicationFactor rf = en.getValue();
        int nodeCount = sizeOrZero(allEndpoints.get(dc));
        if (rf.allReplicas <= 0 || nodeCount <= 0)
            continue;
        DatacenterEndpoints dcEndpoints = new DatacenterEndpoints(rf, sizeOrZero(racks.get(dc)), nodeCount, builder, seenRacks);
        dcs.put(dc, dcEndpoints);
        ++dcsToFill;
    }
    Iterator<Token> tokenIter = TokenMetadata.ringIterator(sortedTokens, searchToken, false);
    while (dcsToFill > 0 && tokenIter.hasNext()) {
        Token next = tokenIter.next();
        InetAddressAndPort ep = tokenMetadata.getEndpoint(next);
        Pair<String, String> location = topology.getLocation(ep);
        DatacenterEndpoints dcEndpoints = dcs.get(location.left);
        if (dcEndpoints != null && dcEndpoints.addEndpointAndCheckIfDone(ep, location, replicatedRange))
            --dcsToFill;
    }
    return builder.build();
}
Also used : Token(org.apache.cassandra.dht.Token) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Pair(org.apache.cassandra.utils.Pair) Topology(org.apache.cassandra.locator.TokenMetadata.Topology) Range(org.apache.cassandra.dht.Range)

Example 29 with ImmutableMultimap

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableMultimap in project calcite by apache.

the class ScalarFunctionImpl method createAll.

/**
 * Creates {@link org.apache.calcite.schema.ScalarFunction} for each method in
 * a given class.
 */
public static ImmutableMultimap<String, ScalarFunction> createAll(Class<?> clazz) {
    final ImmutableMultimap.Builder<String, ScalarFunction> builder = ImmutableMultimap.builder();
    for (Method method : clazz.getMethods()) {
        if (method.getDeclaringClass() == Object.class) {
            continue;
        }
        if (!Modifier.isStatic(method.getModifiers()) && !classHasPublicZeroArgsConstructor(clazz)) {
            continue;
        }
        final ScalarFunction function = create(method);
        builder.put(method.getName(), function);
    }
    return builder.build();
}
Also used : ScalarFunction(org.apache.calcite.schema.ScalarFunction) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Method(java.lang.reflect.Method)

Example 30 with ImmutableMultimap

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableMultimap in project intellij by bazelbuild.

the class BlazeSyncTask method doSyncProject.

/**
 * @return true if sync successfully completed
 */
private SyncResult doSyncProject(BlazeContext context, @Nullable BlazeProjectData oldBlazeProjectData) {
    long syncStartTime = System.currentTimeMillis();
    if (!FileOperationProvider.getInstance().exists(workspaceRoot.directory())) {
        IssueOutput.error(String.format("Workspace '%s' doesn't exist.", workspaceRoot.directory())).submit(context);
        return SyncResult.FAILURE;
    }
    BlazeVcsHandler vcsHandler = BlazeVcsHandler.vcsHandlerForProject(project);
    if (vcsHandler == null) {
        IssueOutput.error("Could not find a VCS handler").submit(context);
        return SyncResult.FAILURE;
    }
    ListeningExecutorService executor = BlazeExecutor.getInstance().getExecutor();
    WorkspacePathResolverAndProjectView workspacePathResolverAndProjectView = computeWorkspacePathResolverAndProjectView(context, vcsHandler, executor);
    if (workspacePathResolverAndProjectView == null) {
        return SyncResult.FAILURE;
    }
    ProjectViewSet projectViewSet = workspacePathResolverAndProjectView.projectViewSet;
    List<String> syncFlags = BlazeFlags.blazeFlags(project, projectViewSet, BlazeCommandName.INFO, BlazeInvocationContext.Sync);
    syncStats.setSyncFlags(syncFlags);
    ListenableFuture<BlazeInfo> blazeInfoFuture = BlazeInfoRunner.getInstance().runBlazeInfo(context, importSettings.getBuildSystem(), Blaze.getBuildSystemProvider(project).getSyncBinaryPath(), workspaceRoot, syncFlags);
    ListenableFuture<WorkingSet> workingSetFuture = vcsHandler.getWorkingSet(project, context, workspaceRoot, executor);
    BlazeInfo blazeInfo = FutureUtil.waitForFuture(context, blazeInfoFuture).timed(Blaze.buildSystemName(project) + "Info", EventType.BlazeInvocation).withProgressMessage(String.format("Running %s info...", Blaze.buildSystemName(project))).onError(String.format("Could not run %s info", Blaze.buildSystemName(project))).run().result();
    if (blazeInfo == null) {
        return SyncResult.FAILURE;
    }
    BlazeVersionData blazeVersionData = BlazeVersionData.build(importSettings.getBuildSystem(), workspaceRoot, blazeInfo);
    if (!BuildSystemVersionChecker.verifyVersionSupported(context, blazeVersionData)) {
        return SyncResult.FAILURE;
    }
    WorkspacePathResolver workspacePathResolver = workspacePathResolverAndProjectView.workspacePathResolver;
    ArtifactLocationDecoder artifactLocationDecoder = new ArtifactLocationDecoderImpl(blazeInfo, workspacePathResolver);
    WorkspaceLanguageSettings workspaceLanguageSettings = LanguageSupport.createWorkspaceLanguageSettings(projectViewSet);
    syncStats.setLanguagesActive(new ArrayList<>(workspaceLanguageSettings.activeLanguages));
    syncStats.setWorkspaceType(workspaceLanguageSettings.getWorkspaceType());
    for (BlazeSyncPlugin syncPlugin : BlazeSyncPlugin.EP_NAME.getExtensions()) {
        syncPlugin.installSdks(context);
    }
    if (!ProjectViewVerifier.verifyProjectView(project, context, workspacePathResolver, projectViewSet, workspaceLanguageSettings)) {
        return SyncResult.FAILURE;
    }
    final BlazeProjectData newBlazeProjectData;
    WorkingSet workingSet = FutureUtil.waitForFuture(context, workingSetFuture).timed("WorkingSet", EventType.Other).withProgressMessage("Computing VCS working set...").onError("Could not compute working set").run().result();
    if (context.isCancelled()) {
        return SyncResult.CANCELLED;
    }
    if (context.hasErrors()) {
        return SyncResult.FAILURE;
    }
    if (workingSet != null) {
        printWorkingSet(context, workingSet);
    }
    SyncState.Builder syncStateBuilder = new SyncState.Builder();
    SyncState previousSyncState = oldBlazeProjectData != null ? oldBlazeProjectData.syncState : null;
    List<TargetExpression> targets = Lists.newArrayList();
    if (syncParams.addProjectViewTargets) {
        Collection<TargetExpression> projectViewTargets = projectViewSet.listItems(TargetSection.KEY);
        if (!projectViewTargets.isEmpty()) {
            syncStats.setBlazeProjectTargets(new ArrayList<>(projectViewTargets));
            targets.addAll(projectViewTargets);
            printTargets(context, "project view", projectViewTargets);
        }
    }
    if (syncParams.addWorkingSet && workingSet != null) {
        Collection<? extends TargetExpression> workingSetTargets = getWorkingSetTargets(projectViewSet, workingSet);
        if (!workingSetTargets.isEmpty()) {
            targets.addAll(workingSetTargets);
            syncStats.setWorkingSetTargets(new ArrayList<>(workingSetTargets));
            printTargets(context, "working set", workingSetTargets);
        }
    }
    if (!syncParams.targetExpressions.isEmpty()) {
        targets.addAll(syncParams.targetExpressions);
        printTargets(context, syncParams.title, syncParams.targetExpressions);
    }
    ShardedTargetsResult shardedTargetsResult = BlazeBuildTargetSharder.expandAndShardTargets(project, context, workspaceRoot, projectViewSet, workspacePathResolver, targets);
    if (shardedTargetsResult.buildResult.status == BuildResult.Status.FATAL_ERROR) {
        return SyncResult.FAILURE;
    }
    ShardedTargetList shardedTargets = shardedTargetsResult.shardedTargets;
    syncStats.setSyncSharded(shardedTargets.shardedTargets.size() > 1);
    BlazeConfigurationHandler configHandler = new BlazeConfigurationHandler(blazeInfo);
    boolean mergeWithOldState = !syncParams.addProjectViewTargets;
    BlazeIdeInterface.IdeResult ideQueryResult = getIdeQueryResult(project, context, projectViewSet, blazeVersionData, configHandler, shardedTargets, workspaceLanguageSettings, artifactLocationDecoder, syncStateBuilder, previousSyncState, mergeWithOldState);
    if (context.isCancelled()) {
        return SyncResult.CANCELLED;
    }
    context.output(PrintOutput.log("ide-query result: " + ideQueryResult.buildResult.status));
    if (ideQueryResult.targetMap == null || ideQueryResult.buildResult.status == BuildResult.Status.FATAL_ERROR) {
        context.setHasError();
        if (ideQueryResult.buildResult.outOfMemory()) {
            SuggestBuildShardingNotification.syncOutOfMemoryError(project, context);
        }
        return SyncResult.FAILURE;
    }
    TargetMap targetMap = ideQueryResult.targetMap;
    context.output(PrintOutput.log("Target map size: " + ideQueryResult.targetMap.targets().size()));
    BuildResult ideInfoResult = ideQueryResult.buildResult;
    ListenableFuture<ImmutableMultimap<TargetKey, TargetKey>> reverseDependenciesFuture = BlazeExecutor.getInstance().submit(() -> ReverseDependencyMap.createRdepsMap(targetMap));
    BuildResult ideResolveResult = resolveIdeArtifacts(project, context, workspaceRoot, projectViewSet, blazeVersionData, workspaceLanguageSettings, shardedTargets);
    if (ideResolveResult.status == BuildResult.Status.FATAL_ERROR) {
        context.setHasError();
        if (ideResolveResult.outOfMemory()) {
            SuggestBuildShardingNotification.syncOutOfMemoryError(project, context);
        }
        return SyncResult.FAILURE;
    }
    if (context.isCancelled()) {
        return SyncResult.CANCELLED;
    }
    Scope.push(context, (childContext) -> {
        childContext.push(new TimingScope("UpdateSyncState", EventType.Other));
        for (BlazeSyncPlugin syncPlugin : BlazeSyncPlugin.EP_NAME.getExtensions()) {
            syncPlugin.updateSyncState(project, childContext, workspaceRoot, projectViewSet, workspaceLanguageSettings, blazeInfo, workingSet, workspacePathResolver, artifactLocationDecoder, targetMap, syncStateBuilder, previousSyncState);
        }
    });
    ImmutableMultimap<TargetKey, TargetKey> reverseDependencies = FutureUtil.waitForFuture(context, reverseDependenciesFuture).timed("ReverseDependencies", EventType.Other).onError("Failed to compute reverse dependency map").run().result();
    if (reverseDependencies == null) {
        return SyncResult.FAILURE;
    }
    newBlazeProjectData = new BlazeProjectData(syncStartTime, targetMap, blazeInfo, blazeVersionData, workspacePathResolver, artifactLocationDecoder, workspaceLanguageSettings, syncStateBuilder.build(), reverseDependencies);
    FileCaches.onSync(project, context, projectViewSet, newBlazeProjectData, syncParams.syncMode);
    ListenableFuture<?> prefetch = PrefetchService.getInstance().prefetchProjectFiles(project, projectViewSet, newBlazeProjectData);
    FutureUtil.waitForFuture(context, prefetch).withProgressMessage("Prefetching files...").timed("PrefetchFiles", EventType.Prefetching).onError("Prefetch failed").run();
    ListenableFuture<DirectoryStructure> directoryStructureFuture = DirectoryStructure.getRootDirectoryStructure(project, workspaceRoot, projectViewSet);
    refreshVirtualFileSystem(context, newBlazeProjectData);
    DirectoryStructure directoryStructure = FutureUtil.waitForFuture(context, directoryStructureFuture).withProgressMessage("Computing directory structure...").timed("DirectoryStructure", EventType.Other).onError("Directory structure computation failed").run().result();
    if (directoryStructure == null) {
        return SyncResult.FAILURE;
    }
    boolean success = updateProject(context, projectViewSet, blazeVersionData, directoryStructure, oldBlazeProjectData, newBlazeProjectData);
    if (!success) {
        return SyncResult.FAILURE;
    }
    SyncResult syncResult = SyncResult.SUCCESS;
    if (ideInfoResult.status == BuildResult.Status.BUILD_ERROR || ideResolveResult.status == BuildResult.Status.BUILD_ERROR) {
        final String errorType = ideInfoResult.status == BuildResult.Status.BUILD_ERROR ? "BUILD file errors" : "compilation errors";
        String message = String.format("Sync was successful, but there were %s. " + "The project may not be fully updated or resolve until fixed. " + "If the errors are from your working set, please uncheck " + "'Blaze > Sync > Expand Sync to Working Set' and try again.", errorType);
        context.output(PrintOutput.error(message));
        IssueOutput.warn(message).submit(context);
        syncResult = SyncResult.PARTIAL_SUCCESS;
    }
    return syncResult;
}
Also used : ShardedTargetsResult(com.google.idea.blaze.base.sync.sharding.BlazeBuildTargetSharder.ShardedTargetsResult) Builder(com.google.idea.blaze.base.model.SyncState.Builder) BlazeIdeInterface(com.google.idea.blaze.base.sync.aspects.BlazeIdeInterface) Builder(com.google.idea.blaze.base.model.SyncState.Builder) BlazeVersionData(com.google.idea.blaze.base.model.BlazeVersionData) BlazeConfigurationHandler(com.google.idea.blaze.base.command.info.BlazeConfigurationHandler) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) SyncState(com.google.idea.blaze.base.model.SyncState) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) WorkspacePathResolver(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver) ArtifactLocationDecoderImpl(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoderImpl) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) WorkingSet(com.google.idea.blaze.base.sync.workspace.WorkingSet) SyncResult(com.google.idea.blaze.base.sync.SyncListener.SyncResult) DirectoryStructure(com.google.idea.blaze.base.sync.projectstructure.DirectoryStructure) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression) ShardedTargetList(com.google.idea.blaze.base.sync.sharding.ShardedTargetList) BlazeInfo(com.google.idea.blaze.base.command.info.BlazeInfo) BuildResult(com.google.idea.blaze.base.sync.aspects.BuildResult) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) BlazeVcsHandler(com.google.idea.blaze.base.vcs.BlazeVcsHandler)

Aggregations

ImmutableMultimap (com.google.common.collect.ImmutableMultimap)30 Path (java.nio.file.Path)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 ImmutableSet (com.google.common.collect.ImmutableSet)7 Map (java.util.Map)6 BuildTarget (com.facebook.buck.model.BuildTarget)4 ImmutableList (com.google.common.collect.ImmutableList)4 SourcePath (com.facebook.buck.rules.SourcePath)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 Multimap (com.google.common.collect.Multimap)3 IOException (java.io.IOException)3 List (java.util.List)3 ClasspathTraversal (com.facebook.buck.jvm.java.classes.ClasspathTraversal)2 ClasspathTraverser (com.facebook.buck.jvm.java.classes.ClasspathTraverser)2 DefaultClasspathTraverser (com.facebook.buck.jvm.java.classes.DefaultClasspathTraverser)2 FileLike (com.facebook.buck.jvm.java.classes.FileLike)2 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)2 Column (com.facebook.presto.hive.metastore.Column)2 ExtendedHiveMetastore (com.facebook.presto.hive.metastore.ExtendedHiveMetastore)2 HivePrivilegeInfo (com.facebook.presto.hive.metastore.HivePrivilegeInfo)2