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 RS_ZK_REGION_CLOSED (2, ExecutorType.MASTER_CLOSE_REGION), // RS has finished closing a region
41 RS_ZK_REGION_OPENING (3, null), // RS is in process of opening a region
42 RS_ZK_REGION_OPENED (4, ExecutorType.MASTER_OPEN_REGION), // RS has finished opening a region
43 RS_ZK_REGION_SPLITTING (5, null), // RS has started a region split
44 RS_ZK_REGION_SPLIT (6, ExecutorType.MASTER_SERVER_OPERATIONS), // RS split has completed.
45 RS_ZK_REGION_FAILED_OPEN (7, ExecutorType.MASTER_CLOSE_REGION), // RS failed to open a region
46 RS_ZK_REGION_MERGING (8, null), // RS has started merging regions
47 RS_ZK_REGION_MERGE (9, ExecutorType.MASTER_SERVER_OPERATIONS), // RS region merge has completed.
48
49 // Messages originating from Master to RS
50 M_RS_OPEN_REGION (20, ExecutorType.RS_OPEN_REGION), // Master asking RS to open a region
51 M_RS_OPEN_ROOT (21, ExecutorType.RS_OPEN_ROOT), // Master asking RS to open root
52 M_RS_OPEN_META (22, ExecutorType.RS_OPEN_META), // Master asking RS to open meta
53 M_RS_CLOSE_REGION (23, ExecutorType.RS_CLOSE_REGION), // Master asking RS to close a region
54 M_RS_CLOSE_ROOT (24, ExecutorType.RS_CLOSE_ROOT), // Master asking RS to close root
55 M_RS_CLOSE_META (25, ExecutorType.RS_CLOSE_META), // Master asking RS to close meta
56
57 // Messages originating from Client to Master
58 C_M_MERGE_REGION (30, ExecutorType.MASTER_TABLE_OPERATIONS), // Client asking Master to merge regions
59 C_M_DELETE_TABLE (40, ExecutorType.MASTER_TABLE_OPERATIONS), // Client asking Master to delete a table
60 C_M_DISABLE_TABLE (41, ExecutorType.MASTER_TABLE_OPERATIONS), // Client asking Master to disable a table
61 C_M_ENABLE_TABLE (42, ExecutorType.MASTER_TABLE_OPERATIONS), // Client asking Master to enable a table
62 C_M_MODIFY_TABLE (43, ExecutorType.MASTER_TABLE_OPERATIONS), // Client asking Master to modify a table
63 C_M_ADD_FAMILY (44, null), // Client asking Master to add family to table
64 C_M_DELETE_FAMILY (45, null), // Client asking Master to delete family of table
65 C_M_MODIFY_FAMILY (46, null), // Client asking Master to modify family of table
66 C_M_CREATE_TABLE (47, ExecutorType.MASTER_TABLE_OPERATIONS), // Client asking Master to create a table
67 C_M_SNAPSHOT_TABLE (48, ExecutorType.MASTER_TABLE_OPERATIONS), // Client asking Master to snapshot an offline table
68 C_M_RESTORE_SNAPSHOT (49, ExecutorType.MASTER_TABLE_OPERATIONS), // Client asking Master to restore a snapshot
69
70 // Updates from master to ZK. This is done by the master and there is
71 // nothing to process by either Master or RS
72 M_ZK_REGION_OFFLINE (50, null), // Master adds this region as offline in ZK
73 M_ZK_REGION_CLOSING (51, null), // Master adds this region as closing in ZK
74
75 // Master controlled events to be executed on the master
76 M_SERVER_SHUTDOWN (70, ExecutorType.MASTER_SERVER_OPERATIONS), // Master is processing shutdown of a RS
77 M_META_SERVER_SHUTDOWN (72, ExecutorType.MASTER_META_SERVER_OPERATIONS), // Master is processing shutdown of RS hosting a meta region (-ROOT- or .META.).
78 M_MASTER_RECOVERY (73, ExecutorType.MASTER_SERVER_OPERATIONS), // Master is processing recovery of regions found in ZK RIT
79
80 // RS controlled events to be executed on the RS
81 RS_PARALLEL_SEEK (80, ExecutorType.RS_PARALLEL_SEEK);
82
83 private final int code;
84 private final ExecutorType executor;
85
86 /**
87 * Constructor
88 */
89 EventType(final int code, final ExecutorType executor) {
90 this.code = code;
91 this.executor = executor;
92 }
93
94 public int getCode() {
95 return this.code;
96 }
97
98 public static EventType get(final int code) {
99 // Is this going to be slow? Its used rare but still...
100 for (EventType et: EventType.values()) {
101 if (et.getCode() == code) return et;
102 }
103 throw new IllegalArgumentException("Unknown code " + code);
104 }
105
106 public boolean isOnlineSchemaChangeSupported() {
107 return (
108 this.equals(EventType.C_M_ADD_FAMILY) ||
109 this.equals(EventType.C_M_DELETE_FAMILY) ||
110 this.equals(EventType.C_M_MODIFY_FAMILY) ||
111 this.equals(EventType.C_M_MODIFY_TABLE)
112 );
113 }
114
115 ExecutorType getExecutorServiceType() {
116 return this.executor;
117 }
118 }