1 /** 2 * Copyright 2009 The Apache Software Foundation 3 * 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 package org.apache.hadoop.hbase.regionserver; 21 22 import java.io.IOException; 23 24 import org.apache.hadoop.hbase.regionserver.ScanQueryMatcher.MatchCode; 25 26 /** 27 * Implementing classes of this interface will be used for the tracking 28 * and enforcement of columns and numbers of versions and timeToLive during 29 * the course of a Get or Scan operation. 30 * <p> 31 * Currently there are two different types of Store/Family-level queries. 32 * <ul><li>{@link ExplicitColumnTracker} is used when the query specifies 33 * one or more column qualifiers to return in the family. 34 * <ul><li>{@link ScanWildcardColumnTracker} is used when no columns are 35 * explicitly specified. 36 * <p> 37 * This class is utilized by {@link ScanQueryMatcher} mainly through two methods: 38 * <ul><li>{@link #checkColumn} is called when a Put satisfies all other 39 * conditions of the query. 40 * <ul><li>{@link #getNextRowOrNextColumn} is called whenever ScanQueryMatcher 41 * believes that the current column should be skipped (by timestamp, filter etc.) 42 * <p> 43 * These two methods returns a 44 * {@link org.apache.hadoop.hbase.regionserver.ScanQueryMatcher.MatchCode} 45 * to define what action should be taken. 46 * <p> 47 * This class is NOT thread-safe as queries are never multi-threaded 48 */ 49 public interface ColumnTracker { 50 51 /** 52 * Checks if the column is present in the list of requested columns by returning the match code 53 * instance. It does not check against the number of versions for the columns asked for. To do the 54 * version check, one has to call {@link #checkVersions(byte[], int, int, long, byte, boolean)} 55 * method based on the return type (INCLUDE) of this method. The values that can be returned by 56 * this method are {@link MatchCode#INCLUDE}, {@link MatchCode#SEEK_NEXT_COL} and 57 * {@link MatchCode#SEEK_NEXT_ROW}. 58 * @param bytes 59 * @param offset 60 * @param length 61 * @param type The type of the KeyValue 62 * @return The match code instance. 63 * @throws IOException in case there is an internal consistency problem caused by a data 64 * corruption. 65 */ 66 ScanQueryMatcher.MatchCode checkColumn(byte[] bytes, int offset, int length, byte type) 67 throws IOException; 68 69 /** 70 * Keeps track of the number of versions for the columns asked for. It assumes that the user has 71 * already checked if the keyvalue needs to be included by calling the 72 * {@link #checkColumn(byte[], int, int, byte)} method. The enum values returned by this method 73 * are {@link MatchCode#SKIP}, {@link MatchCode#INCLUDE}, 74 * {@link MatchCode#INCLUDE_AND_SEEK_NEXT_COL} and {@link MatchCode#INCLUDE_AND_SEEK_NEXT_ROW}. 75 * Implementations which include all the columns could just return {@link MatchCode#INCLUDE} in 76 * the {@link #checkColumn(byte[], int, int, byte)} method and perform all the operations in this 77 * checkVersions method. 78 * @param type the type of the key value (Put/Delete) 79 * @param ttl The timeToLive to enforce. 80 * @param ignoreCount indicates if the KV needs to be excluded while counting (used during 81 * compactions. We only count KV's that are older than all the scanners' read points.) 82 * @return the scan query matcher match code instance 83 * @throws IOException in case there is an internal consistency problem caused by a data 84 * corruption. 85 */ 86 ScanQueryMatcher.MatchCode checkVersions(byte[] bytes, int offset, int length, long ttl, 87 byte type, boolean ignoreCount) throws IOException; 88 89 /** 90 * Resets the Matcher 91 */ 92 public void reset(); 93 94 /** 95 * 96 * @return <code>true</code> when done. 97 */ 98 public boolean done(); 99 100 /** 101 * Used by matcher and scan/get to get a hint of the next column 102 * to seek to after checkColumn() returns SKIP. Returns the next interesting 103 * column we want, or NULL there is none (wildcard scanner). 104 * 105 * Implementations aren't required to return anything useful unless the most recent 106 * call was to checkColumn() and the return code was SKIP. This is pretty implementation 107 * detail-y, but optimizations are like that. 108 * 109 * @return null, or a ColumnCount that we should seek to 110 */ 111 public ColumnCount getColumnHint(); 112 113 /** 114 * Retrieve the MatchCode for the next row or column 115 */ 116 public MatchCode getNextRowOrNextColumn(byte[] bytes, int offset, 117 int qualLength); 118 119 /** 120 * Give the tracker a chance to declare it's done based on only the timestamp 121 * to allow an early out. 122 * 123 * @param timestamp 124 * @return <code>true</code> to early out based on timestamp. 125 */ 126 public boolean isDone(long timestamp); 127 }