@Override public void setDropBehind(Boolean dropCache) throws IOException, UnsupportedOperationException { in.setDropBehind(dropCache); } }
@Override public void setDropBehind(Boolean dropBehind) throws IOException { underLyingStream.setDropBehind(dropBehind); } }
private void setStreamOptions(FSDataInputStream in) { try { in.setDropBehind(dropBehind); } catch (Exception e) { // Skipped. } if (readahead >= 0) { try { in.setReadahead(readahead); } catch (Exception e) { // Skipped. } } }
@Override public void setDropBehind(Boolean dropBehind) throws IOException { underLyingStream.setDropBehind(dropBehind); } }
@Override public void setDropBehind(Boolean dropBehind) throws IOException { underLyingStream.setDropBehind(dropBehind); } }
@Override public void setDropBehind(Boolean dropBehind) throws IOException { underLyingStream.setDropBehind(dropBehind); } }
@Override public void setDropBehind(Boolean dropBehind) throws IOException { underLyingStream.setDropBehind(dropBehind); } }
@Override public void setDropBehind(Boolean dropBehind) throws IOException, UnsupportedOperationException { underlyingIs.setDropBehind(dropBehind); }
@Override public void setDropBehind(Boolean dropBehind) throws IOException, UnsupportedOperationException { try { underlyingIs.setDropBehind(dropBehind); } catch(FSError e) { throw FileSystemWrapper.propagateFSError(e); } }
private FSDataInputStreamWrapper(FileSystem fs, FileLink link, Path path, boolean dropBehind) throws IOException { assert (path == null) != (link == null); this.path = path; this.link = link; this.doCloseStreams = true; // If the fs is not an instance of HFileSystem, then create an instance of HFileSystem // that wraps over the specified fs. In this case, we will not be able to avoid // checksumming inside the filesystem. this.hfs = (fs instanceof HFileSystem) ? (HFileSystem)fs : new HFileSystem(fs); // Initially we are going to read the tail block. Open the reader w/FS checksum. this.useHBaseChecksumConfigured = this.useHBaseChecksum = false; this.stream = (link != null) ? link.open(hfs) : hfs.open(path); try { this.stream.setDropBehind(dropBehind); } catch (Exception e) { // Skipped. } }
static long readHdfsFile(FileSystem fs, Path p, long length, Boolean dropBehind) throws Exception { FSDataInputStream fis = null; long totalRead = 0; try { fis = fs.open(p); if (dropBehind != null) { fis.setDropBehind(dropBehind); } byte buf[] = new byte[8196]; while (length > 0) { int amt = (length > buf.length) ? buf.length : (int)length; int ret = fis.read(buf, 0, amt); if (ret == -1) { return totalRead; } totalRead += ret; length -= ret; } } catch (IOException e) { LOG.error("ioexception", e); } finally { if (fis != null) { fis.close(); } } throw new RuntimeException("unreachable"); }
@Test(timeout=120000) public void testSeekAfterSetDropBehind() throws Exception { // start a cluster LOG.info("testSeekAfterSetDropBehind"); Configuration conf = new HdfsConfiguration(); MiniDFSCluster cluster = null; String TEST_PATH = "/test"; int TEST_PATH_LEN = MAX_TEST_FILE_LEN; try { cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1) .build(); cluster.waitActive(); FileSystem fs = cluster.getFileSystem(); createHdfsFile(fs, new Path(TEST_PATH), TEST_PATH_LEN, false); // verify that we can seek after setDropBehind FSDataInputStream fis = fs.open(new Path(TEST_PATH)); try { Assert.assertTrue(fis.read() != -1); // create BlockReader fis.setDropBehind(false); // clear BlockReader fis.seek(2); // seek } finally { fis.close(); } } finally { if (cluster != null) { cluster.shutdown(); } } } }