1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.client;
19
20 import static org.apache.hadoop.hbase.client.ConnectionUtils.filterCells;
21
22 import java.io.IOException;
23 import java.util.List;
24
25 import org.apache.hadoop.hbase.Cell;
26 import org.apache.hadoop.hbase.CellUtil;
27 import org.apache.hadoop.hbase.classification.InterfaceAudience;
28
29
30
31
32
33
34
35 @InterfaceAudience.Private
36 class AllowPartialScanResultCache extends ScanResultCache {
37
38
39
40 private Cell lastCell;
41
42 private boolean lastResultPartial;
43
44 public AllowPartialScanResultCache(List<Result> cache) {
45 super(cache);
46 }
47
48 private void recordLastResult(Result result) {
49 lastCell = result.rawCells()[result.rawCells().length - 1];
50 lastResultPartial = result.mayHaveMoreCellsInRow();
51 }
52
53 @Override
54 public void loadResultsToCache(Result[] results, boolean isHeartbeatMessage) throws IOException {
55 if (results.length == 0) {
56 if (!isHeartbeatMessage && lastResultPartial) {
57
58
59 numberOfCompleteRows++;
60 }
61 return;
62 }
63 int i;
64 for (i = 0; i < results.length; i++) {
65 Result r = filterCells(results[i], lastCell);
66 if (r != null) {
67 results[i] = r;
68 break;
69 }
70 }
71 if (i == results.length) {
72 return;
73 }
74 if (lastResultPartial && !CellUtil.matchingRow(lastCell, results[0].getRow())) {
75
76 numberOfCompleteRows++;
77 }
78 recordLastResult(results[results.length - 1]);
79 addResultArrayToCache(results, i, results.length);
80 }
81
82 @Override
83 protected void checkUpdateNumberOfCompleteRowsAndCache(Result rs) {
84 if (!rs.mayHaveMoreCellsInRow()) {
85 numberOfCompleteRows++;
86 }
87 addResultToCache(rs);
88 }
89
90 @Override
91 public void clear() {
92
93 super.clear();
94 }
95 }