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 org.apache.hadoop.hbase.CoprocessorEnvironment;
021import org.apache.hadoop.hbase.HBaseInterfaceAudience;
022import org.apache.hadoop.hbase.security.User;
023import org.apache.yetus.audience.InterfaceAudience;
024import org.apache.yetus.audience.InterfaceStability;
025
026import java.util.Optional;
027
028/**
029 * Carries the execution state for a given invocation of an Observer coprocessor
030 * ({@link RegionObserver}, {@link MasterObserver}, or {@link WALObserver})
031 * method. The same ObserverContext instance is passed sequentially to all loaded
032 * coprocessors for a given Observer method trigger, with the
033 * <code>CoprocessorEnvironment</code> reference set appropriately for each Coprocessor type:
034 * e.g. the RegionCoprocessorEnvironment is passed to RegionCoprocessors, and so on.
035 * @param <E> The {@link CoprocessorEnvironment} subclass applicable to the
036 *     revelant Observer interface.
037 */
038@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
039@InterfaceStability.Evolving
040public interface ObserverContext<E extends CoprocessorEnvironment> {
041  E getEnvironment();
042
043  /**
044   * Call to indicate that the current coprocessor's return value (or parameter -- depends on the
045   * call-type) should be used in place of the value that would be obtained via normal processing;
046   * i.e. bypass the core call and return the Coprocessor's result instead. DOES NOT work for all
047   * Coprocessor invocations, only on a small subset of methods, mostly preXXX calls in
048   * RegionObserver. Check javadoc on the pertinent Coprocessor Observer to see if
049   * <code>bypass</code> is supported.
050   * <p>This behavior of honoring only a subset of methods is new since hbase-2.0.0.
051   * <p>Where bypass is supported what is being bypassed is all of the core code
052   * implementing the remainder of the operation. In order to understand what
053   * calling bypass() will skip, a coprocessor implementer should read and
054   * understand all of the remaining code and its nuances. Although this
055   * is good practice for coprocessor developers in general, it demands a lot.
056   * What is skipped is extremely version dependent. The core code will vary, perhaps significantly,
057   * even between point releases. We do not provide the promise of consistent behavior even between
058   * point releases for the bypass semantic. To achieve
059   * that we could not change any code between hook points. Therefore the
060   * coprocessor implementer becomes an HBase core developer in practice as soon
061   * as they rely on bypass(). Every release of HBase may break the assumption
062   * that the replacement for the bypassed code takes care of all necessary
063   * skipped concerns. Because those concerns can change at any point, such an
064   * assumption is never safe.</p>
065   * <p>As of hbase2, when bypass has been set, we will NOT call any Coprocessors follow the
066   * bypassing Coprocessor; we cut short the processing and return the bypassing Coprocessors
067   * response (this used be a separate 'complete' option that has been folded into the
068   * 'bypass' in hbase2.</p>
069   */
070  void bypass();
071
072
073  /**
074   * Returns the active user for the coprocessor call. If an explicit {@code User} instance was
075   * provided to the constructor, that will be returned, otherwise if we are in the context of an
076   * RPC call, the remote user is used. May not be present if the execution is outside of an RPC
077   * context.
078   */
079  Optional<User> getCaller();
080}