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 */ 018package org.apache.hadoop.hbase.chaos.factories; 019 020import org.apache.hadoop.hbase.chaos.actions.Action; 021import org.apache.hadoop.hbase.chaos.actions.AddColumnAction; 022import org.apache.hadoop.hbase.chaos.actions.BatchRestartRsAction; 023import org.apache.hadoop.hbase.chaos.actions.ChangeSplitPolicyAction; 024import org.apache.hadoop.hbase.chaos.actions.CompactRandomRegionOfTableAction; 025import org.apache.hadoop.hbase.chaos.actions.CompactTableAction; 026import org.apache.hadoop.hbase.chaos.actions.DecreaseMaxHFileSizeAction; 027import org.apache.hadoop.hbase.chaos.actions.DumpClusterStatusAction; 028import org.apache.hadoop.hbase.chaos.actions.FlushRandomRegionOfTableAction; 029import org.apache.hadoop.hbase.chaos.actions.FlushTableAction; 030import org.apache.hadoop.hbase.chaos.actions.GracefulRollingRestartRsAction; 031import org.apache.hadoop.hbase.chaos.actions.MergeRandomAdjacentRegionsOfTableAction; 032import org.apache.hadoop.hbase.chaos.actions.MoveRandomRegionOfTableAction; 033import org.apache.hadoop.hbase.chaos.actions.MoveRegionsOfTableAction; 034import org.apache.hadoop.hbase.chaos.actions.RemoveColumnAction; 035import org.apache.hadoop.hbase.chaos.actions.RestartRandomRsAction; 036import org.apache.hadoop.hbase.chaos.actions.RestartRsHoldingMetaAction; 037import org.apache.hadoop.hbase.chaos.actions.RollingBatchRestartRsAction; 038import org.apache.hadoop.hbase.chaos.actions.RollingBatchSuspendResumeRsAction; 039import org.apache.hadoop.hbase.chaos.actions.SplitAllRegionOfTableAction; 040import org.apache.hadoop.hbase.chaos.actions.SplitRandomRegionOfTableAction; 041import org.apache.hadoop.hbase.chaos.monkies.ChaosMonkey; 042import org.apache.hadoop.hbase.chaos.monkies.PolicyBasedChaosMonkey; 043import org.apache.hadoop.hbase.chaos.policies.CompositeSequentialPolicy; 044import org.apache.hadoop.hbase.chaos.policies.DoActionsOncePolicy; 045import org.apache.hadoop.hbase.chaos.policies.PeriodicRandomActionPolicy; 046 047public class StressAssignmentManagerMonkeyFactory extends MonkeyFactory { 048 049 private long gracefulRollingRestartTSSLeepTime; 050 private long rollingBatchSuspendRSSleepTime; 051 private float rollingBatchSuspendtRSRatio; 052 053 @Override 054 public ChaosMonkey build() { 055 loadProperties(); 056 057 // Actions that could slow down region movement. 058 // These could also get regions stuck if there are issues. 059 Action[] actions1 = new Action[] { new CompactTableAction(tableName, 0.5f), 060 new CompactRandomRegionOfTableAction(tableName, 0.6f), new FlushTableAction(tableName), 061 new FlushRandomRegionOfTableAction(tableName) }; 062 063 Action[] actions2 = new Action[] { new SplitRandomRegionOfTableAction(tableName), 064 new MergeRandomAdjacentRegionsOfTableAction(tableName), new AddColumnAction(tableName), 065 new RemoveColumnAction(tableName, columnFamilies), 066 new MoveRegionsOfTableAction(MonkeyConstants.DEFAULT_MOVE_REGIONS_SLEEP_TIME, 1600, 067 tableName), 068 new MoveRandomRegionOfTableAction(MonkeyConstants.DEFAULT_MOVE_RANDOM_REGION_SLEEP_TIME, 069 tableName), 070 new RestartRandomRsAction(MonkeyConstants.DEFAULT_RESTART_RANDOM_RS_SLEEP_TIME), 071 new BatchRestartRsAction(MonkeyConstants.DEFAULT_BATCH_RESTART_RS_SLEEP_TIME, 0.5f), 072 new RollingBatchRestartRsAction(MonkeyConstants.DEFAULT_ROLLING_BATCH_RESTART_RS_SLEEP_TIME, 073 1.0f), 074 new RestartRsHoldingMetaAction(MonkeyConstants.DEFAULT_RESTART_RS_HOLDING_META_SLEEP_TIME), 075 new ChangeSplitPolicyAction(tableName), new SplitAllRegionOfTableAction(tableName), 076 new DecreaseMaxHFileSizeAction(MonkeyConstants.DEFAULT_DECREASE_HFILE_SIZE_SLEEP_TIME, 077 tableName), 078 new GracefulRollingRestartRsAction(gracefulRollingRestartTSSLeepTime), 079 new RollingBatchSuspendResumeRsAction(rollingBatchSuspendRSSleepTime, 080 rollingBatchSuspendtRSRatio) }; 081 082 // Action to log more info for debugging 083 Action[] actions3 = new Action[] { new DumpClusterStatusAction() }; 084 085 return new PolicyBasedChaosMonkey(properties, util, 086 new PeriodicRandomActionPolicy(90 * 1000, actions1), 087 new CompositeSequentialPolicy(new DoActionsOncePolicy(90 * 1000, actions2), 088 new PeriodicRandomActionPolicy(90 * 1000, actions2)), 089 new PeriodicRandomActionPolicy(90 * 1000, actions3)); 090 } 091 092 private void loadProperties() { 093 gracefulRollingRestartTSSLeepTime = 094 Long.parseLong(this.properties.getProperty(MonkeyConstants.GRACEFUL_RESTART_RS_SLEEP_TIME, 095 MonkeyConstants.DEFAULT_GRACEFUL_RESTART_RS_SLEEP_TIME + "")); 096 rollingBatchSuspendRSSleepTime = Long 097 .parseLong(this.properties.getProperty(MonkeyConstants.ROLLING_BATCH_SUSPEND_RS_SLEEP_TIME, 098 MonkeyConstants.DEFAULT_ROLLING_BATCH_SUSPEND_RS_SLEEP_TIME + "")); 099 rollingBatchSuspendtRSRatio = 100 Float.parseFloat(this.properties.getProperty(MonkeyConstants.ROLLING_BATCH_SUSPEND_RS_RATIO, 101 MonkeyConstants.DEFAULT_ROLLING_BATCH_SUSPEND_RS_RATIO + "")); 102 } 103}