View Javadoc

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  
19  package org.apache.hadoop.hbase.regionserver;
20  
21  import java.io.IOException;
22  import java.util.Collections;
23  import java.util.List;
24  import java.util.NavigableSet;
25  
26  import org.apache.hadoop.hbase.HConstants;
27  import org.apache.hadoop.hbase.client.Scan;
28  import org.apache.hadoop.hbase.client.TestFromClientSideWithCoprocessor;
29  import org.apache.hadoop.hbase.coprocessor.BaseRegionObserver;
30  import org.apache.hadoop.hbase.coprocessor.ObserverContext;
31  import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
32  
33  /**
34   * RegionObserver that just reimplements the default behavior,
35   * in order to validate that all the necessary APIs for this are public
36   * This observer is also used in {@link TestFromClientSideWithCoprocessor} and
37   * {@link TestCompactionWithCoprocessor} to make sure that a wide range
38   * of functionality still behaves as expected.
39   */
40  public class NoOpScanPolicyObserver extends BaseRegionObserver {
41    /**
42     * Reimplement the default behavior
43     */
44    @Override
45    public InternalScanner preFlushScannerOpen(final ObserverContext<RegionCoprocessorEnvironment> c,
46        Store store, KeyValueScanner memstoreScanner, InternalScanner s) throws IOException {
47      ScanInfo oldSI = store.getScanInfo();
48      ScanInfo scanInfo = new ScanInfo(oldSI.getConfiguration(), 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, Collections.singletonList(memstoreScanner),
53          ScanType.COMPACT_RETAIN_DELETES, store.getSmallestReadPoint(), 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      ScanInfo oldSI = store.getScanInfo();
65      ScanInfo scanInfo = new ScanInfo(oldSI.getConfiguration(), 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, 
70          store.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      Region r = c.getEnvironment().getRegion();
78      return scan.isReversed() ? new ReversedStoreScanner(store,
79          store.getScanInfo(), scan, targetCols, r.getReadpoint(scan
80              .getIsolationLevel())) : new StoreScanner(store,
81          store.getScanInfo(), scan, targetCols, r.getReadpoint(scan
82              .getIsolationLevel()));
83    }
84  }