Skip to content

Commit

Permalink
HBASE-28481 Prompting table already exists after failing to create ta…
Browse files Browse the repository at this point in the history
…ble with many region replications (#5789)

Signed-off-by: Duo Zhang <zhangduo@apache.org>
Reviewed-by: Vineet Kumar Maheshwari <vineet.4008@gmail.com>
(cherry picked from commit e5d59ca)
  • Loading branch information
guluo2016 authored and Apache9 committed Apr 7, 2024
1 parent a0b84d4 commit 3dd0b6d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private static TableName checkTableName(TableName tableName) {

private static int checkReplicaId(int regionId) {
if (regionId > MAX_REPLICA_ID) {
throw new IllegalArgumentException("ReplicaId cannot be greater than" + MAX_REPLICA_ID);
throw new IllegalArgumentException("ReplicaId cannot be greater than " + MAX_REPLICA_ID);
}
return regionId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
public class CreateTableProcedure extends AbstractStateMachineTableProcedure<CreateTableState> {
private static final Logger LOG = LoggerFactory.getLogger(CreateTableProcedure.class);

private static final int MAX_REGION_REPLICATION = 0x10000;

private TableDescriptor tableDescriptor;
private List<RegionInfo> newRegions;

Expand Down Expand Up @@ -84,10 +86,10 @@ protected Flow executeFromState(final MasterProcedureEnv env, final CreateTableS
switch (state) {
case CREATE_TABLE_PRE_OPERATION:
// Verify if we can create the table
boolean exists = !prepareCreate(env);
boolean success = prepareCreate(env);
releaseSyncLatch();

if (exists) {
if (!success) {
assert isFailed() : "the delete should have an exception here";
return Flow.NO_MORE_STATE;
}
Expand Down Expand Up @@ -263,6 +265,13 @@ private boolean prepareCreate(final MasterProcedureEnv env) throws IOException {
return false;
}

int regionReplicationCount = tableDescriptor.getRegionReplication();
if (regionReplicationCount > MAX_REGION_REPLICATION) {
setFailure("master-create-table", new IllegalArgumentException(
"Region Replication cannot exceed " + MAX_REGION_REPLICATION + "."));
return false;
}

// check for store file tracker configurations
StoreFileTrackerValidationUtils.checkForCreateTable(env.getMasterConfiguration(),
tableDescriptor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import static org.apache.hadoop.hbase.regionserver.storefiletracker.StoreFileTrackerFactory.TRACKER_IMPL;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

Expand Down Expand Up @@ -284,4 +285,32 @@ public void testOnHDFSFailure() throws Exception {
new CreateTableProcedureOnHDFSFailure(procExec.getEnvironment(), htd, regions));
ProcedureTestingUtility.assertProcNotFailed(procExec, procId);
}

@Test
public void testCreateTableWithManyRegionReplication() throws IOException {
final int EXCEED_MAX_REGION_REPLICATION = 0x10001;
TableName tableName = TableName.valueOf(name.getMethodName());
ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();

TableDescriptor tableWithManyRegionReplication = TableDescriptorBuilder.newBuilder(tableName)
.setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("f1")).build())
.setRegionReplication(EXCEED_MAX_REGION_REPLICATION).build();
RegionInfo[] regions01 =
ModifyRegionUtils.createRegionInfos(tableWithManyRegionReplication, null);
long procId01 = ProcedureTestingUtility.submitAndWait(procExec, new CreateTableProcedure(
procExec.getEnvironment(), tableWithManyRegionReplication, regions01));
Procedure<?> result01 = procExec.getResult(procId01);
assertTrue(result01.getException().getCause() instanceof IllegalArgumentException);
assertFalse(UTIL.getAdmin().tableExists(tableName));

TableDescriptor tdesc = TableDescriptorBuilder.newBuilder(tableName)
.setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("f1")).build())
.build();
RegionInfo[] regions02 = ModifyRegionUtils.createRegionInfos(tdesc, null);
long procId02 = ProcedureTestingUtility.submitAndWait(procExec,
new CreateTableProcedure(procExec.getEnvironment(), tdesc, regions02));
Procedure<?> result02 = procExec.getResult(procId02);
assertTrue(result02.isSuccess());
assertTrue(UTIL.getAdmin().tableExists(tableName));
}
}

0 comments on commit 3dd0b6d

Please sign in to comment.