Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDFS-17455. Fix Client throw IndexOutOfBoundsException in DFSInputStream#fetchBlockAt #6710

Merged
merged 4 commits into from
Apr 11, 2024

Conversation

haiyang1987
Copy link
Contributor

@haiyang1987 haiyang1987 commented Apr 5, 2024

Description of PR

https://issues.apache.org/jira/browse/HDFS-17455

When the client read data, connect to the datanode, because at this time the datanode access token is invalid will throw InvalidBlockTokenException. At this time, when call fetchBlockAt method will throw java.lang.IndexOutOfBoundsException causing read data failed.

Root case:

  • The HDFS file contains only one RBW block, with a block data size of 2048KB.
  • The client open this file and seeks to the offset of 1024 to read data.
  • Call DFSInputStream#getBlockReader method connect to the datanode, because at this time the datanode access token is invalid will throw InvalidBlockTokenException., and call DFSInputStream#fetchBlockAt will throw java.lang.IndexOutOfBoundsException.
private synchronized DatanodeInfo blockSeekTo(long target)
     throws IOException {
   if (target >= getFileLength()) {
   // the target size is smaller than fileLength (completeBlockSize + lastBlockBeingWrittenLength),
   // here at this time target is 1024 and getFileLength is 2048
     throw new IOException("Attempted to read past end of file");
   }
   ...
   while (true) {
     ...
     try {
       blockReader = getBlockReader(targetBlock, offsetIntoBlock,
           targetBlock.getBlockSize() - offsetIntoBlock, targetAddr,
           storageType, chosenNode);
       if(connectFailedOnce) {
         DFSClient.LOG.info("Successfully connected to " + targetAddr +
                            " for " + targetBlock.getBlock());
       }
       return chosenNode;
     } catch (IOException ex) {
       ...
       } else if (refetchToken > 0 && tokenRefetchNeeded(ex, targetAddr)) {
         refetchToken--;
         // Here will catch InvalidBlockTokenException.
         fetchBlockAt(target);
       } else {
         ...
       }
     }
   }
 }

private LocatedBlock fetchBlockAt(long offset, long length, boolean useCache)
      throws IOException {
    maybeRegisterBlockRefresh();
    synchronized(infoLock) {
      // Here the locatedBlocks only contains one locatedBlock, at this time the offset is 1024 and fileLength is 0,
      // so the targetBlockIdx is -2
      int targetBlockIdx = locatedBlocks.findBlock(offset);
      if (targetBlockIdx < 0) { // block is not cached
        targetBlockIdx = LocatedBlocks.getInsertIndex(targetBlockIdx);
        // Here the targetBlockIdx is 1;
        useCache = false;
      }
      if (!useCache) { // fetch blocks
        final LocatedBlocks newBlocks = (length == 0)
            ? dfsClient.getLocatedBlocks(src, offset)
            : dfsClient.getLocatedBlocks(src, offset, length);
        if (newBlocks == null || newBlocks.locatedBlockCount() == 0) {
          throw new EOFException("Could not find target position " + offset);
        }
        // Update the LastLocatedBlock, if offset is for last block.
        if (offset >= locatedBlocks.getFileLength()) {
          setLocatedBlocksFields(newBlocks, getLastBlockLength(newBlocks));
        } else {
          locatedBlocks.insertRange(targetBlockIdx,
              newBlocks.getLocatedBlocks());
        }
      }
      // Here the locatedBlocks only contains one locatedBlock, so will throw java.lang.IndexOutOfBoundsException: Index 1 out of bounds for length 1
      return locatedBlocks.get(targetBlockIdx);
    }
  }

The client exception:

java.lang.IndexOutOfBoundsException: Index 1 out of bounds for length 1
        at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
        at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
        at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:266)
        at java.base/java.util.Objects.checkIndex(Objects.java:359)
        at java.base/java.util.ArrayList.get(ArrayList.java:427)
        at org.apache.hadoop.hdfs.protocol.LocatedBlocks.get(LocatedBlocks.java:87)
        at org.apache.hadoop.hdfs.DFSInputStream.fetchBlockAt(DFSInputStream.java:569)
        at org.apache.hadoop.hdfs.DFSInputStream.fetchBlockAt(DFSInputStream.java:540)
        at org.apache.hadoop.hdfs.DFSInputStream.blockSeekTo(DFSInputStream.java:704)
        at org.apache.hadoop.hdfs.DFSInputStream.readWithStrategy(DFSInputStream.java:884)
        at org.apache.hadoop.hdfs.DFSInputStream.read(DFSInputStream.java:957)
        at org.apache.hadoop.hdfs.DFSInputStream.read(DFSInputStream.java:804)

