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.*;
22  import org.apache.hadoop.hbase.chaos.monkies.ChaosMonkey;
23  import org.apache.hadoop.hbase.chaos.monkies.PolicyBasedChaosMonkey;
24  import org.apache.hadoop.hbase.chaos.policies.CompositeSequentialPolicy;
25  import org.apache.hadoop.hbase.chaos.policies.DoActionsOncePolicy;
26  import org.apache.hadoop.hbase.chaos.policies.PeriodicRandomActionPolicy;
27  
28  public class SlowDeterministicMonkeyFactory extends MonkeyFactory {
29  
30    private long action1Period;
31    private long action2Period;
32    private long action3Period;
33    private long action4Period;
34    private long moveRegionsMaxTime;
35    private long moveRegionsSleepTime;
36    private long moveRandomRegionSleepTime;
37    private long restartRandomRSSleepTime;
38    private long batchRestartRSSleepTime;
39    private float batchRestartRSRatio;
40    private long restartActiveMasterSleepTime;
41    private long rollingBatchRestartRSSleepTime;
42    private float rollingBatchRestartRSRatio;
43    private long restartRsHoldingMetaSleepTime;
44    private float compactTableRatio;
45    private float compactRandomRegionRatio;
46    private long decreaseHFileSizeSleepTime;
47  
48    @Override
49    public ChaosMonkey build() {
50  
51      loadProperties();
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, compactTableRatio),
57          new CompactRandomRegionOfTableAction(tableName, compactRandomRegionRatio),
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 ChangeBloomFilterAction(tableName),
75          new ChangeVersionsAction(tableName),
76          new ChangeSplitPolicyAction(tableName),
77      };
78  
79      // Destructive actions to mess things around.
80      Action[] actions3 = new Action[] {
81          new MoveRegionsOfTableAction(moveRegionsSleepTime, moveRegionsMaxTime,
82              tableName),
83          new MoveRandomRegionOfTableAction(moveRandomRegionSleepTime, tableName),
84          new RestartRandomRsAction(restartRandomRSSleepTime),
85          new BatchRestartRsAction(batchRestartRSSleepTime, batchRestartRSRatio),
86          new RestartActiveMasterAction(restartActiveMasterSleepTime),
87          new RollingBatchRestartRsAction(rollingBatchRestartRSSleepTime,
88              rollingBatchRestartRSRatio),
89          new RestartRsHoldingMetaAction(restartRsHoldingMetaSleepTime),
90          new DecreaseMaxHFileSizeAction(decreaseHFileSizeSleepTime, tableName),
91          new SplitAllRegionOfTableAction(tableName),
92      };
93  
94      // Action to log more info for debugging
95      Action[] actions4 = new Action[] {
96          new DumpClusterStatusAction()
97      };
98  
99      return new PolicyBasedChaosMonkey(util,
100         new PeriodicRandomActionPolicy(action1Period, actions1),
101         new PeriodicRandomActionPolicy(action2Period, actions2),
102         new CompositeSequentialPolicy(
103             new DoActionsOncePolicy(action3Period, actions3),
104             new PeriodicRandomActionPolicy(action3Period, actions3)),
105         new PeriodicRandomActionPolicy(action4Period, actions4));
106   }
107 
108   private void loadProperties() {
109 
110       action1Period = Long.parseLong(this.properties.getProperty(
111         MonkeyConstants.PERIODIC_ACTION1_PERIOD,
112         MonkeyConstants.DEFAULT_PERIODIC_ACTION1_PERIOD + ""));
113       action2Period = Long.parseLong(this.properties.getProperty(
114         MonkeyConstants.PERIODIC_ACTION2_PERIOD,
115         MonkeyConstants.DEFAULT_PERIODIC_ACTION2_PERIOD + ""));
116       action3Period = Long.parseLong(this.properties.getProperty(
117         MonkeyConstants.COMPOSITE_ACTION3_PERIOD,
118         MonkeyConstants.DEFAULT_COMPOSITE_ACTION3_PERIOD + ""));
119       action4Period = Long.parseLong(this.properties.getProperty(
120         MonkeyConstants.PERIODIC_ACTION4_PERIOD,
121         MonkeyConstants.DEFAULT_PERIODIC_ACTION4_PERIOD + ""));
122       moveRegionsMaxTime = Long.parseLong(this.properties.getProperty(
123         MonkeyConstants.MOVE_REGIONS_MAX_TIME,
124         MonkeyConstants.DEFAULT_MOVE_REGIONS_MAX_TIME + ""));
125       moveRegionsSleepTime = Long.parseLong(this.properties.getProperty(
126         MonkeyConstants.MOVE_REGIONS_SLEEP_TIME,
127         MonkeyConstants.DEFAULT_MOVE_REGIONS_SLEEP_TIME + ""));
128       moveRandomRegionSleepTime = Long.parseLong(this.properties.getProperty(
129         MonkeyConstants.MOVE_RANDOM_REGION_SLEEP_TIME,
130         MonkeyConstants.DEFAULT_MOVE_RANDOM_REGION_SLEEP_TIME + ""));
131       restartRandomRSSleepTime = Long.parseLong(this.properties.getProperty(
132         MonkeyConstants.RESTART_RANDOM_RS_SLEEP_TIME,
133         MonkeyConstants.DEFAULT_RESTART_RANDOM_RS_SLEEP_TIME + ""));
134       batchRestartRSSleepTime = Long.parseLong(this.properties.getProperty(
135         MonkeyConstants.BATCH_RESTART_RS_SLEEP_TIME,
136         MonkeyConstants.DEFAULT_BATCH_RESTART_RS_SLEEP_TIME + ""));
137       batchRestartRSRatio = Float.parseFloat(this.properties.getProperty(
138         MonkeyConstants.BATCH_RESTART_RS_RATIO,
139         MonkeyConstants.DEFAULT_BATCH_RESTART_RS_RATIO + ""));
140       restartActiveMasterSleepTime = Long.parseLong(this.properties.getProperty(
141         MonkeyConstants.RESTART_ACTIVE_MASTER_SLEEP_TIME,
142         MonkeyConstants.DEFAULT_RESTART_ACTIVE_MASTER_SLEEP_TIME + ""));
143       rollingBatchRestartRSSleepTime = Long.parseLong(this.properties.getProperty(
144         MonkeyConstants.ROLLING_BATCH_RESTART_RS_SLEEP_TIME,
145         MonkeyConstants.DEFAULT_ROLLING_BATCH_RESTART_RS_SLEEP_TIME + ""));
146       rollingBatchRestartRSRatio = Float.parseFloat(this.properties.getProperty(
147         MonkeyConstants.ROLLING_BATCH_RESTART_RS_RATIO,
148         MonkeyConstants.DEFAULT_ROLLING_BATCH_RESTART_RS_RATIO + ""));
149       restartRsHoldingMetaSleepTime = Long.parseLong(this.properties.getProperty(
150         MonkeyConstants.RESTART_RS_HOLDING_META_SLEEP_TIME,
151         MonkeyConstants.DEFAULT_RESTART_RS_HOLDING_META_SLEEP_TIME + ""));
152       compactTableRatio = Float.parseFloat(this.properties.getProperty(
153         MonkeyConstants.COMPACT_TABLE_ACTION_RATIO,
154         MonkeyConstants.DEFAULT_COMPACT_TABLE_ACTION_RATIO + ""));
155       compactRandomRegionRatio = Float.parseFloat(this.properties.getProperty(
156         MonkeyConstants.COMPACT_RANDOM_REGION_RATIO,
157         MonkeyConstants.DEFAULT_COMPACT_RANDOM_REGION_RATIO + ""));
158     decreaseHFileSizeSleepTime = Long.parseLong(this.properties.getProperty(
159         MonkeyConstants.DECREASE_HFILE_SIZE_SLEEP_TIME,
160         MonkeyConstants.DEFAULT_DECREASE_HFILE_SIZE_SLEEP_TIME + ""));
161   }
162 }