001/**
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements.  See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership.  The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License.  You may obtain a copy of the License at
010 *
011 *     http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 */
019package org.apache.hadoop.hbase.regionserver;
020
021import java.io.IOException;
022import java.util.List;
023
024import org.apache.hadoop.hbase.Cell;
025import org.apache.hadoop.hbase.HBaseInterfaceAudience;
026import org.apache.hadoop.hbase.client.RegionInfo;
027import org.apache.yetus.audience.InterfaceAudience;
028import org.apache.yetus.audience.InterfaceStability;
029
030/**
031 * RegionScanner describes iterators over rows in an HRegion.
032 */
033@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
034@InterfaceStability.Evolving
035public interface RegionScanner extends InternalScanner {
036  /**
037   * @return The RegionInfo for this scanner.
038   */
039  RegionInfo getRegionInfo();
040
041  /**
042   * @return True if a filter indicates that this scanner will return no further rows.
043   * @throws IOException in case of I/O failure on a filter.
044   */
045  boolean isFilterDone() throws IOException;
046
047  /**
048   * Do a reseek to the required row. Should not be used to seek to a key which
049   * may come before the current position. Always seeks to the beginning of a
050   * row boundary.
051   *
052   * @throws IOException
053   * @throws IllegalArgumentException
054   *           if row is null
055   *
056   */
057  boolean reseek(byte[] row) throws IOException;
058
059  /**
060   * @return The preferred max buffersize. See
061   * {@link org.apache.hadoop.hbase.client.Scan#setMaxResultSize(long)}
062   */
063  long getMaxResultSize();
064
065  /**
066   * @return The Scanner's MVCC readPt see {@link MultiVersionConcurrencyControl}
067   */
068  long getMvccReadPoint();
069
070  /**
071   * @return The limit on the number of cells to retrieve on each call to next(). See
072   *         {@link org.apache.hadoop.hbase.client.Scan#setBatch(int)}
073   */
074  int getBatch();
075
076  /**
077   * Grab the next row's worth of values. This is a special internal method to be called from
078   * coprocessor hooks to avoid expensive setup. Caller must set the thread's readpoint, start and
079   * close a region operation, an synchronize on the scanner object. Caller should maintain and
080   * update metrics. See {@link #nextRaw(List, ScannerContext)}
081   * @param result return output array
082   * @return true if more rows exist after this one, false if scanner is done
083   * @throws IOException e
084   */
085  boolean nextRaw(List<Cell> result) throws IOException;
086
087  /**
088   * Grab the next row's worth of values. The {@link ScannerContext} is used to enforce and track
089   * any limits associated with this call. Any progress that exists in the {@link ScannerContext}
090   * prior to calling this method will be LOST if {@link ScannerContext#getKeepProgress()} is false.
091   * Upon returning from this method, the {@link ScannerContext} will contain information about the
092   * progress made towards the limits. This is a special internal method to be called from
093   * coprocessor hooks to avoid expensive setup. Caller must set the thread's readpoint, start and
094   * close a region operation, an synchronize on the scanner object. Example: <code>
095   * HRegion region = ...;
096   * RegionScanner scanner = ...
097   * MultiVersionConcurrencyControl.setThreadReadPoint(scanner.getMvccReadPoint());
098   * region.startRegionOperation();
099   * try {
100   *   synchronized(scanner) {
101   *     ...
102   *     boolean moreRows = scanner.nextRaw(values);
103   *     ...
104   *   }
105   * } finally {
106   *   region.closeRegionOperation();
107   * }
108   * </code>
109   * @param result return output array
110   * @param scannerContext The {@link ScannerContext} instance encapsulating all limits that should
111   *          be tracked during calls to this method. The progress towards these limits can be
112   *          tracked within this instance.
113   * @return true if more rows exist after this one, false if scanner is done
114   * @throws IOException e
115   */
116  boolean nextRaw(List<Cell> result, ScannerContext scannerContext)
117      throws IOException;
118}