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