-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HBASE-28150 CreateTableProcedure and DeleteTableProcedure should slee…
…p a while before retrying (#5502) Signed-off-by: Duo Zhang <[email protected]>
- Loading branch information
1 parent
8936a19
commit 5a404c4
Showing
5 changed files
with
190 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
.../test/java/org/apache/hadoop/hbase/coprocessor/BadMasterObserverForCreateDeleteTable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.hadoop.hbase.coprocessor; | ||
|
||
import java.io.IOException; | ||
import java.util.Optional; | ||
import org.apache.hadoop.hbase.TableName; | ||
import org.apache.hadoop.hbase.client.RegionInfo; | ||
import org.apache.hadoop.hbase.client.TableDescriptor; | ||
|
||
/** | ||
* A bad Master Observer to prevent user to create/delete table once. | ||
*/ | ||
public class BadMasterObserverForCreateDeleteTable implements MasterObserver, MasterCoprocessor { | ||
private boolean createFailedOnce = false; | ||
private boolean deleteFailedOnce = false; | ||
|
||
@Override | ||
public void postCompletedCreateTableAction(ObserverContext<MasterCoprocessorEnvironment> ctx, | ||
TableDescriptor desc, RegionInfo[] regions) throws IOException { | ||
if (!createFailedOnce && !desc.getTableName().isSystemTable()) { | ||
createFailedOnce = true; | ||
throw new IOException("execute postCompletedCreateTableAction failed once."); | ||
} | ||
} | ||
|
||
@Override | ||
public void postCompletedDeleteTableAction(ObserverContext<MasterCoprocessorEnvironment> ctx, | ||
TableName tableName) throws IOException { | ||
if (!deleteFailedOnce && !tableName.isSystemTable()) { | ||
deleteFailedOnce = true; | ||
throw new IOException("execute postCompletedDeleteTableAction failed once."); | ||
} | ||
} | ||
|
||
@Override | ||
public Optional<MasterObserver> getMasterObserver() { | ||
return Optional.of(this); | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
...ava/org/apache/hadoop/hbase/master/procedure/TestCreateDeleteTableProcedureWithRetry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.hadoop.hbase.master.procedure; | ||
|
||
import java.io.IOException; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.hbase.HBaseClassTestRule; | ||
import org.apache.hadoop.hbase.HBaseTestingUtil; | ||
import org.apache.hadoop.hbase.TableName; | ||
import org.apache.hadoop.hbase.client.RegionInfo; | ||
import org.apache.hadoop.hbase.client.TableDescriptor; | ||
import org.apache.hadoop.hbase.coprocessor.BadMasterObserverForCreateDeleteTable; | ||
import org.apache.hadoop.hbase.coprocessor.CoprocessorHost; | ||
import org.apache.hadoop.hbase.procedure2.ProcedureExecutor; | ||
import org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility; | ||
import org.apache.hadoop.hbase.testclassification.MasterTests; | ||
import org.apache.hadoop.hbase.testclassification.MediumTests; | ||
import org.apache.hadoop.hbase.util.ModifyRegionUtils; | ||
import org.junit.AfterClass; | ||
import org.junit.Assert; | ||
import org.junit.BeforeClass; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
|
||
@Category({ MasterTests.class, MediumTests.class }) | ||
public class TestCreateDeleteTableProcedureWithRetry { | ||
@ClassRule | ||
public static final HBaseClassTestRule CLASS_RULE = | ||
HBaseClassTestRule.forClass(TestCreateDeleteTableProcedureWithRetry.class); | ||
|
||
private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); | ||
|
||
private static final TableName TABLE_NAME = | ||
TableName.valueOf(TestCreateDeleteTableProcedureWithRetry.class.getSimpleName()); | ||
|
||
private static final String CF = "cf"; | ||
|
||
@BeforeClass | ||
public static void setUp() throws Exception { | ||
Configuration conf = UTIL.getConfiguration(); | ||
conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, | ||
BadMasterObserverForCreateDeleteTable.class.getName()); | ||
UTIL.startMiniCluster(1); | ||
} | ||
|
||
@AfterClass | ||
public static void tearDown() throws Exception { | ||
UTIL.shutdownMiniCluster(); | ||
} | ||
|
||
@Test | ||
public void testCreateDeleteTableRetry() throws IOException { | ||
ProcedureExecutor<MasterProcedureEnv> procExec = | ||
UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor(); | ||
TableDescriptor htd = MasterProcedureTestingUtility.createHTD(TABLE_NAME, CF); | ||
RegionInfo[] regions = ModifyRegionUtils.createRegionInfos(htd, null); | ||
CreateTableProcedure createProc = | ||
new CreateTableProcedure(procExec.getEnvironment(), htd, regions); | ||
ProcedureTestingUtility.submitAndWait(procExec, createProc); | ||
Assert.assertTrue(UTIL.getAdmin().tableExists(TABLE_NAME)); | ||
MasterProcedureTestingUtility.validateTableCreation(UTIL.getMiniHBaseCluster().getMaster(), | ||
TABLE_NAME, regions, CF); | ||
|
||
UTIL.getAdmin().disableTable(TABLE_NAME); | ||
DeleteTableProcedure deleteProc = | ||
new DeleteTableProcedure(procExec.getEnvironment(), TABLE_NAME); | ||
ProcedureTestingUtility.submitAndWait(procExec, deleteProc); | ||
Assert.assertFalse(UTIL.getAdmin().tableExists(TABLE_NAME)); | ||
MasterProcedureTestingUtility.validateTableDeletion(UTIL.getMiniHBaseCluster().getMaster(), | ||
TABLE_NAME); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters