Search in sources :

Example 11 with RecoverableWriter

use of org.apache.flink.core.fs.RecoverableWriter in project flink by apache.

the class HadoopS3RecoverableWriterITCase method testCommitAfterRecovery.

// ----------------------- Test Recovery -----------------------
@Test
public void testCommitAfterRecovery() throws Exception {
    final Path path = new Path(basePathForTest, "part-0");
    final RecoverableWriter initWriter = getRecoverableWriter();
    final RecoverableFsDataOutputStream stream = initWriter.open(path);
    stream.write(bytesOf(testData1));
    stream.persist();
    stream.persist();
    // and write some more data
    stream.write(bytesOf(testData2));
    final RecoverableWriter.CommitRecoverable recoverable = stream.closeForCommit().getRecoverable();
    final byte[] serializedRecoverable = initWriter.getCommitRecoverableSerializer().serialize(recoverable);
    // get a new serializer from a new writer to make sure that no pre-initialized state leaks
    // in.
    final RecoverableWriter newWriter = getRecoverableWriter();
    final SimpleVersionedSerializer<RecoverableWriter.CommitRecoverable> deserializer = newWriter.getCommitRecoverableSerializer();
    final RecoverableWriter.CommitRecoverable recoveredRecoverable = deserializer.deserialize(deserializer.getVersion(), serializedRecoverable);
    final RecoverableFsDataOutputStream.Committer committer = newWriter.recoverForCommit(recoveredRecoverable);
    committer.commitAfterRecovery();
    Assert.assertEquals(testData1 + testData2, getContentsOfFile(path));
}
Also used : Path(org.apache.flink.core.fs.Path) RecoverableWriter(org.apache.flink.core.fs.RecoverableWriter) RecoverableFsDataOutputStream(org.apache.flink.core.fs.RecoverableFsDataOutputStream) Test(org.junit.Test)

Example 12 with RecoverableWriter

use of org.apache.flink.core.fs.RecoverableWriter in project flink by apache.

the class HadoopS3RecoverableWriterITCase method testCallingDeleteObjectTwiceDoesNotThroughException.

@Test
public void testCallingDeleteObjectTwiceDoesNotThroughException() throws Exception {
    final RecoverableWriter writer = getRecoverableWriter();
    final Path path = new Path(basePathForTest, "part-0");
    final RecoverableFsDataOutputStream stream = writer.open(path);
    stream.write(bytesOf(testData1));
    S3Recoverable recoverable = (S3Recoverable) stream.persist();
    stream.closeForCommit().commit();
    // still the data is there as we have not deleted them from the tmp object
    final String content = getContentsOfFile(new Path('/' + recoverable.incompleteObjectName()));
    Assert.assertEquals(testData1, content);
    boolean successfullyDeletedState = writer.cleanupRecoverableState(recoverable);
    Assert.assertTrue(successfullyDeletedState);
    boolean unsuccessfulDeletion = writer.cleanupRecoverableState(recoverable);
    Assert.assertFalse(unsuccessfulDeletion);
}
Also used : Path(org.apache.flink.core.fs.Path) RecoverableWriter(org.apache.flink.core.fs.RecoverableWriter) RecoverableFsDataOutputStream(org.apache.flink.core.fs.RecoverableFsDataOutputStream) S3Recoverable(org.apache.flink.fs.s3.common.writer.S3Recoverable) Test(org.junit.Test)

Example 13 with RecoverableWriter

use of org.apache.flink.core.fs.RecoverableWriter in project flink by apache.

the class GSFileSystemScenarioTest method simpleWriteTest.

