Skip to content

Commit 927735e

Browse files
committed
Fix graceful stop cache recovery test
1 parent 24afefa commit 927735e

1 file changed

Lines changed: 21 additions & 14 deletions

File tree

hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestBlockEvictionOnRegionMovement.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.hadoop.conf.Configuration;
2828
import org.apache.hadoop.fs.Path;
2929
import org.apache.hadoop.hbase.HBaseTestingUtil;
30+
import org.apache.hadoop.hbase.ServerName;
3031
import org.apache.hadoop.hbase.SingleProcessHBaseCluster;
3132
import org.apache.hadoop.hbase.StartTestingClusterOption;
3233
import org.apache.hadoop.hbase.TableName;
@@ -126,20 +127,26 @@ public void testBlockEvictionOnGracefulStop() throws Exception {
126127
: cluster.getRegionServer(0);
127128

128129
assertTrue(regionServingRS.getBlockCache().isPresent());
129-
long oldUsedCacheSize =
130-
regionServingRS.getBlockCache().get().getBlockCaches()[1].getCurrentSize();
131-
assertNotEquals(0, regionServingRS.getBlockCache().get().getBlockCaches()[1].getBlockCount());
132-
133-
cluster.stopRegionServer(regionServingRS.getServerName());
134-
Thread.sleep(500);
135-
cluster.startRegionServer();
136-
Thread.sleep(500);
137-
138-
regionServingRS.getBlockCache().get().waitForCacheInitialization(10000);
139-
long newUsedCacheSize =
140-
regionServingRS.getBlockCache().get().getBlockCaches()[1].getCurrentSize();
141-
assertEquals(oldUsedCacheSize, newUsedCacheSize);
142-
assertNotEquals(0, regionServingRS.getBlockCache().get().getBlockCaches()[1].getBlockCount());
130+
BlockCache oldBucketCache = regionServingRS.getBlockCache().get().getBlockCaches()[1];
131+
long oldUsedCacheSize = oldBucketCache.getCurrentSize();
132+
assertNotEquals(0, oldUsedCacheSize);
133+
assertNotEquals(0, oldBucketCache.getBlockCount());
134+
135+
ServerName serverName = regionServingRS.getServerName();
136+
cluster.stopRegionServer(serverName);
137+
cluster.waitForRegionServerToStop(serverName, 10000);
138+
139+
// Persistent state is restored into a new cache; the stopped cache must release its
140+
// references.
141+
assertEquals(0, oldBucketCache.getCurrentSize());
142+
143+
HRegionServer restartedRegionServer = cluster.startRegionServer().getRegionServer();
144+
assertTrue(restartedRegionServer.getBlockCache().isPresent());
145+
BlockCache restoredBucketCache =
146+
restartedRegionServer.getBlockCache().get().getBlockCaches()[1];
147+
assertTrue(restoredBucketCache.waitForCacheInitialization(10000));
148+
assertEquals(oldUsedCacheSize, restoredBucketCache.getCurrentSize());
149+
assertNotEquals(0, restoredBucketCache.getBlockCount());
143150
}
144151

145152
public TableName writeDataToTable(String testName) throws IOException, InterruptedException {

0 commit comments

Comments
 (0)