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