View Javadoc

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  import java.util.List;
23  
24  import org.apache.hadoop.hbase.Cell;
25  import org.apache.hadoop.hbase.HBaseInterfaceAudience;
26  import org.apache.hadoop.hbase.HRegionInfo;
27  import org.apache.hadoop.hbase.classification.InterfaceAudience;
28  import org.apache.hadoop.hbase.classification.InterfaceStability;
29  
30  /**
31   * RegionScanner describes iterators over rows in an HRegion.
32   */
33  @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
34  @InterfaceStability.Stable
35  public interface RegionScanner extends InternalScanner {
36    /**
37     * @return The RegionInfo for this scanner.
38     */
39    HRegionInfo getRegionInfo();
40  
41    /**
42     * @return True if a filter indicates that this scanner will return no further rows.
43     * @throws IOException in case of I/O failure on a filter.
44     */
45    boolean isFilterDone() throws IOException;
46  
47    /**
48     * Do a reseek to the required row. Should not be used to seek to a key which
49     * may come before the current position. Always seeks to the beginning of a
50     * row boundary.
51     *
52     * @throws IOException
53     * @throws IllegalArgumentException
54     *           if row is null
55     *
56     */
57    boolean reseek(byte[] row) throws IOException;
58  
59    /**
60     * @return The preferred max buffersize. See 
61     * {@link org.apache.hadoop.hbase.client.Scan#setMaxResultSize(long)}
62     */
63    long getMaxResultSize();
64  
65    /**
66     * @return The Scanner's MVCC readPt see {@link MultiVersionConsistencyControl}
67     */
68    long getMvccReadPoint();
69  
70    /**
71     * @return The limit on the number of cells to retrieve on each call to next(). See
72     *         {@link org.apache.hadoop.hbase.client.Scan#setBatch(int)}
73     */
74    int getBatch();
75  
76    /**
77     * Grab the next row's worth of values with the default limit on the number of values to return.
78     * This is a special internal method to be called from coprocessor hooks to avoid expensive setup.
79     * Caller must set the thread's readpoint, start and close a region operation, an synchronize on
80     * the scanner object. Caller should maintain and update metrics. See
81     * {@link #nextRaw(List, int, long)}
82     * @param result return output array
83     * @return a state where NextState#hasMoreValues() is true when more rows exist, false when
84     *         scanner is done.
85     * @throws IOException e
86     */
87    NextState nextRaw(List<Cell> result) throws IOException;
88  
89    /**
90     * Grab the next row's worth of values with the default limit on the number of values to return.
91     * This is a special internal method to be called from coprocessor hooks to avoid expensive setup.
92     * Caller must set the thread's readpoint, start and close a region operation, an synchronize on
93     * the scanner object. Caller should maintain and update metrics. See
94     * {@link #nextRaw(List, int, long)}
95     * @param result return output array
96     * @param limit limit on row count to get
97     * @return a state where NextState#hasMoreValues() is true when more rows exist, false when
98     *         scanner is done.
99     * @throws IOException e
100    */
101   NextState nextRaw(List<Cell> result, int limit) throws IOException;
102 
103   /**
104    * Grab the next row's worth of values with a limit on the number of values to return as well as a
105    * limit on the heap size of those values. This is a special internal method to be called from
106    * coprocessor hooks to avoid expensive setup. Caller must set the thread's readpoint, start and
107    * close a region operation, an synchronize on the scanner object. Example: <code><pre>
108    * HRegion region = ...;
109    * RegionScanner scanner = ...
110    * MultiVersionConsistencyControl.setThreadReadPoint(scanner.getMvccReadPoint());
111    * region.startRegionOperation();
112    * try {
113    *   synchronized(scanner) {
114    *     ...
115    *     boolean moreRows = scanner.nextRaw(values);
116    *     ...
117    *   }
118    * } finally {
119    *   region.closeRegionOperation();
120    * }
121    * </pre></code>
122    * @param result return output array
123    * @param limit limit on row count to get
124    * @param remainingResultSize the space remaining within the restriction on the result size.
125    *          Negative values indicate no limit
126    * @return a state where NextState#hasMoreValues() is true when more rows exist, false when
127    *         scanner is done.
128    * @throws IOException e
129    */
130   NextState nextRaw(List<Cell> result, int limit, final long remainingResultSize)
131       throws IOException;
132 }