1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
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  
31  
32  
33  @InterfaceAudience.Private
34  class ReversedRegionScannerImpl extends RegionScannerImpl {
35  
36    
37  
38  
39  
40  
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      
75      if (this.region.getCoprocessorHost() != null) {
76        return this.region.getCoprocessorHost().postScannerFilterRow(this,
77            currentRow, offset, length);
78      }
79      return true;
80    }
81  
82  }