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