The datanode exception:

2024-03-27 15:56:35,477 WARN  datanode.DataNode (DataXceiver.java:checkAccess(1487)) [DataXceiver for client DFSClient_NONMAPREDUCE_475786505_1 at /xxx [Sending block BP-xxx:blk_1138933918_65194340]] - Block token verification failed: op=READ_BLOCK, remoteAddress=/XXX, message=Can't re-compute password for block_token_identifier (expiryDate=1711562193469, keyId=1775816931, userId=test, blockPoolId=BP-xxx-xxx-xxx, blockId=1138933918, access modes=[READ], storageTypes= [SSD, SSD, SSD], storageIds= [DS-xxx1, DS-xxx2,DS-xxx3]), since the required block key (keyID=1775816931) doesn't exist

@slfan1989 slfan1989 changed the title HDFS-17455.Fix Client throw IndexOutOfBoundsException in DFSInputStream#fetchBlockAt HDFS-17455. Fix Client throw IndexOutOfBoundsException in DFSInputStream#fetchBlockAt Apr 5, 2024
@hadoop-yetus
Copy link

💔 -1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 0m 32s Docker mode activated.
_ Prechecks _
+1 💚 dupname 0m 0s No case conflicting files found.
+0 🆗 codespell 0m 1s codespell was not available.
+0 🆗 detsecrets 0m 1s detect-secrets was not available.
+1 💚 @author 0m 0s The patch does not contain any @author tags.
+1 💚 test4tests 0m 0s The patch appears to include 1 new or modified test files.
_ trunk Compile Tests _
+0 🆗 mvndep 14m 39s Maven dependency ordering for branch
+1 💚 mvninstall 32m 28s trunk passed
+1 💚 compile 5m 31s trunk passed with JDK Ubuntu-11.0.22+7-post-Ubuntu-0ubuntu220.04.1
+1 💚 compile 5m 22s trunk passed with JDK Private Build-1.8.0_402-8u402-ga-2ubuntu1~20.04-b06
+1 💚 checkstyle 1m 26s trunk passed
+1 💚 mvnsite 2m 27s trunk passed
+1 💚 javadoc 1m 57s trunk passed with JDK Ubuntu-11.0.22+7-post-Ubuntu-0ubuntu220.04.1
+1 💚 javadoc 2m 35s trunk passed with JDK Private Build-1.8.0_402-8u402-ga-2ubuntu1~20.04-b06
-1 ❌ spotbugs 2m 59s /branch-spotbugs-hadoop-hdfs-project_hadoop-hdfs-client-warnings.html hadoop-hdfs-project/hadoop-hdfs-client in trunk has 1 extant spotbugs warnings.
+1 💚 shadedclient 37m 40s branch has no errors when building and testing our client artifacts.
_ Patch Compile Tests _
+0 🆗 mvndep 0m 33s Maven dependency ordering for patch
+1 💚 mvninstall 2m 2s the patch passed
+1 💚 compile 5m 19s the patch passed with JDK Ubuntu-11.0.22+7-post-Ubuntu-0ubuntu220.04.1
+1 💚 javac 5m 19s the patch passed
+1 💚 compile 5m 13s the patch passed with JDK Private Build-1.8.0_402-8u402-ga-2ubuntu1~20.04-b06
+1 💚 javac 5m 13s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
-0 ⚠️ checkstyle 1m 14s /results-checkstyle-hadoop-hdfs-project.txt hadoop-hdfs-project: The patch generated 1 new + 33 unchanged - 0 fixed = 34 total (was 33)
+1 💚 mvnsite 2m 3s the patch passed
+1 💚 javadoc 1m 34s the patch passed with JDK Ubuntu-11.0.22+7-post-Ubuntu-0ubuntu220.04.1
+1 💚 javadoc 2m 7s the patch passed with JDK Private Build-1.8.0_402-8u402-ga-2ubuntu1~20.04-b06
+1 💚 spotbugs 5m 55s the patch passed
+1 💚 shadedclient 35m 55s patch has no errors when building and testing our client artifacts.
_ Other Tests _
+1 💚 unit 2m 28s hadoop-hdfs-client in the patch passed.
+1 💚 unit 226m 4s hadoop-hdfs in the patch passed.
+1 💚 asflicense 0m 46s The patch does not generate ASF License warnings.
403m 33s
Subsystem Report/Notes
Docker ClientAPI=1.45 ServerAPI=1.45 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-6710/1/artifact/out/Dockerfile
GITHUB PR #6710
Optional Tests dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell detsecrets
uname Linux 2bcd94340db8 5.15.0-94-generic #104-Ubuntu SMP Tue Jan 9 15:25:40 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/bin/hadoop.sh
git revision trunk / 52f7ba8
Default Java Private Build-1.8.0_402-8u402-ga-2ubuntu1~20.04-b06
Multi-JDK versions /usr/lib/jvm/java-11-openjdk-amd64:Ubuntu-11.0.22+7-post-Ubuntu-0ubuntu220.04.1 /usr/lib/jvm/java-8-openjdk-amd64:Private Build-1.8.0_402-8u402-ga-2ubuntu1~20.04-b06
Test Results https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-6710/1/testReport/
Max. process+thread count 3779 (vs. ulimit of 5500)
modules C: hadoop-hdfs-project/hadoop-hdfs-client hadoop-hdfs-project/hadoop-hdfs U: hadoop-hdfs-project
Console output https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-6710/1/console
versions git=2.25.1 maven=3.6.3 spotbugs=4.2.2
Powered by Apache Yetus 0.14.0 https://yetus.apache.org

