use of org.apache.hadoop.hbase.NamespaceDescriptor in project hbase by apache.
the class CreateTableProcedure method prepareCreate.
private boolean prepareCreate(final MasterProcedureEnv env) throws IOException {
final TableName tableName = getTableName();
if (env.getMasterServices().getTableDescriptors().exists(tableName)) {
setFailure("master-create-table", new TableExistsException(getTableName()));
return false;
}
// check that we have at least 1 CF
if (tableDescriptor.getColumnFamilyCount() == 0) {
setFailure("master-create-table", new DoNotRetryIOException("Table " + getTableName().toString() + " should have at least one column family."));
return false;
}
if (!tableName.isSystemTable()) {
// do not check rs group for system tables as we may block the bootstrap.
Supplier<String> forWhom = () -> "table " + tableName;
RSGroupInfo rsGroupInfo = MasterProcedureUtil.checkGroupExists(env.getMasterServices().getRSGroupInfoManager()::getRSGroup, tableDescriptor.getRegionServerGroup(), forWhom);
if (rsGroupInfo == null) {
// we do not set rs group info on table, check if we have one on namespace
String namespace = tableName.getNamespaceAsString();
NamespaceDescriptor nd = env.getMasterServices().getClusterSchema().getNamespace(namespace);
forWhom = () -> "table " + tableName + "(inherit from namespace)";
rsGroupInfo = MasterProcedureUtil.checkGroupExists(env.getMasterServices().getRSGroupInfoManager()::getRSGroup, MasterProcedureUtil.getNamespaceGroup(nd), forWhom);
}
MasterProcedureUtil.checkGroupNotEmpty(rsGroupInfo, forWhom);
}
// check for store file tracker configurations
StoreFileTrackerValidationUtils.checkForCreateTable(env.getMasterConfiguration(), tableDescriptor);
return true;
}
use of org.apache.hadoop.hbase.NamespaceDescriptor in project hbase by apache.
the class NamespaceStateManager method checkAndUpdateNamespaceRegionCount.
/**
* Check and update region count for an existing table. To handle scenarios like restore snapshot
* @param name name of the table for region count needs to be checked and updated
* @param incr count of regions
* @throws QuotaExceededException if quota exceeds for the number of regions allowed in a
* namespace
* @throws IOException Signals that an I/O exception has occurred.
*/
synchronized void checkAndUpdateNamespaceRegionCount(TableName name, int incr) throws IOException {
String namespace = name.getNamespaceAsString();
NamespaceDescriptor nspdesc = getNamespaceDescriptor(namespace);
if (nspdesc != null) {
NamespaceTableAndRegionInfo currentStatus = getState(namespace);
int regionCountOfTable = currentStatus.getRegionCountOfTable(name);
if ((currentStatus.getRegionCount() - regionCountOfTable + incr) > TableNamespaceManager.getMaxRegions(nspdesc)) {
throw new QuotaExceededException("The table " + name.getNameAsString() + " region count cannot be updated as it would exceed maximum number " + "of regions allowed in the namespace. The total number of regions permitted is " + TableNamespaceManager.getMaxRegions(nspdesc));
}
currentStatus.removeTable(name);
currentStatus.addTable(name, incr);
}
}
use of org.apache.hadoop.hbase.NamespaceDescriptor in project hbase by apache.
the class NamespaceStateManager method initialize.
/**
* Initialize namespace state cache by scanning meta table.
*/
private void initialize() throws IOException {
List<NamespaceDescriptor> namespaces = this.master.getClusterSchema().getNamespaces();
for (NamespaceDescriptor namespace : namespaces) {
addNamespace(namespace.getName());
List<TableName> tables = this.master.listTableNamesByNamespace(namespace.getName());
for (TableName table : tables) {
if (table.isSystemTable()) {
continue;
}
List<RegionInfo> regions = MetaTableAccessor.getTableRegions(this.master.getConnection(), table, true);
addTable(table, regions.size());
}
}
LOG.info("Finished updating state of " + nsStateCache.size() + " namespaces. ");
initialized = true;
}
use of org.apache.hadoop.hbase.NamespaceDescriptor in project hbase by apache.
the class NamespaceStateManager method checkAndUpdateNamespaceRegionCount.
/**
* Check if adding a region violates namespace quota, if not update namespace cache.
*
* @param name
* @param regionName
* @param incr
* @return true, if region can be added to table.
* @throws IOException Signals that an I/O exception has occurred.
*/
synchronized boolean checkAndUpdateNamespaceRegionCount(TableName name, byte[] regionName, int incr) throws IOException {
String namespace = name.getNamespaceAsString();
NamespaceDescriptor nspdesc = getNamespaceDescriptor(namespace);
if (nspdesc != null) {
NamespaceTableAndRegionInfo currentStatus;
currentStatus = getState(namespace);
int regionCount = currentStatus.getRegionCount();
long maxRegionCount = TableNamespaceManager.getMaxRegions(nspdesc);
if (incr > 0 && regionCount >= maxRegionCount) {
LOG.warn("The region " + Bytes.toStringBinary(regionName) + " cannot be created. The region count will exceed quota on the namespace. " + "This may be transient, please retry later if there are any ongoing split" + " operations in the namespace.");
return false;
}
NamespaceTableAndRegionInfo nsInfo = nsStateCache.get(namespace);
if (nsInfo != null) {
nsInfo.incRegionCountForTable(name, incr);
} else {
LOG.warn("Namespace state found null for namespace : " + namespace);
}
}
return true;
}
use of org.apache.hadoop.hbase.NamespaceDescriptor in project hbase by apache.
the class RSGroupUtil method getRSGroupInfo.
/**
* Will try to get the rsgroup from {@link TableDescriptor} first, and then try to get the rsgroup
* from the {@link NamespaceDescriptor}. If still not present, return empty.
*/
public static Optional<RSGroupInfo> getRSGroupInfo(MasterServices master, RSGroupInfoManager manager, TableName tableName) throws IOException {
TableDescriptor td = master.getTableDescriptors().get(tableName);
if (td == null) {
return Optional.empty();
}
// RSGroup information determined by client.
Optional<String> optGroupNameOfTable = td.getRegionServerGroup();
if (optGroupNameOfTable.isPresent()) {
RSGroupInfo group = manager.getRSGroup(optGroupNameOfTable.get());
if (group != null) {
return Optional.of(group);
}
}
// for backward compatible, where we may still have table configs in the RSGroupInfo after
// upgrading when migrating is still on-going.
RSGroupInfo groupFromOldRSGroupInfo = manager.getRSGroupForTable(tableName);
if (groupFromOldRSGroupInfo != null) {
return Optional.of(groupFromOldRSGroupInfo);
}
// RSGroup information determined by administrator.
String groupDeterminedByAdmin = manager.determineRSGroupInfoForTable(tableName);
RSGroupInfo groupInfo = null;
if (groupDeterminedByAdmin != null) {
groupInfo = manager.getRSGroup(groupDeterminedByAdmin);
}
if (groupInfo != null) {
return Optional.of(groupInfo);
}
// Finally, we will try to fall back to namespace as rsgroup if exists
ClusterSchema clusterSchema = master.getClusterSchema();
if (clusterSchema == null) {
if (TableName.isMetaTableName(tableName)) {
LOG.info("Can not get the namespace rs group config for meta table, since the" + " meta table is not online yet, will use default group to assign meta first");
} else {
LOG.warn("ClusterSchema is null, can only use default rsgroup, should not happen?");
}
return Optional.empty();
}
NamespaceDescriptor nd = clusterSchema.getNamespace(tableName.getNamespaceAsString());
String groupNameOfNs = nd.getConfigurationValue(RSGroupInfo.NAMESPACE_DESC_PROP_GROUP);
if (groupNameOfNs == null) {
return Optional.empty();
}
return Optional.ofNullable(manager.getRSGroup(groupNameOfNs));
}
Aggregations