[
https://issues.apache.org/jira/browse/BEAM-4681?focusedWorklogId=167270&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-167270
]
ASF GitHub Bot logged work on BEAM-4681:
----------------------------------------
Author: ASF GitHub Bot
Created on: 18/Nov/18 22:13
Start Date: 18/Nov/18 22:13
Worklog Time Spent: 10m
Work Description: tweise commented on a change in pull request #7008:
[BEAM-4681] Add support for portable timers in Flink batch mode
URL: https://github.com/apache/beam/pull/7008#discussion_r234464176
##########
File path:
runners/flink/src/main/java/org/apache/beam/runners/flink/translation/functions/FlinkExecutableStageFunction.java
##########
@@ -230,20 +330,92 @@ public void close() throws Exception {
private final Collector<RawUnionValue> collector;
private final Map<String, Integer> outputMap;
+ @Nullable private final TimerReceiverFactory timerReceiverFactory;
ReceiverFactory(Collector<RawUnionValue> collector, Map<String, Integer>
outputMap) {
+ this(collector, outputMap, null);
+ }
+
+ ReceiverFactory(
+ Collector<RawUnionValue> collector,
+ Map<String, Integer> outputMap,
+ @Nullable TimerReceiverFactory timerReceiverFactory) {
this.collector = collector;
this.outputMap = outputMap;
+ this.timerReceiverFactory = timerReceiverFactory;
}
@Override
public <OutputT> FnDataReceiver<OutputT> create(String collectionId) {
Integer unionTag = outputMap.get(collectionId);
- checkArgument(unionTag != null, "Unknown PCollection id: %s",
collectionId);
- int tagInt = unionTag;
+ if (unionTag != null) {
+ int tagInt = unionTag;
+ return receivedElement -> {
+ synchronized (collectorLock) {
+ collector.collect(new RawUnionValue(tagInt, receivedElement));
+ }
+ };
+ } else if (timerReceiverFactory != null) {
+ // Delegate to TimerReceiverFactory
+ return timerReceiverFactory.create(collectionId);
+ } else {
+ throw new IllegalStateException(
+ String.format(Locale.ENGLISH, "Unknown PCollectionId %s",
collectionId));
+ }
+ }
+ }
+
+ private static class TimerReceiverFactory implements OutputReceiverFactory {
+
+ private final StageBundleFactory stageBundleFactory;
+ /** Timer PCollection id => TimerReference. */
+ private final HashMap<String, ProcessBundleDescriptors.TimerSpec>
timerOutputIdToSpecMap;
+ /** Timer PCollection id => timer name => TimerSpec. */
+ private final Map<String, Map<String, ProcessBundleDescriptors.TimerSpec>>
timerSpecMap;
+
+ private final BiConsumer<WindowedValue, TimerInternals.TimerData>
timerDataConsumer;
+ private final Coder windowCoder;
+
+ TimerReceiverFactory(
+ StageBundleFactory stageBundleFactory,
+ Collection<TimerReference> timerReferenceCollection,
+ Map<String, Map<String, ProcessBundleDescriptors.TimerSpec>>
timerSpecMap,
+ BiConsumer<WindowedValue, TimerInternals.TimerData> timerDataConsumer,
+ Coder windowCoder) {
+ this.stageBundleFactory = stageBundleFactory;
+ this.timerOutputIdToSpecMap = new HashMap<>();
+ // Gather all timers from all transforms by their output pCollectionId
which is unique
+ for (Map<String, ProcessBundleDescriptors.TimerSpec> transformTimerMap :
+
stageBundleFactory.getProcessBundleDescriptor().getTimerSpecs().values()) {
+ for (ProcessBundleDescriptors.TimerSpec timerSpec :
transformTimerMap.values()) {
+ timerOutputIdToSpecMap.put(timerSpec.outputCollectionId(),
timerSpec);
+ }
+ }
+ this.timerSpecMap = timerSpecMap;
+ this.timerDataConsumer = timerDataConsumer;
+ this.windowCoder = windowCoder;
+ }
+
+ @Override
+ public <OutputT> FnDataReceiver<OutputT> create(String pCollectionId) {
+ final ProcessBundleDescriptors.TimerSpec timerSpec =
+ timerOutputIdToSpecMap.get(pCollectionId);
+
return receivedElement -> {
- synchronized (collectorLock) {
- collector.collect(new RawUnionValue(tagInt, receivedElement));
+ WindowedValue windowedValue = (WindowedValue) receivedElement;
+ Timer timer =
+ Preconditions.checkNotNull(
+ (Timer) ((KV) windowedValue.getValue()).getValue(),
+ "Received null Timer from SDK harness: %s",
+ receivedElement);
+ LOG.info("Timer received: {} {}", pCollectionId, timer);
Review comment:
debug
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 167270)
Time Spent: 22h 20m (was: 22h 10m)
> Integrate support for timers using the portability APIs into Flink
> ------------------------------------------------------------------
>
> Key: BEAM-4681
> URL: https://issues.apache.org/jira/browse/BEAM-4681
> Project: Beam
> Issue Type: Sub-task
> Components: runner-flink
> Reporter: Luke Cwik
> Assignee: Maximilian Michels
> Priority: Major
> Labels: portability, portability-flink
> Fix For: 2.9.0
>
> Time Spent: 22h 20m
> Remaining Estimate: 0h
>
> Consider using the code produced in BEAM-4658 to support timers.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)