HBASE-20633 Dropping a table containing a disable violation policy fails to remove the quota upon table delete
Signed-off-by: Josh Elser <els...@apache.org> Signed-off-by: Michael Stack <st...@apache.org> Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/7ff29d8e Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/7ff29d8e Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/7ff29d8e Branch: refs/heads/HBASE-19064 Commit: 7ff29d8e00543cf54bb2e663a2566db1c5d3707b Parents: a110e1e Author: Nihal Jain <nihaljain...@gmail.com> Authored: Mon May 28 14:36:14 2018 +0530 Committer: Josh Elser <els...@apache.org> Committed: Tue May 29 11:33:56 2018 -0400 ---------------------------------------------------------------------- .../DisableTableViolationPolicyEnforcement.java | 4 +- .../hadoop/hbase/quotas/TestSpaceQuotas.java | 40 +++++++++++++++----- 2 files changed, 34 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/7ff29d8e/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/policies/DisableTableViolationPolicyEnforcement.java ---------------------------------------------------------------------- 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 c85ba21..9d24c92 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 } } http://git-wip-us.apache.org/repos/asf/hbase/blob/7ff29d8e/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestSpaceQuotas.java ---------------------------------------------------------------------- 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 6f7df20..4b96f3d 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 { @@ -385,6 +386,11 @@ public class TestSpaceQuotas { } @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<RegionInfo,Long> 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);