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.classification.InterfaceAudience;
25  import org.apache.hadoop.hbase.Cell;
26  import org.apache.hadoop.hbase.CellUtil;
27  import org.apache.hadoop.hbase.KeyValueUtil;
28  import org.apache.hadoop.hbase.client.Scan;
29  import org.apache.hadoop.hbase.regionserver.HRegion.RegionScannerImpl;
30  
31  /**
32   * ReversibleRegionScannerImpl extends from RegionScannerImpl, and is used to
33   * support reversed scanning.
34   */
35  @InterfaceAudience.Private
36  class ReversedRegionScannerImpl extends RegionScannerImpl {
37  
38    /**
39     * @param scan
40     * @param additionalScanners
41     * @param region
42     * @throws IOException
43     */
44    ReversedRegionScannerImpl(Scan scan,
45        List<KeyValueScanner> additionalScanners, HRegion region, boolean copyCellsFromSharedMem)
46        throws IOException {
47      region.super(scan, additionalScanners, region, copyCellsFromSharedMem);
48    }
49  
50    @Override
51    protected void initializeKVHeap(List<KeyValueScanner> scanners,
52        List<KeyValueScanner> joinedScanners, HRegion region) throws IOException {
53      this.storeHeap = new ReversedKeyValueHeap(scanners, comparator);
54      if (!joinedScanners.isEmpty()) {
55        this.joinedHeap = new ReversedKeyValueHeap(joinedScanners,
56            comparator);
57      }
58    }
59  
60    @Override
61    protected boolean isStopRow(Cell currentRowCell) {
62      return currentRowCell == null
63          || (super.stopRow != null && comparator.compareRows(currentRowCell, stopRow, 0,
64              stopRow.length) <= super.isScan);
65    }
66  
67    @Override
68    protected boolean nextRow(ScannerContext scannerContext, Cell curRowCell)
69        throws IOException {
70      assert super.joinedContinuationRow == null : "Trying to go to next row during joinedHeap read.";
71      byte[] row = new byte[curRowCell.getRowLength()];
72      CellUtil.copyRowTo(curRowCell, row, 0);
73      this.storeHeap.seekToPreviousRow(KeyValueUtil.createFirstOnRow(row));
74      resetFilters();
75      // Calling the hook in CP which allows it to do a fast forward
76      if (this.region.getCoprocessorHost() != null) {
77        return this.region.getCoprocessorHost().postScannerFilterRow(this, curRowCell);
78      }
79      return true;
80    }
81  
82  }