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 * <p>
35 * This class is utilized by {@link ScanQueryMatcher} through two methods:
36 * <ul><li>{@link #checkColumn} is called when a Put satisfies all other
37 * conditions of the query. This method returns a {@link org.apache.hadoop.hbase.regionserver.ScanQueryMatcher.MatchCode} to define
38 * what action should be taken.
39 * <li>{@link #update} is called at the end of every StoreFile or memstore.
40 * <p>
41 * This class is NOT thread-safe as queries are never multi-threaded
42 */
43 public interface ColumnTracker {
44 /**
45 * Keeps track of the number of versions for the columns asked for
46 * @param bytes
47 * @param offset
48 * @param length
49 * @param ttl The timeToLive to enforce.
50 * @param ignoreCount indicates if the KV needs to be excluded while counting
51 * (used during compactions. We only count KV's that are older than all the
52 * scanners' read points.)
53 * @return The match code instance.
54 * @throws IOException in case there is an internal consistency problem
55 * caused by a data corruption.
56 */
57 public ScanQueryMatcher.MatchCode checkColumn(byte [] bytes, int offset,
58 int length, long ttl, boolean ignoreCount) throws IOException;
59
60 /**
61 * Updates internal variables in between files
62 */
63 public void update();
64
65 /**
66 * Resets the Matcher
67 */
68 public void reset();
69
70 /**
71 *
72 * @return <code>true</code> when done.
73 */
74 public boolean done();
75
76 /**
77 * Used by matcher and scan/get to get a hint of the next column
78 * to seek to after checkColumn() returns SKIP. Returns the next interesting
79 * column we want, or NULL there is none (wildcard scanner).
80 *
81 * Implementations aren't required to return anything useful unless the most recent
82 * call was to checkColumn() and the return code was SKIP. This is pretty implementation
83 * detail-y, but optimizations are like that.
84 *
85 * @return null, or a ColumnCount that we should seek to
86 */
87 public ColumnCount getColumnHint();
88
89 /**
90 * Retrieve the MatchCode for the next row or column
91 */
92 public MatchCode getNextRowOrNextColumn(byte[] bytes, int offset,
93 int qualLength);
94
95 /**
96 * Give the tracker a chance to declare it's done based on only the timestamp
97 * to allow an early out.
98 *
99 * @param timestamp
100 * @return <code>true</code> to early out based on timestamp.
101 */
102 public boolean isDone(long timestamp);
103 }