private List<Long> toWindows(SortedSet<Long> windowIndexes) { List<Long> windows = new ArrayList<>(windowIndexes.size()); windowIndexes.forEach(i -> windows.add(i * _windowMs)); return windows; }
private SortedSet<Long> windowIndexesToWindows(SortedSet<Long> original, long windowMs) { SortedSet<Long> result = new TreeSet<>(Collections.reverseOrder()); original.forEach(idx -> result.add(idx * windowMs)); return result; }
/** * Untrack the sorted replicas with the given name to release memory. * * @param sortName the name of the sorted replicas. */ public void untrackSortedReplicas(String sortName) { _brokers.forEach(b -> b.untrackSortedReplicas(sortName)); }
private static void buildCallDefinitions(@NotNull ModuleStub parentStub, @NotNull Beam beam, @NotNull Atoms atoms) { macroNameAritySortedSet(beam, atoms).forEach(macroNameArity -> buildCallDefinition(parentStub, macroNameArity)); }
public Configuration(Set<Pipeline> pipelines) { if (pipelines.isEmpty()) { initialStage = extent[0] = extent[1] = 0; return; } pipelines.forEach(pipeline -> { // skip pipelines without any stages, they don't contribute any rules to run final SortedSet<Stage> stages = pipeline.stages(); if (stages.isEmpty()) { return; } extent[0] = Math.min(extent[0], stages.first().stage()); extent[1] = Math.max(extent[1], stages.last().stage()); stages.forEach(stage -> stageMultimap.put(stage.stage(), stage)); }); if (extent[0] == Integer.MIN_VALUE) { throw new IllegalArgumentException("First stage cannot be at " + Integer.MIN_VALUE); } // the stage before the first stage. initialStage = extent[0] - 1; }
/** * Ask the cluster model to keep track of the replicas sorted with the given priority function and score function. * * The sort will first use the priority function then the score function. The priority function allows the * caller to prioritize a certain type of replicas, e.g immigrant replicas. The selection function determines * which replicas to be included in the sorted replicas. * * It is recommended to use the functions from {@link ReplicaSortFunctionFactory} so the functions can be maintained * in a single place. * * The sorted replica will only be updated in the following cases: * 1. A replica is added to or removed from a broker * 2. A replica's role has changed from leader to follower, and vice versa. * * The sorted replicas are named using the given sortName, and can be accessed using * {@link Broker#trackedSortedReplicas(String)}. If the sorted replicas are no longer needed, * {@link #untrackSortedReplicas(String)} to release memory. * * @param sortName the name of the sorted replicas. * @param selectionFunc the selection function to decide which replicas to include in the sort. * @param priorityFunc the priority function to sort the replicas * @param scoreFunc the score function to sort the replicas with the same priority. * @see SortedReplicas */ public void trackSortedReplicas(String sortName, Function<Replica, Boolean> selectionFunc, Function<Replica, Integer> priorityFunc, Function<Replica, Double> scoreFunc) { _brokers.forEach(b -> b.trackSortedReplicas(sortName, selectionFunc, priorityFunc, scoreFunc)); }
/** * Clears Application registry. This is required for the Metric TCKs as they * all run on the same VM and must not interfere with each other. */ static void clearApplicationRegistry() { MetricRegistry applicationRegistry = getApplicationRegistry(); applicationRegistry.getNames().forEach(applicationRegistry::remove); } }
public Builder removeSegment(DataSegment dataSegment) { SegmentAndSum segmentAndSum = new SegmentAndSum(dataSegment, 0.0, 0.0); if (!segments.remove(segmentAndSum)) { return this; } double t0 = convertStart(dataSegment, interval); double t1 = convertEnd(dataSegment, interval); double leftValue = FastMath.exp(t0) - FastMath.exp(t1); double rightValue = FastMath.exp(-t1) - FastMath.exp(-t0); segments.tailSet(segmentAndSum).forEach(v -> v.leftSum -= leftValue); segments.headSet(segmentAndSum).forEach(v -> v.rightSum -= rightValue); return this; }
@Nonnull private Pipeline resolvePipeline(Pipeline pipeline, Map<String, Rule> ruleNameMap) { log.debug("Resolving pipeline {}", pipeline.name()); pipeline.stages().forEach(stage -> { final List<Rule> resolvedRules = stage.ruleReferences().stream() .map(ref -> { Rule rule = ruleNameMap.get(ref); if (rule == null) { rule = Rule.alwaysFalse("Unresolved rule " + ref); } // make a copy so that the metrics match up (we don't share actual objects between stages) // this also makes sure we don't accidentally share state of generated code between threads rule = rule.invokableCopy(functionRegistry); log.debug("Resolved rule `{}` to {}", ref, rule); // include back reference to stage rule.registerMetrics(metricRegistry, pipeline.id(), String.valueOf(stage.stage())); return rule; }) .collect(Collectors.toList()); stage.setRules(resolvedRules); stage.setPipeline(pipeline); stage.registerMetrics(metricRegistry, pipeline.id()); }); pipeline.registerMetrics(metricRegistry); return pipeline; }
allIndexRanges.forEach(indexRange -> extraIndices.remove(indexRange.indexName())); final Set<String> affectedIndexSetNames = extraIndices.stream() .map(indexSetRegistry::getForIndex)
this.oldsources.add(replicationSource); for (SortedSet<String> walsByGroup : walsByIdRecoveredQueues.get(queueId).values()) { walsByGroup.forEach(wal -> src.enqueueLog(new Path(wal)));
syncFutures.forEach(f -> f.done(f.getTxid(), error)); if (!(consumeExecutor instanceof EventLoop)) { consumeExecutor.shutdown();
clusterModel.brokers().forEach(broker -> numExcludedReplicasByPositionInBroker.put(broker.id(), new HashMap<>())); for (String excludedTopic : excludedTopics) { for (Partition partition : _partitionsByTopic.get(excludedTopic)) {
public Builder addSegment(DataSegment dataSegment) { if (!interval.contains(dataSegment.getInterval().getStartMillis())) { throw new ISE("Failed to add segment to bucket: interval is not covered by this bucket"); } // all values are pre-computed relatively to bucket start (which is considered as 0) double t0 = convertStart(dataSegment, interval); double t1 = convertEnd(dataSegment, interval); double leftValue = FastMath.exp(t0) - FastMath.exp(t1); double rightValue = FastMath.exp(-t1) - FastMath.exp(-t0); SegmentAndSum segmentAndSum = new SegmentAndSum(dataSegment, leftValue, rightValue); // left/right value should be added to left/right sums for elements greater/lower than current segment segments.tailSet(segmentAndSum).forEach(v -> v.leftSum += leftValue); segments.headSet(segmentAndSum).forEach(v -> v.rightSum += rightValue); // leftSum_i = leftValue_i + \sum leftValue_j = leftValue_i + leftSum_{i-1} , j < i SegmentAndSum lower = segments.lower(segmentAndSum); if (lower != null) { segmentAndSum.leftSum = leftValue + lower.leftSum; } // rightSum_i = rightValue_i + \sum rightValue_j = rightValue_i + rightSum_{i+1} , j > i SegmentAndSum higher = segments.higher(segmentAndSum); if (higher != null) { segmentAndSum.rightSum = rightValue + higher.rightSum; } if (!segments.add(segmentAndSum)) { throw new ISE("expect new segment"); } return this; }
AtomicReference<FieldLayout> requested = new AtomicReference<>(); layout.fields().forEach(f -> { if ("wip".equals(f.name())) wip.set(f); else if ("requested".equals(f.name())) requested.set(f);
/** * Get broker return the broker stats. */ public BrokerStats brokerStats() { BrokerStats brokerStats = new BrokerStats(); brokers().forEach(broker -> { double leaderBytesInRate = broker.leadershipLoadForNwResources().expectedUtilizationFor(Resource.NW_IN); brokerStats.addSingleBrokerStats(broker.host().name(), broker.id(), broker.state(), broker.replicas().isEmpty() ? 0 : broker.load().expectedUtilizationFor(Resource.DISK), broker.load().expectedUtilizationFor(Resource.CPU), leaderBytesInRate, broker.load().expectedUtilizationFor(Resource.NW_IN) - leaderBytesInRate, broker.load().expectedUtilizationFor(Resource.NW_OUT), potentialLeadershipLoadFor(broker.id()).expectedUtilizationFor(Resource.NW_OUT), broker.replicas().size(), broker.leaderReplicas().size(), _capacityEstimationInfoByBrokerId.get(broker.id()) != null, broker.capacityFor(Resource.DISK)); }); return brokerStats; }
clusterModel.broker(0).leaderReplicas().forEach(r -> leaderPartitionsOnDemotedBroker.add(r.topicPartition())); Map<TopicPartition, Integer> leaderDistributionBeforeBrokerDemotion = new HashMap<>(); clusterModel.brokers().forEach(b -> { b.leaderReplicas().forEach(r -> leaderDistributionBeforeBrokerDemotion.put(r.topicPartition(), b.id())); });
environment.healthChecks().getNames().forEach( name -> environment.metrics().register( "helios." + name + ".ok", new HealthCheckGauge(environment.healthChecks(), name)));
environment.healthChecks().getNames().forEach( name -> environment.metrics().register( "helios." + name + ".ok", new HealthCheckGauge(environment.healthChecks(), name)));
@EventListener public void onRemoveSelected(RemoveSelectedEvent event) { SortedSet<Integer> indices = new TreeSet<>(Collections.reverseOrder()); indices.addAll(getSelectionModel().getSelectedIndices()); LOG.trace("Removing {} items", indices.size()); indices.forEach(i -> getItems().remove(i.intValue()).invalidate()); requestFocus(); }