This is an automated email from the ASF dual-hosted git repository.
rong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new be8fa171e92 [IOTDB-6010] Fix NPE and IndexOutOfRange Exception in CPU
metrics (#10217) (#10224)
be8fa171e92 is described below
commit be8fa171e92f310db6357a33a94a6bffe4c128fa
Author: Liu Xuxin <[email protected]>
AuthorDate: Tue Jun 20 12:00:44 2023 +0800
[IOTDB-6010] Fix NPE and IndexOutOfRange Exception in CPU metrics (#10217)
(#10224)
* 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