/** * Flushes cached data on Alluxio. * * Called on explicit sync() operation or at close(). * * @param path The path on the FS of the file to close * @param fi FileInfo data struct kept by FUSE * @return 0 on success, a negative value on error */ @Override public int flush(String path, FuseFileInfo fi) { LOG.trace("flush({})", path); final long fd = fi.fh.get(); OpenFileEntry oe = mOpenFiles.getFirstByField(ID_INDEX, fd); if (oe == null) { LOG.error("Cannot find fd for {} in table", path); return -ErrorCodes.EBADFD(); } if (oe.getOut() != null) { try { oe.getOut().flush(); } catch (IOException e) { LOG.error("Failed to flush {}", path, e); return -ErrorCodes.EIO(); } } else { LOG.debug("Not flushing: {} was not open for writing", path); } return 0; }
/** * Tests that {@link FileOutStream#flush()} will flush the under store stream. */ @Test public void flush() throws IOException { Assert.assertFalse(mUnderStorageFlushed.get()); mTestStream.flush(); Assert.assertTrue(mUnderStorageFlushed.get()); }
/** * Tests that the number of bytes written is correct when the stream is created with different * under storage types. */ @Test public void getBytesWrittenWithDifferentUnderStorageType() throws IOException { for (WriteType type : WriteType.values()) { OutStreamOptions options = OutStreamOptions.defaults(sConf).setBlockSizeBytes(BLOCK_LENGTH).setWriteType(type) .setUfsPath(FILE_NAME.getPath()); mTestStream = createTestStream(FILE_NAME, options); mTestStream.write(BufferUtils.getIncreasingByteArray((int) BLOCK_LENGTH)); mTestStream.flush(); Assert.assertEquals(BLOCK_LENGTH, mTestStream.getBytesWritten()); } }