/** * Verifies that the block index is non-empty and throws an * {@link IllegalStateException} otherwise. */ public void ensureNonEmpty() { if (isEmpty()) { throw new IllegalStateException("Block index is empty or not loaded"); } }
@Override public boolean seekTo() throws IOException { if (reader.getDataBlockIndexReader().isEmpty()) { return false; } if (blockBuffer != null && currBlock == 0) { blockBuffer.rewind(); currKeyLen = blockBuffer.getInt(); currValueLen = blockBuffer.getInt(); return true; } currBlock = 0; blockBuffer = reader.readBlockBuffer(currBlock, cacheBlocks, pread, isCompaction); currKeyLen = blockBuffer.getInt(); currValueLen = blockBuffer.getInt(); blockFetches++; return true; }
/** * @return Last key in the file. May be null if file has no entries. * Note that this is not the last rowkey, but rather the byte form of * the last KeyValue. */ public byte[] getLastKey() { if (!fileInfoLoaded) { throw new RuntimeException("Load file info first"); } return dataBlockIndexReader.isEmpty() ? null : lastKey; }
/** * @return the first key in the file. May be null if file has no entries. Note * that this is not the first row key, but rather the byte form of the * first KeyValue. */ @Override public byte [] getFirstKey() { if (dataBlockIndexReader == null) { throw new BlockIndexNotLoadedException(); } return dataBlockIndexReader.isEmpty() ? null : dataBlockIndexReader.getRootBlockKey(0); }
/** * @return the first key in the file. May be null if file has no entries. Note * that this is not the first row key, but rather the byte form of the * first KeyValue. */ @Override public byte [] getFirstKey() { if (dataBlockIndexReader == null) { throw new BlockIndexNotLoadedException(); } return dataBlockIndexReader.isEmpty() ? null : dataBlockIndexReader.getRootBlockKey(0); }
/** * @return Midkey for this file. We work with block boundaries only so * returned midkey is an approximation only. * * @throws IOException */ @Override public byte[] midkey() throws IOException { Preconditions.checkState(isFileInfoLoaded(), "File info is not loaded"); Preconditions.checkState(!dataBlockIndexReader.isEmpty(), "Data block index is not loaded or is empty"); return dataBlockIndexReader.midkey(); }
/** * @return Last key in the file. May be null if file has no entries. Note that * this is not the last row key, but rather the byte form of the last * KeyValue. */ @Override public byte[] getLastKey() { return dataBlockIndexReader.isEmpty() ? null : lastKey; }
/** * @return Last key in the file. May be null if file has no entries. Note that * this is not the last row key, but rather the byte form of the last * KeyValue. */ @Override public byte[] getLastKey() { return dataBlockIndexReader.isEmpty() ? null : lastKey; }
/** * @param key Key to search. * @return Block number of the block containing the key or -1 if not in this * file. */ protected int blockContainingKey(final byte[] key, int offset, int length) { Preconditions.checkState(!dataBlockIndexReader.isEmpty(), "Block index not loaded"); return dataBlockIndexReader.rootBlockContainingKey(key, offset, length); }