-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-33202][runtime] Support switching from batch to stream mode to…
… improve throughput when processing backlog data
- Loading branch information
Showing
73 changed files
with
2,647 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
flink-runtime/src/main/java/org/apache/flink/runtime/source/event/BacklogEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.flink.runtime.source.event; | ||
|
||
import org.apache.flink.runtime.operators.coordination.OperatorEvent; | ||
|
||
/** A source event that notify the source operator of the backlog status. */ | ||
public class BacklogEvent implements OperatorEvent { | ||
|
||
private final boolean backlog; | ||
|
||
public BacklogEvent(boolean backlog) { | ||
this.backlog = backlog; | ||
} | ||
|
||
public boolean isBacklog() { | ||
return backlog; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...aming-java/src/main/java/org/apache/flink/streaming/api/operators/BacklogTimeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.flink.streaming.api.operators; | ||
|
||
import org.apache.flink.runtime.state.KeyGroupedInternalPriorityQueue; | ||
import org.apache.flink.streaming.api.operators.sorted.state.BatchExecutionInternalTimeService; | ||
import org.apache.flink.streaming.runtime.tasks.ProcessingTimeService; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
/** | ||
* An implementation of a {@link InternalTimerService} that manages timers with a single active key | ||
* at a time. This is used by {@link | ||
* org.apache.flink.streaming.api.operators.InternalBacklogAwareTimerServiceImpl} during backlog | ||
* processing. | ||
*/ | ||
class BacklogTimeService<K, N> extends BatchExecutionInternalTimeService<K, N> { | ||
private long maxWatermarkDuringBacklog; | ||
|
||
public BacklogTimeService( | ||
ProcessingTimeService processingTimeService, | ||
Triggerable<K, N> triggerTarget, | ||
KeyGroupedInternalPriorityQueue<TimerHeapInternalTimer<K, N>> eventTimeTimersQueue) { | ||
super(processingTimeService, triggerTarget, eventTimeTimersQueue, null); | ||
} | ||
|
||
@Override | ||
public void registerProcessingTimeTimer(N namespace, long time) { | ||
throw new UnsupportedOperationException( | ||
"BacklogTimeService does not support registering processing timer."); | ||
} | ||
|
||
@Override | ||
public void deleteProcessingTimeTimer(N namespace, long time) { | ||
throw new UnsupportedOperationException( | ||
"BacklogTimeService does not support deleting processing timer."); | ||
} | ||
|
||
/** | ||
* Set the current key of the time service. If the new key is different from the last key, all | ||
* the event time timers of the last key whose timestamp is less than or equal to the max | ||
* watermark during backlog are triggered. | ||
*/ | ||
public void setCurrentKey(K newKey) throws Exception { | ||
if (newKey != null && newKey.equals(currentKey)) { | ||
return; | ||
} | ||
|
||
TimerHeapInternalTimer<K, N> timer; | ||
List<TimerHeapInternalTimer<K, N>> skippedTimers = new LinkedList<>(); | ||
if (currentKey != null) { | ||
while ((timer = eventTimeTimersQueue.peek()) != null | ||
&& timer.getTimestamp() <= maxWatermarkDuringBacklog) { | ||
eventTimeTimersQueue.poll(); | ||
|
||
if (timer.getKey() != currentKey) { | ||
skippedTimers.add(timer); | ||
} else { | ||
triggerTarget.onEventTime(timer); | ||
} | ||
} | ||
eventTimeTimersQueue.addAll(skippedTimers); | ||
} | ||
|
||
if (newKey == null) { | ||
currentWatermark = maxWatermarkDuringBacklog; | ||
} | ||
|
||
currentKey = newKey; | ||
} | ||
|
||
public void setMaxWatermarkDuringBacklog(long watermark) { | ||
maxWatermarkDuringBacklog = watermark; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.