HBASE-22944 Check for hbase:quota table existence in SpaceQuotaRefresherChore
During startup, it's possible that quotas are enabled but the Master has not yet created the hbase:quotas table. Closes #559 Signed-off-by: stack <stack@apache.org> Signed-off-by: Josh Elser <elserj@apache.org>
This commit is contained in:
parent
63593d6cce
commit
ffbf8503ea
|
@ -23,6 +23,7 @@ import java.util.Map.Entry;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.hbase.MetaTableAccessor;
|
||||
import org.apache.hadoop.hbase.ScheduledChore;
|
||||
import org.apache.hadoop.hbase.TableName;
|
||||
import org.apache.yetus.audience.InterfaceAudience;
|
||||
|
@ -60,6 +61,7 @@ public class SpaceQuotaRefresherChore extends ScheduledChore {
|
|||
|
||||
private final RegionServerSpaceQuotaManager manager;
|
||||
private final Connection conn;
|
||||
private boolean quotaTablePresent = false;
|
||||
|
||||
public SpaceQuotaRefresherChore(RegionServerSpaceQuotaManager manager, Connection conn) {
|
||||
super(SpaceQuotaRefresherChore.class.getSimpleName(),
|
||||
|
@ -74,6 +76,13 @@ public class SpaceQuotaRefresherChore extends ScheduledChore {
|
|||
@Override
|
||||
protected void chore() {
|
||||
try {
|
||||
// check whether quotaTable is present or not.
|
||||
if (!quotaTablePresent && !checkQuotaTableExists()) {
|
||||
LOG.info("Quota table not found, skipping quota manager cache refresh.");
|
||||
return;
|
||||
}
|
||||
// since quotaTable is present so setting the flag as true.
|
||||
quotaTablePresent = true;
|
||||
if (LOG.isTraceEnabled()) {
|
||||
LOG.trace("Reading current quota snapshots from hbase:quota.");
|
||||
}
|
||||
|
@ -144,6 +153,16 @@ public class SpaceQuotaRefresherChore extends ScheduledChore {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if hbase:quota exists in hbase:meta
|
||||
*
|
||||
* @return true if hbase:quota table is in meta, else returns false.
|
||||
* @throws IOException throws IOException
|
||||
*/
|
||||
boolean checkQuotaTableExists() throws IOException {
|
||||
return MetaTableAccessor.tableExists(getConnection(), QuotaUtil.QUOTA_TABLE_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given <code>snapshot</code> is in violation, allowing the snapshot to be null.
|
||||
* If the snapshot is null, this is interpreted as no snapshot which implies not in violation.
|
||||
|
|
|
@ -82,6 +82,7 @@ public class TestSpaceQuotaViolationPolicyRefresherChore {
|
|||
chore = mock(SpaceQuotaRefresherChore.class);
|
||||
when(chore.getConnection()).thenReturn(conn);
|
||||
when(chore.getManager()).thenReturn(manager);
|
||||
when(chore.checkQuotaTableExists()).thenReturn(true);
|
||||
doCallRealMethod().when(chore).chore();
|
||||
when(chore.isInViolation(any())).thenCallRealMethod();
|
||||
doCallRealMethod().when(chore).extractQuotaSnapshot(any(), any());
|
||||
|
|
Loading…
Reference in New Issue