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.Arrays;
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 implements ScanResultCache {
37
38
39
40 private Cell lastCell;
41
42 private boolean lastResultPartial;
43
44 private int numberOfCompleteRows;
45
46 private void recordLastResult(Result result) {
47 lastCell = result.rawCells()[result.rawCells().length - 1];
48 lastResultPartial = result.mayHaveMoreCellsInRow();
49 }
50
51 @Override
52 public Result[] addAndGet(Result[] results, boolean isHeartbeatMessage) throws IOException {
53 if (results.length == 0) {
54 if (!isHeartbeatMessage && lastResultPartial) {
55
56
57 numberOfCompleteRows++;
58 }
59 return EMPTY_RESULT_ARRAY;
60 }
61 int i;
62 for (i = 0; i < results.length; i++) {
63 Result r = filterCells(results[i], lastCell);
64 if (r != null) {
65 results[i] = r;
66 break;
67 }
68 }
69 if (i == results.length) {
70 return EMPTY_RESULT_ARRAY;
71 }
72 if (lastResultPartial && !CellUtil.matchingRow(lastCell, results[0].getRow())) {
73
74 numberOfCompleteRows++;
75 }
76 recordLastResult(results[results.length - 1]);
77 if (i > 0) {
78 results = Arrays.copyOfRange(results, i, results.length);
79 }
80 for (Result result : results) {
81 if (!result.mayHaveMoreCellsInRow()) {
82 numberOfCompleteRows++;
83 }
84 }
85 return results;
86 }
87
88 @Override
89 public void clear() {
90
91 }
92
93 @Override
94 public int numberOfCompleteRows() {
95 return numberOfCompleteRows;
96 }
97 }