View Javadoc

1   /**
2    * Copyright The Apache Software Foundation
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one or more
5    * contributor license agreements. See the NOTICE file distributed with this
6    * work for additional information regarding copyright ownership. The ASF
7    * licenses this file to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   *
11   * http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16   * License for the specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.hadoop.hbase.regionserver;
20  
21  import java.io.IOException;
22  import java.util.List;
23  
24  import org.apache.hadoop.hbase.KeyValueUtil;
25  import org.apache.hadoop.hbase.classification.InterfaceAudience;
26  import org.apache.hadoop.hbase.client.Scan;
27  import org.apache.hadoop.hbase.regionserver.HRegion.RegionScannerImpl;
28  
29  /**
30   * ReversibleRegionScannerImpl extends from RegionScannerImpl, and is used to
31   * support reversed scanning.
32   */
33  @InterfaceAudience.Private
34  class ReversedRegionScannerImpl extends RegionScannerImpl {
35  
36    /**
37     * @param scan
38     * @param additionalScanners
39     * @param region
40     * @throws IOException
41     */
42    ReversedRegionScannerImpl(Scan scan,
43        List<KeyValueScanner> additionalScanners, HRegion region)
44        throws IOException {
45      region.super(scan, additionalScanners, region);
46    }
47  
48    @Override
49    protected void initializeKVHeap(List<KeyValueScanner> scanners,
50        List<KeyValueScanner> joinedScanners, HRegion region) throws IOException {
51      this.storeHeap = new ReversedKeyValueHeap(scanners, region.getComparator());
52      if (!joinedScanners.isEmpty()) {
53        this.joinedHeap = new ReversedKeyValueHeap(joinedScanners,
54            region.getComparator());
55      }
56    }
57  
58    @Override
59    protected boolean isStopRow(byte[] currentRow, int offset, short length) {
60      return currentRow == null
61          || (super.stopRow != null && region.getComparator().compareRows(
62              stopRow, 0, stopRow.length, currentRow, offset, length) >= super.isScan);
63    }
64  
65    @Override
66    protected boolean nextRow(ScannerContext scannerContext, byte[] currentRow, int offset,
67        short length) throws IOException {
68      assert super.joinedContinuationRow == null : "Trying to go to next row during joinedHeap read.";
69      byte row[] = new byte[length];
70      System.arraycopy(currentRow, offset, row, 0, length);
71      this.storeHeap.seekToPreviousRow(KeyValueUtil.createFirstOnRow(row));
72      resetFilters();
73  
74      // Calling the hook in CP which allows it to do a fast forward
75      if (this.region.getCoprocessorHost() != null) {
76        return this.region.getCoprocessorHost().postScannerFilterRow(this,
77            currentRow, offset, length);
78      }
79      return true;
80    }
81  
82  }