From 2be702f95feff27e6a434cf4859c948daa3142c6 Mon Sep 17 00:00:00 2001 From: James Moore Date: Fri, 24 Feb 2017 10:26:12 -0500 Subject: [PATCH] guard against NPE while reading FileTrailer and HFileBlock --- .../org/apache/hadoop/hbase/io/hfile/FixedFileTrailer.java | 10 +++++++++- .../main/java/org/apache/hadoop/hbase/io/hfile/HFileBlock.java | 9 ++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/FixedFileTrailer.java hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/FixedFileTrailer.java index f6ae291..3c1cf85 100644 --- hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/FixedFileTrailer.java +++ hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/FixedFileTrailer.java @@ -385,7 +385,15 @@ public class FixedFileTrailer { bufferSize = (int) fileSize; } - istream.seek(seekPoint); + try { + // attempt to seek inside of current blockReader + istream.seek(seekPoint); + } catch (NullPointerException | IOException e) { + // if the seek throws a null pointer exception or IOException attempt to seek on an alternative copy of the data + // this can occur if the blockReader on the DFSInputStream is null + istream.seekToNewSource(seekPoint); + } + ByteBuffer buf = ByteBuffer.allocate(bufferSize); istream.readFully(buf.array(), buf.arrayOffset(), buf.arrayOffset() + buf.limit()); diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileBlock.java hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileBlock.java index 0dc0f80..90a7e99 100644 --- hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileBlock.java +++ hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileBlock.java @@ -1422,7 +1422,14 @@ public class HFileBlock implements Cacheable { if (!pread && streamLock.tryLock()) { // Seek + read. Better for scanning. try { - istream.seek(fileOffset); + try { + // attempt to seek inside of current blockReader + istream.seek(fileOffset); + } catch (NullPointerException | IOException e) { + // if the seek throws a null pointer exception or IOException attempt to seek on an alternative copy of the data + // this can occur if the blockReader on the DFSInputStream is null + istream.seekToNewSource(fileOffset); + } long realOffset = istream.getPos(); if (realOffset != fileOffset) { -- 2.7.4 (Apple Git-66)