1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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.hbase.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
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 }