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.actions; 019 020import org.apache.hadoop.hbase.HBaseTestingUtility; 021import org.apache.hadoop.hbase.TableName; 022import org.apache.hadoop.hbase.client.Admin; 023 024import java.io.IOException; 025import java.util.concurrent.ThreadLocalRandom; 026 027 028public class SplitAllRegionOfTableAction extends Action { 029 private static final int DEFAULT_MAX_SPLITS = 3; 030 private static final String MAX_SPLIT_KEY = "hbase.chaosmonkey.action.maxFullTableSplits"; 031 032 private final TableName tableName; 033 private int maxFullTableSplits = DEFAULT_MAX_SPLITS; 034 private int splits = 0; 035 036 public SplitAllRegionOfTableAction(TableName tableName) { 037 this.tableName = tableName; 038 } 039 040 041 public void init(ActionContext context) throws IOException { 042 super.init(context); 043 this.maxFullTableSplits = getConf().getInt(MAX_SPLIT_KEY, DEFAULT_MAX_SPLITS); 044 } 045 046 @Override 047 public void perform() throws Exception { 048 HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility(); 049 Admin admin = util.getAdmin(); 050 // Don't try the split if we're stopping 051 if (context.isStopping()) { 052 return; 053 } 054 055 056 // Don't always split. This should allow splitting of a full table later in the run 057 if (ThreadLocalRandom.current().nextDouble() 058 < (((double) splits) / ((double) maxFullTableSplits)) / ((double) 2)) { 059 splits++; 060 LOG.info("Performing action: Split all regions of " + tableName); 061 admin.split(tableName); 062 } else { 063 LOG.info("Skipping split of all regions."); 064 } 065 } 066}