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