From 94784848456a92a6502f3a3c0074e44fba4b19c9 Mon Sep 17 00:00:00 2001 From: Xiaoyu Yao Date: Tue, 17 May 2016 14:57:51 -0700 Subject: [PATCH] HADOOP-13159. Fix potential NPE in Metrics2 source for DecayRpcScheduler. Contributed by Xiaoyu Yao. --- .../org/apache/hadoop/ipc/DecayRpcScheduler.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/DecayRpcScheduler.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/DecayRpcScheduler.java index b39bda26c5..3443d0394a 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/DecayRpcScheduler.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/DecayRpcScheduler.java @@ -206,11 +206,6 @@ public DecayRpcScheduler(int numLevels, String ns, Configuration conf) { this.backOffResponseTimeThresholds = parseBackOffResponseTimeThreshold(ns, conf, numLevels); - // Setup delay timer - Timer timer = new Timer(); - DecayTask task = new DecayTask(this, timer); - timer.scheduleAtFixedRate(task, decayPeriodMillis, decayPeriodMillis); - // Setup response time metrics responseTimeTotalInCurrWindow = new AtomicLongArray(numLevels); responseTimeCountInCurrWindow = new AtomicLongArray(numLevels); @@ -223,6 +218,11 @@ public DecayRpcScheduler(int numLevels, String ns, Configuration conf) { Preconditions.checkArgument(topUsersCount > 0, "the number of top users for scheduler metrics must be at least 1"); + // Setup delay timer + Timer timer = new Timer(); + DecayTask task = new DecayTask(this, timer); + timer.scheduleAtFixedRate(task, decayPeriodMillis, decayPeriodMillis); + MetricsProxy prox = MetricsProxy.getInstance(ns, numLevels); prox.setDelegate(this); prox.registerMetrics2Source(ns); @@ -821,9 +821,10 @@ private void addTopNCallerSummary(MetricsRecordBuilder rb) { final int topCallerCount = 10; TopN topNCallers = getTopCallers(topCallerCount); Map decisions = scheduleCacheRef.get(); - for (int i=0; i < topNCallers.size(); i++) { + final int actualCallerCount = topNCallers.size(); + for (int i = 0; i < actualCallerCount; i++) { NameValuePair entry = topNCallers.poll(); - String topCaller = "Top." + (topCallerCount - i) + "." + + String topCaller = "Top." + (actualCallerCount - i) + "." + "Caller(" + entry.getName() + ")"; String topCallerVolume = topCaller + ".Volume"; String topCallerPriority = topCaller + ".Priority";