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