HBASE-26700 The way we bypass broken track file is not enough in StoreFileListFile...
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / regionserver / TestRegionOpen.java
blob781f4d52a40a1665930777c836e64731db2d3b87
1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org.apache.hadoop.hbase.regionserver;
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.fail;
23 import java.io.IOException;
24 import java.util.List;
25 import java.util.concurrent.ThreadPoolExecutor;
26 import org.apache.hadoop.conf.Configuration;
27 import org.apache.hadoop.fs.FileSystem;
28 import org.apache.hadoop.fs.Path;
29 import org.apache.hadoop.hbase.HBaseClassTestRule;
30 import org.apache.hadoop.hbase.HBaseTestingUtil;
31 import org.apache.hadoop.hbase.HConstants;
32 import org.apache.hadoop.hbase.TableName;
33 import org.apache.hadoop.hbase.client.Admin;
34 import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
35 import org.apache.hadoop.hbase.client.Connection;
36 import org.apache.hadoop.hbase.client.ConnectionFactory;
37 import org.apache.hadoop.hbase.client.RegionInfo;
38 import org.apache.hadoop.hbase.client.RegionInfoBuilder;
39 import org.apache.hadoop.hbase.client.TableDescriptor;
40 import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
41 import org.apache.hadoop.hbase.executor.ExecutorType;
42 import org.apache.hadoop.hbase.testclassification.MediumTests;
43 import org.apache.hadoop.hbase.testclassification.RegionServerTests;
44 import org.apache.hadoop.hbase.util.Bytes;
45 import org.apache.hadoop.hbase.util.CommonFSUtils;
46 import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
47 import org.junit.AfterClass;
48 import org.junit.BeforeClass;
49 import org.junit.ClassRule;
50 import org.junit.Rule;
51 import org.junit.Test;
52 import org.junit.experimental.categories.Category;
53 import org.junit.rules.TestName;
54 import org.slf4j.Logger;
55 import org.slf4j.LoggerFactory;
57 @Category({MediumTests.class, RegionServerTests.class})
58 public class TestRegionOpen {
60 @ClassRule
61 public static final HBaseClassTestRule CLASS_RULE =
62 HBaseClassTestRule.forClass(TestRegionOpen.class);
64 private static final Logger LOG = LoggerFactory.getLogger(TestRegionOpen.class);
65 private static final int NB_SERVERS = 1;
67 private static final HBaseTestingUtil HTU = new HBaseTestingUtil();
69 @Rule
70 public TestName name = new TestName();
72 @BeforeClass
73 public static void before() throws Exception {
74 HTU.startMiniCluster(NB_SERVERS);
77 @AfterClass
78 public static void afterClass() throws Exception {
79 HTU.shutdownMiniCluster();
82 private static HRegionServer getRS() {
83 return HTU.getHBaseCluster().getLiveRegionServerThreads().get(0).getRegionServer();
86 @Test
87 public void testPriorityRegionIsOpenedWithSeparateThreadPool() throws Exception {
88 final TableName tableName = TableName.valueOf(TestRegionOpen.class.getSimpleName());
89 ThreadPoolExecutor exec = getRS().getExecutorService()
90 .getExecutorThreadPool(ExecutorType.RS_OPEN_PRIORITY_REGION);
91 long completed = exec.getCompletedTaskCount();
93 TableDescriptor tableDescriptor =
94 TableDescriptorBuilder.newBuilder(tableName).setPriority(HConstants.HIGH_QOS)
95 .setColumnFamily(ColumnFamilyDescriptorBuilder.of(HConstants.CATALOG_FAMILY)).build();
96 try (Connection connection = ConnectionFactory.createConnection(HTU.getConfiguration());
97 Admin admin = connection.getAdmin()) {
98 admin.createTable(tableDescriptor);
101 assertEquals(completed + 1, exec.getCompletedTaskCount());
104 @Test
105 public void testNonExistentRegionReplica() throws Exception {
106 final TableName tableName = TableName.valueOf(name.getMethodName());
107 final byte[] FAMILYNAME = Bytes.toBytes("fam");
108 FileSystem fs = HTU.getTestFileSystem();
109 Admin admin = HTU.getAdmin();
110 Configuration conf = HTU.getConfiguration();
111 Path rootDir = HTU.getDataTestDirOnTestFS();
113 TableDescriptor htd = TableDescriptorBuilder.newBuilder(tableName)
114 .setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILYNAME)).build();
115 admin.createTable(htd);
116 HTU.waitUntilNoRegionsInTransition(60000);
118 // Create new HRI with non-default region replica id
119 RegionInfo hri = RegionInfoBuilder.newBuilder(htd.getTableName())
120 .setStartKey(Bytes.toBytes("A")).setEndKey(Bytes.toBytes("B"))
121 .setRegionId(EnvironmentEdgeManager.currentTime()).setReplicaId(2).build();
122 HRegionFileSystem regionFs = HRegionFileSystem.createRegionOnFileSystem(conf, fs,
123 CommonFSUtils.getTableDir(rootDir, hri.getTable()), hri);
124 Path regionDir = regionFs.getRegionDir();
125 try {
126 HRegionFileSystem.loadRegionInfoFileContent(fs, regionDir);
127 } catch (IOException e) {
128 LOG.info("Caught expected IOE due missing .regioninfo file, due: " + e.getMessage() + " skipping region open.");
129 // We should only have 1 region online
130 List<RegionInfo> regions = admin.getRegions(tableName);
131 LOG.info("Regions: " + regions);
132 if (regions.size() != 1) {
133 fail("Table " + tableName + " should have only one region, but got more: " + regions);
135 return;
137 fail("Should have thrown IOE when attempting to open a non-existing region.");