001/** 002 * Copyright The Apache Software Foundation 003 * 004 * Licensed to the Apache Software Foundation (ASF) under one or more 005 * contributor license agreements. See the NOTICE file distributed with this 006 * work for additional information regarding copyright ownership. The ASF 007 * licenses this file to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance with the License. 009 * You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 015 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 016 * License for the specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.hadoop.hbase.regionserver; 020 021import java.io.IOException; 022import java.util.List; 023 024import org.apache.hadoop.hbase.Cell; 025import org.apache.hadoop.hbase.DoNotRetryIOException; 026import org.apache.hadoop.hbase.HConstants; 027import org.apache.hadoop.hbase.PrivateCellUtil; 028import org.apache.hadoop.hbase.client.Scan; 029import org.apache.hadoop.hbase.regionserver.HRegion.RegionScannerImpl; 030import org.apache.hadoop.hbase.util.Bytes; 031import org.apache.yetus.audience.InterfaceAudience; 032 033/** 034 * ReversibleRegionScannerImpl extends from RegionScannerImpl, and is used to 035 * support reversed scanning. 036 */ 037@InterfaceAudience.Private 038class ReversedRegionScannerImpl extends RegionScannerImpl { 039 040 /** 041 * @param scan 042 * @param additionalScanners 043 * @param region 044 * @throws IOException 045 */ 046 ReversedRegionScannerImpl(Scan scan, List<KeyValueScanner> additionalScanners, HRegion region) 047 throws IOException { 048 region.super(scan, additionalScanners, region); 049 } 050 051 @Override 052 protected void initializeKVHeap(List<KeyValueScanner> scanners, 053 List<KeyValueScanner> joinedScanners, HRegion region) throws IOException { 054 this.storeHeap = new ReversedKeyValueHeap(scanners, comparator); 055 if (!joinedScanners.isEmpty()) { 056 throw new DoNotRetryIOException("Reverse scan with loading CFs on demand is not supported"); 057 } 058 } 059 060 @Override 061 protected boolean shouldStop(Cell currentRowCell) { 062 if (currentRowCell == null) { 063 return true; 064 } 065 if (stopRow == null || Bytes.equals(stopRow, HConstants.EMPTY_START_ROW)) { 066 return false; 067 } 068 int c = comparator.compareRows(currentRowCell, stopRow, 0, stopRow.length); 069 return c < 0 || (c == 0 && !includeStopRow); 070 } 071 072 @Override 073 protected boolean nextRow(ScannerContext scannerContext, Cell curRowCell) 074 throws IOException { 075 assert super.joinedContinuationRow == null : "Trying to go to next row during joinedHeap read."; 076 this.storeHeap.seekToPreviousRow(PrivateCellUtil.createFirstOnRow(curRowCell)); 077 resetFilters(); 078 // Calling the hook in CP which allows it to do a fast forward 079 if (this.region.getCoprocessorHost() != null) { 080 return this.region.getCoprocessorHost().postScannerFilterRow(this, curRowCell); 081 } 082 return true; 083 } 084 085}