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  /**
29   * This is a copy of SlowDeterministicMonkeyFactory that also does mob compactions.
30   */
31  public class MobSlowDeterministicMonkeyFactory extends MonkeyFactory {
32  
33    private long action1Period;
34    private long action2Period;
35    private long action3Period;
36    private long action4Period;
37    private long moveRegionsMaxTime;
38    private long moveRegionsSleepTime;
39    private long moveRandomRegionSleepTime;
40    private long restartRandomRSSleepTime;
41    private long batchRestartRSSleepTime;
42    private float batchRestartRSRatio;
43    private long restartActiveMasterSleepTime;
44    private long rollingBatchRestartRSSleepTime;
45    private float rollingBatchRestartRSRatio;
46    private long restartRsHoldingMetaSleepTime;
47    private float compactTableRatio;
48    private float compactRandomRegionRatio;
49  
50    @Override
51    public ChaosMonkey build() {
52  
53      loadProperties();
54      // Actions such as compact/flush a table/region,
55      // move one region around. They are not so destructive,
56      // can be executed more frequently.
57      Action[] actions1 = new Action[] {
58              new CompactMobAction(tableName, compactTableRatio),
59              new CompactTableAction(tableName, compactTableRatio),
60              new CompactRandomRegionOfTableAction(tableName, compactRandomRegionRatio),
61              new FlushTableAction(tableName),
62              new FlushRandomRegionOfTableAction(tableName),
63              new MoveRandomRegionOfTableAction(tableName)
64      };
65  
66      // Actions such as split/merge/snapshot.
67      // They should not cause data loss, or unreliability
68      // such as region stuck in transition.
69      Action[] actions2 = new Action[] {
70              new SplitRandomRegionOfTableAction(tableName),
71              new MergeRandomAdjacentRegionsOfTableAction(tableName),
72              new SnapshotTableAction(tableName),
73              new AddColumnAction(tableName),
74              new RemoveColumnAction(tableName, columnFamilies),
75              new ChangeEncodingAction(tableName),
76              new ChangeCompressionAction(tableName),
77              new ChangeBloomFilterAction(tableName),
78              new ChangeVersionsAction(tableName)
79      };
80  
81      // Destructive actions to mess things around.
82      Action[] actions3 = new Action[] {
83              new MoveRegionsOfTableAction(moveRegionsSleepTime, moveRegionsMaxTime,
84                      tableName),
85              new MoveRandomRegionOfTableAction(moveRandomRegionSleepTime, tableName),
86              new RestartRandomRsAction(restartRandomRSSleepTime),
87              new BatchRestartRsAction(batchRestartRSSleepTime, batchRestartRSRatio),
88              new RestartActiveMasterAction(restartActiveMasterSleepTime),
89              new RollingBatchRestartRsAction(rollingBatchRestartRSSleepTime,
90                      rollingBatchRestartRSRatio),
91              new RestartRsHoldingMetaAction(restartRsHoldingMetaSleepTime)
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     restartActiveMasterSleepTime = Long.parseLong(this.properties.getProperty(
138             MonkeyConstants.RESTART_ACTIVE_MASTER_SLEEP_TIME,
139             MonkeyConstants.DEFAULT_RESTART_ACTIVE_MASTER_SLEEP_TIME + ""));
140     rollingBatchRestartRSSleepTime = Long.parseLong(this.properties.getProperty(
141             MonkeyConstants.ROLLING_BATCH_RESTART_RS_SLEEP_TIME,
142             MonkeyConstants.DEFAULT_ROLLING_BATCH_RESTART_RS_SLEEP_TIME + ""));
143     rollingBatchRestartRSRatio = Float.parseFloat(this.properties.getProperty(
144             MonkeyConstants.ROLLING_BATCH_RESTART_RS_RATIO,
145             MonkeyConstants.DEFAULT_ROLLING_BATCH_RESTART_RS_RATIO + ""));
146     restartRsHoldingMetaSleepTime = Long.parseLong(this.properties.getProperty(
147             MonkeyConstants.RESTART_RS_HOLDING_META_SLEEP_TIME,
148             MonkeyConstants.DEFAULT_RESTART_RS_HOLDING_META_SLEEP_TIME + ""));
149     compactTableRatio = Float.parseFloat(this.properties.getProperty(
150             MonkeyConstants.COMPACT_TABLE_ACTION_RATIO,
151             MonkeyConstants.DEFAULT_COMPACT_TABLE_ACTION_RATIO + ""));
152     compactRandomRegionRatio = Float.parseFloat(this.properties.getProperty(
153             MonkeyConstants.COMPACT_RANDOM_REGION_RATIO,
154             MonkeyConstants.DEFAULT_COMPACT_RANDOM_REGION_RATIO + ""));
155   }
156 }