diff --git a/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/SnapshotTableAction.java b/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/SnapshotTableAction.java index 89f2413f2318..378a237af0f8 100644 --- a/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/SnapshotTableAction.java +++ b/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/SnapshotTableAction.java @@ -17,13 +17,19 @@ */ 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. */ @@ -31,14 +37,20 @@ 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 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 @@ -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); } diff --git a/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/MobNoKillMonkeyFactory.java b/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/MobNoKillMonkeyFactory.java index 846c9cf01e04..b08e94b7b8c0 100644 --- a/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/MobNoKillMonkeyFactory.java +++ b/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/MobNoKillMonkeyFactory.java @@ -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) }; diff --git a/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/MobSlowDeterministicMonkeyFactory.java b/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/MobSlowDeterministicMonkeyFactory.java index a68a8fc2f14c..ef8c307fad8f 100644 --- a/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/MobSlowDeterministicMonkeyFactory.java +++ b/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/MobSlowDeterministicMonkeyFactory.java @@ -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() { @@ -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[] { @@ -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 + "")); } } diff --git a/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/MonkeyConstants.java b/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/MonkeyConstants.java index 0263a568d965..3fda08447290 100644 --- a/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/MonkeyConstants.java +++ b/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/MonkeyConstants.java @@ -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 MONKEY_CONFIGURATION_KEY_PREFIXES = new HashSet<>( - Arrays.asList("sdm.", "move.", "restart.", "batch.", "rolling.", "compact.", "unbalance.", - "decrease.", "decrease.", "graceful.", "cpu.", "network.", "fill.", "data.", "skip")); + Set 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; @@ -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; } diff --git a/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/NoKillMonkeyFactory.java b/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/NoKillMonkeyFactory.java index 1bc166e9e170..a9529e40b970 100644 --- a/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/NoKillMonkeyFactory.java +++ b/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/NoKillMonkeyFactory.java @@ -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) }; diff --git a/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/SlowDeterministicMonkeyFactory.java b/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/SlowDeterministicMonkeyFactory.java index 876402111a7d..565577683435 100644 --- a/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/SlowDeterministicMonkeyFactory.java +++ b/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/SlowDeterministicMonkeyFactory.java @@ -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), @@ -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() { @@ -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 + "")); } }