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.
[FLINK-11667][checkpointing] Add Synchronous Checkpoint handling in S…
…treamTask. This is a necessary step towards implementing the "stop with a savepoint". Essentially, a synchronous savepoint is one that waits until also the notifyOnCheckpointComplete is successfully executed, before releasing the checkpoint lock (on the StreamTask side).
- Loading branch information
Showing
17 changed files
with
1,145 additions
and
64 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
104 changes: 104 additions & 0 deletions
104
.../src/main/java/org/apache/flink/runtime/taskmanager/BlockingCallMonitoringThreadPool.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,104 @@ | ||
/* | ||
* 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:https://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.taskmanager; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.LinkedBlockingQueue; | ||
import java.util.concurrent.ThreadFactory; | ||
import java.util.concurrent.ThreadPoolExecutor; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import static org.apache.flink.util.Preconditions.checkNotNull; | ||
|
||
/** | ||
* A Thread Pool used to monitor the number of in-flight calls that block and wait for another task executed | ||
* by the same pool in order to get unblocked. When a call (blocking or non-blocking) is submitted, the size | ||
* of the pool is set to {@code 1 + activeBlockingCalls}. This allows the thread pool size to follow the needs | ||
* of the system and to avoid any redundant idle threads consuming resources. | ||
*/ | ||
public class BlockingCallMonitoringThreadPool { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(BlockingCallMonitoringThreadPool.class); | ||
|
||
private final AtomicInteger inFlightBlockingCallCounter = new AtomicInteger(0); | ||
|
||
private final ThreadPoolExecutor executor; | ||
|
||
public BlockingCallMonitoringThreadPool(final ThreadFactory dispatcherThreadFactory) { | ||
this.executor = new ThreadPoolExecutor( | ||
1, | ||
1, | ||
10L, | ||
TimeUnit.SECONDS, | ||
new LinkedBlockingQueue<>(), | ||
checkNotNull(dispatcherThreadFactory)); | ||
} | ||
|
||
public void submit(final Runnable runnable, final boolean blocking) { | ||
if (blocking) { | ||
submitBlocking(runnable); | ||
} else { | ||
submit(runnable); | ||
} | ||
} | ||
|
||
private void submit(final Runnable task) { | ||
adjustThreadPoolSize(inFlightBlockingCallCounter.get()); | ||
executor.execute(task); | ||
} | ||
|
||
private void submitBlocking(final Runnable task) { | ||
adjustThreadPoolSize(inFlightBlockingCallCounter.incrementAndGet()); | ||
CompletableFuture.runAsync(task, executor).whenComplete( | ||
(ignored, e) -> inFlightBlockingCallCounter.decrementAndGet()); | ||
} | ||
|
||
private void adjustThreadPoolSize(final int activeBlockingCalls) { | ||
if (activeBlockingCalls > 1) { | ||
LOG.debug("There are {} active threads with blocking calls", activeBlockingCalls); | ||
} | ||
|
||
final int newPoolSize = 1 + activeBlockingCalls; | ||
|
||
// We have to reset the core pool size because (quoted from the official docs): | ||
// `` | ||
// If there are more than corePoolSize but less than maximumPoolSize threads running, | ||
// ** a new thread will be created ONLY IF THE QUEUE IS FULL **. | ||
// `` | ||
|
||
executor.setCorePoolSize(newPoolSize); | ||
executor.setMaximumPoolSize(newPoolSize); | ||
} | ||
|
||
public void shutdown() { | ||
executor.shutdown(); | ||
} | ||
|
||
public boolean isShutdown() { | ||
return executor.isShutdown(); | ||
} | ||
|
||
public void shutdownNow() { | ||
executor.shutdownNow(); | ||
} | ||
} |
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
Oops, something went wrong.