1   package org.apache.hadoop.hbase.regionserver;
2   
3   import java.io.IOException;
4   import java.util.Collections;
5   import java.util.List;
6   import java.util.NavigableSet;
7   
8   import org.apache.hadoop.hbase.HConstants;
9   import org.apache.hadoop.hbase.client.Scan;
10  import org.apache.hadoop.hbase.client.TestFromClientSideWithCoprocessor;
11  import org.apache.hadoop.hbase.coprocessor.BaseRegionObserver;
12  import org.apache.hadoop.hbase.coprocessor.ObserverContext;
13  import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
14  
15  /**
16   * RegionObserver that just reimplements the default behavior,
17   * in order to validate that all the necessary APIs for this are public
18   * This observer is also used in {@link TestFromClientSideWithCoprocessor} and
19   * {@link TestCompactionWithCoprocessor} to make sure that a wide range
20   * of functionality still behaves as expected.
21   */
22  public class NoOpScanPolicyObserver extends BaseRegionObserver {
23    /**
24     * Reimplement the default behavior
25     */
26    @Override
27    public InternalScanner preFlushScannerOpen(final ObserverContext<RegionCoprocessorEnvironment> c,
28        Store store, KeyValueScanner memstoreScanner, InternalScanner s) throws IOException {
29      Store.ScanInfo oldSI = store.getScanInfo();
30      Store.ScanInfo scanInfo = new Store.ScanInfo(store.getFamily(), oldSI.getTtl(),
31          oldSI.getTimeToPurgeDeletes(), oldSI.getComparator());
32      Scan scan = new Scan();
33      scan.setMaxVersions(oldSI.getMaxVersions());
34      return new StoreScanner(store, scanInfo, scan, Collections.singletonList(memstoreScanner),
35          ScanType.MINOR_COMPACT, store.getHRegion().getSmallestReadPoint(),
36          HConstants.OLDEST_TIMESTAMP);
37    }
38  
39    /**
40     * Reimplement the default behavior
41     */
42    @Override
43    public InternalScanner preCompactScannerOpen(final ObserverContext<RegionCoprocessorEnvironment> c,
44        Store store, List<? extends KeyValueScanner> scanners, ScanType scanType, long earliestPutTs,
45        InternalScanner s) throws IOException {
46      // this demonstrates how to override the scanners default behavior
47      Store.ScanInfo oldSI = store.getScanInfo();
48      Store.ScanInfo scanInfo = new Store.ScanInfo(store.getFamily(), oldSI.getTtl(),
49          oldSI.getTimeToPurgeDeletes(), oldSI.getComparator());
50      Scan scan = new Scan();
51      scan.setMaxVersions(oldSI.getMaxVersions());
52      return new StoreScanner(store, scanInfo, scan, scanners, scanType, store.getHRegion()
53          .getSmallestReadPoint(), earliestPutTs);
54    }
55  
56    @Override
57    public KeyValueScanner preStoreScannerOpen(final ObserverContext<RegionCoprocessorEnvironment> c,
58        Store store, final Scan scan, final NavigableSet<byte[]> targetCols, KeyValueScanner s)
59        throws IOException {
60      return new StoreScanner(store, store.getScanInfo(), scan, targetCols);
61    }
62  }