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.function.IntConsumer; 022import org.apache.commons.lang3.NotImplementedException; 023import org.apache.hadoop.fs.Path; 024import org.apache.hadoop.hbase.Cell; 025import org.apache.hadoop.hbase.client.Scan; 026import org.apache.yetus.audience.InterfaceAudience; 027 028/** 029 * A "non-lazy" scanner which always does a real seek operation. Most scanners are inherited from 030 * this class. 031 */ 032@InterfaceAudience.Private 033public abstract class NonLazyKeyValueScanner implements KeyValueScanner { 034 035 @Override 036 public boolean requestSeek(Cell kv, boolean forward, boolean useBloom) throws IOException { 037 return doRealSeek(this, kv, forward); 038 } 039 040 @Override 041 public boolean realSeekDone() { 042 return true; 043 } 044 045 @Override 046 public void enforceSeek() throws IOException { 047 throw new NotImplementedException("enforceSeek must not be called on a " + "non-lazy scanner"); 048 } 049 050 public static boolean doRealSeek(KeyValueScanner scanner, Cell kv, boolean forward) 051 throws IOException { 052 return forward ? scanner.reseek(kv) : scanner.seek(kv); 053 } 054 055 @Override 056 public boolean shouldUseScanner(Scan scan, HStore store, long oldestUnexpiredTS) { 057 // No optimizations implemented by default. 058 return true; 059 } 060 061 @Override 062 public boolean isFileScanner() { 063 // Not a file by default. 064 return false; 065 } 066 067 @Override 068 public void recordBlockSize(IntConsumer blockSizeConsumer) { 069 // do nothing 070 } 071 072 @Override 073 public Path getFilePath() { 074 // Not a file by default. 075 return null; 076 } 077 078 @Override 079 public Cell getNextIndexedKey() { 080 return null; 081 } 082 083 @Override 084 public void shipped() throws IOException { 085 // do nothing 086 } 087}