Stream data from flink to S3

Viewed 339

I am using Flink on amazon EMR and want to stream results of my pipeline to s3 bucket.

I am using Flink version => 1.11.2

This is a code snippet of how the code looks right now variable :

val outputPath = new Path("s3://test/flinkStreamTest/failureLogs/dt=2021-04-15/")

val sink: StreamingFileSink[String] = StreamingFileSink
      .forRowFormat(outputPath, new SimpleStringEncoder[String]("UTF-8"))
      .withRollingPolicy(
        DefaultRollingPolicy.builder()
          .withRolloverInterval(TimeUnit.MINUTES.toMillis(15))
          .withInactivityInterval(TimeUnit.MINUTES.toMillis(5))
          .withMaxPartSize(1024 * 1024 * 1024)
          .build()
      )
      .build()

val enrichedStream = AsyncDataStream
      .unorderedWait(
        resConsumer,
        new AsyncElasticRequest(elasticIndexName, elasticHost, elasticPort),
        asyncTimeOut.toInt, TimeUnit.MILLISECONDS,
        asyncCapacity.toInt
      ) // this is my pipeline result. it returns a string

enrichedStream.addSink(sink)
   
env.execute("run pipeline") // this is just to run the pipeline

And this is the error i am currently getting;

java.lang.UnsupportedOperationException: Recoverable writers on Hadoop are only supported for HDFS
    at org.apache.flink.runtime.fs.hdfs.HadoopRecoverableWriter.<init>(HadoopRecoverableWriter.java:61)
    at org.apache.flink.runtime.fs.hdfs.HadoopFileSystem.createRecoverableWriter(HadoopFileSystem.java:202)
    at org.apache.flink.core.fs.SafetyNetWrapperFileSystem.createRecoverableWriter(SafetyNetWrapperFileSystem.java:69)
    at org.apache.flink.streaming.api.functions.sink.filesystem.StreamingFileSink$RowFormatBuilder.createBuckets(StreamingFileSink.java:260)
    at org.apache.flink.streaming.api.functions.sink.filesystem.StreamingFileSink.initializeState(StreamingFileSink.java:396)
    at org.apache.flink.streaming.util.functions.StreamingFunctionUtils.tryRestoreFunction(StreamingFunctionUtils.java:185)
    at org.apache.flink.streaming.util.functions.StreamingFunctionUtils.restoreFunctionState(StreamingFunctionUtils.java:167)
    at org.apache.flink.streaming.api.operators.AbstractUdfStreamOperator.initializeState(AbstractUdfStreamOperator.java:96)
    at org.apache.flink.streaming.api.operators.StreamOperatorStateHandler.initializeOperatorState(StreamOperatorStateHandler.java:106)
    at org.apache.flink.streaming.api.operators.AbstractStreamOperator.initializeState(AbstractStreamOperator.java:258)
    at org.apache.flink.streaming.runtime.tasks.OperatorChain.initializeStateAndOpenOperators(OperatorChain.java:290)
    at org.apache.flink.streaming.runtime.tasks.StreamTask.lambda$beforeInvoke$0(StreamTask.java:479)
    at org.apache.flink.streaming.runtime.tasks.StreamTaskActionExecutor$1.runThrowing(StreamTaskActionExecutor.java:47)
    at org.apache.flink.streaming.runtime.tasks.StreamTask.beforeInvoke(StreamTask.java:475)
    at org.apache.flink.streaming.runtime.tasks.StreamTask.invoke(StreamTask.java:528)
    at org.apache.flink.runtime.taskmanager.Task.doRun(Task.java:721)
    at org.apache.flink.runtime.taskmanager.Task.run(Task.java:546)
    at java.lang.Thread.run(Thread.java:748)

I have placed the s3-fs-hadoop jar file in the plugins/s3-fs-hadoop folder. I also have the same s3-fs-hadoop jar in /usr/lib/flink/lib just in case flink looks for the s3-fs-hadoop jar in that folder also. Please can someone help me. I have searched and searched but cant seem to resolve it.

Thanks

1 Answers

I figured it out. I needed to restart the entire flink long running application (not restart job). Also had to remove the s3-fs-hadoop jar I placed in /usr/lib/flink/lib directory but kept a copy of the s3-fs-hadoop jar in the plugins/s3-fs-hadoop folder.

Related