Search in sources :

Example 6 with FsCheckpointStateOutputStream

use of org.apache.flink.runtime.state.filesystem.FsCheckpointStreamFactory.FsCheckpointStateOutputStream in project flink by apache.

the class FsCheckpointStorageAccessTest method testDirectoriesForExclusiveAndSharedState.

@Test
public void testDirectoriesForExclusiveAndSharedState() throws Exception {
    final FileSystem fs = LocalFileSystem.getSharedInstance();
    final Path checkpointDir = randomTempPath();
    final Path sharedStateDir = randomTempPath();
    FsCheckpointStorageLocation storageLocation = new FsCheckpointStorageLocation(fs, checkpointDir, sharedStateDir, randomTempPath(), CheckpointStorageLocationReference.getDefault(), FILE_SIZE_THRESHOLD, WRITE_BUFFER_SIZE);
    assertNotEquals(storageLocation.getCheckpointDirectory(), storageLocation.getSharedStateDirectory());
    assertEquals(0, fs.listStatus(storageLocation.getCheckpointDirectory()).length);
    assertEquals(0, fs.listStatus(storageLocation.getSharedStateDirectory()).length);
    // create exclusive state
    FsCheckpointStateOutputStream exclusiveStream = storageLocation.createCheckpointStateOutputStream(CheckpointedStateScope.EXCLUSIVE);
    exclusiveStream.write(42);
    exclusiveStream.flushToFile();
    StreamStateHandle exclusiveHandle = exclusiveStream.closeAndGetHandle();
    assertEquals(1, fs.listStatus(storageLocation.getCheckpointDirectory()).length);
    assertEquals(0, fs.listStatus(storageLocation.getSharedStateDirectory()).length);
    // create shared state
    FsCheckpointStateOutputStream sharedStream = storageLocation.createCheckpointStateOutputStream(CheckpointedStateScope.SHARED);
    sharedStream.write(42);
    sharedStream.flushToFile();
    StreamStateHandle sharedHandle = sharedStream.closeAndGetHandle();
    assertEquals(1, fs.listStatus(storageLocation.getCheckpointDirectory()).length);
    assertEquals(1, fs.listStatus(storageLocation.getSharedStateDirectory()).length);
    // drop state
    exclusiveHandle.discardState();
    sharedHandle.discardState();
}
Also used : Path(org.apache.flink.core.fs.Path) FsCheckpointStateOutputStream(org.apache.flink.runtime.state.filesystem.FsCheckpointStreamFactory.FsCheckpointStateOutputStream) StreamStateHandle(org.apache.flink.runtime.state.StreamStateHandle) LocalFileSystem(org.apache.flink.core.fs.local.LocalFileSystem) TestFileSystem(org.apache.flink.testutils.TestFileSystem) DuplicatingFileSystem(org.apache.flink.core.fs.DuplicatingFileSystem) FileSystem(org.apache.flink.core.fs.FileSystem) Test(org.junit.Test)

Aggregations

FsCheckpointStateOutputStream (org.apache.flink.runtime.state.filesystem.FsCheckpointStreamFactory.FsCheckpointStateOutputStream)6 Test (org.junit.Test)6 Path (org.apache.flink.core.fs.Path)4 File (java.io.File)3 IOException (java.io.IOException)3 StreamStateHandle (org.apache.flink.runtime.state.StreamStateHandle)3 JobID (org.apache.flink.api.common.JobID)2 FileSystem (org.apache.flink.core.fs.FileSystem)2 CheckpointStateOutputStream (org.apache.flink.runtime.state.CheckpointStateOutputStream)2 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 Random (java.util.Random)1 DuplicatingFileSystem (org.apache.flink.core.fs.DuplicatingFileSystem)1 LocalFileSystem (org.apache.flink.core.fs.local.LocalFileSystem)1 ByteStreamStateHandle (org.apache.flink.runtime.state.memory.ByteStreamStateHandle)1 TestFileSystem (org.apache.flink.testutils.TestFileSystem)1