Search in sources :

Example 46 with Nullable

use of org.checkerframework.checker.nullness.qual.Nullable in project beam by apache.

the class TimeUtil method fromCloudTime.

/**
 * Converts a time value received via the Dataflow API into the corresponding {@link Instant}.
 *
 * @return the parsed time, or null if a parse error occurs
 */
@Nullable
public static Instant fromCloudTime(String time) {
    Matcher matcher = TIME_PATTERN.matcher(time);
    if (!matcher.matches()) {
        return null;
    }
    int year = Integer.parseInt(matcher.group(1));
    int month = Integer.parseInt(matcher.group(2));
    int day = Integer.parseInt(matcher.group(3));
    int hour = Integer.parseInt(matcher.group(4));
    int minute = Integer.parseInt(matcher.group(5));
    int second = Integer.parseInt(matcher.group(6));
    int millis = computeMillis(matcher.group(7));
    return new DateTime(year, month, day, hour, minute, second, millis, ISOChronology.getInstanceUTC()).toInstant();
}
Also used : Matcher(java.util.regex.Matcher) DateTime(org.joda.time.DateTime) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 47 with Nullable

use of org.checkerframework.checker.nullness.qual.Nullable in project beam by apache.

the class WorkItemStatusClient method execute.

@Nullable
private synchronized WorkItemServiceState execute(WorkItemStatus status) throws IOException {
    WorkItemServiceState result = workUnitClient.reportWorkItemStatus(status);
    if (result != null) {
        nextReportIndex = result.getNextReportIndex();
        if (nextReportIndex == null && !status.getCompleted()) {
            LOG.error("Missing next work index in {} when reporting {}.", result, status);
        }
        commitMetrics();
    }
    if (status.getCompleted()) {
        checkState(!finalStateSent, "cannot reportUpdates after sending a final state");
        finalStateSent = true;
    }
    return result;
}
Also used : WorkItemServiceState(com.google.api.services.dataflow.model.WorkItemServiceState) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 48 with Nullable

use of org.checkerframework.checker.nullness.qual.Nullable in project beam by apache.

the class StreamingDataflowWorker method scheduleWorkItem.

private void scheduleWorkItem(final ComputationState computationState, final Instant inputDataWatermark, final Instant synchronizedProcessingTime, final Windmill.WorkItem workItem) {
    Preconditions.checkNotNull(inputDataWatermark);
    // May be null if output watermark not yet known.
    @Nullable final Instant outputDataWatermark = WindmillTimeUtils.windmillToHarnessWatermark(workItem.getOutputDataWatermark());
    Preconditions.checkState(outputDataWatermark == null || !outputDataWatermark.isAfter(inputDataWatermark));
    SdkWorkerHarness worker = sdkHarnessRegistry.getAvailableWorkerAndAssignWork();
    Work work = new Work(workItem) {

        @Override
        public void run() {
            try {
                process(worker, computationState, inputDataWatermark, outputDataWatermark, synchronizedProcessingTime, this);
            } finally {
                // Reduce the work associated with the worker
                sdkHarnessRegistry.completeWork(worker);
            }
        }
    };
    if (!computationState.activateWork(ShardedKey.create(workItem.getKey(), workItem.getShardingKey()), work)) {
        // Free worker if the work was not activated.
        // This can happen if it's duplicate work or some other reason.
        sdkHarnessRegistry.completeWork(worker);
    }
}
Also used : Instant(org.joda.time.Instant) SdkWorkerHarness(org.apache.beam.runners.dataflow.worker.SdkHarnessRegistry.SdkWorkerHarness) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 49 with Nullable

use of org.checkerframework.checker.nullness.qual.Nullable in project beam by apache.

the class StateTable method get.

/**
 * Gets the {@link State} in the specified {@link StateNamespace} with the specified {@link
 * StateTag}, binding it using the {@link #binderForNamespace} if it is not already present in
 * this {@link StateTable}.
 */
public <StateT extends State> StateT get(StateNamespace namespace, StateTag<StateT> tag, StateContext<?> c) {
    Equivalence.Wrapper<StateTag> tagById = StateTags.ID_EQUIVALENCE.wrap((StateTag) tag);
    @Nullable State storage = getOrNull(namespace, tagById, c);
    if (storage != null) {
        @SuppressWarnings("unchecked") StateT typedStorage = (StateT) storage;
        return typedStorage;
    }
    StateT typedStorage = tag.bind(binderForNamespace(namespace, c));
    stateTable.put(namespace, tagById, typedStorage);
    return typedStorage;
}
Also used : Equivalence(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Equivalence) State(org.apache.beam.sdk.state.State) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 50 with Nullable

use of org.checkerframework.checker.nullness.qual.Nullable in project beam by apache.

