sijie closed pull request #1988: Fix: avoid closing RuntimeFactory when any
function stops
URL: https://github.com/apache/incubator-pulsar/pull/1988
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/JavaInstanceMain.java
b/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/JavaInstanceMain.java
index 554f9acb99..5a63ec3691 100644
---
a/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/JavaInstanceMain.java
+++
b/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/JavaInstanceMain.java
@@ -155,6 +155,7 @@
private Server server;
private RuntimeSpawner runtimeSpawner;
+ private ThreadRuntimeFactory containerFactory;
private Long lastHealthCheckTs = null;
private ScheduledExecutorService timer;
@@ -222,7 +223,7 @@ public void start() throws Exception {
instanceConfig.setFunctionDetails(functionDetails);
instanceConfig.setPort(port);
- ThreadRuntimeFactory containerFactory = new
ThreadRuntimeFactory("LocalRunnerThreadGroup", pulsarServiceUrl,
+ containerFactory = new ThreadRuntimeFactory("LocalRunnerThreadGroup",
pulsarServiceUrl,
stateStorageServiceUrl,
AuthenticationConfig.builder().clientAuthenticationPlugin(clientAuthenticationPlugin)
.clientAuthenticationParameters(clientAuthenticationParameters).useTls(isTrue(useTls))
@@ -302,6 +303,9 @@ public void close() {
if (timer != null) {
timer.shutdown();
}
+ if (containerFactory != null) {
+ containerFactory.close();
+ }
} catch (Exception ex) {
System.err.println(ex);
}
diff --git
a/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/RuntimeSpawner.java
b/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/RuntimeSpawner.java
index 8b60deda25..236042ed52 100644
---
a/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/RuntimeSpawner.java
+++
b/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/RuntimeSpawner.java
@@ -27,14 +27,12 @@
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.ExecutionException;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.pulsar.functions.instance.InstanceConfig;
-import org.apache.pulsar.functions.proto.InstanceCommunication;
import org.apache.pulsar.functions.proto.InstanceCommunication.FunctionStatus;
import org.apache.pulsar.functions.utils.Utils;
import static
org.apache.pulsar.functions.proto.Function.FunctionDetails.Runtime.PYTHON;
@@ -130,9 +128,6 @@ public void close() {
runtime.stop();
runtime = null;
}
- if (runtimeFactory != null) {
- runtimeFactory.close();
- }
if (processLivenessCheckTimer != null) {
processLivenessCheckTimer.cancel();
processLivenessCheckTimer = null;
diff --git
a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/FunctionRuntimeManager.java
b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/FunctionRuntimeManager.java
index ba1a33d997..25122954e7 100644
---
a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/FunctionRuntimeManager.java
+++
b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/FunctionRuntimeManager.java
@@ -521,6 +521,9 @@ private void setFunctionRuntimeInfo(String
fullyQualifiedInstanceId, FunctionRun
public void close() throws Exception {
this.functionActioner.close();
this.functionAssignmentTailer.close();
+ if (runtimeFactory != null) {
+ runtimeFactory.close();
+ }
}
private Map<String, Assignment> diff(Map<String, Assignment>
assignmentMap1, Map<String, Assignment> assignmentMap2) {
----------------------------------------------------------------
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]
With regards,
Apache Git Services