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.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.
63     */
64    RS_ZK_REGION_SPLITTING    (5, null),
65    /**
66     * RS_ZK_REGION_SPLIT<br>
67     * 
68     * RS split has completed.
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.
81     */
82    RS_ZK_REGION_MERGING      (8, null),
83    /**
84     * RS_ZK_REGION_MERGE<br>
85     * 
86     * RS region merge has completed.
87     */
88    RS_ZK_REGION_MERGED       (9, ExecutorType.MASTER_SERVER_OPERATIONS),
89  
90    /**
91     * Messages originating from Master to RS.<br>
92     * M_RS_OPEN_REGION<br>
93     * Master asking RS to open a region.
94     */
95    M_RS_OPEN_REGION          (20, ExecutorType.RS_OPEN_REGION),
96    /**
97     * Messages originating from Master to RS.<br>
98     * M_RS_OPEN_ROOT<br>
99     * Master asking RS to open root.
100    */
101   M_RS_OPEN_ROOT            (21, ExecutorType.RS_OPEN_ROOT),
102   /**
103    * Messages originating from Master to RS.<br>
104    * M_RS_OPEN_META<br>
105    * Master asking RS to open meta.
106    */
107   M_RS_OPEN_META            (22, ExecutorType.RS_OPEN_META),
108   /**
109    * Messages originating from Master to RS.<br>
110    * M_RS_CLOSE_REGION<br>
111    * Master asking RS to close a region.
112    */
113   M_RS_CLOSE_REGION         (23, ExecutorType.RS_CLOSE_REGION),
114   /**
115    * Messages originating from Master to RS.<br>
116    * M_RS_CLOSE_ROOT<br>
117    * Master asking RS to close root.
118    */
119   M_RS_CLOSE_ROOT           (24, ExecutorType.RS_CLOSE_ROOT),
120   /**
121    * Messages originating from Master to RS.<br>
122    * M_RS_CLOSE_META<br>
123    * Master asking RS to close meta.
124    */
125   M_RS_CLOSE_META           (25, ExecutorType.RS_CLOSE_META),
126 
127   /**
128    * Messages originating from Client to Master.<br>
129    * C_M_MERGE_REGION<br>
130    * Client asking Master to merge regions.
131    */
132   C_M_MERGE_REGION          (30, ExecutorType.MASTER_TABLE_OPERATIONS),
133   /**
134    * Messages originating from Client to Master.<br>
135    * C_M_DELETE_TABLE<br>
136    * Client asking Master to delete a table.
137    */
138   C_M_DELETE_TABLE          (40, ExecutorType.MASTER_TABLE_OPERATIONS),
139   /**
140    * Messages originating from Client to Master.<br>
141    * C_M_DISABLE_TABLE<br>
142    * Client asking Master to disable a table.
143    */
144   C_M_DISABLE_TABLE         (41, ExecutorType.MASTER_TABLE_OPERATIONS),
145   /**
146    * Messages originating from Client to Master.<br>
147    * C_M_ENABLE_TABLE<br>
148    * Client asking Master to enable a table.
149    */
150   C_M_ENABLE_TABLE          (42, ExecutorType.MASTER_TABLE_OPERATIONS),
151   /**
152    * Messages originating from Client to Master.<br>
153    * C_M_MODIFY_TABLE<br>
154    * Client asking Master to modify a table.
155    */
156   C_M_MODIFY_TABLE          (43, ExecutorType.MASTER_TABLE_OPERATIONS),
157   /**
158    * Messages originating from Client to Master.<br>
159    * C_M_ADD_FAMILY<br>
160    * Client asking Master to add family to table.
161    */
162   C_M_ADD_FAMILY            (44, null),
163   /**
164    * Messages originating from Client to Master.<br>
165    * C_M_DELETE_FAMILY<br>
166    * Client asking Master to delete family of table.
167    */
168   C_M_DELETE_FAMILY         (45, null),
169   /**
170    * Messages originating from Client to Master.<br>
171    * C_M_MODIFY_FAMILY<br>
172    * Client asking Master to modify family of table.
173    */
174   C_M_MODIFY_FAMILY         (46, null),
175   /**
176    * Messages originating from Client to Master.<br>
177    * C_M_CREATE_TABLE<br>
178    * Client asking Master to create a table.
179    */
180   C_M_CREATE_TABLE          (47, ExecutorType.MASTER_TABLE_OPERATIONS),
181   /**
182    * Messages originating from Client to Master.<br>
183    * C_M_SNAPSHOT_TABLE<br>
184    * Client asking Master to snapshot an offline table.
185    */
186   C_M_SNAPSHOT_TABLE        (48, ExecutorType.MASTER_TABLE_OPERATIONS),
187   /**
188    * Messages originating from Client to Master.<br>
189    * C_M_RESTORE_SNAPSHOT<br>
190    * Client asking Master to restore a snapshot.
191    */
192   C_M_RESTORE_SNAPSHOT      (49, ExecutorType.MASTER_TABLE_OPERATIONS),
193 
194   // Updates from master to ZK. This is done by the master and there is
195   // nothing to process by either Master or RS
196   /**
197    * M_ZK_REGION_OFFLINE
198    * Master adds this region as offline in ZK
199    */
200   M_ZK_REGION_OFFLINE       (50, null),
201   /**
202    * M_ZK_REGION_CLOSING
203    * Master adds this region as closing in ZK
204    */
205   M_ZK_REGION_CLOSING       (51, null),
206   
207   /**
208    * Master controlled events to be executed on the master
209    * M_SERVER_SHUTDOWN
210    * Master is processing shutdown of a RS
211    */
212   M_SERVER_SHUTDOWN         (70, ExecutorType.MASTER_SERVER_OPERATIONS),
213   /**
214    * Master controlled events to be executed on the master.<br>
215    * M_META_SERVER_SHUTDOWN <br>
216    * Master is processing shutdown of RS hosting a meta region (-ROOT- or .META.).
217    */
218   M_META_SERVER_SHUTDOWN    (72, ExecutorType.MASTER_META_SERVER_OPERATIONS),
219   /**
220    * Master controlled events to be executed on the master.<br>
221    * 
222    * M_MASTER_RECOVERY<br>
223    * Master is processing recovery of regions found in ZK RIT
224    */
225   M_MASTER_RECOVERY         (73, ExecutorType.MASTER_SERVER_OPERATIONS),
226   /**
227    * Master controlled events to be executed on the master.<br>
228    * 
229    * M_LOG_REPLAY<br>
230    * Master is processing log replay of failed region server
231    */
232   M_LOG_REPLAY              (74, ExecutorType.M_LOG_REPLAY_OPS),
233 
234   /**
235    * RS controlled events to be executed on the RS.<br>
236    * 
237    * RS_PARALLEL_SEEK
238    */
239   RS_PARALLEL_SEEK          (80, ExecutorType.RS_PARALLEL_SEEK);
240 
241   private final int code;
242   private final ExecutorType executor;
243 
244   /**
245    * Constructor
246    */
247   EventType(final int code, final ExecutorType executor) {
248     this.code = code;
249     this.executor = executor;
250   }
251 
252   public int getCode() {
253     return this.code;
254   }
255 
256   public static EventType get(final int code) {
257     // Is this going to be slow?  Its used rare but still...
258     for (EventType et: EventType.values()) {
259       if (et.getCode() == code) return et;
260     }
261     throw new IllegalArgumentException("Unknown code " + code);
262   }
263 
264   public boolean isOnlineSchemaChangeSupported() {
265     return (
266       this.equals(EventType.C_M_ADD_FAMILY) ||
267       this.equals(EventType.C_M_DELETE_FAMILY) ||
268       this.equals(EventType.C_M_MODIFY_FAMILY) ||
269       this.equals(EventType.C_M_MODIFY_TABLE)
270     );
271   }
272 
273   ExecutorType getExecutorServiceType() {
274     return this.executor;
275   }
276 }