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.Action; 022import org.apache.hadoop.hbase.chaos.actions.AddColumnAction; 023import org.apache.hadoop.hbase.chaos.actions.BatchRestartRsAction; 024import org.apache.hadoop.hbase.chaos.actions.ChangeBloomFilterAction; 025import org.apache.hadoop.hbase.chaos.actions.ChangeCompressionAction; 026import org.apache.hadoop.hbase.chaos.actions.ChangeEncodingAction; 027import org.apache.hadoop.hbase.chaos.actions.ChangeSplitPolicyAction; 028import org.apache.hadoop.hbase.chaos.actions.ChangeVersionsAction; 029import org.apache.hadoop.hbase.chaos.actions.CompactRandomRegionOfTableAction; 030import org.apache.hadoop.hbase.chaos.actions.CompactTableAction; 031import org.apache.hadoop.hbase.chaos.actions.DecreaseMaxHFileSizeAction; 032import org.apache.hadoop.hbase.chaos.actions.DumpClusterStatusAction; 033import org.apache.hadoop.hbase.chaos.actions.FlushRandomRegionOfTableAction; 034import org.apache.hadoop.hbase.chaos.actions.FlushTableAction; 035import org.apache.hadoop.hbase.chaos.actions.MergeRandomAdjacentRegionsOfTableAction; 036import org.apache.hadoop.hbase.chaos.actions.MoveRandomRegionOfTableAction; 037import org.apache.hadoop.hbase.chaos.actions.MoveRegionsOfTableAction; 038import org.apache.hadoop.hbase.chaos.actions.RemoveColumnAction; 039import org.apache.hadoop.hbase.chaos.actions.RestartActiveMasterAction; 040import org.apache.hadoop.hbase.chaos.actions.RestartRandomRsAction; 041import org.apache.hadoop.hbase.chaos.actions.RestartRsHoldingMetaAction; 042import org.apache.hadoop.hbase.chaos.actions.RollingBatchRestartRsAction; 043import org.apache.hadoop.hbase.chaos.actions.SnapshotTableAction; 044import org.apache.hadoop.hbase.chaos.actions.SplitAllRegionOfTableAction; 045import org.apache.hadoop.hbase.chaos.actions.SplitRandomRegionOfTableAction; 046import org.apache.hadoop.hbase.chaos.monkies.ChaosMonkey; 047import org.apache.hadoop.hbase.chaos.monkies.PolicyBasedChaosMonkey; 048import org.apache.hadoop.hbase.chaos.policies.CompositeSequentialPolicy; 049import org.apache.hadoop.hbase.chaos.policies.DoActionsOncePolicy; 050import org.apache.hadoop.hbase.chaos.policies.PeriodicRandomActionPolicy; 051 052public class SlowDeterministicMonkeyFactory extends MonkeyFactory { 053 054 private long action1Period; 055 private long action2Period; 056 private long action3Period; 057 private long action4Period; 058 private long moveRegionsMaxTime; 059 private long moveRegionsSleepTime; 060 private long moveRandomRegionSleepTime; 061 private long restartRandomRSSleepTime; 062 private long batchRestartRSSleepTime; 063 private float batchRestartRSRatio; 064 private long restartActiveMasterSleepTime; 065 private long rollingBatchRestartRSSleepTime; 066 private float rollingBatchRestartRSRatio; 067 private long restartRsHoldingMetaSleepTime; 068 private float compactTableRatio; 069 private float compactRandomRegionRatio; 070 private long decreaseHFileSizeSleepTime; 071 072 @Override 073 public ChaosMonkey build() { 074 075 loadProperties(); 076 // Actions such as compact/flush a table/region, 077 // move one region around. They are not so destructive, 078 // can be executed more frequently. 079 Action[] actions1 = new Action[] { 080 new CompactTableAction(tableName, compactTableRatio), 081 new CompactRandomRegionOfTableAction(tableName, compactRandomRegionRatio), 082 new FlushTableAction(tableName), 083 new FlushRandomRegionOfTableAction(tableName), 084 new MoveRandomRegionOfTableAction(tableName) 085 }; 086 087 // Actions such as split/merge/snapshot. 088 // They should not cause data loss, or unreliability 089 // such as region stuck in transition. 090 Action[] actions2 = new Action[] { 091 new SplitRandomRegionOfTableAction(tableName), 092 new MergeRandomAdjacentRegionsOfTableAction(tableName), 093 new SnapshotTableAction(tableName), 094 new AddColumnAction(tableName), 095 new RemoveColumnAction(tableName, columnFamilies), 096 new ChangeEncodingAction(tableName), 097 new ChangeCompressionAction(tableName), 098 new ChangeBloomFilterAction(tableName), 099 new ChangeVersionsAction(tableName), 100 new ChangeSplitPolicyAction(tableName), 101 }; 102 103 // Destructive actions to mess things around. 104 Action[] actions3 = new Action[] { 105 new MoveRegionsOfTableAction(moveRegionsSleepTime, moveRegionsMaxTime, 106 tableName), 107 new MoveRandomRegionOfTableAction(moveRandomRegionSleepTime, tableName), 108 new RestartRandomRsAction(restartRandomRSSleepTime), 109 new BatchRestartRsAction(batchRestartRSSleepTime, batchRestartRSRatio), 110 new RestartActiveMasterAction(restartActiveMasterSleepTime), 111 new RollingBatchRestartRsAction(rollingBatchRestartRSSleepTime, 112 rollingBatchRestartRSRatio), 113 new RestartRsHoldingMetaAction(restartRsHoldingMetaSleepTime), 114 new DecreaseMaxHFileSizeAction(decreaseHFileSizeSleepTime, tableName), 115 new SplitAllRegionOfTableAction(tableName), 116 }; 117 118 // Action to log more info for debugging 119 Action[] actions4 = new Action[] { 120 new DumpClusterStatusAction() 121 }; 122 123 return new PolicyBasedChaosMonkey(util, 124 new PeriodicRandomActionPolicy(action1Period, actions1), 125 new PeriodicRandomActionPolicy(action2Period, actions2), 126 new CompositeSequentialPolicy( 127 new DoActionsOncePolicy(action3Period, actions3), 128 new PeriodicRandomActionPolicy(action3Period, actions3)), 129 new PeriodicRandomActionPolicy(action4Period, actions4)); 130 } 131 132 private void loadProperties() { 133 134 action1Period = Long.parseLong(this.properties.getProperty( 135 MonkeyConstants.PERIODIC_ACTION1_PERIOD, 136 MonkeyConstants.DEFAULT_PERIODIC_ACTION1_PERIOD + "")); 137 action2Period = Long.parseLong(this.properties.getProperty( 138 MonkeyConstants.PERIODIC_ACTION2_PERIOD, 139 MonkeyConstants.DEFAULT_PERIODIC_ACTION2_PERIOD + "")); 140 action3Period = Long.parseLong(this.properties.getProperty( 141 MonkeyConstants.COMPOSITE_ACTION3_PERIOD, 142 MonkeyConstants.DEFAULT_COMPOSITE_ACTION3_PERIOD + "")); 143 action4Period = Long.parseLong(this.properties.getProperty( 144 MonkeyConstants.PERIODIC_ACTION4_PERIOD, 145 MonkeyConstants.DEFAULT_PERIODIC_ACTION4_PERIOD + "")); 146 moveRegionsMaxTime = Long.parseLong(this.properties.getProperty( 147 MonkeyConstants.MOVE_REGIONS_MAX_TIME, 148 MonkeyConstants.DEFAULT_MOVE_REGIONS_MAX_TIME + "")); 149 moveRegionsSleepTime = Long.parseLong(this.properties.getProperty( 150 MonkeyConstants.MOVE_REGIONS_SLEEP_TIME, 151 MonkeyConstants.DEFAULT_MOVE_REGIONS_SLEEP_TIME + "")); 152 moveRandomRegionSleepTime = Long.parseLong(this.properties.getProperty( 153 MonkeyConstants.MOVE_RANDOM_REGION_SLEEP_TIME, 154 MonkeyConstants.DEFAULT_MOVE_RANDOM_REGION_SLEEP_TIME + "")); 155 restartRandomRSSleepTime = Long.parseLong(this.properties.getProperty( 156 MonkeyConstants.RESTART_RANDOM_RS_SLEEP_TIME, 157 MonkeyConstants.DEFAULT_RESTART_RANDOM_RS_SLEEP_TIME + "")); 158 batchRestartRSSleepTime = Long.parseLong(this.properties.getProperty( 159 MonkeyConstants.BATCH_RESTART_RS_SLEEP_TIME, 160 MonkeyConstants.DEFAULT_BATCH_RESTART_RS_SLEEP_TIME + "")); 161 batchRestartRSRatio = Float.parseFloat(this.properties.getProperty( 162 MonkeyConstants.BATCH_RESTART_RS_RATIO, 163 MonkeyConstants.DEFAULT_BATCH_RESTART_RS_RATIO + "")); 164 restartActiveMasterSleepTime = Long.parseLong(this.properties.getProperty( 165 MonkeyConstants.RESTART_ACTIVE_MASTER_SLEEP_TIME, 166 MonkeyConstants.DEFAULT_RESTART_ACTIVE_MASTER_SLEEP_TIME + "")); 167 rollingBatchRestartRSSleepTime = Long.parseLong(this.properties.getProperty( 168 MonkeyConstants.ROLLING_BATCH_RESTART_RS_SLEEP_TIME, 169 MonkeyConstants.DEFAULT_ROLLING_BATCH_RESTART_RS_SLEEP_TIME + "")); 170 rollingBatchRestartRSRatio = Float.parseFloat(this.properties.getProperty( 171 MonkeyConstants.ROLLING_BATCH_RESTART_RS_RATIO, 172 MonkeyConstants.DEFAULT_ROLLING_BATCH_RESTART_RS_RATIO + "")); 173 restartRsHoldingMetaSleepTime = Long.parseLong(this.properties.getProperty( 174 MonkeyConstants.RESTART_RS_HOLDING_META_SLEEP_TIME, 175 MonkeyConstants.DEFAULT_RESTART_RS_HOLDING_META_SLEEP_TIME + "")); 176 compactTableRatio = Float.parseFloat(this.properties.getProperty( 177 MonkeyConstants.COMPACT_TABLE_ACTION_RATIO, 178 MonkeyConstants.DEFAULT_COMPACT_TABLE_ACTION_RATIO + "")); 179 compactRandomRegionRatio = Float.parseFloat(this.properties.getProperty( 180 MonkeyConstants.COMPACT_RANDOM_REGION_RATIO, 181 MonkeyConstants.DEFAULT_COMPACT_RANDOM_REGION_RATIO + "")); 182 decreaseHFileSizeSleepTime = Long.parseLong(this.properties.getProperty( 183 MonkeyConstants.DECREASE_HFILE_SIZE_SLEEP_TIME, 184 MonkeyConstants.DEFAULT_DECREASE_HFILE_SIZE_SLEEP_TIME + "")); 185 } 186}