001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.coprocessor;
019
020import java.io.IOException;
021import org.apache.hadoop.hbase.HBaseInterfaceAudience;
022import org.apache.hadoop.hbase.replication.ReplicationEndpoint;
023import org.apache.yetus.audience.InterfaceAudience;
024import org.apache.yetus.audience.InterfaceStability;
025
026/**
027 * Defines coprocessor hooks for interacting with operations on the
028 * {@link org.apache.hadoop.hbase.regionserver.HRegionServer} process. Since most implementations
029 * will be interested in only a subset of hooks, this class uses 'default' functions to avoid having
030 * to add unnecessary overrides. When the functions are non-empty, it's simply to satisfy the
031 * compiler by returning value of expected (non-void) type. It is done in a way that these default
032 * definitions act as no-op. So our suggestion to implementation would be to not call these
033 * 'default' methods from overrides. <br>
034 * <br>
035 * <h3>Exception Handling</h3> For all functions, exception handling is done as follows:
036 * <ul>
037 * <li>Exceptions of type {@link IOException} are reported back to client.</li>
038 * <li>For any other kind of exception:
039 * <ul>
040 * <li>If the configuration {@link CoprocessorHost#ABORT_ON_ERROR_KEY} is set to true, then the
041 * server aborts.</li>
042 * <li>Otherwise, coprocessor is removed from the server and
043 * {@link org.apache.hadoop.hbase.DoNotRetryIOException} is returned to the client.</li>
044 * </ul>
045 * </li>
046 * </ul>
047 */
048@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
049@InterfaceStability.Evolving
050public interface RegionServerObserver {
051  /**
052   * Called before stopping region server.
053   * @param ctx the environment to interact with the framework and region server.
054   */
055  default void preStopRegionServer(final ObserverContext<RegionServerCoprocessorEnvironment> ctx)
056    throws IOException {
057  }
058
059  /**
060   * This will be called before executing user request to roll a region server WAL.
061   * @param ctx the environment to interact with the framework and region server.
062   */
063  default void preRollWALWriterRequest(
064    final ObserverContext<RegionServerCoprocessorEnvironment> ctx) throws IOException {
065  }
066
067  /**
068   * This will be called after executing user request to roll a region server WAL.
069   * @param ctx the environment to interact with the framework and region server.
070   */
071  default void postRollWALWriterRequest(
072    final ObserverContext<RegionServerCoprocessorEnvironment> ctx) throws IOException {
073  }
074
075  /**
076   * This will be called after the replication endpoint is instantiated.
077   * @param ctx      the environment to interact with the framework and region server.
078   * @param endpoint - the base endpoint for replication
079   * @return the endpoint to use during replication.
080   */
081  default ReplicationEndpoint postCreateReplicationEndPoint(
082    ObserverContext<RegionServerCoprocessorEnvironment> ctx, ReplicationEndpoint endpoint) {
083    return endpoint;
084  }
085
086  // TODO remove below 2 hooks when we implement AC as a core impl than a CP impl.
087  /**
088   * This will be called before executing replication request to shipping log entries.
089   * @param ctx the environment to interact with the framework and region server.
090   * @deprecated As of release 2.0.0 with out any replacement. This is maintained for internal usage
091   *             by AccessController. Do not use these hooks in custom co-processors.
092   */
093  @Deprecated
094  default void preReplicateLogEntries(final ObserverContext<RegionServerCoprocessorEnvironment> ctx)
095    throws IOException {
096  }
097
098  /**
099   * This will be called after executing replication request to shipping log entries.
100   * @param ctx the environment to interact with the framework and region server.
101   * @deprecated As of release 2.0.0 with out any replacement. This is maintained for internal usage
102   *             by AccessController. Do not use these hooks in custom co-processors.
103   */
104  @Deprecated
105  default void postReplicateLogEntries(
106    final ObserverContext<RegionServerCoprocessorEnvironment> ctx) throws IOException {
107  }
108
109  /**
110   * This will be called before clearing compaction queues
111   * @param ctx the environment to interact with the framework and region server.
112   */
113  default void preClearCompactionQueues(
114    final ObserverContext<RegionServerCoprocessorEnvironment> ctx) throws IOException {
115  }
116
117  /**
118   * This will be called after clearing compaction queues
119   * @param ctx the environment to interact with the framework and region server.
120   */
121  default void postClearCompactionQueues(
122    final ObserverContext<RegionServerCoprocessorEnvironment> ctx) throws IOException {
123  }
124
125  /**
126   * This will be called before executing procedures
127   * @param ctx the environment to interact with the framework and region server.
128   */
129  default void preExecuteProcedures(ObserverContext<RegionServerCoprocessorEnvironment> ctx)
130    throws IOException {
131  }
132
133  /**
134   * This will be called after executing procedures
135   * @param ctx the environment to interact with the framework and region server.
136   */
137  default void postExecuteProcedures(ObserverContext<RegionServerCoprocessorEnvironment> ctx)
138    throws IOException {
139  }
140}