/* Test writing a single array of bytes to a stream. */
@Test
public void simpleWriteTest() throws IOException {
    // only run the test for valid chunk sizes
    assumeTrue(writeChunkSizeIsValid);
    // create the options and writer
    GSFileSystemOptions options = new GSFileSystemOptions(flinkConfig);
    RecoverableWriter writer = new GSRecoverableWriter(storage, options);
    // create a stream and write some random bytes to it
    RecoverableFsDataOutputStream stream = writer.open(path);
    byte[] data = new byte[128];
    random.nextBytes(data);
    stream.write(data);
    // close for commit
    RecoverableFsDataOutputStream.Committer committer = stream.closeForCommit();
    // there should be a single blob now, in the specified temporary bucket or, if no temporary
    // bucket
    // specified, in the final bucket
    assertEquals(1, storage.blobs.size());
    GSBlobIdentifier temporaryBlobIdentifier = (GSBlobIdentifier) storage.blobs.keySet().toArray()[0];
    String expectedTemporaryBucket = StringUtils.isNullOrWhitespaceOnly(temporaryBucketName) ? blobIdentifier.bucketName : temporaryBucketName;
    assertEquals(expectedTemporaryBucket, temporaryBlobIdentifier.bucketName);
    // commit
    committer.commit();
    // there should be exactly one blob after commit, with the expected contents.
    // all temporary blobs should be removed.
    assertEquals(1, storage.blobs.size());
    MockBlobStorage.BlobValue blobValue = storage.blobs.get(blobIdentifier);
    assertArrayEquals(data, blobValue.content);
}
Also used : RecoverableWriter(org.apache.flink.core.fs.RecoverableWriter) GSRecoverableWriter(org.apache.flink.fs.gs.writer.GSRecoverableWriter) RecoverableFsDataOutputStream(org.apache.flink.core.fs.RecoverableFsDataOutputStream) GSRecoverableWriter(org.apache.flink.fs.gs.writer.GSRecoverableWriter) GSBlobIdentifier(org.apache.flink.fs.gs.storage.GSBlobIdentifier) MockBlobStorage(org.apache.flink.fs.gs.storage.MockBlobStorage) Test(org.junit.Test)

Example 14 with RecoverableWriter

use of org.apache.flink.core.fs.RecoverableWriter in project flink by apache.

the class OutputStreamBasedPartFileRecoverableMigrationTest method testSerializationPending.

@Test
public void testSerializationPending() throws IOException {
    String scenario = "pending";
    java.nio.file.Path path = resolveVersionPath(previousVersion, scenario);
    RecoverableWriter writer = FileSystem.getLocalFileSystem().createRecoverableWriter();
    OutputStreamBasedPendingFileRecoverableSerializer serializer = new OutputStreamBasedPendingFileRecoverableSerializer(writer.getCommitRecoverableSerializer());
    PendingFileRecoverable recoverable = serializer.deserialize(previousVersion, Files.readAllBytes(path.resolve("recoverable")));
    Assert.assertTrue(recoverable instanceof OutputStreamBasedPendingFileRecoverable);
    // make sure the CommitRecoverable is valid
    writer.recoverForCommit(((OutputStreamBasedPendingFileRecoverable) recoverable).getCommitRecoverable());
}
Also used : RecoverableWriter(org.apache.flink.core.fs.RecoverableWriter) OutputStreamBasedPendingFileRecoverableSerializer(org.apache.flink.streaming.api.functions.sink.filesystem.OutputStreamBasedPartFileWriter.OutputStreamBasedPendingFileRecoverableSerializer) PendingFileRecoverable(org.apache.flink.streaming.api.functions.sink.filesystem.InProgressFileWriter.PendingFileRecoverable) OutputStreamBasedPendingFileRecoverable(org.apache.flink.streaming.api.functions.sink.filesystem.OutputStreamBasedPartFileWriter.OutputStreamBasedPendingFileRecoverable) OutputStreamBasedPendingFileRecoverable(org.apache.flink.streaming.api.functions.sink.filesystem.OutputStreamBasedPartFileWriter.OutputStreamBasedPendingFileRecoverable) Test(org.junit.Test)

Example 15 with RecoverableWriter

use of org.apache.flink.core.fs.RecoverableWriter in project flink by apache.

