Skip to content

Commit 6f4baae

Browse files
committed
HBASE-23095 Reuse FileStatus in StoreFileInfo
1 parent 3697e36 commit 6f4baae

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFileInfo.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.regex.Matcher;
2626
import java.util.regex.Pattern;
2727

28+
import com.sun.istack.Nullable;
2829
import org.apache.hadoop.conf.Configuration;
2930
import org.apache.hadoop.fs.FileStatus;
3031
import org.apache.hadoop.fs.FileSystem;
@@ -111,11 +112,11 @@ public class StoreFileInfo {
111112
*/
112113
public StoreFileInfo(final Configuration conf, final FileSystem fs, final Path initialPath)
113114
throws IOException {
114-
this(conf, fs, initialPath, null, null);
115+
this(conf, fs, null, initialPath);
115116
}
116117

117-
private StoreFileInfo(final Configuration conf, final FileSystem fs, final Path initialPath,
118-
final Long createdTimestamp, final Long size) throws IOException {
118+
private StoreFileInfo(final Configuration conf, final FileSystem fs,
119+
@Nullable final FileStatus fileStatus, final Path initialPath) throws IOException {
119120
assert fs != null;
120121
assert initialPath != null;
121122
assert conf != null;
@@ -143,13 +144,13 @@ private StoreFileInfo(final Configuration conf, final FileSystem fs, final Path
143144
" reference to " + referencePath);
144145
} else if (isHFile(p)) {
145146
// HFile
146-
if (createdTimestamp != null && size != null) {
147-
this.createdTimestamp = createdTimestamp;
148-
this.size = size;
149-
} else {
150-
FileStatus fileStatus = fs.getFileStatus(initialPath);
147+
if (fileStatus != null) {
151148
this.createdTimestamp = fileStatus.getModificationTime();
152149
this.size = fileStatus.getLen();
150+
} else {
151+
FileStatus fStatus = fs.getFileStatus(initialPath);
152+
this.createdTimestamp = fStatus.getModificationTime();
153+
this.size = fStatus.getLen();
153154
}
154155
this.reference = null;
155156
this.link = null;
@@ -166,7 +167,7 @@ private StoreFileInfo(final Configuration conf, final FileSystem fs, final Path
166167
*/
167168
public StoreFileInfo(final Configuration conf, final FileSystem fs, final FileStatus fileStatus)
168169
throws IOException {
169-
this(conf, fs, fileStatus.getPath(), fileStatus.getModificationTime(), fileStatus.getLen());
170+
this(conf, fs, fileStatus, fileStatus.getPath());
170171
}
171172

172173
/**

hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotStoreFileSize.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,41 @@
1515
*/
1616
package org.apache.hadoop.hbase.snapshot;
1717

18+
import java.io.IOException;
19+
import java.util.Collection;
20+
import java.util.HashMap;
21+
import java.util.Iterator;
22+
import java.util.List;
23+
import java.util.Map;
24+
1825
import org.apache.hadoop.conf.Configuration;
1926
import org.apache.hadoop.fs.FileStatus;
2027
import org.apache.hadoop.fs.FileSystem;
2128
import org.apache.hadoop.fs.Path;
2229
import org.apache.hadoop.hbase.HBaseClassTestRule;
2330
import org.apache.hadoop.hbase.HBaseTestingUtility;
2431
import org.apache.hadoop.hbase.TableName;
25-
import org.apache.hadoop.hbase.client.*;
32+
import org.apache.hadoop.hbase.client.Admin;
33+
import org.apache.hadoop.hbase.client.RegionInfo;
34+
import org.apache.hadoop.hbase.client.Table;
2635
import org.apache.hadoop.hbase.master.snapshot.SnapshotManager;
2736
import org.apache.hadoop.hbase.regionserver.HRegionFileSystem;
2837
import org.apache.hadoop.hbase.regionserver.StoreFileInfo;
2938
import org.apache.hadoop.hbase.testclassification.MasterTests;
3039
import org.apache.hadoop.hbase.testclassification.MediumTests;
3140
import org.apache.hadoop.hbase.util.FSUtils;
32-
import org.junit.*;
33-
34-
import java.io.IOException;
35-
import java.util.*;
3641

37-
import org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDataManifest;
3842
import org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDescription;
3943
import org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotRegionManifest;
44+
45+
import org.junit.AfterClass;
46+
import org.junit.Assert;
47+
import org.junit.BeforeClass;
48+
import org.junit.ClassRule;
49+
import org.junit.Test;
4050
import org.junit.experimental.categories.Category;
4151

52+
4253
/**
4354
* Validate if storefile length match
4455
* both snapshop manifest and filesystem.

0 commit comments

Comments
 (0)