Skip to content

Commit ca0d9f3

Browse files
authored
HBASE-23079 RegionRemoteProcedureBase should override setTimeoutFailure (#672)
Signed-off-by: Guanghao Zhang <zghao@apache.org>
1 parent ce0fbc2 commit ca0d9f3

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/RegionRemoteProcedureBase.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,13 @@ protected Procedure<MasterProcedureEnv>[] execute(MasterProcedureEnv env)
324324
}
325325
}
326326

327+
@Override
328+
protected synchronized boolean setTimeoutFailure(MasterProcedureEnv env) {
329+
setState(ProcedureProtos.ProcedureState.RUNNABLE);
330+
env.getProcedureScheduler().addFront(this);
331+
return false; // 'false' means that this procedure handled the timeout
332+
}
333+
327334
@Override
328335
public boolean storeInDispatchedQueue() {
329336
return false;
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
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.
17+
*/
18+
package org.apache.hadoop.hbase.master.assignment;
19+
20+
import java.io.IOException;
21+
import java.util.concurrent.CompletableFuture;
22+
import java.util.concurrent.ExecutionException;
23+
import java.util.concurrent.TimeUnit;
24+
import org.apache.hadoop.conf.Configuration;
25+
import org.apache.hadoop.hbase.HBaseClassTestRule;
26+
import org.apache.hadoop.hbase.HBaseTestingUtility;
27+
import org.apache.hadoop.hbase.HConstants;
28+
import org.apache.hadoop.hbase.ProcedureTestUtil;
29+
import org.apache.hadoop.hbase.TableName;
30+
import org.apache.hadoop.hbase.client.AsyncAdmin;
31+
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
32+
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
33+
import org.apache.hadoop.hbase.master.HMaster;
34+
import org.apache.hadoop.hbase.master.MasterServices;
35+
import org.apache.hadoop.hbase.testclassification.MasterTests;
36+
import org.apache.hadoop.hbase.testclassification.MediumTests;
37+
import org.apache.hadoop.hbase.util.Bytes;
38+
import org.apache.zookeeper.KeeperException;
39+
import org.junit.AfterClass;
40+
import org.junit.BeforeClass;
41+
import org.junit.ClassRule;
42+
import org.junit.Test;
43+
import org.junit.experimental.categories.Category;
44+
45+
/**
46+
* Testcase for HBASE-23079.
47+
*/
48+
@Category({ MasterTests.class, MediumTests.class })
49+
public class TestOpenRegionProcedureBackoff {
50+
51+
@ClassRule
52+
public static final HBaseClassTestRule CLASS_RULE =
53+
HBaseClassTestRule.forClass(TestOpenRegionProcedureBackoff.class);
54+
55+
private static volatile boolean FAIL = false;
56+
57+
private static final class AssignmentManagerForTest extends AssignmentManager {
58+
59+
public AssignmentManagerForTest(MasterServices master) {
60+
super(master);
61+
}
62+
63+
@Override
64+
void persistToMeta(RegionStateNode regionNode) throws IOException {
65+
if (FAIL) {
66+
throw new IOException("Inject Error!");
67+
}
68+
super.persistToMeta(regionNode);
69+
}
70+
}
71+
72+
public static final class HMasterForTest extends HMaster {
73+
74+
public HMasterForTest(Configuration conf) throws IOException, KeeperException {
75+
super(conf);
76+
}
77+
78+
@Override
79+
protected AssignmentManager createAssignmentManager(MasterServices master) {
80+
return new AssignmentManagerForTest(master);
81+
}
82+
}
83+
84+
private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
85+
86+
private static TableName NAME = TableName.valueOf("Open");
87+
88+
private static byte[] CF = Bytes.toBytes("cf");
89+
90+
@BeforeClass
91+
public static void setUp() throws Exception {
92+
Configuration conf = UTIL.getConfiguration();
93+
conf.setClass(HConstants.MASTER_IMPL, HMasterForTest.class, HMaster.class);
94+
UTIL.startMiniCluster(1);
95+
UTIL.waitTableAvailable(TableName.META_TABLE_NAME);
96+
}
97+
98+
@AfterClass
99+
public static void tearDown() throws Exception {
100+
UTIL.shutdownMiniCluster();
101+
}
102+
103+
private void assertBackoffIncrease() throws IOException, InterruptedException {
104+
ProcedureTestUtil.waitUntilProcedureWaitingTimeout(UTIL, OpenRegionProcedure.class, 30000);
105+
ProcedureTestUtil.waitUntilProcedureTimeoutIncrease(UTIL, OpenRegionProcedure.class, 2);
106+
}
107+
108+
@Test
109+
public void testBackoff() throws IOException, InterruptedException, ExecutionException {
110+
FAIL = true;
111+
AsyncAdmin admin = UTIL.getAsyncConnection().getAdminBuilder()
112+
.setRpcTimeout(5, TimeUnit.MINUTES).setOperationTimeout(10, TimeUnit.MINUTES).build();
113+
CompletableFuture<?> future = admin.createTable(TableDescriptorBuilder.newBuilder(NAME)
114+
.setColumnFamily(ColumnFamilyDescriptorBuilder.of(CF)).build());
115+
assertBackoffIncrease();
116+
FAIL = false;
117+
future.get();
118+
UTIL.waitTableAvailable(NAME);
119+
}
120+
}

0 commit comments

Comments
 (0)