HBASE-16486 Unify system table creation using the same createSystemTable API (Stephen Yuan Jiang)

This commit is contained in:
Stephen Yuan Jiang 2016-08-24 15:20:53 -07:00
parent 9cbe516b1f
commit 8a692ff189
8 changed files with 54 additions and 46 deletions

View File

@ -22,7 +22,6 @@ package org.apache.hadoop.hbase.rsgroup;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.common.net.HostAndPort;
import com.google.protobuf.ServiceException;
@ -53,6 +52,7 @@ import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.MetaTableAccessor;
import org.apache.hadoop.hbase.ProcedureInfo;
import org.apache.hadoop.hbase.MetaTableAccessor.DefaultVisitorBase;
import org.apache.hadoop.hbase.NamespaceDescriptor;
import org.apache.hadoop.hbase.ServerName;
@ -71,8 +71,6 @@ import org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel;
import org.apache.hadoop.hbase.master.MasterServices;
import org.apache.hadoop.hbase.master.ServerListener;
import org.apache.hadoop.hbase.master.TableStateManager;
import org.apache.hadoop.hbase.master.procedure.CreateTableProcedure;
import org.apache.hadoop.hbase.master.procedure.ProcedurePrepareLatch;
import org.apache.hadoop.hbase.protobuf.ProtobufMagic;
import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
import org.apache.hadoop.hbase.protobuf.RequestConverter;
@ -82,7 +80,6 @@ import org.apache.hadoop.hbase.protobuf.generated.RSGroupProtos;
import org.apache.hadoop.hbase.regionserver.DisabledRegionSplitPolicy;
import org.apache.hadoop.hbase.security.access.AccessControlLists;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.ModifyRegionUtils;
import org.apache.hadoop.hbase.zookeeper.ZKUtil;
import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
import org.apache.zookeeper.KeeperException;
@ -703,22 +700,12 @@ public class RSGroupInfoManagerImpl implements RSGroupInfoManager, ServerListene
}
private void createGroupTable(MasterServices masterServices) throws IOException {
HRegionInfo[] newRegions =
ModifyRegionUtils.createHRegionInfos(RSGROUP_TABLE_DESC, null);
ProcedurePrepareLatch latch = ProcedurePrepareLatch.createLatch();
masterServices.getMasterProcedureExecutor().submitProcedure(
new CreateTableProcedure(
masterServices.getMasterProcedureExecutor().getEnvironment(),
RSGROUP_TABLE_DESC,
newRegions,
latch),
HConstants.NO_NONCE,
HConstants.NO_NONCE);
latch.await();
Long procId = masterServices.createSystemTable(RSGROUP_TABLE_DESC);
// wait for region to be online
int tries = 600;
while(masterServices.getAssignmentManager().getRegionStates()
.getRegionServerOfRegion(newRegions[0]) == null && tries > 0) {
while (!(masterServices.getMasterProcedureExecutor().isFinished(procId))
&& masterServices.getMasterProcedureExecutor().isRunning()
&& tries > 0) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
@ -727,7 +714,12 @@ public class RSGroupInfoManagerImpl implements RSGroupInfoManager, ServerListene
tries--;
}
if(tries <= 0) {
throw new IOException("Failed to create group table.");
throw new IOException("Failed to create group table in a given time.");
} else {
ProcedureInfo result = masterServices.getMasterProcedureExecutor().getResult(procId);
if (result != null && result.isFailed()) {
throw new IOException("Failed to create group table. " + result.getExceptionFullMessage());
}
}
}

View File

