You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ma...@apache.org on 2023/02/21 06:08:57 UTC
[iotdb] branch master updated: [IOTDB-5562] Change the data type of AutoGuage from long to double in metric module (#9107)
This is an automated email from the ASF dual-hosted git repository.
marklau99 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 e204dddfc8 [IOTDB-5562] Change the data type of AutoGuage from long to double in metric module (#9107)
e204dddfc8 is described below
commit e204dddfc8bdc3b99605c3a6be6930dd89e010fd
Author: Potato <ta...@apache.org>
AuthorDate: Tue Feb 21 14:08:51 2023 +0800
[IOTDB-5562] Change the data type of AutoGuage from long to double in metric module (#9107)
---
.../manager/load/balancer/RegionBalancer.java | 2 +-
.../region/CopySetRegionGroupAllocator.java | 2 +-
.../region/GreedyRegionGroupAllocator.java | 8 +++----
.../balancer/region/IRegionGroupAllocator.java | 2 +-
.../iotdb/confignode/manager/node/NodeManager.java | 4 ++--
.../node/heartbeat/DataNodeHeartbeatCache.java | 4 ++--
.../region/GreedyRegionGroupAllocatorTest.java | 14 +++++------
.../dropwizard/DropwizardMetricManager.java | 4 ++--
.../dropwizard/type/DropwizardAutoGauge.java | 16 ++++++-------
.../iotdb/metrics/AbstractMetricManager.java | 27 ++++++++++-----------
.../iotdb/metrics/AbstractMetricService.java | 6 ++---
.../iotdb/metrics/impl/DoNothingAutoGauge.java | 4 ++--
.../iotdb/metrics/impl/DoNothingMetricManager.java | 28 +++++++++++-----------
.../org/apache/iotdb/metrics/type/AutoGauge.java | 2 +-
.../micrometer/MicrometerMetricManager.java | 6 ++---
.../micrometer/type/MicrometerAutoGauge.java | 17 +++++++------
.../iotdb/db/service/metrics/SystemMetrics.java | 2 +-
.../impl/DataNodeInternalRPCServiceImpl.java | 24 +++++++++----------
.../apache/iotdb/db/metric/MetricServiceTest.java | 24 ++++++++++---------
thrift/src/main/thrift/datanode.thrift | 4 ++--
20 files changed, 100 insertions(+), 100 deletions(-)
diff --git a/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/RegionBalancer.java b/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/RegionBalancer.java
index 2a33f6bcd7..882a5eeebe 100644
--- a/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/RegionBalancer.java
+++ b/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/RegionBalancer.java
@@ -106,7 +106,7 @@ public class RegionBalancer {
for (int i = 0; i < allotment; i++) {
// Prepare input data
Map<Integer, TDataNodeConfiguration> availableDataNodeMap = new ConcurrentHashMap<>();
- Map<Integer, Long> freeDiskSpaceMap = new ConcurrentHashMap<>();
+ Map<Integer, Double> freeDiskSpaceMap = new ConcurrentHashMap<>();
targetDataNodes.forEach(
dataNodeConfiguration -> {
int dataNodeId = dataNodeConfiguration.getLocation().getDataNodeId();
diff --git a/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/region/CopySetRegionGroupAllocator.java b/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/region/CopySetRegionGroupAllocator.java
index c801e2b353..cf9255469e 100644
--- a/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/region/CopySetRegionGroupAllocator.java
+++ b/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/region/CopySetRegionGroupAllocator.java
@@ -51,7 +51,7 @@ public class CopySetRegionGroupAllocator implements IRegionGroupAllocator {
@Override
public TRegionReplicaSet generateOptimalRegionReplicasDistribution(
Map<Integer, TDataNodeConfiguration> availableDataNodeMap,
- Map<Integer, Long> freeDiskSpaceMap,
+ Map<Integer, Double> freeDiskSpaceMap,
List<TRegionReplicaSet> allocatedRegionGroups,
int replicationFactor,
TConsensusGroupId consensusGroupId) {
diff --git a/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/region/GreedyRegionGroupAllocator.java b/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/region/GreedyRegionGroupAllocator.java
index 5c0fdc1724..f95041ab74 100644
--- a/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/region/GreedyRegionGroupAllocator.java
+++ b/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/region/GreedyRegionGroupAllocator.java
@@ -45,7 +45,7 @@ public class GreedyRegionGroupAllocator implements IRegionGroupAllocator {
@Override
public TRegionReplicaSet generateOptimalRegionReplicasDistribution(
Map<Integer, TDataNodeConfiguration> availableDataNodeMap,
- Map<Integer, Long> freeDiskSpaceMap,
+ Map<Integer, Double> freeDiskSpaceMap,
List<TRegionReplicaSet> allocatedRegionGroups,
int replicationFactor,
TConsensusGroupId consensusGroupId) {
@@ -59,7 +59,7 @@ public class GreedyRegionGroupAllocator implements IRegionGroupAllocator {
private List<TDataNodeLocation> buildWeightList(
Map<Integer, TDataNodeConfiguration> availableDataNodeMap,
- Map<Integer, Long> freeDiskSpaceMap,
+ Map<Integer, Double> freeDiskSpaceMap,
List<TRegionReplicaSet> allocatedRegionGroups) {
// Map<DataNodeId, Region count>
Map<Integer, AtomicInteger> regionCounter = new ConcurrentHashMap<>();
@@ -75,7 +75,7 @@ public class GreedyRegionGroupAllocator implements IRegionGroupAllocator {
.getAndIncrement()));
/* Construct priority map */
- Map<TDataNodeLocation, Pair<Integer, Long>> priorityMap = new ConcurrentHashMap<>();
+ Map<TDataNodeLocation, Pair<Integer, Double>> priorityMap = new ConcurrentHashMap<>();
availableDataNodeMap
.keySet()
.forEach(
@@ -84,7 +84,7 @@ public class GreedyRegionGroupAllocator implements IRegionGroupAllocator {
availableDataNodeMap.get(dataNodeId).getLocation(),
new Pair<>(
regionCounter.getOrDefault(dataNodeId, ZERO).get(),
- freeDiskSpaceMap.getOrDefault(dataNodeId, 0L))));
+ freeDiskSpaceMap.getOrDefault(dataNodeId, 0d))));
return priorityMap.entrySet().stream()
.sorted(
diff --git a/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/region/IRegionGroupAllocator.java b/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/region/IRegionGroupAllocator.java
index c33f2ead2d..0a3f3f568e 100644
--- a/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/region/IRegionGroupAllocator.java
+++ b/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/region/IRegionGroupAllocator.java
@@ -39,7 +39,7 @@ public interface IRegionGroupAllocator {
*/
TRegionReplicaSet generateOptimalRegionReplicasDistribution(
Map<Integer, TDataNodeConfiguration> availableDataNodeMap,
- Map<Integer, Long> freeDiskSpaceMap,
+ Map<Integer, Double> freeDiskSpaceMap,
List<TRegionReplicaSet> allocatedRegionGroups,
int replicationFactor,
TConsensusGroupId consensusGroupId);
diff --git a/confignode/src/main/java/org/apache/iotdb/confignode/manager/node/NodeManager.java b/confignode/src/main/java/org/apache/iotdb/confignode/manager/node/NodeManager.java
index a7040004c0..2c929d4385 100644
--- a/confignode/src/main/java/org/apache/iotdb/confignode/manager/node/NodeManager.java
+++ b/confignode/src/main/java/org/apache/iotdb/confignode/manager/node/NodeManager.java
@@ -911,10 +911,10 @@ public class NodeManager {
* @param dataNodeId The index of the specified DataNode
* @return The free disk space that sample through heartbeat, 0 if no heartbeat received
*/
- public long getFreeDiskSpace(int dataNodeId) {
+ public double getFreeDiskSpace(int dataNodeId) {
DataNodeHeartbeatCache dataNodeHeartbeatCache =
(DataNodeHeartbeatCache) nodeCacheMap.get(dataNodeId);
- return dataNodeHeartbeatCache == null ? 0 : dataNodeHeartbeatCache.getFreeDiskSpace();
+ return dataNodeHeartbeatCache == null ? 0d : dataNodeHeartbeatCache.getFreeDiskSpace();
}
/**
diff --git a/confignode/src/main/java/org/apache/iotdb/confignode/manager/node/heartbeat/DataNodeHeartbeatCache.java b/confignode/src/main/java/org/apache/iotdb/confignode/manager/node/heartbeat/DataNodeHeartbeatCache.java
index 3965fc6566..5754d27320 100644
--- a/confignode/src/main/java/org/apache/iotdb/confignode/manager/node/heartbeat/DataNodeHeartbeatCache.java
+++ b/confignode/src/main/java/org/apache/iotdb/confignode/manager/node/heartbeat/DataNodeHeartbeatCache.java
@@ -29,7 +29,7 @@ public class DataNodeHeartbeatCache extends BaseNodeCache {
/** Constructor for create DataNodeHeartbeatCache with default NodeStatistics */
public DataNodeHeartbeatCache() {
super();
- this.latestLoadSample = new TLoadSample((short) 0, 0, 0, 0);
+ this.latestLoadSample = new TLoadSample();
}
@Override
@@ -70,7 +70,7 @@ public class DataNodeHeartbeatCache extends BaseNodeCache {
}
}
- public long getFreeDiskSpace() {
+ public double getFreeDiskSpace() {
return latestLoadSample.getFreeDiskSpace();
}
}
diff --git a/confignode/src/test/java/org/apache/iotdb/confignode/manager/load/balancer/region/GreedyRegionGroupAllocatorTest.java b/confignode/src/test/java/org/apache/iotdb/confignode/manager/load/balancer/region/GreedyRegionGroupAllocatorTest.java
index fa9c2378ef..67aebe6ba6 100644
--- a/confignode/src/test/java/org/apache/iotdb/confignode/manager/load/balancer/region/GreedyRegionGroupAllocatorTest.java
+++ b/confignode/src/test/java/org/apache/iotdb/confignode/manager/load/balancer/region/GreedyRegionGroupAllocatorTest.java
@@ -45,13 +45,13 @@ public class GreedyRegionGroupAllocatorTest {
public void testEvenDistribution() {
/* Construct input data */
Map<Integer, TDataNodeConfiguration> availableDataNodeMap = new ConcurrentHashMap<>();
- Map<Integer, Long> freeSpaceMap = new ConcurrentHashMap<>();
+ Map<Integer, Double> freeSpaceMap = new ConcurrentHashMap<>();
Random random = new Random();
// Set 6 DataNodes
for (int i = 0; i < 6; i++) {
availableDataNodeMap.put(
i, new TDataNodeConfiguration().setLocation(new TDataNodeLocation().setDataNodeId(i)));
- freeSpaceMap.put(i, random.nextLong());
+ freeSpaceMap.put(i, random.nextDouble());
}
/* Allocate 6 RegionGroups */
@@ -94,11 +94,11 @@ public class GreedyRegionGroupAllocatorTest {
availableDataNodeMap.put(
i, new TDataNodeConfiguration().setLocation(new TDataNodeLocation().setDataNodeId(i)));
}
- Map<Integer, Long> freeSpaceMap = new ConcurrentHashMap<>();
- freeSpaceMap.put(0, 20000331L);
- freeSpaceMap.put(1, 20000522L);
- freeSpaceMap.put(2, 666L);
- freeSpaceMap.put(3, 999L);
+ Map<Integer, Double> freeSpaceMap = new ConcurrentHashMap<>();
+ freeSpaceMap.put(0, 20000331d);
+ freeSpaceMap.put(1, 20000522d);
+ freeSpaceMap.put(2, 666d);
+ freeSpaceMap.put(3, 999d);
/* Allocate the first RegionGroup */
List<TRegionReplicaSet> allocatedRegionGroups = new ArrayList<>();
diff --git a/metrics/dropwizard-metrics/src/main/java/org/apache/iotdb/metrics/dropwizard/DropwizardMetricManager.java b/metrics/dropwizard-metrics/src/main/java/org/apache/iotdb/metrics/dropwizard/DropwizardMetricManager.java
index 34d69870bc..5fa25f3a45 100644
--- a/metrics/dropwizard-metrics/src/main/java/org/apache/iotdb/metrics/dropwizard/DropwizardMetricManager.java
+++ b/metrics/dropwizard-metrics/src/main/java/org/apache/iotdb/metrics/dropwizard/DropwizardMetricManager.java
@@ -38,7 +38,7 @@ import org.apache.iotdb.metrics.utils.MetricType;
import com.codahale.metrics.MetricFilter;
import com.codahale.metrics.MetricRegistry;
-import java.util.function.ToLongFunction;
+import java.util.function.ToDoubleFunction;
/**
* Metric manager based on dropwizard metrics. More details in https://metrics.dropwizard.io/4.1.2/.
@@ -58,7 +58,7 @@ public class DropwizardMetricManager extends AbstractMetricManager {
}
@Override
- public <T> AutoGauge createAutoGauge(MetricInfo metricInfo, T obj, ToLongFunction<T> mapper) {
+ public <T> AutoGauge createAutoGauge(MetricInfo metricInfo, T obj, ToDoubleFunction<T> mapper) {
DropwizardAutoGauge<T> dropwizardGauge = new DropwizardAutoGauge<>(obj, mapper);
metricRegistry.register(DropwizardMetricNameTool.toFlatString(metricInfo), dropwizardGauge);
return dropwizardGauge;
diff --git a/metrics/dropwizard-metrics/src/main/java/org/apache/iotdb/metrics/dropwizard/type/DropwizardAutoGauge.java b/metrics/dropwizard-metrics/src/main/java/org/apache/iotdb/metrics/dropwizard/type/DropwizardAutoGauge.java
index 288ffc9fbc..172f020fd9 100644
--- a/metrics/dropwizard-metrics/src/main/java/org/apache/iotdb/metrics/dropwizard/type/DropwizardAutoGauge.java
+++ b/metrics/dropwizard-metrics/src/main/java/org/apache/iotdb/metrics/dropwizard/type/DropwizardAutoGauge.java
@@ -22,28 +22,28 @@ package org.apache.iotdb.metrics.dropwizard.type;
import org.apache.iotdb.metrics.type.AutoGauge;
import java.lang.ref.WeakReference;
-import java.util.function.ToLongFunction;
+import java.util.function.ToDoubleFunction;
-public class DropwizardAutoGauge<T> implements AutoGauge, com.codahale.metrics.Gauge<Long> {
+public class DropwizardAutoGauge<T> implements AutoGauge, com.codahale.metrics.Gauge<Double> {
private final WeakReference<T> refObject;
- private final ToLongFunction<T> mapper;
+ private final ToDoubleFunction<T> mapper;
- public DropwizardAutoGauge(T obj, ToLongFunction<T> mapper) {
+ public DropwizardAutoGauge(T obj, ToDoubleFunction<T> mapper) {
this.refObject = new WeakReference<>(obj);
this.mapper = mapper;
}
@Override
- public Long getValue() {
+ public Double getValue() {
if (refObject.get() == null) {
- return 0L;
+ return 0d;
}
- return mapper.applyAsLong(refObject.get());
+ return mapper.applyAsDouble(refObject.get());
}
@Override
- public long value() {
+ public double value() {
return getValue();
}
}
diff --git a/metrics/interface/src/main/java/org/apache/iotdb/metrics/AbstractMetricManager.java b/metrics/interface/src/main/java/org/apache/iotdb/metrics/AbstractMetricManager.java
index ffd77eccc6..e077598ba3 100644
--- a/metrics/interface/src/main/java/org/apache/iotdb/metrics/AbstractMetricManager.java
+++ b/metrics/interface/src/main/java/org/apache/iotdb/metrics/AbstractMetricManager.java
@@ -41,7 +41,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
-import java.util.function.ToLongFunction;
+import java.util.function.ToDoubleFunction;
public abstract class AbstractMetricManager {
protected static final MetricConfig METRIC_CONFIG =
@@ -56,7 +56,6 @@ public abstract class AbstractMetricManager {
metrics = new ConcurrentHashMap<>();
}
- // region get or create metric
/**
* Get counter. return if exists, create if not.
*
@@ -67,7 +66,7 @@ public abstract class AbstractMetricManager {
*/
public Counter getOrCreateCounter(String name, MetricLevel metricLevel, String... tags) {
if (invalid(metricLevel, name, tags)) {
- return DoNothingMetricManager.doNothingCounter;
+ return DoNothingMetricManager.DO_NOTHING_COUNTER;
}
MetricInfo metricInfo = new MetricInfo(MetricType.COUNTER, name, tags);
IMetric metric =
@@ -97,12 +96,12 @@ public abstract class AbstractMetricManager {
* @param name the name of name
* @param metricLevel the level of name
* @param obj which will be monitored automatically
- * @param mapper use which to map the obj to a long value
+ * @param mapper use which to map the obj to a double value
*/
public <T> AutoGauge createAutoGauge(
- String name, MetricLevel metricLevel, T obj, ToLongFunction<T> mapper, String... tags) {
+ String name, MetricLevel metricLevel, T obj, ToDoubleFunction<T> mapper, String... tags) {
if (invalid(metricLevel, name, tags)) {
- return DoNothingMetricManager.doNothingAutoGauge;
+ return DoNothingMetricManager.DO_NOTHING_AUTO_GAUGE;
}
MetricInfo metricInfo = new MetricInfo(MetricType.AUTO_GAUGE, name, tags);
AutoGauge gauge = createAutoGauge(metricInfo, obj, mapper);
@@ -116,10 +115,10 @@ public abstract class AbstractMetricManager {
*
* @param metricInfo the metricInfo of autoGauge
* @param obj which will be monitored automatically
- * @param mapper use which to map the obj to a long value
+ * @param mapper use which to map the obj to a double value
*/
protected abstract <T> AutoGauge createAutoGauge(
- MetricInfo metricInfo, T obj, ToLongFunction<T> mapper);
+ MetricInfo metricInfo, T obj, ToDoubleFunction<T> mapper);
/**
* Get autoGauge.
@@ -130,12 +129,12 @@ public abstract class AbstractMetricManager {
*/
public AutoGauge getAutoGauge(String name, MetricLevel metricLevel, String... tags) {
if (invalid(metricLevel, name, tags)) {
- return DoNothingMetricManager.doNothingAutoGauge;
+ return DoNothingMetricManager.DO_NOTHING_AUTO_GAUGE;
}
MetricInfo metricInfo = new MetricInfo(MetricType.AUTO_GAUGE, name, tags);
IMetric metric = metrics.get(metricInfo);
if (metric == null) {
- return DoNothingMetricManager.doNothingAutoGauge;
+ return DoNothingMetricManager.DO_NOTHING_AUTO_GAUGE;
} else if (metric instanceof AutoGauge) {
return (AutoGauge) metric;
}
@@ -153,7 +152,7 @@ public abstract class AbstractMetricManager {
*/
public Gauge getOrCreateGauge(String name, MetricLevel metricLevel, String... tags) {
if (invalid(metricLevel, name, tags)) {
- return DoNothingMetricManager.doNothingGauge;
+ return DoNothingMetricManager.DO_NOTHING_GAUGE;
}
MetricInfo metricInfo = new MetricInfo(MetricType.GAUGE, name, tags);
IMetric metric =
@@ -188,7 +187,7 @@ public abstract class AbstractMetricManager {
*/
public Rate getOrCreateRate(String name, MetricLevel metricLevel, String... tags) {
if (invalid(metricLevel, name, tags)) {
- return DoNothingMetricManager.doNothingRate;
+ return DoNothingMetricManager.DO_NOTHING_RATE;
}
MetricInfo metricInfo = new MetricInfo(MetricType.RATE, name, tags);
IMetric metric =
@@ -223,7 +222,7 @@ public abstract class AbstractMetricManager {
*/
public Histogram getOrCreateHistogram(String name, MetricLevel metricLevel, String... tags) {
if (invalid(metricLevel, name, tags)) {
- return DoNothingMetricManager.doNothingHistogram;
+ return DoNothingMetricManager.DO_NOTHING_HISTOGRAM;
}
MetricInfo metricInfo = new MetricInfo(MetricType.HISTOGRAM, name, tags);
IMetric metric =
@@ -258,7 +257,7 @@ public abstract class AbstractMetricManager {
*/
public Timer getOrCreateTimer(String name, MetricLevel metricLevel, String... tags) {
if (invalid(metricLevel, name, tags)) {
- return DoNothingMetricManager.doNothingTimer;
+ return DoNothingMetricManager.DO_NOTHING_TIMER;
}
MetricInfo metricInfo = new MetricInfo(MetricType.TIMER, name, tags);
IMetric metric =
diff --git a/metrics/interface/src/main/java/org/apache/iotdb/metrics/AbstractMetricService.java b/metrics/interface/src/main/java/org/apache/iotdb/metrics/AbstractMetricService.java
index 3875850cd0..923d1fc950 100644
--- a/metrics/interface/src/main/java/org/apache/iotdb/metrics/AbstractMetricService.java
+++ b/metrics/interface/src/main/java/org/apache/iotdb/metrics/AbstractMetricService.java
@@ -52,7 +52,7 @@ import java.util.Map;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.concurrent.TimeUnit;
-import java.util.function.ToLongFunction;
+import java.util.function.ToDoubleFunction;
/** MetricService is the entry to get all metric features. */
public abstract class AbstractMetricService {
@@ -224,7 +224,7 @@ public abstract class AbstractMetricService {
}
public <T> AutoGauge createAutoGauge(
- String metric, MetricLevel metricLevel, T obj, ToLongFunction<T> mapper, String... tags) {
+ String metric, MetricLevel metricLevel, T obj, ToDoubleFunction<T> mapper, String... tags) {
return metricManager.createAutoGauge(metric, metricLevel, obj, mapper, tags);
}
@@ -279,7 +279,7 @@ public abstract class AbstractMetricService {
/** GetOrCreateAutoGauge with internal report. */
public <T> AutoGauge createAutoGaugeWithInternalReport(
- String metric, MetricLevel metricLevel, T obj, ToLongFunction<T> mapper, String... tags) {
+ String metric, MetricLevel metricLevel, T obj, ToDoubleFunction<T> mapper, String... tags) {
AutoGauge gauge = metricManager.createAutoGauge(metric, metricLevel, obj, mapper, tags);
internalReporter.addAutoGauge(gauge, metric, tags);
return gauge;
diff --git a/metrics/interface/src/main/java/org/apache/iotdb/metrics/impl/DoNothingAutoGauge.java b/metrics/interface/src/main/java/org/apache/iotdb/metrics/impl/DoNothingAutoGauge.java
index 21a31cae48..9ab929dbed 100644
--- a/metrics/interface/src/main/java/org/apache/iotdb/metrics/impl/DoNothingAutoGauge.java
+++ b/metrics/interface/src/main/java/org/apache/iotdb/metrics/impl/DoNothingAutoGauge.java
@@ -23,7 +23,7 @@ import org.apache.iotdb.metrics.type.AutoGauge;
public class DoNothingAutoGauge implements AutoGauge {
@Override
- public long value() {
- return 0;
+ public double value() {
+ return 0d;
}
}
diff --git a/metrics/interface/src/main/java/org/apache/iotdb/metrics/impl/DoNothingMetricManager.java b/metrics/interface/src/main/java/org/apache/iotdb/metrics/impl/DoNothingMetricManager.java
index 3588a0cdfa..af406a7178 100644
--- a/metrics/interface/src/main/java/org/apache/iotdb/metrics/impl/DoNothingMetricManager.java
+++ b/metrics/interface/src/main/java/org/apache/iotdb/metrics/impl/DoNothingMetricManager.java
@@ -30,45 +30,45 @@ import org.apache.iotdb.metrics.utils.MetricInfo;
import org.apache.iotdb.metrics.utils.MetricLevel;
import org.apache.iotdb.metrics.utils.MetricType;
-import java.util.function.ToLongFunction;
+import java.util.function.ToDoubleFunction;
public class DoNothingMetricManager extends AbstractMetricManager {
- public static final DoNothingCounter doNothingCounter = new DoNothingCounter();
- public static final DoNothingHistogram doNothingHistogram = new DoNothingHistogram();
- public static final DoNothingAutoGauge doNothingAutoGauge = new DoNothingAutoGauge();
- public static final DoNothingGauge doNothingGauge = new DoNothingGauge();
- public static final DoNothingRate doNothingRate = new DoNothingRate();
- public static final DoNothingTimer doNothingTimer = new DoNothingTimer();
+ public static final DoNothingCounter DO_NOTHING_COUNTER = new DoNothingCounter();
+ public static final DoNothingHistogram DO_NOTHING_HISTOGRAM = new DoNothingHistogram();
+ public static final DoNothingAutoGauge DO_NOTHING_AUTO_GAUGE = new DoNothingAutoGauge();
+ public static final DoNothingGauge DO_NOTHING_GAUGE = new DoNothingGauge();
+ public static final DoNothingRate DO_NOTHING_RATE = new DoNothingRate();
+ public static final DoNothingTimer DO_NOTHING_TIMER = new DoNothingTimer();
@Override
public Counter createCounter(MetricInfo metricInfo) {
- return doNothingCounter;
+ return DO_NOTHING_COUNTER;
}
@Override
- public <T> AutoGauge createAutoGauge(MetricInfo metricInfo, T obj, ToLongFunction<T> mapper) {
- return doNothingAutoGauge;
+ public <T> AutoGauge createAutoGauge(MetricInfo metricInfo, T obj, ToDoubleFunction<T> mapper) {
+ return DO_NOTHING_AUTO_GAUGE;
}
@Override
public Gauge createGauge(MetricInfo metricInfo) {
- return doNothingGauge;
+ return DO_NOTHING_GAUGE;
}
@Override
public Histogram createHistogram(MetricInfo metricInfo) {
- return doNothingHistogram;
+ return DO_NOTHING_HISTOGRAM;
}
@Override
public Rate createRate(MetricInfo metricInfo) {
- return doNothingRate;
+ return DO_NOTHING_RATE;
}
@Override
public Timer createTimer(MetricInfo metricInfo) {
- return doNothingTimer;
+ return DO_NOTHING_TIMER;
}
@Override
diff --git a/metrics/interface/src/main/java/org/apache/iotdb/metrics/type/AutoGauge.java b/metrics/interface/src/main/java/org/apache/iotdb/metrics/type/AutoGauge.java
index d50765ca75..7c5058fd33 100644
--- a/metrics/interface/src/main/java/org/apache/iotdb/metrics/type/AutoGauge.java
+++ b/metrics/interface/src/main/java/org/apache/iotdb/metrics/type/AutoGauge.java
@@ -23,7 +23,7 @@ import java.util.Map;
public interface AutoGauge extends IMetric {
/** get value according to the state of obj. */
- long value();
+ double value();
@Override
default void constructValueMap(Map<String, Object> result) {
diff --git a/metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/MicrometerMetricManager.java b/metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/MicrometerMetricManager.java
index b1ce1c8c0c..107235f89a 100644
--- a/metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/MicrometerMetricManager.java
+++ b/metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/MicrometerMetricManager.java
@@ -41,7 +41,7 @@ import io.micrometer.core.instrument.Tags;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import java.util.concurrent.atomic.AtomicLong;
-import java.util.function.ToLongFunction;
+import java.util.function.ToDoubleFunction;
/** Metric manager based on micrometer. More details in https://micrometer.io/. */
@SuppressWarnings("common-java:DuplicatedBlocks")
@@ -61,8 +61,8 @@ public class MicrometerMetricManager extends AbstractMetricManager {
}
@Override
- public <T> AutoGauge createAutoGauge(MetricInfo metricInfo, T obj, ToLongFunction<T> mapper) {
- return new MicrometerAutoGauge<T>(
+ public <T> AutoGauge createAutoGauge(MetricInfo metricInfo, T obj, ToDoubleFunction<T> mapper) {
+ return new MicrometerAutoGauge<>(
meterRegistry, metricInfo.getName(), obj, mapper, metricInfo.getTagsInArray());
}
diff --git a/metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/type/MicrometerAutoGauge.java b/metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/type/MicrometerAutoGauge.java
index 98a29bdef2..871dd8ca83 100644
--- a/metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/type/MicrometerAutoGauge.java
+++ b/metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/type/MicrometerAutoGauge.java
@@ -25,31 +25,30 @@ import io.micrometer.core.instrument.Tags;
import org.slf4j.LoggerFactory;
import java.lang.ref.WeakReference;
-import java.util.function.ToLongFunction;
+import java.util.function.ToDoubleFunction;
public class MicrometerAutoGauge<T> implements AutoGauge {
+
private final WeakReference<T> refObject;
- private final ToLongFunction<T> mapper;
+ private final ToDoubleFunction<T> mapper;
public MicrometerAutoGauge(
io.micrometer.core.instrument.MeterRegistry meterRegistry,
String metricName,
T object,
- ToLongFunction<T> mapper,
+ ToDoubleFunction<T> mapper,
String... tags) {
LoggerFactory.getLogger(MicrometerAutoGauge.class).info("{},{}", metricName, tags);
this.refObject =
- new WeakReference<>(
- meterRegistry.gauge(
- metricName, Tags.of(tags), object, value -> (double) mapper.applyAsLong(value)));
+ new WeakReference<>(meterRegistry.gauge(metricName, Tags.of(tags), object, mapper));
this.mapper = mapper;
}
@Override
- public long value() {
+ public double value() {
if (refObject.get() == null) {
- return 0L;
+ return 0d;
}
- return mapper.applyAsLong(refObject.get());
+ return mapper.applyAsDouble(refObject.get());
}
}
diff --git a/server/src/main/java/org/apache/iotdb/db/service/metrics/SystemMetrics.java b/server/src/main/java/org/apache/iotdb/db/service/metrics/SystemMetrics.java
index 7d14b5d9b3..55d15a403c 100644
--- a/server/src/main/java/org/apache/iotdb/db/service/metrics/SystemMetrics.java
+++ b/server/src/main/java/org/apache/iotdb/db/service/metrics/SystemMetrics.java
@@ -101,7 +101,7 @@ public class SystemMetrics implements IMetricSet {
Metric.SYS_CPU_LOAD.toString(),
MetricLevel.CORE,
osMxBean,
- a -> (long) (osMxBean.getSystemCpuLoad() * 100),
+ a -> osMxBean.getSystemCpuLoad() * 100,
Tag.NAME.toString(),
"system");
diff --git a/server/src/main/java/org/apache/iotdb/db/service/thrift/impl/DataNodeInternalRPCServiceImpl.java b/server/src/main/java/org/apache/iotdb/db/service/thrift/impl/DataNodeInternalRPCServiceImpl.java
index 66b4c540cf..49f7ff8a18 100644
--- a/server/src/main/java/org/apache/iotdb/db/service/thrift/impl/DataNodeInternalRPCServiceImpl.java
+++ b/server/src/main/java/org/apache/iotdb/db/service/thrift/impl/DataNodeInternalRPCServiceImpl.java
@@ -954,20 +954,20 @@ public class DataNodeInternalRPCServiceImpl implements IDataNodeRPCService.Iface
TLoadSample loadSample = new TLoadSample();
// Sample cpu load
- long cpuLoad =
+ double cpuLoad =
MetricService.getInstance()
.getAutoGauge(
Metric.SYS_CPU_LOAD.toString(), MetricLevel.CORE, Tag.NAME.toString(), "system")
.value();
if (cpuLoad != 0) {
- loadSample.setCpuUsageRate((short) cpuLoad);
+ loadSample.setCpuUsageRate(cpuLoad);
}
// Sample memory load
- long usedMemory = getMemory("jvm.memory.used.bytes");
- long maxMemory = getMemory("jvm.memory.max.bytes");
+ double usedMemory = getMemory("jvm.memory.used.bytes");
+ double maxMemory = getMemory("jvm.memory.max.bytes");
if (usedMemory != 0 && maxMemory != 0) {
- loadSample.setMemoryUsageRate((double) usedMemory * 100 / maxMemory);
+ loadSample.setMemoryUsageRate(usedMemory * 100 / maxMemory);
}
// Sample disk load
@@ -1020,8 +1020,8 @@ public class DataNodeInternalRPCServiceImpl implements IDataNodeRPCService.Iface
return result;
}
- private long getMemory(String gaugeName) {
- long result = 0;
+ private double getMemory(String gaugeName) {
+ double result = 0d;
try {
//
List<String> heapIds = Arrays.asList("PS Eden Space", "PS Old Eden", "Ps Survivor Space");
@@ -1041,7 +1041,7 @@ public class DataNodeInternalRPCServiceImpl implements IDataNodeRPCService.Iface
}
} catch (Exception e) {
LOGGER.warn("Failed to get memory from metric because: ", e);
- return 0;
+ return 0d;
}
return result;
}
@@ -1049,7 +1049,7 @@ public class DataNodeInternalRPCServiceImpl implements IDataNodeRPCService.Iface
private void sampleDiskLoad(TLoadSample loadSample) {
final CommonConfig commonConfig = CommonDescriptor.getInstance().getConfig();
- long freeDisk =
+ double freeDisk =
MetricService.getInstance()
.getAutoGauge(
Metric.SYS_DISK_FREE_SPACE.toString(),
@@ -1057,7 +1057,7 @@ public class DataNodeInternalRPCServiceImpl implements IDataNodeRPCService.Iface
Tag.NAME.toString(),
"system")
.value();
- long totalDisk =
+ double totalDisk =
MetricService.getInstance()
.getAutoGauge(
Metric.SYS_DISK_TOTAL_SPACE.toString(),
@@ -1067,9 +1067,9 @@ public class DataNodeInternalRPCServiceImpl implements IDataNodeRPCService.Iface
.value();
if (freeDisk != 0 && totalDisk != 0) {
- double freeDiskRatio = (double) freeDisk / totalDisk;
+ double freeDiskRatio = freeDisk / totalDisk;
loadSample.setFreeDiskSpace(freeDisk);
- loadSample.setDiskUsageRate(1.0 - freeDiskRatio);
+ loadSample.setDiskUsageRate(1d - freeDiskRatio);
// Reset NodeStatus if necessary
if (freeDiskRatio < commonConfig.getDiskSpaceWarningThreshold()) {
LOGGER.warn(
diff --git a/server/src/test/java/org/apache/iotdb/db/metric/MetricServiceTest.java b/server/src/test/java/org/apache/iotdb/db/metric/MetricServiceTest.java
index a2381a04e4..e0c7fc91b8 100644
--- a/server/src/test/java/org/apache/iotdb/db/metric/MetricServiceTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/metric/MetricServiceTest.java
@@ -49,6 +49,8 @@ import static org.junit.Assert.assertTrue;
public class MetricServiceTest {
+ private static final double DELTA = 0.000001;
+
private static final MetricConfig metricConfig =
MetricConfigDescriptor.getInstance().getMetricConfig();
private static AbstractMetricService metricService = new DoNothingMetricService();
@@ -99,7 +101,7 @@ public class MetricServiceTest {
"counter4", MetricLevel.IMPORTANT, "tag", "value", "tag2", "value");
assertNotEquals(counter1, counter2);
counter2 = metricService.getOrCreateCounter("counter5", MetricLevel.NORMAL, "tag", "value");
- assertEquals(DoNothingMetricManager.doNothingCounter, counter2);
+ assertEquals(DoNothingMetricManager.DO_NOTHING_COUNTER, counter2);
assertEquals(4, metricService.getMetricsByType(MetricType.COUNTER).size());
metricService.count(10, "counter6", MetricLevel.IMPORTANT, "tag", "value");
assertEquals(5, metricService.getMetricsByType(MetricType.COUNTER).size());
@@ -125,7 +127,7 @@ public class MetricServiceTest {
"gauge4", MetricLevel.IMPORTANT, "tag", "value", "tag2", "value");
assertNotEquals(gauge1, gauge2);
gauge2 = metricService.getOrCreateGauge("gauge5", MetricLevel.NORMAL, "tag", "value");
- assertEquals(DoNothingMetricManager.doNothingGauge, gauge2);
+ assertEquals(DoNothingMetricManager.DO_NOTHING_GAUGE, gauge2);
assertEquals(4, metricService.getMetricsByType(MetricType.GAUGE).size());
metricService.gauge(10, "gauge6", MetricLevel.IMPORTANT, "tag", "value");
assertEquals(5, metricService.getMetricsByType(MetricType.GAUGE).size());
@@ -140,16 +142,16 @@ public class MetricServiceTest {
AutoGauge autoGauge =
metricService.createAutoGauge(
"autoGauge", MetricLevel.IMPORTANT, list, List::size, "tag", "value");
- assertEquals(0L, autoGauge.value());
+ assertEquals(0d, autoGauge.value(), DELTA);
list.add(1);
- assertEquals(1L, autoGauge.value());
+ assertEquals(1d, autoGauge.value(), DELTA);
list.clear();
- assertEquals(0L, autoGauge.value());
+ assertEquals(0d, autoGauge.value(), DELTA);
list.add(1);
- assertEquals(1L, autoGauge.value());
+ assertEquals(1d, autoGauge.value(), DELTA);
list = null;
System.gc();
- assertEquals(0L, autoGauge.value());
+ assertEquals(0d, autoGauge.value(), DELTA);
assertEquals(4, metricService.getMetricsByType(MetricType.GAUGE).size());
assertEquals(1, metricService.getMetricsByType(MetricType.AUTO_GAUGE).size());
metricService.remove(MetricType.AUTO_GAUGE, "autoGauge", "tag", "value");
@@ -175,7 +177,7 @@ public class MetricServiceTest {
assertNotEquals(rate1, rate2);
rate2 = metricService.getOrCreateRate("rate5", MetricLevel.NORMAL, "tag", "value");
assertEquals(4, metricService.getMetricsByType(MetricType.RATE).size());
- assertEquals(DoNothingMetricManager.doNothingRate, rate2);
+ assertEquals(DoNothingMetricManager.DO_NOTHING_RATE, rate2);
metricService.rate(10, "rate6", MetricLevel.IMPORTANT, "tag", "value");
assertEquals(5, metricService.getMetricsByType(MetricType.RATE).size());
metricService.remove(MetricType.RATE, "rate6");
@@ -211,7 +213,7 @@ public class MetricServiceTest {
assertNotEquals(histogram1, histogram2);
histogram2 =
metricService.getOrCreateHistogram("histogram5", MetricLevel.NORMAL, "tag", "value");
- assertEquals(DoNothingMetricManager.doNothingHistogram, histogram2);
+ assertEquals(DoNothingMetricManager.DO_NOTHING_HISTOGRAM, histogram2);
assertEquals(4, metricService.getMetricsByType(MetricType.HISTOGRAM).size());
metricService.histogram(10, "histogram6", MetricLevel.IMPORTANT, "tag", "value");
assertEquals(5, metricService.getMetricsByType(MetricType.HISTOGRAM).size());
@@ -278,10 +280,10 @@ public class MetricServiceTest {
Timer timer =
metricService.getOrCreateTimer("same_name", MetricLevel.IMPORTANT, "tag", "value");
assertNotNull(timer);
- assertNotEquals(DoNothingMetricManager.doNothingTimer, timer);
+ assertNotEquals(DoNothingMetricManager.DO_NOTHING_TIMER, timer);
Counter counter = metricService.getOrCreateCounter("same_name", MetricLevel.IMPORTANT);
assertNotNull(counter);
- assertEquals(DoNothingMetricManager.doNothingCounter, counter);
+ assertEquals(DoNothingMetricManager.DO_NOTHING_COUNTER, counter);
}
private void getOrCreateDifferentMetricsWithSameName() {
diff --git a/thrift/src/main/thrift/datanode.thrift b/thrift/src/main/thrift/datanode.thrift
index cf3fab6143..81ff5c1116 100644
--- a/thrift/src/main/thrift/datanode.thrift
+++ b/thrift/src/main/thrift/datanode.thrift
@@ -227,14 +227,14 @@ struct THeartbeatResp {
struct TLoadSample {
// Percentage of occupied cpu in DataNode
- 1: required i16 cpuUsageRate
+ 1: required double cpuUsageRate
// Percentage of occupied memory space in DataNode
2: required double memoryUsageRate
// Percentage of occupied disk space in DataNode
3: required double diskUsageRate
// The size of free disk space
// Unit: Byte
- 4: required i64 freeDiskSpace
+ 4: required double freeDiskSpace
}
struct TRegionRouteReq {