Skip to content

Commit

Permalink
address comments and use spotless:apply
Browse files Browse the repository at this point in the history
  • Loading branch information
taklwu committed May 10, 2022
1 parent 0e7ee53 commit c6ee9a4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,6 @@ private static boolean preadWithExtraOnHeap(ByteBuff buff, FSDataInputStream dis
while (bytesRead < lengthMustRead) {
int ret = dis.read(position + bytesRead, buf, bytesRead, remain);
if (ret < 0) {
if (remain <= extraLen) {
// break for the "extra data" when hitting end of stream and remaining is necessary
break;
}
throw new IOException("Premature EOF from inputStream (positional read returned " + ret
+ ", was trying to read " + necessaryLen + " necessary bytes and " + extraLen
+ " extra bytes, successfully read " + bytesRead);
Expand Down Expand Up @@ -311,10 +307,6 @@ private static boolean preadWithExtraDirectly(ByteBuff buff, FSDataInputStream d
throw e;
}
if (ret < 0) {
if (remain <= extraLen) {
// break for the "extra data" when hitting end of stream and remaining is necessary
break;
}
throw new IOException("Premature EOF from inputStream (positional read returned " + ret
+ ", was trying to read " + necessaryLen + " necessary bytes and " + extraLen
+ " extra bytes, successfully read " + bytesRead);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1453,10 +1453,12 @@ protected boolean readAtOffset(FSDataInputStream istream, ByteBuff dest, int siz
} else {
// Positional read. Better for random reads; or when the streamLock is already locked.
int extraSize = peekIntoNextBlock ? hdrSize : 0;
boolean readAllBytes = hfs.getConf()
.getBoolean(HConstants.HFILE_PREAD_ALL_BYTES_ENABLED_KEY,
boolean readAllBytes =
hfs.getConf().getBoolean(HConstants.HFILE_PREAD_ALL_BYTES_ENABLED_KEY,
HConstants.HFILE_PREAD_ALL_BYTES_ENABLED_DEFAULT);
if (!BlockIOUtils.preadWithExtra(dest, istream, fileOffset, size, extraSize, readAllBytes)) {
if (
!BlockIOUtils.preadWithExtra(dest, istream, fileOffset, size, extraSize, readAllBytes)
) {
// did not read the next block header.
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public class TestBlockIOUtils {
private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();

private static final int NUM_TEST_BLOCKS = 2;
private static final Compression.Algorithm COMPRESSION_ALGO = Compression.Algorithm.GZ;

@Test
public void testIsByteBufferReadable() throws IOException {
Expand Down Expand Up @@ -122,18 +123,19 @@ private void testPreadReadFullBytesInternal(boolean readAllBytes) throws IOExcep
conf.setBoolean(HConstants.HFILE_PREAD_ALL_BYTES_ENABLED_KEY, readAllBytes);
FileSystem fs = TEST_UTIL.getTestFileSystem();
Path path = new Path(TEST_UTIL.getDataTestDirOnTestFS(), testName.getMethodName());
Random rand = new Random();
long totalDataBlockBytes = writeBlocks(TEST_UTIL.getConfiguration(), rand,
Compression.Algorithm.GZ, path);
readDataBlocksAndVerify(fs, path, totalDataBlockBytes);
// give a fixed seed such we can see failure easily.
Random rand = new Random(5685632);
long totalDataBlockBytes =
writeBlocks(TEST_UTIL.getConfiguration(), rand, COMPRESSION_ALGO, path);
readDataBlocksAndVerify(fs, path, COMPRESSION_ALGO, totalDataBlockBytes);
}

private long writeBlocks(Configuration conf, Random rand, Compression.Algorithm compressAlgo,
Path path) throws IOException {
FileSystem fs = HFileSystem.get(conf);
FSDataOutputStream os = fs.create(path);
HFileContext meta = new HFileContextBuilder().withHBaseCheckSum(true)
.withCompression(compressAlgo).withBytesPerCheckSum(HFile.DEFAULT_BYTES_PER_CHECKSUM).build();
HFileContext meta =
new HFileContextBuilder().withHBaseCheckSum(true).withCompression(compressAlgo).build();
HFileBlock.Writer hbw = new HFileBlock.Writer(conf, null, meta);
long totalDataBlockBytes = 0;
for (int i = 0; i < NUM_TEST_BLOCKS; ++i) {
Expand Down Expand Up @@ -165,18 +167,17 @@ private long writeBlocks(Configuration conf, Random rand, Compression.Algorithm
return totalDataBlockBytes;
}

private void readDataBlocksAndVerify(FileSystem fs, Path path, long totalDataBlockBytes)
throws IOException {
private void readDataBlocksAndVerify(FileSystem fs, Path path, Compression.Algorithm compressAlgo,
long totalDataBlockBytes) throws IOException {
FSDataInputStream is = fs.open(path);
HFileContext fileContext =
new HFileContextBuilder().withHBaseCheckSum(true)
.withCompression(Compression.Algorithm.GZ).build();
new HFileContextBuilder().withHBaseCheckSum(true).withCompression(compressAlgo).build();
ReaderContext context =
new ReaderContextBuilder().withInputStreamWrapper(new FSDataInputStreamWrapper(is))
.withReaderType(ReaderContext.ReaderType.PREAD)
.withFileSize(totalDataBlockBytes).withFilePath(path).withFileSystem(fs).build();
HFileBlock.FSReader hbr = new HFileBlock.FSReaderImpl(context, fileContext,
ByteBuffAllocator.HEAP, fs.getConf());
.withReaderType(ReaderContext.ReaderType.PREAD).withFileSize(totalDataBlockBytes)
.withFilePath(path).withFileSystem(fs).build();
HFileBlock.FSReader hbr =
new HFileBlock.FSReaderImpl(context, fileContext, ByteBuffAllocator.HEAP, fs.getConf());

long onDiskSizeOfNextBlock = -1;
long offset = 0;
Expand Down

0 comments on commit c6ee9a4

Please sign in to comment.