This message was automatically generated.

@haiyang1987
Copy link
Contributor Author

Hi @ZanderXu @Hexiaoqiao @ayushtkn @zhangshuyan0 please help me review this PR when you are free, thanks ~

Copy link
Contributor

@ZanderXu ZanderXu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @haiyang1987 for your report. Nice catch.

Just changing the exception type is a not a good solution. For this case, InputStream should read data from the last UC block, right? If so, can you fix this logic so that the InputStream reads the last UC block instead of throwing an exception?

@ZanderXu
Copy link
Contributor

ZanderXu commented Apr 7, 2024

EOF Exception is needed if the offset is bigger than file length.

@hadoop-yetus
Copy link

💔 -1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 11m 45s Docker mode activated.
_ Prechecks _
+1 💚 dupname 0m 0s No case conflicting files found.
+0 🆗 codespell 0m 0s codespell was not available.
+0 🆗 detsecrets 0m 0s detect-secrets was not available.
+1 💚 @author 0m 0s The patch does not contain any @author tags.
+1 💚 test4tests 0m 0s The patch appears to include 1 new or modified test files.
_ trunk Compile Tests _
+0 🆗 mvndep 14m 45s Maven dependency ordering for branch
+1 💚 mvninstall 32m 51s trunk passed
+1 💚 compile 5m 30s trunk passed with JDK Ubuntu-11.0.22+7-post-Ubuntu-0ubuntu220.04.1
+1 💚 compile 5m 26s trunk passed with JDK Private Build-1.8.0_402-8u402-ga-2ubuntu1~20.04-b06
+1 💚 checkstyle 1m 26s trunk passed
+1 💚 mvnsite 2m 24s trunk passed
+1 💚 javadoc 1m 50s trunk passed with JDK Ubuntu-11.0.22+7-post-Ubuntu-0ubuntu220.04.1
+1 💚 javadoc 2m 27s trunk passed with JDK Private Build-1.8.0_402-8u402-ga-2ubuntu1~20.04-b06
-1 ❌ spotbugs 2m 42s /branch-spotbugs-hadoop-hdfs-project_hadoop-hdfs-client-warnings.html hadoop-hdfs-project/hadoop-hdfs-client in trunk has 1 extant spotbugs warnings.
+1 💚 shadedclient 35m 38s branch has no errors when building and testing our client artifacts.
_ Patch Compile Tests _
+0 🆗 mvndep 0m 34s Maven dependency ordering for patch
+1 💚 mvninstall 2m 2s the patch passed
+1 💚 compile 5m 20s the patch passed with JDK Ubuntu-11.0.22+7-post-Ubuntu-0ubuntu220.04.1
+1 💚 javac 5m 20s the patch passed
+1 💚 compile 5m 12s the patch passed with JDK Private Build-1.8.0_402-8u402-ga-2ubuntu1~20.04-b06
+1 💚 javac 5m 12s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
+1 💚 checkstyle 1m 14s the patch passed
+1 💚 mvnsite 2m 7s the patch passed
+1 💚 javadoc 1m 31s the patch passed with JDK Ubuntu-11.0.22+7-post-Ubuntu-0ubuntu220.04.1
+1 💚 javadoc 2m 14s the patch passed with JDK Private Build-1.8.0_402-8u402-ga-2ubuntu1~20.04-b06
+1 💚 spotbugs 5m 55s the patch passed
+1 💚 shadedclient 35m 37s patch has no errors when building and testing our client artifacts.
_ Other Tests _
+1 💚 unit 2m 29s hadoop-hdfs-client in the patch passed.
+1 💚 unit 226m 32s hadoop-hdfs in the patch passed.
+1 💚 asflicense 0m 48s The patch does not generate ASF License warnings.
413m 11s
Subsystem Report/Notes
Docker ClientAPI=1.45 ServerAPI=1.45 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-6710/2/artifact/out/Dockerfile
GITHUB PR #6710
Optional Tests dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell detsecrets
uname Linux 924ead2f0057 5.15.0-94-generic #104-Ubuntu SMP Tue Jan 9 15:25:40 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/bin/hadoop.sh
git revision trunk / 2c9a6fb
Default Java Private Build-1.8.0_402-8u402-ga-2ubuntu1~20.04-b06
Multi-JDK versions /usr/lib/jvm/java-11-openjdk-amd64:Ubuntu-11.0.22+7-post-Ubuntu-0ubuntu220.04.1 /usr/lib/jvm/java-8-openjdk-amd64:Private Build-1.8.0_402-8u402-ga-2ubuntu1~20.04-b06
Test Results https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-6710/2/testReport/
Max. process+thread count 3483 (vs. ulimit of 5500)
modules C: hadoop-hdfs-project/hadoop-hdfs-client hadoop-hdfs-project/hadoop-hdfs U: hadoop-hdfs-project
Console output https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-6710/2/console
versions git=2.25.1 maven=3.6.3 spotbugs=4.2.2
Powered by Apache Yetus 0.14.0 https://yetus.apache.org

