Skip to content

Commit cbc328a

Browse files
committed
HBASE-22146 SpaceQuotaViolationPolicy Disable is not working in Namespace level
1 parent 3c31981 commit cbc328a

4 files changed

Lines changed: 79 additions & 0 deletions

File tree

hbase-server/src/main/java/org/apache/hadoop/hbase/namespace/NamespaceAuditor.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.hadoop.hbase.namespace;
1919

2020
import java.io.IOException;
21+
import java.util.Set;
2122

2223
import org.apache.hadoop.hbase.HBaseIOException;
2324
import org.apache.hadoop.hbase.MetaTableAccessor;
@@ -141,6 +142,10 @@ public void addNamespace(NamespaceDescriptor ns) throws IOException {
141142

142143
public void deleteNamespace(String namespace) throws IOException {
143144
stateManager.deleteNamespace(namespace);
145+
Set<TableName> tableNameSet = getState(namespace).getTables();
146+
for (TableName tableName: tableNameSet) {
147+
removeFromNamespaceUsage(tableName);
148+
}
144149
}
145150

146151
public void removeFromNamespaceUsage(TableName tableName)

hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/QuotaUtil.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,14 @@ private static void deleteQuotas(final Connection connection, final byte[] rowKe
267267
delete.addColumns(QUOTA_FAMILY_INFO, qualifier);
268268
}
269269
doDelete(connection, delete);
270+
if (isNamespaceRowKey(rowKey)) {
271+
TableName[] tableArray = connection.getAdmin().listTableNamesByNamespace(getNamespaceFromRowKey(rowKey));
272+
for (TableName tableName: tableArray) {
273+
if (QuotaUtil.getTableQuota(connection, tableName) == null) {
274+
deleteTableQuota(connection,tableName);
275+
}
276+
}
277+
}
270278
}
271279

272280
public static Map<String, UserQuotaState> fetchUserQuotas(final Connection connection,

hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/SpaceQuotaHelperForTests.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,28 @@ TableName writeUntilViolation(SpaceViolationPolicy policyToViolate) throws Excep
158158
return tn;
159159
}
160160

161+
162+
TableName writeUntilViolationAndVerifyViolationInNamespace(
163+
String ns, SpaceViolationPolicy policyToViolate, Mutation m) throws Exception {
164+
final TableName tn = writeUntilViolationInNamespace(ns, policyToViolate);
165+
verifyViolation(policyToViolate, tn, m);
166+
return tn;
167+
}
168+
169+
TableName writeUntilViolationInNamespace(String ns, SpaceViolationPolicy policyToViolate) throws Exception {
170+
TableName tn = createTableWithRegions(ns,10);
171+
172+
setQuotaLimit(ns, policyToViolate, 4L);
173+
174+
// Write more data than should be allowed and flush it to disk
175+
writeData(tn, 5L * SpaceQuotaHelperForTests.ONE_MEGABYTE);
176+
177+
// This should be sufficient time for the chores to run and see the change.
178+
Thread.sleep(5000);
179+
180+
return tn;
181+
}
182+
161183
/**
162184
* Verifies that the given policy on the given table has been violated
163185
*/
@@ -271,6 +293,17 @@ void setQuotaLimit(final TableName tn, SpaceViolationPolicy policy, long sizeInM
271293
LOG.debug("Quota limit set for table = {}, limit = {}", tn, sizeLimit);
272294
}
273295

296+
/**
297+
* Sets the given quota (policy & limit) on the passed namespace.
298+
*/
299+
void setQuotaLimit(String ns, SpaceViolationPolicy policy, long sizeInMBs)
300+
throws Exception {
301+
final long sizeLimit = sizeInMBs * SpaceQuotaHelperForTests.ONE_MEGABYTE;
302+
QuotaSettings settings = QuotaSettingsFactory.limitNamespaceSpace(ns, sizeLimit, policy);
303+
testUtil.getAdmin().setQuota(settings);
304+
LOG.debug("Quota limit set for namespace = {}, limit = {}", ns, sizeLimit);
305+
}
306+
274307
/**
275308
* Removes the space quota from the given table
276309
*/
@@ -280,6 +313,16 @@ void removeQuotaFromtable(final TableName tn) throws Exception {
280313
LOG.debug("Space quota settings removed from the table ", tn);
281314
}
282315

316+
/**
317+
* Removes the space quota from the given namespace
318+
*/
319+
void removeQuotaFromNamespace(String ns) throws Exception {
320+
QuotaSettings removeQuota = QuotaSettingsFactory.removeNamespaceSpaceLimit(ns);
321+
Admin admin = testUtil.getAdmin();
322+
admin.setQuota(removeQuota);
323+
LOG.debug("Space quota settings removed from the namespace ", ns);
324+
}
325+
283326
/**
284327
* Removes all quotas defined in the HBase quota table.
285328
*/

hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestSpaceQuotaRemoval.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.apache.hadoop.conf.Configuration;
2121
import org.apache.hadoop.hbase.HBaseClassTestRule;
2222
import org.apache.hadoop.hbase.HBaseTestingUtility;
23+
import org.apache.hadoop.hbase.NamespaceDescriptor;
2324
import org.apache.hadoop.hbase.TableName;
2425
import org.apache.hadoop.hbase.client.Put;
2526
import org.apache.hadoop.hbase.testclassification.LargeTests;
@@ -139,6 +140,28 @@ private void setQuotaAndThenRemove(SpaceViolationPolicy policy) throws Exception
139140
helper.verifyNoViolation(tn, put);
140141
}
141142

143+
@Test
144+
public void testSetNamespaceSizeQuotaAndThenRemove() throws Exception {
145+
Put put = new Put(Bytes.toBytes("to_reject"));
146+
put.addColumn(Bytes.toBytes(SpaceQuotaHelperForTests.F1), Bytes.toBytes("to"),
147+
Bytes.toBytes("reject"));
148+
149+
SpaceViolationPolicy policy = SpaceViolationPolicy.NO_INSERTS;
150+
151+
//Create namespace
152+
NamespaceDescriptor nsd = helper.createNamespace();
153+
String ns = nsd.getName();
154+
155+
// Do puts until we violate space policy on table tn1
156+
final TableName tn1 = helper.writeUntilViolationAndVerifyViolationInNamespace(ns, policy, put);
157+
158+
// Now, remove the quota from namespace
159+
helper.removeQuotaFromNamespace(ns);
160+
161+
// Put a new row now on tn1: should not violate as quota settings removed from namespace
162+
helper.verifyNoViolation(tn1, put);
163+
}
164+
142165
private void setQuotaAndThenRemoveInOneAmongTwoTables(SpaceViolationPolicy policy)
143166
throws Exception {
144167
Put put = new Put(Bytes.toBytes("to_reject"));

0 commit comments

Comments
 (0)