@Override public boolean seekBefore(Cell key) throws IOException { if (top) { Optional<Cell> fk = getFirstKey(); if (PrivateCellUtil.compareKeyIgnoresMvcc(getComparator(), key, fk.get()) <= 0) { return false; } } else { // The equals sign isn't strictly necessary just here to be consistent // with seekTo if (PrivateCellUtil.compareKeyIgnoresMvcc(getComparator(), key, splitCell) >= 0) { boolean ret = this.delegate.seekBefore(splitCell); if (ret) { atEnd = false; } return ret; } } boolean ret = this.delegate.seekBefore(key); if (ret) { atEnd = false; } return ret; }
@Override public Optional<Cell> getLastKey() { if (top) { return super.getLastKey(); } // Get a scanner that caches the block and that uses pread. HFileScanner scanner = getScanner(true, true); try { if (scanner.seekBefore(this.splitCell)) { return Optional.ofNullable(scanner.getKey()); } } catch (IOException e) { LOG.warn("Failed seekBefore " + Bytes.toStringBinary(this.splitkey), e); } finally { if (scanner != null) { scanner.close(); } } return Optional.empty(); }
private void checkSeekBefore(Cell[] cells, HFileScanner scanner, int i) throws IOException { assertEquals("Failed to seek to the key before #" + i + " (" + CellUtil.getCellKeyAsString(cells[i]) + ")", true, scanner.seekBefore(cells[i])); }
@Override public int seekTo(Cell key) throws IOException { if (top) { if (PrivateCellUtil.compareKeyIgnoresMvcc(getComparator(), key, splitCell) < 0) { return -1; } } else { if (PrivateCellUtil.compareKeyIgnoresMvcc(getComparator(), key, splitCell) >= 0) { // we would place the scanner in the second half. // it might be an error to return false here ever... boolean res = delegate.seekBefore(splitCell); if (!res) { throw new IOException( "Seeking for a key in bottom of file, but key exists in top of file, " + "failed on seekBefore(midkey)"); } return 1; } } return delegate.seekTo(key); }
private void checkNoSeekBefore(Cell[] cells, HFileScanner scanner, int i) throws IOException { assertEquals("Incorrectly succeeded in seeking to before first key (" + CellUtil.getCellKeyAsString(cells[i]) + ")", false, scanner.seekBefore(cells[i])); }
@Override public int reseekTo(Cell key) throws IOException { // This function is identical to the corresponding seekTo function // except // that we call reseekTo (and not seekTo) on the delegate. if (top) { if (PrivateCellUtil.compareKeyIgnoresMvcc(getComparator(), key, splitCell) < 0) { return -1; } } else { if (PrivateCellUtil.compareKeyIgnoresMvcc(getComparator(), key, splitCell) >= 0) { // we would place the scanner in the second half. // it might be an error to return false here ever... boolean res = delegate.seekBefore(splitCell); if (!res) { throw new IOException("Seeking for a key in bottom of file, but" + " key exists in top of file, failed on seekBefore(midkey)"); } return 1; } } if (atEnd) { // skip the 'reseek' and just return 1. return 1; } return delegate.reseekTo(key); }
private Cell doTestOfSeekBefore(Path p, FileSystem fs, Reference bottom, Cell seekBefore, CacheConfig cacheConfig) throws IOException { final HalfStoreFileReader halfreader = new HalfStoreFileReader(fs, p, cacheConfig, bottom, true, new AtomicInteger(0), true, TEST_UTIL.getConfiguration()); halfreader.loadFileInfo(); final HFileScanner scanner = halfreader.getScanner(false, false); scanner.seekBefore(seekBefore); return scanner.getCell(); }
Cell seekKey = PrivateCellUtil.createFirstOnRow(key); if (seekCount != null) seekCount.increment(); if (!hfs.seekBefore(seekKey)) { this.cur = null; return false;
reader.loadFileInfo(); HFileScanner scanner = reader.getScanner(false, true); assertFalse(scanner.seekBefore(toKV("a", tagUsage))); assertFalse(scanner.seekBefore(toKV("c", tagUsage))); assertTrue(scanner.seekBefore(toKV("d", tagUsage))); assertEquals("c", toRowStr(scanner.getCell())); assertTrue(scanner.seekBefore(toKV("e", tagUsage))); assertEquals("c", toRowStr(scanner.getCell())); assertTrue(scanner.seekBefore(toKV("f", tagUsage))); assertEquals("e", toRowStr(scanner.getCell())); assertTrue(scanner.seekBefore(toKV("g", tagUsage))); assertEquals("e", toRowStr(scanner.getCell())); assertTrue(scanner.seekBefore(toKV("h", tagUsage))); assertEquals("g", toRowStr(scanner.getCell())); assertTrue(scanner.seekBefore(toKV("i", tagUsage))); assertEquals("g", toRowStr(scanner.getCell())); assertTrue(scanner.seekBefore(toKV("j", tagUsage))); assertEquals("i", toRowStr(scanner.getCell())); Cell cell = scanner.getCell(); assertTrue(scanner.seekBefore(toKV("k", tagUsage))); assertEquals("i", toRowStr(scanner.getCell())); assertTrue(scanner.seekBefore(toKV("l", tagUsage))); assertEquals("k", toRowStr(scanner.getCell()));
reader.loadFileInfo(); HFileScanner scanner = reader.getScanner(false, true); assertFalse(scanner.seekBefore(toKV("a", tagUsage))); assertFalse(scanner.seekBefore(toKV("b", tagUsage))); assertFalse(scanner.seekBefore(toKV("c", tagUsage))); assertTrue(scanner.seekBefore(toKV("d", tagUsage))); assertFalse(scanner.getCell() instanceof ByteBufferKeyValue); assertEquals("c", toRowStr(scanner.getCell())); assertTrue(scanner.seekBefore(toKV("e", tagUsage))); assertEquals("c", toRowStr(scanner.getCell())); assertTrue(scanner.seekBefore(toKV("f", tagUsage))); assertEquals("e", toRowStr(scanner.getCell())); assertTrue(scanner.seekBefore(toKV("g", tagUsage))); assertEquals("e", toRowStr(scanner.getCell())); assertTrue(scanner.seekBefore(toKV("h", tagUsage))); assertEquals("g", toRowStr(scanner.getCell())); assertTrue(scanner.seekBefore(toKV("i", tagUsage))); assertEquals("g", toRowStr(scanner.getCell())); assertTrue(scanner.seekBefore(toKV("j", tagUsage))); assertEquals("i", toRowStr(scanner.getCell())); assertTrue(scanner.seekBefore(toKV("k", tagUsage)));
@Override public byte[] getLastKey() { if (top) { return super.getLastKey(); } // Get a scanner that caches the block and that uses pread. HFileScanner scanner = getScanner(true, true); try { if (scanner.seekBefore(this.splitkey)) { return Bytes.toBytes(scanner.getKey()); } } catch (IOException e) { LOG.warn("Failed seekBefore " + Bytes.toStringBinary(this.splitkey), e); } return null; }
public boolean seekBefore(byte [] key, int offset, int length) throws IOException { if (top) { byte[] fk = getFirstKey(); // This will be null when the file is empty in which we can not seekBefore to any key if (fk == null) return false; if (getComparator().compare(key, offset, length, fk, 0, fk.length) <= 0) { return false; } } else { // The equals sign isn't strictly necessary just here to be consistent with seekTo if (getComparator().compare(key, offset, length, splitkey, 0, splitkey.length) >= 0) { return this.delegate.seekBefore(splitkey, 0, splitkey.length); } } return this.delegate.seekBefore(key, offset, length); }
@Override public byte[] getLastKey() { if (top) { return super.getLastKey(); } // Get a scanner that caches the block and that uses pread. HFileScanner scanner = getScanner(true, true); try { if (scanner.seekBefore(this.splitkey)) { return Bytes.toBytes(scanner.getKey()); } } catch (IOException e) { LOG.warn("Failed seekBefore " + Bytes.toStringBinary(this.splitkey), e); } return null; }
private void checkSeekBefore(Cell[] cells, HFileScanner scanner, int i) throws IOException { assertEquals("Failed to seek to the key before #" + i + " (" + CellUtil.getCellKeyAsString(cells[i]) + ")", true, scanner.seekBefore(cells[i])); }
public int seekTo(byte[] key, int offset, int length) throws IOException { if (top) { if (getComparator().compare(key, offset, length, splitkey, 0, splitkey.length) < 0) { return -1; } } else { if (getComparator().compare(key, offset, length, splitkey, 0, splitkey.length) >= 0) { // we would place the scanner in the second half. // it might be an error to return false here ever... boolean res = delegate.seekBefore(splitkey, 0, splitkey.length); if (!res) { throw new IOException("Seeking for a key in bottom of file, but key exists in top of file, failed on seekBefore(midkey)"); } return 1; } } return delegate.seekTo(key, offset, length); }
private void checkNoSeekBefore(Cell[] cells, HFileScanner scanner, int i) throws IOException { assertEquals("Incorrectly succeeded in seeking to before first key (" + CellUtil.getCellKeyAsString(cells[i]) + ")", false, scanner.seekBefore(cells[i])); }
@Override public int reseekTo(Cell key) throws IOException { // This function is identical to the corresponding seekTo function // except // that we call reseekTo (and not seekTo) on the delegate. if (top) { if (getComparator().compareOnlyKeyPortion(key, splitCell) < 0) { return -1; } } else { if (getComparator().compareOnlyKeyPortion(key, splitCell) >= 0) { // we would place the scanner in the second half. // it might be an error to return false here ever... boolean res = delegate.seekBefore(splitCell); if (!res) { throw new IOException("Seeking for a key in bottom of file, but" + " key exists in top of file, failed on seekBefore(midkey)"); } return 1; } } if (atEnd) { // skip the 'reseek' and just return 1. return 1; } return delegate.reseekTo(key); }
@Override public int seekTo(Cell key) throws IOException { if (top) { if (getComparator().compareOnlyKeyPortion(key, splitCell) < 0) { return -1; } } else { if (getComparator().compareOnlyKeyPortion(key, splitCell) >= 0) { // we would place the scanner in the second half. // it might be an error to return false here ever... boolean res = delegate.seekBefore(splitCell); if (!res) { throw new IOException( "Seeking for a key in bottom of file, but key exists in top of file, " + "failed on seekBefore(midkey)"); } return 1; } } return delegate.seekTo(key); }
@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. if (top) { if (getComparator().compare(key, offset, length, splitkey, 0, splitkey.length) < 0) { return -1; } } else { if (getComparator().compare(key, offset, length, splitkey, 0, splitkey.length) >= 0) { // we would place the scanner in the second half. // it might be an error to return false here ever... boolean res = delegate.seekBefore(splitkey, 0, splitkey.length); if (!res) { throw new IOException("Seeking for a key in bottom of file, but" + " key exists in top of file, failed on seekBefore(midkey)"); } return 1; } } if (atEnd) { // skip the 'reseek' and just return 1. return 1; } return delegate.reseekTo(key, offset, length); }
private Cell doTestOfSeekBefore(Path p, FileSystem fs, Reference bottom, Cell seekBefore, CacheConfig cacheConfig) throws IOException { final HalfStoreFileReader halfreader = new HalfStoreFileReader(fs, p, cacheConfig, bottom, true, new AtomicInteger(0), true, TEST_UTIL.getConfiguration()); halfreader.loadFileInfo(); final HFileScanner scanner = halfreader.getScanner(false, false); scanner.seekBefore(seekBefore); return scanner.getCell(); }