From 5d597a1aec903c3363b77fd9847357c385fa412a Mon Sep 17 00:00:00 2001 From: xiezhineng Date: Wed, 17 Apr 2024 18:21:53 +0800 Subject: [PATCH] add offsetInBlock to avoid reading duplicate data from datanode. --- .../java/org/apache/hadoop/hdfs/StripeReader.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/StripeReader.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/StripeReader.java index dc3e3b06d49f3..e4e933b42ec21 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/StripeReader.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/StripeReader.java @@ -235,7 +235,8 @@ private ByteBufferStrategy[] getReadStrategies(StripingChunk chunk) { private int readToBuffer(BlockReader blockReader, DatanodeInfo currentNode, ByteBufferStrategy strategy, - LocatedBlock currentBlock, int chunkIndex) throws IOException { + LocatedBlock currentBlock, int chunkIndex, long offsetInBlock) + throws IOException { final int targetLength = strategy.getTargetLength(); int curAttempts = 0; while (curAttempts < readDNMaxAttempts) { @@ -267,7 +268,7 @@ private int readToBuffer(BlockReader blockReader, readerInfos[chunkIndex].reader.close(); } if (dfsStripedInputStream.createBlockReader(currentBlock, - alignedStripe.getOffsetInBlock(), targetBlocks, + offsetInBlock, targetBlocks, readerInfos, chunkIndex, readTo)) { blockReader = readerInfos[chunkIndex].reader; String msg = "Reconnect to " + currentNode.getInfoAddr() @@ -307,9 +308,9 @@ private Callable readCells(final BlockReader reader, int ret = 0; for (ByteBufferStrategy strategy : strategies) { - int bytesReead = readToBuffer(reader, datanode, strategy, currentBlock, - chunkIndex); - ret += bytesReead; + int bytesRead = readToBuffer(reader, datanode, strategy, currentBlock, + chunkIndex, alignedStripe.getOffsetInBlock() + ret); + ret += bytesRead; } return new BlockReadStats(ret, reader.isShortCircuit(), reader.getNetworkDistance());