1 /**
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19 package org.apache.hadoop.hbase.regionserver;
20
21 import java.io.IOException;
22
23 import org.apache.hadoop.classification.InterfaceAudience;
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 @InterfaceAudience.Private
50 public interface ColumnTracker {
51 /**
52 * Keeps track of the number of versions for the columns asked for
53 * @param bytes
54 * @param offset
55 * @param length
56 * @param ttl The timeToLive to enforce.
57 * @param type The type of the KeyValue
58 * @param ignoreCount indicates if the KV needs to be excluded while counting
59 * (used during compactions. We only count KV's that are older than all the
60 * scanners' read points.)
61 * @return The match code instance.
62 * @throws IOException in case there is an internal consistency problem
63 * caused by a data corruption.
64 */
65 ScanQueryMatcher.MatchCode checkColumn(byte[] bytes, int offset,
66 int length, long ttl, byte type, boolean ignoreCount)
67 throws IOException;
68
69 /**
70 * Resets the Matcher
71 */
72 void reset();
73
74 /**
75 *
76 * @return <code>true</code> when done.
77 */
78 boolean done();
79
80 /**
81 * Used by matcher and scan/get to get a hint of the next column
82 * to seek to after checkColumn() returns SKIP. Returns the next interesting
83 * column we want, or NULL there is none (wildcard scanner).
84 *
85 * Implementations aren't required to return anything useful unless the most recent
86 * call was to checkColumn() and the return code was SKIP. This is pretty implementation
87 * detail-y, but optimizations are like that.
88 *
89 * @return null, or a ColumnCount that we should seek to
90 */
91 ColumnCount getColumnHint();
92
93 /**
94 * Retrieve the MatchCode for the next row or column
95 */
96 MatchCode getNextRowOrNextColumn(
97 byte[] bytes, int offset, int qualLength
98 );
99
100 /**
101 * Give the tracker a chance to declare it's done based on only the timestamp
102 * to allow an early out.
103 *
104 * @param timestamp
105 * @return <code>true</code> to early out based on timestamp.
106 */
107 boolean isDone(long timestamp);
108 }