001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.executor;
019
020import org.apache.yetus.audience.InterfaceAudience;
021
022/**
023 * List of all HBase event handler types.
024 * <p>
025 * Event types are named by a convention: event type names specify the component from which the
026 * event originated and then where its destined -- e.g. RS_ZK_ prefix means the event came from a
027 * regionserver destined for zookeeper -- and then what the even is; e.g. REGION_OPENING.
028 * <p>
029 * We give the enums indices so we can add types later and keep them grouped together rather than
030 * have to add them always to the end as we would have to if we used raw enum ordinals.
031 */
032@InterfaceAudience.Private
033public enum EventType {
034  // Messages originating from RS (NOTE: there is NO direct communication from
035  // RS to Master). These are a result of RS updates into ZK.
036  // RS_ZK_REGION_CLOSING (1), // It is replaced by M_ZK_REGION_CLOSING(HBASE-4739)
037
038  /**
039   * RS_ZK_REGION_CLOSED<br>
040   * RS has finished closing a region.
041   */
042  RS_ZK_REGION_CLOSED(2, ExecutorType.MASTER_CLOSE_REGION),
043  /**
044   * RS_ZK_REGION_OPENING<br>
045   * RS is in process of opening a region.
046   */
047  RS_ZK_REGION_OPENING(3, null),
048  /**
049   * RS_ZK_REGION_OPENED<br>
050   * RS has finished opening a region.
051   */
052  RS_ZK_REGION_OPENED(4, ExecutorType.MASTER_OPEN_REGION),
053  /**
054   * RS_ZK_REGION_SPLITTING<br>
055   * RS has started a region split after master says it's ok to move on.
056   */
057  RS_ZK_REGION_SPLITTING(5, null),
058  /**
059   * RS_ZK_REGION_SPLIT<br>
060   * RS split has completed and is notifying the master.
061   */
062  RS_ZK_REGION_SPLIT(6, ExecutorType.MASTER_SERVER_OPERATIONS),
063  /**
064   * RS_ZK_REGION_FAILED_OPEN<br>
065   * RS failed to open a region.
066   */
067  RS_ZK_REGION_FAILED_OPEN(7, ExecutorType.MASTER_CLOSE_REGION),
068  /**
069   * RS_ZK_REGION_MERGING<br>
070   * RS has started merging regions after master says it's ok to move on.
071   */
072  RS_ZK_REGION_MERGING(8, null),
073  /**
074   * RS_ZK_REGION_MERGE<br>
075   * RS region merge has completed and is notifying the master.
076   */
077  RS_ZK_REGION_MERGED(9, ExecutorType.MASTER_SERVER_OPERATIONS),
078  /**
079   * RS_ZK_REQUEST_REGION_SPLIT<br>
080   * RS has requested to split a region. This is to notify master and check with master if the
081   * region is in a state good to split.
082   */
083  RS_ZK_REQUEST_REGION_SPLIT(10, null),
084  /**
085   * RS_ZK_REQUEST_REGION_MERGE<br>
086   * RS has requested to merge two regions. This is to notify master and check with master if two
087   * regions is in states good to merge.
088   */
089  RS_ZK_REQUEST_REGION_MERGE(11, null),
090
091  /**
092   * Messages originating from Master to RS.<br>
093   * M_RS_OPEN_REGION<br>
094   * Master asking RS to open a region.
095   */
096  M_RS_OPEN_REGION(20, ExecutorType.RS_OPEN_REGION),
097  /**
098   * Messages originating from Master to RS.<br>
099   * M_RS_OPEN_ROOT<br>
100   * Master asking RS to open root.
101   */
102  M_RS_OPEN_ROOT(21, ExecutorType.RS_OPEN_ROOT),
103  /**
104   * Messages originating from Master to RS.<br>
105   * M_RS_OPEN_META<br>
106   * Master asking RS to open meta.
107   */
108  M_RS_OPEN_META(22, ExecutorType.RS_OPEN_META),
109  /**
110   * Messages originating from Master to RS.<br>
111   * M_RS_CLOSE_REGION<br>
112   * Master asking RS to close a region.
113   */
114  M_RS_CLOSE_REGION(23, ExecutorType.RS_CLOSE_REGION),
115  /**
116   * Messages originating from Master to RS.<br>
117   * M_RS_CLOSE_ROOT<br>
118   * Master asking RS to close root.
119   */
120  M_RS_CLOSE_ROOT(24, ExecutorType.RS_CLOSE_ROOT),
121  /**
122   * Messages originating from Master to RS.<br>
123   * M_RS_CLOSE_META<br>
124   * Master asking RS to close meta.
125   */
126  M_RS_CLOSE_META(25, ExecutorType.RS_CLOSE_META),
127  /**
128   * Messages originating from Master to RS.<br>
129   * M_RS_OPEN_PRIORITY_REGION<br>
130   * Master asking RS to open a priority region.
131   */
132  M_RS_OPEN_PRIORITY_REGION(26, ExecutorType.RS_OPEN_PRIORITY_REGION),
133  /**
134   * Messages originating from Master to RS.<br>
135   * M_RS_SWITCH_RPC_THROTTLE<br>
136   * Master asking RS to switch rpc throttle state.
137   */
138  M_RS_SWITCH_RPC_THROTTLE(27, ExecutorType.RS_SWITCH_RPC_THROTTLE),
139
140  /**
141   * Messages originating from Client to Master.<br>
142   * C_M_MERGE_REGION<br>
143   * Client asking Master to merge regions.
144   */
145  C_M_MERGE_REGION(30, ExecutorType.MASTER_MERGE_OPERATIONS),
146  /**
147   * Messages originating from Client to Master.<br>
148   * C_M_DELETE_TABLE<br>
149   * Client asking Master to delete a table.
150   */
151  C_M_DELETE_TABLE(40, ExecutorType.MASTER_TABLE_OPERATIONS),
152  /**
153   * Messages originating from Client to Master.<br>
154   * C_M_DISABLE_TABLE<br>
155   * Client asking Master to disable a table.
156   */
157  C_M_DISABLE_TABLE(41, ExecutorType.MASTER_TABLE_OPERATIONS),
158  /**
159   * Messages originating from Client to Master.<br>
160   * C_M_ENABLE_TABLE<br>
161   * Client asking Master to enable a table.
162   */
163  C_M_ENABLE_TABLE(42, ExecutorType.MASTER_TABLE_OPERATIONS),
164  /**
165   * Messages originating from Client to Master.<br>
166   * C_M_MODIFY_TABLE<br>
167   * Client asking Master to modify a table.
168   */
169  C_M_MODIFY_TABLE(43, ExecutorType.MASTER_TABLE_OPERATIONS),
170  /**
171   * Messages originating from Client to Master.<br>
172   * C_M_ADD_FAMILY<br>
173   * Client asking Master to add family to table.
174   */
175  C_M_ADD_FAMILY(44, null),
176  /**
177   * Messages originating from Client to Master.<br>
178   * C_M_DELETE_FAMILY<br>
179   * Client asking Master to delete family of table.
180   */
181  C_M_DELETE_FAMILY(45, null),
182  /**
183   * Messages originating from Client to Master.<br>
184   * C_M_MODIFY_FAMILY<br>
185   * Client asking Master to modify family of table.
186   */
187  C_M_MODIFY_FAMILY(46, null),
188  /**
189   * Messages originating from Client to Master.<br>
190   * C_M_CREATE_TABLE<br>
191   * Client asking Master to create a table.
192   */
193  C_M_CREATE_TABLE(47, ExecutorType.MASTER_TABLE_OPERATIONS),
194  /**
195   * Messages originating from Client to Master.<br>
196   * C_M_SNAPSHOT_TABLE<br>
197   * Client asking Master to snapshot an offline table.
198   */
199  C_M_SNAPSHOT_TABLE(48, ExecutorType.MASTER_SNAPSHOT_OPERATIONS),
200  /**
201   * Messages originating from Client to Master.<br>
202   * C_M_RESTORE_SNAPSHOT<br>
203   * Client asking Master to restore a snapshot.
204   */
205  C_M_RESTORE_SNAPSHOT(49, ExecutorType.MASTER_SNAPSHOT_OPERATIONS),
206
207  // Updates from master to ZK. This is done by the master and there is
208  // nothing to process by either Master or RS
209  /**
210   * M_ZK_REGION_OFFLINE Master adds this region as offline in ZK
211   */
212  M_ZK_REGION_OFFLINE(50, null),
213  /**
214   * M_ZK_REGION_CLOSING Master adds this region as closing in ZK
215   */
216  M_ZK_REGION_CLOSING(51, null),
217
218  /**
219   * Master controlled events to be executed on the master M_SERVER_SHUTDOWN Master is processing
220   * shutdown of a RS
221   */
222  M_SERVER_SHUTDOWN(70, ExecutorType.MASTER_SERVER_OPERATIONS),
223  /**
224   * Master controlled events to be executed on the master.<br>
225   * M_META_SERVER_SHUTDOWN <br>
226   * Master is processing shutdown of RS hosting a meta region (-ROOT- or hbase:meta).
227   */
228  M_META_SERVER_SHUTDOWN(72, ExecutorType.MASTER_META_SERVER_OPERATIONS),
229  /**
230   * Master controlled events to be executed on the master.<br>
231   * M_MASTER_RECOVERY<br>
232   * Master is processing recovery of regions found in ZK RIT
233   */
234  M_MASTER_RECOVERY(73, ExecutorType.MASTER_SERVER_OPERATIONS),
235  /**
236   * Master controlled events to be executed on the master.<br>
237   * M_LOG_REPLAY<br>
238   * Master is processing log replay of failed region server
239   */
240  M_LOG_REPLAY(74, ExecutorType.M_LOG_REPLAY_OPS),
241
242  /**
243   * RS controlled events to be executed on the RS.<br>
244   * RS_PARALLEL_SEEK
245   */
246  RS_PARALLEL_SEEK(80, ExecutorType.RS_PARALLEL_SEEK),
247
248  /**
249   * RS wal recovery work items (splitting wals) to be executed on the RS.<br>
250   * RS_LOG_REPLAY
251   */
252  RS_LOG_REPLAY(81, ExecutorType.RS_LOG_REPLAY_OPS),
253
254  /**
255   * RS flush triggering from secondary region replicas to primary region replica. <br>
256   * RS_REGION_REPLICA_FLUSH
257   */
258  RS_REGION_REPLICA_FLUSH(82, ExecutorType.RS_REGION_REPLICA_FLUSH_OPS),
259
260  /**
261   * RS compacted files discharger <br>
262   * RS_COMPACTED_FILES_DISCHARGER
263   */
264  RS_COMPACTED_FILES_DISCHARGER(83, ExecutorType.RS_COMPACTED_FILES_DISCHARGER),
265
266  /**
267   * RS refresh peer.<br>
268   * RS_REFRESH_PEER
269   */
270  RS_REFRESH_PEER(84, ExecutorType.RS_REFRESH_PEER),
271
272  /**
273   * RS replay sync replication wal.<br>
274   * RS_REPLAY_SYNC_REPLICATION_WAL
275   */
276  RS_REPLAY_SYNC_REPLICATION_WAL(85, ExecutorType.RS_REPLAY_SYNC_REPLICATION_WAL),
277
278  /**
279   * RS claim replication queue.<br>
280   * RS_CLAIM_REPLICATION_QUEUE
281   */
282  RS_CLAIM_REPLICATION_QUEUE(86, ExecutorType.RS_CLAIM_REPLICATION_QUEUE),
283
284  /**
285   * RS snapshot regions.<br>
286   * RS_SNAPSHOT_REGIONS
287   */
288  RS_SNAPSHOT_REGIONS(87, ExecutorType.RS_SNAPSHOT_OPERATIONS),
289
290  /**
291   * RS verify snapshot.<br>
292   * RS_VERIFY_SNAPSHOT
293   */
294  RS_VERIFY_SNAPSHOT(88, ExecutorType.RS_SNAPSHOT_OPERATIONS),
295
296  /**
297   * RS flush regions.<br>
298   * RS_FLUSH_OPERATIONS
299   */
300  RS_FLUSH_REGIONS(89, ExecutorType.RS_FLUSH_OPERATIONS);
301
302  private final int code;
303  private final ExecutorType executor;
304
305  /**
306   * Constructor
307   */
308  EventType(final int code, final ExecutorType executor) {
309    this.code = code;
310    this.executor = executor;
311  }
312
313  public int getCode() {
314    return this.code;
315  }
316
317  public static EventType get(final int code) {
318    // Is this going to be slow? Its used rare but still...
319    for (EventType et : EventType.values()) {
320      if (et.getCode() == code) {
321        return et;
322      }
323    }
324    throw new IllegalArgumentException("Unknown code " + code);
325  }
326
327  ExecutorType getExecutorServiceType() {
328    return this.executor;
329  }
330}