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
.master
;
20 import java
.util
.List
;
21 import java
.util
.concurrent
.CountDownLatch
;
22 import org
.apache
.hadoop
.hbase
.HBaseClassTestRule
;
23 import org
.apache
.hadoop
.hbase
.HBaseTestingUtility
;
24 import org
.apache
.hadoop
.hbase
.TableName
;
25 import org
.apache
.hadoop
.hbase
.client
.Admin
;
26 import org
.apache
.hadoop
.hbase
.client
.Put
;
27 import org
.apache
.hadoop
.hbase
.client
.RegionInfo
;
28 import org
.apache
.hadoop
.hbase
.client
.Result
;
29 import org
.apache
.hadoop
.hbase
.client
.ResultScanner
;
30 import org
.apache
.hadoop
.hbase
.client
.Scan
;
31 import org
.apache
.hadoop
.hbase
.client
.Table
;
32 import org
.apache
.hadoop
.hbase
.master
.assignment
.MergeTableRegionsProcedure
;
33 import org
.apache
.hadoop
.hbase
.master
.assignment
.TransitRegionStateProcedure
;
34 import org
.apache
.hadoop
.hbase
.master
.procedure
.MasterProcedureEnv
;
35 import org
.apache
.hadoop
.hbase
.procedure2
.ProcedureExecutor
;
36 import org
.apache
.hadoop
.hbase
.testclassification
.MasterTests
;
37 import org
.apache
.hadoop
.hbase
.testclassification
.MediumTests
;
38 import org
.apache
.hadoop
.hbase
.util
.Bytes
;
39 import org
.junit
.AfterClass
;
40 import org
.junit
.Assert
;
41 import org
.junit
.BeforeClass
;
42 import org
.junit
.ClassRule
;
43 import org
.junit
.Test
;
44 import org
.junit
.experimental
.categories
.Category
;
45 import org
.slf4j
.Logger
;
46 import org
.slf4j
.LoggerFactory
;
50 @Category({MasterTests
.class, MediumTests
.class})
51 public class TestMergeTableRegionsWhileRSCrash
{
54 public static final HBaseClassTestRule CLASS_RULE
=
55 HBaseClassTestRule
.forClass(TestMergeTableRegionsWhileRSCrash
.class);
57 private static final Logger LOG
= LoggerFactory
58 .getLogger(TestMergeTableRegionsWhileRSCrash
.class);
60 protected static final HBaseTestingUtility UTIL
= new HBaseTestingUtility();
61 private static TableName TABLE_NAME
= TableName
.valueOf("test");
62 private static Admin admin
;
63 private static byte[] CF
= Bytes
.toBytes("cf");
64 private static byte[] SPLITKEY
= Bytes
.toBytes("row5");
65 private static CountDownLatch mergeCommitArrive
= new CountDownLatch(1);
66 private static Table TABLE
;
70 public static void setupCluster() throws Exception
{
71 UTIL
.startMiniCluster(1);
72 admin
= UTIL
.getAdmin();
73 byte[][] splitKeys
= new byte[1][];
74 splitKeys
[0] = SPLITKEY
;
75 TABLE
= UTIL
.createTable(TABLE_NAME
, CF
, splitKeys
);
76 UTIL
.waitTableAvailable(TABLE_NAME
);
80 public static void cleanupTest() throws Exception
{
82 UTIL
.shutdownMiniCluster();
83 } catch (Exception e
) {
84 LOG
.warn("failure shutting down cluster", e
);
89 public void test() throws Exception
{
90 //write some rows to the table
91 for (int i
= 0; i
< 10; i
++) {
92 byte[] row
= Bytes
.toBytes("row" + i
);
93 Put put
= new Put(row
);
94 put
.addColumn(CF
, CF
, CF
);
97 MasterProcedureEnv env
= UTIL
.getMiniHBaseCluster().getMaster()
98 .getMasterProcedureExecutor().getEnvironment();
99 final ProcedureExecutor
<MasterProcedureEnv
> executor
= UTIL
.getMiniHBaseCluster()
100 .getMaster().getMasterProcedureExecutor();
101 List
<RegionInfo
> regionInfos
= admin
.getRegions(TABLE_NAME
);
102 MergeTableRegionsProcedure mergeTableRegionsProcedure
= new MergeTableRegionsProcedure(
103 env
, new RegionInfo
[] {regionInfos
.get(0), regionInfos
.get(1)}, false);
104 executor
.submitProcedure(mergeTableRegionsProcedure
);
106 () -> executor
.getProcedures().stream().filter(p
-> p
instanceof TransitRegionStateProcedure
)
107 .map(p
-> (TransitRegionStateProcedure
) p
)
108 .anyMatch(p
-> TABLE_NAME
.equals(p
.getTableName())));
109 UTIL
.getMiniHBaseCluster().killRegionServer(
110 UTIL
.getMiniHBaseCluster().getRegionServer(0).getServerName());
111 UTIL
.getMiniHBaseCluster().startRegionServer();
112 UTIL
.waitUntilNoRegionsInTransition();
113 Scan scan
= new Scan();
114 ResultScanner results
= TABLE
.getScanner(scan
);
116 Result result
= null;
117 while ((result
= results
.next()) != null) {
120 Assert
.assertEquals("There should be 10 rows!", 10, count
);