View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  package org.apache.hadoop.hbase.master.handler;
20  
21  import org.apache.commons.logging.Log;
22  import org.apache.commons.logging.LogFactory;
23  import org.apache.hadoop.classification.InterfaceAudience;
24  import org.apache.hadoop.hbase.HRegionInfo;
25  import org.apache.hadoop.hbase.Server;
26  import org.apache.hadoop.hbase.executor.EventHandler;
27  import org.apache.hadoop.hbase.executor.EventType;
28  import org.apache.hadoop.hbase.master.AssignmentManager;
29  import org.apache.hadoop.hbase.master.RegionState;
30  
31  /**
32   * Handles CLOSED region event on Master.
33   * <p>
34   * If table is being disabled, deletes ZK unassigned node and removes from
35   * regions in transition.
36   * <p>
37   * Otherwise, assigns the region to another server.
38   */
39  @InterfaceAudience.Private
40  public class ClosedRegionHandler extends EventHandler implements TotesHRegionInfo {
41    private static final Log LOG = LogFactory.getLog(ClosedRegionHandler.class);
42    private final AssignmentManager assignmentManager;
43    private final HRegionInfo regionInfo;
44    private final ClosedPriority priority;
45  
46    private enum ClosedPriority {
47      META (1),
48      USER (2);
49  
50      private final int value;
51      ClosedPriority(int value) {
52        this.value = value;
53      }
54      public int getValue() {
55        return value;
56      }
57    };
58  
59    public ClosedRegionHandler(Server server, AssignmentManager assignmentManager,
60        HRegionInfo regionInfo) {
61      super(server, EventType.RS_ZK_REGION_CLOSED);
62      this.assignmentManager = assignmentManager;
63      this.regionInfo = regionInfo;
64      if(regionInfo.isMetaRegion()) {
65        priority = ClosedPriority.META;
66      } else {
67        priority = ClosedPriority.USER;
68      }
69    }
70  
71    @Override
72    public int getPriority() {
73      return priority.getValue();
74    }
75  
76    @Override
77    public HRegionInfo getHRegionInfo() {
78      return this.regionInfo;
79    }
80  
81    @Override
82    public String toString() {
83      String name = "UnknownServerName";
84      if(server != null && server.getServerName() != null) {
85        name = server.getServerName().toString();
86      }
87      return getClass().getSimpleName() + "-" + name + "-" + getSeqid();
88    }
89  
90    @Override
91    public void process() {
92      LOG.debug("Handling CLOSED event for " + regionInfo.getEncodedName());
93      // Check if this table is being disabled or not
94      if (this.assignmentManager.getZKTable().
95          isDisablingOrDisabledTable(this.regionInfo.getTable())) {
96        assignmentManager.offlineDisabledRegion(regionInfo);
97        return;
98      }
99      // ZK Node is in CLOSED state, assign it.
100     assignmentManager.getRegionStates().updateRegionState(
101       regionInfo, RegionState.State.CLOSED);
102     // This below has to do w/ online enable/disable of a table
103     assignmentManager.removeClosedRegion(regionInfo);
104     assignmentManager.assign(regionInfo, true);
105   }
106 }