001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.regionserver.querymatcher;
019
020import java.io.IOException;
021
022import org.apache.hadoop.hbase.Cell;
023import org.apache.hadoop.hbase.PrivateCellUtil;
024import org.apache.yetus.audience.InterfaceAudience;
025import org.apache.hadoop.hbase.regionserver.ScanInfo;
026
027/**
028 * Query matcher for major compaction.
029 */
030@InterfaceAudience.Private
031public class MajorCompactionScanQueryMatcher extends DropDeletesCompactionScanQueryMatcher {
032
033  public MajorCompactionScanQueryMatcher(ScanInfo scanInfo, DeleteTracker deletes,
034      ColumnTracker columns, long readPointToUse, long earliestPutTs, long oldestUnexpiredTS,
035      long now) {
036    super(scanInfo, deletes, columns, readPointToUse, earliestPutTs, oldestUnexpiredTS, now);
037  }
038
039  @Override
040  public MatchCode match(Cell cell) throws IOException {
041    MatchCode returnCode = preCheck(cell);
042    if (returnCode != null) {
043      return returnCode;
044    }
045    long timestamp = cell.getTimestamp();
046    long mvccVersion = cell.getSequenceId();
047    byte typeByte = cell.getTypeByte();
048
049    // The delete logic is pretty complicated now.
050    // This is corroborated by the following:
051    // 1. The store might be instructed to keep deleted rows around.
052    // 2. A scan can optionally see past a delete marker now.
053    // 3. If deleted rows are kept, we have to find out when we can
054    // remove the delete markers.
055    // 4. Family delete markers are always first (regardless of their TS)
056    // 5. Delete markers should not be counted as version
057    // 6. Delete markers affect puts of the *same* TS
058    // 7. Delete marker need to be version counted together with puts
059    // they affect
060    //
061    if (PrivateCellUtil.isDelete(typeByte)) {
062      if (mvccVersion > maxReadPointToTrackVersions) {
063        // We can not drop this delete marker yet, and also we should not use this delete marker to
064        // mask any cell yet.
065        return MatchCode.INCLUDE;
066      }
067      trackDelete(cell);
068      returnCode = tryDropDelete(cell);
069      if (returnCode != null) {
070        return returnCode;
071      }
072    } else {
073      returnCode = checkDeleted(deletes, cell);
074      if (returnCode != null) {
075        return returnCode;
076      }
077    }
078    // Skip checking column since we do not remove column during compaction.
079    return columns.checkVersions(cell, timestamp, typeByte,
080      mvccVersion > maxReadPointToTrackVersions);
081  }
082}