Ejemplo n.º 1
0
  /**
   * Get the HRegionInfo from cache, if not there, from the hbase:meta table. Be careful. Does RPC.
   * Do not hold a lock or synchronize when you call this method.
   *
   * @param regionName
   * @return HRegionInfo for the region
   */
  @SuppressWarnings("deprecation")
  protected HRegionInfo getRegionInfo(final byte[] regionName) {
    String encodedName = HRegionInfo.encodeRegionName(regionName);
    RegionState regionState = getRegionState(encodedName);
    if (regionState != null) {
      return regionState.getRegion();
    }

    try {
      Pair<HRegionInfo, ServerName> p =
          MetaTableAccessor.getRegion(server.getConnection(), regionName);
      HRegionInfo hri = p == null ? null : p.getFirst();
      if (hri != null) {
        createRegionState(hri);
      }
      return hri;
    } catch (IOException e) {
      server.abort(
          "Aborting because error occoured while reading "
              + Bytes.toStringBinary(regionName)
              + " from hbase:meta",
          e);
      return null;
    }
  }
Ejemplo n.º 2
0
 private RegionState putRegionState(RegionState regionState) {
   HRegionInfo hri = regionState.getRegion();
   String encodedName = hri.getEncodedName();
   TableName table = hri.getTable();
   RegionState oldState = regionStates.put(encodedName, regionState);
   Map<String, RegionState> map = regionStatesTableIndex.get(table);
   if (map == null) {
     map = new HashMap<String, RegionState>();
     regionStatesTableIndex.put(table, map);
   }
   map.put(encodedName, regionState);
   return oldState;
 }
Ejemplo n.º 3
0
 /**
  * A table is deleted. Remove its regions from all internal maps. We loop through all regions
  * assuming we don't delete tables too much.
  */
 public void tableDeleted(final TableName tableName) {
   Set<HRegionInfo> regionsToDelete = new HashSet<HRegionInfo>();
   synchronized (this) {
     for (RegionState state : regionStates.values()) {
       HRegionInfo region = state.getRegion();
       if (region.getTable().equals(tableName)) {
         regionsToDelete.add(region);
       }
     }
   }
   for (HRegionInfo region : regionsToDelete) {
     deleteRegion(region);
   }
 }
Ejemplo n.º 4
0
 /**
  * Gets current state of all regions of the table. This method looks at the in-memory state. It
  * does not go to <code>hbase:meta</code>. Method guaranteed to return keys for all states in
  * {@link org.apache.hadoop.hbase.master.RegionState.State}
  *
  * @param tableName
  * @return Online regions from <code>tableName</code>
  */
 public synchronized Map<RegionState.State, List<HRegionInfo>> getRegionByStateOfTable(
     TableName tableName) {
   Map<RegionState.State, List<HRegionInfo>> tableRegions =
       new HashMap<State, List<HRegionInfo>>();
   for (State state : State.values()) {
     tableRegions.put(state, new ArrayList<HRegionInfo>());
   }
   Map<String, RegionState> indexMap = regionStatesTableIndex.get(tableName);
   if (indexMap == null) return tableRegions;
   for (RegionState regionState : indexMap.values()) {
     tableRegions.get(regionState.getState()).add(regionState.getRegion());
   }
   return tableRegions;
 }