the class WatermarkHold method addGarbageCollectionHold.

/**
 * Attempt to add a 'garbage collection hold' if it is required. Return the {@link Instant} at
 * which the hold was added (ie the end of window time plus allowed lateness), or {@literal null}
 * if no hold was added.
 *
 * <p>A garbage collection hold is added in two situations:
 *
 * <ol>
 *   <li>An incoming element has a timestamp earlier than the output watermark, and was too late
 *       for placing the usual element hold or an end of window hold. Place the garbage collection
 *       hold so that we can guarantee when the pane is finally triggered its output will not be
 *       dropped due to excessive lateness by any downstream computation.
 *   <li>The {@link WindowingStrategy#getClosingBehavior()} is {@link
 *       ClosingBehavior#FIRE_ALWAYS}, and thus we guarantee a final pane will be emitted for all
 *       windows which saw at least one element. Again, the garbage collection hold guarantees
 *       that any empty final pane can be given a timestamp which will not be considered beyond
 *       allowed lateness by any downstream computation.
 * </ol>
 *
 * <p>We use {@code paneIsEmpty} to distinguish cases 1 and 2.
 */
@Nullable
private Instant addGarbageCollectionHold(ReduceFn<?, ?, ?, W>.Context context, boolean paneIsEmpty) {
    Instant outputWM = timerInternals.currentOutputWatermarkTime();
    Instant inputWM = timerInternals.currentInputWatermarkTime();
    Instant gcHold = LateDataUtils.garbageCollectionTime(context.window(), windowingStrategy);
    if (gcHold.isBefore(inputWM)) {
        WindowTracing.trace("{}.addGarbageCollectionHold: gc hold would be before the input watermark " + "for key:{}; window: {}; inputWatermark: {}; outputWatermark: {}", getClass().getSimpleName(), context.key(), context.window(), inputWM, outputWM);
        return null;
    }
    if (paneIsEmpty && context.windowingStrategy().getClosingBehavior() == ClosingBehavior.FIRE_IF_NON_EMPTY) {
        WindowTracing.trace("WatermarkHold.addGarbageCollectionHold: garbage collection hold at {} is unnecessary " + "since empty pane and FIRE_IF_NON_EMPTY for key:{}; window:{}; inputWatermark:{}; " + "outputWatermark:{}", gcHold, context.key(), context.window(), inputWM, outputWM);
        return null;
    }
    if (!gcHold.isBefore(BoundedWindow.TIMESTAMP_MAX_VALUE)) {
        // If the garbage collection hold is past the timestamp we can represent, instead truncate
        // to the maximum timestamp that is not positive infinity. This ensures all windows will
        // eventually be garbage collected.
        gcHold = BoundedWindow.TIMESTAMP_MAX_VALUE.minus(Duration.millis(1L));
    }
    checkState(!gcHold.isBefore(inputWM), "Garbage collection hold %s cannot be before input watermark %s", gcHold, inputWM);
    checkState(!gcHold.isAfter(BoundedWindow.TIMESTAMP_MAX_VALUE), "Garbage collection hold %s is beyond end-of-time", gcHold);
    // Same EXTRA_HOLD_TAG vs elementHoldTag discussion as in addEndOfWindowHold above.
    context.state().access(EXTRA_HOLD_TAG).add(gcHold);
    WindowTracing.trace("WatermarkHold.addGarbageCollectionHold: garbage collection hold at {} is on time for " + "key:{}; window:{}; inputWatermark:{}; outputWatermark:{}", gcHold, context.key(), context.window(), inputWM, outputWM);
    return gcHold;
}
Also used : Instant(org.joda.time.Instant) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Aggregations

Nullable (org.checkerframework.checker.nullness.qual.Nullable)285 ArrayList (java.util.ArrayList)27 TypeElement (javax.lang.model.element.TypeElement)23 IOException (java.io.IOException)21 Map (java.util.Map)21 ExecutableElement (javax.lang.model.element.ExecutableElement)19 ServerLevel (net.minecraft.server.level.ServerLevel)19 List (java.util.List)16 Instant (org.joda.time.Instant)16 VariableElement (javax.lang.model.element.VariableElement)15 HashMap (java.util.HashMap)14 Optional (java.util.Optional)14 Element (javax.lang.model.element.Element)13 TreePath (com.sun.source.util.TreePath)12 BlockPos (net.minecraft.core.BlockPos)12 Method (java.lang.reflect.Method)11 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)11 MonotonicNonNull (org.checkerframework.checker.nullness.qual.MonotonicNonNull)10 VariableTree (com.sun.source.tree.VariableTree)8 ClassTree (com.sun.source.tree.ClassTree)7