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.capacity.Capacity
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.ResourceCommitRequest; 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.server.resourcemanager.scheduler.event.SchedulerEvent;
import org.apache.hadoop.yarn.sls.SLSRunner; import org.apache.hadoop.yarn.sls.SLSRunner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Private @Private
@Unstable @Unstable
@ -45,6 +47,7 @@ public class SLSCapacityScheduler extends CapacityScheduler implements
private final SLSSchedulerCommons schedulerCommons; private final SLSSchedulerCommons schedulerCommons;
private Configuration conf; private Configuration conf;
private SLSRunner runner; private SLSRunner runner;
private static final Logger LOG = LoggerFactory.getLogger(SLSCapacityScheduler.class);
public SLSCapacityScheduler() { public SLSCapacityScheduler() {
schedulerCommons = new SLSSchedulerCommons(this); schedulerCommons = new SLSSchedulerCommons(this);
@ -105,7 +108,12 @@ public class SLSCapacityScheduler extends CapacityScheduler implements
@Override @Override
public void handle(SchedulerEvent schedulerEvent) { 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 @Override

View File

@ -31,6 +31,8 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ContainerUpdates;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.SchedulerEvent; 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.server.resourcemanager.scheduler.fair.FairScheduler;
import org.apache.hadoop.yarn.sls.SLSRunner; import org.apache.hadoop.yarn.sls.SLSRunner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List; import java.util.List;
@ -40,6 +42,7 @@ public class SLSFairScheduler extends FairScheduler
implements SchedulerWrapper, Configurable { implements SchedulerWrapper, Configurable {
private final SLSSchedulerCommons schedulerCommons; private final SLSSchedulerCommons schedulerCommons;
private SLSRunner runner; private SLSRunner runner;
private static final Logger LOG = LoggerFactory.getLogger(SLSFairScheduler.class);
public SLSFairScheduler() { public SLSFairScheduler() {
schedulerCommons = new SLSSchedulerCommons(this); schedulerCommons = new SLSSchedulerCommons(this);
@ -63,7 +66,12 @@ public class SLSFairScheduler extends FairScheduler
@Override @Override
public void handle(SchedulerEvent schedulerEvent) { 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 @Override

View File

@ -178,7 +178,7 @@ public abstract class SchedulerMetrics {
pool.scheduleAtFixedRate(new HistogramsRunnable(), 0, 1000, pool.scheduleAtFixedRate(new HistogramsRunnable(), 0, 1000,
TimeUnit.MILLISECONDS); 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, pool.scheduleAtFixedRate(new MetricsLogRunnable(), 0, 1000,
TimeUnit.MILLISECONDS); TimeUnit.MILLISECONDS);
@ -467,6 +467,9 @@ public abstract class SchedulerMetrics {
schedulerHistogramList.add(histogram); schedulerHistogramList.add(histogram);
histogramTimerMap.put(histogram, schedulerHandleTimerMap.get(e)); histogramTimerMap.put(histogram, schedulerHandleTimerMap.get(e));
} }
} catch (Exception e) {
LOG.error("Caught exception while registering scheduler metrics", e);
throw e;
} finally { } finally {
samplerLock.unlock(); samplerLock.unlock();
} }
@ -510,6 +513,9 @@ public abstract class SchedulerMetrics {
} }
); );
} }
} catch (Exception e) {
LOG.error("Caught exception while registering nodes usage metrics", e);
throw e;
} finally { } finally {
samplerLock.unlock(); samplerLock.unlock();
} }