Skip to content

Commit 181ffe7

Browse files
committed
HBASE-27568 ChaosMonkey add support for JournalNodes (apache#4963)
Signed-off-by: Reid Chan <[email protected]>
1 parent 6d2064d commit 181ffe7

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
@@ -56,7 +56,7 @@ public class DistributedHBaseCluster extends HBaseCluster {
5656
* restarted instances of the same server will have different ServerName and will not coincide
5757
* with past dead ones. So there's no need to cleanup this list.
5858
*/
59-
private Set<ServerName> killedRegionServers = new HashSet<>();
59+
private final Set<ServerName> killedRegionServers = new HashSet<>();
6060

6161
public DistributedHBaseCluster(Configuration conf, ClusterManager clusterManager)
6262
throws IOException {
@@ -247,6 +247,37 @@ public void waitForNameNodeToStop(ServerName serverName, long timeout) throws IO
247247
waitForServiceToStop(ServiceType.HADOOP_NAMENODE, serverName, timeout);
248248
}
249249

250+
@Override
251+
public void startJournalNode(ServerName serverName) throws IOException {
252+
LOG.info("Starting journal node on: {}", serverName.getServerName());
253+
clusterManager.start(ServiceType.HADOOP_JOURNALNODE, serverName.getHostname(),
254+
serverName.getPort());
255+
}
256+
257+
@Override
258+
public void killJournalNode(ServerName serverName) throws IOException {
259+
LOG.info("Aborting journal node on: {}", serverName.getServerName());
260+
clusterManager.kill(ServiceType.HADOOP_JOURNALNODE, serverName.getHostname(),
261+
serverName.getPort());
262+
}
263+
264+
@Override
265+
public void stopJournalNode(ServerName serverName) throws IOException {
266+
LOG.info("Stopping journal node on: {}", serverName.getServerName());
267+
clusterManager.stop(ServiceType.HADOOP_JOURNALNODE, serverName.getHostname(),
268+
serverName.getPort());
269+
}
270+
271+
@Override
272+
public void waitForJournalNodeToStart(ServerName serverName, long timeout) throws IOException {
273+
waitForServiceToStart(ServiceType.HADOOP_JOURNALNODE, serverName, timeout);
274+
}
275+
276+
@Override
277+
public void waitForJournalNodeToStop(ServerName serverName, long timeout) throws IOException {
278+
waitForServiceToStop(ServiceType.HADOOP_JOURNALNODE, serverName, timeout);
279+
}
280+
250281
private void waitForServiceToStop(ServiceType service, ServerName serverName, long timeout)
251282
throws IOException {
252283
LOG.info("Waiting for service: {} to stop: {}", service, serverName.getServerName());
@@ -263,7 +294,7 @@ private void waitForServiceToStop(ServiceType service, ServerName serverName, lo
263294

264295
private void waitForServiceToStart(ServiceType service, ServerName serverName, long timeout)
265296
throws IOException {
266-
LOG.info("Waiting for service: {} to start: ", service, serverName.getServerName());
297+
LOG.info("Waiting for service: {} to start: {}", service, serverName.getServerName());
267298
long start = System.currentTimeMillis();
268299

269300
while ((System.currentTimeMillis() - start) < timeout) {
@@ -358,8 +389,7 @@ public boolean restoreClusterMetrics(ClusterMetrics initial) throws IOException
358389
LOG.info("Restoring cluster - started");
359390

360391
// do a best effort restore
361-
boolean success = true;
362-
success = restoreMasters(initial, current) & success;
392+
boolean success = restoreMasters(initial, current);
363393
success = restoreRegionServers(initial, current) & success;
364394
success = restoreAdmin() & success;
365395

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
@@ -261,18 +261,32 @@ protected void startDataNode(ServerName server) throws IOException {
261261
}
262262

263263
protected void killNameNode(ServerName server) throws IOException {
264-
getLogger().info("Killing namenode :-{}", server.getHostname());
264+
getLogger().info("Killing namenode {}", server.getHostname());
265265
cluster.killNameNode(server);
266266
cluster.waitForNameNodeToStop(server, killNameNodeTimeout);
267-
getLogger().info("Killed namenode:{}. Reported num of rs:{}", server,
267+
getLogger().info("Killed namenode {}. Reported num of rs:{}", server,
268268
cluster.getClusterMetrics().getLiveServerMetrics().size());
269269
}
270270

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

278292
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
@@ -120,4 +120,17 @@ void restartNameNode(ServerName server, long sleepTime) throws IOException {
120120
getLogger().info("Starting name node: {}", server);
121121
startNameNode(server);
122122
}
123+
124+
void restartJournalNode(ServerName server, long sleepTime) throws IOException {
125+
sleepTime = Math.max(sleepTime, 1000);
126+
// Don't try the kill if we're stopping
127+
if (context.isStopping()) {
128+
return;
129+
}
130+
getLogger().info("Killing journal node: {}", server);
131+
killJournalNode(server);
132+
sleep(sleepTime);
133+
getLogger().info("Starting journal node: {}", server);
134+
startJournalNode(server);
135+
}
123136
}
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/HBaseCluster.java

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

286+
/**
287+
* Starts a new journalnode on the given hostname or if this is a mini/local cluster, silently
288+
* logs warning message.
289+
* @throws IOException if something goes wrong
290+
*/
291+
public abstract void startJournalNode(ServerName serverName) throws IOException;
292+
293+
/**
294+
* Kills the journalnode process if this is a distributed cluster, otherwise, this causes master
295+
* to exit doing basic clean up only.
296+
* @throws IOException if something goes wrong
297+
*/
298+
public abstract void killJournalNode(ServerName serverName) throws IOException;
299+
300+
/**
301+
* Stops the journalnode if this is a distributed cluster, otherwise silently logs warning
302+
* message.
303+
* @throws IOException if something goes wrong
304+
*/
305+
public abstract void stopJournalNode(ServerName serverName) throws IOException;
306+
307+
/**
308+
* Wait for the specified journalnode to join the cluster
309+
* @throws IOException if something goes wrong or timeout occurs
310+
*/
311+
public abstract void waitForJournalNodeToStart(ServerName serverName, long timeout)
312+
throws IOException;
313+
314+
/**
315+
* Wait for the specified journalnode to stop
316+
* @throws IOException if something goes wrong or timeout occurs
317+
*/
318+
public abstract void waitForJournalNodeToStop(ServerName serverName, long timeout)
319+
throws IOException;
320+
286321
/**
287322
* Starts a new master on the given hostname or if this is a mini/local cluster, starts a master
288323
* locally.

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

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

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

0 commit comments

Comments
 (0)