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
20 package org.apache.hadoop.hbase.executor;
21
22 import org.apache.hadoop.hbase.classification.InterfaceAudience;
23
24 /**
25 * List of all HBase event handler types. Event types are named by a
26 * convention: event type names specify the component from which the event
27 * originated and then where its destined -- e.g. RS2ZK_ prefix means the
28 * event came from a regionserver destined for zookeeper -- and then what
29 * the even is; e.g. REGION_OPENING.
30 *
31 * <p>We give the enums indices so we can add types later and keep them
32 * grouped together rather than have to add them always to the end as we
33 * would have to if we used raw enum ordinals.
34 */
35 @InterfaceAudience.Private
36 public enum EventType {
37 // Messages originating from RS (NOTE: there is NO direct communication from
38 // RS to Master). These are a result of RS updates into ZK.
39 // RS_ZK_REGION_CLOSING (1), // It is replaced by M_ZK_REGION_CLOSING(HBASE-4739)
40
41 /**
42 * RS_ZK_REGION_CLOSED<br>
43 *
44 * RS has finished closing a region.
45 */
46 RS_ZK_REGION_CLOSED (2, ExecutorType.MASTER_CLOSE_REGION),
47 /**
48 * RS_ZK_REGION_OPENING<br>
49 *
50 * RS is in process of opening a region.
51 */
52 RS_ZK_REGION_OPENING (3, null),
53 /**
54 * RS_ZK_REGION_OPENED<br>
55 *
56 * RS has finished opening a region.
57 */
58 RS_ZK_REGION_OPENED (4, ExecutorType.MASTER_OPEN_REGION),
59 /**
60 * RS_ZK_REGION_SPLITTING<br>
61 *
62 * RS has started a region split after master says it's ok to move on.
63 */
64 RS_ZK_REGION_SPLITTING (5, null),
65 /**
66 * RS_ZK_REGION_SPLIT<br>
67 *
68 * RS split has completed and is notifying the master.
69 */
70 RS_ZK_REGION_SPLIT (6, ExecutorType.MASTER_SERVER_OPERATIONS),
71 /**
72 * RS_ZK_REGION_FAILED_OPEN<br>
73 *
74 * RS failed to open a region.
75 */
76 RS_ZK_REGION_FAILED_OPEN (7, ExecutorType.MASTER_CLOSE_REGION),
77 /**
78 * RS_ZK_REGION_MERGING<br>
79 *
80 * RS has started merging regions after master says it's ok to move on.
81 */
82 RS_ZK_REGION_MERGING (8, null),
83 /**
84 * RS_ZK_REGION_MERGE<br>
85 *
86 * RS region merge has completed and is notifying the master.
87 */
88 RS_ZK_REGION_MERGED (9, ExecutorType.MASTER_SERVER_OPERATIONS),
89 /**
90 * RS_ZK_REQUEST_REGION_SPLIT<br>
91 *
92 * RS has requested to split a region. This is to notify master
93 * and check with master if the region is in a state good to split.
94 */
95 RS_ZK_REQUEST_REGION_SPLIT (10, null),
96 /**
97 * RS_ZK_REQUEST_REGION_MERGE<br>
98 *
99 * RS has requested to merge two regions. This is to notify master
100 * and check with master if two regions is in states good to merge.
101 */
102 RS_ZK_REQUEST_REGION_MERGE (11, null),
103
104 /**
105 * Messages originating from Master to RS.<br>
106 * M_RS_OPEN_REGION<br>
107 * Master asking RS to open a region.
108 */
109 M_RS_OPEN_REGION (20, ExecutorType.RS_OPEN_REGION),
110 /**
111 * Messages originating from Master to RS.<br>
112 * M_RS_OPEN_ROOT<br>
113 * Master asking RS to open root.
114 */
115 M_RS_OPEN_ROOT (21, ExecutorType.RS_OPEN_ROOT),
116 /**
117 * Messages originating from Master to RS.<br>
118 * M_RS_OPEN_META<br>
119 * Master asking RS to open meta.
120 */
121 M_RS_OPEN_META (22, ExecutorType.RS_OPEN_META),
122 /**
123 * Messages originating from Master to RS.<br>
124 * M_RS_CLOSE_REGION<br>
125 * Master asking RS to close a region.
126 */
127 M_RS_CLOSE_REGION (23, ExecutorType.RS_CLOSE_REGION),
128 /**
129 * Messages originating from Master to RS.<br>
130 * M_RS_CLOSE_ROOT<br>
131 * Master asking RS to close root.
132 */
133 M_RS_CLOSE_ROOT (24, ExecutorType.RS_CLOSE_ROOT),
134 /**
135 * Messages originating from Master to RS.<br>
136 * M_RS_CLOSE_META<br>
137 * Master asking RS to close meta.
138 */
139 M_RS_CLOSE_META (25, ExecutorType.RS_CLOSE_META),
140 /**
141 * Messages originating from Master to RS.<br>
142 * M_RS_OPEN_PRIORITY_REGION<br>
143 * Master asking RS to open a priority region.
144 */
145 M_RS_OPEN_PRIORITY_REGION (26, ExecutorType.RS_OPEN_PRIORITY_REGION),
146
147 /**
148 * Messages originating from Client to Master.<br>
149 * C_M_MERGE_REGION<br>
150 * Client asking Master to merge regions.
151 */
152 C_M_MERGE_REGION (30, ExecutorType.MASTER_TABLE_OPERATIONS),
153 /**
154 * Messages originating from Client to Master.<br>
155 * C_M_DELETE_TABLE<br>
156 * Client asking Master to delete a table.
157 */
158 C_M_DELETE_TABLE (40, ExecutorType.MASTER_TABLE_OPERATIONS),
159 /**
160 * Messages originating from Client to Master.<br>
161 * C_M_DISABLE_TABLE<br>
162 * Client asking Master to disable a table.
163 */
164 C_M_DISABLE_TABLE (41, ExecutorType.MASTER_TABLE_OPERATIONS),
165 /**
166 * Messages originating from Client to Master.<br>
167 * C_M_ENABLE_TABLE<br>
168 * Client asking Master to enable a table.
169 */
170 C_M_ENABLE_TABLE (42, ExecutorType.MASTER_TABLE_OPERATIONS),
171 /**
172 * Messages originating from Client to Master.<br>
173 * C_M_MODIFY_TABLE<br>
174 * Client asking Master to modify a table.
175 */
176 C_M_MODIFY_TABLE (43, ExecutorType.MASTER_TABLE_OPERATIONS),
177 /**
178 * Messages originating from Client to Master.<br>
179 * C_M_ADD_FAMILY<br>
180 * Client asking Master to add family to table.
181 */
182 C_M_ADD_FAMILY (44, null),
183 /**
184 * Messages originating from Client to Master.<br>
185 * C_M_DELETE_FAMILY<br>
186 * Client asking Master to delete family of table.
187 */
188 C_M_DELETE_FAMILY (45, null),
189 /**
190 * Messages originating from Client to Master.<br>
191 * C_M_MODIFY_FAMILY<br>
192 * Client asking Master to modify family of table.
193 */
194 C_M_MODIFY_FAMILY (46, null),
195 /**
196 * Messages originating from Client to Master.<br>
197 * C_M_CREATE_TABLE<br>
198 * Client asking Master to create a table.
199 */
200 C_M_CREATE_TABLE (47, ExecutorType.MASTER_TABLE_OPERATIONS),
201 /**
202 * Messages originating from Client to Master.<br>
203 * C_M_SNAPSHOT_TABLE<br>
204 * Client asking Master to snapshot an offline table.
205 */
206 C_M_SNAPSHOT_TABLE (48, ExecutorType.MASTER_TABLE_OPERATIONS),
207 /**
208 * Messages originating from Client to Master.<br>
209 * C_M_RESTORE_SNAPSHOT<br>
210 * Client asking Master to restore a snapshot.
211 */
212 C_M_RESTORE_SNAPSHOT (49, ExecutorType.MASTER_TABLE_OPERATIONS),
213
214 // Updates from master to ZK. This is done by the master and there is
215 // nothing to process by either Master or RS
216 /**
217 * M_ZK_REGION_OFFLINE
218 * Master adds this region as offline in ZK
219 */
220 M_ZK_REGION_OFFLINE (50, null),
221 /**
222 * M_ZK_REGION_CLOSING
223 * Master adds this region as closing in ZK
224 */
225 M_ZK_REGION_CLOSING (51, null),
226
227 /**
228 * Master controlled events to be executed on the master
229 * M_SERVER_SHUTDOWN
230 * Master is processing shutdown of a RS
231 */
232 M_SERVER_SHUTDOWN (70, ExecutorType.MASTER_SERVER_OPERATIONS),
233 /**
234 * Master controlled events to be executed on the master.<br>
235 * M_META_SERVER_SHUTDOWN <br>
236 * Master is processing shutdown of RS hosting a meta region (-ROOT- or hbase:meta).
237 */
238 M_META_SERVER_SHUTDOWN (72, ExecutorType.MASTER_META_SERVER_OPERATIONS),
239 /**
240 * Master controlled events to be executed on the master.<br>
241 *
242 * M_MASTER_RECOVERY<br>
243 * Master is processing recovery of regions found in ZK RIT
244 */
245 M_MASTER_RECOVERY (73, ExecutorType.MASTER_SERVER_OPERATIONS),
246 /**
247 * Master controlled events to be executed on the master.<br>
248 *
249 * M_LOG_REPLAY<br>
250 * Master is processing log replay of failed region server
251 */
252 M_LOG_REPLAY (74, ExecutorType.M_LOG_REPLAY_OPS),
253
254 /**
255 * RS controlled events to be executed on the RS.<br>
256 *
257 * RS_PARALLEL_SEEK
258 */
259 RS_PARALLEL_SEEK (80, ExecutorType.RS_PARALLEL_SEEK),
260
261 /**
262 * RS wal recovery work items(either creating recover.edits or directly replay wals)
263 * to be executed on the RS.<br>
264 *
265 * RS_LOG_REPLAY
266 */
267 RS_LOG_REPLAY (81, ExecutorType.RS_LOG_REPLAY_OPS),
268
269 /**
270 * RS flush triggering from secondary region replicas to primary region replica. <br>
271 *
272 * RS_REGION_REPLICA_FLUSH
273 */
274 RS_REGION_REPLICA_FLUSH (82, ExecutorType.RS_REGION_REPLICA_FLUSH_OPS);
275
276 private final int code;
277 private final ExecutorType executor;
278
279 /**
280 * Constructor
281 */
282 EventType(final int code, final ExecutorType executor) {
283 this.code = code;
284 this.executor = executor;
285 }
286
287 public int getCode() {
288 return this.code;
289 }
290
291 public static EventType get(final int code) {
292 // Is this going to be slow? Its used rare but still...
293 for (EventType et: EventType.values()) {
294 if (et.getCode() == code) return et;
295 }
296 throw new IllegalArgumentException("Unknown code " + code);
297 }
298
299 public boolean isOnlineSchemaChangeSupported() {
300 return (
301 this.equals(EventType.C_M_ADD_FAMILY) ||
302 this.equals(EventType.C_M_DELETE_FAMILY) ||
303 this.equals(EventType.C_M_MODIFY_FAMILY) ||
304 this.equals(EventType.C_M_MODIFY_TABLE)
305 );
306 }
307
308 ExecutorType getExecutorServiceType() {
309 return this.executor;
310 }
311 }