HBASE-13357 If maxTables/maxRegions exceeds quota in a namespace, throw QuotaExceededException (Ashish Singhi)
This commit is contained in:
parent
0967c6af29
commit
a6ff17b958
|
@ -24,7 +24,6 @@ import java.util.concurrent.ConcurrentMap;
|
|||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.hadoop.hbase.DoNotRetryIOException;
|
||||
import org.apache.hadoop.hbase.HRegionInfo;
|
||||
import org.apache.hadoop.hbase.MetaTableAccessor;
|
||||
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.master.MasterServices;
|
||||
import org.apache.hadoop.hbase.master.TableNamespaceManager;
|
||||
import org.apache.hadoop.hbase.quotas.QuotaExceededException;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
|
||||
/**
|
||||
|
@ -123,13 +123,14 @@ class NamespaceStateManager {
|
|||
NamespaceTableAndRegionInfo currentStatus;
|
||||
currentStatus = getState(nspdesc.getName());
|
||||
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 "
|
||||
+ " in the namespace.");
|
||||
+ " in the namespace. The total number of tables permitted is "
|
||||
+ TableNamespaceManager.getMaxTables(nspdesc));
|
||||
}
|
||||
if ((currentStatus.getRegionCount() + numRegions) > TableNamespaceManager
|
||||
.getMaxRegions(nspdesc)) {
|
||||
throw new DoNotRetryIOException("The table " + table.getNameAsString()
|
||||
throw new QuotaExceededException("The table " + table.getNameAsString()
|
||||
+ " is not allowed to have " + numRegions
|
||||
+ " regions. The total number of regions permitted is only "
|
||||
+ TableNamespaceManager.getMaxRegions(nspdesc)
|
||||
|
|
|
@ -68,6 +68,7 @@ import org.apache.hadoop.hbase.master.RegionState;
|
|||
import org.apache.hadoop.hbase.master.RegionStates;
|
||||
import org.apache.hadoop.hbase.master.TableNamespaceManager;
|
||||
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.regionserver.HRegion;
|
||||
import org.apache.hadoop.hbase.regionserver.HRegionServer;
|
||||
|
@ -589,4 +590,21 @@ public class TestNamespaceAuditor {
|
|||
ADMIN.deleteTable(tableName);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue