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