1 /*
2 * Copyright 2011 The Apache Software Foundation
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
21 package org.apache.hadoop.hbase.coprocessor;
22
23 import org.apache.hadoop.hbase.*;
24
25 import java.io.IOException;
26
27 /**
28 * Defines coprocessor hooks for interacting with operations on the
29 * {@link org.apache.hadoop.hbase.master.HMaster} process.
30 */
31 public interface MasterObserver extends Coprocessor {
32
33 /**
34 * Called before a new table is created by
35 * {@link org.apache.hadoop.hbase.master.HMaster}.
36 * It can't bypass the default action, e.g., ctx.bypass() won't have effect.
37 * @param ctx the environment to interact with the framework and master
38 * @param desc the HTableDescriptor for the table
39 * @param regions the initial regions created for the table
40 * @throws IOException
41 */
42 void preCreateTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
43 HTableDescriptor desc, HRegionInfo[] regions) throws IOException;
44
45 /**
46 * Called after the createTable operation has been requested.
47 * @param ctx the environment to interact with the framework and master
48 * @param desc the HTableDescriptor for the table
49 * @param regions the initial regions created for the table
50 * @throws IOException
51 */
52 void postCreateTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
53 HTableDescriptor desc, HRegionInfo[] regions) throws IOException;
54
55 /**
56 * Called before {@link org.apache.hadoop.hbase.master.HMaster} deletes a
57 * table
58 * It can't bypass the default action, e.g., ctx.bypass() won't have effect.
59 * @param ctx the environment to interact with the framework and master
60 * @param tableName the name of the table
61 */
62 void preDeleteTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
63 byte[] tableName) throws IOException;
64
65 /**
66 * Called after the deleteTable operation has been requested.
67 * @param ctx the environment to interact with the framework and master
68 * @param tableName the name of the table
69 */
70 void postDeleteTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
71 byte[] tableName) throws IOException;
72
73 /**
74 * Called prior to modifying a table's properties.
75 * It can't bypass the default action, e.g., ctx.bypass() won't have effect.
76 * @param ctx the environment to interact with the framework and master
77 * @param tableName the name of the table
78 * @param htd the HTableDescriptor
79 */
80 void preModifyTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
81 final byte[] tableName, HTableDescriptor htd) throws IOException;
82
83 /**
84 * Called after the modifyTable operation has been requested.
85 * @param ctx the environment to interact with the framework and master
86 * @param tableName the name of the table
87 * @param htd the HTableDescriptor
88 */
89 void postModifyTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
90 final byte[] tableName, HTableDescriptor htd) throws IOException;
91
92 /**
93 * Called prior to adding a new column family to the table.
94 * @param ctx the environment to interact with the framework and master
95 * @param tableName the name of the table
96 * @param column the HColumnDescriptor
97 */
98 void preAddColumn(final ObserverContext<MasterCoprocessorEnvironment> ctx,
99 byte[] tableName, HColumnDescriptor column) throws IOException;
100
101 /**
102 * Called after the new column family has been created.
103 * @param ctx the environment to interact with the framework and master
104 * @param tableName the name of the table
105 * @param column the HColumnDescriptor
106 */
107 void postAddColumn(final ObserverContext<MasterCoprocessorEnvironment> ctx,
108 byte[] tableName, HColumnDescriptor column) throws IOException;
109
110 /**
111 * Called prior to modifying a column family's attributes.
112 * @param ctx the environment to interact with the framework and master
113 * @param tableName the name of the table
114 * @param descriptor the HColumnDescriptor
115 */
116 void preModifyColumn(final ObserverContext<MasterCoprocessorEnvironment> ctx,
117 byte [] tableName, HColumnDescriptor descriptor) throws IOException;
118
119 /**
120 * Called after the column family has been updated.
121 * @param ctx the environment to interact with the framework and master
122 * @param tableName the name of the table
123 * @param descriptor the HColumnDescriptor
124 */
125 void postModifyColumn(final ObserverContext<MasterCoprocessorEnvironment> ctx,
126 byte[] tableName, HColumnDescriptor descriptor) throws IOException;
127
128 /**
129 * Called prior to deleting the entire column family.
130 * @param ctx the environment to interact with the framework and master
131 * @param tableName the name of the table
132 * @param c the column
133 */
134 void preDeleteColumn(final ObserverContext<MasterCoprocessorEnvironment> ctx,
135 final byte [] tableName, final byte[] c) throws IOException;
136
137 /**
138 * Called after the column family has been deleted.
139 * @param ctx the environment to interact with the framework and master
140 * @param tableName the name of the table
141 * @param c the column
142 */
143 void postDeleteColumn(final ObserverContext<MasterCoprocessorEnvironment> ctx,
144 final byte [] tableName, final byte[] c) throws IOException;
145
146 /**
147 * Called prior to enabling a table.
148 * It can't bypass the default action, e.g., ctx.bypass() won't have effect.
149 * @param ctx the environment to interact with the framework and master
150 * @param tableName the name of the table
151 */
152 void preEnableTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
153 final byte[] tableName) throws IOException;
154
155 /**
156 * Called after the enableTable operation has been requested.
157 * @param ctx the environment to interact with the framework and master
158 * @param tableName the name of the table
159 */
160 void postEnableTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
161 final byte[] tableName) throws IOException;
162
163 /**
164 * Called prior to disabling a table.
165 * It can't bypass the default action, e.g., ctx.bypass() won't have effect.
166 * @param ctx the environment to interact with the framework and master
167 * @param tableName the name of the table
168 */
169 void preDisableTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
170 final byte[] tableName) throws IOException;
171
172 /**
173 * Called after the disableTable operation has been requested.
174 * @param ctx the environment to interact with the framework and master
175 * @param tableName the name of the table
176 */
177 void postDisableTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
178 final byte[] tableName) throws IOException;
179
180 /**
181 * Called prior to moving a given region from one region server to another.
182 * @param ctx the environment to interact with the framework and master
183 * @param region the HRegionInfo
184 * @param srcServer the source ServerName
185 * @param destServer the destination ServerName
186 */
187 void preMove(final ObserverContext<MasterCoprocessorEnvironment> ctx,
188 final HRegionInfo region, final ServerName srcServer,
189 final ServerName destServer)
190 throws IOException;
191
192 /**
193 * Called after the region move has been requested.
194 * @param ctx the environment to interact with the framework and master
195 * @param region the HRegionInfo
196 * @param srcServer the source ServerName
197 * @param destServer the destination ServerName
198 */
199 void postMove(final ObserverContext<MasterCoprocessorEnvironment> ctx,
200 final HRegionInfo region, final ServerName srcServer,
201 final ServerName destServer)
202 throws IOException;
203
204 /**
205 * Called prior to assigning a specific region.
206 * @param ctx the environment to interact with the framework and master
207 * @param regionInfo the regionInfo of the region
208 */
209 void preAssign(final ObserverContext<MasterCoprocessorEnvironment> ctx,
210 final HRegionInfo regionInfo) throws IOException;
211
212 /**
213 * Called after the region assignment has been requested.
214 * @param ctx the environment to interact with the framework and master
215 * @param regionInfo the regionInfo of the region
216 */
217 void postAssign(final ObserverContext<MasterCoprocessorEnvironment> ctx,
218 final HRegionInfo regionInfo) throws IOException;
219
220 /**
221 * Called prior to unassigning a given region.
222 * @param ctx the environment to interact with the framework and master
223 * @param regionInfo
224 * @param force whether to force unassignment or not
225 */
226 void preUnassign(final ObserverContext<MasterCoprocessorEnvironment> ctx,
227 final HRegionInfo regionInfo, final boolean force) throws IOException;
228
229 /**
230 * Called after the region unassignment has been requested.
231 * @param ctx the environment to interact with the framework and master
232 * @param regionInfo
233 * @param force whether to force unassignment or not
234 */
235 void postUnassign(final ObserverContext<MasterCoprocessorEnvironment> ctx,
236 final HRegionInfo regionInfo, final boolean force) throws IOException;
237
238 /**
239 * Called prior to requesting rebalancing of the cluster regions, though after
240 * the initial checks for regions in transition and the balance switch flag.
241 * @param ctx the environment to interact with the framework and master
242 */
243 void preBalance(final ObserverContext<MasterCoprocessorEnvironment> ctx)
244 throws IOException;
245
246 /**
247 * Called after the balancing plan has been submitted.
248 * @param ctx the environment to interact with the framework and master
249 */
250 void postBalance(final ObserverContext<MasterCoprocessorEnvironment> ctx)
251 throws IOException;
252
253 /**
254 * Called prior to modifying the flag used to enable/disable region balancing.
255 * @param ctx the coprocessor instance's environment
256 * @param newValue the new flag value submitted in the call
257 */
258 boolean preBalanceSwitch(final ObserverContext<MasterCoprocessorEnvironment> ctx,
259 final boolean newValue) throws IOException;
260
261 /**
262 * Called after the flag to enable/disable balancing has changed.
263 * @param ctx the coprocessor instance's environment
264 * @param oldValue the previously set balanceSwitch value
265 * @param newValue the newly set balanceSwitch value
266 */
267 void postBalanceSwitch(final ObserverContext<MasterCoprocessorEnvironment> ctx,
268 final boolean oldValue, final boolean newValue) throws IOException;
269
270 /**
271 * Called prior to shutting down the full HBase cluster, including this
272 * {@link org.apache.hadoop.hbase.master.HMaster} process.
273 */
274 void preShutdown(final ObserverContext<MasterCoprocessorEnvironment> ctx)
275 throws IOException;
276
277
278 /**
279 * Called immediately prior to stopping this
280 * {@link org.apache.hadoop.hbase.master.HMaster} process.
281 */
282 void preStopMaster(final ObserverContext<MasterCoprocessorEnvironment> ctx)
283 throws IOException;
284
285 /**
286 * Called immediately after an active master instance has completed
287 * initialization. Will not be called on standby master instances unless
288 * they take over the active role.
289 */
290 void postStartMaster(final ObserverContext<MasterCoprocessorEnvironment> ctx)
291 throws IOException;
292 }