Skip to content

Commit 6d5e87a

Browse files
committed
HADOOP-15507. Add MapReduce counters about EC bytes read.
1 parent 8d31ddc commit 6d5e87a

File tree

9 files changed

+76
-3
lines changed

9 files changed

+76
-3
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java

+34
Original file line numberDiff line numberDiff line change
@@ -3605,6 +3605,7 @@ public static class StatisticsData {
36053605
private volatile long bytesReadDistanceOfOneOrTwo;
36063606
private volatile long bytesReadDistanceOfThreeOrFour;
36073607
private volatile long bytesReadDistanceOfFiveOrLarger;
3608+
private volatile long bytesReadErasureCoded;
36083609

36093610
/**
36103611
* Add another StatisticsData object to this one.
@@ -3621,6 +3622,7 @@ void add(StatisticsData other) {
36213622
other.bytesReadDistanceOfThreeOrFour;
36223623
this.bytesReadDistanceOfFiveOrLarger +=
36233624
other.bytesReadDistanceOfFiveOrLarger;
3625+
this.bytesReadErasureCoded += other.bytesReadErasureCoded;
36243626
}
36253627

36263628
/**
@@ -3638,6 +3640,7 @@ void negate() {
36383640
-this.bytesReadDistanceOfThreeOrFour;
36393641
this.bytesReadDistanceOfFiveOrLarger =
36403642
-this.bytesReadDistanceOfFiveOrLarger;
3643+
this.bytesReadErasureCoded = -this.bytesReadErasureCoded;
36413644
}
36423645

36433646
@Override
@@ -3682,6 +3685,10 @@ public long getBytesReadDistanceOfThreeOrFour() {
36823685
public long getBytesReadDistanceOfFiveOrLarger() {
36833686
return bytesReadDistanceOfFiveOrLarger;
36843687
}
3688+
3689+
public long getBytesReadErasureCoded() {
3690+
return bytesReadErasureCoded;
3691+
}
36853692
}
36863693

36873694
private interface StatisticsAggregator<T> {
@@ -3873,6 +3880,14 @@ public void incrementWriteOps(int count) {
38733880
getThreadStatistics().writeOps += count;
38743881
}
38753882

3883+
/**
3884+
* Increment the bytes read on erasure-coded files in the statistics.
3885+
* @param newBytes the additional bytes read
3886+
*/
3887+
public void incrementBytesReadErasureCoded(long newBytes) {
3888+
getThreadStatistics().bytesReadErasureCoded += newBytes;
3889+
}
3890+
38763891
/**
38773892
* Increment the bytes read by the network distance in the statistics
38783893
* In the common network topology setup, distance value should be an even
@@ -4067,6 +4082,25 @@ public StatisticsData aggregate() {
40674082
});
40684083
}
40694084

4085+
/**
4086+
* Get the total number of bytes read on erasure-coded files.
4087+
* @return the number of bytes
4088+
*/
4089+
public long getBytesReadErasureCoded() {
4090+
return visitAll(new StatisticsAggregator<Long>() {
4091+
private long bytesReadErasureCoded = 0;
4092+
4093+
@Override
4094+
public void accept(StatisticsData data) {
4095+
bytesReadErasureCoded += data.bytesReadErasureCoded;
4096+
}
4097+
4098+
public Long aggregate() {
4099+
return bytesReadErasureCoded;
4100+
}
4101+
});
4102+
}
4103+
40704104
@Override
40714105
public String toString() {
40724106
return visitAll(new StatisticsAggregator<String>() {

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystemStorageStatistics.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public class FileSystemStorageStatistics extends StorageStatistics {
4646
"bytesReadLocalHost",
4747
"bytesReadDistanceOfOneOrTwo",
4848
"bytesReadDistanceOfThreeOrFour",
49-
"bytesReadDistanceOfFiveOrLarger"
49+
"bytesReadDistanceOfFiveOrLarger",
50+
"bytesReadErasureCoded"
5051
};
5152

5253
private static class LongStatisticIterator
@@ -104,6 +105,8 @@ private static Long fetch(StatisticsData data, String key) {
104105
return data.getBytesReadDistanceOfThreeOrFour();
105106
case "bytesReadDistanceOfFiveOrLarger":
106107
return data.getBytesReadDistanceOfFiveOrLarger();
108+
case "bytesReadErasureCoded":
109+
return data.getBytesReadErasureCoded();
107110
default:
108111
return null;
109112
}

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFileSystemStorageStatistics.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ public class TestFileSystemStorageStatistics {
5151
"bytesReadLocalHost",
5252
"bytesReadDistanceOfOneOrTwo",
5353
"bytesReadDistanceOfThreeOrFour",
54-
"bytesReadDistanceOfFiveOrLarger"
54+
"bytesReadDistanceOfFiveOrLarger",
55+
"bytesReadErasureCoded"
5556
};
5657

5758
private FileSystem.Statistics statistics =
@@ -74,6 +75,7 @@ public void setup() {
7475
statistics.incrementBytesReadByDistance(0, RandomUtils.nextInt(100));
7576
statistics.incrementBytesReadByDistance(1, RandomUtils.nextInt(100));
7677
statistics.incrementBytesReadByDistance(3, RandomUtils.nextInt(100));
78+
statistics.incrementBytesReadErasureCoded(RandomUtils.nextInt(100));
7779
}
7880

7981
@Test
@@ -126,6 +128,8 @@ private long getStatisticsValue(String name) {
126128
return statistics.getBytesReadByDistance(3);
127129
case "bytesReadDistanceOfFiveOrLarger":
128130
return statistics.getBytesReadByDistance(5);
131+
case "bytesReadErasureCoded":
132+
return statistics.getBytesReadErasureCoded();
129133
default:
130134
return 0;
131135
}

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSClient.java

+6
Original file line numberDiff line numberDiff line change
@@ -2942,6 +2942,12 @@ void updateFileSystemReadStats(int distance, int nRead) {
29422942
}
29432943
}
29442944

2945+
void updateFileSystemECReadStats(int nRead) {
2946+
if (stats != null) {
2947+
stats.incrementBytesReadErasureCoded(nRead);
2948+
}
2949+
}
2950+
29452951
/**
29462952
* Create hedged reads thread pool, HEDGED_READ_THREAD_POOL, if
29472953
* it does not already exist.

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java

+4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import org.apache.hadoop.hdfs.DFSUtilClient.CorruptedBlocks;
6262
import org.apache.hadoop.hdfs.client.impl.BlockReaderFactory;
6363
import org.apache.hadoop.hdfs.client.impl.DfsClientConf;
64+
import org.apache.hadoop.hdfs.protocol.BlockType;
6465
import org.apache.hadoop.hdfs.protocol.ClientDatanodeProtocol;
6566
import org.apache.hadoop.hdfs.protocol.DatanodeInfo;
6667
import org.apache.hadoop.hdfs.protocol.ExtendedBlock;
@@ -1082,6 +1083,9 @@ void actualGetFromOneDataNode(final DNAddrPair datanode, final long startInBlk,
10821083
IOUtilsClient.updateReadStatistics(readStatistics, nread, reader);
10831084
dfsClient.updateFileSystemReadStats(
10841085
reader.getNetworkDistance(), nread);
1086+
if (readStatistics.getBlockType() == BlockType.STRIPED) {
1087+
dfsClient.updateFileSystemECReadStats(nread);
1088+
}
10851089
if (nread != len) {
10861090
throw new IOException("truncated return from reader.read(): " +
10871091
"excpected " + len + ", got " + nread);

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/ReaderStrategy.java

+8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
package org.apache.hadoop.hdfs;
1919

20+
import org.apache.hadoop.hdfs.protocol.BlockType;
21+
2022
import java.io.IOException;
2123
import java.nio.ByteBuffer;
2224
import static org.apache.hadoop.hdfs.util.IOUtilsClient.updateReadStatistics;
@@ -121,6 +123,9 @@ public int readFromBlock(BlockReader blockReader,
121123
updateReadStatistics(readStatistics, nRead, blockReader);
122124
dfsClient.updateFileSystemReadStats(blockReader.getNetworkDistance(),
123125
nRead);
126+
if (readStatistics.getBlockType() == BlockType.STRIPED) {
127+
dfsClient.updateFileSystemECReadStats(nRead);
128+
}
124129
offset += nRead;
125130
}
126131
return nRead;
@@ -188,6 +193,9 @@ public int readFromBlock(BlockReader blockReader,
188193
updateReadStatistics(readStatistics, nRead, blockReader);
189194
dfsClient.updateFileSystemReadStats(blockReader.getNetworkDistance(),
190195
nRead);
196+
if (readStatistics.getBlockType() == BlockType.STRIPED) {
197+
dfsClient.updateFileSystemECReadStats(nRead);
198+
}
191199
}
192200

193201
return nRead;

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/Task.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ abstract public class Task implements Writable, Configurable {
8686

8787
public static String MERGED_OUTPUT_PREFIX = ".merged";
8888
public static final long DEFAULT_COMBINE_RECORDS_BEFORE_PROGRESS = 10000;
89+
private static final String HDFS_URI_SCHEME = "hdfs";
8990

9091
/**
9192
* @deprecated Provided for compatibility. Use {@link TaskCounter} instead.
@@ -1125,7 +1126,8 @@ public void incrementGcCounter() {
11251126
class FileSystemStatisticUpdater {
11261127
private List<FileSystem.Statistics> stats;
11271128
private Counters.Counter readBytesCounter, writeBytesCounter,
1128-
readOpsCounter, largeReadOpsCounter, writeOpsCounter;
1129+
readOpsCounter, largeReadOpsCounter, writeOpsCounter,
1130+
readBytesEcCounter;
11291131
private String scheme;
11301132
FileSystemStatisticUpdater(List<FileSystem.Statistics> stats, String scheme) {
11311133
this.stats = stats;
@@ -1153,23 +1155,33 @@ void updateCounters() {
11531155
writeOpsCounter = counters.findCounter(scheme,
11541156
FileSystemCounter.WRITE_OPS);
11551157
}
1158+
if (readBytesEcCounter == null && scheme.equals(HDFS_URI_SCHEME)) {
1159+
// EC bytes only applies to hdfs
1160+
readBytesEcCounter =
1161+
counters.findCounter(scheme, FileSystemCounter.BYTES_READ_EC);
1162+
}
11561163
long readBytes = 0;
11571164
long writeBytes = 0;
11581165
long readOps = 0;
11591166
long largeReadOps = 0;
11601167
long writeOps = 0;
1168+
long readBytesEC = 0;
11611169
for (FileSystem.Statistics stat: stats) {
11621170
readBytes = readBytes + stat.getBytesRead();
11631171
writeBytes = writeBytes + stat.getBytesWritten();
11641172
readOps = readOps + stat.getReadOps();
11651173
largeReadOps = largeReadOps + stat.getLargeReadOps();
11661174
writeOps = writeOps + stat.getWriteOps();
1175+
readBytesEC = readBytesEC + stat.getBytesReadErasureCoded();
11671176
}
11681177
readBytesCounter.setValue(readBytes);
11691178
writeBytesCounter.setValue(writeBytes);
11701179
readOpsCounter.setValue(readOps);
11711180
largeReadOpsCounter.setValue(largeReadOps);
11721181
writeOpsCounter.setValue(writeOps);
1182+
if (readBytesEcCounter != null) {
1183+
readBytesEcCounter.setValue(readBytesEC);
1184+
}
11731185
}
11741186
}
11751187

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/FileSystemCounter.java

+1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ public enum FileSystemCounter {
2727
READ_OPS,
2828
LARGE_READ_OPS,
2929
WRITE_OPS,
30+
BYTES_READ_EC,
3031
}

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/resources/org/apache/hadoop/mapreduce/FileSystemCounter.properties

+1
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ BYTES_WRITTEN.name= Number of bytes written
1919
READ_OPS.name= Number of read operations
2020
LARGE_READ_OPS.name= Number of large read operations
2121
WRITE_OPS.name= Number of write operations
22+
BYTES_READ_EC.name= Number of bytes read erasure-coded

0 commit comments

Comments
 (0)