Java Code Examples for org.apache.flink.core.fs.FSDataOutputStream#close()
The following examples show how to use
org.apache.flink.core.fs.FSDataOutputStream#close() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RheemFileOutputFormat.java From rheem with Apache License 2.0 | 6 votes |
@Override public void close() throws IOException { try { this.writer.close(); DataOutputViewStreamWrapper o = this.outView; if (o != null) { o.close(); } } finally { final FSDataOutputStream s = this.stream; if (s != null) { this.stream = null; s.close(); } } }
Example 2
Source File: FileOutputFormat.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Override public void close() throws IOException { final FSDataOutputStream s = this.stream; if (s != null) { this.stream = null; s.close(); } }
Example 3
Source File: RocksDBStateDownloader.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * Copies the file from a single state handle to the given path. */ private void downloadDataForStateHandle( Path restoreFilePath, StreamStateHandle remoteFileHandle, CloseableRegistry closeableRegistry) throws IOException { FSDataInputStream inputStream = null; FSDataOutputStream outputStream = null; try { FileSystem restoreFileSystem = restoreFilePath.getFileSystem(); inputStream = remoteFileHandle.openInputStream(); closeableRegistry.registerCloseable(inputStream); outputStream = restoreFileSystem.create(restoreFilePath, FileSystem.WriteMode.OVERWRITE); closeableRegistry.registerCloseable(outputStream); byte[] buffer = new byte[8 * 1024]; while (true) { int numBytes = inputStream.read(buffer); if (numBytes == -1) { break; } outputStream.write(buffer, 0, numBytes); } } finally { if (closeableRegistry.unregisterCloseable(inputStream)) { inputStream.close(); } if (closeableRegistry.unregisterCloseable(outputStream)) { outputStream.close(); } } }
Example 4
Source File: CheckpointStateOutputStreamTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * This test validates that a close operation can happen even while a 'closeAndGetHandle()' * call is in progress. * <p> * <p>That behavior is essential for fast cancellation (concurrent cleanup). */ @Test public void testCloseDoesNotLock() throws Exception { final Path folder = new Path(tmp.newFolder().toURI()); final String fileName = "this-is-ignored-anyways.file"; final FileSystem fileSystem = spy(new TestFs((path) -> new BlockerStream())); final FSDataOutputStream checkpointStream = createTestStream(fileSystem, folder, fileName); final OneShotLatch sync = new OneShotLatch(); final CheckedThread thread = new CheckedThread() { @Override public void go() throws Exception { sync.trigger(); // that call should now block, because it accesses the position closeAndGetResult(checkpointStream); } }; thread.start(); sync.await(); checkpointStream.close(); // the thread may or may not fail, that depends on the thread race // it is not important for this test, important is that the thread does not freeze/lock up try { thread.sync(); } catch (IOException ignored) {} }
Example 5
Source File: FileOutputFormat.java From flink with Apache License 2.0 | 5 votes |
@Override public void close() throws IOException { final FSDataOutputStream s = this.stream; if (s != null) { this.stream = null; s.close(); } }
Example 6
Source File: RocksDBStateDownloader.java From flink with Apache License 2.0 | 5 votes |
/** * Copies the file from a single state handle to the given path. */ private void downloadDataForStateHandle( Path restoreFilePath, StreamStateHandle remoteFileHandle, CloseableRegistry closeableRegistry) throws IOException { FSDataInputStream inputStream = null; FSDataOutputStream outputStream = null; try { FileSystem restoreFileSystem = restoreFilePath.getFileSystem(); inputStream = remoteFileHandle.openInputStream(); closeableRegistry.registerCloseable(inputStream); outputStream = restoreFileSystem.create(restoreFilePath, FileSystem.WriteMode.OVERWRITE); closeableRegistry.registerCloseable(outputStream); byte[] buffer = new byte[8 * 1024]; while (true) { int numBytes = inputStream.read(buffer); if (numBytes == -1) { break; } outputStream.write(buffer, 0, numBytes); } } finally { if (closeableRegistry.unregisterCloseable(inputStream)) { inputStream.close(); } if (closeableRegistry.unregisterCloseable(outputStream)) { outputStream.close(); } } }
Example 7
Source File: CheckpointStateOutputStreamTest.java From flink with Apache License 2.0 | 5 votes |
/** * This test validates that a close operation can happen even while a 'closeAndGetHandle()' * call is in progress. * <p> * <p>That behavior is essential for fast cancellation (concurrent cleanup). */ @Test public void testCloseDoesNotLock() throws Exception { final Path folder = new Path(tmp.newFolder().toURI()); final String fileName = "this-is-ignored-anyways.file"; final FileSystem fileSystem = spy(new TestFs((path) -> new BlockerStream())); final FSDataOutputStream checkpointStream = createTestStream(fileSystem, folder, fileName); final OneShotLatch sync = new OneShotLatch(); final CheckedThread thread = new CheckedThread() { @Override public void go() throws Exception { sync.trigger(); // that call should now block, because it accesses the position closeAndGetResult(checkpointStream); } }; thread.start(); sync.await(); checkpointStream.close(); // the thread may or may not fail, that depends on the thread race // it is not important for this test, important is that the thread does not freeze/lock up try { thread.sync(); } catch (IOException ignored) {} }
Example 8
Source File: RocksDBCheckpointIterator.java From bravo with Apache License 2.0 | 5 votes |
private void copyStateDataHandleData( Path restoreFilePath, StreamStateHandle remoteFileHandle) throws IOException { FileSystem restoreFileSystem = restoreFilePath.getFileSystem(); FSDataInputStream inputStream = null; FSDataOutputStream outputStream = null; try { inputStream = remoteFileHandle.openInputStream(); cancelStreamRegistry.registerCloseable(inputStream); outputStream = restoreFileSystem.create(restoreFilePath, FileSystem.WriteMode.OVERWRITE); cancelStreamRegistry.registerCloseable(outputStream); byte[] buffer = new byte[8 * 1024]; while (true) { int numBytes = inputStream.read(buffer); if (numBytes == -1) { break; } outputStream.write(buffer, 0, numBytes); } } finally { if (cancelStreamRegistry.unregisterCloseable(inputStream)) { inputStream.close(); } if (cancelStreamRegistry.unregisterCloseable(outputStream)) { outputStream.close(); } } }
Example 9
Source File: FileOutputFormat.java From flink with Apache License 2.0 | 5 votes |
@Override public void close() throws IOException { final FSDataOutputStream s = this.stream; if (s != null) { this.stream = null; s.close(); } }
Example 10
Source File: CheckpointStateOutputStreamTest.java From flink with Apache License 2.0 | 5 votes |
/** * This test validates that a close operation can happen even while a 'closeAndGetHandle()' * call is in progress. * <p> * <p>That behavior is essential for fast cancellation (concurrent cleanup). */ @Test public void testCloseDoesNotLock() throws Exception { final Path folder = new Path(tmp.newFolder().toURI()); final String fileName = "this-is-ignored-anyways.file"; final FileSystem fileSystem = spy(new TestFs((path) -> new BlockerStream())); final FSDataOutputStream checkpointStream = createTestStream(fileSystem, folder, fileName); final OneShotLatch sync = new OneShotLatch(); final CheckedThread thread = new CheckedThread() { @Override public void go() throws Exception { sync.trigger(); // that call should now block, because it accesses the position closeAndGetResult(checkpointStream); } }; thread.start(); sync.await(); checkpointStream.close(); // the thread may or may not fail, that depends on the thread race // it is not important for this test, important is that the thread does not freeze/lock up try { thread.sync(); } catch (IOException ignored) {} }