HBASE-13429 Remove deprecated seek/reseek methods from HFileScanner.

This commit is contained in:
anoopsjohn 2015-04-09 22:42:57 +05:30
parent 80dbf06651
commit 6eeb5b38e1
9 changed files with 41 additions and 176 deletions

View File

@ -676,11 +676,6 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
}
}
@Override
public int seekToKeyInBlock(byte[] key, int offset, int length, boolean seekBefore) {
return seekToKeyInBlock(new KeyValue.KeyOnlyKeyValue(key, offset, length), seekBefore);
}
@Override
public int seekToKeyInBlock(Cell seekCell, boolean seekBefore) {
int rowCommonPrefix = 0;

View File

@ -172,27 +172,6 @@ public interface DataBlockEncoder {
*/
boolean next();
/**
* Moves the seeker position within the current block to:
* <ul>
* <li>the last key that that is less than or equal to the given key if
* <code>seekBefore</code> is false</li>
* <li>the last key that is strictly less than the given key if <code>
* seekBefore</code> is true. The caller is responsible for loading the
* previous block if the requested key turns out to be the first key of the
* current block.</li>
* </ul>
* @param key byte array containing the key
* @param offset key position the array
* @param length key length in bytes
* @param seekBefore find the key strictly less than the given key in case
* of an exact match. Does not matter in case of an inexact match.
* @return 0 on exact match, 1 on inexact match.
*/
@Deprecated
int seekToKeyInBlock(
byte[] key, int offset, int length, boolean seekBefore
);
/**
* Moves the seeker position within the current block to:
* <ul>

View File

@ -140,35 +140,6 @@ public class PrefixTreeSeeker implements EncodedSeeker {
private static final boolean USE_POSITION_BEFORE = false;
/**
* Seek forward only (should be called reseekToKeyInBlock?).
* <p/>
* If the exact key is found look at the seekBefore variable and:<br/>
* - if true: go to the previous key if it's true<br/>
* - if false: stay on the exact key
* <p/>
* If the exact key is not found, then go to the previous key *if possible*, but remember to
* leave the scanner in a valid state if possible.
* <p/>
* @param keyOnlyBytes KeyValue format of a Cell's key at which to position the seeker
* @param offset offset into the keyOnlyBytes array
* @param length number of bytes of the keyOnlyBytes array to use
* @param forceBeforeOnExactMatch if an exact match is found and seekBefore=true, back up 1 Cell
* @return 0 if the seeker is on the exact key<br/>
* 1 if the seeker is not on the key for any reason, including seekBefore being true
*/
@Override
public int seekToKeyInBlock(byte[] keyOnlyBytes, int offset, int length,
boolean forceBeforeOnExactMatch) {
if (USE_POSITION_BEFORE) {
return seekToOrBeforeUsingPositionAtOrBefore(keyOnlyBytes, offset, length,
forceBeforeOnExactMatch);
} else {
return seekToOrBeforeUsingPositionAtOrAfter(keyOnlyBytes, offset, length,
forceBeforeOnExactMatch);
}
}
/*
* Support both of these options since the underlying PrefixTree supports both. Possibly
* expand the EncodedSeeker to utilize them both.

View File

@ -173,17 +173,6 @@ public class HalfStoreFileReader extends StoreFile.Reader {
return true;
}
@Override
public boolean seekBefore(byte[] key) throws IOException {
return seekBefore(key, 0, key.length);
}
@Override
public boolean seekBefore(byte [] key, int offset, int length)
throws IOException {
return seekBefore(new KeyValue.KeyOnlyKeyValue(key, offset, length));
}
@Override
public boolean seekTo() throws IOException {
if (top) {
@ -212,29 +201,6 @@ public class HalfStoreFileReader extends StoreFile.Reader {
splitkey, 0, splitkey.length) < 0;
}
@Override
public int seekTo(byte[] key) throws IOException {
return seekTo(key, 0, key.length);
}
@Override
public int seekTo(byte[] key, int offset, int length) throws IOException {
return seekTo(new KeyValue.KeyOnlyKeyValue(key, offset, length));
}
@Override
public int reseekTo(byte[] key) throws IOException {
return reseekTo(key, 0, key.length);
}
@Override
public int reseekTo(byte[] key, int offset, int length)
throws IOException {
//This function is identical to the corresponding seekTo function except
//that we call reseekTo (and not seekTo) on the delegate.
return reseekTo(new KeyValue.KeyOnlyKeyValue(key, offset, length));
}
public org.apache.hadoop.hbase.io.hfile.HFile.Reader getReader() {
return this.delegate.getReader();
}
@ -338,7 +304,7 @@ public class HalfStoreFileReader extends StoreFile.Reader {
// Get a scanner that caches the block and that uses pread.
HFileScanner scanner = getScanner(true, true);
try {
if (scanner.seekBefore(this.splitkey)) {
if (scanner.seekBefore(this.splitCell)) {
return Bytes.toBytes(scanner.getKey());
}
} catch (IOException e) {

View File

@ -264,7 +264,7 @@ public class HFilePrettyPrinter extends Configured implements Tool {
if (this.isSeekToRow) {
// seek to the first kv on this row
shouldScanKeysValues =
(scanner.seekTo(KeyValueUtil.createFirstOnRow(this.row).getKey()) != -1);
(scanner.seekTo(KeyValueUtil.createFirstOnRow(this.row)) != -1);
} else {
shouldScanKeysValues = scanner.seekTo();
}

View File

@ -477,21 +477,6 @@ public class HFileReaderImpl implements HFile.Reader, Configurable {
throw new NotSeekedException();
}
@Override
public int seekTo(byte[] key) throws IOException {
return seekTo(key, 0, key.length);
}
@Override
public boolean seekBefore(byte[] key) throws IOException {
return seekBefore(key, 0, key.length);
}
@Override
public int reseekTo(byte[] key) throws IOException {
return reseekTo(key, 0, key.length);
}
@Override
public HFile.Reader getReader() {
return reader;
@ -651,18 +636,6 @@ public class HFileReaderImpl implements HFile.Reader, Configurable {
return nextIndexedKey;
}
@Override
public int seekTo(byte[] key, int offset, int length) throws IOException {
// Always rewind to the first key of the block, because the given key
// might be before or after the current key.
return seekTo(new KeyValue.KeyOnlyKeyValue(key, offset, length));
}
@Override
public int reseekTo(byte[] key, int offset, int length) throws IOException {
return reseekTo(new KeyValue.KeyOnlyKeyValue(key, offset, length));
}
@Override
public int seekTo(Cell key) throws IOException {
return seekTo(key, true);
@ -723,11 +696,6 @@ public class HFileReaderImpl implements HFile.Reader, Configurable {
blockWithScanInfo.getNextIndexedKey(), rewind, key, false);
}
@Override
public boolean seekBefore(byte[] key, int offset, int length) throws IOException {
return seekBefore(new KeyValue.KeyOnlyKeyValue(key, offset, length));
}
@Override
public boolean seekBefore(Cell key) throws IOException {
HFileBlock seekToBlock = reader.getDataBlockIndexReader().seekToDataBlock(key, block,

View File

@ -30,7 +30,7 @@ import org.apache.hadoop.hbase.Cell;
*
* <p>A scanner doesn't always have a key/value that it is pointing to
* when it is first created and before
* {@link #seekTo()}/{@link #seekTo(byte[])} are called.
* {@link #seekTo()}/{@link #seekTo(Cell)} are called.
* In this case, {@link #getKey()}/{@link #getValue()} returns null. At most
* other times, a key and value will be available. The general pattern is that
* you position the Scanner using the seekTo variants and then getKey and
@ -39,69 +39,57 @@ import org.apache.hadoop.hbase.Cell;
@InterfaceAudience.Private
public interface HFileScanner {
/**
* SeekTo or just before the passed <code>key</code>. Examine the return
* code to figure whether we found the key or not.
* Consider the key stream of all the keys in the file,
* <code>k[0] .. k[n]</code>, where there are n keys in the file.
* @param key Key to find.
* @return -1, if key < k[0], no position;
* 0, such that k[i] = key and scanner is left in position i; and
* 1, such that k[i] < key, and scanner is left in position i.
* The scanner will position itself between k[i] and k[i+1] where
* k[i] < key <= k[i+1].
* If there is no key k[i+1] greater than or equal to the input key, then the
* SeekTo or just before the passed <code>cell</code>. Examine the return
* code to figure whether we found the cell or not.
* Consider the cell stream of all the cells in the file,
* <code>c[0] .. c[n]</code>, where there are n cells in the file.
* @param cell
* @return -1, if cell < c[0], no position;
* 0, such that c[i] = cell and scanner is left in position i; and
* 1, such that c[i] < cell, and scanner is left in position i.
* The scanner will position itself between c[i] and c[i+1] where
* c[i] < cell <= c[i+1].
* If there is no cell c[i+1] greater than or equal to the input cell, then the
* scanner will position itself at the end of the file and next() will return
* false when it is called.
* @throws IOException
*/
@Deprecated
int seekTo(byte[] key) throws IOException;
@Deprecated
int seekTo(byte[] key, int offset, int length) throws IOException;
int seekTo(Cell cell) throws IOException;
int seekTo(Cell c) throws IOException;
/**
* Reseek to or just before the passed <code>key</code>. Similar to seekTo
* Reseek to or just before the passed <code>cell</code>. Similar to seekTo
* except that this can be called even if the scanner is not at the beginning
* of a file.
* This can be used to seek only to keys which come after the current position
* This can be used to seek only to cells which come after the current position
* of the scanner.
* Consider the key stream of all the keys in the file,
* <code>k[0] .. k[n]</code>, where there are n keys in the file after
* Consider the cell stream of all the cells in the file,
* <code>c[0] .. c[n]</code>, where there are n cellc in the file after
* current position of HFileScanner.
* The scanner will position itself between k[i] and k[i+1] where
* k[i] < key <= k[i+1].
* If there is no key k[i+1] greater than or equal to the input key, then the
* The scanner will position itself between c[i] and c[i+1] where
* c[i] < cell <= c[i+1].
* If there is no cell c[i+1] greater than or equal to the input cell, then the
* scanner will position itself at the end of the file and next() will return
* false when it is called.
* @param key Key to find (should be non-null)
* @return -1, if key < k[0], no position;
* 0, such that k[i] = key and scanner is left in position i; and
* 1, such that k[i] < key, and scanner is left in position i.
* @param cell Cell to find (should be non-null)
* @return -1, if cell < c[0], no position;
* 0, such that c[i] = cell and scanner is left in position i; and
* 1, such that c[i] < cell, and scanner is left in position i.
* @throws IOException
*/
@Deprecated
int reseekTo(byte[] key) throws IOException;
@Deprecated
int reseekTo(byte[] key, int offset, int length) throws IOException;
int reseekTo(Cell cell) throws IOException;
int reseekTo(Cell c) throws IOException;
/**
* Consider the key stream of all the keys in the file,
* <code>k[0] .. k[n]</code>, where there are n keys in the file.
* @param key Key to find
* @return false if key <= k[0] or true with scanner in position 'i' such
* that: k[i] < key. Furthermore: there may be a k[i+1], such that
* k[i] < key <= k[i+1] but there may also NOT be a k[i+1], and next() will
* Consider the cell stream of all the cells in the file,
* <code>c[0] .. c[n]</code>, where there are n cells in the file.
* @param cell Cell to find
* @return false if cell <= c[0] or true with scanner in position 'i' such
* that: c[i] < cell. Furthermore: there may be a c[i+1], such that
* c[i] < cell <= c[i+1] but there may also NOT be a c[i+1], and next() will
* return false (EOF).
* @throws IOException
*/
@Deprecated
boolean seekBefore(byte[] key) throws IOException;
@Deprecated
boolean seekBefore(byte[] key, int offset, int length) throws IOException;
boolean seekBefore(Cell cell) throws IOException;
boolean seekBefore(Cell kv) throws IOException;
/**
* Positions this scanner at the start of the file.
* @return False if empty file; i.e. a call to next would return false and
@ -117,14 +105,14 @@ public interface HFileScanner {
boolean next() throws IOException;
/**
* Gets a buffer view to the current key. You must call
* {@link #seekTo(byte[])} before this method.
* {@link #seekTo(Cell)} before this method.
* @return byte buffer for the key. The limit is set to the key size, and the
* position is 0, the start of the buffer view.
*/
ByteBuffer getKey();
/**
* Gets a buffer view to the current value. You must call
* {@link #seekTo(byte[])} before this method.
* {@link #seekTo(Cell)} before this method.
*
* @return byte buffer for the value. The limit is set to the value size, and
* the position is 0, the start of the buffer view.
@ -136,13 +124,13 @@ public interface HFileScanner {
Cell getKeyValue();
/**
* Convenience method to get a copy of the key as a string - interpreting the
* bytes as UTF8. You must call {@link #seekTo(byte[])} before this method.
* bytes as UTF8. You must call {@link #seekTo(Cell)} before this method.
* @return key as a string
*/
String getKeyString();
/**
* Convenience method to get a copy of the value as a string - interpreting
* the bytes as UTF8. You must call {@link #seekTo(byte[])} before this method.
* the bytes as UTF8. You must call {@link #seekTo(Cell)} before this method.
* @return value as a string
*/
String getValueString();
@ -152,7 +140,7 @@ public interface HFileScanner {
HFile.Reader getReader();
/**
* @return True is scanner has had one of the seek calls invoked; i.e.
* {@link #seekBefore(byte[])} or {@link #seekTo()} or {@link #seekTo(byte[])}.
* {@link #seekBefore(Cell)} or {@link #seekTo()} or {@link #seekTo(Cell)}.
* Otherwise returns false.
*/
boolean isSeeked();

View File

@ -1870,8 +1870,7 @@ public class HStore implements Store {
// Unlikely that there'll be an instance of actual first row in table.
if (walkForwardInSingleRow(scanner, firstOnRow, state)) return true;
// If here, need to start backing up.
while (scanner.seekBefore(firstOnRow.getBuffer(), firstOnRow.getKeyOffset(),
firstOnRow.getKeyLength())) {
while (scanner.seekBefore(firstOnRow)) {
Cell kv = scanner.getKeyValue();
if (!state.isTargetTable(kv)) break;
if (!state.isBetterCandidate(kv)) break;

View File

@ -422,8 +422,7 @@ public class StoreFileScanner implements KeyValueScanner {
KeyValue seekKey = KeyValueUtil.createFirstOnRow(key.getRowArray(), key.getRowOffset(),
key.getRowLength());
if (seekCount != null) seekCount.incrementAndGet();
if (!hfs.seekBefore(seekKey.getBuffer(), seekKey.getKeyOffset(),
seekKey.getKeyLength())) {
if (!hfs.seekBefore(seekKey)) {
close();
return false;
}