1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 package org.apache.hadoop.hbase.regionserver.querymatcher;
19
20 import java.io.IOException;
21
22 import org.apache.hadoop.hbase.Cell;
23 import org.apache.hadoop.hbase.CellUtil;
24 import org.apache.hadoop.hbase.classification.InterfaceAudience;
25 import org.apache.hadoop.hbase.regionserver.DeleteTracker;
26 import org.apache.hadoop.hbase.regionserver.ScanInfo;
27
28 /**
29 * Query matcher for major compaction.
30 */
31 @InterfaceAudience.Private
32 public class MajorCompactionScanQueryMatcher extends DropDeletesCompactionScanQueryMatcher {
33
34 public MajorCompactionScanQueryMatcher(ScanInfo scanInfo, DeleteTracker deletes,
35 long readPointToUse, long earliestPutTs, long oldestUnexpiredTS, long now) {
36 super(scanInfo, deletes, readPointToUse, earliestPutTs, oldestUnexpiredTS, now);
37 }
38
39 @Override
40 public MatchCode match(Cell cell) throws IOException {
41 MatchCode returnCode = preCheck(cell);
42 if (returnCode != null) {
43 return returnCode;
44 }
45 long timestamp = cell.getTimestamp();
46 long mvccVersion = cell.getSequenceId();
47 byte typeByte = cell.getTypeByte();
48
49 // The delete logic is pretty complicated now.
50 // This is corroborated by the following:
51 // 1. The store might be instructed to keep deleted rows around.
52 // 2. A scan can optionally see past a delete marker now.
53 // 3. If deleted rows are kept, we have to find out when we can
54 // remove the delete markers.
55 // 4. Family delete markers are always first (regardless of their TS)
56 // 5. Delete markers should not be counted as version
57 // 6. Delete markers affect puts of the *same* TS
58 // 7. Delete marker need to be version counted together with puts
59 // they affect
60 //
61 if (CellUtil.isDelete(typeByte)) {
62 if (mvccVersion > maxReadPointToTrackVersions) {
63 // We can not drop this delete marker yet, and also we should not use this delete marker to
64 // mask any cell yet.
65 return MatchCode.INCLUDE;
66 }
67 trackDelete(cell);
68 returnCode = tryDropDelete(cell);
69 if (returnCode != null) {
70 return returnCode;
71 }
72 } else {
73 returnCode = checkDeleted(deletes, cell);
74 if (returnCode != null) {
75 return returnCode;
76 }
77 }
78 // Skip checking column since we do not remove column during compaction.
79 return columns.checkVersions(cell.getQualifierArray(), cell.getQualifierOffset(),
80 cell.getQualifierLength(), timestamp, typeByte,
81 mvccVersion > maxReadPointToTrackVersions);
82 }
83 }