001/*
002 * Copyright 2011 The Apache Software Foundation
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.apache.hadoop.hbase.coprocessor;
018
019import java.util.List;
020import java.util.NavigableSet;
021
022import com.google.common.collect.ImmutableList;
023import org.apache.hadoop.hbase.CoprocessorEnvironment;
024import org.apache.hadoop.hbase.HRegionInfo;
025import org.apache.hadoop.hbase.KeyValue;
026import org.apache.hadoop.hbase.client.Append;
027import org.apache.hadoop.hbase.client.Delete;
028import org.apache.hadoop.hbase.client.Get;
029import org.apache.hadoop.hbase.client.Increment;
030import org.apache.hadoop.hbase.client.Mutation;
031import org.apache.hadoop.hbase.client.Put;
032import org.apache.hadoop.hbase.client.Result;
033import org.apache.hadoop.hbase.client.Scan;
034import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
035import org.apache.hadoop.hbase.filter.WritableByteArrayComparable;
036import org.apache.hadoop.hbase.regionserver.HRegion;
037import org.apache.hadoop.hbase.regionserver.InternalScanner;
038import org.apache.hadoop.hbase.regionserver.KeyValueScanner;
039import org.apache.hadoop.hbase.regionserver.MiniBatchOperationInProgress;
040import org.apache.hadoop.hbase.regionserver.RegionScanner;
041import org.apache.hadoop.hbase.regionserver.ScanType;
042import org.apache.hadoop.hbase.regionserver.Store;
043import org.apache.hadoop.hbase.regionserver.StoreFile;
044import org.apache.hadoop.hbase.regionserver.compactions.CompactSelection;
045import org.apache.hadoop.hbase.regionserver.compactions.CompactionRequest;
046import org.apache.hadoop.hbase.regionserver.wal.HLogKey;
047import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
048import org.apache.hadoop.hbase.util.Pair;
049
050import java.io.IOException;
051
052/**
053 * An abstract class that implements RegionObserver.
054 * By extending it, you can create your own region observer without
055 * overriding all abstract methods of RegionObserver.
056 */
057public abstract class BaseRegionObserver implements RegionObserver {
058  @Override
059  public void start(CoprocessorEnvironment e) throws IOException { }
060
061  @Override
062  public void stop(CoprocessorEnvironment e) throws IOException { }
063
064  @Override
065  public void preOpen(ObserverContext<RegionCoprocessorEnvironment> e) throws IOException { }
066
067  @Override
068  public void postOpen(ObserverContext<RegionCoprocessorEnvironment> e) { }
069
070  @Override
071  public void preClose(ObserverContext<RegionCoprocessorEnvironment> c, boolean abortRequested)
072      throws IOException { }
073
074  @Override
075  public void postClose(ObserverContext<RegionCoprocessorEnvironment> e,
076      boolean abortRequested) { }
077
078  @Override
079  public InternalScanner preFlushScannerOpen(final ObserverContext<RegionCoprocessorEnvironment> c,
080      final Store store, final KeyValueScanner memstoreScanner, final InternalScanner s)
081      throws IOException {
082    return s;
083  }
084
085  @Override
086  public void preFlush(ObserverContext<RegionCoprocessorEnvironment> e) throws IOException {
087  }
088
089  @Override
090  public void postFlush(ObserverContext<RegionCoprocessorEnvironment> e) throws IOException {
091  }
092
093  @Override
094  public InternalScanner preFlush(ObserverContext<RegionCoprocessorEnvironment> e, Store store,
095      InternalScanner scanner) throws IOException {
096    return scanner;
097  }
098
099  @Override
100  public void postFlush(ObserverContext<RegionCoprocessorEnvironment> e, Store store,
101      StoreFile resultFile) throws IOException {
102  }
103
104  @Override
105  public void preSplit(ObserverContext<RegionCoprocessorEnvironment> e) throws IOException {
106  }
107
108  @Override
109  public void postSplit(ObserverContext<RegionCoprocessorEnvironment> e, HRegion l, HRegion r)
110      throws IOException {
111  }
112
113  @Override
114  public void preCompactSelection(final ObserverContext<RegionCoprocessorEnvironment> c,
115      final Store store, final List<StoreFile> candidates, final CompactionRequest request)
116      throws IOException {
117    preCompactSelection(c, store, candidates);
118  }
119
120  @Override
121  public void preCompactSelection(final ObserverContext<RegionCoprocessorEnvironment> c,
122      final Store store, final List<StoreFile> candidates) throws IOException { }
123
124  @Override
125  public void postCompactSelection(final ObserverContext<RegionCoprocessorEnvironment> c,
126      final Store store, final ImmutableList<StoreFile> selected, CompactionRequest request) {
127    postCompactSelection(c, store, selected);
128  }
129
130  @Override
131  public void postCompactSelection(final ObserverContext<RegionCoprocessorEnvironment> c,
132      final Store store, final ImmutableList<StoreFile> selected) { }
133
134  @Override
135  public InternalScanner preCompact(ObserverContext<RegionCoprocessorEnvironment> e,
136      final Store store, final InternalScanner scanner) throws IOException {
137    return scanner;
138  }
139
140  @Override
141  public InternalScanner preCompact(ObserverContext<RegionCoprocessorEnvironment> e,
142      final Store store, final InternalScanner scanner, CompactionRequest request)
143      throws IOException {
144    return preCompact(e, store, scanner);
145  }
146
147  @Override
148  public InternalScanner preCompactScannerOpen(final ObserverContext<RegionCoprocessorEnvironment> c,
149      final Store store, List<? extends KeyValueScanner> scanners, final ScanType scanType,
150      final long earliestPutTs, final InternalScanner s) throws IOException {
151    return s;
152  }
153
154  @Override
155  public InternalScanner preCompactScannerOpen(
156      final ObserverContext<RegionCoprocessorEnvironment> c, final Store store,
157      List<? extends KeyValueScanner> scanners, final ScanType scanType, final long earliestPutTs,
158      final InternalScanner s, CompactionRequest request) throws IOException {
159    return preCompactScannerOpen(c, store, scanners, scanType, earliestPutTs, s);
160  }
161
162  @Override
163  public void postCompact(ObserverContext<RegionCoprocessorEnvironment> e, final Store store,
164      final StoreFile resultFile) throws IOException {
165  }
166
167  @Override
168  public void postCompact(ObserverContext<RegionCoprocessorEnvironment> e, final Store store,
169      final StoreFile resultFile, CompactionRequest request) throws IOException {
170    postCompact(e, store, resultFile);
171  }
172
173  @Override
174  public void preGetClosestRowBefore(final ObserverContext<RegionCoprocessorEnvironment> e,
175      final byte [] row, final byte [] family, final Result result)
176    throws IOException {
177  }
178
179  @Override
180  public void postGetClosestRowBefore(final ObserverContext<RegionCoprocessorEnvironment> e,
181      final byte [] row, final byte [] family, final Result result)
182      throws IOException {
183  }
184
185  @Override
186  public void preGet(final ObserverContext<RegionCoprocessorEnvironment> e,
187      final Get get, final List<KeyValue> results) throws IOException {
188  }
189
190  @Override
191  public void postGet(final ObserverContext<RegionCoprocessorEnvironment> e,
192      final Get get, final List<KeyValue> results) throws IOException {
193  }
194
195  @Override
196  public boolean preExists(final ObserverContext<RegionCoprocessorEnvironment> e,
197      final Get get, final boolean exists) throws IOException {
198    return exists;
199  }
200
201  @Override
202  public boolean postExists(final ObserverContext<RegionCoprocessorEnvironment> e,
203      final Get get, boolean exists) throws IOException {
204    return exists;
205  }
206
207  @Override
208  public void prePut(final ObserverContext<RegionCoprocessorEnvironment> e, 
209      final Put put, final WALEdit edit, final boolean writeToWAL) throws IOException {
210  }
211
212  @Override
213  public void postPut(final ObserverContext<RegionCoprocessorEnvironment> e, 
214      final Put put, final WALEdit edit, final boolean writeToWAL) throws IOException {
215  }
216
217  @Override
218  public void preDelete(final ObserverContext<RegionCoprocessorEnvironment> e, 
219      final Delete delete, final WALEdit edit, final boolean writeToWAL) throws IOException {
220  }
221
222  @Override
223  public void postDelete(final ObserverContext<RegionCoprocessorEnvironment> e,
224      final Delete delete, final WALEdit edit, final boolean writeToWAL) throws IOException {
225  }
226  
227  @Override
228  public void preBatchMutate(final ObserverContext<RegionCoprocessorEnvironment> c,
229      final MiniBatchOperationInProgress<Pair<Mutation, Integer>> miniBatchOp) throws IOException {
230  }
231
232  @Override
233  public void postBatchMutate(final ObserverContext<RegionCoprocessorEnvironment> c,
234      final MiniBatchOperationInProgress<Pair<Mutation, Integer>> miniBatchOp) throws IOException {
235  }
236
237  @Override
238  public boolean preCheckAndPut(final ObserverContext<RegionCoprocessorEnvironment> e,
239      final byte [] row, final byte [] family, final byte [] qualifier,
240      final CompareOp compareOp, final WritableByteArrayComparable comparator,
241      final Put put, final boolean result) throws IOException {
242    return result;
243  }
244
245  @Override
246  public boolean postCheckAndPut(final ObserverContext<RegionCoprocessorEnvironment> e,
247      final byte [] row, final byte [] family, final byte [] qualifier,
248      final CompareOp compareOp, final WritableByteArrayComparable comparator,
249      final Put put, final boolean result) throws IOException {
250    return result;
251  }
252
253  @Override
254  public boolean preCheckAndDelete(final ObserverContext<RegionCoprocessorEnvironment> e,
255      final byte [] row, final byte [] family, final byte [] qualifier,
256      final CompareOp compareOp, final WritableByteArrayComparable comparator,
257      final Delete delete, final boolean result) throws IOException {
258    return result;
259  }
260
261  @Override
262  public boolean postCheckAndDelete(final ObserverContext<RegionCoprocessorEnvironment> e,
263      final byte [] row, final byte [] family, final byte [] qualifier,
264      final CompareOp compareOp, final WritableByteArrayComparable comparator,
265      final Delete delete, final boolean result) throws IOException {
266    return result;
267  }
268
269  @Override
270  public Result preAppend(final ObserverContext<RegionCoprocessorEnvironment> e,
271      final Append append) throws IOException {
272    return null;
273  }
274
275  @Override
276  public Result postAppend(final ObserverContext<RegionCoprocessorEnvironment> e,
277      final Append append, final Result result) throws IOException {
278    return result;
279  }
280
281  @Override
282  public long preIncrementColumnValue(final ObserverContext<RegionCoprocessorEnvironment> e,
283      final byte [] row, final byte [] family, final byte [] qualifier,
284      final long amount, final boolean writeToWAL) throws IOException {
285    return amount;
286  }
287
288  @Override
289  public long postIncrementColumnValue(final ObserverContext<RegionCoprocessorEnvironment> e,
290      final byte [] row, final byte [] family, final byte [] qualifier,
291      final long amount, final boolean writeToWAL, long result)
292      throws IOException {
293    return result;
294  }
295
296  @Override
297  public Result preIncrement(final ObserverContext<RegionCoprocessorEnvironment> e,
298      final Increment increment) throws IOException {
299    return null;
300  }
301
302  @Override
303  public Result postIncrement(final ObserverContext<RegionCoprocessorEnvironment> e,
304      final Increment increment, final Result result) throws IOException {
305    return result;
306  }
307
308  @Override
309  public RegionScanner preScannerOpen(final ObserverContext<RegionCoprocessorEnvironment> e,
310      final Scan scan, final RegionScanner s) throws IOException {
311    return s;
312  }
313
314  @Override
315  public KeyValueScanner preStoreScannerOpen(final ObserverContext<RegionCoprocessorEnvironment> c,
316      final Store store, final Scan scan, final NavigableSet<byte[]> targetCols,
317      final KeyValueScanner s) throws IOException {
318    return s;
319  }
320
321  @Override
322  public RegionScanner postScannerOpen(final ObserverContext<RegionCoprocessorEnvironment> e,
323      final Scan scan, final RegionScanner s) throws IOException {
324    return s;
325  }
326
327  @Override
328  public boolean preScannerNext(final ObserverContext<RegionCoprocessorEnvironment> e,
329      final InternalScanner s, final List<Result> results,
330      final int limit, final boolean hasMore) throws IOException {
331    return hasMore;
332  }
333
334  @Override
335  public boolean postScannerNext(final ObserverContext<RegionCoprocessorEnvironment> e,
336      final InternalScanner s, final List<Result> results, final int limit,
337      final boolean hasMore) throws IOException {
338    return hasMore;
339  }
340
341  @Override
342  public boolean postScannerFilterRow(final ObserverContext<RegionCoprocessorEnvironment> e,
343      final InternalScanner s, final byte[] currentRow, final int offset, final short length,
344      final boolean hasMore) throws IOException {
345    return hasMore;
346  }
347
348  @Override
349  public void preScannerClose(final ObserverContext<RegionCoprocessorEnvironment> e,
350      final InternalScanner s) throws IOException {
351  }
352
353  @Override
354  public void postScannerClose(final ObserverContext<RegionCoprocessorEnvironment> e,
355      final InternalScanner s) throws IOException {
356  }
357
358  @Override
359  public void preWALRestore(ObserverContext<RegionCoprocessorEnvironment> env, HRegionInfo info,
360      HLogKey logKey, WALEdit logEdit) throws IOException {
361  }
362
363  @Override
364  public void postWALRestore(ObserverContext<RegionCoprocessorEnvironment> env,
365      HRegionInfo info, HLogKey logKey, WALEdit logEdit) throws IOException {
366  }
367
368  @Override
369  public void preBulkLoadHFile(final ObserverContext<RegionCoprocessorEnvironment> ctx,
370    List<Pair<byte[], String>> familyPaths) throws IOException {
371  }
372
373  @Override
374  public boolean postBulkLoadHFile(ObserverContext<RegionCoprocessorEnvironment> ctx,
375    List<Pair<byte[], String>> familyPaths, boolean hasLoaded) throws IOException {
376    return hasLoaded;
377  }
378
379  @Override
380  public void preLockRow(ObserverContext<RegionCoprocessorEnvironment> ctx, byte[] regionName,
381      byte[] row) throws IOException { }
382
383  @Override
384  public void preUnlockRow(ObserverContext<RegionCoprocessorEnvironment> ctx, byte[] regionName,
385      long lockId) throws IOException { }
386
387  @Override
388  public void postLockRow(ObserverContext<RegionCoprocessorEnvironment> ctx, byte[] regionName,
389      byte[] row) throws IOException { }
390
391  @Override
392  public void postUnlockRow(ObserverContext<RegionCoprocessorEnvironment> ctx, byte[] regionName,
393      long lockId) throws IOException { }
394}