Skip to content

Commit 31407d7

Browse files
author
Ravindra Dingankar
committed
log unexpected transfer rate data
1 parent b00ea94 commit 31407d7

3 files changed

Lines changed: 10 additions & 26 deletions

File tree

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSUtil.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,20 +1936,4 @@ public static boolean isParentEntry(final String path, final String parent) {
19361936
return path.charAt(parent.length()) == Path.SEPARATOR_CHAR
19371937
|| parent.equals(Path.SEPARATOR);
19381938
}
1939-
1940-
/**
1941-
* Calculate the transfer rate in bytes/second. Return -1 for any negative input.
1942-
* @param bytes bytes
1943-
* @param durationMS duration in milliseconds
1944-
* @return the number of bytes/second of the transfer rate
1945-
*/
1946-
public static long transferRateBytesPerSecond(long bytes, long durationMS) {
1947-
if (bytes < 0 || durationMS < 0) {
1948-
return -1;
1949-
}
1950-
if (durationMS == 0) {
1951-
durationMS = 1;
1952-
}
1953-
return bytes * 1000 / durationMS;
1954-
}
19551939
}

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataXceiver.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,11 @@ public void readBlock(final ExtendedBlock block,
633633
datanode.metrics.incrBytesRead((int) read);
634634
datanode.metrics.incrBlocksRead();
635635
datanode.metrics.incrTotalReadTime(duration);
636-
datanode.metrics.addReadTransferRate(DFSUtil.transferRateBytesPerSecond(read, duration));
636+
if (read < 0 || duration <= 0) {
637+
LOG.warn("Unexpected value for data transfer bytes={} duration={}", read, duration);
638+
} else {
639+
datanode.metrics.addReadTransferRate(read * 1000 / duration);
640+
}
637641
} catch ( SocketException ignored ) {
638642
LOG.trace("{}:Ignoring exception while serving {} to {}",
639643
dnR, block, remoteAddress, ignored);
@@ -1124,7 +1128,11 @@ public void copyBlock(final ExtendedBlock block,
11241128
datanode.metrics.incrBytesRead((int) read);
11251129
datanode.metrics.incrBlocksRead();
11261130
datanode.metrics.incrTotalReadTime(duration);
1127-
datanode.metrics.addReadTransferRate(DFSUtil.transferRateBytesPerSecond(read, duration));
1131+
if (read < 0 || duration <= 0) {
1132+
LOG.warn("Unexpected value for data transfer bytes={} duration={}", read, duration);
1133+
} else {
1134+
datanode.metrics.addReadTransferRate(read * 1000 / duration);
1135+
}
11281136

11291137
LOG.info("Copied {} to {}", block, peer.getRemoteAddressString());
11301138
} catch (IOException ioe) {

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSUtil.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,12 +1108,4 @@ public void testErrorMessageForInvalidNameservice() throws Exception {
11081108
LambdaTestUtils.intercept(IOException.class, expectedErrorMessage,
11091109
()->DFSUtil.getNNServiceRpcAddressesForCluster(conf));
11101110
}
1111-
1112-
@Test
1113-
public void testTransferRateBytesPerSecond() {
1114-
assertEquals(9830, DFSUtil.transferRateBytesPerSecond(983, 100));
1115-
assertEquals(983000, DFSUtil.transferRateBytesPerSecond(983, 0));
1116-
assertEquals(-1, DFSUtil.transferRateBytesPerSecond(-983, 100));
1117-
assertEquals(-1, DFSUtil.transferRateBytesPerSecond(983, -100));
1118-
}
11191111
}

0 commit comments

Comments
 (0)