You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@linkis.apache.org by ca...@apache.org on 2023/06/19 08:07:53 UTC
[linkis] branch dev-1.4.0 updated: fix: reuseEngine may throw NullPointerException exception #4662 (#4663)
This is an automated email from the ASF dual-hosted git repository.
casion pushed a commit to branch dev-1.4.0
in repository https://gitbox.apache.org/repos/asf/linkis.git
The following commit(s) were added to refs/heads/dev-1.4.0 by this push:
new 114937484 fix: reuseEngine may throw NullPointerException exception #4662 (#4663)
114937484 is described below
commit 114937484b4b6dbcf20ab1ee0038aee0770a12a2
Author: CharlieYan <16...@users.noreply.github.com>
AuthorDate: Mon Jun 19 16:07:47 2023 +0800
fix: reuseEngine may throw NullPointerException exception #4662 (#4663)
---
.../service/engine/DefaultEngineReuseService.java | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/linkis-computation-governance/linkis-manager/linkis-application-manager/src/main/java/org/apache/linkis/manager/am/service/engine/DefaultEngineReuseService.java b/linkis-computation-governance/linkis-manager/linkis-application-manager/src/main/java/org/apache/linkis/manager/am/service/engine/DefaultEngineReuseService.java
index 9c9e9ef92..53c4fd3f1 100644
--- a/linkis-computation-governance/linkis-manager/linkis-application-manager/src/main/java/org/apache/linkis/manager/am/service/engine/DefaultEngineReuseService.java
+++ b/linkis-computation-governance/linkis-manager/linkis-application-manager/src/main/java/org/apache/linkis/manager/am/service/engine/DefaultEngineReuseService.java
@@ -45,6 +45,8 @@ import org.apache.linkis.manager.label.utils.LabelUtils;
import org.apache.linkis.rpc.Sender;
import org.apache.linkis.rpc.message.annotation.Receiver;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.compress.utils.Lists;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.commons.lang3.tuple.MutablePair;
@@ -162,7 +164,7 @@ public class DefaultEngineReuseService extends AbstractEngineService implements
instances.keySet().toArray(new ScoreServiceInstance[0]);
EngineNode[] engineScoreList = getEngineNodeManager().getEngineNodes(scoreServiceInstances);
- EngineNode engine = null;
+ List<EngineNode> engines = Lists.newArrayList();
int count = 1;
long timeout =
engineReuseRequest.getTimeOut() <= 0
@@ -176,7 +178,7 @@ public class DefaultEngineReuseService extends AbstractEngineService implements
long startTime = System.currentTimeMillis();
try {
LinkisUtils.waitUntil(
- () -> selectEngineToReuse(MutablePair.of(count, reuseLimit), engine, engineScoreList),
+ () -> selectEngineToReuse(MutablePair.of(count, reuseLimit), engines, engineScoreList),
Duration.ofMillis(timeout));
} catch (TimeoutException e) {
throw new LinkisRetryException(
@@ -189,6 +191,7 @@ public class DefaultEngineReuseService extends AbstractEngineService implements
AMConstant.ENGINE_ERROR_CODE,
"Failed to reuse engineConn time taken " + (System.currentTimeMillis() - startTime));
}
+ EngineNode engine = engines.get(0);
logger.info(
"Finished to reuse Engine for request: "
+ engineReuseRequest
@@ -201,7 +204,7 @@ public class DefaultEngineReuseService extends AbstractEngineService implements
.stream()
.filter(kv -> kv.getKey().getServiceInstance().equals(engine.getServiceInstance()))
.collect(Collectors.toList());
- if (engineServiceLabelList != null && !engineServiceLabelList.isEmpty()) {
+ if (!engineServiceLabelList.isEmpty()) {
engine.setLabels(engineServiceLabelList.get(0).getValue());
} else {
logger.info(
@@ -216,7 +219,7 @@ public class DefaultEngineReuseService extends AbstractEngineService implements
public boolean selectEngineToReuse(
MutablePair<Integer, Integer> count2reuseLimit,
- EngineNode engine,
+ List<EngineNode> engines,
EngineNode[] engineScoreList) {
if (count2reuseLimit.getLeft() > count2reuseLimit.getRight()) {
throw new LinkisRetryException(
@@ -229,7 +232,8 @@ public class DefaultEngineReuseService extends AbstractEngineService implements
}
EngineNode engineNode = (EngineNode) choseNode.get();
logger.info("prepare to reuse engineNode: " + engineNode.getServiceInstance());
- engine =
+
+ EngineNode reuseEngine =
LinkisUtils.tryCatch(
() -> getEngineNodeManager().reuseEngine(engineNode),
(Throwable t) -> {
@@ -244,7 +248,11 @@ public class DefaultEngineReuseService extends AbstractEngineService implements
}
return null;
});
- if (engine == null) {
+ if (Objects.nonNull(reuseEngine)) {
+ engines.add(reuseEngine);
+ }
+
+ if (CollectionUtils.isEmpty(engines)) {
Integer count = count2reuseLimit.getKey() + 1;
count2reuseLimit.setLeft(count);
engineScoreList =
@@ -252,6 +260,6 @@ public class DefaultEngineReuseService extends AbstractEngineService implements
.filter(node -> !node.equals(choseNode.get()))
.toArray(EngineNode[]::new);
}
- return engine != null;
+ return CollectionUtils.isNotEmpty(engines);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@linkis.apache.org
For additional commands, e-mail: commits-help@linkis.apache.org