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 21:59:33 -07:00
parent 440079951e
commit 86d570b959
7 changed files with 43 additions and 24 deletions

View File

@ -1601,6 +1601,30 @@ public class HMaster extends HRegionServer implements MasterServices, Server {
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

@ -127,6 +127,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

@ -30,7 +30,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.NamespaceDescriptor;
import org.apache.hadoop.hbase.TableName;
@ -44,7 +43,6 @@ import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.constraint.ConstraintException;
import org.apache.hadoop.hbase.master.procedure.CreateNamespaceProcedure;
import org.apache.hadoop.hbase.master.procedure.CreateTableProcedure;
import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos;
import org.apache.hadoop.hbase.util.Bytes;
@ -196,15 +194,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

@ -477,13 +477,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

@ -124,7 +124,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)
@ -134,10 +135,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

@ -209,7 +209,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

@ -237,6 +237,11 @@ public class TestCatalogJanitor {
return -1;
}
@Override
public long createSystemTable(final HTableDescriptor hTableDescriptor) throws IOException {
return -1;
}
@Override
public SnapshotManager getSnapshotManager() {
return null;