/** * Updates the current block to be the given {@link HFileBlock}. Seeks to * the the first key/value pair. * * @param newBlock the block to make current * @throws CorruptHFileException */ @Override protected void updateCurrentBlock(HFileBlock newBlock) throws CorruptHFileException { // sanity checks if (newBlock.getBlockType() != BlockType.ENCODED_DATA) { throw new IllegalStateException("EncodedScanner works only on encoded data blocks"); } short dataBlockEncoderId = newBlock.getDataBlockEncodingId(); if (!DataBlockEncoding.isCorrectEncoder(dataBlockEncoder, dataBlockEncoderId)) { String encoderCls = dataBlockEncoder.getClass().getName(); throw new CorruptHFileException("Encoder " + encoderCls + " doesn't support data block encoding " + DataBlockEncoding.getNameFromId(dataBlockEncoderId)); } updateCurrBlockRef(newBlock); ByteBuff encodedBuffer = getEncodedBuffer(newBlock); seeker.setCurrentBuffer(encodedBuffer); blockFetches.incrementAndGet(); // Reset the next indexed key this.nextIndexedKey = null; }
@Test public void testGetDataBlockEncoder() throws Exception { for (DataBlockEncoding algo : DataBlockEncoding.values()) { DataBlockEncoder encoder = DataBlockEncoding.getDataBlockEncoderById(algo.getId()); if (algo.getId() != 0) { assertTrue(DataBlockEncoding.isCorrectEncoder(encoder, algo.getId())); } } try { DataBlockEncoding.getDataBlockEncoderById((short) -1); fail("Illegal encoderId, should get IllegalArgumentException."); } catch (IllegalArgumentException ie) { } try { DataBlockEncoding.getDataBlockEncoderById(Byte.MAX_VALUE); // fail because idArray[Byte.MAX_VALUE] = null fail("Illegal encoderId, should get IllegalArgumentException."); } catch (IllegalArgumentException ie) { } }
/** * Updates the current block to be the given {@link HFileBlock}. Seeks to * the the first key/value pair. * * @param newBlock the block to make current * @throws CorruptHFileException */ private void updateCurrentBlock(HFileBlock newBlock) throws CorruptHFileException { block = newBlock; // sanity checks if (block.getBlockType() != BlockType.ENCODED_DATA) { throw new IllegalStateException( "EncodedScanner works only on encoded data blocks"); } short dataBlockEncoderId = block.getDataBlockEncodingId(); if (!DataBlockEncoding.isCorrectEncoder(dataBlockEncoder, dataBlockEncoderId)) { String encoderCls = dataBlockEncoder.getClass().getName(); throw new CorruptHFileException("Encoder " + encoderCls + " doesn't support data block encoding " + DataBlockEncoding.getNameFromId(dataBlockEncoderId)); } seeker.setCurrentBuffer(getEncodedBuffer(newBlock)); blockFetches.incrementAndGet(); // Reset the next indexed key this.nextIndexedKey = null; }
/** * Updates the current block to be the given {@link HFileBlock}. Seeks to * the the first key/value pair. * * @param newBlock the block to make current */ private void updateCurrentBlock(HFileBlock newBlock) { block = newBlock; // sanity checks if (block.getBlockType() != BlockType.ENCODED_DATA) { throw new IllegalStateException( "EncodedScannerV2 works only on encoded data blocks"); } short dataBlockEncoderId = block.getDataBlockEncodingId(); if (dataBlockEncoder == null || !DataBlockEncoding.isCorrectEncoder(dataBlockEncoder, dataBlockEncoderId)) { DataBlockEncoder encoder = DataBlockEncoding.getDataBlockEncoderById(dataBlockEncoderId); setDataBlockEncoder(encoder); } seeker.setCurrentBuffer(getEncodedBuffer(newBlock)); blockFetches++; }
@Test public void testGetDataBlockEncoder() throws Exception { for (DataBlockEncoding algo : DataBlockEncoding.values()) { DataBlockEncoder encoder = DataBlockEncoding.getDataBlockEncoderById(algo.getId()); if (algo.getId() != 0) { assertTrue(DataBlockEncoding.isCorrectEncoder(encoder, algo.getId())); } } try { DataBlockEncoding.getDataBlockEncoderById((short) -1); fail("Illegal encoderId, should get IllegalArgumentException."); } catch (IllegalArgumentException ie) { } try { DataBlockEncoding.getDataBlockEncoderById(Byte.MAX_VALUE); // fail because idArray[Byte.MAX_VALUE] = null fail("Illegal encoderId, should get IllegalArgumentException."); } catch (IllegalArgumentException ie) { } }