Search in sources :

Example 1 with FsCheckpointStreamFactory

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

the class ChannelStateCheckpointWriterTest method testSmallFilesNotWritten.

@Test
@SuppressWarnings("ConstantConditions")
public void testSmallFilesNotWritten() throws Exception {
    int threshold = 100;
    File checkpointsDir = temporaryFolder.newFolder("checkpointsDir");
    File sharedStateDir = temporaryFolder.newFolder("sharedStateDir");
    FsCheckpointStreamFactory checkpointStreamFactory = new FsCheckpointStreamFactory(getSharedInstance(), fromLocalFile(checkpointsDir), fromLocalFile(sharedStateDir), threshold, threshold);
    ChannelStateWriteResult result = new ChannelStateWriteResult();
    ChannelStateCheckpointWriter writer = createWriter(result, checkpointStreamFactory.createCheckpointStateOutputStream(EXCLUSIVE));
    NetworkBuffer buffer = new NetworkBuffer(MemorySegmentFactory.allocateUnpooledSegment(threshold / 2), FreeingBufferRecycler.INSTANCE);
    writer.writeInput(new InputChannelInfo(1, 2), buffer);
    writer.completeOutput();
    writer.completeInput();
    assertTrue(result.isDone());
    assertEquals(0, checkpointsDir.list().length);
    assertEquals(0, sharedStateDir.list().length);
}
Also used : FsCheckpointStreamFactory(org.apache.flink.runtime.state.filesystem.FsCheckpointStreamFactory) NetworkBuffer(org.apache.flink.runtime.io.network.buffer.NetworkBuffer) File(java.io.File) Path.fromLocalFile(org.apache.flink.core.fs.Path.fromLocalFile) ChannelStateWriteResult(org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter.ChannelStateWriteResult) Test(org.junit.Test)

Example 2 with FsCheckpointStreamFactory

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

the class ChannelStateCheckpointWriterTest method testFileHandleSize.

@Test
public void testFileHandleSize() throws Exception {
    int numChannels = 3;
    int numWritesPerChannel = 4;
    int numBytesPerWrite = 5;
    ChannelStateWriteResult result = new ChannelStateWriteResult();
    ChannelStateCheckpointWriter writer = createWriter(result, new FsCheckpointStreamFactory(getSharedInstance(), fromLocalFile(temporaryFolder.newFolder("checkpointsDir")), fromLocalFile(temporaryFolder.newFolder("sharedStateDir")), numBytesPerWrite - 1, numBytesPerWrite - 1).createCheckpointStateOutputStream(EXCLUSIVE));
    InputChannelInfo[] channels = IntStream.range(0, numChannels).mapToObj(i -> new InputChannelInfo(0, i)).toArray(InputChannelInfo[]::new);
    for (int call = 0; call < numWritesPerChannel; call++) {
        for (int channel = 0; channel < numChannels; channel++) {
            write(writer, channels[channel], getData(numBytesPerWrite));
        }
    }
    writer.completeInput();
    writer.completeOutput();
    for (InputChannelStateHandle handle : result.inputChannelStateHandles.get()) {
        assertEquals((Integer.BYTES + numBytesPerWrite) * numWritesPerChannel, handle.getStateSize());
    }
}
Also used : IntStream(java.util.stream.IntStream) MemorySegmentFactory.wrap(org.apache.flink.core.memory.MemorySegmentFactory.wrap) ByteArrayOutputStream(java.io.ByteArrayOutputStream) EXCLUSIVE(org.apache.flink.runtime.state.CheckpointedStateScope.EXCLUSIVE) HashMap(java.util.HashMap) Random(java.util.Random) RunnableWithException(org.apache.flink.util.function.RunnableWithException) NetworkBuffer(org.apache.flink.runtime.io.network.buffer.NetworkBuffer) Collections.singletonList(java.util.Collections.singletonList) DataOutputStream(java.io.DataOutputStream) MemoryCheckpointOutputStream(org.apache.flink.runtime.state.memory.MemCheckpointStreamFactory.MemoryCheckpointOutputStream) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) MemorySegment(org.apache.flink.core.memory.MemorySegment) MemorySegmentFactory(org.apache.flink.core.memory.MemorySegmentFactory) InputChannelStateHandle(org.apache.flink.runtime.state.InputChannelStateHandle) Assert.assertTrue(org.junit.Assert.assertTrue) FreeingBufferRecycler(org.apache.flink.runtime.io.network.buffer.FreeingBufferRecycler) Test(org.junit.Test) IOException(java.io.IOException) ChannelStateWriteResult(org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter.ChannelStateWriteResult) StreamStateHandle(org.apache.flink.runtime.state.StreamStateHandle) Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) File(java.io.File) Rule(org.junit.Rule) FsCheckpointStreamFactory(org.apache.flink.runtime.state.filesystem.FsCheckpointStreamFactory) Assert.assertFalse(org.junit.Assert.assertFalse) TemporaryFolder(org.junit.rules.TemporaryFolder) LocalFileSystem.getSharedInstance(org.apache.flink.core.fs.local.LocalFileSystem.getSharedInstance) Assert.assertEquals(org.junit.Assert.assertEquals) CheckpointStateOutputStream(org.apache.flink.runtime.state.CheckpointStateOutputStream) Path.fromLocalFile(org.apache.flink.core.fs.Path.fromLocalFile) FsCheckpointStreamFactory(org.apache.flink.runtime.state.filesystem.FsCheckpointStreamFactory) ChannelStateWriteResult(org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter.ChannelStateWriteResult) InputChannelStateHandle(org.apache.flink.runtime.state.InputChannelStateHandle) Test(org.junit.Test)

