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.actions; 020 021import java.io.IOException; 022import java.util.Arrays; 023import java.util.List; 024import org.apache.commons.lang3.RandomUtils; 025import org.apache.hadoop.hbase.ServerName; 026import org.apache.hadoop.hbase.util.RegionMover; 027import org.apache.hadoop.util.Shell; 028import org.slf4j.Logger; 029import org.slf4j.LoggerFactory; 030 031/** 032 * Gracefully restarts every regionserver in a rolling fashion. At each step, it unloads, 033 * restarts the loads every rs server sleeping randomly (0-sleepTime) in between servers. 034 */ 035public class GracefulRollingRestartRsAction extends RestartActionBaseAction { 036 private static final Logger LOG = LoggerFactory.getLogger(GracefulRollingRestartRsAction.class); 037 038 public GracefulRollingRestartRsAction(long sleepTime) { 039 super(sleepTime); 040 } 041 042 @Override protected Logger getLogger() { 043 return LOG; 044 } 045 046 @Override 047 public void perform() throws Exception { 048 getLogger().info("Performing action: Rolling restarting non-master region servers"); 049 List<ServerName> selectedServers = selectServers(); 050 051 getLogger().info("Disabling balancer to make unloading possible"); 052 setBalancer(false, true); 053 054 for (ServerName server : selectedServers) { 055 String rsName = server.getAddress().toString(); 056 try (RegionMover rm = 057 new RegionMover.RegionMoverBuilder(rsName, getConf()).ack(true).build()) { 058 getLogger().info("Unloading {}", server); 059 rm.unload(); 060 getLogger().info("Restarting {}", server); 061 gracefulRestartRs(server, sleepTime); 062 getLogger().info("Loading {}", server); 063 rm.load(); 064 } catch (Shell.ExitCodeException e) { 065 getLogger().info("Problem restarting but presume successful; code={}", e.getExitCode(), e); 066 } 067 sleep(RandomUtils.nextInt(0, (int)sleepTime)); 068 } 069 getLogger().info("Enabling balancer"); 070 setBalancer(true, true); 071 } 072 073 protected List<ServerName> selectServers() throws IOException { 074 return Arrays.asList(getCurrentServers()); 075 } 076}