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.ChangeBloomFilterAction; 024import org.apache.hadoop.hbase.chaos.actions.ChangeCompressionAction; 025import org.apache.hadoop.hbase.chaos.actions.ChangeEncodingAction; 026import org.apache.hadoop.hbase.chaos.actions.ChangeSplitPolicyAction; 027import org.apache.hadoop.hbase.chaos.actions.ChangeVersionsAction; 028import org.apache.hadoop.hbase.chaos.actions.CompactRandomRegionOfTableAction; 029import org.apache.hadoop.hbase.chaos.actions.CompactTableAction; 030import org.apache.hadoop.hbase.chaos.actions.DecreaseMaxHFileSizeAction; 031import org.apache.hadoop.hbase.chaos.actions.DumpClusterStatusAction; 032import org.apache.hadoop.hbase.chaos.actions.FlushRandomRegionOfTableAction; 033import org.apache.hadoop.hbase.chaos.actions.FlushTableAction; 034import org.apache.hadoop.hbase.chaos.actions.GracefulRollingRestartRsAction; 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.RollingBatchSuspendResumeRsAction; 044import org.apache.hadoop.hbase.chaos.actions.SnapshotTableAction; 045import org.apache.hadoop.hbase.chaos.actions.SplitAllRegionOfTableAction; 046import org.apache.hadoop.hbase.chaos.actions.SplitRandomRegionOfTableAction; 047import org.apache.hadoop.hbase.chaos.monkies.ChaosMonkey; 048import org.apache.hadoop.hbase.chaos.monkies.PolicyBasedChaosMonkey; 049import org.apache.hadoop.hbase.chaos.policies.CompositeSequentialPolicy; 050import org.apache.hadoop.hbase.chaos.policies.DoActionsOncePolicy; 051import org.apache.hadoop.hbase.chaos.policies.PeriodicRandomActionPolicy; 052 053public class SlowDeterministicMonkeyFactory extends MonkeyFactory { 054 055 protected Action[] getLightWeightedActions() { 056 return new Action[] { new CompactTableAction(tableName, compactTableRatio), 057 new CompactRandomRegionOfTableAction(tableName, compactRandomRegionRatio), 058 new FlushTableAction(tableName), new FlushRandomRegionOfTableAction(tableName), 059 new MoveRandomRegionOfTableAction(tableName) }; 060 } 061 062 protected Action[] getMidWeightedActions() { 063 return new Action[] { new SplitRandomRegionOfTableAction(tableName), 064 new MergeRandomAdjacentRegionsOfTableAction(tableName), 065 new SnapshotTableAction(tableName, snapshotTableTtl), new AddColumnAction(tableName), 066 new RemoveColumnAction(tableName, columnFamilies), new ChangeEncodingAction(tableName), 067 new ChangeCompressionAction(tableName), new ChangeBloomFilterAction(tableName), 068 new ChangeVersionsAction(tableName), new ChangeSplitPolicyAction(tableName), }; 069 } 070 071 protected Action[] getHeavyWeightedActions() { 072 return new Action[] { 073 new MoveRegionsOfTableAction(moveRegionsSleepTime, moveRegionsMaxTime, tableName), 074 new MoveRandomRegionOfTableAction(moveRandomRegionSleepTime, tableName), 075 new RestartRandomRsAction(restartRandomRSSleepTime), 076 new BatchRestartRsAction(batchRestartRSSleepTime, batchRestartRSRatio), 077 new RestartActiveMasterAction(restartActiveMasterSleepTime), 078 new RollingBatchRestartRsAction(rollingBatchRestartRSSleepTime, rollingBatchRestartRSRatio), 079 new RestartRsHoldingMetaAction(restartRsHoldingMetaSleepTime), 080 new DecreaseMaxHFileSizeAction(decreaseHFileSizeSleepTime, decreaseHFileSizeMinHFileSize, 081 decreaseHFileSizeHFileSizeJitter, tableName), 082 new SplitAllRegionOfTableAction(tableName), 083 new GracefulRollingRestartRsAction(gracefulRollingRestartTSSLeepTime), 084 new RollingBatchSuspendResumeRsAction(rollingBatchSuspendRSSleepTime, 085 rollingBatchSuspendRSRatio) }; 086 } 087 088 @Override 089 public ChaosMonkey build() { 090 loadProperties(); 091 // Actions such as compact/flush a table/region, 092 // move one region around. They are not so destructive, 093 // can be executed more frequently. 094 Action[] actions1 = getLightWeightedActions(); 095 096 // Actions such as split/merge/snapshot. 097 // They should not cause data loss, or unreliability 098 // such as region stuck in transition. 099 Action[] actions2 = getMidWeightedActions(); 100 101 // Destructive actions to mess things around. 102 Action[] actions3 = getHeavyWeightedActions(); 103 104 // Action to log more info for debugging 105 Action[] actions4 = new Action[] { new DumpClusterStatusAction() }; 106 107 return new PolicyBasedChaosMonkey(properties, util, 108 new PeriodicRandomActionPolicy(action1Period, actions1), 109 new PeriodicRandomActionPolicy(action2Period, actions2), 110 new CompositeSequentialPolicy(new DoActionsOncePolicy(action3Period, actions3), 111 new PeriodicRandomActionPolicy(action3Period, actions3)), 112 new PeriodicRandomActionPolicy(action4Period, actions4)); 113 } 114}