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  
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   /**
142    * Messages originating from Client to Master.<br>
143    * C_M_MERGE_REGION<br>
144    * Client asking Master to merge regions.
145    */
146   C_M_MERGE_REGION          (30, ExecutorType.MASTER_TABLE_OPERATIONS),
147   /**
148    * Messages originating from Client to Master.<br>
149    * C_M_DELETE_TABLE<br>
150    * Client asking Master to delete a table.
151    */
152   C_M_DELETE_TABLE          (40, ExecutorType.MASTER_TABLE_OPERATIONS),
153   /**
154    * Messages originating from Client to Master.<br>
155    * C_M_DISABLE_TABLE<br>
156    * Client asking Master to disable a table.
157    */
158   C_M_DISABLE_TABLE         (41, ExecutorType.MASTER_TABLE_OPERATIONS),
159   /**
160    * Messages originating from Client to Master.<br>
161    * C_M_ENABLE_TABLE<br>
162    * Client asking Master to enable a table.
163    */
164   C_M_ENABLE_TABLE          (42, ExecutorType.MASTER_TABLE_OPERATIONS),
165   /**
166    * Messages originating from Client to Master.<br>
167    * C_M_MODIFY_TABLE<br>
168    * Client asking Master to modify a table.
169    */
170   C_M_MODIFY_TABLE          (43, ExecutorType.MASTER_TABLE_OPERATIONS),
171   /**
172    * Messages originating from Client to Master.<br>
173    * C_M_ADD_FAMILY<br>
174    * Client asking Master to add family to table.
175    */
176   C_M_ADD_FAMILY            (44, null),
177   /**
178    * Messages originating from Client to Master.<br>
179    * C_M_DELETE_FAMILY<br>
180    * Client asking Master to delete family of table.
181    */
182   C_M_DELETE_FAMILY         (45, null),
183   /**
184    * Messages originating from Client to Master.<br>
185    * C_M_MODIFY_FAMILY<br>
186    * Client asking Master to modify family of table.
187    */
188   C_M_MODIFY_FAMILY         (46, null),
189   /**
190    * Messages originating from Client to Master.<br>
191    * C_M_CREATE_TABLE<br>
192    * Client asking Master to create a table.
193    */
194   C_M_CREATE_TABLE          (47, ExecutorType.MASTER_TABLE_OPERATIONS),
195   /**
196    * Messages originating from Client to Master.<br>
197    * C_M_SNAPSHOT_TABLE<br>
198    * Client asking Master to snapshot an offline table.
199    */
200   C_M_SNAPSHOT_TABLE        (48, ExecutorType.MASTER_TABLE_OPERATIONS),
201   /**
202    * Messages originating from Client to Master.<br>
203    * C_M_RESTORE_SNAPSHOT<br>
204    * Client asking Master to restore a snapshot.
205    */
206   C_M_RESTORE_SNAPSHOT      (49, ExecutorType.MASTER_TABLE_OPERATIONS),
207 
208   // Updates from master to ZK. This is done by the master and there is
209   // nothing to process by either Master or RS
210   /**
211    * M_ZK_REGION_OFFLINE
212    * Master adds this region as offline in ZK
213    */
214   M_ZK_REGION_OFFLINE       (50, null),
215   /**
216    * M_ZK_REGION_CLOSING
217    * Master adds this region as closing in ZK
218    */
219   M_ZK_REGION_CLOSING       (51, null),
220 
221   /**
222    * Master controlled events to be executed on the master
223    * M_SERVER_SHUTDOWN
224    * Master is processing shutdown of a RS
225    */
226   M_SERVER_SHUTDOWN         (70, ExecutorType.MASTER_SERVER_OPERATIONS),
227   /**
228    * Master controlled events to be executed on the master.<br>
229    * M_META_SERVER_SHUTDOWN <br>
230    * Master is processing shutdown of RS hosting a meta region (-ROOT- or hbase:meta).
231    */
232   M_META_SERVER_SHUTDOWN    (72, ExecutorType.MASTER_META_SERVER_OPERATIONS),
233   /**
234    * Master controlled events to be executed on the master.<br>
235    *
236    * M_MASTER_RECOVERY<br>
237    * Master is processing recovery of regions found in ZK RIT
238    */
239   M_MASTER_RECOVERY         (73, ExecutorType.MASTER_SERVER_OPERATIONS),
240   /**
241    * Master controlled events to be executed on the master.<br>
242    *
243    * M_LOG_REPLAY<br>
244    * Master is processing log replay of failed region server
245    */
246   M_LOG_REPLAY              (74, ExecutorType.M_LOG_REPLAY_OPS),
247 
248   /**
249    * RS controlled events to be executed on the RS.<br>
250    *
251    * RS_PARALLEL_SEEK
252    */
253   RS_PARALLEL_SEEK          (80, ExecutorType.RS_PARALLEL_SEEK),
254 
255   /**
256    * RS wal recovery work items(either creating recover.edits or directly replay wals)
257    * to be executed on the RS.<br>
258    *
259    * RS_LOG_REPLAY
260    */
261   RS_LOG_REPLAY             (81, ExecutorType.RS_LOG_REPLAY_OPS),
262 
263   /**
264    * RS flush triggering from secondary region replicas to primary region replica. <br>
265    *
266    * RS_REGION_REPLICA_FLUSH
267    */
268   RS_REGION_REPLICA_FLUSH   (82, ExecutorType.RS_REGION_REPLICA_FLUSH_OPS);
269 
270   private final int code;
271   private final ExecutorType executor;
272 
273   /**
274    * Constructor
275    */
276   EventType(final int code, final ExecutorType executor) {
277     this.code = code;
278     this.executor = executor;
279   }
280 
281   public int getCode() {
282     return this.code;
283   }
284 
285   public static EventType get(final int code) {
286     // Is this going to be slow?  Its used rare but still...
287     for (EventType et: EventType.values()) {
288       if (et.getCode() == code) return et;
289     }
290     throw new IllegalArgumentException("Unknown code " + code);
291   }
292 
293   public boolean isOnlineSchemaChangeSupported() {
294     return (
295       this.equals(EventType.C_M_ADD_FAMILY) ||
296       this.equals(EventType.C_M_DELETE_FAMILY) ||
297       this.equals(EventType.C_M_MODIFY_FAMILY) ||
298       this.equals(EventType.C_M_MODIFY_TABLE)
299     );
300   }
301 
302   ExecutorType getExecutorServiceType() {
303     return this.executor;
304   }
305 }