Skip to content

Commit

Permalink
HDFS-17455. Modify patch based on comments
Browse files Browse the repository at this point in the history
  • Loading branch information
haiyang1987 committed Apr 8, 2024
1 parent 2c9a6fb commit 79945e9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -520,15 +520,20 @@ private LocatedBlock fetchBlockAt(long offset, long length, boolean useCache)
// Update the LastLocatedBlock, if offset is for last block.
if (offset >= locatedBlocks.getFileLength()) {
setLocatedBlocksFields(newBlocks, getLastBlockLength(newBlocks));
// Here locatedBlocks has been updated, need to check offset again.
// If offset to the portion of the last block, will return the last block,
// otherwise the block containing the specified offset needs to be searched again.
if (offset >= locatedBlocks.getFileLength()) {
return locatedBlocks.getLastLocatedBlock();
} else {
targetBlockIdx = locatedBlocks.findBlock(offset);
assert targetBlockIdx >= 0 && targetBlockIdx < locatedBlocks.locatedBlockCount();
}
} else {
locatedBlocks.insertRange(targetBlockIdx,
newBlocks.getLocatedBlocks());
}
}
if (targetBlockIdx >= locatedBlocks.locatedBlockCount()) {
DFSClient.LOG.debug("Could not find target position " + offset);
throw new EOFException("Could not find target position " + offset);
}
return locatedBlocks.get(targetBlockIdx);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,6 @@ public void testReadWithoutPreferredCachingReplica() throws IOException {
public void testCreateBlockReaderWhenInvalidBlockTokenException() throws
IOException, InterruptedException, TimeoutException {
GenericTestUtils.setLogLevel(DFSClient.LOG, Level.DEBUG);
GenericTestUtils.LogCapturer logs =
GenericTestUtils.LogCapturer.captureLogs(DFSClient.LOG);
Configuration conf = new Configuration();
DFSClientFaultInjector oldFaultInjector = DFSClientFaultInjector.get();
try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(3).build()) {
Expand Down Expand Up @@ -363,9 +361,6 @@ public Void answer(InvocationOnMock invocation) throws Throwable {
int read = in.read(buf, 0, bufLen);
assertEquals(1024, read);
}

assertTrue(logs.getOutput().contains("Could not find target position 1"));
logs.clearOutput();
} finally {
DFSClientFaultInjector.set(oldFaultInjector);
}
Expand Down

0 comments on commit 79945e9

Please sign in to comment.