View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    * <p>
10   * http://www.apache.org/licenses/LICENSE-2.0
11   * <p>
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.chaos.factories;
19  
20  import org.apache.hadoop.hbase.chaos.actions.Action;
21  import org.apache.hadoop.hbase.chaos.actions.AddColumnAction;
22  import org.apache.hadoop.hbase.chaos.actions.BatchRestartRsAction;
23  import org.apache.hadoop.hbase.chaos.actions.ChangeSplitPolicyAction;
24  import org.apache.hadoop.hbase.chaos.actions.CompactRandomRegionOfTableAction;
25  import org.apache.hadoop.hbase.chaos.actions.CompactTableAction;
26  import org.apache.hadoop.hbase.chaos.actions.DecreaseMaxHFileSizeAction;
27  import org.apache.hadoop.hbase.chaos.actions.DumpClusterStatusAction;
28  import org.apache.hadoop.hbase.chaos.actions.FlushRandomRegionOfTableAction;
29  import org.apache.hadoop.hbase.chaos.actions.FlushTableAction;
30  import org.apache.hadoop.hbase.chaos.actions.MergeRandomAdjacentRegionsOfTableAction;
31  import org.apache.hadoop.hbase.chaos.actions.MoveRandomRegionOfTableAction;
32  import org.apache.hadoop.hbase.chaos.actions.MoveRegionsOfTableAction;
33  import org.apache.hadoop.hbase.chaos.actions.RemoveColumnAction;
34  import org.apache.hadoop.hbase.chaos.actions.RestartRandomRsAction;
35  import org.apache.hadoop.hbase.chaos.actions.RestartRsHoldingMetaAction;
36  import org.apache.hadoop.hbase.chaos.actions.RollingBatchRestartRsAction;
37  import org.apache.hadoop.hbase.chaos.actions.RollingBatchSuspendResumeRsAction;
38  import org.apache.hadoop.hbase.chaos.actions.SplitAllRegionOfTableAction;
39  import org.apache.hadoop.hbase.chaos.actions.SplitRandomRegionOfTableAction;
40  import org.apache.hadoop.hbase.chaos.monkies.ChaosMonkey;
41  import org.apache.hadoop.hbase.chaos.monkies.PolicyBasedChaosMonkey;
42  import org.apache.hadoop.hbase.chaos.policies.CompositeSequentialPolicy;
43  import org.apache.hadoop.hbase.chaos.policies.DoActionsOncePolicy;
44  import org.apache.hadoop.hbase.chaos.policies.PeriodicRandomActionPolicy;
45  
46  public class StressAssignmentManagerMonkeyFactory extends MonkeyFactory {
47  
48    private long rollingBatchSuspendRSSleepTime;
49    private float rollingBatchSuspendtRSRatio;
50  
51    @Override
52    public ChaosMonkey build() {
53  
54      loadProperties();
55  
56      // Actions that could slow down region movement.
57      // These could also get regions stuck if there are issues.
58      Action[] actions1 = new Action[]{
59          new CompactTableAction(tableName, 0.5f),
60          new CompactRandomRegionOfTableAction(tableName, 0.6f),
61          new FlushTableAction(tableName),
62          new FlushRandomRegionOfTableAction(tableName)
63      };
64  
65      Action[] actions2 = new Action[]{
66          new SplitRandomRegionOfTableAction(tableName),
67          new MergeRandomAdjacentRegionsOfTableAction(tableName),
68          new AddColumnAction(tableName),
69          new RemoveColumnAction(tableName, columnFamilies),
70          new MoveRegionsOfTableAction(MonkeyConstants.DEFAULT_MOVE_REGIONS_SLEEP_TIME,
71              1600,
72              tableName),
73          new MoveRandomRegionOfTableAction(MonkeyConstants.DEFAULT_MOVE_RANDOM_REGION_SLEEP_TIME,
74              tableName),
75          new RestartRandomRsAction(MonkeyConstants.DEFAULT_RESTART_RANDOM_RS_SLEEP_TIME),
76          new BatchRestartRsAction(MonkeyConstants.DEFAULT_ROLLING_BATCH_RESTART_RS_SLEEP_TIME, 0.5f),
77          new RollingBatchRestartRsAction(MonkeyConstants.DEFAULT_BATCH_RESTART_RS_SLEEP_TIME, 1.0f),
78          new RestartRsHoldingMetaAction(MonkeyConstants.DEFAULT_RESTART_RS_HOLDING_META_SLEEP_TIME),
79          new ChangeSplitPolicyAction(tableName),
80          new SplitAllRegionOfTableAction(tableName),
81          new DecreaseMaxHFileSizeAction(MonkeyConstants.DEFAULT_DECREASE_HFILE_SIZE_SLEEP_TIME,
82              tableName),
83        new RollingBatchSuspendResumeRsAction(rollingBatchSuspendRSSleepTime,
84            rollingBatchSuspendtRSRatio)
85      };
86  
87      // Action to log more info for debugging
88      Action[] actions3 = new Action[]{
89          new DumpClusterStatusAction()
90      };
91  
92      return new PolicyBasedChaosMonkey(util,
93          new PeriodicRandomActionPolicy(90 * 1000, actions1),
94          new CompositeSequentialPolicy(
95              new DoActionsOncePolicy(90 * 1000, actions2),
96              new PeriodicRandomActionPolicy(90 * 1000, actions2)),
97          new PeriodicRandomActionPolicy(90 * 1000, actions3)
98      );
99    }
100 
101   private void loadProperties() {
102     rollingBatchSuspendRSSleepTime = Long.parseLong(this.properties.getProperty(
103         MonkeyConstants.ROLLING_BATCH_RESTART_RS_SLEEP_TIME,
104         MonkeyConstants.DEFAULT_ROLLING_BATCH_RESTART_RS_SLEEP_TIME + ""));
105     rollingBatchSuspendtRSRatio = Float.parseFloat(this.properties.getProperty(
106         MonkeyConstants.ROLLING_BATCH_RESTART_RS_RATIO,
107         MonkeyConstants.DEFAULT_ROLLING_BATCH_RESTART_RS_RATIO + ""));
108   }
109 }