This message was automatically generated.

@haiyang1987
Copy link
Contributor Author

Thanks @haiyang1987 for your report. Nice catch.

Just changing the exception type is a not a good solution. For this case, InputStream should read data from the last UC block, right? If so, can you fix this logic so that the InputStream reads the last UC block instead of throwing an exception?

Thanks @ZanderXu for your comment.

@haiyang1987
Copy link
Contributor Author

Update PR.

Hi @ZanderXu @Hexiaoqiao @ayushtkn @zhangshuyan0 please help me review this PR when you are free, thanks ~

@hadoop-yetus
Copy link

💔 -1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 0m 33s Docker mode activated.
_ Prechecks _
+1 💚 dupname 0m 0s No case conflicting files found.
+0 🆗 codespell 0m 1s codespell was not available.
+0 🆗 detsecrets 0m 1s detect-secrets was not available.
+1 💚 @author 0m 0s The patch does not contain any @author tags.
+1 💚 test4tests 0m 0s The patch appears to include 1 new or modified test files.
_ trunk Compile Tests _
+0 🆗 mvndep 14m 36s Maven dependency ordering for branch
+1 💚 mvninstall 32m 23s trunk passed
+1 💚 compile 5m 26s trunk passed with JDK Ubuntu-11.0.22+7-post-Ubuntu-0ubuntu220.04.1
+1 💚 compile 5m 18s trunk passed with JDK Private Build-1.8.0_402-8u402-ga-2ubuntu1~20.04-b06
+1 💚 checkstyle 1m 26s trunk passed
+1 💚 mvnsite 2m 25s trunk passed
+1 💚 javadoc 1m 51s trunk passed with JDK Ubuntu-11.0.22+7-post-Ubuntu-0ubuntu220.04.1
+1 💚 javadoc 2m 25s trunk passed with JDK Private Build-1.8.0_402-8u402-ga-2ubuntu1~20.04-b06
-1 ❌ spotbugs 2m 39s /branch-spotbugs-hadoop-hdfs-project_hadoop-hdfs-client-warnings.html hadoop-hdfs-project/hadoop-hdfs-client in trunk has 1 extant spotbugs warnings.
+1 💚 shadedclient 35m 40s branch has no errors when building and testing our client artifacts.
_ Patch Compile Tests _
+0 🆗 mvndep 0m 34s Maven dependency ordering for patch
+1 💚 mvninstall 1m 59s the patch passed
+1 💚 compile 5m 19s the patch passed with JDK Ubuntu-11.0.22+7-post-Ubuntu-0ubuntu220.04.1
+1 💚 javac 5m 19s the patch passed
+1 💚 compile 5m 13s the patch passed with JDK Private Build-1.8.0_402-8u402-ga-2ubuntu1~20.04-b06
+1 💚 javac 5m 13s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
+1 💚 checkstyle 1m 14s the patch passed
+1 💚 mvnsite 2m 7s the patch passed
+1 💚 javadoc 1m 32s the patch passed with JDK Ubuntu-11.0.22+7-post-Ubuntu-0ubuntu220.04.1
+1 💚 javadoc 2m 13s the patch passed with JDK Private Build-1.8.0_402-8u402-ga-2ubuntu1~20.04-b06
+1 💚 spotbugs 5m 52s the patch passed
+1 💚 shadedclient 35m 34s patch has no errors when building and testing our client artifacts.
_ Other Tests _
+1 💚 unit 2m 27s hadoop-hdfs-client in the patch passed.
+1 💚 unit 224m 46s hadoop-hdfs in the patch passed.
+1 💚 asflicense 0m 47s The patch does not generate ASF License warnings.
399m 16s
Subsystem Report/Notes
Docker ClientAPI=1.45 ServerAPI=1.45 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-6710/3/artifact/out/Dockerfile
GITHUB PR #6710
Optional Tests dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell detsecrets
uname Linux 1f085f5a0d20 5.15.0-94-generic #104-Ubuntu SMP Tue Jan 9 15:25:40 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/bin/hadoop.sh
git revision trunk / 79945e9
Default Java Private Build-1.8.0_402-8u402-ga-2ubuntu1~20.04-b06
Multi-JDK versions /usr/lib/jvm/java-11-openjdk-amd64:Ubuntu-11.0.22+7-post-Ubuntu-0ubuntu220.04.1 /usr/lib/jvm/java-8-openjdk-amd64:Private Build-1.8.0_402-8u402-ga-2ubuntu1~20.04-b06
Test Results https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-6710/3/testReport/
Max. process+thread count 3747 (vs. ulimit of 5500)
modules C: hadoop-hdfs-project/hadoop-hdfs-client hadoop-hdfs-project/hadoop-hdfs U: hadoop-hdfs-project
Console output https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-6710/3/console
versions git=2.25.1 maven=3.6.3 spotbugs=4.2.2
Powered by Apache Yetus 0.14.0 https://yetus.apache.org

