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  package org.apache.hadoop.hbase.coprocessor;
20  
21  import java.io.IOException;
22  import java.util.List;
23  
24  import org.apache.hadoop.hbase.CellScanner;
25  import org.apache.hadoop.hbase.Coprocessor;
26  import org.apache.hadoop.hbase.MetaMutationAnnotation;
27  import org.apache.hadoop.hbase.client.Mutation;
28  import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.WALEntry;
29  import org.apache.hadoop.hbase.regionserver.HRegion;
30  import org.apache.hadoop.hbase.replication.ReplicationEndpoint;
31  
32  public interface RegionServerObserver extends Coprocessor {
33  
34    /**
35     * Called before stopping region server.
36     * @param env An instance of RegionServerCoprocessorEnvironment
37     * @throws IOException Signals that an I/O exception has occurred.
38     */
39    void preStopRegionServer(
40      final ObserverContext<RegionServerCoprocessorEnvironment> env)
41      throws IOException;
42  
43    /**
44     * Called before the regions merge. 
45     * Call {@link org.apache.hadoop.hbase.coprocessor.ObserverContext#bypass()} to skip the merge.
46     * @throws IOException if an error occurred on the coprocessor
47     * @param ctx
48     * @param regionA
49     * @param regionB
50     * @throws IOException
51     */
52    void preMerge(final ObserverContext<RegionServerCoprocessorEnvironment> ctx,
53        final HRegion regionA, final HRegion regionB) throws IOException;
54  
55    /**
56     * called after the regions merge.
57     * @param c
58     * @param regionA
59     * @param regionB
60     * @param mergedRegion
61     * @throws IOException
62     */
63    void postMerge(final ObserverContext<RegionServerCoprocessorEnvironment> c,
64        final HRegion regionA, final HRegion regionB, final HRegion mergedRegion) throws IOException;
65  
66    /**
67     * This will be called before PONR step as part of regions merge transaction. Calling
68     * {@link org.apache.hadoop.hbase.coprocessor.ObserverContext#bypass()} rollback the merge
69     * @param ctx
70     * @param regionA
71     * @param regionB
72     * @param metaEntries mutations to execute on hbase:meta atomically with regions merge updates. 
73     *        Any puts or deletes to execute on hbase:meta can be added to the mutations.
74     * @throws IOException
75     */
76    void preMergeCommit(final ObserverContext<RegionServerCoprocessorEnvironment> ctx,
77        final HRegion regionA, final HRegion regionB,
78        @MetaMutationAnnotation List<Mutation> metaEntries) throws IOException;
79  
80    /**
81     * This will be called after PONR step as part of regions merge transaction.
82     * @param ctx
83     * @param regionA
84     * @param regionB
85     * @param mergedRegion
86     * @throws IOException
87     */
88    void postMergeCommit(final ObserverContext<RegionServerCoprocessorEnvironment> ctx,
89        final HRegion regionA, final HRegion regionB, final HRegion mergedRegion) throws IOException;
90  
91    /**
92     * This will be called before the roll back of the regions merge.
93     * @param ctx
94     * @param regionA
95     * @param regionB
96     * @throws IOException
97     */
98    void preRollBackMerge(final ObserverContext<RegionServerCoprocessorEnvironment> ctx,
99        final HRegion regionA, final HRegion regionB) throws IOException;
100 
101   /**
102    * This will be called after the roll back of the regions merge.
103    * @param ctx
104    * @param regionA
105    * @param regionB
106    * @throws IOException
107    */
108   void postRollBackMerge(final ObserverContext<RegionServerCoprocessorEnvironment> ctx,
109       final HRegion regionA, final HRegion regionB) throws IOException;
110 
111   /**
112    * This will be called before executing user request to roll a region server WAL.
113    * @param ctx An instance of ObserverContext
114    * @throws IOException Signals that an I/O exception has occurred.
115    */
116   void preRollWALWriterRequest(final ObserverContext<RegionServerCoprocessorEnvironment> ctx)
117       throws IOException;
118 
119   /**
120    * This will be called after executing user request to roll a region server WAL.
121    * @param ctx An instance of ObserverContext
122    * @throws IOException Signals that an I/O exception has occurred.
123    */
124   void postRollWALWriterRequest(final ObserverContext<RegionServerCoprocessorEnvironment> ctx)
125       throws IOException;
126 
127   /**
128    * This will be called after the replication endpoint is instantiated.
129    * @param ctx
130    * @param endpoint - the base endpoint for replication
131    * @return the endpoint to use during replication.
132    */
133   ReplicationEndpoint postCreateReplicationEndPoint(
134       ObserverContext<RegionServerCoprocessorEnvironment> ctx, ReplicationEndpoint endpoint);
135 
136   /**
137    * This will be called before executing replication request to shipping log entries.
138    * @param ctx An instance of ObserverContext
139    * @param entries list of WALEntries to replicate
140    * @param cells Cells that the WALEntries refer to (if cells is non-null)
141    * @throws IOException Signals that an I/O exception has occurred.
142    */
143   void preReplicateLogEntries(final ObserverContext<RegionServerCoprocessorEnvironment> ctx,
144       List<WALEntry> entries, CellScanner cells) throws IOException;
145 
146   /**
147    * This will be called after executing replication request to shipping log entries.
148    * @param ctx An instance of ObserverContext
149    * @param entries list of WALEntries to replicate
150    * @param cells Cells that the WALEntries refer to (if cells is non-null)
151    * @throws IOException Signals that an I/O exception has occurred.
152    */
153   void postReplicateLogEntries(final ObserverContext<RegionServerCoprocessorEnvironment> ctx,
154       List<WALEntry> entries, CellScanner cells) throws IOException;
155 }