View Javadoc

1   /*
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   * http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  package org.apache.hadoop.hbase.coprocessor;
21  
22  import org.apache.hadoop.hbase.classification.InterfaceAudience;
23  import org.apache.hadoop.hbase.classification.InterfaceStability;
24  import org.apache.hadoop.hbase.Coprocessor;
25  import org.apache.hadoop.hbase.HBaseInterfaceAudience;
26  import org.apache.hadoop.hbase.HRegionInfo;
27  import org.apache.hadoop.hbase.regionserver.wal.HLogKey;
28  import org.apache.hadoop.hbase.wal.WALKey;
29  import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
30  
31  import java.io.IOException;
32  
33  /**
34   * It's provided to have a way for coprocessors to observe, rewrite,
35   * or skip WALEdits as they are being written to the WAL.
36   *
37   * Note that implementers of WALObserver will not see WALEdits that report themselves
38   * as empty via {@link WALEdit#isEmpty()}.
39   *
40   * {@link org.apache.hadoop.hbase.coprocessor.RegionObserver} provides
41   * hooks for adding logic for WALEdits in the region context during reconstruction,
42   *
43   * Defines coprocessor hooks for interacting with operations on the
44   * {@link org.apache.hadoop.hbase.wal.WAL}.
45   */
46  @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
47  @InterfaceStability.Evolving
48  public interface WALObserver extends Coprocessor {
49  
50    /**
51     * Called before a {@link org.apache.hadoop.hbase.regionserver.wal.WALEdit}
52     * is writen to WAL.
53     *
54     * @return true if default behavior should be bypassed, false otherwise
55     */
56    // TODO: return value is not used
57    boolean preWALWrite(ObserverContext<? extends WALCoprocessorEnvironment> ctx,
58        HRegionInfo info, WALKey logKey, WALEdit logEdit) throws IOException;
59  
60    /**
61     * Called before a {@link org.apache.hadoop.hbase.regionserver.wal.WALEdit}
62     * is writen to WAL.
63     *
64     * This method is left in place to maintain binary compatibility with older
65     * {@link WALObserver}s. If an implementation directly overrides
66     * {@link #preWALWrite(ObserverContext, HRegionInfo, WALKey, WALEdit)} then this version
67     * won't be called at all, barring problems with the Security Manager. To work correctly
68     * in the presence of a strict Security Manager, or in the case of an implementation that
69     * relies on a parent class to implement preWALWrite, you should implement this method
70     * as a call to the non-deprecated version.
71     *
72     * Users of this method will see all edits that can be treated as HLogKey. If there are
73     * edits that can't be treated as HLogKey they won't be offered to coprocessors that rely
74     * on this method. If a coprocessor gets skipped because of this mechanism, a log message
75     * at ERROR will be generated per coprocessor on the logger for {@link CoprocessorHost} once per
76     * classloader.
77     *
78     * @return true if default behavior should be bypassed, false otherwise
79     * @deprecated use {@link #preWALWrite(ObserverContext, HRegionInfo, WALKey, WALEdit)}
80     */
81    @Deprecated
82    boolean preWALWrite(ObserverContext<WALCoprocessorEnvironment> ctx,
83        HRegionInfo info, HLogKey logKey, WALEdit logEdit) throws IOException;
84  
85    /**
86     * Called after a {@link org.apache.hadoop.hbase.regionserver.wal.WALEdit}
87     * is writen to WAL.
88     */
89    void postWALWrite(ObserverContext<? extends WALCoprocessorEnvironment> ctx,
90        HRegionInfo info, WALKey logKey, WALEdit logEdit) throws IOException;
91  
92    /**
93     * Called after a {@link org.apache.hadoop.hbase.regionserver.wal.WALEdit}
94     * is writen to WAL.
95     *
96     * This method is left in place to maintain binary compatibility with older
97     * {@link WALObserver}s. If an implementation directly overrides
98     * {@link #postWALWrite(ObserverContext, HRegionInfo, WALKey, WALEdit)} then this version
99     * won't be called at all, barring problems with the Security Manager. To work correctly
100    * in the presence of a strict Security Manager, or in the case of an implementation that
101    * relies on a parent class to implement preWALWrite, you should implement this method
102    * as a call to the non-deprecated version.
103    *
104    * Users of this method will see all edits that can be treated as HLogKey. If there are
105    * edits that can't be treated as HLogKey they won't be offered to coprocessors that rely
106    * on this method. If a coprocessor gets skipped because of this mechanism, a log message
107    * at ERROR will be generated per coprocessor on the logger for {@link CoprocessorHost} once per
108    * classloader.
109    *
110    * @deprecated use {@link #postWALWrite(ObserverContext, HRegionInfo, WALKey, WALEdit)}
111    */
112   @Deprecated
113   void postWALWrite(ObserverContext<WALCoprocessorEnvironment> ctx,
114       HRegionInfo info, HLogKey logKey, WALEdit logEdit) throws IOException;
115 }