001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.chaos.factories;
019
020import org.apache.hadoop.hbase.chaos.actions.Action;
021import org.apache.hadoop.hbase.chaos.actions.AddColumnAction;
022import org.apache.hadoop.hbase.chaos.actions.BatchRestartRsAction;
023import org.apache.hadoop.hbase.chaos.actions.ChangeBloomFilterAction;
024import org.apache.hadoop.hbase.chaos.actions.ChangeCompressionAction;
025import org.apache.hadoop.hbase.chaos.actions.ChangeEncodingAction;
026import org.apache.hadoop.hbase.chaos.actions.ChangeVersionsAction;
027import org.apache.hadoop.hbase.chaos.actions.CompactMobAction;
028import org.apache.hadoop.hbase.chaos.actions.CompactRandomRegionOfTableAction;
029import org.apache.hadoop.hbase.chaos.actions.CompactTableAction;
030import org.apache.hadoop.hbase.chaos.actions.DumpClusterStatusAction;
031import org.apache.hadoop.hbase.chaos.actions.FlushRandomRegionOfTableAction;
032import org.apache.hadoop.hbase.chaos.actions.FlushTableAction;
033import org.apache.hadoop.hbase.chaos.actions.MergeRandomAdjacentRegionsOfTableAction;
034import org.apache.hadoop.hbase.chaos.actions.MoveRandomRegionOfTableAction;
035import org.apache.hadoop.hbase.chaos.actions.MoveRegionsOfTableAction;
036import org.apache.hadoop.hbase.chaos.actions.RemoveColumnAction;
037import org.apache.hadoop.hbase.chaos.actions.RestartActiveMasterAction;
038import org.apache.hadoop.hbase.chaos.actions.RestartRandomRsAction;
039import org.apache.hadoop.hbase.chaos.actions.RestartRsHoldingMetaAction;
040import org.apache.hadoop.hbase.chaos.actions.RollingBatchRestartRsAction;
041import org.apache.hadoop.hbase.chaos.actions.SnapshotTableAction;
042import org.apache.hadoop.hbase.chaos.actions.SplitRandomRegionOfTableAction;
043import org.apache.hadoop.hbase.chaos.monkies.ChaosMonkey;
044import org.apache.hadoop.hbase.chaos.monkies.PolicyBasedChaosMonkey;
045import org.apache.hadoop.hbase.chaos.policies.CompositeSequentialPolicy;
046import org.apache.hadoop.hbase.chaos.policies.DoActionsOncePolicy;
047import org.apache.hadoop.hbase.chaos.policies.PeriodicRandomActionPolicy;
048
049/**
050 * This is a copy of SlowDeterministicMonkeyFactory that also does mob compactions.
051 */
052public class MobSlowDeterministicMonkeyFactory extends MonkeyFactory {
053
054  @Override
055  public ChaosMonkey build() {
056    loadProperties();
057    // Actions such as compact/flush a table/region,
058    // move one region around. They are not so destructive,
059    // can be executed more frequently.
060    Action[] actions1 = new Action[] { new CompactMobAction(tableName, compactTableRatio),
061      new CompactTableAction(tableName, compactTableRatio),
062      new CompactRandomRegionOfTableAction(tableName, compactRandomRegionRatio),
063      new FlushTableAction(tableName), new FlushRandomRegionOfTableAction(tableName),
064      new MoveRandomRegionOfTableAction(tableName) };
065
066    // Actions such as split/merge/snapshot.
067    // They should not cause data loss, or unreliability
068    // such as region stuck in transition.
069    Action[] actions2 = new Action[] { new SplitRandomRegionOfTableAction(tableName),
070      new MergeRandomAdjacentRegionsOfTableAction(tableName),
071      new SnapshotTableAction(tableName, snapshotTableTtl), new AddColumnAction(tableName),
072      new RemoveColumnAction(tableName, columnFamilies), new ChangeEncodingAction(tableName),
073      new ChangeCompressionAction(tableName), new ChangeBloomFilterAction(tableName),
074      new ChangeVersionsAction(tableName) };
075
076    // Destructive actions to mess things around.
077    Action[] actions3 = new Action[] {
078      new MoveRegionsOfTableAction(moveRegionsSleepTime, moveRegionsMaxTime, tableName),
079      new MoveRandomRegionOfTableAction(moveRandomRegionSleepTime, tableName),
080      new RestartRandomRsAction(restartRandomRSSleepTime),
081      new BatchRestartRsAction(batchRestartRSSleepTime, batchRestartRSRatio),
082      new RestartActiveMasterAction(restartActiveMasterSleepTime),
083      new RollingBatchRestartRsAction(rollingBatchRestartRSSleepTime, rollingBatchRestartRSRatio),
084      new RestartRsHoldingMetaAction(restartRsHoldingMetaSleepTime) };
085
086    // Action to log more info for debugging
087    Action[] actions4 = new Action[] { new DumpClusterStatusAction() };
088
089    return new PolicyBasedChaosMonkey(properties, util,
090      new PeriodicRandomActionPolicy(action1Period, actions1),
091      new PeriodicRandomActionPolicy(action2Period, actions2),
092      new CompositeSequentialPolicy(new DoActionsOncePolicy(action3Period, actions3),
093        new PeriodicRandomActionPolicy(action3Period, actions3)),
094      new PeriodicRandomActionPolicy(action4Period, actions4));
095  }
096}