YARN-10680. Revisit try blocks without catch blocks but having finally blocks. Contributed by Susheel Gupta

This commit is contained in:
Szilard Nemeth 2022-10-15 21:51:08 +02:00
parent 77e551a478
commit b0d5182c31
3 changed files with 25 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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();
}