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.util;
019
020import java.util.List;
021import java.util.concurrent.Callable;
022import org.apache.hadoop.hbase.ServerName;
023import org.apache.hadoop.hbase.client.Admin;
024import org.apache.hadoop.hbase.client.RegionInfo;
025import org.apache.yetus.audience.InterfaceAudience;
026import org.slf4j.Logger;
027import org.slf4j.LoggerFactory;
028
029/**
030 * Move Regions without Acknowledging.Usefule in case of RS shutdown as we might want to shut the RS
031 * down anyways and not abort on a stuck region. Improves movement performance
032 */
033@InterfaceAudience.Private
034class MoveWithoutAck implements Callable<Boolean> {
035
036  private static final Logger LOG = LoggerFactory.getLogger(MoveWithoutAck.class);
037
038  private final RegionInfo region;
039  private final ServerName targetServer;
040  private final List<RegionInfo> movedRegions;
041  private final ServerName sourceServer;
042  private final Admin admin;
043
044  MoveWithoutAck(Admin admin, RegionInfo regionInfo, ServerName sourceServer,
045    ServerName targetServer, List<RegionInfo> movedRegions) {
046    this.admin = admin;
047    this.region = regionInfo;
048    this.targetServer = targetServer;
049    this.movedRegions = movedRegions;
050    this.sourceServer = sourceServer;
051  }
052
053  @Override
054  public Boolean call() {
055    try {
056      LOG.info("Moving region: {} from {} to {}", region.getEncodedName(), sourceServer,
057        targetServer);
058      admin.move(region.getEncodedNameAsBytes(), targetServer);
059      LOG.info("Requested move {} from {} to {}", region.getEncodedName(), sourceServer,
060        targetServer);
061    } catch (Exception e) {
062      LOG.error("Error Moving Region: {}", region.getEncodedName(), e);
063    } finally {
064      movedRegions.add(region);
065    }
066    return true;
067  }
068}