Example 3 with FsCheckpointStreamFactory

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

the class RocksDBStateUploaderTest method testMultiThreadUploadCorrectly.

/**
 * Test that upload files with multi-thread correctly.
 */
@Test
public void testMultiThreadUploadCorrectly() throws Exception {
    File checkpointPrivateFolder = temporaryFolder.newFolder("private");
    org.apache.flink.core.fs.Path checkpointPrivateDirectory = org.apache.flink.core.fs.Path.fromLocalFile(checkpointPrivateFolder);
    File checkpointSharedFolder = temporaryFolder.newFolder("shared");
    org.apache.flink.core.fs.Path checkpointSharedDirectory = org.apache.flink.core.fs.Path.fromLocalFile(checkpointSharedFolder);
    FileSystem fileSystem = checkpointPrivateDirectory.getFileSystem();
    int fileStateSizeThreshold = 1024;
    int writeBufferSize = 4096;
    FsCheckpointStreamFactory checkpointStreamFactory = new FsCheckpointStreamFactory(fileSystem, checkpointPrivateDirectory, checkpointSharedDirectory, fileStateSizeThreshold, writeBufferSize);
    String localFolder = "local";
    temporaryFolder.newFolder(localFolder);
    int sstFileCount = 6;
    Map<StateHandleID, Path> sstFilePaths = generateRandomSstFiles(localFolder, sstFileCount, fileStateSizeThreshold);
    try (RocksDBStateUploader rocksDBStateUploader = new RocksDBStateUploader(5)) {
        Map<StateHandleID, StreamStateHandle> sstFiles = rocksDBStateUploader.uploadFilesToCheckpointFs(sstFilePaths, checkpointStreamFactory, CheckpointedStateScope.SHARED, new CloseableRegistry());
        for (Map.Entry<StateHandleID, Path> entry : sstFilePaths.entrySet()) {
            assertStateContentEqual(entry.getValue(), sstFiles.get(entry.getKey()).openInputStream());
        }
    }
}
Also used : Path(java.nio.file.Path) CloseableRegistry(org.apache.flink.core.fs.CloseableRegistry) StreamStateHandle(org.apache.flink.runtime.state.StreamStateHandle) ByteStreamStateHandle(org.apache.flink.runtime.state.memory.ByteStreamStateHandle) StateHandleID(org.apache.flink.runtime.state.StateHandleID) FileSystem(org.apache.flink.core.fs.FileSystem) FsCheckpointStreamFactory(org.apache.flink.runtime.state.filesystem.FsCheckpointStreamFactory) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 4 with FsCheckpointStreamFactory

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

the class RocksIncrementalSnapshotStrategyTest method testCheckpointIsIncremental.