the class OutputStreamBasedPartFileRecoverableMigrationTest method prepareDeserializationPending.

@Test
@Ignore
public void prepareDeserializationPending() throws IOException {
    String scenario = "pending";
    java.nio.file.Path path = resolveVersionPath(CURRENT_VERSION, scenario);
    RecoverableWriter writer = FileSystem.getLocalFileSystem().createRecoverableWriter();
    OutputStreamBasedPendingFileRecoverableSerializer serializer = new OutputStreamBasedPendingFileRecoverableSerializer(writer.getCommitRecoverableSerializer());
    RecoverableFsDataOutputStream outputStream = writer.open(new Path(path.resolve("content").toString()));
    outputStream.write(PENDING_CONTENT.getBytes(StandardCharsets.UTF_8));
    CommitRecoverable commitRecoverable = outputStream.closeForCommit().getRecoverable();
    OutputStreamBasedPendingFileRecoverable recoverable = new OutputStreamBasedPendingFileRecoverable(commitRecoverable);
    byte[] bytes = serializer.serialize(recoverable);
    Files.write(path.resolve("recoverable"), bytes);
}
Also used : Path(org.apache.flink.core.fs.Path) RecoverableWriter(org.apache.flink.core.fs.RecoverableWriter) OutputStreamBasedPendingFileRecoverableSerializer(org.apache.flink.streaming.api.functions.sink.filesystem.OutputStreamBasedPartFileWriter.OutputStreamBasedPendingFileRecoverableSerializer) RecoverableFsDataOutputStream(org.apache.flink.core.fs.RecoverableFsDataOutputStream) CommitRecoverable(org.apache.flink.core.fs.RecoverableWriter.CommitRecoverable) OutputStreamBasedPendingFileRecoverable(org.apache.flink.streaming.api.functions.sink.filesystem.OutputStreamBasedPartFileWriter.OutputStreamBasedPendingFileRecoverable) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

RecoverableWriter (org.apache.flink.core.fs.RecoverableWriter)24 Test (org.junit.Test)22 RecoverableFsDataOutputStream (org.apache.flink.core.fs.RecoverableFsDataOutputStream)21 Path (org.apache.flink.core.fs.Path)16 Ignore (org.junit.Ignore)4 ResumeRecoverable (org.apache.flink.core.fs.RecoverableWriter.ResumeRecoverable)3 MockBlobStorage (org.apache.flink.fs.gs.storage.MockBlobStorage)3 GSRecoverableWriter (org.apache.flink.fs.gs.writer.GSRecoverableWriter)3 OutputStreamBasedInProgressFileRecoverable (org.apache.flink.streaming.api.functions.sink.filesystem.OutputStreamBasedPartFileWriter.OutputStreamBasedInProgressFileRecoverable)3 OutputStreamBasedPendingFileRecoverable (org.apache.flink.streaming.api.functions.sink.filesystem.OutputStreamBasedPartFileWriter.OutputStreamBasedPendingFileRecoverable)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 CommitRecoverable (org.apache.flink.core.fs.RecoverableWriter.CommitRecoverable)2 S3Recoverable (org.apache.flink.fs.s3.common.writer.S3Recoverable)2 OutputStreamBasedInProgressFileRecoverableSerializer (org.apache.flink.streaming.api.functions.sink.filesystem.OutputStreamBasedPartFileWriter.OutputStreamBasedInProgressFileRecoverableSerializer)2 OutputStreamBasedPendingFileRecoverableSerializer (org.apache.flink.streaming.api.functions.sink.filesystem.OutputStreamBasedPartFileWriter.OutputStreamBasedPendingFileRecoverableSerializer)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 FSDataInputStream (org.apache.flink.core.fs.FSDataInputStream)1 GSBlobIdentifier (org.apache.flink.fs.gs.storage.GSBlobIdentifier)1 InProgressFileRecoverable (org.apache.flink.streaming.api.functions.sink.filesystem.InProgressFileWriter.InProgressFileRecoverable)1