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.Cell;
25 import org.apache.hadoop.hbase.HConstants;
26 import org.apache.hadoop.hbase.KeyValueUtil;
27 import org.apache.hadoop.hbase.classification.InterfaceAudience;
28 import org.apache.hadoop.hbase.client.Scan;
29 import org.apache.hadoop.hbase.regionserver.HRegion.RegionScannerImpl;
30 import org.apache.hadoop.hbase.util.Bytes;
31
32
33
34
35
36 @InterfaceAudience.Private
37 class ReversedRegionScannerImpl extends RegionScannerImpl {
38
39
40
41
42
43
44
45 ReversedRegionScannerImpl(Scan scan,
46 List<KeyValueScanner> additionalScanners, HRegion region)
47 throws IOException {
48 region.super(scan, additionalScanners, region);
49 }
50
51 @Override
52 protected void initializeKVHeap(List<KeyValueScanner> scanners,
53 List<KeyValueScanner> joinedScanners, HRegion region) throws IOException {
54 this.storeHeap = new ReversedKeyValueHeap(scanners, region.getComparator());
55 if (!joinedScanners.isEmpty()) {
56 this.joinedHeap = new ReversedKeyValueHeap(joinedScanners,
57 region.getComparator());
58 }
59 }
60
61 protected boolean shouldStop(Cell currentRowCell) {
62 if (currentRowCell == null) {
63 return true;
64 }
65 if (stopRow == null || Bytes.equals(stopRow, HConstants.EMPTY_START_ROW)) {
66 return false;
67 }
68 int c = region.getComparator().compareRows(currentRowCell, stopRow, 0, stopRow.length);
69 return c < 0 || (c == 0 && !includeStopRow);
70 }
71
72 @Override
73 protected boolean nextRow(ScannerContext scannerContext, byte[] currentRow, int offset,
74 short length) throws IOException {
75 assert super.joinedContinuationRow == null : "Trying to go to next row during joinedHeap read.";
76 byte row[] = new byte[length];
77 System.arraycopy(currentRow, offset, row, 0, length);
78 this.storeHeap.seekToPreviousRow(KeyValueUtil.createFirstOnRow(row));
79 resetFilters();
80
81
82 if (this.region.getCoprocessorHost() != null) {
83 return this.region.getCoprocessorHost().postScannerFilterRow(this,
84 currentRow, offset, length);
85 }
86 return true;
87 }
88
89 }