diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java index 08987ea6b194..08b951a0eaf7 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java @@ -7756,8 +7756,8 @@ public static HRegion openReadOnlyFileSystemHRegion(final Configuration conf, fi return r.openHRegion(null); } - public static void warmupHRegion(final RegionInfo info, final TableDescriptor htd, final WAL wal, - final Configuration conf, final RegionServerServices rsServices, + public static HRegion warmupHRegion(final RegionInfo info, final TableDescriptor htd, + final WAL wal, final Configuration conf, final RegionServerServices rsServices, final CancelableProgressable reporter) throws IOException { Objects.requireNonNull(info, "RegionInfo cannot be null"); @@ -7773,6 +7773,8 @@ public static void warmupHRegion(final RegionInfo info, final TableDescriptor ht } HRegion r = HRegion.newHRegion(tableDir, wal, fs, conf, info, htd, null); r.initializeWarmup(reporter); + r.close(); + return r; } /** diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java index 5a2a74a61a46..5b52ab07a482 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java @@ -243,6 +243,8 @@ public Set get() { // SFT implementations. private final Supplier storeFileWriterCreationTrackerFactory; + private final boolean warmup; + /** * Constructor * @param family HColumnDescriptor for this column @@ -290,6 +292,7 @@ protected HStore(final HRegion region, final ColumnFamilyDescriptor family, this.compactionCheckMultiplier = DEFAULT_COMPACTCHECKER_INTERVAL_MULTIPLIER; } + this.warmup = warmup; this.storeEngine = createStoreEngine(this, this.conf, region.getCellComparator()); storeEngine.initialize(warmup); // if require writing to tmp dir first, then we just return null, which indicate that we do not @@ -740,7 +743,7 @@ private ImmutableCollection closeWithoutLock() throws IOException { public Void call() throws IOException { boolean evictOnClose = getCacheConfig() != null ? getCacheConfig().shouldEvictOnClose() : true; - f.closeStoreFile(evictOnClose); + f.closeStoreFile(!warmup && evictOnClose); return null; } }); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestWarmupRegion.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestWarmupRegion.java index 420c0a6cac60..95b3c6dd3ae6 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestWarmupRegion.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestWarmupRegion.java @@ -120,7 +120,7 @@ public boolean evaluate() throws IOException { */ @After public void tearDown() throws Exception { - // Nothing to do. + TEST_UTIL.deleteTable(TABLENAME); } protected void runwarmup() throws InterruptedException { @@ -163,4 +163,16 @@ public void testWarmup() throws Exception { serverid = (serverid + 1) % 2; } } + + @Test + public void testWarmupAndClose() throws IOException { + HRegionServer rs = TEST_UTIL.getMiniHBaseCluster().getRegionServer(0); + HRegion region = TEST_UTIL.getMiniHBaseCluster().getRegions(TABLENAME).get(0); + RegionInfo info = region.getRegionInfo(); + + TableDescriptor htd = table.getDescriptor(); + HRegion warmedUpRegion = + warmupHRegion(info, htd, rs.getWAL(info), rs.getConfiguration(), rs, null); + assertTrue(warmedUpRegion.isClosed()); + } }