浏览代码

HDFS-17471. Correct the percentage of sample range. (#6742). Contributed by fuchaohong.

Signed-off-by: He Xiaoqiao <hexiaoqiao@apache.org>
fuchaohong 1 年之前
父节点
当前提交
ddb805951e

+ 1 - 1
hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/client/impl/metrics/BlockReaderIoProvider.java

@@ -65,7 +65,7 @@ public class BlockReaderIoProvider {
   public int read(FileChannel dataIn, ByteBuffer dst, long position)
   public int read(FileChannel dataIn, ByteBuffer dst, long position)
       throws IOException{
       throws IOException{
     final int nRead;
     final int nRead;
-    if (isEnabled && (ThreadLocalRandom.current().nextInt() < sampleRangeMax)) {
+    if (isEnabled && (ThreadLocalRandom.current().nextInt(Integer.MAX_VALUE) < sampleRangeMax)) {
       long begin = timer.monotonicNow();
       long begin = timer.monotonicNow();
       nRead = dataIn.read(dst, position);
       nRead = dataIn.read(dst, position);
       long latency = timer.monotonicNow() - begin;
       long latency = timer.monotonicNow() - begin;

+ 1 - 1
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/ProfilingFileIoEvents.java

@@ -80,7 +80,7 @@ class ProfilingFileIoEvents {
 
 
   public long beforeFileIo(@Nullable FsVolumeSpi volume,
   public long beforeFileIo(@Nullable FsVolumeSpi volume,
       FileIoProvider.OPERATION op, long len) {
       FileIoProvider.OPERATION op, long len) {
-    if (isEnabled && ThreadLocalRandom.current().nextInt() < sampleRangeMax) {
+    if (isEnabled && ThreadLocalRandom.current().nextInt(Integer.MAX_VALUE) < sampleRangeMax) {
       DataNodeVolumeMetrics metrics = getVolumeMetrics(volume);
       DataNodeVolumeMetrics metrics = getVolumeMetrics(volume);
       if (metrics != null) {
       if (metrics != null) {
         return Time.monotonicNow();
         return Time.monotonicNow();