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.Server;
26  import org.apache.hadoop.hbase.executor.EventHandler;
27  import org.apache.hadoop.hbase.master.AssignmentManager;
28  
29  /**
30   * Handles CLOSED region event on Master.
31   * <p>
32   * If table is being disabled, deletes ZK unassigned node and removes from
33   * regions in transition.
34   * <p>
35   * Otherwise, assigns the region to another server.
36   */
37  public class ClosedRegionHandler extends EventHandler implements TotesHRegionInfo {
38    private static final Log LOG = LogFactory.getLog(ClosedRegionHandler.class);
39    private final AssignmentManager assignmentManager;
40    private final HRegionInfo regionInfo;
41    private final ClosedPriority priority;
42  
43    private enum ClosedPriority {
44      ROOT (1),
45      META (2),
46      USER (3);
47  
48      private final int value;
49      ClosedPriority(int value) {
50        this.value = value;
51      }
52      public int getValue() {
53        return value;
54      }
55    };
56  
57    public ClosedRegionHandler(Server server, AssignmentManager assignmentManager,
58        HRegionInfo regionInfo) {
59      super(server, EventType.RS_ZK_REGION_CLOSED);
60      this.assignmentManager = assignmentManager;
61      this.regionInfo = regionInfo;
62      if(regionInfo.isRootRegion()) {
63        priority = ClosedPriority.ROOT;
64      } else 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.getTableNameAsString())) {
96        assignmentManager.offlineDisabledRegion(regionInfo);
97        return;
98      }
99      // ZK Node is in CLOSED state, assign it.
100     // TODO: Should we remove the region from RIT too?  We don't?  Makes for
101     // a 'forcing' log message when we go to update state from CLOSED to OFFLINE
102     assignmentManager.setOffline(regionInfo);
103     // This below has to do w/ online enable/disable of a table
104     assignmentManager.removeClosedRegion(regionInfo);
105     assignmentManager.assign(regionInfo, true);
106   }
107 }