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.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 import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos;
31
32
33
34
35
36
37
38
39
40 @InterfaceAudience.Private
41 public class ClosedRegionHandler extends EventHandler implements TotesHRegionInfo {
42 private static final Log LOG = LogFactory.getLog(ClosedRegionHandler.class);
43 private final AssignmentManager assignmentManager;
44 private final HRegionInfo regionInfo;
45 private final ClosedPriority priority;
46
47 private enum ClosedPriority {
48 META (1),
49 USER (2);
50
51 private final int value;
52 ClosedPriority(int value) {
53 this.value = value;
54 }
55 public int getValue() {
56 return value;
57 }
58 };
59
60 public ClosedRegionHandler(Server server, AssignmentManager assignmentManager,
61 HRegionInfo regionInfo) {
62 super(server, EventType.RS_ZK_REGION_CLOSED);
63 this.assignmentManager = assignmentManager;
64 this.regionInfo = regionInfo;
65 if(regionInfo.isMetaRegion()) {
66 priority = ClosedPriority.META;
67 } else {
68 priority = ClosedPriority.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 String toString() {
84 String name = "UnknownServerName";
85 if(server != null && server.getServerName() != null) {
86 name = server.getServerName().toString();
87 }
88 return getClass().getSimpleName() + "-" + name + "-" + getSeqid();
89 }
90
91 @Override
92 public void process() {
93 LOG.debug("Handling CLOSED event for " + regionInfo.getEncodedName());
94
95 if (this.assignmentManager.getTableStateManager().isTableState(this.regionInfo.getTable(),
96 ZooKeeperProtos.Table.State.DISABLED, ZooKeeperProtos.Table.State.DISABLING) ||
97 assignmentManager.getReplicasToClose().contains(regionInfo)) {
98 assignmentManager.offlineDisabledRegion(regionInfo);
99 return;
100 }
101
102 assignmentManager.getRegionStates().setRegionStateTOCLOSED(regionInfo, null);
103
104 assignmentManager.removeClosedRegion(regionInfo);
105 assignmentManager.assign(regionInfo, true);
106 }
107 }