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