View Javadoc

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.HConstants;
24  import org.apache.hadoop.hbase.KeepDeletedCells;
25  import org.apache.hadoop.hbase.classification.InterfaceAudience;
26  import org.apache.hadoop.hbase.filter.Filter;
27  import org.apache.hadoop.hbase.regionserver.DeleteTracker;
28  import org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost;
29  import org.apache.hadoop.hbase.regionserver.ScanInfo;
30  import org.apache.hadoop.hbase.regionserver.ScanType;
31  
32  /**
33   * Query matcher for compaction.
34   */
35  @InterfaceAudience.Private
36  public abstract class CompactionScanQueryMatcher extends ScanQueryMatcher {
37  
38    /** readPoint over which the KVs are unconditionally included */
39    protected final long maxReadPointToTrackVersions;
40  
41    /** Keeps track of deletes */
42    protected final DeleteTracker deletes;
43  
44    /** whether to return deleted rows */
45    protected final KeepDeletedCells keepDeletedCells;
46  
47    protected CompactionScanQueryMatcher(ScanInfo scanInfo, DeleteTracker deletes,
48        long readPointToUse, long oldestUnexpiredTS, long now) {
49      super(createStartKeyFromRow(HConstants.EMPTY_START_ROW, scanInfo), scanInfo,
50          new ScanWildcardColumnTracker(scanInfo.getMinVersions(), scanInfo.getMaxVersions(),
51              oldestUnexpiredTS),
52          oldestUnexpiredTS, now);
53      this.maxReadPointToTrackVersions = readPointToUse;
54      this.deletes = deletes;
55      this.keepDeletedCells = scanInfo.getKeepDeletedCells();
56    }
57  
58    @Override
59    public boolean hasNullColumnInQuery() {
60      return true;
61    }
62  
63    @Override
64    public boolean isUserScan() {
65      return false;
66    }
67  
68    @Override
69    public boolean moreRowsMayExistAfter(Cell cell) {
70      return true;
71    }
72  
73    @Override
74    public Filter getFilter() {
75      // no filter when compaction
76      return null;
77    }
78  
79    @Override
80    public Cell getNextKeyHint(Cell cell) throws IOException {
81      // no filter, so no key hint.
82      return null;
83    }
84  
85    @Override
86    protected void reset() {
87      deletes.reset();
88    }
89  
90    protected final void trackDelete(Cell cell) {
91      // If keepDeletedCells is true, then we only remove cells by versions or TTL during
92      // compaction, so we do not need to track delete here.
93      // If keepDeletedCells is TTL and the delete marker is expired, then we can make sure that the
94      // minVerions is larger than 0(otherwise we will just return at preCheck). So here we still
95      // need to track the delete marker to see if it masks some cells.
96      if (keepDeletedCells == KeepDeletedCells.FALSE
97          || (keepDeletedCells == KeepDeletedCells.TTL && cell.getTimestamp() < oldestUnexpiredTS)) {
98        deletes.add(cell);
99      }
100   }
101 
102   public static CompactionScanQueryMatcher create(ScanInfo scanInfo, ScanType scanType,
103       long readPointToUse, long earliestPutTs, long oldestUnexpiredTS, long now,
104       byte[] dropDeletesFromRow, byte[] dropDeletesToRow,
105       RegionCoprocessorHost regionCoprocessorHost) throws IOException {
106     DeleteTracker deleteTracker = instantiateDeleteTracker(regionCoprocessorHost);
107     if (dropDeletesFromRow == null) {
108       if (scanType == ScanType.COMPACT_RETAIN_DELETES) {
109         return new MinorCompactionScanQueryMatcher(scanInfo, deleteTracker, readPointToUse,
110             oldestUnexpiredTS, now);
111       } else {
112         return new MajorCompactionScanQueryMatcher(scanInfo, deleteTracker, readPointToUse,
113             earliestPutTs, oldestUnexpiredTS, now);
114       }
115     } else {
116       return new StripeCompactionScanQueryMatcher(scanInfo, deleteTracker, readPointToUse,
117           earliestPutTs, oldestUnexpiredTS, now, dropDeletesFromRow, dropDeletesToRow);
118     }
119   }
120 }