// Verify the next checkpoint is still incremental after a savepoint completed.
@Test
public void testCheckpointIsIncremental() throws Exception {
    try (CloseableRegistry closeableRegistry = new CloseableRegistry();
        RocksIncrementalSnapshotStrategy checkpointSnapshotStrategy = createSnapshotStrategy(closeableRegistry)) {
        FsCheckpointStreamFactory checkpointStreamFactory = createFsCheckpointStreamFactory();
        // make and notify checkpoint with id 1
        snapshot(1L, checkpointSnapshotStrategy, checkpointStreamFactory, closeableRegistry);
        checkpointSnapshotStrategy.notifyCheckpointComplete(1L);
        // notify savepoint with id 2
        checkpointSnapshotStrategy.notifyCheckpointComplete(2L);
        // make checkpoint with id 3
        IncrementalRemoteKeyedStateHandle incrementalRemoteKeyedStateHandle3 = snapshot(3L, checkpointSnapshotStrategy, checkpointStreamFactory, closeableRegistry);
        // If 3rd checkpoint's placeholderStateHandleCount > 0,it means 3rd checkpoint is
        // incremental.
        Map<StateHandleID, StreamStateHandle> sharedState3 = incrementalRemoteKeyedStateHandle3.getSharedState();
        long placeholderStateHandleCount = sharedState3.entrySet().stream().filter(e -> e.getValue() instanceof PlaceholderStreamStateHandle).count();
        Assert.assertTrue(placeholderStateHandleCount > 0);
    }
}
Also used : RocksDBResource(org.apache.flink.contrib.streaming.state.RocksDBResource) StateHandleID(org.apache.flink.runtime.state.StateHandleID) IncrementalRemoteKeyedStateHandle(org.apache.flink.runtime.state.IncrementalRemoteKeyedStateHandle) ResourceGuard(org.apache.flink.util.ResourceGuard) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) IntSerializer(org.apache.flink.api.common.typeutils.base.IntSerializer) RocksDBOptions(org.apache.flink.contrib.streaming.state.RocksDBOptions) CloseableRegistry(org.apache.flink.core.fs.CloseableRegistry) RocksDB(org.rocksdb.RocksDB) TestLocalRecoveryConfig(org.apache.flink.runtime.state.TestLocalRecoveryConfig) Map(java.util.Map) RocksDBException(org.rocksdb.RocksDBException) KeyGroupRange(org.apache.flink.runtime.state.KeyGroupRange) StateDescriptor(org.apache.flink.api.common.state.StateDescriptor) CompositeKeySerializationUtils(org.apache.flink.runtime.state.CompositeKeySerializationUtils) Test(org.junit.Test) IOException(java.io.IOException) CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) UUID(java.util.UUID) ArrayListSerializer(org.apache.flink.runtime.state.ArrayListSerializer) StreamStateHandle(org.apache.flink.runtime.state.StreamStateHandle) File(java.io.File) PlaceholderStreamStateHandle(org.apache.flink.runtime.state.PlaceholderStreamStateHandle) Rule(org.junit.Rule) TreeMap(java.util.TreeMap) FsCheckpointStreamFactory(org.apache.flink.runtime.state.filesystem.FsCheckpointStreamFactory) ColumnFamilyHandle(org.rocksdb.ColumnFamilyHandle) RegisteredKeyValueStateBackendMetaInfo(org.apache.flink.runtime.state.RegisteredKeyValueStateBackendMetaInfo) RocksDBKeyedStateBackend(org.apache.flink.contrib.streaming.state.RocksDBKeyedStateBackend) Assert(org.junit.Assert) TemporaryFolder(org.junit.rules.TemporaryFolder) SortedMap(java.util.SortedMap) LocalFileSystem.getSharedInstance(org.apache.flink.core.fs.local.LocalFileSystem.getSharedInstance) RocksDBStateUploader(org.apache.flink.contrib.streaming.state.RocksDBStateUploader) Path.fromLocalFile(org.apache.flink.core.fs.Path.fromLocalFile) PlaceholderStreamStateHandle(org.apache.flink.runtime.state.PlaceholderStreamStateHandle) StreamStateHandle(org.apache.flink.runtime.state.StreamStateHandle) PlaceholderStreamStateHandle(org.apache.flink.runtime.state.PlaceholderStreamStateHandle) StateHandleID(org.apache.flink.runtime.state.StateHandleID) FsCheckpointStreamFactory(org.apache.flink.runtime.state.filesystem.FsCheckpointStreamFactory) IncrementalRemoteKeyedStateHandle(org.apache.flink.runtime.state.IncrementalRemoteKeyedStateHandle) CloseableRegistry(org.apache.flink.core.fs.CloseableRegistry) Test(org.junit.Test)

Example 5 with FsCheckpointStreamFactory

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

the class RocksIncrementalSnapshotStrategyTest method createFsCheckpointStreamFactory.

public FsCheckpointStreamFactory createFsCheckpointStreamFactory() throws IOException {
    int threshold = 100;
    File checkpointsDir = tmp.newFolder("checkpointsDir");
    File sharedStateDir = tmp.newFolder("sharedStateDir");
    FsCheckpointStreamFactory checkpointStreamFactory = new FsCheckpointStreamFactory(getSharedInstance(), fromLocalFile(checkpointsDir), fromLocalFile(sharedStateDir), threshold, threshold);
    return checkpointStreamFactory;
}
Also used : FsCheckpointStreamFactory(org.apache.flink.runtime.state.filesystem.FsCheckpointStreamFactory) File(java.io.File) Path.fromLocalFile(org.apache.flink.core.fs.Path.fromLocalFile)

Aggregations

File (java.io.File)5 FsCheckpointStreamFactory (org.apache.flink.runtime.state.filesystem.FsCheckpointStreamFactory)5 Path.fromLocalFile (org.apache.flink.core.fs.Path.fromLocalFile)4 Test (org.junit.Test)4 Map (java.util.Map)3 StreamStateHandle (org.apache.flink.runtime.state.StreamStateHandle)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 CloseableRegistry (org.apache.flink.core.fs.CloseableRegistry)2 LocalFileSystem.getSharedInstance (org.apache.flink.core.fs.local.LocalFileSystem.getSharedInstance)2 ChannelStateWriteResult (org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter.ChannelStateWriteResult)2 NetworkBuffer (org.apache.flink.runtime.io.network.buffer.NetworkBuffer)2 StateHandleID (org.apache.flink.runtime.state.StateHandleID)2 Rule (org.junit.Rule)2 TemporaryFolder (org.junit.rules.TemporaryFolder)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Collections.singletonList (java.util.Collections.singletonList)1