This message was automatically generated.

// 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()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense. Please make the comments clearer.

          /**
           * After updating the locatedBlock, the block to which the offset belongs
           * should be researched like {@link DFSInputStream#getBlockAt(long)}.
           */

Path path = new Path(file);
long fileLen = 1024 * 64;
EnumSet<CreateFlag> createFlags = EnumSet.of(CREATE);
FSDataOutputStream out = fs.create(path, FsPermission.getFileDefault(), createFlags,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this out should be closed in the finally logic, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

EnumSet<CreateFlag> createFlags = EnumSet.of(CREATE);
FSDataOutputStream out = fs.create(path, FsPermission.getFileDefault(), createFlags,
fs.getConf().getInt(IO_FILE_BUFFER_SIZE_KEY, 4096), (short) 3,
fs.getDefaultBlockSize(path), null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the default block size? 256MB? If so, please hardcode it.

byte[] toWrite = new byte[bufferLen];
Random rb = new Random(0);
long bytesToWrite = fileLen;
while (bytesToWrite > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These logic is unnecessary if you just want to write 64KB data. 2KB is enough, right? I see you just seek to 1024.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here will write 5KB data, ensure that the test can seek to 1024 and read 1KB of data.

while (bytesToWrite > 0) {
rb.nextBytes(toWrite);
int bytesToWriteNext = (bufferLen < bytesToWrite) ? bufferLen : (int) bytesToWrite;
out.write(toWrite, 0, bytesToWriteNext);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some comments to show that you just want to create a file which only contains one UC block.

int bufLen = 1024;
byte[] buf = new byte[bufLen];
//Seek the offset to 1024.
in.seek(1024);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add some comments to show that the offset should be in (0, fileSize).

@haiyang1987
Copy link
Contributor Author

Thanks @ZanderXu for your detailed review, i will update it later.

@Hexiaoqiao
Copy link
Contributor

@haiyang1987 Thanks for your works. At description I see that you mentioned,

      // Here the locatedBlocks only contains one locatedBlock, at this time the offset is 1024 and fileLength is 0,
      // so the targetBlockIdx is -2
      int targetBlockIdx = locatedBlocks.findBlock(offset);

This is the root cause here, right ? I am a little confused with it why here return -2 which is binary search for collections contains only one element, IIUC, it will return -1 for this case. Please correct me if i missed something.

@ZanderXu
Copy link
Contributor

ZanderXu commented Apr 9, 2024

I am a little confused with it why here return -2 which is binary search for collections contains only one element, IIUC, it will return -1 for this case. Please correct me if i missed something.

The binary search will return -1 if the offset is less than the smallest offset in the list. And it will return -2 if the offset is greater than the maximum offset in the list.

We can reproduce by the following steps:

  1. Assume one file contains 20 completed blocks and 1 UC block.
  2. The current locatedBlocks only cache the 10 ~ 20 blocks.
  3. The binary search will return -1 if the offset is less than the offset of the first cached block, such as offset in the first ten blocks.
  4. The binary search will return -2 if the offset is greater than the offset of the last cached block, such as offset in the last UC block.

And another bug is that the currentBlock should be relocated after locatedBlocks is refreshed.

@Hexiaoqiao
Copy link
Contributor

Got it. My bad, the first feeling is out of scope will return -1 for binary search, but actually not.

Copy link
Contributor

@Hexiaoqiao Hexiaoqiao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Will +1 once the comment have fixed.

@haiyang1987
Copy link
Contributor Author

Thanks @ZanderXu @Hexiaoqiao for your detailed coment.

Update pr, please help me review this PR again when you are free, thanks ~

Copy link
Contributor

@ZanderXu ZanderXu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM +1.

@hadoop-yetus
Copy link

💔 -1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 0m 34s Docker mode activated.
_ Prechecks _
+1 💚 dupname 0m 0s No case conflicting files found.
+0 🆗 codespell 0m 0s codespell was not available.
+0 🆗 detsecrets 0m 0s detect-secrets was not available.
+1 💚 @author 0m 0s The patch does not contain any @author tags.
+1 💚 test4tests 0m 0s The patch appears to include 1 new or modified test files.
_ trunk Compile Tests _
+0 🆗 mvndep 14m 17s Maven dependency ordering for branch
+1 💚 mvninstall 32m 44s trunk passed
+1 💚 compile 5m 31s trunk passed with JDK Ubuntu-11.0.22+7-post-Ubuntu-0ubuntu220.04.1
+1 💚 compile 5m 19s trunk passed with JDK Private Build-1.8.0_402-8u402-ga-2ubuntu1~20.04-b06
+1 💚 checkstyle 1m 26s trunk passed
+1 💚 mvnsite 2m 25s trunk passed
+1 💚 javadoc 1m 50s trunk passed with JDK Ubuntu-11.0.22+7-post-Ubuntu-0ubuntu220.04.1
+1 💚 javadoc 2m 24s trunk passed with JDK Private Build-1.8.0_402-8u402-ga-2ubuntu1~20.04-b06
-1 ❌ spotbugs 2m 35s /branch-spotbugs-hadoop-hdfs-project_hadoop-hdfs-client-warnings.html hadoop-hdfs-project/hadoop-hdfs-client in trunk has 1 extant spotbugs warnings.
+1 💚 shadedclient 35m 44s branch has no errors when building and testing our client artifacts.
_ Patch Compile Tests _
+0 🆗 mvndep 0m 32s Maven dependency ordering for patch
+1 💚 mvninstall 2m 1s the patch passed
+1 💚 compile 5m 21s the patch passed with JDK Ubuntu-11.0.22+7-post-Ubuntu-0ubuntu220.04.1
+1 💚 javac 5m 21s the patch passed
+1 💚 compile 5m 11s the patch passed with JDK Private Build-1.8.0_402-8u402-ga-2ubuntu1~20.04-b06
+1 💚 javac 5m 11s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
+1 💚 checkstyle 1m 14s the patch passed
+1 💚 mvnsite 2m 4s the patch passed
+1 💚 javadoc 1m 29s the patch passed with JDK Ubuntu-11.0.22+7-post-Ubuntu-0ubuntu220.04.1
+1 💚 javadoc 2m 12s the patch passed with JDK Private Build-1.8.0_402-8u402-ga-2ubuntu1~20.04-b06
+1 💚 spotbugs 5m 55s the patch passed
+1 💚 shadedclient 35m 32s patch has no errors when building and testing our client artifacts.
_ Other Tests _
+1 💚 unit 2m 28s hadoop-hdfs-client in the patch passed.
-1 ❌ unit 231m 8s /patch-unit-hadoop-hdfs-project_hadoop-hdfs.txt hadoop-hdfs in the patch passed.
+1 💚 asflicense 0m 47s The patch does not generate ASF License warnings.
405m 41s
Reason Tests
Failed junit tests hadoop.hdfs.server.balancer.TestBalancerWithHANameNodes
Subsystem Report/Notes
Docker ClientAPI=1.45 ServerAPI=1.45 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-6710/4/artifact/out/Dockerfile
GITHUB PR #6710
Optional Tests dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell detsecrets
uname Linux eae96800de5f 5.15.0-94-generic #104-Ubuntu SMP Tue Jan 9 15:25:40 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/bin/hadoop.sh
git revision trunk / cc6f05f
Default Java Private Build-1.8.0_402-8u402-ga-2ubuntu1~20.04-b06
Multi-JDK versions /usr/lib/jvm/java-11-openjdk-amd64:Ubuntu-11.0.22+7-post-Ubuntu-0ubuntu220.04.1 /usr/lib/jvm/java-8-openjdk-amd64:Private Build-1.8.0_402-8u402-ga-2ubuntu1~20.04-b06
Test Results https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-6710/4/testReport/
Max. process+thread count 3594 (vs. ulimit of 5500)
modules C: hadoop-hdfs-project/hadoop-hdfs-client hadoop-hdfs-project/hadoop-hdfs U: hadoop-hdfs-project
Console output https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-6710/4/console
versions git=2.25.1 maven=3.6.3 spotbugs=4.2.2
Powered by Apache Yetus 0.14.0 https://yetus.apache.org

This message was automatically generated.

Copy link
Contributor

@Hexiaoqiao Hexiaoqiao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. +1. Will commit in next day.

@Hexiaoqiao
Copy link
Contributor

Hi @haiyang1987 . There are one spotbug find and another unit test failed at latest Yetus report which is not related to this changes, would you mind to fix it later? Thanks.

@haiyang1987
Copy link
Contributor Author

Hi @haiyang1987 . There are one spotbug find and another unit test failed at latest Yetus report which is not related to this changes, would you mind to fix it later? Thanks.

Sure, I will to fix it later. Thanks~

@Hexiaoqiao Hexiaoqiao merged commit 81b0597 into apache:trunk Apr 11, 2024
1 of 5 checks passed
@Hexiaoqiao
Copy link
Contributor

Committed to trunk. Thanks @haiyang1987 and @ZanderXu .

@haiyang1987
Copy link
Contributor Author

Thanks @ZanderXu @Hexiaoqiao for your review and merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants