Skip to content

Commit 6920e72

Browse files
haohao0103alanzhao
andauthored
HBASE-27688 HFile splitting occurs during bulkload, the CREATE_TIME_TS of hfileinfo is 0 (#5097)
Co-authored-by: alanzhao <[email protected]> Signed-off-by: Duo Zhang <[email protected]>
1 parent 24653dd commit 6920e72

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/tool/LoadIncrementalHFiles.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
import org.apache.hadoop.hbase.security.UserProvider;
9393
import org.apache.hadoop.hbase.security.token.FsDelegationToken;
9494
import org.apache.hadoop.hbase.util.Bytes;
95+
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
9596
import org.apache.hadoop.hbase.util.FSUtils;
9697
import org.apache.hadoop.hbase.util.FSVisitor;
9798
import org.apache.hadoop.hbase.util.Pair;
@@ -1182,7 +1183,7 @@ private static void copyHFileHalf(Configuration conf, Path inFile, Path outFile,
11821183
.withChecksumType(StoreUtils.getChecksumType(conf))
11831184
.withBytesPerCheckSum(StoreUtils.getBytesPerChecksum(conf)).withBlockSize(blocksize)
11841185
.withDataBlockEncoding(familyDescriptor.getDataBlockEncoding()).withIncludesTags(true)
1185-
.build();
1186+
.withCreateTime(EnvironmentEdgeManager.currentTime()).build();
11861187
halfWriter = new StoreFileWriter.Builder(conf, cacheConf, fs).withFilePath(outFile)
11871188
.withBloomType(bloomFilterType).withFileContext(hFileContext).build();
11881189
HFileScanner scanner = halfReader.getScanner(false, false, false);

hbase-server/src/test/java/org/apache/hadoop/hbase/tool/TestLoadIncrementalHFiles.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
package org.apache.hadoop.hbase.tool;
1919

20+
import static org.hamcrest.Matchers.greaterThan;
2021
import static org.junit.Assert.assertArrayEquals;
2122
import static org.junit.Assert.assertEquals;
2223
import static org.junit.Assert.assertThrows;
@@ -61,6 +62,7 @@
6162
import org.apache.hadoop.hbase.util.Bytes;
6263
import org.apache.hadoop.hbase.util.CommonFSUtils;
6364
import org.apache.hadoop.hbase.util.HFileTestUtil;
65+
import org.hamcrest.MatcherAssert;
6466
import org.junit.AfterClass;
6567
import org.junit.BeforeClass;
6668
import org.junit.ClassRule;
@@ -568,6 +570,39 @@ public void testSplitStoreFile() throws IOException {
568570
assertEquals(1000, rowCount);
569571
}
570572

573+
/**
574+
* This method tests that the create_time property of the HFile produced by the splitstorefile
575+
* method is greater than 0 HBASE-27688
576+
*/
577+
@Test
578+
public void testSplitStoreFileWithCreateTimeTS() throws IOException {
579+
Path dir = util.getDataTestDirOnTestFS("testSplitStoreFileWithCreateTimeTS");
580+
FileSystem fs = util.getTestFileSystem();
581+
Path testIn = new Path(dir, "testhfile");
582+
ColumnFamilyDescriptor familyDesc = ColumnFamilyDescriptorBuilder.of(FAMILY);
583+
HFileTestUtil.createHFile(util.getConfiguration(), fs, testIn, FAMILY, QUALIFIER,
584+
Bytes.toBytes("aaa"), Bytes.toBytes("zzz"), 1000);
585+
586+
Path bottomOut = new Path(dir, "bottom.out");
587+
Path topOut = new Path(dir, "top.out");
588+
589+
BulkLoadHFilesTool.splitStoreFile(util.getConfiguration(), testIn, familyDesc,
590+
Bytes.toBytes("ggg"), bottomOut, topOut);
591+
592+
verifyHFileCreateTimeTS(bottomOut);
593+
verifyHFileCreateTimeTS(topOut);
594+
}
595+
596+
private void verifyHFileCreateTimeTS(Path p) throws IOException {
597+
Configuration conf = util.getConfiguration();
598+
599+
try (HFile.Reader reader =
600+
HFile.createReader(p.getFileSystem(conf), p, new CacheConfig(conf), true, conf)) {
601+
long fileCreateTime = reader.getHFileInfo().getHFileContext().getFileCreateTime();
602+
MatcherAssert.assertThat(fileCreateTime, greaterThan(0L));
603+
}
604+
}
605+
571606
@Test
572607
public void testSplitStoreFileWithNoneToNone() throws IOException {
573608
testSplitStoreFileWithDifferentEncoding(DataBlockEncoding.NONE, DataBlockEncoding.NONE);

0 commit comments

Comments
 (0)