From e322d024bacb56ac6a99065b3578f0e3c989e1d5 Mon Sep 17 00:00:00 2001 From: PHILO-HE Date: Fri, 1 Jun 2018 17:59:54 +0800 Subject: [PATCH] Avoid NPE when tackling timeout action (#1780) --- .../org/smartdata/server/engine/CmdletManager.java | 14 ++++++++++---- .../server/engine/cmdlet/CmdletDispatcher.java | 4 +++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/smart-engine/src/main/java/org/smartdata/server/engine/CmdletManager.java b/smart-engine/src/main/java/org/smartdata/server/engine/CmdletManager.java index 4d7eec17133..fba2849fce6 100644 --- a/smart-engine/src/main/java/org/smartdata/server/engine/CmdletManager.java +++ b/smart-engine/src/main/java/org/smartdata/server/engine/CmdletManager.java @@ -79,7 +79,8 @@ */ public class CmdletManager extends AbstractService { private static final Logger LOG = LoggerFactory.getLogger(CmdletManager.class); - public static final long TIMEOUT_MULTIPLIER = 60; + public static final int TIMEOUT_MULTIPLIER = 100; + public static final int TIMEOUT_MIN_MILLISECOND = 30000; public static final String TIMEOUTLOG = "Timeout error occurred for getting this action's status report."; public static final String ACTION_SKIP_LOG = @@ -137,9 +138,12 @@ public CmdletManager(ServerContext context) throws IOException { SmartConfKeys.SMART_CMDLET_CACHE_BATCH_DEFAULT); int reportPeriod = context.getConf().getInt(SmartConfKeys.SMART_STATUS_REPORT_PERIOD_KEY, - SmartConfKeys.SMART_STATUS_REPORT_PERIOD_DEFAULT); - this.timeout = - TIMEOUT_MULTIPLIER * reportPeriod < 30000 ? 30000 : TIMEOUT_MULTIPLIER * reportPeriod; + SmartConfKeys.SMART_STATUS_REPORT_PERIOD_DEFAULT); + int maxInterval = reportPeriod * context.getConf().getInt( + SmartConfKeys.SMART_STATUS_REPORT_PERIOD_MULTIPLIER_KEY, + SmartConfKeys.SMART_STATUS_REPORT_PERIOD_MULTIPLIER_DEFAULT); + this.timeout = TIMEOUT_MULTIPLIER * maxInterval < TIMEOUT_MIN_MILLISECOND + ? TIMEOUT_MIN_MILLISECOND : TIMEOUT_MULTIPLIER * maxInterval; } @VisibleForTesting @@ -1181,6 +1185,8 @@ public void run() { LOG.error(e.getMessage()); } catch (IOException e) { LOG.error(e.getMessage()); + } catch (Throwable t) { + LOG.error("Unexpected exception occurs.", t); } } diff --git a/smart-engine/src/main/java/org/smartdata/server/engine/cmdlet/CmdletDispatcher.java b/smart-engine/src/main/java/org/smartdata/server/engine/cmdlet/CmdletDispatcher.java index ffed5c4cb4e..701e2616d1a 100644 --- a/smart-engine/src/main/java/org/smartdata/server/engine/cmdlet/CmdletDispatcher.java +++ b/smart-engine/src/main/java/org/smartdata/server/engine/cmdlet/CmdletDispatcher.java @@ -399,7 +399,9 @@ public void onCmdletFinished(long cmdletId) { synchronized (dispatchedToSrvs) { if (dispatchedToSrvs.containsKey(cmdletId)) { LaunchCmdlet cmdlet = idToLaunchCmdlet.get(cmdletId); - regNodes.get(cmdlet.getNodeId()).incrementAndGet(); + if (regNodes.get(cmdlet.getNodeId()) != null) { + regNodes.get(cmdlet.getNodeId()).incrementAndGet(); + } ExecutorType t = dispatchedToSrvs.remove(cmdletId); updateSlotsLeft(t.ordinal(), 1); completeOn[t.ordinal()] = cmdlet.getNodeId();