Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package org.apache.hadoop.hbase.util;
 
 import java.util.List;
 import java.util.Map;
 
This class contains helper methods that repair parts of hbase's filesystem contents.
 
 public class HBaseFsckRepair {
   public static final Log LOG = LogFactory.getLog(HBaseFsckRepair.class);

  
Fix multiple assignment by doing silent closes on each RS hosting the region and then force ZK unassigned node to OFFLINE to trigger assignment by master.

Parameters:
admin HBase admin used to undeploy
region Region to undeploy
servers list of Servers to undeploy from
 
   public static void fixMultiAssignment(HBaseAdmin adminHRegionInfo region,
       List<ServerNameservers)
     HRegionInfo actualRegion = new HRegionInfo(region);
 
     // Close region on the servers silently
     for(ServerName server : servers) {
       closeRegionSilentlyAndWait(adminserveractualRegion);
     }
 
     // Force ZK node to OFFLINE so master assigns
     forceOfflineInZK(adminactualRegion);
   }

  
Fix unassigned by creating/transition the unassigned ZK node for this region to OFFLINE state with a special flag to tell the master that this is a forced operation by HBCK. This assumes that info is in META.

 
   public static void fixUnassigned(HBaseAdmin adminHRegionInfo region)
       throws IOExceptionKeeperException {
     HRegionInfo actualRegion = new HRegionInfo(region);
 
     // Force ZK node to OFFLINE so master assigns
     forceOfflineInZK(adminactualRegion);
   }

  
In 0.90, this forces an HRI offline by setting the RegionTransitionData in ZK to have HBCK_CODE_NAME as the server. This is a special case in the AssignmentManager that attempts an assign call by the master.

See also:
org.apache.hadoop.hbase.master.AssignementManager.handleHBCK This doesn't seem to work properly in the updated version of 0.92+'s hbck so we use assign to force the region into transition. This has the side-effect of requiring a HRegionInfo that considers regionId (timestamp) in comparators that is addressed by HBASE-5563.
  private static void forceOfflineInZK(HBaseAdmin adminfinal HRegionInfo region)
    admin.assign(region.getRegionName());
  }
  /*
   * Should we check all assignments or just not in RIT?
   */
  public static void waitUntilAssigned(HBaseAdmin admin,
      HRegionInfo regionthrows IOExceptionInterruptedException {
    long timeout = admin.getConfiguration().getLong("hbase.hbck.assign.timeout", 120000);
    long expiration = timeout + System.currentTimeMillis();
    while (System.currentTimeMillis() < expiration) {
      try {
        Map<StringRegionStaterits=
            admin.getClusterStatus().getRegionsInTransition();
        if (rits.keySet() != null && !rits.keySet().contains(region.getEncodedName())) {
          // yay! no longer RIT
          return;
        }
        // still in rit
        .info("Region still in transition, waiting for "
            + "it to become assigned: " + region);
      } catch (IOException e) {
        .warn("Exception when waiting for region to become assigned,"
            + " retrying"e);
      }
      Thread.sleep(1000);
    }
    throw new IOException("Region " + region + " failed to move out of " +
        "transition within timeout " + timeout + "ms");
  }

  
Contacts a region server and waits up to hbase.hbck.close.timeout ms (default 120s) to close the region. This bypasses the active hmaster.
  public static void closeRegionSilentlyAndWait(HBaseAdmin admin,
      ServerName serverHRegionInfo regionthrows IOExceptionInterruptedException {
    HConnection connection = admin.getConnection();
    AdminService.BlockingInterface rs = connection.getAdmin(server);
    try {
      ProtobufUtil.closeRegion(rsserverregion.getRegionName(), false);
    } catch (IOException e) {
      .warn("Exception when closing region: " + region.getRegionNameAsString(), e);
    }
    long timeout = admin.getConfiguration()
      .getLong("hbase.hbck.close.timeout", 120000);
    long expiration = timeout + System.currentTimeMillis();
    while (System.currentTimeMillis() < expiration) {
      try {
        HRegionInfo rsRegion =
          ProtobufUtil.getRegionInfo(rsregion.getRegionName());
        if (rsRegion == nullreturn;
      } catch (IOException ioe) {
        if (ioe instanceof NotServingRegionException// no need to retry again
          return;
        .warn("Exception when retrieving regioninfo from: " + region.getRegionNameAsString(), ioe);
      }
      Thread.sleep(1000);
    }
    throw new IOException("Region " + region + " failed to close within"
        + " timeout " + timeout);
  }

  
Puts the specified HRegionInfo into META.
  public static void fixMetaHoleOnline(Configuration conf,
      HRegionInfo hrithrows IOException {
    HTable meta = new HTable(conf.);
    MetaEditor.addRegionToMeta(metahri);
    meta.close();
  }

  
Creates, flushes, and closes a new region.
  public static HRegion createHDFSRegionDir(Configuration conf,
      HRegionInfo hriHTableDescriptor htdthrows IOException {
    // Create HRegion
    Path root = FSUtils.getRootDir(conf);
    HRegion region = HRegion.createHRegion(hrirootconfhtdnull);
    // Close the new region to flush to disk. Close log file too.
    region.close();
    return region;
  }
New to GrepCode? Check out our FAQ X