Skip to content

Commit da26134

Browse files
authored
HBASE-27568 ChaosMonkey add support for JournalNodes (#4963)
Signed-off-by: Reid Chan <[email protected]>
1 parent cc54d22 commit da26134

File tree

8 files changed

+208
-9
lines changed

8 files changed

+208
-9
lines changed

hbase-it/src/test/java/org/apache/hadoop/hbase/ClusterManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ interface ClusterManager extends Configurable {
3131
/**
3232
* Type of the service daemon
3333
*/
34-
public static enum ServiceType {
34+
enum ServiceType {
3535
HADOOP_NAMENODE("namenode"),
3636
HADOOP_DATANODE("datanode"),
37+
HADOOP_JOURNALNODE("journalnode"),
3738
HADOOP_JOBTRACKER("jobtracker"),
3839
HADOOP_TASKTRACKER("tasktracker"),
3940
ZOOKEEPER_SERVER("QuorumPeerMain"),

hbase-it/src/test/java/org/apache/hadoop/hbase/DistributedHBaseCluster.java

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class DistributedHBaseCluster extends HBaseClusterInterface {
5858
* restarted instances of the same server will have different ServerName and will not coincide
5959
* with past dead ones. So there's no need to cleanup this list.
6060
*/
61-
private Set<ServerName> killedRegionServers = new HashSet<>();
61+
private final Set<ServerName> killedRegionServers = new HashSet<>();
6262

6363
public DistributedHBaseCluster(Configuration conf, ClusterManager clusterManager)
6464
throws IOException {
@@ -237,6 +237,37 @@ public void waitForNameNodeToStop(ServerName serverName, long timeout) throws IO
237237
waitForServiceToStop(ServiceType.HADOOP_NAMENODE, serverName, timeout);
238238
}
239239

240+
@Override
241+
public void startJournalNode(ServerName serverName) throws IOException {
242+
LOG.info("Starting journal node on: {}", serverName.getServerName());
243+
clusterManager.start(ServiceType.HADOOP_JOURNALNODE, serverName.getHostname(),
244+
serverName.getPort());
245+
}
246+
247+
@Override
248+
public void killJournalNode(ServerName serverName) throws IOException {
249+
LOG.info("Aborting journal node on: {}", serverName.getServerName());
250+
clusterManager.kill(ServiceType.HADOOP_JOURNALNODE, serverName.getHostname(),
251+
serverName.getPort());
252+
}
253+
254+
@Override
255+
public void stopJournalNode(ServerName serverName) throws IOException {
256+
LOG.info("Stopping journal node on: {}", serverName.getServerName());
257+
clusterManager.stop(ServiceType.HADOOP_JOURNALNODE, serverName.getHostname(),
258+
serverName.getPort());
259+
}
260+
261+
@Override
262+
public void waitForJournalNodeToStart(ServerName serverName, long timeout) throws IOException {
263+
waitForServiceToStart(ServiceType.HADOOP_JOURNALNODE, serverName, timeout);
264+
}
265+
266+
@Override
267+
public void waitForJournalNodeToStop(ServerName serverName, long timeout) throws IOException {
268+
waitForServiceToStop(ServiceType.HADOOP_JOURNALNODE, serverName, timeout);
269+
}
270+
240271
private void waitForServiceToStop(ServiceType service, ServerName serverName, long timeout)
241272
throws IOException {
242273
LOG.info("Waiting for service: {} to stop: {}", service, serverName.getServerName());
@@ -253,7 +284,7 @@ private void waitForServiceToStop(ServiceType service, ServerName serverName, lo
253284

254285
private void waitForServiceToStart(ServiceType service, ServerName serverName, long timeout)
255286
throws IOException {
256-
LOG.info("Waiting for service: {} to start: ", service, serverName.getServerName());
287+
LOG.info("Waiting for service: {} to start: {}", service, serverName.getServerName());
257288
long start = EnvironmentEdgeManager.currentTime();
258289

259290
while ((EnvironmentEdgeManager.currentTime() - start) < timeout) {
@@ -343,8 +374,7 @@ public boolean restoreClusterMetrics(ClusterMetrics initial) throws IOException
343374
LOG.info("Restoring cluster - started");
344375

345376
// do a best effort restore
346-
boolean success = true;
347-
success = restoreMasters(initial, current) && success;
377+
boolean success = restoreMasters(initial, current);
348378
success = restoreRegionServers(initial, current) && success;
349379
success = restoreAdmin() && success;
350380

hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/Action.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,18 +260,32 @@ protected void startDataNode(ServerName server) throws IOException {
260260
}
261261

262262
protected void killNameNode(ServerName server) throws IOException {
263-
getLogger().info("Killing namenode :-{}", server.getHostname());
263+
getLogger().info("Killing namenode {}", server.getHostname());
264264
cluster.killNameNode(server);
265265
cluster.waitForNameNodeToStop(server, killNameNodeTimeout);
266-
getLogger().info("Killed namenode:{}. Reported num of rs:{}", server,
266+
getLogger().info("Killed namenode {}. Reported num of rs:{}", server,
267267
cluster.getClusterMetrics().getLiveServerMetrics().size());
268268
}
269269

270270
protected void startNameNode(ServerName server) throws IOException {
271-
getLogger().info("Starting Namenode :-{}", server.getHostname());
271+
getLogger().info("Starting namenode {}", server.getHostname());
272272
cluster.startNameNode(server);
273273
cluster.waitForNameNodeToStart(server, startNameNodeTimeout);
274-
getLogger().info("Started namenode:{}", server);
274+
getLogger().info("Started namenode {}", server);
275+
}
276+
277+
protected void killJournalNode(ServerName server) throws IOException {
278+
getLogger().info("Killing journalnode {}", server.getHostname());
279+
cluster.killJournalNode(server);
280+
cluster.waitForJournalNodeToStop(server, killNameNodeTimeout);
281+
getLogger().info("Killed journalnode {}", server);
282+
}
283+
284+
protected void startJournalNode(ServerName server) throws IOException {
285+
getLogger().info("Starting journalnode {}", server.getHostname());
286+
cluster.startJournalNode(server);
287+
cluster.waitForJournalNodeToStart(server, startNameNodeTimeout);
288+
getLogger().info("Started journalnode {}", server);
275289
}
276290

277291
protected void unbalanceRegions(ClusterMetrics clusterStatus, List<ServerName> fromServers,

hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RestartActionBaseAction.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,17 @@ void restartNameNode(ServerName server, long sleepTime) throws IOException {
122122
getLogger().info("Starting name node: {}", server);
123123
startNameNode(server);
124124
}
125+
126+
void restartJournalNode(ServerName server, long sleepTime) throws IOException {
127+
sleepTime = Math.max(sleepTime, 1000);
128+
// Don't try the kill if we're stopping
129+
if (context.isStopping()) {
130+
return;
131+
}
132+
getLogger().info("Killing journal node: {}", server);
133+
killJournalNode(server);
134+
sleep(sleepTime);
135+
getLogger().info("Starting journal node: {}", server);
136+
startJournalNode(server);
137+
}
125138
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.hbase.chaos.actions;
19+
20+
import java.util.Arrays;
21+
import org.apache.commons.lang3.StringUtils;
22+
import org.apache.hadoop.conf.Configuration;
23+
import org.apache.hadoop.hbase.ServerName;
24+
import org.apache.hadoop.hbase.chaos.monkies.PolicyBasedChaosMonkey;
25+
import org.apache.hadoop.hbase.net.Address;
26+
import org.apache.hadoop.hdfs.DFSUtil;
27+
import org.apache.hadoop.hdfs.DistributedFileSystem;
28+
import org.apache.hadoop.hdfs.HAUtil;
29+
import org.slf4j.Logger;
30+
import org.slf4j.LoggerFactory;
31+
32+
public class RestartRandomJournalNodeAction extends RestartActionBaseAction {
33+
private static final Logger LOG = LoggerFactory.getLogger(RestartRandomJournalNodeAction.class);
34+
35+
public RestartRandomJournalNodeAction(long sleepTime) {
36+
super(sleepTime);
37+
}
38+
39+
@Override
40+
protected Logger getLogger() {
41+
return LOG;
42+
}
43+
44+
@Override
45+
public void perform() throws Exception {
46+
getLogger().info("Performing action: Restart random JournalNode");
47+
48+
final String qjournal;
49+
try (final DistributedFileSystem dfs = HdfsActionUtils.createDfs(getConf())) {
50+
final Configuration conf = dfs.getConf();
51+
final String nameServiceID = DFSUtil.getNamenodeNameServiceId(conf);
52+
if (!HAUtil.isHAEnabled(conf, nameServiceID)) {
53+
getLogger().info("HA for HDFS is not enabled; skipping");
54+
return;
55+
}
56+
57+
qjournal = conf.get("dfs.namenode.shared.edits.dir");
58+
if (StringUtils.isEmpty(qjournal)) {
59+
getLogger().info("Empty qjournals!");
60+
return;
61+
}
62+
}
63+
64+
final ServerName journalNode =
65+
PolicyBasedChaosMonkey.selectRandomItem(getJournalNodes(qjournal));
66+
restartJournalNode(journalNode, sleepTime);
67+
}
68+
69+
private static ServerName[] getJournalNodes(final String qjournal) {
70+
// WARNING: HDFS internals. qjournal looks like this:
71+
// qjournal://journalnode-0.example.com:8485;...;journalnode-N.example.com:8485/hk8se
72+
// When done, we have an array of journalnodes+ports: e.g.journalnode-0.example.com:8485
73+
final String[] journalNodes =
74+
qjournal.toLowerCase().replaceAll("qjournal:\\/\\/", "").replaceAll("\\/.*$", "").split(";");
75+
return Arrays.stream(journalNodes).map(Address::fromString)
76+
.map(addr -> ServerName.valueOf(addr.getHostName(), addr.getPort()))
77+
.toArray(ServerName[]::new);
78+
}
79+
}

hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/ServerAndDependenciesKillingMonkeyFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.apache.hadoop.hbase.chaos.actions.RestartActiveMasterAction;
2626
import org.apache.hadoop.hbase.chaos.actions.RestartActiveNameNodeAction;
2727
import org.apache.hadoop.hbase.chaos.actions.RestartRandomDataNodeAction;
28+
import org.apache.hadoop.hbase.chaos.actions.RestartRandomJournalNodeAction;
2829
import org.apache.hadoop.hbase.chaos.actions.RestartRandomRsExceptMetaAction;
2930
import org.apache.hadoop.hbase.chaos.actions.RestartRandomZKNodeAction;
3031
import org.apache.hadoop.hbase.chaos.actions.RollingBatchRestartRsAction;
@@ -59,6 +60,7 @@ public ChaosMonkey build() {
5960
new ForceBalancerAction(),
6061
new RestartActiveNameNodeAction(60000),
6162
new RestartRandomDataNodeAction(60000),
63+
new RestartRandomJournalNodeAction(60000),
6264
new RestartRandomZKNodeAction(60000),
6365
new GracefulRollingRestartRsAction(gracefulRollingRestartTSSLeepTime),
6466
new RollingBatchSuspendResumeRsAction(rollingBatchSuspendRSSleepTime,

hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseClusterInterface.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,41 @@ public abstract void waitForNameNodeToStart(ServerName serverName, long timeout)
262262
public abstract void waitForNameNodeToStop(ServerName serverName, long timeout)
263263
throws IOException;
264264

265+
/**
266+
* Starts a new journalnode on the given hostname or if this is a mini/local cluster, silently
267+
* logs warning message.
268+
* @throws IOException if something goes wrong
269+
*/
270+
public abstract void startJournalNode(ServerName serverName) throws IOException;
271+
272+
/**
273+
* Kills the journalnode process if this is a distributed cluster, otherwise, this causes master
274+
* to exit doing basic clean up only.
275+
* @throws IOException if something goes wrong
276+
*/
277+
public abstract void killJournalNode(ServerName serverName) throws IOException;
278+
279+
/**
280+
* Stops the journalnode if this is a distributed cluster, otherwise silently logs warning
281+
* message.
282+
* @throws IOException if something goes wrong
283+
*/
284+
public abstract void stopJournalNode(ServerName serverName) throws IOException;
285+
286+
/**
287+
* Wait for the specified journalnode to join the cluster
288+
* @throws IOException if something goes wrong or timeout occurs
289+
*/
290+
public abstract void waitForJournalNodeToStart(ServerName serverName, long timeout)
291+
throws IOException;
292+
293+
/**
294+
* Wait for the specified journalnode to stop
295+
* @throws IOException if something goes wrong or timeout occurs
296+
*/
297+
public abstract void waitForJournalNodeToStop(ServerName serverName, long timeout)
298+
throws IOException;
299+
265300
/**
266301
* Starts a new master on the given hostname or if this is a mini/local cluster, starts a master
267302
* locally.

hbase-server/src/test/java/org/apache/hadoop/hbase/SingleProcessHBaseCluster.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,31 @@ public void waitForNameNodeToStop(ServerName serverName, long timeout) throws IO
372372
LOG.warn("Waiting for namenodes to stop on mini cluster is not supported");
373373
}
374374

375+
@Override
376+
public void startJournalNode(ServerName serverName) {
377+
LOG.warn("Starting journalnodes on mini cluster is not supported");
378+
}
379+
380+
@Override
381+
public void killJournalNode(ServerName serverName) {
382+
LOG.warn("Aborting journalnodes on mini cluster is not supported");
383+
}
384+
385+
@Override
386+
public void stopJournalNode(ServerName serverName) {
387+
LOG.warn("Stopping journalnodes on mini cluster is not supported");
388+
}
389+
390+
@Override
391+
public void waitForJournalNodeToStart(ServerName serverName, long timeout) {
392+
LOG.warn("Waiting for journalnodes to start on mini cluster is not supported");
393+
}
394+
395+
@Override
396+
public void waitForJournalNodeToStop(ServerName serverName, long timeout) {
397+
LOG.warn("Waiting for journalnodes to stop on mini cluster is not supported");
398+
}
399+
375400
@Override
376401
public void startMaster(String hostname, int port) throws IOException {
377402
this.startMaster();

0 commit comments

Comments
 (0)