View Javadoc

1   /*
2    *
3    * Licensed under the Apache License, Version 2.0 (the "License");
4    * you may not use this file except in compliance with the License.
5    * You may obtain a copy of the License at
6    *
7    *     http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  
16  package org.apache.hadoop.hbase.coprocessor;
17  
18  import java.util.List;
19  import java.util.NavigableSet;
20  
21  import com.google.common.collect.ImmutableList;
22  
23  import org.apache.hadoop.classification.InterfaceAudience;
24  import org.apache.hadoop.classification.InterfaceStability;
25  import org.apache.hadoop.hbase.CoprocessorEnvironment;
26  import org.apache.hadoop.hbase.HRegionInfo;
27  import org.apache.hadoop.hbase.KeyValue;
28  import org.apache.hadoop.hbase.client.Append;
29  import org.apache.hadoop.hbase.client.Delete;
30  import org.apache.hadoop.hbase.client.Get;
31  import org.apache.hadoop.hbase.client.Increment;
32  import org.apache.hadoop.hbase.client.Mutation;
33  import org.apache.hadoop.hbase.client.Put;
34  import org.apache.hadoop.hbase.client.Result;
35  import org.apache.hadoop.hbase.client.Scan;
36  import org.apache.hadoop.hbase.client.Durability;
37  import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
38  import org.apache.hadoop.hbase.filter.ByteArrayComparable;
39  import org.apache.hadoop.hbase.regionserver.HRegion;
40  import org.apache.hadoop.hbase.regionserver.InternalScanner;
41  import org.apache.hadoop.hbase.regionserver.KeyValueScanner;
42  import org.apache.hadoop.hbase.regionserver.MiniBatchOperationInProgress;
43  import org.apache.hadoop.hbase.regionserver.RegionScanner;
44  import org.apache.hadoop.hbase.regionserver.ScanType;
45  import org.apache.hadoop.hbase.regionserver.Store;
46  import org.apache.hadoop.hbase.regionserver.StoreFile;
47  import org.apache.hadoop.hbase.regionserver.compactions.CompactionRequest;
48  import org.apache.hadoop.hbase.regionserver.wal.HLogKey;
49  import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
50  import org.apache.hadoop.hbase.util.Pair;
51  
52  import java.io.IOException;
53  
54  /**
55   * An abstract class that implements RegionObserver.
56   * By extending it, you can create your own region observer without
57   * overriding all abstract methods of RegionObserver.
58   */
59  @InterfaceAudience.Public
60  @InterfaceStability.Evolving
61  public abstract class BaseRegionObserver implements RegionObserver {
62    @Override
63    public void start(CoprocessorEnvironment e) throws IOException { }
64  
65    @Override
66    public void stop(CoprocessorEnvironment e) throws IOException { }
67  
68    @Override
69    public void preOpen(ObserverContext<RegionCoprocessorEnvironment> e) throws IOException { }
70  
71    @Override
72    public void postOpen(ObserverContext<RegionCoprocessorEnvironment> e) { }
73  
74    @Override
75    public void preClose(ObserverContext<RegionCoprocessorEnvironment> c, boolean abortRequested)
76        throws IOException { }
77  
78    @Override
79    public void postClose(ObserverContext<RegionCoprocessorEnvironment> e,
80        boolean abortRequested) { }
81  
82    @Override
83    public InternalScanner preFlushScannerOpen(final ObserverContext<RegionCoprocessorEnvironment> c,
84        final Store store, final KeyValueScanner memstoreScanner, final InternalScanner s)
85        throws IOException {
86      return s;
87    }
88  
89    @Override
90    public void preFlush(ObserverContext<RegionCoprocessorEnvironment> e) throws IOException {
91    }
92  
93    @Override
94    public void postFlush(ObserverContext<RegionCoprocessorEnvironment> e) throws IOException {
95    }
96  
97    @Override
98    public InternalScanner preFlush(ObserverContext<RegionCoprocessorEnvironment> e, Store store,
99        InternalScanner scanner) throws IOException {
100     return scanner;
101   }
102 
103   @Override
104   public void postFlush(ObserverContext<RegionCoprocessorEnvironment> e, Store store,
105       StoreFile resultFile) throws IOException {
106   }
107 
108   @Override
109   public void preSplit(ObserverContext<RegionCoprocessorEnvironment> e) throws IOException {
110   }
111   
112   @Override
113   public void preSplit(ObserverContext<RegionCoprocessorEnvironment> c,
114       byte[] splitRow) throws IOException {
115   }
116   
117   @Override
118   public void preRollBackSplit(ObserverContext<RegionCoprocessorEnvironment> ctx)
119       throws IOException {
120   }
121   
122   @Override
123   public void postRollBackSplit(
124       ObserverContext<RegionCoprocessorEnvironment> ctx) throws IOException {
125   }
126   
127   @Override
128   public void postCompleteSplit(
129       ObserverContext<RegionCoprocessorEnvironment> ctx) throws IOException {
130   }
131 
132   @Override
133   public void postSplit(ObserverContext<RegionCoprocessorEnvironment> e, HRegion l, HRegion r)
134       throws IOException {
135   }
136 
137   @Override
138   public void preCompactSelection(final ObserverContext<RegionCoprocessorEnvironment> c,
139       final Store store, final List<StoreFile> candidates) throws IOException { }
140 
141   @Override
142   public void preCompactSelection(final ObserverContext<RegionCoprocessorEnvironment> c,
143       final Store store, final List<StoreFile> candidates, final CompactionRequest request)
144       throws IOException {
145     preCompactSelection(c, store, candidates);
146   }
147 
148   @Override
149   public void postCompactSelection(final ObserverContext<RegionCoprocessorEnvironment> c,
150       final Store store, final ImmutableList<StoreFile> selected) { }
151 
152   @Override
153   public void postCompactSelection(final ObserverContext<RegionCoprocessorEnvironment> c,
154       final Store store, final ImmutableList<StoreFile> selected, CompactionRequest request) {
155     postCompactSelection(c, store, selected);
156   }
157 
158   @Override
159   public InternalScanner preCompact(ObserverContext<RegionCoprocessorEnvironment> e,
160       final Store store, final InternalScanner scanner, final ScanType scanType)
161       throws IOException {
162     return scanner;
163   }
164 
165   @Override
166   public InternalScanner preCompact(ObserverContext<RegionCoprocessorEnvironment> e,
167       final Store store, final InternalScanner scanner, final ScanType scanType,
168       CompactionRequest request) throws IOException {
169     return preCompact(e, store, scanner, scanType);
170   }
171 
172   @Override
173   public InternalScanner preCompactScannerOpen(
174       final ObserverContext<RegionCoprocessorEnvironment> c, final Store store,
175       List<? extends KeyValueScanner> scanners, final ScanType scanType, final long earliestPutTs,
176       final InternalScanner s) throws IOException {
177     return s;
178   }
179 
180   @Override
181   public InternalScanner preCompactScannerOpen(
182       final ObserverContext<RegionCoprocessorEnvironment> c, final Store store,
183       List<? extends KeyValueScanner> scanners, final ScanType scanType, final long earliestPutTs,
184       final InternalScanner s, CompactionRequest request) throws IOException {
185     return preCompactScannerOpen(c, store, scanners, scanType, earliestPutTs, s);
186   }
187 
188   @Override
189   public void postCompact(ObserverContext<RegionCoprocessorEnvironment> e, final Store store,
190       final StoreFile resultFile) throws IOException {
191   }
192 
193 @Override
194   public void postCompact(ObserverContext<RegionCoprocessorEnvironment> e, final Store store,
195       final StoreFile resultFile, CompactionRequest request) throws IOException {
196     postCompact(e, store, resultFile);
197   }
198 
199   @Override
200   public void preGetClosestRowBefore(final ObserverContext<RegionCoprocessorEnvironment> e,
201       final byte [] row, final byte [] family, final Result result)
202     throws IOException {
203   }
204 
205   @Override
206   public void postGetClosestRowBefore(final ObserverContext<RegionCoprocessorEnvironment> e,
207       final byte [] row, final byte [] family, final Result result)
208       throws IOException {
209   }
210 
211   @Override
212   public void preGet(final ObserverContext<RegionCoprocessorEnvironment> e,
213       final Get get, final List<KeyValue> results) throws IOException {
214   }
215 
216   @Override
217   public void postGet(final ObserverContext<RegionCoprocessorEnvironment> e,
218       final Get get, final List<KeyValue> results) throws IOException {
219   }
220 
221   @Override
222   public boolean preExists(final ObserverContext<RegionCoprocessorEnvironment> e,
223       final Get get, final boolean exists) throws IOException {
224     return exists;
225   }
226 
227   @Override
228   public boolean postExists(final ObserverContext<RegionCoprocessorEnvironment> e,
229       final Get get, boolean exists) throws IOException {
230     return exists;
231   }
232 
233   @Override
234   public void prePut(final ObserverContext<RegionCoprocessorEnvironment> e, 
235       final Put put, final WALEdit edit, final Durability durability) throws IOException {
236   }
237 
238   @Override
239   public void postPut(final ObserverContext<RegionCoprocessorEnvironment> e, 
240       final Put put, final WALEdit edit, final Durability durability) throws IOException {
241   }
242 
243   @Override
244   public void preDelete(final ObserverContext<RegionCoprocessorEnvironment> e, final Delete delete,
245       final WALEdit edit, final Durability durability) throws IOException {
246   }
247 
248   @Override
249   public void postDelete(final ObserverContext<RegionCoprocessorEnvironment> e,
250       final Delete delete, final WALEdit edit, final Durability durability)
251       throws IOException {
252   }
253   
254   @Override
255   public void preBatchMutate(final ObserverContext<RegionCoprocessorEnvironment> c,
256       final MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException {
257   }
258 
259   @Override
260   public void postBatchMutate(final ObserverContext<RegionCoprocessorEnvironment> c,
261       final MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException {
262   }
263 
264   @Override
265   public boolean preCheckAndPut(final ObserverContext<RegionCoprocessorEnvironment> e,
266       final byte [] row, final byte [] family, final byte [] qualifier,
267       final CompareOp compareOp, final ByteArrayComparable comparator,
268       final Put put, final boolean result) throws IOException {
269     return result;
270   }
271 
272   @Override
273   public boolean postCheckAndPut(final ObserverContext<RegionCoprocessorEnvironment> e,
274       final byte [] row, final byte [] family, final byte [] qualifier,
275       final CompareOp compareOp, final ByteArrayComparable comparator,
276       final Put put, final boolean result) throws IOException {
277     return result;
278   }
279 
280   @Override
281   public boolean preCheckAndDelete(final ObserverContext<RegionCoprocessorEnvironment> e,
282       final byte [] row, final byte [] family, final byte [] qualifier,
283       final CompareOp compareOp, final ByteArrayComparable comparator,
284       final Delete delete, final boolean result) throws IOException {
285     return result;
286   }
287 
288   @Override
289   public boolean postCheckAndDelete(final ObserverContext<RegionCoprocessorEnvironment> e,
290       final byte [] row, final byte [] family, final byte [] qualifier,
291       final CompareOp compareOp, final ByteArrayComparable comparator,
292       final Delete delete, final boolean result) throws IOException {
293     return result;
294   }
295 
296   @Override
297   public Result preAppend(final ObserverContext<RegionCoprocessorEnvironment> e,
298       final Append append) throws IOException {
299     return null;
300   }
301 
302   @Override
303   public Result postAppend(final ObserverContext<RegionCoprocessorEnvironment> e,
304       final Append append, final Result result) throws IOException {
305     return result;
306   }
307 
308   @Override
309   public long preIncrementColumnValue(final ObserverContext<RegionCoprocessorEnvironment> e,
310       final byte [] row, final byte [] family, final byte [] qualifier,
311       final long amount, final boolean writeToWAL) throws IOException {
312     return amount;
313   }
314 
315   @Override
316   public long postIncrementColumnValue(final ObserverContext<RegionCoprocessorEnvironment> e,
317       final byte [] row, final byte [] family, final byte [] qualifier,
318       final long amount, final boolean writeToWAL, long result)
319       throws IOException {
320     return result;
321   }
322 
323   @Override
324   public Result preIncrement(final ObserverContext<RegionCoprocessorEnvironment> e,
325       final Increment increment) throws IOException {
326     return null;
327   }
328 
329   @Override
330   public Result postIncrement(final ObserverContext<RegionCoprocessorEnvironment> e,
331       final Increment increment, final Result result) throws IOException {
332     return result;
333   }
334 
335   @Override
336   public RegionScanner preScannerOpen(final ObserverContext<RegionCoprocessorEnvironment> e,
337       final Scan scan, final RegionScanner s) throws IOException {
338     return s;
339   }
340 
341   @Override
342   public KeyValueScanner preStoreScannerOpen(final ObserverContext<RegionCoprocessorEnvironment> c,
343       final Store store, final Scan scan, final NavigableSet<byte[]> targetCols,
344       final KeyValueScanner s) throws IOException {
345     return s;
346   }
347 
348   @Override
349   public RegionScanner postScannerOpen(final ObserverContext<RegionCoprocessorEnvironment> e,
350       final Scan scan, final RegionScanner s) throws IOException {
351     return s;
352   }
353 
354   @Override
355   public boolean preScannerNext(final ObserverContext<RegionCoprocessorEnvironment> e,
356       final InternalScanner s, final List<Result> results,
357       final int limit, final boolean hasMore) throws IOException {
358     return hasMore;
359   }
360 
361   @Override
362   public boolean postScannerNext(final ObserverContext<RegionCoprocessorEnvironment> e,
363       final InternalScanner s, final List<Result> results, final int limit,
364       final boolean hasMore) throws IOException {
365     return hasMore;
366   }
367 
368   @Override
369   public boolean postScannerFilterRow(final ObserverContext<RegionCoprocessorEnvironment> e,
370       final InternalScanner s, final byte[] currentRow, final boolean hasMore) throws IOException {
371     return hasMore;
372   }
373   
374   @Override
375   public void preScannerClose(final ObserverContext<RegionCoprocessorEnvironment> e,
376       final InternalScanner s) throws IOException {
377   }
378 
379   @Override
380   public void postScannerClose(final ObserverContext<RegionCoprocessorEnvironment> e,
381       final InternalScanner s) throws IOException {
382   }
383 
384   @Override
385   public void preWALRestore(ObserverContext<RegionCoprocessorEnvironment> env, HRegionInfo info,
386       HLogKey logKey, WALEdit logEdit) throws IOException {
387   }
388 
389   @Override
390   public void postWALRestore(ObserverContext<RegionCoprocessorEnvironment> env,
391       HRegionInfo info, HLogKey logKey, WALEdit logEdit) throws IOException {
392   }
393 
394   @Override
395   public void preBulkLoadHFile(final ObserverContext<RegionCoprocessorEnvironment> ctx,
396     List<Pair<byte[], String>> familyPaths) throws IOException {
397   }
398 
399   @Override
400   public boolean postBulkLoadHFile(ObserverContext<RegionCoprocessorEnvironment> ctx,
401     List<Pair<byte[], String>> familyPaths, boolean hasLoaded) throws IOException {
402     return hasLoaded;
403   }
404 }