Skip to content

Commit

Permalink
HBASE-22146 SpaceQuotaViolationPolicy Disable in Namespace-upd4
Browse files Browse the repository at this point in the history
  • Loading branch information
skochhar committed Jul 15, 2020
1 parent 5a16749 commit 19f46a6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,34 @@ static List<Delete> createDeletesForExistingSnapshotsFromScan(Connection connect
}
}

/**
* Remove table usage snapshots (u:p columns) for the namespace passed
* @param connection connection to re-use
* @param namespace the namespace to fetch the list of table usage snapshots
*/
static void deleteTableUsageSnapshotsForNamespace(Connection connection, String namespace)
throws IOException {
Scan s = new Scan();
//Get rows for all tables in namespace
s.setRowPrefixFilter(Bytes.toBytes("t." + namespace));
//Scan for table usage column (u:p) in quota table
s.addColumn(QUOTA_FAMILY_USAGE,QUOTA_QUALIFIER_POLICY);
//Scan for table quota column (q:s) if table has a space quota defined
s.addColumn(QUOTA_FAMILY_INFO,QUOTA_QUALIFIER_SETTINGS);
try (Table quotaTable = connection.getTable(QUOTA_TABLE_NAME);
ResultScanner rs = quotaTable.getScanner(s)) {
for (Result r : rs) {
byte[] data = r.getValue(QUOTA_FAMILY_INFO, QUOTA_QUALIFIER_SETTINGS);
//if table does not have a table space quota defined, delete table usage column (u:p)
if (data == null) {
Delete delete = new Delete(r.getRow());
delete.addColumns(QUOTA_FAMILY_USAGE,QUOTA_QUALIFIER_POLICY);
quotaTable.delete(delete);
}
}
}
}

/**
* Fetches the computed size of all snapshots against tables in a namespace for space quotas.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.apache.hadoop.hbase.TableNotDisabledException;
import org.apache.hadoop.hbase.TableNotEnabledException;
import org.apache.hadoop.hbase.TableNotFoundException;
import org.apache.hadoop.hbase.NamespaceDescriptor;
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.Delete;
Expand Down Expand Up @@ -265,31 +264,13 @@ private static void deleteQuotas(final Connection connection, final byte[] rowKe
final byte[] qualifier) throws IOException {
Delete delete = new Delete(rowKey);
if (qualifier != null) {
//Check if delete qualifier is for persisted space quota snapshot usage column family
if (Arrays.equals(qualifier,QUOTA_QUALIFIER_POLICY)) {
delete.addColumns(QUOTA_FAMILY_USAGE, qualifier);
} else
delete.addColumns(QUOTA_FAMILY_INFO, qualifier);
delete.addColumns(QUOTA_FAMILY_INFO, qualifier);
}
if (isNamespaceRowKey(rowKey)) {
//Check namespace is not deleted before you get info about quota and list of tables in namespace
NamespaceDescriptor[] descs = connection.getAdmin().listNamespaceDescriptors();
String ns = getNamespaceFromRowKey(rowKey);
int index = 0;
while (index < descs.length) {
if (ns.equals(descs[index].getName())) {
Quotas namespaceQuota = getNamespaceQuota(connection,ns);
if (namespaceQuota != null && namespaceQuota.hasSpace()) {
TableName[] tableArray = connection.getAdmin().listTableNamesByNamespace(ns);
for (TableName tableName : tableArray) {
deleteQuotas(connection, getTableRowKey(tableName), QUOTA_QUALIFIER_POLICY);
}
}
//Exit the while loop by moving to last index
index = descs.length;
} else {
index++;
}
Quotas namespaceQuota = getNamespaceQuota(connection,ns);
if (namespaceQuota != null && namespaceQuota.hasSpace()) {
deleteTableUsageSnapshotsForNamespace(connection, ns);
}
}
doDelete(connection, delete);
Expand Down

0 comments on commit 19f46a6

Please sign in to comment.