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