From 6f4baaef593cadaaa08904bb8edab8a9876561a2 Mon Sep 17 00:00:00 2001 From: Karthik Palanisamy Date: Mon, 30 Sep 2019 14:50:13 -0700 Subject: [PATCH] HBASE-23095 Reuse FileStatus in StoreFileInfo --- .../hbase/regionserver/StoreFileInfo.java | 19 +++++++-------- .../snapshot/TestSnapshotStoreFileSize.java | 23 ++++++++++++++----- 2 files changed, 27 insertions(+), 15 deletions(-) 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 98bc5031157d..8676689f1496 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 @@ -25,6 +25,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import com.sun.istack.Nullable; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; @@ -111,11 +112,11 @@ public class StoreFileInfo { */ public StoreFileInfo(final Configuration conf, final FileSystem fs, final Path initialPath) throws IOException { - this(conf, fs, initialPath, null, null); + this(conf, fs, null, initialPath); } - private StoreFileInfo(final Configuration conf, final FileSystem fs, final Path initialPath, - final Long createdTimestamp, final Long size) throws IOException { + private StoreFileInfo(final Configuration conf, final FileSystem fs, + @Nullable final FileStatus fileStatus, final Path initialPath) throws IOException { assert fs != null; assert initialPath != null; assert conf != null; @@ -143,13 +144,13 @@ private StoreFileInfo(final Configuration conf, final FileSystem fs, final Path " reference to " + referencePath); } else if (isHFile(p)) { // HFile - if (createdTimestamp != null && size != null) { - this.createdTimestamp = createdTimestamp; - this.size = size; - } else { - FileStatus fileStatus = fs.getFileStatus(initialPath); + 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.reference = null; this.link = null; @@ -166,7 +167,7 @@ private StoreFileInfo(final Configuration conf, final FileSystem fs, final Path */ public StoreFileInfo(final Configuration conf, final FileSystem fs, final FileStatus fileStatus) throws IOException { - this(conf, fs, fileStatus.getPath(), fileStatus.getModificationTime(), fileStatus.getLen()); + this(conf, fs, fileStatus, fileStatus.getPath()); } /** diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotStoreFileSize.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotStoreFileSize.java index e5fcd4a9cee0..86dc5834307d 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotStoreFileSize.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotStoreFileSize.java @@ -15,6 +15,13 @@ */ package org.apache.hadoop.hbase.snapshot; +import java.io.IOException; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; @@ -22,23 +29,27 @@ import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.TableName; -import org.apache.hadoop.hbase.client.*; +import org.apache.hadoop.hbase.client.Admin; +import org.apache.hadoop.hbase.client.RegionInfo; +import org.apache.hadoop.hbase.client.Table; import org.apache.hadoop.hbase.master.snapshot.SnapshotManager; import org.apache.hadoop.hbase.regionserver.HRegionFileSystem; import org.apache.hadoop.hbase.regionserver.StoreFileInfo; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.FSUtils; -import org.junit.*; - -import java.io.IOException; -import java.util.*; -import org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDataManifest; import org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDescription; import org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotRegionManifest; + +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; import org.junit.experimental.categories.Category; + /** * Validate if storefile length match * both snapshop manifest and filesystem.