HBASE-13357 If maxTables/maxRegions exceeds quota in a namespace, throw QuotaExceededException (Ashish Singhi)

This commit is contained in:
tedyu 2015-03-28 14:01:06 -07:00
parent 0967c6af29
commit a6ff17b958
2 changed files with 23 additions and 4 deletions

View File

@ -24,7 +24,6 @@ import java.util.concurrent.ConcurrentMap;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.DoNotRetryIOException;
import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.MetaTableAccessor; import org.apache.hadoop.hbase.MetaTableAccessor;
import org.apache.hadoop.hbase.NamespaceDescriptor; import org.apache.hadoop.hbase.NamespaceDescriptor;
@ -32,6 +31,7 @@ import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.classification.InterfaceAudience; import org.apache.hadoop.hbase.classification.InterfaceAudience;
import org.apache.hadoop.hbase.master.MasterServices; import org.apache.hadoop.hbase.master.MasterServices;
import org.apache.hadoop.hbase.master.TableNamespaceManager; import org.apache.hadoop.hbase.master.TableNamespaceManager;
import org.apache.hadoop.hbase.quotas.QuotaExceededException;
import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Bytes;
/** /**
@ -123,13 +123,14 @@ class NamespaceStateManager {
NamespaceTableAndRegionInfo currentStatus; NamespaceTableAndRegionInfo currentStatus;
currentStatus = getState(nspdesc.getName()); currentStatus = getState(nspdesc.getName());
if ((currentStatus.getTables().size()) >= TableNamespaceManager.getMaxTables(nspdesc)) { if ((currentStatus.getTables().size()) >= TableNamespaceManager.getMaxTables(nspdesc)) {
throw new DoNotRetryIOException("The table " + table.getNameAsString() throw new QuotaExceededException("The table " + table.getNameAsString()
+ "cannot be created as it would exceed maximum number of tables allowed " + "cannot be created as it would exceed maximum number of tables allowed "
+ " in the namespace."); + " in the namespace. The total number of tables permitted is "
+ TableNamespaceManager.getMaxTables(nspdesc));
} }
if ((currentStatus.getRegionCount() + numRegions) > TableNamespaceManager if ((currentStatus.getRegionCount() + numRegions) > TableNamespaceManager
.getMaxRegions(nspdesc)) { .getMaxRegions(nspdesc)) {
throw new DoNotRetryIOException("The table " + table.getNameAsString() throw new QuotaExceededException("The table " + table.getNameAsString()
+ " is not allowed to have " + numRegions + " is not allowed to have " + numRegions
+ " regions. The total number of regions permitted is only " + " regions. The total number of regions permitted is only "
+ TableNamespaceManager.getMaxRegions(nspdesc) + TableNamespaceManager.getMaxRegions(nspdesc)

View File

@ -68,6 +68,7 @@ import org.apache.hadoop.hbase.master.RegionState;
import org.apache.hadoop.hbase.master.RegionStates; import org.apache.hadoop.hbase.master.RegionStates;
import org.apache.hadoop.hbase.master.TableNamespaceManager; import org.apache.hadoop.hbase.master.TableNamespaceManager;
import org.apache.hadoop.hbase.quotas.MasterQuotaManager; import org.apache.hadoop.hbase.quotas.MasterQuotaManager;
import org.apache.hadoop.hbase.quotas.QuotaExceededException;
import org.apache.hadoop.hbase.quotas.QuotaUtil; import org.apache.hadoop.hbase.quotas.QuotaUtil;
import org.apache.hadoop.hbase.regionserver.HRegion; import org.apache.hadoop.hbase.regionserver.HRegion;
import org.apache.hadoop.hbase.regionserver.HRegionServer; import org.apache.hadoop.hbase.regionserver.HRegionServer;
@ -589,4 +590,21 @@ public class TestNamespaceAuditor {
ADMIN.deleteTable(tableName); ADMIN.deleteTable(tableName);
observer.tableDeletionLatch.await(); observer.tableDeletionLatch.await();
} }
@Test(expected = QuotaExceededException.class, timeout = 30000)
public void testExceedTableQuotaInNamespace() throws Exception {
String nsp = prefix + "_testExceedTableQuotaInNamespace";
NamespaceDescriptor nspDesc =
NamespaceDescriptor.create(nsp).addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "1")
.build();
ADMIN.createNamespace(nspDesc);
assertNotNull("Namespace descriptor found null.", ADMIN.getNamespaceDescriptor(nsp));
assertEquals(ADMIN.listNamespaceDescriptors().length, 3);
HTableDescriptor tableDescOne =
new HTableDescriptor(TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table1"));
HTableDescriptor tableDescTwo =
new HTableDescriptor(TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table2"));
ADMIN.createTable(tableDescOne);
ADMIN.createTable(tableDescTwo, Bytes.toBytes("AAA"), Bytes.toBytes("ZZZ"), 4);
}
} }