Skip to content

Commit 66197dd

Browse files
committed
HBASE-22803 Modify config value range to enable turning off of the hbck chore (#466)
Signed-off-by: Guanghao Zhang <[email protected]>
1 parent 549348a commit 66197dd

4 files changed

Lines changed: 58 additions & 5 deletions

File tree

hbase-server/src/main/java/org/apache/hadoop/hbase/master/HbckChore.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,26 @@ public class HbckChore extends ScheduledChore {
101101
private volatile long checkingStartTimestamp = 0;
102102
private volatile long checkingEndTimestamp = 0;
103103

104+
private boolean disabled = false;
105+
104106
public HbckChore(MasterServices master) {
105107
super("HbckChore-", master,
106108
master.getConfiguration().getInt(HBCK_CHORE_INTERVAL, DEFAULT_HBCK_CHORE_INTERVAL));
107109
this.master = master;
110+
int interval =
111+
master.getConfiguration().getInt(HBCK_CHORE_INTERVAL, DEFAULT_HBCK_CHORE_INTERVAL);
112+
if (interval <= 0) {
113+
LOG.warn(HBCK_CHORE_INTERVAL + " is <=0 hence disabling hbck chore");
114+
disableChore();
115+
}
108116
}
109117

110118
@Override
111119
protected synchronized void chore() {
120+
if (isDisabled() || isRunning()) {
121+
LOG.warn("hbckChore is either disabled or is already running. Can't run the chore");
122+
return;
123+
}
112124
running = true;
113125
regionInfoMap.clear();
114126
disabledTableRegions.clear();
@@ -127,6 +139,29 @@ protected synchronized void chore() {
127139
running = false;
128140
}
129141

142+
// This function does the sanity checks of making sure the chore is not run when it is
143+
// disabled or when it's already running. It returns whether the chore was actually run or not.
144+
protected boolean runChore() {
145+
if (isDisabled() || isRunning()) {
146+
if (isDisabled()) {
147+
LOG.warn("hbck chore is disabled! Set " + HBCK_CHORE_INTERVAL + " > 0 to enable it.");
148+
} else {
149+
LOG.warn("hbck chore already running. Can't run till it finishes.");
150+
}
151+
return false;
152+
}
153+
chore();
154+
return true;
155+
}
156+
157+
private void disableChore() {
158+
this.disabled = true;
159+
}
160+
161+
public boolean isDisabled() {
162+
return this.disabled;
163+
}
164+
130165
private void saveCheckResultToSnapshot() {
131166
// Need synchronized here, as this "snapshot" may be access by web ui.
132167
rwLock.writeLock().lock();

hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterRpcServices.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2324,11 +2324,7 @@ public RunHbckChoreResponse runHbckChore(RpcController c, RunHbckChoreRequest re
23242324
rpcPreCheck("runHbckChore");
23252325
LOG.info("{} request HBCK chore to run", master.getClientIdAuditPrefix());
23262326
HbckChore hbckChore = master.getHbckChore();
2327-
boolean ran = false;
2328-
if (!hbckChore.isRunning()) {
2329-
hbckChore.chore();
2330-
ran = true;
2331-
}
2327+
boolean ran = hbckChore.runChore();
23322328
return RunHbckChoreResponse.newBuilder().setRan(ran).build();
23332329
}
23342330

hbase-server/src/main/resources/hbase-webapps/master/hbck.jsp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@
8181
<div class="page-header">
8282
<h1>HBCK Chore Report</h1>
8383
<p>
84+
<% if (hbckChore.isDisabled()) { %>
85+
<span>HBCK chore is currently disabled. Set hbase.master.hbck.chore.interval > 0 in the config & do a rolling-restart to enable it.</span>
86+
<% } else { %>
8487
<span>Checking started at <%= iso8601start %> and generated report at <%= iso8601end %>. Execute 'hbck_chore_run' in hbase shell to generate a new sub-report.</span>
88+
<% } %>
8589
</p>
8690
</div>
8791
</div>

hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestHbckChore.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,22 @@ public void testOrphanRegionsOnFS() throws Exception {
198198
hbckChore.choreForTesting();
199199
assertEquals(0, hbckChore.getOrphanRegionsOnFS().size());
200200
}
201+
202+
@Test
203+
public void testChoreDisable() {
204+
// The way to disable to chore is to set hbase.master.hbck.chore.interval <= 0
205+
// When the interval is > 0, the chore should run.
206+
long lastRunTime = hbckChore.getCheckingEndTimestamp();
207+
hbckChore.choreForTesting();
208+
boolean ran = lastRunTime != hbckChore.getCheckingEndTimestamp();
209+
assertTrue(ran);
210+
211+
// When the interval <= 0, the chore shouldn't run
212+
master.getConfiguration().setInt("hbase.master.hbck.chore.interval", 0);
213+
HbckChore hbckChoreWithChangedConf = new HbckChore(master);
214+
lastRunTime = hbckChoreWithChangedConf.getCheckingEndTimestamp();
215+
hbckChoreWithChangedConf.choreForTesting();
216+
ran = lastRunTime != hbckChoreWithChangedConf.getCheckingEndTimestamp();
217+
assertFalse(ran);
218+
}
201219
}

0 commit comments

Comments
 (0)