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;
021import org.apache.hadoop.hbase.ExtendedCell;
022import org.apache.hadoop.hbase.PrivateCellUtil;
023import org.apache.hadoop.hbase.regionserver.ScanInfo;
024import org.apache.yetus.audience.InterfaceAudience;
025
026/**
027 * Query matcher for major compaction.
028 */
029@InterfaceAudience.Private
030public class MajorCompactionScanQueryMatcher extends DropDeletesCompactionScanQueryMatcher {
031
032  public MajorCompactionScanQueryMatcher(ScanInfo scanInfo, DeleteTracker deletes,
033    ColumnTracker columns, long readPointToUse, long earliestPutTs, long oldestUnexpiredTS,
034    long now) {
035    super(scanInfo, deletes, columns, readPointToUse, earliestPutTs, oldestUnexpiredTS, now);
036  }
037
038  @Override
039  public MatchCode match(ExtendedCell cell) throws IOException {
040    MatchCode returnCode = preCheck(cell);
041    if (returnCode != null) {
042      return returnCode;
043    }
044    long timestamp = cell.getTimestamp();
045    long mvccVersion = cell.getSequenceId();
046    byte typeByte = cell.getTypeByte();
047
048    // The delete logic is pretty complicated now.
049    // This is corroborated by the following:
050    // 1. The store might be instructed to keep deleted rows around.
051    // 2. A scan can optionally see past a delete marker now.
052    // 3. If deleted rows are kept, we have to find out when we can
053    // remove the delete markers.
054    // 4. Family delete markers are always first (regardless of their TS)
055    // 5. Delete markers should not be counted as version
056    // 6. Delete markers affect puts of the *same* TS
057    // 7. Delete marker need to be version counted together with puts
058    // they affect
059    //
060    if (PrivateCellUtil.isDelete(typeByte)) {
061      if (mvccVersion > maxReadPointToTrackVersions) {
062        // We can not drop this delete marker yet, and also we should not use this delete marker to
063        // mask any cell yet.
064        return MatchCode.INCLUDE;
065      }
066      trackDelete(cell);
067      returnCode = tryDropDelete(cell);
068      if (returnCode != null) {
069        return returnCode;
070      }
071    } else {
072      returnCode = checkDeleted(deletes, cell);
073      if (returnCode != null) {
074        return returnCode;
075      }
076    }
077    // Skip checking column since we do not remove column during compaction.
078    return columns.checkVersions(cell, timestamp, typeByte,
079      mvccVersion > maxReadPointToTrackVersions);
080  }
081}