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.CellUtil;
24  import org.apache.hadoop.hbase.KeepDeletedCells;
25  import org.apache.hadoop.hbase.classification.InterfaceAudience;
26  import org.apache.hadoop.hbase.client.Scan;
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  
31  /**
32   * Query matcher for normal user scan.
33   */
34  @InterfaceAudience.Private
35  public abstract class NormalUserScanQueryMatcher extends UserScanQueryMatcher {
36  
37    /** Keeps track of deletes */
38    private final DeleteTracker deletes;
39  
40    /** True if we are doing a 'Get' Scan. Every Get is actually a one-row Scan. */
41    private final boolean get;
42  
43    /** whether time range queries can see rows "behind" a delete */
44    private final boolean seePastDeleteMarkers;
45  
46    protected NormalUserScanQueryMatcher(Scan scan, ScanInfo scanInfo, ColumnTracker columns,
47        boolean hasNullColumn, DeleteTracker deletes, long oldestUnexpiredTS, long now) {
48      super(scan, scanInfo, columns, hasNullColumn, oldestUnexpiredTS, now);
49      this.deletes = deletes;
50      this.get = scan.isGetScan();
51      this.seePastDeleteMarkers = scanInfo.getKeepDeletedCells() != KeepDeletedCells.FALSE;
52    }
53  
54    @Override
55    public MatchCode match(Cell cell) throws IOException {
56      if (filter != null && filter.filterAllRemaining()) {
57        return MatchCode.DONE_SCAN;
58      }
59      MatchCode returnCode = preCheck(cell);
60      if (returnCode != null) {
61        return returnCode;
62      }
63      long timestamp = cell.getTimestamp();
64      byte typeByte = cell.getTypeByte();
65      if (CellUtil.isDelete(typeByte)) {
66        boolean includeDeleteMarker = seePastDeleteMarkers ? tr.withinTimeRange(timestamp)
67            : tr.withinOrAfterTimeRange(timestamp);
68        if (includeDeleteMarker) {
69          this.deletes.add(cell);
70        }
71        return MatchCode.SKIP;
72      }
73      returnCode = checkDeleted(deletes, cell);
74      if (returnCode != null) {
75        return returnCode;
76      }
77      return matchColumn(cell, timestamp, typeByte);
78    }
79  
80    @Override
81    protected void reset() {
82      deletes.reset();
83    }
84  
85    @Override
86    protected boolean isGet() {
87      return get;
88    }
89  
90    public static NormalUserScanQueryMatcher create(Scan scan, ScanInfo scanInfo,
91        ColumnTracker columns, boolean hasNullColumn, long oldestUnexpiredTS, long now,
92        RegionCoprocessorHost regionCoprocessorHost) throws IOException {
93      DeleteTracker deletes = instantiateDeleteTracker(regionCoprocessorHost);
94      if (scan.isReversed()) {
95        if (scan.includeStopRow()) {
96          return new NormalUserScanQueryMatcher(scan, scanInfo, columns, hasNullColumn, deletes,
97              oldestUnexpiredTS, now) {
98  
99            @Override
100           protected boolean moreRowsMayExistsAfter(int cmpToStopRow) {
101             return cmpToStopRow >= 0;
102           }
103         };
104       } else {
105         return new NormalUserScanQueryMatcher(scan, scanInfo, columns, hasNullColumn, deletes,
106             oldestUnexpiredTS, now) {
107 
108           @Override
109           protected boolean moreRowsMayExistsAfter(int cmpToStopRow) {
110             return cmpToStopRow > 0;
111           }
112         };
113       }
114     } else {
115       if (scan.includeStopRow()) {
116         return new NormalUserScanQueryMatcher(scan, scanInfo, columns, hasNullColumn, deletes,
117             oldestUnexpiredTS, now) {
118 
119           @Override
120           protected boolean moreRowsMayExistsAfter(int cmpToStopRow) {
121             return cmpToStopRow <= 0;
122           }
123         };
124       } else {
125         return new NormalUserScanQueryMatcher(scan, scanInfo, columns, hasNullColumn, deletes,
126             oldestUnexpiredTS, now) {
127 
128           @Override
129           protected boolean moreRowsMayExistsAfter(int cmpToStopRow) {
130             return cmpToStopRow < 0;
131           }
132         };
133       }
134     }
135   }
136 }