HBASE-8994 Adding log to chaos monkey actions to show what're performed

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1505144 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
jxiang 2013-07-20 14:38:27 +00:00
parent 245cd38983
commit b17b2e46a8
1 changed files with 42 additions and 7 deletions

View File

@ -331,6 +331,7 @@ public class ChaosMonkey extends AbstractHBaseTool implements Stoppable {
public static class MoveRegionsOfTable extends Action { public static class MoveRegionsOfTable extends Action {
private final long sleepTime; private final long sleepTime;
private final byte[] tableNameBytes; private final byte[] tableNameBytes;
private final String tableName;
public MoveRegionsOfTable(String tableName) { public MoveRegionsOfTable(String tableName) {
this(-1, tableName); this(-1, tableName);
@ -339,6 +340,7 @@ public class ChaosMonkey extends AbstractHBaseTool implements Stoppable {
public MoveRegionsOfTable(long sleepTime, String tableName) { public MoveRegionsOfTable(long sleepTime, String tableName) {
this.sleepTime = sleepTime; this.sleepTime = sleepTime;
this.tableNameBytes = Bytes.toBytes(tableName); this.tableNameBytes = Bytes.toBytes(tableName);
this.tableName = tableName;
} }
@Override @Override
@ -349,11 +351,13 @@ public class ChaosMonkey extends AbstractHBaseTool implements Stoppable {
Collection<ServerName> serversList = admin.getClusterStatus().getServers(); Collection<ServerName> serversList = admin.getClusterStatus().getServers();
ServerName[] servers = serversList.toArray(new ServerName[serversList.size()]); ServerName[] servers = serversList.toArray(new ServerName[serversList.size()]);
LOG.info("Performing action: Move regions of table " + tableName);
for (HRegionInfo regionInfo:regions) { for (HRegionInfo regionInfo:regions) {
try { try {
byte[] destServerName = String destServerName =
Bytes.toBytes(servers[RandomUtils.nextInt(servers.length)].getServerName()); servers[RandomUtils.nextInt(servers.length)].getServerName();
admin.move(regionInfo.getRegionName(), destServerName); LOG.debug("Moving " + regionInfo.getRegionNameAsString() + " to " + destServerName);
admin.move(regionInfo.getRegionName(), Bytes.toBytes(destServerName));
} catch (Exception e) { } catch (Exception e) {
LOG.debug("Error moving region", e); LOG.debug("Error moving region", e);
} }
@ -367,6 +371,7 @@ public class ChaosMonkey extends AbstractHBaseTool implements Stoppable {
public static class MoveRandomRegionOfTable extends Action { public static class MoveRandomRegionOfTable extends Action {
private final long sleepTime; private final long sleepTime;
private final byte[] tableNameBytes; private final byte[] tableNameBytes;
private final String tableName;
public MoveRandomRegionOfTable(String tableName) { public MoveRandomRegionOfTable(String tableName) {
this(-1, tableName); this(-1, tableName);
@ -375,6 +380,7 @@ public class ChaosMonkey extends AbstractHBaseTool implements Stoppable {
public MoveRandomRegionOfTable(long sleepTime, String tableName) { public MoveRandomRegionOfTable(long sleepTime, String tableName) {
this.sleepTime = sleepTime; this.sleepTime = sleepTime;
this.tableNameBytes = Bytes.toBytes(tableName); this.tableNameBytes = Bytes.toBytes(tableName);
this.tableName = tableName;
} }
@Override @Override
@ -385,6 +391,8 @@ public class ChaosMonkey extends AbstractHBaseTool implements Stoppable {
List<HRegionInfo> regions = admin.getTableRegions(tableNameBytes); List<HRegionInfo> regions = admin.getTableRegions(tableNameBytes);
HRegionInfo region = selectRandomItem( HRegionInfo region = selectRandomItem(
regions.toArray(new HRegionInfo[regions.size()])); regions.toArray(new HRegionInfo[regions.size()]));
LOG.info("Performing action: Move random region of table "
+ tableName + ", region=" + region.getRegionNameAsString());
admin.unassign(region.getRegionName(), false); admin.unassign(region.getRegionName(), false);
if (sleepTime > 0) { if (sleepTime > 0) {
Thread.sleep(sleepTime); Thread.sleep(sleepTime);
@ -395,6 +403,7 @@ public class ChaosMonkey extends AbstractHBaseTool implements Stoppable {
public static class SplitRandomRegionOfTable extends Action { public static class SplitRandomRegionOfTable extends Action {
private final byte[] tableNameBytes; private final byte[] tableNameBytes;
private final long sleepTime; private final long sleepTime;
private final String tableName;
public SplitRandomRegionOfTable(String tableName) { public SplitRandomRegionOfTable(String tableName) {
this(-1, tableName); this(-1, tableName);
@ -403,6 +412,7 @@ public class ChaosMonkey extends AbstractHBaseTool implements Stoppable {
public SplitRandomRegionOfTable(int sleepTime, String tableName) { public SplitRandomRegionOfTable(int sleepTime, String tableName) {
this.tableNameBytes = Bytes.toBytes(tableName); this.tableNameBytes = Bytes.toBytes(tableName);
this.sleepTime = sleepTime; this.sleepTime = sleepTime;
this.tableName = tableName;
} }
@Override @Override
@ -413,6 +423,8 @@ public class ChaosMonkey extends AbstractHBaseTool implements Stoppable {
List<HRegionInfo> regions = admin.getTableRegions(tableNameBytes); List<HRegionInfo> regions = admin.getTableRegions(tableNameBytes);
HRegionInfo region = selectRandomItem( HRegionInfo region = selectRandomItem(
regions.toArray(new HRegionInfo[regions.size()])); regions.toArray(new HRegionInfo[regions.size()]));
LOG.info("Performing action: Split random region of table "
+ tableName + ", region=" + region.getRegionNameAsString());
admin.split(region.getRegionName()); admin.split(region.getRegionName());
if (sleepTime > 0) { if (sleepTime > 0) {
Thread.sleep(sleepTime); Thread.sleep(sleepTime);
@ -439,7 +451,8 @@ public class ChaosMonkey extends AbstractHBaseTool implements Stoppable {
public void perform() throws Exception { public void perform() throws Exception {
HBaseTestingUtility util = context.getHaseIntegrationTestingUtility(); HBaseTestingUtility util = context.getHaseIntegrationTestingUtility();
HBaseAdmin admin = util.getHBaseAdmin(); HBaseAdmin admin = util.getHBaseAdmin();
LOG.info("Performing action: Merge random adjacent regions of table " + tableName);
List<HRegionInfo> regions = admin.getTableRegions(tableNameBytes); List<HRegionInfo> regions = admin.getTableRegions(tableNameBytes);
if (regions.size() < 2) { if (regions.size() < 2) {
LOG.info("Table " + tableName + " doesn't have enough region to merge"); LOG.info("Table " + tableName + " doesn't have enough region to merge");
@ -449,6 +462,7 @@ public class ChaosMonkey extends AbstractHBaseTool implements Stoppable {
int i = RandomUtils.nextInt(regions.size() - 1); int i = RandomUtils.nextInt(regions.size() - 1);
HRegionInfo a = regions.get(i++); HRegionInfo a = regions.get(i++);
HRegionInfo b = regions.get(i); HRegionInfo b = regions.get(i);
LOG.debug("Merging " + a.getRegionNameAsString() + " and " + b.getRegionNameAsString());
admin.mergeRegions(a.getEncodedNameAsBytes(), b.getEncodedNameAsBytes(), false); admin.mergeRegions(a.getEncodedNameAsBytes(), b.getEncodedNameAsBytes(), false);
if (sleepTime > 0) { if (sleepTime > 0) {
Thread.sleep(sleepTime); Thread.sleep(sleepTime);
@ -460,6 +474,7 @@ public class ChaosMonkey extends AbstractHBaseTool implements Stoppable {
private final byte[] tableNameBytes; private final byte[] tableNameBytes;
private final int majorRatio; private final int majorRatio;
private final long sleepTime; private final long sleepTime;
private final String tableName;
public CompactTable( public CompactTable(
String tableName, float majorRatio) { String tableName, float majorRatio) {
@ -471,13 +486,17 @@ public class ChaosMonkey extends AbstractHBaseTool implements Stoppable {
this.tableNameBytes = Bytes.toBytes(tableName); this.tableNameBytes = Bytes.toBytes(tableName);
this.majorRatio = (int) (100 * majorRatio); this.majorRatio = (int) (100 * majorRatio);
this.sleepTime = sleepTime; this.sleepTime = sleepTime;
this.tableName = tableName;
} }
@Override @Override
public void perform() throws Exception { public void perform() throws Exception {
HBaseTestingUtility util = context.getHaseIntegrationTestingUtility(); HBaseTestingUtility util = context.getHaseIntegrationTestingUtility();
HBaseAdmin admin = util.getHBaseAdmin(); HBaseAdmin admin = util.getHBaseAdmin();
if (RandomUtils.nextInt(100) < majorRatio) { boolean major = RandomUtils.nextInt(100) < majorRatio;
LOG.info("Performing action: Compact table " + tableName + ", major=" + major);
if (major) {
admin.majorCompact(tableNameBytes); admin.majorCompact(tableNameBytes);
} else { } else {
admin.compact(tableNameBytes); admin.compact(tableNameBytes);
@ -492,6 +511,7 @@ public class ChaosMonkey extends AbstractHBaseTool implements Stoppable {
private final byte[] tableNameBytes; private final byte[] tableNameBytes;
private final int majorRatio; private final int majorRatio;
private final long sleepTime; private final long sleepTime;
private final String tableName;
public CompactRandomRegionOfTable( public CompactRandomRegionOfTable(
String tableName, float majorRatio) { String tableName, float majorRatio) {
@ -503,6 +523,7 @@ public class ChaosMonkey extends AbstractHBaseTool implements Stoppable {
this.tableNameBytes = Bytes.toBytes(tableName); this.tableNameBytes = Bytes.toBytes(tableName);
this.majorRatio = (int) (100 * majorRatio); this.majorRatio = (int) (100 * majorRatio);
this.sleepTime = sleepTime; this.sleepTime = sleepTime;
this.tableName = tableName;
} }
@Override @Override
@ -512,7 +533,11 @@ public class ChaosMonkey extends AbstractHBaseTool implements Stoppable {
List<HRegionInfo> regions = admin.getTableRegions(tableNameBytes); List<HRegionInfo> regions = admin.getTableRegions(tableNameBytes);
HRegionInfo region = selectRandomItem( HRegionInfo region = selectRandomItem(
regions.toArray(new HRegionInfo[regions.size()])); regions.toArray(new HRegionInfo[regions.size()]));
if (RandomUtils.nextInt(100) < majorRatio) { boolean major = RandomUtils.nextInt(100) < majorRatio;
LOG.info("Performing action: Compact random region of table "
+ tableName + ", major=" + major + ", region=" + region.getRegionNameAsString());
if (major) {
admin.majorCompact(region.getRegionName()); admin.majorCompact(region.getRegionName());
} else { } else {
admin.compact(region.getRegionName()); admin.compact(region.getRegionName());
@ -526,6 +551,7 @@ public class ChaosMonkey extends AbstractHBaseTool implements Stoppable {
public static class FlushTable extends Action { public static class FlushTable extends Action {
private final byte[] tableNameBytes; private final byte[] tableNameBytes;
private final long sleepTime; private final long sleepTime;
private final String tableName;
public FlushTable(String tableName) { public FlushTable(String tableName) {
this(-1, tableName); this(-1, tableName);
@ -534,12 +560,15 @@ public class ChaosMonkey extends AbstractHBaseTool implements Stoppable {
public FlushTable(int sleepTime, String tableName) { public FlushTable(int sleepTime, String tableName) {
this.tableNameBytes = Bytes.toBytes(tableName); this.tableNameBytes = Bytes.toBytes(tableName);
this.sleepTime = sleepTime; this.sleepTime = sleepTime;
this.tableName = tableName;
} }
@Override @Override
public void perform() throws Exception { public void perform() throws Exception {
HBaseTestingUtility util = context.getHaseIntegrationTestingUtility(); HBaseTestingUtility util = context.getHaseIntegrationTestingUtility();
HBaseAdmin admin = util.getHBaseAdmin(); HBaseAdmin admin = util.getHBaseAdmin();
LOG.info("Performing action: Flush table " + tableName);
admin.flush(tableNameBytes); admin.flush(tableNameBytes);
if (sleepTime > 0) { if (sleepTime > 0) {
Thread.sleep(sleepTime); Thread.sleep(sleepTime);
@ -550,6 +579,7 @@ public class ChaosMonkey extends AbstractHBaseTool implements Stoppable {
public static class FlushRandomRegionOfTable extends Action { public static class FlushRandomRegionOfTable extends Action {
private final byte[] tableNameBytes; private final byte[] tableNameBytes;
private final long sleepTime; private final long sleepTime;
private final String tableName;
public FlushRandomRegionOfTable(String tableName) { public FlushRandomRegionOfTable(String tableName) {
this (-1, tableName); this (-1, tableName);
@ -558,6 +588,7 @@ public class ChaosMonkey extends AbstractHBaseTool implements Stoppable {
public FlushRandomRegionOfTable(int sleepTime, String tableName) { public FlushRandomRegionOfTable(int sleepTime, String tableName) {
this.tableNameBytes = Bytes.toBytes(tableName); this.tableNameBytes = Bytes.toBytes(tableName);
this.sleepTime = sleepTime; this.sleepTime = sleepTime;
this.tableName = tableName;
} }
@Override @Override
@ -567,6 +598,9 @@ public class ChaosMonkey extends AbstractHBaseTool implements Stoppable {
List<HRegionInfo> regions = admin.getTableRegions(tableNameBytes); List<HRegionInfo> regions = admin.getTableRegions(tableNameBytes);
HRegionInfo region = selectRandomItem( HRegionInfo region = selectRandomItem(
regions.toArray(new HRegionInfo[regions.size()])); regions.toArray(new HRegionInfo[regions.size()]));
LOG.info("Performing action: Flush random region of table "
+ tableName + ", region=" + region.getRegionNameAsString());
admin.flush(region.getRegionName()); admin.flush(region.getRegionName());
if (sleepTime > 0) { if (sleepTime > 0) {
Thread.sleep(sleepTime); Thread.sleep(sleepTime);
@ -592,6 +626,8 @@ public class ChaosMonkey extends AbstractHBaseTool implements Stoppable {
HBaseTestingUtility util = context.getHaseIntegrationTestingUtility(); HBaseTestingUtility util = context.getHaseIntegrationTestingUtility();
String snapshotName = tableName + "-it-" + System.currentTimeMillis(); String snapshotName = tableName + "-it-" + System.currentTimeMillis();
HBaseAdmin admin = util.getHBaseAdmin(); HBaseAdmin admin = util.getHBaseAdmin();
LOG.info("Performing action: Snapshot table " + tableName);
admin.snapshot(snapshotName, tableName); admin.snapshot(snapshotName, tableName);
if (sleepTime > 0) { if (sleepTime > 0) {
Thread.sleep(sleepTime); Thread.sleep(sleepTime);
@ -1039,5 +1075,4 @@ public class ChaosMonkey extends AbstractHBaseTool implements Stoppable {
int ret = ToolRunner.run(conf, monkey, args); int ret = ToolRunner.run(conf, monkey, args);
System.exit(ret); System.exit(ret);
} }
} }