diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFileInfo.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFileInfo.java index 5eaab23fc6cf..dc8f83384e23 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFileInfo.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFileInfo.java @@ -52,6 +52,7 @@ public class StoreFileInfo { private static final Logger LOG = LoggerFactory.getLogger(StoreFileInfo.class); + private final FileStatus localStatus = null ; /** * A non-capture group, for hfiles, so that this can be embedded. HFiles are uuid ([0-9a-z]+). * Bulk loaded hfiles has (_SeqId_[0-9]+_) has suffix. The mob del file has (_del) as suffix. @@ -97,7 +98,7 @@ public class StoreFileInfo { private RegionCoprocessorHost coprocessorHost; - // timestamp on when the file was created, is 0 and ignored for reference or link files + // change to use the createdTimestamp of reference or link files , will it create some problem later ? private long createdTimestamp; private long size; @@ -155,18 +156,20 @@ private StoreFileInfo(final Configuration conf, final FileSystem fs, final FileS } else if (isHFile(p) || isMobFile(p) || isMobRefFile(p)) { // HFile if (fileStatus != null) { - this.createdTimestamp = fileStatus.getModificationTime(); - this.size = fileStatus.getLen(); - } else { - FileStatus fStatus = fs.getFileStatus(initialPath); - this.createdTimestamp = fStatus.getModificationTime(); - this.size = fStatus.getLen(); + this.localStatus = fileStatus; + }else{ + this.localStatus = loadAndCacheFileStatus(fs); } + this.createdTimestamp = localStatus.getModificationTime(); + this.size = localStatus.getLen(); this.reference = null; this.link = null; } else { throw new IOException("path=" + p + " doesn't look like a valid StoreFile"); } + if(this.localStatus == null ){ + this.localStatus = loadAndCacheFileStatus(fs); + } } /** @@ -286,7 +289,6 @@ ReaderContext createReaderContext(boolean doDropBehind, long readahead, ReaderTy if (this.link != null) { // HFileLink in = new FSDataInputStreamWrapper(fs, this.link, doDropBehind, readahead); - status = this.link.getFileStatus(fs); } else if (this.reference != null) { // HFile Reference Path referencePath = getReferredToFile(this.getPath()); @@ -300,11 +302,10 @@ ReaderContext createReaderContext(boolean doDropBehind, long readahead, ReaderTy newFnfe.initCause(fnfe); throw newFnfe; } - status = fs.getFileStatus(referencePath); } else { in = new FSDataInputStreamWrapper(fs, this.getPath(), doDropBehind, readahead); - status = fs.getFileStatus(initialPath); } + status = getFileStatus(); long length = status.getLen(); ReaderContextBuilder contextBuilder = new ReaderContextBuilder().withInputStreamWrapper(in).withFileSize(length) @@ -349,21 +350,15 @@ private HDFSBlocksDistribution computeHDFSBlocksDistributionInternal(final FileS return FSUtils.computeHDFSBlocksDistribution(fs, status, 0, status.getLen()); } } - - /** - * Get the {@link FileStatus} of the file referenced by this StoreFileInfo - * @param fs The current file system to use. - * @return The {@link FileStatus} of the file referenced by this StoreFileInfo - */ - public FileStatus getReferencedFileStatus(final FileSystem fs) throws IOException { - FileStatus status; + private FileStatus loadAndCacheFileStatus(final FileSystem fs) throws IOException { + FileStatus status = null ; if (this.reference != null) { if (this.link != null) { FileNotFoundException exToThrow = null; for (int i = 0; i < this.link.getLocations().length; i++) { // HFileLink Reference try { - return link.getFileStatus(fs); + status = link.getFileStatus(fs); } catch (FileNotFoundException ex) { // try the other location exToThrow = ex; @@ -381,7 +376,7 @@ public FileStatus getReferencedFileStatus(final FileSystem fs) throws IOExceptio for (int i = 0; i < this.link.getLocations().length; i++) { // HFileLink try { - return link.getFileStatus(fs); + status = link.getFileStatus(fs); } catch (FileNotFoundException ex) { // try the other location exToThrow = ex; @@ -394,6 +389,17 @@ public FileStatus getReferencedFileStatus(final FileSystem fs) throws IOExceptio } return status; } + /** + * Get the {@link FileStatus} of the file referenced by this StoreFileInfo + * @param fs The current file system to use. + * @return The {@link FileStatus} of the file referenced by this StoreFileInfo + */ + public FileStatus getReferencedFileStatus(final FileSystem fs) throws IOException { + if(null == this.localStatus){ + throw new IOException("localStatus is not initialize on construct"); + } + return this.localStatus; + } /** @return The {@link Path} of the file */ public Path getPath() {