Skip to content

Commit 2b3c9b1

Browse files
shardul-cr7joshelser
authored andcommitted
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 <[email protected]> Signed-off-by: Josh Elser <[email protected]>
1 parent e890776 commit 2b3c9b1

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.concurrent.TimeUnit;
2424

2525
import org.apache.hadoop.conf.Configuration;
26+
import org.apache.hadoop.hbase.MetaTableAccessor;
2627
import org.apache.hadoop.hbase.ScheduledChore;
2728
import org.apache.hadoop.hbase.TableName;
2829
import org.apache.yetus.audience.InterfaceAudience;
@@ -60,6 +61,7 @@ public class SpaceQuotaRefresherChore extends ScheduledChore {
6061

6162
private final RegionServerSpaceQuotaManager manager;
6263
private final Connection conn;
64+
private boolean quotaTablePresent = false;
6365

6466
public SpaceQuotaRefresherChore(RegionServerSpaceQuotaManager manager, Connection conn) {
6567
super(SpaceQuotaRefresherChore.class.getSimpleName(),
@@ -74,6 +76,13 @@ public SpaceQuotaRefresherChore(RegionServerSpaceQuotaManager manager, Connectio
7476
@Override
7577
protected void chore() {
7678
try {
79+
// check whether quotaTable is present or not.
80+
if (!quotaTablePresent && !checkQuotaTableExists()) {
81+
LOG.info("Quota table not found, skipping quota manager cache refresh.");
82+
return;
83+
}
84+
// since quotaTable is present so setting the flag as true.
85+
quotaTablePresent = true;
7786
if (LOG.isTraceEnabled()) {
7887
LOG.trace("Reading current quota snapshots from hbase:quota.");
7988
}
@@ -144,6 +153,16 @@ protected void chore() {
144153
}
145154
}
146155

156+
/**
157+
* Checks if hbase:quota exists in hbase:meta
158+
*
159+
* @return true if hbase:quota table is in meta, else returns false.
160+
* @throws IOException throws IOException
161+
*/
162+
boolean checkQuotaTableExists() throws IOException {
163+
return MetaTableAccessor.tableExists(getConnection(), QuotaUtil.QUOTA_TABLE_NAME);
164+
}
165+
147166
/**
148167
* Checks if the given <code>snapshot</code> is in violation, allowing the snapshot to be null.
149168
* If the snapshot is null, this is interpreted as no snapshot which implies not in violation.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public void setup() throws IOException {
8282
chore = mock(SpaceQuotaRefresherChore.class);
8383
when(chore.getConnection()).thenReturn(conn);
8484
when(chore.getManager()).thenReturn(manager);
85+
when(chore.checkQuotaTableExists()).thenReturn(true);
8586
doCallRealMethod().when(chore).chore();
8687
when(chore.isInViolation(any())).thenCallRealMethod();
8788
doCallRealMethod().when(chore).extractQuotaSnapshot(any(), any());

0 commit comments

Comments
 (0)