001/** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019package org.apache.hadoop.hbase.chaos.factories; 020 021import org.apache.hadoop.hbase.chaos.actions.*; 022import org.apache.hadoop.hbase.chaos.monkies.ChaosMonkey; 023import org.apache.hadoop.hbase.chaos.monkies.PolicyBasedChaosMonkey; 024import org.apache.hadoop.hbase.chaos.policies.CompositeSequentialPolicy; 025import org.apache.hadoop.hbase.chaos.policies.DoActionsOncePolicy; 026import org.apache.hadoop.hbase.chaos.policies.PeriodicRandomActionPolicy; 027 028/** 029 * This is a copy of SlowDeterministicMonkeyFactory that also does mob compactions. 030 */ 031public class MobSlowDeterministicMonkeyFactory extends MonkeyFactory { 032 033 private long action1Period; 034 private long action2Period; 035 private long action3Period; 036 private long action4Period; 037 private long moveRegionsMaxTime; 038 private long moveRegionsSleepTime; 039 private long moveRandomRegionSleepTime; 040 private long restartRandomRSSleepTime; 041 private long batchRestartRSSleepTime; 042 private float batchRestartRSRatio; 043 private long restartActiveMasterSleepTime; 044 private long rollingBatchRestartRSSleepTime; 045 private float rollingBatchRestartRSRatio; 046 private long restartRsHoldingMetaSleepTime; 047 private float compactTableRatio; 048 private float compactRandomRegionRatio; 049 050 @Override 051 public ChaosMonkey build() { 052 053 loadProperties(); 054 // Actions such as compact/flush a table/region, 055 // move one region around. They are not so destructive, 056 // can be executed more frequently. 057 Action[] actions1 = new Action[] { 058 new CompactMobAction(tableName, compactTableRatio), 059 new CompactTableAction(tableName, compactTableRatio), 060 new CompactRandomRegionOfTableAction(tableName, compactRandomRegionRatio), 061 new FlushTableAction(tableName), 062 new FlushRandomRegionOfTableAction(tableName), 063 new MoveRandomRegionOfTableAction(tableName) 064 }; 065 066 // Actions such as split/merge/snapshot. 067 // They should not cause data loss, or unreliability 068 // such as region stuck in transition. 069 Action[] actions2 = new Action[] { 070 new SplitRandomRegionOfTableAction(tableName), 071 new MergeRandomAdjacentRegionsOfTableAction(tableName), 072 new SnapshotTableAction(tableName), 073 new AddColumnAction(tableName), 074 new RemoveColumnAction(tableName, columnFamilies), 075 new ChangeEncodingAction(tableName), 076 new ChangeCompressionAction(tableName), 077 new ChangeBloomFilterAction(tableName), 078 new ChangeVersionsAction(tableName) 079 }; 080 081 // Destructive actions to mess things around. 082 Action[] actions3 = new Action[] { 083 new MoveRegionsOfTableAction(moveRegionsSleepTime, moveRegionsMaxTime, 084 tableName), 085 new MoveRandomRegionOfTableAction(moveRandomRegionSleepTime, tableName), 086 new RestartRandomRsAction(restartRandomRSSleepTime), 087 new BatchRestartRsAction(batchRestartRSSleepTime, batchRestartRSRatio), 088 new RestartActiveMasterAction(restartActiveMasterSleepTime), 089 new RollingBatchRestartRsAction(rollingBatchRestartRSSleepTime, 090 rollingBatchRestartRSRatio), 091 new RestartRsHoldingMetaAction(restartRsHoldingMetaSleepTime) 092 }; 093 094 // Action to log more info for debugging 095 Action[] actions4 = new Action[] { 096 new DumpClusterStatusAction() 097 }; 098 099 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}