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.ExtendedCell; 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(ExtendedCell kv, boolean forward, boolean useBloom) 037 throws IOException { 038 return doRealSeek(this, kv, forward); 039 } 040 041 @Override 042 public boolean realSeekDone() { 043 return true; 044 } 045 046 @Override 047 public void enforceSeek() throws IOException { 048 throw new NotImplementedException("enforceSeek must not be called on a " + "non-lazy scanner"); 049 } 050 051 public static boolean doRealSeek(KeyValueScanner scanner, ExtendedCell kv, boolean forward) 052 throws IOException { 053 return forward ? scanner.reseek(kv) : scanner.seek(kv); 054 } 055 056 @Override 057 public boolean shouldUseScanner(Scan scan, HStore store, long oldestUnexpiredTS) { 058 // No optimizations implemented by default. 059 return true; 060 } 061 062 @Override 063 public boolean isFileScanner() { 064 // Not a file by default. 065 return false; 066 } 067 068 @Override 069 public void recordBlockSize(IntConsumer blockSizeConsumer) { 070 // do nothing 071 } 072 073 @Override 074 public Path getFilePath() { 075 // Not a file by default. 076 return null; 077 } 078 079 @Override 080 public ExtendedCell getNextIndexedKey() { 081 return null; 082 } 083 084 @Override 085 public void shipped() throws IOException { 086 // do nothing 087 } 088}