Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,40 @@
*/
package org.apache.hadoop.hbase.chaos.actions;

import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;
import org.apache.hadoop.hbase.HBaseTestingUtil;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.SnapshotType;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableMap;

/**
* Action that tries to take a snapshot of a table.
*/
public class SnapshotTableAction extends Action {
private static final Logger LOG = LoggerFactory.getLogger(SnapshotTableAction.class);
private final TableName tableName;
private final long sleepTime;
private final Map<String, Object> snapshotProps;

public SnapshotTableAction(TableName tableName) {
this(-1, tableName);
public SnapshotTableAction(TableName tableName, long ttl) {
this(-1, tableName, ttl);
}

public SnapshotTableAction(int sleepTime, TableName tableName) {
public SnapshotTableAction(int sleepTime, TableName tableName, long ttl) {
this.tableName = tableName;
this.sleepTime = sleepTime;
if (ttl > 0) {
snapshotProps = ImmutableMap.of("TTL", ttl);
} else {
snapshotProps = Collections.emptyMap();
}
}

@Override
Expand All @@ -58,7 +70,9 @@ public void perform() throws Exception {
}

getLogger().info("Performing action: Snapshot table {}", tableName);
admin.snapshot(snapshotName, tableName);
SnapshotType type =
ThreadLocalRandom.current().nextBoolean() ? SnapshotType.FLUSH : SnapshotType.SKIPFLUSH;
admin.snapshot(snapshotName, tableName, type, snapshotProps);
if (sleepTime > 0) {
Thread.sleep(sleepTime);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public ChaosMonkey build() {
new MoveRandomRegionOfTableAction(tableName) };

Action[] actions2 = new Action[] { new SplitRandomRegionOfTableAction(tableName),
new MergeRandomAdjacentRegionsOfTableAction(tableName), new SnapshotTableAction(tableName),
new MergeRandomAdjacentRegionsOfTableAction(tableName),
new SnapshotTableAction(tableName, MonkeyConstants.DEFAULT_SNAPSHOT_TABLE_TTL),
new AddColumnAction(tableName), new RemoveColumnAction(tableName, columnFamilies),
new ChangeEncodingAction(tableName), new ChangeCompressionAction(tableName),
new ChangeBloomFilterAction(tableName), new ChangeVersionsAction(tableName) };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class MobSlowDeterministicMonkeyFactory extends MonkeyFactory {
private long restartRsHoldingMetaSleepTime;
private float compactTableRatio;
private float compactRandomRegionRatio;
private long snapshotTableTtl;

@Override
public ChaosMonkey build() {
Expand All @@ -85,10 +86,11 @@ public ChaosMonkey build() {
// They should not cause data loss, or unreliability
// such as region stuck in transition.
Action[] actions2 = new Action[] { new SplitRandomRegionOfTableAction(tableName),
new MergeRandomAdjacentRegionsOfTableAction(tableName), new SnapshotTableAction(tableName),
new AddColumnAction(tableName), new RemoveColumnAction(tableName, columnFamilies),
new ChangeEncodingAction(tableName), new ChangeCompressionAction(tableName),
new ChangeBloomFilterAction(tableName), new ChangeVersionsAction(tableName) };
new MergeRandomAdjacentRegionsOfTableAction(tableName),
new SnapshotTableAction(tableName, snapshotTableTtl), new AddColumnAction(tableName),
new RemoveColumnAction(tableName, columnFamilies), new ChangeEncodingAction(tableName),
new ChangeCompressionAction(tableName), new ChangeBloomFilterAction(tableName),
new ChangeVersionsAction(tableName) };

// Destructive actions to mess things around.
Action[] actions3 = new Action[] {
Expand Down Expand Up @@ -158,5 +160,8 @@ private void loadProperties() {
compactRandomRegionRatio =
Float.parseFloat(this.properties.getProperty(MonkeyConstants.COMPACT_RANDOM_REGION_RATIO,
MonkeyConstants.DEFAULT_COMPACT_RANDOM_REGION_RATIO + ""));
snapshotTableTtl =
Long.parseLong(this.properties.getProperty(MonkeyConstants.SNAPSHOT_TABLE_TTL,
MonkeyConstants.DEFAULT_SNAPSHOT_TABLE_TTL + ""));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,14 @@ public interface MonkeyConstants {
String FILL_DISK_FILE_SIZE = "fill.disk.file.size";
String FILL_DISK_ISSUE_DURATION = "fill.disk.issue.duration";
String DATA_ISSUE_CHANCE = "data.issue.chance";
String SNAPSHOT_TABLE_TTL = "snapshot.table.ttl";

/**
* A Set of prefixes which encompasses all of the configuration properties for the ChaosMonky.
*/
Set<String> MONKEY_CONFIGURATION_KEY_PREFIXES = new HashSet<>(
Arrays.asList("sdm.", "move.", "restart.", "batch.", "rolling.", "compact.", "unbalance.",
"decrease.", "decrease.", "graceful.", "cpu.", "network.", "fill.", "data.", "skip"));
Set<String> MONKEY_CONFIGURATION_KEY_PREFIXES = new HashSet<>(Arrays.asList("sdm.", "move.",
"restart.", "batch.", "rolling.", "compact.", "unbalance.", "decrease.", "decrease.",
"graceful.", "cpu.", "network.", "fill.", "data.", "snapshot.", "skip"));

long DEFAULT_PERIODIC_ACTION1_PERIOD = 60 * 1000;
long DEFAULT_PERIODIC_ACTION2_PERIOD = 90 * 1000;
Expand Down Expand Up @@ -121,4 +122,5 @@ public interface MonkeyConstants {
long DEFAULT_FILL_DISK_FILE_SIZE = 0;
long DEFAULT_FILL_DISK_ISSUE_DURATION = 5 * 60 * 1000;
float DEFAULT_DATA_ISSUE_CHANCE = 0.01f;
long DEFAULT_SNAPSHOT_TABLE_TTL = -1L;
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public ChaosMonkey build() {
new MoveRandomRegionOfTableAction(tableName) };

Action[] actions2 = new Action[] { new SplitRandomRegionOfTableAction(tableName),
new MergeRandomAdjacentRegionsOfTableAction(tableName), new SnapshotTableAction(tableName),
new MergeRandomAdjacentRegionsOfTableAction(tableName),
new SnapshotTableAction(tableName, MonkeyConstants.DEFAULT_SNAPSHOT_TABLE_TTL),
new AddColumnAction(tableName), new RemoveColumnAction(tableName, columnFamilies),
new ChangeEncodingAction(tableName), new ChangeCompressionAction(tableName),
new ChangeBloomFilterAction(tableName), new ChangeVersionsAction(tableName) };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public class SlowDeterministicMonkeyFactory extends MonkeyFactory {
private long gracefulRollingRestartTSSLeepTime;
private long rollingBatchSuspendRSSleepTime;
private float rollingBatchSuspendtRSRatio;
private long snapshotTableTtl;

protected Action[] getLightWeightedActions() {
return new Action[] { new CompactTableAction(tableName, compactTableRatio),
Expand All @@ -81,11 +82,11 @@ protected Action[] getLightWeightedActions() {

protected Action[] getMidWeightedActions() {
return new Action[] { new SplitRandomRegionOfTableAction(tableName),
new MergeRandomAdjacentRegionsOfTableAction(tableName), new SnapshotTableAction(tableName),
new AddColumnAction(tableName), new RemoveColumnAction(tableName, columnFamilies),
new ChangeEncodingAction(tableName), new ChangeCompressionAction(tableName),
new ChangeBloomFilterAction(tableName), new ChangeVersionsAction(tableName),
new ChangeSplitPolicyAction(tableName), };
new MergeRandomAdjacentRegionsOfTableAction(tableName),
new SnapshotTableAction(tableName, snapshotTableTtl), new AddColumnAction(tableName),
new RemoveColumnAction(tableName, columnFamilies), new ChangeEncodingAction(tableName),
new ChangeCompressionAction(tableName), new ChangeBloomFilterAction(tableName),
new ChangeVersionsAction(tableName), new ChangeSplitPolicyAction(tableName), };
}

protected Action[] getHeavyWeightedActions() {
Expand Down Expand Up @@ -193,5 +194,8 @@ private void loadProperties() {
rollingBatchSuspendtRSRatio =
Float.parseFloat(this.properties.getProperty(MonkeyConstants.ROLLING_BATCH_SUSPEND_RS_RATIO,
MonkeyConstants.DEFAULT_ROLLING_BATCH_SUSPEND_RS_RATIO + ""));
snapshotTableTtl =
Long.parseLong(this.properties.getProperty(MonkeyConstants.SNAPSHOT_TABLE_TTL,
MonkeyConstants.DEFAULT_SNAPSHOT_TABLE_TTL + ""));
}
}