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