@ -1476,6 +1476,30 @@ public class HMaster extends HRegionServer implements MasterServices {
return procId;
}
@Override
public long createSystemTable(final HTableDescriptor hTableDescriptor) throws IOException {
if (isStopped()) {
throw new MasterNotRunningException();
}
TableName tableName = hTableDescriptor.getTableName();
if (!(tableName.isSystemTable())) {
throw new IllegalArgumentException(
"Only system table creation can use this createSystemTable API");
}
HRegionInfo[] newRegions = ModifyRegionUtils.createHRegionInfos(hTableDescriptor, null);
LOG.info(getClientIdAuditPrefix() + " create " + hTableDescriptor);
// This special create table is called locally to master. Therefore, no RPC means no need
// to use nonce to detect duplicated RPC call.
long procId = this.procedureExecutor.submitProcedure(
new CreateTableProcedure(procedureExecutor.getEnvironment(), hTableDescriptor, newRegions));
return procId;
}
/**
* Checks whether the table conforms to some sane limits, and configured
* values (compression, etc) work. Throws an exception if something is wrong.

View File

@ -146,6 +146,13 @@ public interface MasterServices extends Server {
final long nonceGroup,
final long nonce) throws IOException;
/**
* Create a system table using the given table definition.
* @param hTableDescriptor The system table definition
* a single region is created.
*/
long createSystemTable(final HTableDescriptor hTableDescriptor) throws IOException;
/**
* Delete a table
* @param tableName The table name

View File

@ -29,7 +29,6 @@ import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.DoNotRetryIOException;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.MetaTableAccessor;
import org.apache.hadoop.hbase.NamespaceDescriptor;
@ -45,7 +44,6 @@ import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.client.TableState;
import org.apache.hadoop.hbase.constraint.ConstraintException;
import org.apache.hadoop.hbase.exceptions.TimeoutIOException;
import org.apache.hadoop.hbase.master.procedure.CreateTableProcedure;
import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
import org.apache.hadoop.hbase.procedure2.ProcedureExecutor;
import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
@ -200,15 +198,7 @@ public class TableNamespaceManager {
}
private void createNamespaceTable(MasterServices masterServices) throws IOException {
HRegionInfo[] newRegions = new HRegionInfo[]{
new HRegionInfo(HTableDescriptor.NAMESPACE_TABLEDESC.getTableName(), null, null)};
// we need to create the table this way to bypass checkInitialized
masterServices.getMasterProcedureExecutor()
.submitProcedure(new CreateTableProcedure(
masterServices.getMasterProcedureExecutor().getEnvironment(),
HTableDescriptor.NAMESPACE_TABLEDESC,
newRegions));
masterServices.createSystemTable(HTableDescriptor.NAMESPACE_TABLEDESC);
}
@SuppressWarnings("deprecation")

View File

@ -32,7 +32,6 @@ import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.classification.InterfaceAudience;
import org.apache.hadoop.hbase.classification.InterfaceStability;
import org.apache.hadoop.hbase.master.MasterServices;
import org.apache.hadoop.hbase.master.procedure.CreateTableProcedure;
import org.apache.hadoop.hbase.namespace.NamespaceAuditor;
import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.SetQuotaRequest;
@ -457,15 +456,7 @@ public class MasterQuotaManager implements RegionStateListener {
}
private void createQuotaTable() throws IOException {
HRegionInfo newRegions[] = new HRegionInfo[] {
new HRegionInfo(QuotaUtil.QUOTA_TABLE_NAME)
};
masterServices.getMasterProcedureExecutor()
.submitProcedure(new CreateTableProcedure(
masterServices.getMasterProcedureExecutor().getEnvironment(),
QuotaUtil.QUOTA_TABLE_DESC,
newRegions));
masterServices.createSystemTable(QuotaUtil.QUOTA_TABLE_DESC);
}
private static class NamedLock<T> {

View File

@ -125,7 +125,8 @@ public class AccessControlLists {
* @throws IOException
*/
static void createACLTable(MasterServices master) throws IOException {
master.createTable(new HTableDescriptor(ACL_TABLE_NAME)
/** Table descriptor for ACL table */
final HTableDescriptor ACL_TABLEDESC = new HTableDescriptor(ACL_TABLE_NAME)
.addFamily(new HColumnDescriptor(ACL_LIST_FAMILY)
.setMaxVersions(1)
.setInMemory(true)
@ -135,10 +136,8 @@ public class AccessControlLists {
.setScope(HConstants.REPLICATION_SCOPE_LOCAL)
// Set cache data blocks in L1 if more than one cache tier deployed; e.g. this will
// be the case if we are using CombinedBlockCache (Bucket Cache).
.setCacheDataInL1(true)),
null,
HConstants.NO_NONCE,
HConstants.NO_NONCE);
.setCacheDataInL1(true));
master.createSystemTable(ACL_TABLEDESC);
}
/**

View File

@ -207,7 +207,7 @@ public class VisibilityController extends BaseMasterAndRegionObserver implements
DisabledRegionSplitPolicy.class.getName());
labelsTable.setValue(Bytes.toBytes(HConstants.DISALLOW_WRITES_IN_RECOVERING),
Bytes.toBytes(true));
master.createTable(labelsTable, null, HConstants.NO_NONCE, HConstants.NO_NONCE);
master.createSystemTable(labelsTable);
}
}

View File

@ -72,6 +72,11 @@ public class MockNoopMasterServices implements MasterServices, Server {
return -1;
}
@Override
public long createSystemTable(final HTableDescriptor hTableDescriptor) throws IOException {
return -1;
}
@Override
public AssignmentManager getAssignmentManager() {
return null;