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