From ddb805951ecd7602926afbc024fcb83794bc8489 Mon Sep 17 00:00:00 2001 From: fuchaohong <1783129294@qq.com> Date: Tue, 30 Apr 2024 12:18:47 +0800 Subject: [PATCH] HDFS-17471. Correct the percentage of sample range. (#6742). Contributed by fuchaohong. Signed-off-by: He Xiaoqiao --- .../hadoop/hdfs/client/impl/metrics/BlockReaderIoProvider.java | 2 +- .../hadoop/hdfs/server/datanode/ProfilingFileIoEvents.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/client/impl/metrics/BlockReaderIoProvider.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/client/impl/metrics/BlockReaderIoProvider.java index 0792db80b6..7e535a071d 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/client/impl/metrics/BlockReaderIoProvider.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/client/impl/metrics/BlockReaderIoProvider.java @@ -65,7 +65,7 @@ public BlockReaderIoProvider(@Nullable ShortCircuitConf conf, public int read(FileChannel dataIn, ByteBuffer dst, long position) throws IOException{ final int nRead; - if (isEnabled && (ThreadLocalRandom.current().nextInt() < sampleRangeMax)) { + if (isEnabled && (ThreadLocalRandom.current().nextInt(Integer.MAX_VALUE) < sampleRangeMax)) { long begin = timer.monotonicNow(); nRead = dataIn.read(dst, position); long latency = timer.monotonicNow() - begin; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/ProfilingFileIoEvents.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/ProfilingFileIoEvents.java index c22401b645..dbaf047ef3 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/ProfilingFileIoEvents.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/ProfilingFileIoEvents.java @@ -80,7 +80,7 @@ public void afterMetadataOp(@Nullable FsVolumeSpi volume, public long beforeFileIo(@Nullable FsVolumeSpi volume, FileIoProvider.OPERATION op, long len) { - if (isEnabled && ThreadLocalRandom.current().nextInt() < sampleRangeMax) { + if (isEnabled && ThreadLocalRandom.current().nextInt(Integer.MAX_VALUE) < sampleRangeMax) { DataNodeVolumeMetrics metrics = getVolumeMetrics(volume); if (metrics != null) { return Time.monotonicNow();