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.Cell; 022import org.apache.hadoop.hbase.regionserver.ShipperListener; 023import org.apache.hadoop.hbase.regionserver.querymatcher.ScanQueryMatcher.MatchCode; 024import org.apache.yetus.audience.InterfaceAudience; 025 026/** 027 * Implementing classes of this interface will be used for the tracking and enforcement of columns 028 * and numbers of versions and timeToLive during the course of a Get or Scan operation. 029 * <p> 030 * Currently there are two different types of Store/Family-level queries. 031 * <ul> 032 * <li>{@link ExplicitColumnTracker} is used when the query specifies one or more column qualifiers 033 * to return in the family.</li> 034 * <li>{@link ScanWildcardColumnTracker} is used when no columns are explicitly specified.</li> 035 * </ul> 036 * <p> 037 * This class is utilized by {@link ScanQueryMatcher} mainly through two methods: 038 * <ul> 039 * <li>{@link #checkColumn} is called when a Put satisfies all other conditions of the query.</li> 040 * <li>{@link #getNextRowOrNextColumn} is called whenever ScanQueryMatcher believes that the current 041 * column should be skipped (by timestamp, filter etc.)</li> 042 * </ul> 043 * <p> 044 * These two methods returns a 045 * {@link org.apache.hadoop.hbase.regionserver.querymatcher.ScanQueryMatcher.MatchCode} to define 046 * what action should be taken. 047 * <p> 048 * This class is NOT thread-safe as queries are never multi-threaded 049 */ 050@InterfaceAudience.Private 051public interface ColumnTracker extends ShipperListener { 052 053 /** 054 * Checks if the column is present in the list of requested columns by returning the match code 055 * instance. It does not check against the number of versions for the columns asked for. To do the 056 * version check, one has to call {@link #checkVersions(Cell, long, byte, boolean)} method based 057 * on the return type (INCLUDE) of this method. The values that can be returned by this method are 058 * {@link MatchCode#INCLUDE}, {@link MatchCode#SEEK_NEXT_COL} and {@link MatchCode#SEEK_NEXT_ROW}. 059 * @param cell a cell with the column to match against 060 * @param type The type of the Cell 061 * @return The match code instance. 062 * @throws IOException in case there is an internal consistency problem caused by a data 063 * corruption. 064 */ 065 ScanQueryMatcher.MatchCode checkColumn(Cell cell, byte type) throws IOException; 066 067 /** 068 * Keeps track of the number of versions for the columns asked for. It assumes that the user has 069 * already checked if the cell needs to be included by calling the 070 * {@link #checkColumn(Cell, byte)} method. The enum values returned by this method are 071 * {@link MatchCode#SKIP}, {@link MatchCode#INCLUDE}, {@link MatchCode#INCLUDE_AND_SEEK_NEXT_COL} 072 * and {@link MatchCode#INCLUDE_AND_SEEK_NEXT_ROW}. Implementations which include all the columns 073 * could just return {@link MatchCode#INCLUDE} in the {@link #checkColumn(Cell, byte)} method and 074 * perform all the operations in this checkVersions method. 075 * @param cell a cell with the column to match against 076 * @param timestamp The timestamp of the cell. 077 * @param type the type of the key value (Put/Delete) 078 * @param ignoreCount indicates if the KV needs to be excluded while counting (used during 079 * compactions. We only count KV's that are older than all the scanners' read 080 * points.) 081 * @return the scan query matcher match code instance 082 * @throws IOException in case there is an internal consistency problem caused by a data 083 * corruption. 084 */ 085 ScanQueryMatcher.MatchCode checkVersions(Cell cell, long timestamp, byte type, 086 boolean ignoreCount) throws IOException; 087 088 /** 089 * Resets the Matcher 090 */ 091 void reset(); 092 093 /** Returns <code>true</code> when done. */ 094 boolean done(); 095 096 /** 097 * Used by matcher and scan/get to get a hint of the next column to seek to after checkColumn() 098 * returns SKIP. Returns the next interesting column we want, or NULL there is none (wildcard 099 * scanner). Implementations aren't required to return anything useful unless the most recent call 100 * was to checkColumn() and the return code was SKIP. This is pretty implementation detail-y, but 101 * optimizations are like that. 102 * @return null, or a ColumnCount that we should seek to 103 */ 104 ColumnCount getColumnHint(); 105 106 /** 107 * Retrieve the MatchCode for the next row or column n 108 */ 109 MatchCode getNextRowOrNextColumn(Cell cell); 110 111 /** 112 * Give the tracker a chance to declare it's done based on only the timestamp to allow an early 113 * out. n * @return <code>true</code> to early out based on timestamp. 114 */ 115 boolean isDone(long timestamp); 116 117 /** 118 * This method is used to inform the column tracker that we are done with this column. We may get 119 * this information from external filters or timestamp range and we then need to indicate this 120 * information to tracker. It is currently implemented for ExplicitColumnTracker. n 121 */ 122 default void doneWithColumn(Cell cell) { 123 } 124}