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