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    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
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  
19  package org.apache.hadoop.hbase.chaos.factories;
20  
21  import org.apache.hadoop.hbase.chaos.actions.Action;
22  import org.apache.hadoop.hbase.chaos.actions.AddColumnAction;
23  import org.apache.hadoop.hbase.chaos.actions.BatchRestartRsAction;
24  import org.apache.hadoop.hbase.chaos.actions.ChangeCompressionAction;
25  import org.apache.hadoop.hbase.chaos.actions.ChangeEncodingAction;
26  import org.apache.hadoop.hbase.chaos.actions.ChangeVersionsAction;
27  import org.apache.hadoop.hbase.chaos.actions.CompactRandomRegionOfTableAction;
28  import org.apache.hadoop.hbase.chaos.actions.CompactTableAction;
29  import org.apache.hadoop.hbase.chaos.actions.DumpClusterStatusAction;
30  import org.apache.hadoop.hbase.chaos.actions.FlushRandomRegionOfTableAction;
31  import org.apache.hadoop.hbase.chaos.actions.FlushTableAction;
32  import org.apache.hadoop.hbase.chaos.actions.MergeRandomAdjacentRegionsOfTableAction;
33  import org.apache.hadoop.hbase.chaos.actions.MoveRandomRegionOfTableAction;
34  import org.apache.hadoop.hbase.chaos.actions.MoveRegionsOfTableAction;
35  import org.apache.hadoop.hbase.chaos.actions.RemoveColumnAction;
36  import org.apache.hadoop.hbase.chaos.actions.RestartActiveMasterAction;
37  import org.apache.hadoop.hbase.chaos.actions.RestartRandomRsAction;
38  import org.apache.hadoop.hbase.chaos.actions.RestartRsHoldingMetaAction;
39  import org.apache.hadoop.hbase.chaos.actions.RollingBatchRestartRsAction;
40  import org.apache.hadoop.hbase.chaos.actions.SnapshotTableAction;
41  import org.apache.hadoop.hbase.chaos.actions.SplitRandomRegionOfTableAction;
42  import org.apache.hadoop.hbase.chaos.monkies.ChaosMonkey;
43  import org.apache.hadoop.hbase.chaos.monkies.PolicyBasedChaosMonkey;
44  import org.apache.hadoop.hbase.chaos.policies.CompositeSequentialPolicy;
45  import org.apache.hadoop.hbase.chaos.policies.DoActionsOncePolicy;
46  import org.apache.hadoop.hbase.chaos.policies.PeriodicRandomActionPolicy;
47  
48  public class SlowDeterministicMonkeyFactory extends MonkeyFactory {
49    @Override
50    public ChaosMonkey build() {
51  
52      // Actions such as compact/flush a table/region,
53      // move one region around. They are not so destructive,
54      // can be executed more frequently.
55      Action[] actions1 = new Action[] {
56          new CompactTableAction(tableName, 0.5f),
57          new CompactRandomRegionOfTableAction(tableName, 0.6f),
58          new FlushTableAction(tableName),
59          new FlushRandomRegionOfTableAction(tableName),
60          new MoveRandomRegionOfTableAction(tableName)
61      };
62  
63      // Actions such as split/merge/snapshot.
64      // They should not cause data loss, or unreliability
65      // such as region stuck in transition.
66      Action[] actions2 = new Action[] {
67          new SplitRandomRegionOfTableAction(tableName),
68          new MergeRandomAdjacentRegionsOfTableAction(tableName),
69          new SnapshotTableAction(tableName),
70          new AddColumnAction(tableName),
71          new RemoveColumnAction(tableName, columnFamilies),
72          new ChangeEncodingAction(tableName),
73          new ChangeCompressionAction(tableName),
74          new ChangeVersionsAction(tableName)
75      };
76  
77      // Destructive actions to mess things around.
78      Action[] actions3 = new Action[] {
79          new MoveRegionsOfTableAction(800, tableName),
80          new MoveRandomRegionOfTableAction(800, tableName),
81          new RestartRandomRsAction(60000),
82          new BatchRestartRsAction(5000, 0.5f),
83          new RestartActiveMasterAction(5000),
84          new RollingBatchRestartRsAction(5000, 1.0f),
85          new RestartRsHoldingMetaAction(35000)
86      };
87  
88      // Action to log more info for debugging
89      Action[] actions4 = new Action[] {
90          new DumpClusterStatusAction()
91      };
92  
93      return new PolicyBasedChaosMonkey(util,
94          new PeriodicRandomActionPolicy(60 * 1000, actions1),
95          new PeriodicRandomActionPolicy(90 * 1000, actions2),
96          new CompositeSequentialPolicy(
97              new DoActionsOncePolicy(150 * 1000, actions3),
98              new PeriodicRandomActionPolicy(150 * 1000, actions3)),
99          new PeriodicRandomActionPolicy(90 * 1000, actions4));
100   }
101 }