From eaeca5d327ea8d34629dd4dcd658b31a6440df0d Mon Sep 17 00:00:00 2001 From: Sakthi Date: Fri, 28 Sep 2018 01:08:59 -0700 Subject: [PATCH] HBASE-21225: Having RPC & Space quota on a table doesn't allow space quota to be removed using 'NONE' --- .../hbase/quotas/GlobalQuotaSettingsImpl.java | 4 +- .../hbase/quotas/TestMasterQuotasObserver.java | 170 +++++++++++++-------- 2 files changed, 111 insertions(+), 63 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/GlobalQuotaSettingsImpl.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/GlobalQuotaSettingsImpl.java index 311969154e45fd10e02fc9d0d13969ba9542a16e..8c2cd1f4ea44cd524b481cedb65eb2a425d5593f 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/GlobalQuotaSettingsImpl.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/GlobalQuotaSettingsImpl.java @@ -176,8 +176,8 @@ public class GlobalQuotaSettingsImpl extends GlobalQuotaSettings { } if (quotaToMerge.getRemove()) { - // Update the builder to propagate the removal - spaceBuilder.setRemove(true).clearSoftLimit().clearViolationPolicy(); + // To prevent the "REMOVE => true" row in QuotaTableUtil.QUOTA_TABLE_NAME + spaceBuilder = null; } else { // Add the new settings to the existing settings spaceBuilder.mergeFrom(quotaToMerge); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestMasterQuotasObserver.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestMasterQuotasObserver.java index 92e1d9dd4fa2f9ff7d987d963ac133f495836fe4..e3591a1feb5c35645fedb91894b54d45b3e987fb 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestMasterQuotasObserver.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestMasterQuotasObserver.java @@ -90,7 +90,7 @@ public class TestMasterQuotasObserver { } @Test - public void testTableSpaceQuotaRemoved() throws Exception { + public void testTableWithSpaceAndRPCQuota() throws Exception { final Connection conn = TEST_UTIL.getConnection(); final Admin admin = conn.getAdmin(); final TableName tn = TableName.valueOf(testName.getMethodName()); @@ -98,47 +98,113 @@ public class TestMasterQuotasObserver { if (admin.tableExists(tn)) { dropTable(admin, tn); } + createTable(admin, tn); assertEquals(0, getNumSpaceQuotas()); + assertEquals(0, getThrottleQuotas()); - // Set space quota - QuotaSettings settings = QuotaSettingsFactory.limitTableSpace( - tn, 1024L, SpaceViolationPolicy.NO_INSERTS); + // Set Both quotas + QuotaSettings settings = + QuotaSettingsFactory.limitTableSpace(tn, 1024L, SpaceViolationPolicy.NO_INSERTS); admin.setQuota(settings); + + settings = + QuotaSettingsFactory.throttleTable(tn, ThrottleType.REQUEST_SIZE, 2L, TimeUnit.HOURS); + admin.setQuota(settings); + assertEquals(1, getNumSpaceQuotas()); + assertEquals(1, getThrottleQuotas()); + + // Remove Space quota + settings = QuotaSettingsFactory.removeTableSpaceLimit(tn); + admin.setQuota(settings); + assertEquals(0, getNumSpaceQuotas()); + assertEquals(1, getThrottleQuotas()); + + settings = + QuotaSettingsFactory.limitTableSpace(tn, 1024L, SpaceViolationPolicy.NO_INSERTS); + admin.setQuota(settings); + assertEquals(1, getNumSpaceQuotas()); + assertEquals(1, getThrottleQuotas()); + + settings = QuotaSettingsFactory.unthrottleTable(tn); + admin.setQuota(settings); + assertEquals(1, getNumSpaceQuotas()); + assertEquals(0, getThrottleQuotas()); + + settings = + QuotaSettingsFactory.throttleTable(tn, ThrottleType.REQUEST_SIZE, 2L, TimeUnit.HOURS); + admin.setQuota(settings); + assertEquals(1, getNumSpaceQuotas()); + assertEquals(1, getThrottleQuotas()); - // Drop the table and observe the Space quota being automatically deleted as well dropTable(admin, tn); + assertEquals(0, getNumSpaceQuotas()); + assertEquals(0, getThrottleQuotas()); } @Test - public void testTableRPCQuotaRemoved() throws Exception { + public void testNamespaceWithSpaceAndRPCQuota() throws Exception { final Connection conn = TEST_UTIL.getConnection(); final Admin admin = conn.getAdmin(); final TableName tn = TableName.valueOf(testName.getMethodName()); - // Drop the table if it somehow exists - if (admin.tableExists(tn)) { - dropTable(admin, tn); + final String ns = testName.getMethodName(); + // Drop the ns if it somehow exists + if (namespaceExists(ns)) { + admin.deleteNamespace(ns); } - createTable(admin, tn); + // Create the ns + NamespaceDescriptor desc = NamespaceDescriptor.create(ns).build(); + admin.createNamespace(desc); + assertEquals(0, getNumSpaceQuotas()); assertEquals(0, getThrottleQuotas()); - // Set RPC quota + // Set Both quotas QuotaSettings settings = - QuotaSettingsFactory.throttleTable(tn, ThrottleType.REQUEST_SIZE, 2L, TimeUnit.HOURS); + QuotaSettingsFactory.limitNamespaceSpace(ns, 1024L, SpaceViolationPolicy.NO_INSERTS); + admin.setQuota(settings); + + settings = + QuotaSettingsFactory.throttleNamespace(ns, ThrottleType.REQUEST_SIZE, 2L, TimeUnit.HOURS); admin.setQuota(settings); + assertEquals(1, getNumSpaceQuotas()); assertEquals(1, getThrottleQuotas()); - // Delete the table and observe the RPC quota being automatically deleted as well - dropTable(admin, tn); + settings = QuotaSettingsFactory.removeNamespaceSpaceLimit(ns); + admin.setQuota(settings); + assertEquals(0, getNumSpaceQuotas()); + assertEquals(1, getThrottleQuotas()); + + settings = + QuotaSettingsFactory.limitNamespaceSpace(ns, 1024L, SpaceViolationPolicy.NO_INSERTS); + admin.setQuota(settings); + assertEquals(1, getNumSpaceQuotas()); + assertEquals(1, getThrottleQuotas()); + + + settings = QuotaSettingsFactory.unthrottleNamespace(ns); + admin.setQuota(settings); + assertEquals(1, getNumSpaceQuotas()); + assertEquals(0, getThrottleQuotas()); + + settings = + QuotaSettingsFactory.throttleNamespace(ns, ThrottleType.REQUEST_SIZE, 2L, TimeUnit.HOURS); + admin.setQuota(settings); + assertEquals(1, getNumSpaceQuotas()); + assertEquals(1, getThrottleQuotas()); + + + // Delete the namespace and observe the quotas being automatically deleted as well + admin.deleteNamespace(ns); + assertEquals(0, getNumSpaceQuotas()); assertEquals(0, getThrottleQuotas()); } @Test - public void testTableSpaceAndRPCQuotaRemoved() throws Exception { + public void testTableDropWithSpaceQuota() throws Exception { final Connection conn = TEST_UTIL.getConnection(); final Admin admin = conn.getAdmin(); final TableName tn = TableName.valueOf(testName.getMethodName()); @@ -146,31 +212,48 @@ public class TestMasterQuotasObserver { if (admin.tableExists(tn)) { dropTable(admin, tn); } - createTable(admin, tn); assertEquals(0, getNumSpaceQuotas()); - assertEquals(0, getThrottleQuotas()); - // Set Both quotas - QuotaSettings settings = - QuotaSettingsFactory.limitTableSpace(tn, 1024L, SpaceViolationPolicy.NO_INSERTS); + // Set space quota + QuotaSettings settings = QuotaSettingsFactory.limitTableSpace( + tn, 1024L, SpaceViolationPolicy.NO_INSERTS); admin.setQuota(settings); + assertEquals(1, getNumSpaceQuotas()); - settings = + // Drop the table and observe the Space quota being automatically deleted as well + dropTable(admin, tn); + assertEquals(0, getNumSpaceQuotas()); + } + + @Test + public void testTableDropWithRPCQuota() throws Exception { + final Connection conn = TEST_UTIL.getConnection(); + final Admin admin = conn.getAdmin(); + final TableName tn = TableName.valueOf(testName.getMethodName()); + // Drop the table if it somehow exists + if (admin.tableExists(tn)) { + dropTable(admin, tn); + } + + createTable(admin, tn); + assertEquals(0, getThrottleQuotas()); + + // Set RPC quota + QuotaSettings settings = QuotaSettingsFactory.throttleTable(tn, ThrottleType.REQUEST_SIZE, 2L, TimeUnit.HOURS); admin.setQuota(settings); - assertEquals(1, getNumSpaceQuotas()); assertEquals(1, getThrottleQuotas()); - // Delete the table and observe the quotas being automatically deleted as well + // Delete the table and observe the RPC quota being automatically deleted as well dropTable(admin, tn); - assertEquals(0, getNumSpaceQuotas()); assertEquals(0, getThrottleQuotas()); } + @Test - public void testNamespaceSpaceQuotaRemoved() throws Exception { + public void testNamespaceDropWithSpaceQuota() throws Exception { final Connection conn = TEST_UTIL.getConnection(); final Admin admin = conn.getAdmin(); final String ns = testName.getMethodName(); @@ -196,7 +279,7 @@ public class TestMasterQuotasObserver { } @Test - public void testNamespaceRPCQuotaRemoved() throws Exception { + public void testNamespaceDropWithRPCQuota() throws Exception { final Connection conn = TEST_UTIL.getConnection(); final Admin admin = conn.getAdmin(); final String ns = testName.getMethodName(); @@ -221,41 +304,6 @@ public class TestMasterQuotasObserver { assertEquals(0, getThrottleQuotas()); } - @Test - public void testNamespaceSpaceAndRPCQuotaRemoved() throws Exception { - final Connection conn = TEST_UTIL.getConnection(); - final Admin admin = conn.getAdmin(); - final TableName tn = TableName.valueOf(testName.getMethodName()); - final String ns = testName.getMethodName(); - // Drop the ns if it somehow exists - if (namespaceExists(ns)) { - admin.deleteNamespace(ns); - } - - // Create the ns - NamespaceDescriptor desc = NamespaceDescriptor.create(ns).build(); - admin.createNamespace(desc); - assertEquals(0, getNumSpaceQuotas()); - assertEquals(0, getThrottleQuotas()); - - // Set Both quotas - QuotaSettings settings = - QuotaSettingsFactory.limitNamespaceSpace(ns, 1024L, SpaceViolationPolicy.NO_INSERTS); - admin.setQuota(settings); - - settings = - QuotaSettingsFactory.throttleNamespace(ns, ThrottleType.REQUEST_SIZE, 2L, TimeUnit.HOURS); - admin.setQuota(settings); - - assertEquals(1, getNumSpaceQuotas()); - assertEquals(1, getThrottleQuotas()); - - // Delete the namespace and observe the quotas being automatically deleted as well - admin.deleteNamespace(ns); - assertEquals(0, getNumSpaceQuotas()); - assertEquals(0, getThrottleQuotas()); - } - @Test public void testObserverAddedByDefault() throws Exception { final HMaster master = TEST_UTIL.getHBaseCluster().getMaster(); -- 2.15.1 (Apple Git-101)