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 java.util.Set;
023import org.apache.hadoop.fs.Path;
024import org.apache.hadoop.hbase.ExtendedCell;
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  /** Returns The RegionInfo for this scanner. */
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. 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  /** Returns The Scanner's MVCC readPt see {@link MultiVersionConcurrencyControl} */
058  long getMvccReadPoint();
059
060  /**
061   * @return The limit on the number of cells to retrieve on each call to next(). See
062   *         {@link org.apache.hadoop.hbase.client.Scan#setBatch(int)}
063   */
064  int getBatch();
065
066  /**
067   * @return The Scanner's {@link org.apache.hadoop.hbase.client.Scan#ID_ATRIBUTE} value, or null if
068   *         not set.
069   */
070  default String getOperationId() {
071    return null;
072  }
073
074  /**
075   * Grab the next row's worth of values. This is a special internal method to be called from
076   * coprocessor hooks to avoid expensive setup. Caller must set the thread's readpoint, start and
077   * close a region operation, an synchronize on the scanner object. Caller should maintain and
078   * update metrics. See {@link #nextRaw(List, ScannerContext)}
079   * @param result return output array
080   * @return true if more rows exist after this one, false if scanner is done
081   * @throws IOException e
082   */
083  boolean nextRaw(List<? super ExtendedCell> result) throws IOException;
084
085  /**
086   * Grab the next row's worth of values. The {@link ScannerContext} is used to enforce and track
087   * any limits associated with this call. Any progress that exists in the {@link ScannerContext}
088   * prior to calling this method will be LOST if {@link ScannerContext#getKeepProgress()} is false.
089   * Upon returning from this method, the {@link ScannerContext} will contain information about the
090   * progress made towards the limits. This is a special internal method to be called from
091   * coprocessor hooks to avoid expensive setup. Caller must set the thread's readpoint, start and
092   * close a region operation, an synchronize on the scanner object. Example: <code>
093   * HRegion region = ...;
094   * RegionScanner scanner = ...
095   * MultiVersionConcurrencyControl.setThreadReadPoint(scanner.getMvccReadPoint());
096   * region.startRegionOperation();
097   * try {
098   *   synchronized(scanner) {
099   *     ...
100   *     boolean moreRows = scanner.nextRaw(values);
101   *     ...
102   *   }
103   * } finally {
104   *   region.closeRegionOperation();
105   * }
106   * </code>
107   * @param result         return output array
108   * @param scannerContext The {@link ScannerContext} instance encapsulating all limits that should
109   *                       be tracked during calls to this method. The progress towards these limits
110   *                       can be tracked within this instance.
111   * @return true if more rows exist after this one, false if scanner is done
112   * @throws IOException e
113   */
114  boolean nextRaw(List<? super ExtendedCell> result, ScannerContext scannerContext)
115    throws IOException;
116
117  /**
118   * Returns the set of store file paths that were successfully read by this scanner. Typically
119   * populated only after the scanner is closed.
120   */
121  Set<Path> getFilesRead();
122}