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