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