View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.hadoop.hbase.coprocessor;
21  
22  import java.io.IOException;
23  import java.util.ArrayList;
24  import java.util.List;
25  import java.util.NavigableSet;
26  
27  import org.apache.hadoop.hbase.classification.InterfaceAudience;
28  import org.apache.hadoop.hbase.classification.InterfaceStability;
29  import org.apache.hadoop.fs.FileSystem;
30  import org.apache.hadoop.fs.Path;
31  import org.apache.hadoop.hbase.Cell;
32  import org.apache.hadoop.hbase.CoprocessorEnvironment;
33  import org.apache.hadoop.hbase.HBaseInterfaceAudience;
34  import org.apache.hadoop.hbase.HRegionInfo;
35  import org.apache.hadoop.hbase.KeyValue;
36  import org.apache.hadoop.hbase.KeyValueUtil;
37  import org.apache.hadoop.hbase.client.Append;
38  import org.apache.hadoop.hbase.client.Delete;
39  import org.apache.hadoop.hbase.client.Durability;
40  import org.apache.hadoop.hbase.client.Get;
41  import org.apache.hadoop.hbase.client.Increment;
42  import org.apache.hadoop.hbase.client.Mutation;
43  import org.apache.hadoop.hbase.client.Put;
44  import org.apache.hadoop.hbase.client.Result;
45  import org.apache.hadoop.hbase.client.Scan;
46  import org.apache.hadoop.hbase.filter.ByteArrayComparable;
47  import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
48  import org.apache.hadoop.hbase.io.FSDataInputStreamWrapper;
49  import org.apache.hadoop.hbase.io.Reference;
50  import org.apache.hadoop.hbase.io.hfile.CacheConfig;
51  import org.apache.hadoop.hbase.regionserver.DeleteTracker;
52  import org.apache.hadoop.hbase.regionserver.HRegion;
53  import org.apache.hadoop.hbase.regionserver.HRegion.Operation;
54  import org.apache.hadoop.hbase.regionserver.InternalScanner;
55  import org.apache.hadoop.hbase.regionserver.KeyValueScanner;
56  import org.apache.hadoop.hbase.regionserver.MiniBatchOperationInProgress;
57  import org.apache.hadoop.hbase.regionserver.RegionScanner;
58  import org.apache.hadoop.hbase.regionserver.ScanType;
59  import org.apache.hadoop.hbase.regionserver.Store;
60  import org.apache.hadoop.hbase.regionserver.StoreFile;
61  import org.apache.hadoop.hbase.regionserver.StoreFile.Reader;
62  import org.apache.hadoop.hbase.regionserver.compactions.CompactionRequest;
63  import org.apache.hadoop.hbase.regionserver.wal.HLogKey;
64  import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
65  import org.apache.hadoop.hbase.util.Pair;
66  
67  import com.google.common.collect.ImmutableList;
68  
69  /**
70   * An abstract class that implements RegionObserver.
71   * By extending it, you can create your own region observer without
72   * overriding all abstract methods of RegionObserver.
73   */
74  @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
75  @InterfaceStability.Evolving
76  public abstract class BaseRegionObserver implements RegionObserver {
77    @Override
78    public void start(CoprocessorEnvironment e) throws IOException { }
79  
80    @Override
81    public void stop(CoprocessorEnvironment e) throws IOException { }
82  
83    @Override
84    public void preOpen(ObserverContext<RegionCoprocessorEnvironment> e) throws IOException { }
85  
86    @Override
87    public void postOpen(ObserverContext<RegionCoprocessorEnvironment> e) { }
88  
89    @Override
90    public void postLogReplay(ObserverContext<RegionCoprocessorEnvironment> e) { }
91  
92    @Override
93    public void preClose(ObserverContext<RegionCoprocessorEnvironment> c, boolean abortRequested)
94        throws IOException { }
95  
96    @Override
97    public void postClose(ObserverContext<RegionCoprocessorEnvironment> e,
98        boolean abortRequested) { }
99  
100   @Override
101   public InternalScanner preFlushScannerOpen(final ObserverContext<RegionCoprocessorEnvironment> c,
102       final Store store, final KeyValueScanner memstoreScanner, final InternalScanner s)
103       throws IOException {
104     return s;
105   }
106 
107   @Override
108   public void preFlush(ObserverContext<RegionCoprocessorEnvironment> e) throws IOException {
109   }
110 
111   @Override
112   public void postFlush(ObserverContext<RegionCoprocessorEnvironment> e) throws IOException {
113   }
114 
115   @Override
116   public InternalScanner preFlush(ObserverContext<RegionCoprocessorEnvironment> e, Store store,
117       InternalScanner scanner) throws IOException {
118     return scanner;
119   }
120 
121   @Override
122   public void postFlush(ObserverContext<RegionCoprocessorEnvironment> e, Store store,
123       StoreFile resultFile) throws IOException {
124   }
125 
126   @Override
127   public void preSplit(ObserverContext<RegionCoprocessorEnvironment> e) throws IOException {
128   }
129   
130   @Override
131   public void preSplit(ObserverContext<RegionCoprocessorEnvironment> c,
132       byte[] splitRow) throws IOException {
133   }
134 
135   @Override
136   public void preSplitBeforePONR(ObserverContext<RegionCoprocessorEnvironment> ctx,
137       byte[] splitKey, List<Mutation> metaEntries) throws IOException {
138   }
139   
140   @Override
141   public void preSplitAfterPONR(
142       ObserverContext<RegionCoprocessorEnvironment> ctx) throws IOException {
143   }
144   
145   @Override
146   public void preRollBackSplit(ObserverContext<RegionCoprocessorEnvironment> ctx)
147       throws IOException {
148   }
149   
150   @Override
151   public void postRollBackSplit(
152       ObserverContext<RegionCoprocessorEnvironment> ctx) throws IOException {
153   }
154   
155   @Override
156   public void postCompleteSplit(
157       ObserverContext<RegionCoprocessorEnvironment> ctx) throws IOException {
158   }
159 
160   @Override
161   public void postSplit(ObserverContext<RegionCoprocessorEnvironment> e, HRegion l, HRegion r)
162       throws IOException {
163   }
164 
165   @Override
166   public void preCompactSelection(final ObserverContext<RegionCoprocessorEnvironment> c,
167       final Store store, final List<StoreFile> candidates) throws IOException { }
168 
169   @Override
170   public void preCompactSelection(final ObserverContext<RegionCoprocessorEnvironment> c,
171       final Store store, final List<StoreFile> candidates, final CompactionRequest request)
172       throws IOException {
173     preCompactSelection(c, store, candidates);
174   }
175 
176   @Override
177   public void postCompactSelection(final ObserverContext<RegionCoprocessorEnvironment> c,
178       final Store store, final ImmutableList<StoreFile> selected) { }
179 
180   @Override
181   public void postCompactSelection(final ObserverContext<RegionCoprocessorEnvironment> c,
182       final Store store, final ImmutableList<StoreFile> selected, CompactionRequest request) {
183     postCompactSelection(c, store, selected);
184   }
185 
186   @Override
187   public InternalScanner preCompact(ObserverContext<RegionCoprocessorEnvironment> e,
188       final Store store, final InternalScanner scanner, final ScanType scanType)
189       throws IOException {
190     return scanner;
191   }
192 
193   @Override
194   public InternalScanner preCompact(ObserverContext<RegionCoprocessorEnvironment> e,
195       final Store store, final InternalScanner scanner, final ScanType scanType,
196       CompactionRequest request) throws IOException {
197     return preCompact(e, store, scanner, scanType);
198   }
199 
200   @Override
201   public InternalScanner preCompactScannerOpen(
202       final ObserverContext<RegionCoprocessorEnvironment> c, final Store store,
203       List<? extends KeyValueScanner> scanners, final ScanType scanType, final long earliestPutTs,
204       final InternalScanner s) throws IOException {
205     return s;
206   }
207 
208   @Override
209   public InternalScanner preCompactScannerOpen(
210       final ObserverContext<RegionCoprocessorEnvironment> c, final Store store,
211       List<? extends KeyValueScanner> scanners, final ScanType scanType, final long earliestPutTs,
212       final InternalScanner s, CompactionRequest request) throws IOException {
213     return preCompactScannerOpen(c, store, scanners, scanType, earliestPutTs, s);
214   }
215 
216   @Override
217   public void postCompact(ObserverContext<RegionCoprocessorEnvironment> e, final Store store,
218       final StoreFile resultFile) throws IOException {
219   }
220 
221 @Override
222   public void postCompact(ObserverContext<RegionCoprocessorEnvironment> e, final Store store,
223       final StoreFile resultFile, CompactionRequest request) throws IOException {
224     postCompact(e, store, resultFile);
225   }
226 
227   @Override
228   public void preGetClosestRowBefore(final ObserverContext<RegionCoprocessorEnvironment> e,
229       final byte [] row, final byte [] family, final Result result)
230     throws IOException {
231   }
232 
233   @Override
234   public void postGetClosestRowBefore(final ObserverContext<RegionCoprocessorEnvironment> e,
235       final byte [] row, final byte [] family, final Result result)
236       throws IOException {
237   }
238 
239   @Override
240   public void preGetOp(final ObserverContext<RegionCoprocessorEnvironment> e,
241       final Get get, final List<Cell> results) throws IOException {
242     // By default we are executing the deprecated preGet to support legacy RegionObservers
243     // We may use the results coming in and we may return the results going out.
244     List<KeyValue> kvs = new ArrayList<KeyValue>(results.size());
245     for (Cell c : results) {
246       kvs.add(KeyValueUtil.ensureKeyValue(c));
247     }
248     preGet(e, get, kvs);
249     results.clear();
250     results.addAll(kvs);
251   }
252 
253   /**
254    * WARNING: please override preGetOp instead of this method.  This is to maintain some
255    * compatibility and to ease the transition from 0.94 -> 0.96.  It is super inefficient!
256    */
257   @Deprecated
258   @Override
259   public void preGet(final ObserverContext<RegionCoprocessorEnvironment> c, final Get get,
260       final List<KeyValue> result)
261     throws IOException {
262   }
263 
264   @Override
265   public void postGetOp(final ObserverContext<RegionCoprocessorEnvironment> e,
266       final Get get, final List<Cell> results) throws IOException {
267     // By default we are executing the deprecated preGet to support legacy RegionObservers
268     // We may use the results coming in and we may return the results going out.
269     List<KeyValue> kvs = new ArrayList<KeyValue>(results.size());
270     for (Cell c : results) {
271       kvs.add(KeyValueUtil.ensureKeyValue(c));
272     }
273     postGet(e, get, kvs);
274     results.clear();
275     results.addAll(kvs);
276   }
277 
278   /**
279    * WARNING: please override postGetOp instead of this method.  This is to maintain some
280    * compatibility and to ease the transition from 0.94 -> 0.96.  It is super inefficient!
281    */
282   @Deprecated
283   @Override
284   public void postGet(final ObserverContext<RegionCoprocessorEnvironment> c, final Get get,
285       final List<KeyValue> result)
286     throws IOException {
287   }
288 
289   
290   @Override
291   public boolean preExists(final ObserverContext<RegionCoprocessorEnvironment> e,
292       final Get get, final boolean exists) throws IOException {
293     return exists;
294   }
295 
296   @Override
297   public boolean postExists(final ObserverContext<RegionCoprocessorEnvironment> e,
298       final Get get, boolean exists) throws IOException {
299     return exists;
300   }
301 
302   @Override
303   public void prePut(final ObserverContext<RegionCoprocessorEnvironment> e, 
304       final Put put, final WALEdit edit, final Durability durability) throws IOException {
305   }
306 
307   @Override
308   public void postPut(final ObserverContext<RegionCoprocessorEnvironment> e, 
309       final Put put, final WALEdit edit, final Durability durability) throws IOException {
310   }
311 
312   @Override
313   public void preDelete(final ObserverContext<RegionCoprocessorEnvironment> e, final Delete delete,
314       final WALEdit edit, final Durability durability) throws IOException {
315   }
316 
317   @Override
318   public void prePrepareTimeStampForDeleteVersion(
319       final ObserverContext<RegionCoprocessorEnvironment> e, final Mutation delete,
320       final Cell cell, final byte[] byteNow, final Get get) throws IOException {
321   }
322 
323   @Override
324   public void postDelete(final ObserverContext<RegionCoprocessorEnvironment> e,
325       final Delete delete, final WALEdit edit, final Durability durability)
326       throws IOException {
327   }
328   
329   @Override
330   public void preBatchMutate(final ObserverContext<RegionCoprocessorEnvironment> c,
331       final MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException {
332   }
333 
334   @Override
335   public void postBatchMutate(final ObserverContext<RegionCoprocessorEnvironment> c,
336       final MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException {
337   }
338 
339   @Override
340   public void postBatchMutateIndispensably(final ObserverContext<RegionCoprocessorEnvironment> ctx,
341       MiniBatchOperationInProgress<Mutation> miniBatchOp, final boolean success) throws IOException {
342   }
343 
344   @Override
345   public boolean preCheckAndPut(final ObserverContext<RegionCoprocessorEnvironment> e,
346       final byte [] row, final byte [] family, final byte [] qualifier,
347       final CompareOp compareOp, final ByteArrayComparable comparator,
348       final Put put, final boolean result) throws IOException {
349     return result;
350   }
351 
352   @Override
353   public boolean preCheckAndPutAfterRowLock(
354       final ObserverContext<RegionCoprocessorEnvironment> e,
355       final byte[] row, final byte[] family, final byte[] qualifier, final CompareOp compareOp,
356       final ByteArrayComparable comparator, final Put put,
357       final boolean result) throws IOException {
358     return result;
359   }
360 
361   @Override
362   public boolean postCheckAndPut(final ObserverContext<RegionCoprocessorEnvironment> e,
363       final byte [] row, final byte [] family, final byte [] qualifier,
364       final CompareOp compareOp, final ByteArrayComparable comparator,
365       final Put put, final boolean result) throws IOException {
366     return result;
367   }
368 
369   @Override
370   public boolean preCheckAndDelete(final ObserverContext<RegionCoprocessorEnvironment> e,
371       final byte [] row, final byte [] family, final byte [] qualifier,
372       final CompareOp compareOp, final ByteArrayComparable comparator,
373       final Delete delete, final boolean result) throws IOException {
374     return result;
375   }
376 
377   @Override
378   public boolean preCheckAndDeleteAfterRowLock(
379       final ObserverContext<RegionCoprocessorEnvironment> e,
380       final byte[] row, final byte[] family, final byte[] qualifier, final CompareOp compareOp,
381       final ByteArrayComparable comparator, final Delete delete,
382       final boolean result) throws IOException {
383     return result;
384   }
385 
386   @Override
387   public boolean postCheckAndDelete(final ObserverContext<RegionCoprocessorEnvironment> e,
388       final byte [] row, final byte [] family, final byte [] qualifier,
389       final CompareOp compareOp, final ByteArrayComparable comparator,
390       final Delete delete, final boolean result) throws IOException {
391     return result;
392   }
393 
394   @Override
395   public Result preAppend(final ObserverContext<RegionCoprocessorEnvironment> e,
396       final Append append) throws IOException {
397     return null;
398   }
399 
400   @Override
401   public Result preAppendAfterRowLock(final ObserverContext<RegionCoprocessorEnvironment> e,
402       final Append append) throws IOException {
403     return null;
404   }
405 
406   @Override
407   public Result postAppend(final ObserverContext<RegionCoprocessorEnvironment> e,
408       final Append append, final Result result) throws IOException {
409     return result;
410   }
411 
412   @Override
413   public long preIncrementColumnValue(final ObserverContext<RegionCoprocessorEnvironment> e,
414       final byte [] row, final byte [] family, final byte [] qualifier,
415       final long amount, final boolean writeToWAL) throws IOException {
416     return amount;
417   }
418 
419   @Override
420   public long postIncrementColumnValue(final ObserverContext<RegionCoprocessorEnvironment> e,
421       final byte [] row, final byte [] family, final byte [] qualifier,
422       final long amount, final boolean writeToWAL, long result)
423       throws IOException {
424     return result;
425   }
426 
427   @Override
428   public Result preIncrement(final ObserverContext<RegionCoprocessorEnvironment> e,
429       final Increment increment) throws IOException {
430     return null;
431   }
432 
433   @Override
434   public Result preIncrementAfterRowLock(final ObserverContext<RegionCoprocessorEnvironment> e,
435       final Increment increment) throws IOException {
436     return null;
437   }
438 
439   @Override
440   public Result postIncrement(final ObserverContext<RegionCoprocessorEnvironment> e,
441       final Increment increment, final Result result) throws IOException {
442     return result;
443   }
444 
445   @Override
446   public RegionScanner preScannerOpen(final ObserverContext<RegionCoprocessorEnvironment> e,
447       final Scan scan, final RegionScanner s) throws IOException {
448     return s;
449   }
450 
451   @Override
452   public KeyValueScanner preStoreScannerOpen(final ObserverContext<RegionCoprocessorEnvironment> c,
453       final Store store, final Scan scan, final NavigableSet<byte[]> targetCols,
454       final KeyValueScanner s) throws IOException {
455     return s;
456   }
457 
458   @Override
459   public RegionScanner postScannerOpen(final ObserverContext<RegionCoprocessorEnvironment> e,
460       final Scan scan, final RegionScanner s) throws IOException {
461     return s;
462   }
463 
464   @Override
465   public boolean preScannerNext(final ObserverContext<RegionCoprocessorEnvironment> e,
466       final InternalScanner s, final List<Result> results,
467       final int limit, final boolean hasMore) throws IOException {
468     return hasMore;
469   }
470 
471   @Override
472   public boolean postScannerNext(final ObserverContext<RegionCoprocessorEnvironment> e,
473       final InternalScanner s, final List<Result> results, final int limit,
474       final boolean hasMore) throws IOException {
475     return hasMore;
476   }
477 
478   @Override
479   public boolean postScannerFilterRow(final ObserverContext<RegionCoprocessorEnvironment> e,
480       final InternalScanner s, final byte[] currentRow, final int offset, final short length,
481       final boolean hasMore) throws IOException {
482     return hasMore;
483   }
484 
485   @Override
486   public void preScannerClose(final ObserverContext<RegionCoprocessorEnvironment> e,
487       final InternalScanner s) throws IOException {
488   }
489 
490   @Override
491   public void postScannerClose(final ObserverContext<RegionCoprocessorEnvironment> e,
492       final InternalScanner s) throws IOException {
493   }
494 
495   @Override
496   public void preWALRestore(ObserverContext<RegionCoprocessorEnvironment> env, HRegionInfo info,
497       HLogKey logKey, WALEdit logEdit) throws IOException {
498   }
499 
500   @Override
501   public void postWALRestore(ObserverContext<RegionCoprocessorEnvironment> env,
502       HRegionInfo info, HLogKey logKey, WALEdit logEdit) throws IOException {
503   }
504 
505   @Override
506   public void preBulkLoadHFile(final ObserverContext<RegionCoprocessorEnvironment> ctx,
507     List<Pair<byte[], String>> familyPaths) throws IOException {
508   }
509 
510   @Override
511   public boolean postBulkLoadHFile(ObserverContext<RegionCoprocessorEnvironment> ctx,
512     List<Pair<byte[], String>> familyPaths, boolean hasLoaded) throws IOException {
513     return hasLoaded;
514   }
515 
516   @Override
517   public Reader preStoreFileReaderOpen(ObserverContext<RegionCoprocessorEnvironment> ctx,
518       FileSystem fs, Path p, FSDataInputStreamWrapper in, long size, CacheConfig cacheConf,
519       Reference r, Reader reader) throws IOException {
520     return reader;
521   }
522 
523   @Override
524   public Reader postStoreFileReaderOpen(ObserverContext<RegionCoprocessorEnvironment> ctx,
525       FileSystem fs, Path p, FSDataInputStreamWrapper in, long size, CacheConfig cacheConf,
526       Reference r, Reader reader) throws IOException {
527     return reader;
528   }
529 
530   @Override
531   public Cell postMutationBeforeWAL(ObserverContext<RegionCoprocessorEnvironment> ctx,
532       MutationType opType, Mutation mutation, Cell oldCell, Cell newCell) throws IOException {
533     return newCell;
534   }
535 
536   @Override
537   public void postStartRegionOperation(final ObserverContext<RegionCoprocessorEnvironment> ctx,
538       Operation op) throws IOException {
539   }
540 
541   @Override
542   public void postCloseRegionOperation(final ObserverContext<RegionCoprocessorEnvironment> ctx,
543       Operation op) throws IOException {
544   }
545 
546   @Override
547   public DeleteTracker postInstantiateDeleteTracker(
548       final ObserverContext<RegionCoprocessorEnvironment> ctx, DeleteTracker delTracker)
549       throws IOException {
550     return delTracker;
551   }
552 }