diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/policies/DisableTableViolationPolicyEnforcement.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/policies/DisableTableViolationPolicyEnforcement.java index c85ba21db9c..9d24c92bccb 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/policies/DisableTableViolationPolicyEnforcement.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/policies/DisableTableViolationPolicyEnforcement.java @@ -20,6 +20,7 @@ import java.io.IOException; import org.apache.hadoop.hbase.TableNotDisabledException; import org.apache.hadoop.hbase.TableNotEnabledException; +import org.apache.hadoop.hbase.TableNotFoundException; import org.apache.yetus.audience.InterfaceAudience; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -62,8 +63,9 @@ public class DisableTableViolationPolicyEnforcement extends DefaultViolationPoli if (LOG.isTraceEnabled()) { LOG.trace("Enable is complete for " + getTableName()); } - } catch (TableNotDisabledException tnde) { + } catch (TableNotDisabledException | TableNotFoundException e) { // The state we wanted it to be in + // Or, in case table is not found, nothing to do } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestSpaceQuotas.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestSpaceQuotas.java index 6f7df200a8b..4b96f3d7dac 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestSpaceQuotas.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestSpaceQuotas.java @@ -88,6 +88,7 @@ public class TestSpaceQuotas { @Rule public TestName testName = new TestName(); private SpaceQuotaHelperForTests helper; + private final TableName NON_EXISTENT_TABLE = TableName.valueOf("NON_EXISTENT_TABLE"); @BeforeClass public static void setUp() throws Exception { @@ -384,6 +385,11 @@ public class TestSpaceQuotas { setQuotaAndThenDropTable(SpaceViolationPolicy.NO_WRITES_COMPACTIONS); } + @Test + public void testSetQuotaAndThenDropTableWithDisable() throws Exception { + setQuotaAndThenDropTable(SpaceViolationPolicy.DISABLE); + } + @Test public void testSetQuotaAndThenIncreaseQuotaWithNoInserts() throws Exception { setQuotaAndThenIncreaseQuota(SpaceViolationPolicy.NO_INSERTS); @@ -419,6 +425,26 @@ public class TestSpaceQuotas { setQuotaAndThenRemoveInOneAmongTwoTables(SpaceViolationPolicy.DISABLE); } + @Test + public void testSetQuotaOnNonExistingTableWithNoInserts() throws Exception { + setQuotaLimit(NON_EXISTENT_TABLE, SpaceViolationPolicy.NO_INSERTS, 2L); + } + + @Test + public void testSetQuotaOnNonExistingTableWithNoWrites() throws Exception { + setQuotaLimit(NON_EXISTENT_TABLE, SpaceViolationPolicy.NO_WRITES, 2L); + } + + @Test + public void testSetQuotaOnNonExistingTableWithNoWritesCompaction() throws Exception { + setQuotaLimit(NON_EXISTENT_TABLE, SpaceViolationPolicy.NO_WRITES_COMPACTIONS, 2L); + } + + @Test + public void testSetQuotaOnNonExistingTableWithDisable() throws Exception { + setQuotaLimit(NON_EXISTENT_TABLE, SpaceViolationPolicy.DISABLE, 2L); + } + private void setQuotaAndThenRemove(SpaceViolationPolicy policy) throws Exception { Put put = new Put(Bytes.toBytes("to_reject")); put.addColumn(Bytes.toBytes(SpaceQuotaHelperForTests.F1), Bytes.toBytes("to"), @@ -463,7 +489,7 @@ public class TestSpaceQuotas { final TableName tn = writeUntilViolationAndVerifyViolation(policy, put); // Now, increase limit and perform put - increaseQuotaLimit(tn, policy); + setQuotaLimit(tn, policy, 4L); // Put some row now: should not violate as quota limit increased verifyNoViolation(policy, tn, put); @@ -496,12 +522,12 @@ public class TestSpaceQuotas { LOG.debug("Space quota settings removed from the table ", tn); } - private void increaseQuotaLimit(final TableName tn, SpaceViolationPolicy policy) + private void setQuotaLimit(final TableName tn, SpaceViolationPolicy policy, long sizeInMBs) throws Exception { - final long sizeLimit = 4L * SpaceQuotaHelperForTests.ONE_MEGABYTE; + final long sizeLimit = sizeInMBs * SpaceQuotaHelperForTests.ONE_MEGABYTE; QuotaSettings settings = QuotaSettingsFactory.limitTableSpace(tn, sizeLimit, policy); TEST_UTIL.getAdmin().setQuota(settings); - LOG.debug("Quota limit increased for table ", tn); + LOG.debug("Quota limit set for table = {}, limit = {}", tn, sizeLimit); } private Map getReportedSizesForTable(TableName tn) { @@ -518,11 +544,7 @@ public class TestSpaceQuotas { private TableName writeUntilViolation(SpaceViolationPolicy policyToViolate) throws Exception { TableName tn = helper.createTableWithRegions(10); - - final long sizeLimit = 2L * SpaceQuotaHelperForTests.ONE_MEGABYTE; - QuotaSettings settings = QuotaSettingsFactory.limitTableSpace(tn, sizeLimit, policyToViolate); - TEST_UTIL.getAdmin().setQuota(settings); - + setQuotaLimit(tn, policyToViolate, 2L); // Write more data than should be allowed and flush it to disk helper.writeData(tn, 3L * SpaceQuotaHelperForTests.ONE_MEGABYTE);