예제 #1
0
  /**
   * A region is online, won't be in transition any more. We can't confirm it is really online on
   * specified region server because it hasn't been put in region server's online region list yet.
   */
  public void regionOnline(final HRegionInfo hri, final ServerName serverName, long openSeqNum) {
    String encodedName = hri.getEncodedName();
    if (!serverManager.isServerOnline(serverName)) {
      // This is possible if the region server dies before master gets a
      // chance to handle ZK event in time. At this time, if the dead server
      // is already processed by SSH, we should ignore this event.
      // If not processed yet, ignore and let SSH deal with it.
      LOG.warn("Ignored, " + encodedName + " was opened on a dead server: " + serverName);
      return;
    }
    updateRegionState(hri, State.OPEN, serverName, openSeqNum);

    synchronized (this) {
      regionsInTransition.remove(encodedName);
      ServerName oldServerName = regionAssignments.put(hri, serverName);
      if (!serverName.equals(oldServerName)) {
        if (LOG.isDebugEnabled()) {
          LOG.debug("Onlined " + hri.getShortNameToLog() + " on " + serverName);
        }
        addToServerHoldings(serverName, hri);
        addToReplicaMapping(hri);
        if (oldServerName == null) {
          oldServerName = oldAssignments.remove(encodedName);
        }
        if (oldServerName != null
            && !oldServerName.equals(serverName)
            && serverHoldings.containsKey(oldServerName)) {
          LOG.info("Offlined " + hri.getShortNameToLog() + " from " + oldServerName);
          removeFromServerHoldings(oldServerName, hri);
        }
      }
    }
  }
예제 #2
0
 /**
  * Add a region to RegionStates with the specified state. If the region is already in
  * RegionStates, this call has no effect, and the original state is returned.
  *
  * @param hri the region info to create a state for
  * @param newState the state to the region in set to
  * @param serverName the server the region is transitioning on
  * @param lastHost the last server that hosts the region
  * @return the current state
  */
 public synchronized RegionState createRegionState(
     final HRegionInfo hri, State newState, ServerName serverName, ServerName lastHost) {
   if (newState == null || (newState == State.OPEN && serverName == null)) {
     newState = State.OFFLINE;
   }
   if (hri.isOffline() && hri.isSplit()) {
     newState = State.SPLIT;
     serverName = null;
   }
   String encodedName = hri.getEncodedName();
   RegionState regionState = regionStates.get(encodedName);
   if (regionState != null) {
     LOG.warn(
         "Tried to create a state for a region already in RegionStates, "
             + "used existing: "
             + regionState
             + ", ignored new: "
             + newState);
   } else {
     regionState = new RegionState(hri, newState, serverName);
     putRegionState(regionState);
     if (newState == State.OPEN) {
       if (!serverName.equals(lastHost)) {
         LOG.warn(
             "Open region's last host "
                 + lastHost
                 + " should be the same as the current one "
                 + serverName
                 + ", ignored the last and used the current one");
         lastHost = serverName;
       }
       lastAssignments.put(encodedName, lastHost);
       regionAssignments.put(hri, lastHost);
     } else if (!isOneOfStates(regionState, State.MERGED, State.SPLIT, State.OFFLINE)) {
       regionsInTransition.put(encodedName, regionState);
     }
     if (lastHost != null && newState != State.SPLIT) {
       addToServerHoldings(lastHost, hri);
       if (newState != State.OPEN) {
         oldAssignments.put(encodedName, lastHost);
       }
     }
   }
   return regionState;
 }