Ejemplo n.º 5
0
 /**
  * At cluster clean re/start, mark all user regions closed except those of tables that are
  * excluded, such as disabled/disabling/enabling tables. All user regions and their previous
  * locations are returned.
  */
 synchronized Map<HRegionInfo, ServerName> closeAllUserRegions(Set<TableName> excludedTables) {
   boolean noExcludeTables = excludedTables == null || excludedTables.isEmpty();
   Set<HRegionInfo> toBeClosed = new HashSet<HRegionInfo>(regionStates.size());
   for (RegionState state : regionStates.values()) {
     HRegionInfo hri = state.getRegion();
     if (state.isSplit() || hri.isSplit()) {
       continue;
     }
     TableName tableName = hri.getTable();
     if (!TableName.META_TABLE_NAME.equals(tableName)
         && (noExcludeTables || !excludedTables.contains(tableName))) {
       toBeClosed.add(hri);
     }
   }
   Map<HRegionInfo, ServerName> allUserRegions =
       new HashMap<HRegionInfo, ServerName>(toBeClosed.size());
   for (HRegionInfo hri : toBeClosed) {
     RegionState regionState = updateRegionState(hri, State.CLOSED);
     allUserRegions.put(hri, regionState.getServerName());
   }
   return allUserRegions;
 }
Ejemplo n.º 6
0
  /** A server is offline, all regions on it are dead. */
  public List<HRegionInfo> serverOffline(final ServerName sn) {
    // Offline all regions on this server not already in transition.
    List<HRegionInfo> rits = new ArrayList<HRegionInfo>();
    Set<HRegionInfo> regionsToCleanIfNoMetaEntry = new HashSet<HRegionInfo>();
    // Offline regions outside the loop and synchronized block to avoid
    // ConcurrentModificationException and deadlock in case of meta anassigned,
    // but RegionState a blocked.
    Set<HRegionInfo> regionsToOffline = new HashSet<HRegionInfo>();
    synchronized (this) {
      Set<HRegionInfo> assignedRegions = serverHoldings.get(sn);
      if (assignedRegions == null) {
        assignedRegions = new HashSet<HRegionInfo>();
      }

      for (HRegionInfo region : assignedRegions) {
        // Offline open regions, no need to offline if SPLIT/MERGED/OFFLINE
        if (isRegionOnline(region)) {
          regionsToOffline.add(region);
        } else if (isRegionInState(region, State.SPLITTING, State.MERGING)) {
          LOG.debug("Offline splitting/merging region " + getRegionState(region));
          regionsToOffline.add(region);
        }
      }

      for (RegionState state : regionsInTransition.values()) {
        HRegionInfo hri = state.getRegion();
        if (assignedRegions.contains(hri)) {
          // Region is open on this region server, but in transition.
          // This region must be moving away from this server, or splitting/merging.
          // SSH will handle it, either skip assigning, or re-assign.
          LOG.info("Transitioning " + state + " will be handled by ServerCrashProcedure for " + sn);
        } else if (sn.equals(state.getServerName())) {
          // Region is in transition on this region server, and this
          // region is not open on this server. So the region must be
          // moving to this server from another one (i.e. opening or
          // pending open on this server, was open on another one.
          // Offline state is also kind of pending open if the region is in
          // transition. The region could be in failed_close state too if we have
          // tried several times to open it while this region server is not reachable)
          if (isOneOfStates(
              state,
              State.OPENING,
              State.PENDING_OPEN,
              State.FAILED_OPEN,
              State.FAILED_CLOSE,
              State.OFFLINE)) {
            LOG.info(
                "Found region in " + state + " to be reassigned by ServerCrashProcedure for " + sn);
            rits.add(hri);
          } else if (isOneOfStates(state, State.SPLITTING_NEW)) {
            regionsToCleanIfNoMetaEntry.add(state.getRegion());
          } else {
            LOG.warn("THIS SHOULD NOT HAPPEN: unexpected " + state);
          }
        }
      }
      this.notifyAll();
    }

    for (HRegionInfo hri : regionsToOffline) {
      regionOffline(hri);
    }

    cleanIfNoMetaEntry(regionsToCleanIfNoMetaEntry);
    return rits;
  }
Ejemplo n.º 7
0
 /** @return True if hbase:meta table region is in transition. */
 public synchronized boolean isMetaRegionInTransition() {
   for (RegionState state : regionsInTransition.values()) {
     if (state.getRegion().isMetaRegion()) return true;
   }
   return false;
 }