View Javadoc

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  import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription;
25  
26  import java.io.IOException;
27  
28  /**
29   * Defines coprocessor hooks for interacting with operations on the
30   * {@link org.apache.hadoop.hbase.master.HMaster} process.
31   */
32  public interface MasterObserver extends Coprocessor {
33  
34    /**
35     * Called before a new table is created by
36     * {@link org.apache.hadoop.hbase.master.HMaster}.
37     * It can't bypass the default action, e.g., ctx.bypass() won't have effect.
38     * @param ctx the environment to interact with the framework and master
39     * @param desc the HTableDescriptor for the table
40     * @param regions the initial regions created for the table
41     * @throws IOException
42     */
43    void preCreateTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
44        HTableDescriptor desc, HRegionInfo[] regions) throws IOException;
45  
46    /**
47     * Called after the createTable operation has been requested.
48     * @param ctx the environment to interact with the framework and master
49     * @param desc the HTableDescriptor for the table
50     * @param regions the initial regions created for the table
51     * @throws IOException
52     */
53    void postCreateTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
54        HTableDescriptor desc, HRegionInfo[] regions) throws IOException;
55  
56    /**
57     * Called before {@link org.apache.hadoop.hbase.master.HMaster} deletes a
58     * table
59     * It can't bypass the default action, e.g., ctx.bypass() won't have effect.
60     * @param ctx the environment to interact with the framework and master
61     * @param tableName the name of the table
62     */
63    void preDeleteTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
64        byte[] tableName) throws IOException;
65  
66    /**
67     * Called after the deleteTable operation has been requested.
68     * @param ctx the environment to interact with the framework and master
69     * @param tableName the name of the table
70     */
71    void postDeleteTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
72        byte[] tableName) throws IOException;
73  
74    /**
75     * Called prior to modifying a table's properties.
76     * It can't bypass the default action, e.g., ctx.bypass() won't have effect.
77     * @param ctx the environment to interact with the framework and master
78     * @param tableName the name of the table
79     * @param htd the HTableDescriptor
80     */
81    void preModifyTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
82        final byte[] tableName, HTableDescriptor htd) throws IOException;
83  
84    /**
85     * Called after the modifyTable operation has been requested.
86     * @param ctx the environment to interact with the framework and master
87     * @param tableName the name of the table
88     * @param htd the HTableDescriptor
89     */
90    void postModifyTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
91        final byte[] tableName, HTableDescriptor htd) throws IOException;
92  
93    /**
94     * Called prior to adding a new column family to the table.
95     * @param ctx the environment to interact with the framework and master
96     * @param tableName the name of the table
97     * @param column the HColumnDescriptor
98     */
99    void preAddColumn(final ObserverContext<MasterCoprocessorEnvironment> ctx,
100       byte[] tableName, HColumnDescriptor column) throws IOException;
101 
102   /**
103    * Called after the new column family has been created.
104    * @param ctx the environment to interact with the framework and master
105    * @param tableName the name of the table
106    * @param column the HColumnDescriptor
107    */
108   void postAddColumn(final ObserverContext<MasterCoprocessorEnvironment> ctx,
109       byte[] tableName, HColumnDescriptor column) throws IOException;
110 
111   /**
112    * Called prior to modifying a column family's attributes.
113    * @param ctx the environment to interact with the framework and master
114    * @param tableName the name of the table
115    * @param descriptor the HColumnDescriptor
116    */
117   void preModifyColumn(final ObserverContext<MasterCoprocessorEnvironment> ctx,
118       byte [] tableName, HColumnDescriptor descriptor) throws IOException;
119 
120   /**
121    * Called after the column family has been updated.
122    * @param ctx the environment to interact with the framework and master
123    * @param tableName the name of the table
124    * @param descriptor the HColumnDescriptor
125    */
126   void postModifyColumn(final ObserverContext<MasterCoprocessorEnvironment> ctx,
127       byte[] tableName, HColumnDescriptor descriptor) throws IOException;
128 
129   /**
130    * Called prior to deleting the entire column family.
131    * @param ctx the environment to interact with the framework and master
132    * @param tableName the name of the table
133    * @param c the column
134    */
135   void preDeleteColumn(final ObserverContext<MasterCoprocessorEnvironment> ctx,
136       final byte [] tableName, final byte[] c) throws IOException;
137 
138   /**
139    * Called after the column family has been deleted.
140    * @param ctx the environment to interact with the framework and master
141    * @param tableName the name of the table
142    * @param c the column
143    */
144   void postDeleteColumn(final ObserverContext<MasterCoprocessorEnvironment> ctx,
145       final byte [] tableName, final byte[] c) throws IOException;
146 
147   /**
148    * Called prior to enabling a table.
149    * It can't bypass the default action, e.g., ctx.bypass() won't have effect.
150    * @param ctx the environment to interact with the framework and master
151    * @param tableName the name of the table
152    */
153   void preEnableTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
154       final byte[] tableName) throws IOException;
155 
156   /**
157    * Called after the enableTable operation has been requested.
158    * @param ctx the environment to interact with the framework and master
159    * @param tableName the name of the table
160    */
161   void postEnableTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
162       final byte[] tableName) throws IOException;
163 
164   /**
165    * Called prior to disabling a table.
166    * It can't bypass the default action, e.g., ctx.bypass() won't have effect.
167    * @param ctx the environment to interact with the framework and master
168    * @param tableName the name of the table
169    */
170   void preDisableTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
171       final byte[] tableName) throws IOException;
172 
173   /**
174    * Called after the disableTable operation has been requested.
175    * @param ctx the environment to interact with the framework and master
176    * @param tableName the name of the table
177    */
178   void postDisableTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
179       final byte[] tableName) throws IOException;
180 
181   /**
182    * Called prior to moving a given region from one region server to another.
183    * @param ctx the environment to interact with the framework and master
184    * @param region the HRegionInfo
185    * @param srcServer the source ServerName
186    * @param destServer the destination ServerName
187    */
188   void preMove(final ObserverContext<MasterCoprocessorEnvironment> ctx,
189       final HRegionInfo region, final ServerName srcServer,
190       final ServerName destServer)
191     throws IOException;
192 
193   /**
194    * Called after the region move has been requested.
195    * @param ctx the environment to interact with the framework and master
196    * @param region the HRegionInfo
197    * @param srcServer the source ServerName
198    * @param destServer the destination ServerName
199    */
200   void postMove(final ObserverContext<MasterCoprocessorEnvironment> ctx,
201       final HRegionInfo region, final ServerName srcServer,
202       final ServerName destServer)
203     throws IOException;
204 
205   /**
206    * Called prior to assigning a specific region.
207    * @param ctx the environment to interact with the framework and master
208    * @param regionInfo the regionInfo of the region
209    */
210   void preAssign(final ObserverContext<MasterCoprocessorEnvironment> ctx,
211       final HRegionInfo regionInfo) throws IOException;
212   
213   /**
214    * Called after the region assignment has been requested.
215    * @param ctx the environment to interact with the framework and master
216    * @param regionInfo the regionInfo of the region
217    */
218   void postAssign(final ObserverContext<MasterCoprocessorEnvironment> ctx,
219       final HRegionInfo regionInfo) throws IOException;
220   
221   /**
222    * Called prior to unassigning a given region.
223    * @param ctx the environment to interact with the framework and master
224    * @param regionInfo
225    * @param force whether to force unassignment or not
226    */
227   void preUnassign(final ObserverContext<MasterCoprocessorEnvironment> ctx,
228       final HRegionInfo regionInfo, final boolean force) throws IOException;
229 
230   /**
231    * Called after the region unassignment has been requested.
232    * @param ctx the environment to interact with the framework and master
233    * @param regionInfo
234    * @param force whether to force unassignment or not
235    */
236   void postUnassign(final ObserverContext<MasterCoprocessorEnvironment> ctx,
237       final HRegionInfo regionInfo, final boolean force) throws IOException;
238 
239   /**
240    * Called prior to requesting rebalancing of the cluster regions, though after
241    * the initial checks for regions in transition and the balance switch flag.
242    * @param ctx the environment to interact with the framework and master
243    */
244   void preBalance(final ObserverContext<MasterCoprocessorEnvironment> ctx)
245       throws IOException;
246 
247   /**
248    * Called after the balancing plan has been submitted.
249    * @param ctx the environment to interact with the framework and master
250    */
251   void postBalance(final ObserverContext<MasterCoprocessorEnvironment> ctx)
252       throws IOException;
253 
254   /**
255    * Called prior to modifying the flag used to enable/disable region balancing.
256    * @param ctx the coprocessor instance's environment
257    * @param newValue the new flag value submitted in the call
258    */
259   boolean preBalanceSwitch(final ObserverContext<MasterCoprocessorEnvironment> ctx,
260       final boolean newValue) throws IOException;
261 
262   /**
263    * Called after the flag to enable/disable balancing has changed.
264    * @param ctx the coprocessor instance's environment
265    * @param oldValue the previously set balanceSwitch value
266    * @param newValue the newly set balanceSwitch value
267    */
268   void postBalanceSwitch(final ObserverContext<MasterCoprocessorEnvironment> ctx,
269       final boolean oldValue, final boolean newValue) throws IOException;
270 
271   /**
272    * Called prior to shutting down the full HBase cluster, including this
273    * {@link org.apache.hadoop.hbase.master.HMaster} process.
274    */
275   void preShutdown(final ObserverContext<MasterCoprocessorEnvironment> ctx)
276       throws IOException;
277 
278 
279   /**
280    * Called immediately prior to stopping this
281    * {@link org.apache.hadoop.hbase.master.HMaster} process.
282    */
283   void preStopMaster(final ObserverContext<MasterCoprocessorEnvironment> ctx)
284       throws IOException;
285 
286   /**
287    * Called immediately after an active master instance has completed
288    * initialization.  Will not be called on standby master instances unless
289    * they take over the active role.
290    */
291   void postStartMaster(final ObserverContext<MasterCoprocessorEnvironment> ctx)
292       throws IOException;
293 
294   /**
295    * Called before a new snapshot is taken.
296    * Called as part of snapshot RPC call.
297    * It can't bypass the default action, e.g., ctx.bypass() won't have effect.
298    * @param ctx the environment to interact with the framework and master
299    * @param snapshot the SnapshotDescriptor for the snapshot
300    * @param hTableDescriptor the hTableDescriptor of the table to snapshot
301    * @throws IOException
302    */
303   void preSnapshot(final ObserverContext<MasterCoprocessorEnvironment> ctx,
304       final SnapshotDescription snapshot, final HTableDescriptor hTableDescriptor)
305       throws IOException;
306 
307   /**
308    * Called after the snapshot operation has been requested.
309    * Called as part of snapshot RPC call.
310    * @param ctx the environment to interact with the framework and master
311    * @param snapshot the SnapshotDescriptor for the snapshot
312    * @param hTableDescriptor the hTableDescriptor of the table to snapshot
313    * @throws IOException
314    */
315   void postSnapshot(final ObserverContext<MasterCoprocessorEnvironment> ctx,
316       final SnapshotDescription snapshot, final HTableDescriptor hTableDescriptor)
317       throws IOException;
318 
319   /**
320    * Called before a snapshot is cloned.
321    * Called as part of restoreSnapshot RPC call.
322    * It can't bypass the default action, e.g., ctx.bypass() won't have effect.
323    * @param ctx the environment to interact with the framework and master
324    * @param snapshot the SnapshotDescriptor for the snapshot
325    * @param hTableDescriptor the hTableDescriptor of the table to create
326    * @throws IOException
327    */
328   void preCloneSnapshot(final ObserverContext<MasterCoprocessorEnvironment> ctx,
329       final SnapshotDescription snapshot, final HTableDescriptor hTableDescriptor)
330       throws IOException;
331 
332   /**
333    * Called after a snapshot clone operation has been requested.
334    * Called as part of restoreSnapshot RPC call.
335    * @param ctx the environment to interact with the framework and master
336    * @param snapshot the SnapshotDescriptor for the snapshot
337    * @param hTableDescriptor the hTableDescriptor of the table to create
338    * @throws IOException
339    */
340   void postCloneSnapshot(final ObserverContext<MasterCoprocessorEnvironment> ctx,
341       final SnapshotDescription snapshot, final HTableDescriptor hTableDescriptor)
342       throws IOException;
343 
344   /**
345    * Called before a snapshot is restored.
346    * Called as part of restoreSnapshot RPC call.
347    * It can't bypass the default action, e.g., ctx.bypass() won't have effect.
348    * @param ctx the environment to interact with the framework and master
349    * @param snapshot the SnapshotDescriptor for the snapshot
350    * @param hTableDescriptor the hTableDescriptor of the table to restore
351    * @throws IOException
352    */
353   void preRestoreSnapshot(final ObserverContext<MasterCoprocessorEnvironment> ctx,
354       final SnapshotDescription snapshot, final HTableDescriptor hTableDescriptor)
355       throws IOException;
356 
357   /**
358    * Called after a snapshot restore operation has been requested.
359    * Called as part of restoreSnapshot RPC call.
360    * @param ctx the environment to interact with the framework and master
361    * @param snapshot the SnapshotDescriptor for the snapshot
362    * @param hTableDescriptor the hTableDescriptor of the table to restore
363    * @throws IOException
364    */
365   void postRestoreSnapshot(final ObserverContext<MasterCoprocessorEnvironment> ctx,
366       final SnapshotDescription snapshot, final HTableDescriptor hTableDescriptor)
367       throws IOException;
368 
369   /**
370    * Called before a snapshot is deleted.
371    * Called as part of deleteSnapshot RPC call.
372    * It can't bypass the default action, e.g., ctx.bypass() won't have effect.
373    * @param ctx the environment to interact with the framework and master
374    * @param snapshot the SnapshotDescriptor of the snapshot to delete
375    * @throws IOException
376    */
377   void preDeleteSnapshot(final ObserverContext<MasterCoprocessorEnvironment> ctx,
378       final SnapshotDescription snapshot) throws IOException;
379 
380   /**
381    * Called after the delete snapshot operation has been requested.
382    * Called as part of deleteSnapshot RPC call.
383    * @param ctx the environment to interact with the framework and master
384    * @param snapshot the SnapshotDescriptor of the snapshot to delete
385    * @throws IOException
386    */
387   void postDeleteSnapshot(final ObserverContext<MasterCoprocessorEnvironment> ctx,
388       final SnapshotDescription snapshot) throws IOException;
389 }