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.NamespaceDescriptor;
26  import org.apache.hadoop.hbase.Server;
27  import org.apache.hadoop.hbase.coordination.OpenRegionCoordination;
28  import org.apache.hadoop.hbase.executor.EventHandler;
29  import org.apache.hadoop.hbase.executor.EventType;
30  import org.apache.hadoop.hbase.master.AssignmentManager;
31  
32  /**
33   * Handles OPENED region event on Master.
34   */
35  @InterfaceAudience.Private
36  public class OpenedRegionHandler extends EventHandler implements TotesHRegionInfo {
37    private static final Log LOG = LogFactory.getLog(OpenedRegionHandler.class);
38    private final AssignmentManager assignmentManager;
39    private final HRegionInfo regionInfo;
40    private final OpenedPriority priority;
41  
42    private OpenRegionCoordination coordination;
43    private OpenRegionCoordination.OpenRegionDetails ord;
44  
45    private enum OpenedPriority {
46      META (1),
47      SYSTEM (2),
48      USER (3);
49  
50      private final int value;
51      OpenedPriority(int value) {
52        this.value = value;
53      }
54      public int getValue() {
55        return value;
56      }
57    };
58  
59    public OpenedRegionHandler(Server server,
60        AssignmentManager assignmentManager, HRegionInfo regionInfo,
61        OpenRegionCoordination coordination,
62        OpenRegionCoordination.OpenRegionDetails ord) {
63      super(server, EventType.RS_ZK_REGION_OPENED);
64      this.assignmentManager = assignmentManager;
65      this.regionInfo = regionInfo;
66      this.coordination = coordination;
67      this.ord = ord;
68      if(regionInfo.isMetaRegion()) {
69        priority = OpenedPriority.META;
70      } else if(regionInfo.getTable()
71          .getNamespaceAsString().equals(NamespaceDescriptor.SYSTEM_NAMESPACE_NAME_STR)) {
72        priority = OpenedPriority.SYSTEM;
73      } else {
74        priority = OpenedPriority.USER;
75      }
76    }
77  
78    @Override
79    public int getPriority() {
80      return priority.getValue();
81    }
82  
83    @Override
84    public HRegionInfo getHRegionInfo() {
85      return this.regionInfo;
86    }
87  
88    @Override
89    public String toString() {
90      String name = "UnknownServerName";
91      if(server != null && server.getServerName() != null) {
92        name = server.getServerName().toString();
93      }
94      return getClass().getSimpleName() + "-" + name + "-" + getSeqid();
95    }
96  
97    @Override
98    public void process() {
99      if (!coordination.commitOpenOnMasterSide(assignmentManager,regionInfo, ord)) {
100         assignmentManager.unassign(regionInfo);
101     }
102   }
103 }