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 preClose(ObserverContext<RegionCoprocessorEnvironment> c, boolean abortRequested)
80        throws IOException { }
81  
82    @Override
83    public void postClose(ObserverContext<RegionCoprocessorEnvironment> e,
84        boolean abortRequested) { }
85  
86    @Override
87    public InternalScanner preFlushScannerOpen(final ObserverContext<RegionCoprocessorEnvironment> c,
88        final Store store, final KeyValueScanner memstoreScanner, final InternalScanner s)
89        throws IOException {
90      return s;
91    }
92  
93    @Override
94    public void preFlush(ObserverContext<RegionCoprocessorEnvironment> e) throws IOException {
95    }
96  
97    @Override
98    public void postFlush(ObserverContext<RegionCoprocessorEnvironment> e) throws IOException {
99    }
100 
101   @Override
102   public InternalScanner preFlush(ObserverContext<RegionCoprocessorEnvironment> e, Store store,
103       InternalScanner scanner) throws IOException {
104     return scanner;
105   }
106 
107   @Override
108   public void postFlush(ObserverContext<RegionCoprocessorEnvironment> e, Store store,
109       StoreFile resultFile) throws IOException {
110   }
111 
112   @Override
113   public void preSplit(ObserverContext<RegionCoprocessorEnvironment> e) throws IOException {
114   }
115   
116   @Override
117   public void preSplit(ObserverContext<RegionCoprocessorEnvironment> c,
118       byte[] splitRow) throws IOException {
119   }
120   
121   @Override
122   public void preRollBackSplit(ObserverContext<RegionCoprocessorEnvironment> ctx)
123       throws IOException {
124   }
125   
126   @Override
127   public void postRollBackSplit(
128       ObserverContext<RegionCoprocessorEnvironment> ctx) throws IOException {
129   }
130   
131   @Override
132   public void postCompleteSplit(
133       ObserverContext<RegionCoprocessorEnvironment> ctx) throws IOException {
134   }
135 
136   @Override
137   public void postSplit(ObserverContext<RegionCoprocessorEnvironment> e, HRegion l, HRegion r)
138       throws IOException {
139   }
140 
141   @Override
142   public void preCompactSelection(final ObserverContext<RegionCoprocessorEnvironment> c,
143       final Store store, final List<StoreFile> candidates) throws IOException { }
144 
145   @Override
146   public void preCompactSelection(final ObserverContext<RegionCoprocessorEnvironment> c,
147       final Store store, final List<StoreFile> candidates, final CompactionRequest request)
148       throws IOException {
149     preCompactSelection(c, store, candidates);
150   }
151 
152   @Override
153   public void postCompactSelection(final ObserverContext<RegionCoprocessorEnvironment> c,
154       final Store store, final ImmutableList<StoreFile> selected) { }
155 
156   @Override
157   public void postCompactSelection(final ObserverContext<RegionCoprocessorEnvironment> c,
158       final Store store, final ImmutableList<StoreFile> selected, CompactionRequest request) {
159     postCompactSelection(c, store, selected);
160   }
161 
162   @Override
163   public InternalScanner preCompact(ObserverContext<RegionCoprocessorEnvironment> e,
164       final Store store, final InternalScanner scanner, final ScanType scanType)
165       throws IOException {
166     return scanner;
167   }
168 
169   @Override
170   public InternalScanner preCompact(ObserverContext<RegionCoprocessorEnvironment> e,
171       final Store store, final InternalScanner scanner, final ScanType scanType,
172       CompactionRequest request) throws IOException {
173     return preCompact(e, store, scanner, scanType);
174   }
175 
176   @Override
177   public InternalScanner preCompactScannerOpen(
178       final ObserverContext<RegionCoprocessorEnvironment> c, final Store store,
179       List<? extends KeyValueScanner> scanners, final ScanType scanType, final long earliestPutTs,
180       final InternalScanner s) throws IOException {
181     return s;
182   }
183 
184   @Override
185   public InternalScanner preCompactScannerOpen(
186       final ObserverContext<RegionCoprocessorEnvironment> c, final Store store,
187       List<? extends KeyValueScanner> scanners, final ScanType scanType, final long earliestPutTs,
188       final InternalScanner s, CompactionRequest request) throws IOException {
189     return preCompactScannerOpen(c, store, scanners, scanType, earliestPutTs, s);
190   }
191 
192   @Override
193   public void postCompact(ObserverContext<RegionCoprocessorEnvironment> e, final Store store,
194       final StoreFile resultFile) throws IOException {
195   }
196 
197 @Override
198   public void postCompact(ObserverContext<RegionCoprocessorEnvironment> e, final Store store,
199       final StoreFile resultFile, CompactionRequest request) throws IOException {
200     postCompact(e, store, resultFile);
201   }
202 
203   @Override
204   public void preGetClosestRowBefore(final ObserverContext<RegionCoprocessorEnvironment> e,
205       final byte [] row, final byte [] family, final Result result)
206     throws IOException {
207   }
208 
209   @Override
210   public void postGetClosestRowBefore(final ObserverContext<RegionCoprocessorEnvironment> e,
211       final byte [] row, final byte [] family, final Result result)
212       throws IOException {
213   }
214 
215   @Override
216   public void preGetOp(final ObserverContext<RegionCoprocessorEnvironment> e,
217       final Get get, final List<Cell> results) throws IOException {
218     // By default we are executing the deprecated preGet to support legacy RegionObservers
219     // We may use the results coming in and we may return the results going out.
220     List<KeyValue> kvs = new ArrayList<KeyValue>(results.size());
221     for (Cell c : results) {
222       kvs.add(KeyValueUtil.ensureKeyValue(c));
223     }
224     preGet(e, get, kvs);
225     results.clear();
226     results.addAll(kvs);
227   }
228 
229   /**
230    * WARNING: please override preGetOp instead of this method.  This is to maintain some
231    * compatibility and to ease the transition from 0.94 -> 0.96.  It is super inefficient!
232    */
233   @Deprecated
234   @Override
235   public void preGet(final ObserverContext<RegionCoprocessorEnvironment> c, final Get get,
236       final List<KeyValue> result)
237     throws IOException {
238   }
239 
240   @Override
241   public void postGetOp(final ObserverContext<RegionCoprocessorEnvironment> e,
242       final Get get, final List<Cell> results) throws IOException {
243     // By default we are executing the deprecated preGet to support legacy RegionObservers
244     // We may use the results coming in and we may return the results going out.
245     List<KeyValue> kvs = new ArrayList<KeyValue>(results.size());
246     for (Cell c : results) {
247       kvs.add(KeyValueUtil.ensureKeyValue(c));
248     }
249     postGet(e, get, kvs);
250     results.clear();
251     results.addAll(kvs);
252   }
253 
254   /**
255    * WARNING: please override postGetOp instead of this method.  This is to maintain some
256    * compatibility and to ease the transition from 0.94 -> 0.96.  It is super inefficient!
257    */
258   @Deprecated
259   @Override
260   public void postGet(final ObserverContext<RegionCoprocessorEnvironment> c, final Get get,
261       final List<KeyValue> result)
262     throws IOException {
263   }
264 
265   
266   @Override
267   public boolean preExists(final ObserverContext<RegionCoprocessorEnvironment> e,
268       final Get get, final boolean exists) throws IOException {
269     return exists;
270   }
271 
272   @Override
273   public boolean postExists(final ObserverContext<RegionCoprocessorEnvironment> e,
274       final Get get, boolean exists) throws IOException {
275     return exists;
276   }
277 
278   @Override
279   public void prePut(final ObserverContext<RegionCoprocessorEnvironment> e, 
280       final Put put, final WALEdit edit, final Durability durability) throws IOException {
281   }
282 
283   @Override
284   public void postPut(final ObserverContext<RegionCoprocessorEnvironment> e, 
285       final Put put, final WALEdit edit, final Durability durability) throws IOException {
286   }
287 
288   @Override
289   public void preDelete(final ObserverContext<RegionCoprocessorEnvironment> e, final Delete delete,
290       final WALEdit edit, final Durability durability) throws IOException {
291   }
292 
293   @Override
294   public void postDelete(final ObserverContext<RegionCoprocessorEnvironment> e,
295       final Delete delete, final WALEdit edit, final Durability durability)
296       throws IOException {
297   }
298   
299   @Override
300   public void preBatchMutate(final ObserverContext<RegionCoprocessorEnvironment> c,
301       final MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException {
302   }
303 
304   @Override
305   public void postBatchMutate(final ObserverContext<RegionCoprocessorEnvironment> c,
306       final MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException {
307   }
308 
309   @Override
310   public boolean preCheckAndPut(final ObserverContext<RegionCoprocessorEnvironment> e,
311       final byte [] row, final byte [] family, final byte [] qualifier,
312       final CompareOp compareOp, final ByteArrayComparable comparator,
313       final Put put, final boolean result) throws IOException {
314     return result;
315   }
316 
317   @Override
318   public boolean postCheckAndPut(final ObserverContext<RegionCoprocessorEnvironment> e,
319       final byte [] row, final byte [] family, final byte [] qualifier,
320       final CompareOp compareOp, final ByteArrayComparable comparator,
321       final Put put, final boolean result) throws IOException {
322     return result;
323   }
324 
325   @Override
326   public boolean preCheckAndDelete(final ObserverContext<RegionCoprocessorEnvironment> e,
327       final byte [] row, final byte [] family, final byte [] qualifier,
328       final CompareOp compareOp, final ByteArrayComparable comparator,
329       final Delete delete, final boolean result) throws IOException {
330     return result;
331   }
332 
333   @Override
334   public boolean postCheckAndDelete(final ObserverContext<RegionCoprocessorEnvironment> e,
335       final byte [] row, final byte [] family, final byte [] qualifier,
336       final CompareOp compareOp, final ByteArrayComparable comparator,
337       final Delete delete, final boolean result) throws IOException {
338     return result;
339   }
340 
341   @Override
342   public Result preAppend(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 postIncrement(final ObserverContext<RegionCoprocessorEnvironment> e,
376       final Increment increment, final Result result) throws IOException {
377     return result;
378   }
379 
380   @Override
381   public RegionScanner preScannerOpen(final ObserverContext<RegionCoprocessorEnvironment> e,
382       final Scan scan, final RegionScanner s) throws IOException {
383     return s;
384   }
385 
386   @Override
387   public KeyValueScanner preStoreScannerOpen(final ObserverContext<RegionCoprocessorEnvironment> c,
388       final Store store, final Scan scan, final NavigableSet<byte[]> targetCols,
389       final KeyValueScanner s) throws IOException {
390     return s;
391   }
392 
393   @Override
394   public RegionScanner postScannerOpen(final ObserverContext<RegionCoprocessorEnvironment> e,
395       final Scan scan, final RegionScanner s) throws IOException {
396     return s;
397   }
398 
399   @Override
400   public boolean preScannerNext(final ObserverContext<RegionCoprocessorEnvironment> e,
401       final InternalScanner s, final List<Result> results,
402       final int limit, final boolean hasMore) throws IOException {
403     return hasMore;
404   }
405 
406   @Override
407   public boolean postScannerNext(final ObserverContext<RegionCoprocessorEnvironment> e,
408       final InternalScanner s, final List<Result> results, final int limit,
409       final boolean hasMore) throws IOException {
410     return hasMore;
411   }
412 
413   @Override
414   public boolean postScannerFilterRow(final ObserverContext<RegionCoprocessorEnvironment> e,
415       final InternalScanner s, final byte[] currentRow, final boolean hasMore) throws IOException {
416     return hasMore;
417   }
418   
419   @Override
420   public void preScannerClose(final ObserverContext<RegionCoprocessorEnvironment> e,
421       final InternalScanner s) throws IOException {
422   }
423 
424   @Override
425   public void postScannerClose(final ObserverContext<RegionCoprocessorEnvironment> e,
426       final InternalScanner s) throws IOException {
427   }
428 
429   @Override
430   public void preWALRestore(ObserverContext<RegionCoprocessorEnvironment> env, HRegionInfo info,
431       HLogKey logKey, WALEdit logEdit) throws IOException {
432   }
433 
434   @Override
435   public void postWALRestore(ObserverContext<RegionCoprocessorEnvironment> env,
436       HRegionInfo info, HLogKey logKey, WALEdit logEdit) throws IOException {
437   }
438 
439   @Override
440   public void preBulkLoadHFile(final ObserverContext<RegionCoprocessorEnvironment> ctx,
441     List<Pair<byte[], String>> familyPaths) throws IOException {
442   }
443 
444   @Override
445   public boolean postBulkLoadHFile(ObserverContext<RegionCoprocessorEnvironment> ctx,
446     List<Pair<byte[], String>> familyPaths, boolean hasLoaded) throws IOException {
447     return hasLoaded;
448   }
449 }