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 org.apache.yetus.audience.InterfaceAudience;
021import org.apache.hadoop.hbase.Cell;
022import org.apache.hadoop.hbase.CellComparator;
023import org.apache.hadoop.hbase.regionserver.ShipperListener;
024
025/**
026 * This interface is used for the tracking and enforcement of Deletes during the course of a Get or
027 * Scan operation.
028 * <p>
029 * This class is utilized through three methods:
030 * <ul>
031 * <li>{@link #add} when encountering a Delete</li>
032 * <li>{@link #isDeleted} when checking if a Put Cell has been deleted</li>
033 * <li>{@link #update} when reaching the end of a StoreFile</li>
034 * </ul>
035 */
036@InterfaceAudience.Private
037public interface DeleteTracker extends ShipperListener {
038
039  /**
040   * Add the specified cell to the list of deletes to check against for this row operation.
041   * <p>
042   * This is called when a Delete is encountered in a StoreFile.
043   * @param cell - the delete cell
044   */
045  void add(Cell cell);
046
047  /**
048   * Check if the specified cell buffer has been deleted by a previously seen delete.
049   * @param cell - current cell to check if deleted by a previously seen delete
050   * @return deleteResult The result tells whether the Cell is deleted and why
051   */
052  DeleteResult isDeleted(Cell cell);
053
054  /**
055   * @return true if there are no current delete, false otherwise
056   */
057  boolean isEmpty();
058
059  /**
060   * Called at the end of every StoreFile.
061   * <p>
062   * Many optimized implementations of Trackers will require an update at when the end of each
063   * StoreFile is reached.
064   */
065  void update();
066
067  /**
068   * Called between rows.
069   * <p>
070   * This clears everything as if a new DeleteTracker was instantiated.
071   */
072  void reset();
073
074  /**
075   * Returns codes for delete result. The codes tell the ScanQueryMatcher whether the kv is deleted
076   * and why. Based on the delete result, the ScanQueryMatcher will decide the next operation
077   */
078  enum DeleteResult {
079    FAMILY_DELETED, // The Cell is deleted by a delete family.
080    FAMILY_VERSION_DELETED, // The Cell is deleted by a delete family version.
081    COLUMN_DELETED, // The Cell is deleted by a delete column.
082    VERSION_DELETED, // The Cell is deleted by a version delete.
083    NOT_DELETED,
084    VERSION_MASKED  // The Cell is masked by max number of versions which is considered as
085                    // deleted in strong semantics of versions(See MvccTracker)
086  }
087
088  /**
089   * Return the comparator passed to this delete tracker
090   * @return the cell comparator
091   */
092  CellComparator getCellComparator();
093
094}