View Javadoc

1   /**
2    * Copyright 2010 The Apache Software Foundation
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
19   */
20  package org.apache.hadoop.hbase.master.handler;
21  
22  import org.apache.commons.logging.Log;
23  import org.apache.commons.logging.LogFactory;
24  import org.apache.hadoop.hbase.HRegionInfo;
25  import org.apache.hadoop.hbase.HServerInfo;
26  import org.apache.hadoop.hbase.Server;
27  import org.apache.hadoop.hbase.executor.EventHandler;
28  import org.apache.hadoop.hbase.master.AssignmentManager;
29  import org.apache.hadoop.hbase.zookeeper.ZKAssign;
30  import org.apache.zookeeper.KeeperException;
31  
32  /**
33   * Handles OPENED region event on Master.
34   */
35  public class OpenedRegionHandler extends EventHandler implements TotesHRegionInfo {
36    private static final Log LOG = LogFactory.getLog(OpenedRegionHandler.class);
37    private final AssignmentManager assignmentManager;
38    private final HRegionInfo regionInfo;
39    private final HServerInfo serverInfo;
40    private final OpenedPriority priority;
41  
42    private enum OpenedPriority {
43      ROOT (1),
44      META (2),
45      USER (3);
46  
47      private final int value;
48      OpenedPriority(int value) {
49        this.value = value;
50      }
51      public int getValue() {
52        return value;
53      }
54    };
55  
56    public OpenedRegionHandler(Server server,
57        AssignmentManager assignmentManager, HRegionInfo regionInfo,
58        HServerInfo serverInfo) {
59      super(server, EventType.RS_ZK_REGION_OPENED);
60      this.assignmentManager = assignmentManager;
61      this.regionInfo = regionInfo;
62      this.serverInfo = serverInfo;
63      if(regionInfo.isRootRegion()) {
64        priority = OpenedPriority.ROOT;
65      } else if(regionInfo.isMetaRegion()) {
66        priority = OpenedPriority.META;
67      } else {
68        priority = OpenedPriority.USER;
69      }
70    }
71  
72    @Override
73    public int getPriority() {
74      return priority.getValue();
75    }
76  
77    @Override
78    public HRegionInfo getHRegionInfo() {
79      return this.regionInfo;
80    }
81  
82    @Override
83    public void process() {
84      LOG.debug("Handling OPENED event for " + this.regionInfo.getEncodedName() +
85        "; deleting unassigned node");
86      // Remove region from in-memory transition and unassigned node from ZK
87      try {
88        ZKAssign.deleteOpenedNode(server.getZooKeeper(),
89            regionInfo.getEncodedName());
90      } catch (KeeperException e) {
91        server.abort("Error deleting OPENED node in ZK for transition ZK node (" +
92            regionInfo.getEncodedName() + ")", e);
93      }
94      // Code to defend against case where we get SPLIT before region open
95      // processing completes; temporary till we make SPLITs go via zk -- 0.92.
96      if (this.assignmentManager.isRegionInTransition(regionInfo) != null) {
97        this.assignmentManager.regionOnline(regionInfo, serverInfo);
98      } else {
99        LOG.warn("Skipping the onlining of " + regionInfo.getRegionNameAsString() +
100         " because regions is NOT in RIT -- presuming this is because it SPLIT");
101     }
102     if (this.assignmentManager.getZKTable().isDisablingOrDisabledTable(
103         regionInfo.getTableDesc().getNameAsString())) {
104       LOG.debug("Opened region " + regionInfo.getRegionNameAsString() + " but "
105           + "this table is disabled, triggering close of region");
106       assignmentManager.unassign(regionInfo);
107     } else {
108       LOG.debug("Opened region " + regionInfo.getRegionNameAsString() +
109           " on " + serverInfo.getServerName());
110     }
111   }
112 }