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  /** Returns The RegionInfo for this scanner. */
035  RegionInfo getRegionInfo();
036
037  /**
038   * @return True if a filter indicates that this scanner will return no further rows.
039   * @throws IOException in case of I/O failure on a filter.
040   */
041  boolean isFilterDone() throws IOException;
042
043  /**
044   * Do a reseek to the required row. Should not be used to seek to a key which may come before the
045   * current position. Always seeks to the beginning of a row boundary. nn * if row is null
046   */
047  boolean reseek(byte[] row) throws IOException;
048
049  /**
050   * @return The preferred max buffersize. See
051   *         {@link org.apache.hadoop.hbase.client.Scan#setMaxResultSize(long)}
052   */
053  long getMaxResultSize();
054
055  /** Returns The Scanner's MVCC readPt see {@link MultiVersionConcurrencyControl} */
056  long getMvccReadPoint();
057
058  /**
059   * @return The limit on the number of cells to retrieve on each call to next(). See
060   *         {@link org.apache.hadoop.hbase.client.Scan#setBatch(int)}
061   */
062  int getBatch();
063
064  /**
065   * @return The Scanner's {@link org.apache.hadoop.hbase.client.Scan#ID_ATRIBUTE} value, or null if
066   *         not set.
067   */
068  default String getOperationId() {
069    return null;
070  }
071
072  /**
073   * Grab the next row's worth of values. This is a special internal method to be called from
074   * coprocessor hooks to avoid expensive setup. Caller must set the thread's readpoint, start and
075   * close a region operation, an synchronize on the scanner object. Caller should maintain and
076   * update metrics. See {@link #nextRaw(List, ScannerContext)}
077   * @param result return output array
078   * @return true if more rows exist after this one, false if scanner is done
079   * @throws IOException e
080   */
081  boolean nextRaw(List<Cell> result) throws IOException;
082
083  /**
084   * Grab the next row's worth of values. The {@link ScannerContext} is used to enforce and track
085   * any limits associated with this call. Any progress that exists in the {@link ScannerContext}
086   * prior to calling this method will be LOST if {@link ScannerContext#getKeepProgress()} is false.
087   * Upon returning from this method, the {@link ScannerContext} will contain information about the
088   * progress made towards the limits. This is a special internal method to be called from
089   * coprocessor hooks to avoid expensive setup. Caller must set the thread's readpoint, start and
090   * close a region operation, an synchronize on the scanner object. Example: <code>
091   * HRegion region = ...;
092   * RegionScanner scanner = ...
093   * MultiVersionConcurrencyControl.setThreadReadPoint(scanner.getMvccReadPoint());
094   * region.startRegionOperation();
095   * try {
096   *   synchronized(scanner) {
097   *     ...
098   *     boolean moreRows = scanner.nextRaw(values);
099   *     ...
100   *   }
101   * } finally {
102   *   region.closeRegionOperation();
103   * }
104   * </code>
105   * @param result         return output array
106   * @param scannerContext The {@link ScannerContext} instance encapsulating all limits that should
107   *                       be tracked during calls to this method. The progress towards these limits
108   *                       can be tracked within this instance.
109   * @return true if more rows exist after this one, false if scanner is done
110   * @throws IOException e
111   */
112  boolean nextRaw(List<Cell> result, ScannerContext scannerContext) throws IOException;
113}