This is an automated email from the ASF dual-hosted git repository. marklau99 pushed a commit to branch fix-npe-in-cpu-metrics in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit f588be5fa863e0250e7a1c80b538dcb9778b0a28 Author: Liu Xuxin <[email protected]> AuthorDate: Mon Jun 19 23:37:44 2023 +0800 [IOTDB-6010] Fix NPE and IndexOutOfRange Exception in CPU metrics (#10217) * The reason for npe is that when getting cpu time from map, we use get but not getOrDefault, which may cause NPE. * The reason for IndexOutOfBound Exception is that, the size of module map array and thread name array is not the same. --- .../org/apache/iotdb/metrics/metricsets/cpu/CpuUsageMetrics.java | 6 +++--- .../main/java/org/apache/iotdb/commons/concurrent/ThreadName.java | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/cpu/CpuUsageMetrics.java b/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/cpu/CpuUsageMetrics.java index 56a2864f22f..e21ff0471c7 100644 --- a/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/cpu/CpuUsageMetrics.java +++ b/metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/cpu/CpuUsageMetrics.java @@ -251,12 +251,12 @@ public class CpuUsageMetrics implements IMetricSet { for (ThreadInfo threadInfo : threadInfos) { long id = threadInfo.getThreadId(); long beforeCpuTime = beforeThreadCpuTime.getOrDefault(id, 0L); - long afterCpuTime = afterThreadCpuTime.get(id); - if (afterCpuTime < beforeCpuTime) { + long afterCpuTime = afterThreadCpuTime.getOrDefault(id, 0L); + if (afterCpuTime < beforeCpuTime || afterCpuTime == 0L) { continue; } long beforeUserTime = beforeThreadUserTime.getOrDefault(id, 0L); - long afterUserTime = afterThreadUserTime.get(id); + long afterUserTime = afterThreadUserTime.getOrDefault(id, 0L); totalIncrementTime += afterCpuTime - beforeCpuTime; String module = getThreadModuleById(id, threadInfo); String pool = getThreadPoolById(id, threadInfo); diff --git a/node-commons/src/main/java/org/apache/iotdb/commons/concurrent/ThreadName.java b/node-commons/src/main/java/org/apache/iotdb/commons/concurrent/ThreadName.java index 7170d4a4e4c..51783d4c281 100644 --- a/node-commons/src/main/java/org/apache/iotdb/commons/concurrent/ThreadName.java +++ b/node-commons/src/main/java/org/apache/iotdb/commons/concurrent/ThreadName.java @@ -305,7 +305,6 @@ public enum ThreadName { DataNodeThreadModule.IOT_CONSENSUS, DataNodeThreadModule.RATIS_CONSENSUS, DataNodeThreadModule.COMPUTE, - DataNodeThreadModule.SYNC, DataNodeThreadModule.JVM, DataNodeThreadModule.METRICS, DataNodeThreadModule.OTHER
