1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.regionserver;
19  
20  import java.io.IOException;
21  import java.util.Collections;
22  import java.util.List;
23  import java.util.NavigableSet;
24  
25  import org.apache.hadoop.hbase.HConstants;
26  import org.apache.hadoop.hbase.client.Scan;
27  import org.apache.hadoop.hbase.client.TestFromClientSideWithCoprocessor;
28  import org.apache.hadoop.hbase.coprocessor.BaseRegionObserver;
29  import org.apache.hadoop.hbase.coprocessor.ObserverContext;
30  import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
31  
32  /**
33   * RegionObserver that just reimplements the default behavior,
34   * in order to validate that all the necessary APIs for this are public
35   * This observer is also used in {@link TestFromClientSideWithCoprocessor} and
36   * {@link TestCompactionWithCoprocessor} to make sure that a wide range
37   * of functionality still behaves as expected.
38   */
39  public class NoOpScanPolicyObserver extends BaseRegionObserver {
40    /**
41     * Reimplement the default behavior
42     */
43    @Override
44    public InternalScanner preFlushScannerOpen(final ObserverContext<RegionCoprocessorEnvironment> c,
45        Store store, KeyValueScanner memstoreScanner, InternalScanner s) throws IOException {
46      Store.ScanInfo oldSI = store.getScanInfo();
47      Store.ScanInfo scanInfo = new Store.ScanInfo(store.getFamily(), oldSI.getTtl(),
48          oldSI.getTimeToPurgeDeletes(), oldSI.getComparator());
49      Scan scan = new Scan();
50      scan.setMaxVersions(oldSI.getMaxVersions());
51      return new StoreScanner(store, scanInfo, scan, Collections.singletonList(memstoreScanner),
52          ScanType.MINOR_COMPACT, store.getHRegion().getSmallestReadPoint(),
53          HConstants.OLDEST_TIMESTAMP);
54    }
55  
56    /**
57     * Reimplement the default behavior
58     */
59    @Override
60    public InternalScanner preCompactScannerOpen(final ObserverContext<RegionCoprocessorEnvironment> c,
61        Store store, List<? extends KeyValueScanner> scanners, ScanType scanType, long earliestPutTs,
62        InternalScanner s) throws IOException {
63      // this demonstrates how to override the scanners default behavior
64      Store.ScanInfo oldSI = store.getScanInfo();
65      Store.ScanInfo scanInfo = new Store.ScanInfo(store.getFamily(), oldSI.getTtl(),
66          oldSI.getTimeToPurgeDeletes(), oldSI.getComparator());
67      Scan scan = new Scan();
68      scan.setMaxVersions(oldSI.getMaxVersions());
69      return new StoreScanner(store, scanInfo, scan, scanners, scanType, store.getHRegion()
70          .getSmallestReadPoint(), earliestPutTs);
71    }
72  
73    @Override
74    public KeyValueScanner preStoreScannerOpen(final ObserverContext<RegionCoprocessorEnvironment> c,
75        Store store, final Scan scan, final NavigableSet<byte[]> targetCols, KeyValueScanner s)
76        throws IOException {
77      return new StoreScanner(store, store.getScanInfo(), scan, targetCols);
78    }
79  }