From b0d5182c31043d70d614d3378c42974d6f468b27 Mon Sep 17 00:00:00 2001 From: Szilard Nemeth Date: Sat, 15 Oct 2022 21:51:08 +0200 Subject: [PATCH] YARN-10680. Revisit try blocks without catch blocks but having finally blocks. Contributed by Susheel Gupta --- .../yarn/sls/scheduler/SLSCapacityScheduler.java | 10 +++++++++- .../hadoop/yarn/sls/scheduler/SLSFairScheduler.java | 10 +++++++++- .../hadoop/yarn/sls/scheduler/SchedulerMetrics.java | 8 +++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/scheduler/SLSCapacityScheduler.java b/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/scheduler/SLSCapacityScheduler.java index 18e12cca05..6cc4cf7597 100644 --- a/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/scheduler/SLSCapacityScheduler.java +++ b/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/scheduler/SLSCapacityScheduler.java @@ -36,6 +36,8 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.ResourceCommitRequest; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.SchedulerEvent; import org.apache.hadoop.yarn.sls.SLSRunner; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @Private @Unstable @@ -45,6 +47,7 @@ public class SLSCapacityScheduler extends CapacityScheduler implements private final SLSSchedulerCommons schedulerCommons; private Configuration conf; private SLSRunner runner; + private static final Logger LOG = LoggerFactory.getLogger(SLSCapacityScheduler.class); public SLSCapacityScheduler() { schedulerCommons = new SLSSchedulerCommons(this); @@ -105,7 +108,12 @@ public boolean tryCommit(Resource cluster, ResourceCommitRequest r, @Override public void handle(SchedulerEvent schedulerEvent) { - schedulerCommons.handle(schedulerEvent); + try { + schedulerCommons.handle(schedulerEvent); + } catch(Exception e) { + LOG.error("Caught exception while handling scheduler event", e); + throw e; + } } @Override diff --git a/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/scheduler/SLSFairScheduler.java b/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/scheduler/SLSFairScheduler.java index 1b4d5ced69..beb411025f 100644 --- a/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/scheduler/SLSFairScheduler.java +++ b/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/scheduler/SLSFairScheduler.java @@ -31,6 +31,8 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.SchedulerEvent; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler; import org.apache.hadoop.yarn.sls.SLSRunner; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.List; @@ -40,6 +42,7 @@ public class SLSFairScheduler extends FairScheduler implements SchedulerWrapper, Configurable { private final SLSSchedulerCommons schedulerCommons; private SLSRunner runner; + private static final Logger LOG = LoggerFactory.getLogger(SLSFairScheduler.class); public SLSFairScheduler() { schedulerCommons = new SLSSchedulerCommons(this); @@ -63,7 +66,12 @@ public Allocation allocate(ApplicationAttemptId attemptId, @Override public void handle(SchedulerEvent schedulerEvent) { - schedulerCommons.handle(schedulerEvent); + try { + schedulerCommons.handle(schedulerEvent); + } catch (Exception e){ + LOG.error("Caught exception while handling scheduler event", e); + throw e; + } } @Override diff --git a/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/scheduler/SchedulerMetrics.java b/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/scheduler/SchedulerMetrics.java index a1e530a6f7..f66cf4384d 100644 --- a/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/scheduler/SchedulerMetrics.java +++ b/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/scheduler/SchedulerMetrics.java @@ -178,7 +178,7 @@ void init(ResourceScheduler resourceScheduler, Configuration config) pool.scheduleAtFixedRate(new HistogramsRunnable(), 0, 1000, TimeUnit.MILLISECONDS); - // a thread to output metrics for real-tiem tracking + // a thread to output metrics for real-time tracking pool.scheduleAtFixedRate(new MetricsLogRunnable(), 0, 1000, TimeUnit.MILLISECONDS); @@ -467,6 +467,9 @@ private void registerSchedulerMetrics() { schedulerHistogramList.add(histogram); histogramTimerMap.put(histogram, schedulerHandleTimerMap.get(e)); } + } catch (Exception e) { + LOG.error("Caught exception while registering scheduler metrics", e); + throw e; } finally { samplerLock.unlock(); } @@ -510,6 +513,9 @@ public Integer getValue() { } ); } + } catch (Exception e) { + LOG.error("Caught exception while registering nodes usage metrics", e); + throw e; } finally { samplerLock.unlock(); }