Skip to content

Commit eb92b25

Browse files
authored
HBASE-22803 Modify config value range to enable turning off of the hbck chore (#466)
Signed-off-by: Guanghao Zhang <zghao@apache.org>
1 parent 9250977 commit eb92b25

File tree

4 files changed

+58
-5
lines changed

4 files changed

+58
-5
lines changed

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
@@ -99,14 +99,26 @@ public class HbckChore extends ScheduledChore {
9999
private volatile long checkingStartTimestamp = 0;
100100
private volatile long checkingEndTimestamp = 0;
101101

102+
private boolean disabled = false;
103+
102104
public HbckChore(MasterServices master) {
103105
super("HbckChore-", master,
104106
master.getConfiguration().getInt(HBCK_CHORE_INTERVAL, DEFAULT_HBCK_CHORE_INTERVAL));
105107
this.master = master;
108+
int interval =
109+
master.getConfiguration().getInt(HBCK_CHORE_INTERVAL, DEFAULT_HBCK_CHORE_INTERVAL);
110+
if (interval <= 0) {
111+
LOG.warn(HBCK_CHORE_INTERVAL + " is <=0 hence disabling hbck chore");
112+
disableChore();
113+
}
106114
}
107115

108116
@Override
109117
protected synchronized void chore() {
118+
if (isDisabled() || isRunning()) {
119+
LOG.warn("hbckChore is either disabled or is already running. Can't run the chore");
120+
return;
121+
}
110122
running = true;
111123
regionInfoMap.clear();
112124
orphanRegionsOnRS.clear();
@@ -124,6 +136,29 @@ protected synchronized void chore() {
124136
running = false;
125137
}
126138

139+
// This function does the sanity checks of making sure the chore is not run when it is
140+
// disabled or when it's already running. It returns whether the chore was actually run or not.
141+
protected boolean runChore() {
142+
if (isDisabled() || isRunning()) {
143+
if (isDisabled()) {
144+
LOG.warn("hbck chore is disabled! Set " + HBCK_CHORE_INTERVAL + " > 0 to enable it.");
145+
} else {
146+
LOG.warn("hbck chore already running. Can't run till it finishes.");
147+
}
148+
return false;
149+
}
150+
chore();
151+
return true;
152+
}
153+
154+
private void disableChore() {
155+
this.disabled = true;
156+
}
157+
158+
public boolean isDisabled() {
159+
return this.disabled;
160+
}
161+
127162
private void saveCheckResultToSnapshot() {
128163
// Need synchronized here, as this "snapshot" may be access by web ui.
129164
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
@@ -2376,11 +2376,7 @@ public RunHbckChoreResponse runHbckChore(RpcController c, RunHbckChoreRequest re
23762376
rpcPreCheck("runHbckChore");
23772377
LOG.info("{} request HBCK chore to run", master.getClientIdAuditPrefix());
23782378
HbckChore hbckChore = master.getHbckChore();
2379-
boolean ran = false;
2380-
if (!hbckChore.isRunning()) {
2381-
hbckChore.chore();
2382-
ran = true;
2383-
}
2379+
boolean ran = hbckChore.runChore();
23842380
return RunHbckChoreResponse.newBuilder().setRan(ran).build();
23852381
}
23862382

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

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