BukrosSzabolcs commented on a change in pull request #675: HBASE-23085: Network and Data related Actions URL: https://github.com/apache/hbase/pull/675#discussion_r332084372
########## File path: hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/CorruptPackagesCommandAction.java ########## @@ -0,0 +1,70 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hbase.chaos.actions; + +import java.io.IOException; + +import org.apache.hadoop.hbase.ServerName; +import org.apache.hadoop.hbase.chaos.monkies.PolicyBasedChaosMonkey; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * Corrupt network packages on a random regionserver. + */ +public class CorruptPackagesCommandAction extends CommandAction { + private static final Logger LOG = LoggerFactory.getLogger(CorruptPackagesCommandAction.class); + private float ratio; + private long duration; + + /** + * Corrupt network packages on a random regionserver. + * + * @param ratio the ratio of packages corrupted + * @param duration the time this issue persists in milliseconds + * @param timeout the timeout for executing required commands on the region server in milliseconds + */ + public CorruptPackagesCommandAction(float ratio, long duration, long timeout) { + super(timeout); + this.ratio = ratio; + this.duration = duration; + } + + protected void localPerform() throws IOException { + LOG.info("Starting to execute CorruptPackagesCommandAction"); + ServerName server = PolicyBasedChaosMonkey.selectRandomItem(getCurrentServers()); + String hostname = server.getHostname(); + + try { + clusterManager.execSudoWithRetries(hostname, timeout, getCommand("add")); + Thread.sleep(duration); + } catch (InterruptedException e) { + LOG.debug("Failed to run the command for the full duration", e); + } finally { + clusterManager.execSudoWithRetries(hostname, timeout, getCommand("del")); + } + + LOG.info("Finished to execute CorruptPackagesCommandAction"); + } + + private String getCommand(String operation){ + return String.format("tc qdisc %s dev eth0 root netem corrupt %s%%", operation, ratio * 100); Review comment: What would be the advantage? For a ration of 0.35f, the generated string in it's current form returns "35.0%", if I would replace it with "%f%%", the output would change to "35.000000%". Would you prefer a specific format, like round to 2 decimals? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services