001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.regionserver;
019
020import java.io.IOException;
021import java.util.List;
022import org.apache.hadoop.hbase.Cell;
023import org.apache.hadoop.hbase.HBaseInterfaceAudience;
024import org.apache.hadoop.hbase.client.RegionInfo;
025import org.apache.yetus.audience.InterfaceAudience;
026import org.apache.yetus.audience.InterfaceStability;
027
028/**
029 * RegionScanner describes iterators over rows in an HRegion.
030 */
031@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
032@InterfaceStability.Evolving
033public interface RegionScanner extends InternalScanner {
034  /**
035   * @return The RegionInfo for this scanner.
036   */
037  RegionInfo getRegionInfo();
038
039  /**
040   * @return True if a filter indicates that this scanner will return no further rows.
041   * @throws IOException in case of I/O failure on a filter.
042   */
043  boolean isFilterDone() throws IOException;
044
045  /**
046   * Do a reseek to the required row. Should not be used to seek to a key which may come before the
047   * current position. Always seeks to the beginning of a row boundary. nn * if row is null
048   */
049  boolean reseek(byte[] row) throws IOException;
050
051  /**
052   * @return The preferred max buffersize. See
053   *         {@link org.apache.hadoop.hbase.client.Scan#setMaxResultSize(long)}
054   */
055  long getMaxResultSize();
056
057  /**
058   * @return The Scanner's MVCC readPt see {@link MultiVersionConcurrencyControl}
059   */
060  long getMvccReadPoint();
061
062  /**
063   * @return The limit on the number of cells to retrieve on each call to next(). See
064   *         {@link org.apache.hadoop.hbase.client.Scan#setBatch(int)}
065   */
066  int getBatch();
067
068  /**
069   * @return The Scanner's {@link org.apache.hadoop.hbase.client.Scan#ID_ATRIBUTE} value, or null if
070   *         not set.
071   */
072  default String getOperationId() {
073    return null;
074  }
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
112   *                       can be 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) throws IOException;
117}