forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "[FLINK-22881] Revert toggling IDLE/ACTIVE on records in IDLE …
…state" This reverts commit 2c260b5.
- Loading branch information
1 parent
55eb22b
commit 8758b21
Showing
5 changed files
with
102 additions
and
240 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
70 changes: 70 additions & 0 deletions
70
...g-java/src/main/java/org/apache/flink/streaming/runtime/streamstatus/AnnouncedStatus.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,70 @@ | ||
/* | ||
* 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.runtime.streamstatus; | ||
|
||
import org.apache.flink.annotation.Internal; | ||
|
||
import java.util.function.Consumer; | ||
|
||
/** | ||
* {@link StreamStatus#IDLE} requires that no records nor watermarks travel through the branch. In | ||
* order to keep the older behaviour that records could've been generated down the pipeline even | ||
* though the sources were idle we go through a short ACTIVE/IDLE loop. This is a helper class that | ||
* lets you easily flip the status around a code block. | ||
*/ | ||
@Internal | ||
public final class AnnouncedStatus { | ||
private StreamStatus currentStatus; | ||
|
||
public AnnouncedStatus(StreamStatus currentStatus) { | ||
this.currentStatus = currentStatus; | ||
} | ||
|
||
public StreamStatus getCurrentStatus() { | ||
return currentStatus; | ||
} | ||
|
||
public void setCurrentStatus(StreamStatus currentStatus) { | ||
this.currentStatus = currentStatus; | ||
} | ||
|
||
/** | ||
* Makes sure that the last emitted StreamStatus was ACTIVE. | ||
* | ||
* <p>Example usage: | ||
* | ||
* <pre>{@code | ||
* try (AutoCloseable ignored = announcedStatus.ensureActive(this::writeStreamStatus)) { | ||
* serializationDelegate.setInstance(record); | ||
* recordWriter.emit(serializationDelegate); | ||
* } catch (Exception e) { | ||
* throw new RuntimeException(e.getMessage(), e); | ||
* } | ||
* }</pre> | ||
* | ||
* @param statusConsumer a consumer which sends the status downstream | ||
*/ | ||
public AutoCloseable ensureActive(Consumer<StreamStatus> statusConsumer) { | ||
if (currentStatus.isIdle()) { | ||
statusConsumer.accept(StreamStatus.ACTIVE); | ||
return () -> statusConsumer.accept(StreamStatus.IDLE); | ||
} | ||
return () -> {}; | ||
} | ||
} |
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.