Amazon EMR在为Apache-Flink提交作业时遇到可恢复的Hadoop错误

时间:2019-04-04 13:47:19

标签: amazon-s3 apache-flink hadoop2

Added Depedency Pom Details :

<dependencies>
        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-clients_2.11</artifactId>
            <version>1.7.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-streaming-java_2.11</artifactId>
            <version>1.7.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-core</artifactId>
            <version>1.7.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-java</artifactId>
            <version>1.7.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-runtime_2.11</artifactId>
            <version>1.7.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-table_2.11</artifactId>
            <version>1.7.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-connector-kafka-0.10_2.11</artifactId>
            <version>1.7.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-connector-filesystem_2.11</artifactId>
            <version>1.7.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-hadoop-compatibility_2.11</artifactId>
            <version>1.7.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-s3-fs-hadoop</artifactId>
            <version>1.7.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-shaded-hadoop</artifactId>
            <version>1.7.1</version>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-aws</artifactId>
            <version>2.8.5</version>
        </dependency>
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-hdfs</artifactId>
            <version>2.8.5</version>
        </dependency>
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-common</artifactId>
            <version>2.8.5</version>
        </dependency>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-s3</artifactId>
            <version>1.11.529</version>
        </dependency>
        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-streaming-connectors</artifactId>
            <version>1.1.5</version>
            <type>pom</type>
        </dependency>
    </dependencies>
  

java.lang.UnsupportedOperationException:Hadoop上的可恢复编写器   仅支持HDFS和Hadoop版本2.7或更高版本,网址为   org.apache.flink.runtime.fs.hdfs.HadoopRecoverableWriter。(HadoopRecoverableWriter.java:57)     在   org.apache.flink.runtime.fs.hdfs.HadoopFileSystem.createRecoverableWriter(HadoopFileSystem.java:202)     在   org.apache.flink.core.fs.SafetyNetWrapperFileSystem.createRecoverableWriter(SafetyNetWrapperFileSystem.java:69)     在   org.apache.flink.streaming.api.functions.sink.filesystem.Buckets。(Buckets.java:112)     在   org.apache.flink.streaming.api.functions.sink.filesystem.StreamingFileSink $ RowFormatBuilder.createBuckets(StreamingFileSink.java:242)     在   org.apache.flink.streaming.api.functions.sink.filesystem.StreamingFileSink.initializeState(StreamingFileSink.java:327)     在   org.apache.flink.streaming.util.functions.StreamingFunctionUtils.tryRestoreFunction(StreamingFunctionUtils.java:178)     在   org.apache.flink.streaming.util.functions.StreamingFunctionUtils.restoreFunctionState(StreamingFunctionUtils.java:160)     在   org.apache.flink.streaming.api.operators.AbstractUdfStreamOperator.initializeState(AbstractUdfStreamOperator.java:96)     在   org.apache.flink.streaming.api.operators.AbstractStreamOperator.initializeState(AbstractStreamOperator.java:278)     在   org.apache.flink.streaming.runtime.tasks.StreamTask.initializeState(StreamTask.java:738)     在   org.apache.flink.streaming.runtime.tasks.StreamTask.invoke(StreamTask.java:289)     在org.apache.flink.runtime.taskmanager.Task.run(Task.java:704)处   java.lang.Thread.run(Thread.java:748)

2 个答案:

答案 0 :(得分:1)

Flink使用称为ServiceLoader的东西来加载interface with pluggable File Systems所需的组件。如果您希望查看Flink在代码中的位置,请转到org.apache.flink.core.fs.FileSystem。注意initialize函数,该函数使用了RAW_FACTORIES变量。 RAW_FACTORIES由函数loadFileSystems创建,您可以看到它利用Java的ServiceLoader

在从Flink启动应用程序之前,需要先设置文件系统组件。这意味着您的Flink应用程序不需要捆绑这些组件,应为您的应用程序提供它们。

EMR不提供Flink需要使用S3作为流文件接收器的S3文件系统组件。引发此异常不是因为版本不够高,而是因为Flink在缺少与s3方案(see code here)匹配的文件系统的情况下加载了HadoopFileSystem。

通过为我的Flink应用程序启用DEBUG日志记录级别,您可以查看文件系统是否正在加载,EMR允许您在配置中执行以下操作:

{
    "Classification": "flink-log4j",
    "Properties": {
      "log4j.rootLogger": "DEBUG,file"
    }
  },{
    "Classification": "flink-log4j-yarn-session",
    "Properties": {
      "log4j.rootLogger": "DEBUG,stdout"
    }
  }

在YARN资源管理器中可以找到相关日志,查看单个节点的日志。搜索字符串"Added file system"应该可以帮助您找到所有成功加载的文件系统。

在此调查中也很方便的方法是SSH到主节点并使用flink-scala REPL,在这里我可以看到FileSystem Flink决定在给定文件URI的情况下加载什么。

解决方案是在启动Flink应用程序之前,将S3文件系统实现的JAR放到/usr/lib/flink/lib/中。可以通过引导动作来抓取flink-s3-fs-hadoopflink-s3-fs-presto(取决于您所使用的实现)来完成此操作。我的引导操作脚本如下所示:

sudo mkdir -p /usr/lib/flink/lib
cd /usr/lib/flink/lib

sudo curl -O https://search.maven.org/remotecontent?filepath=org/apache/flink/flink-s3-fs-hadoop/1.8.1/flink-s3-fs-hadoop-1.8.1.jar

答案 1 :(得分:0)

为了仅一次保证使用Flink的StreamingFileSink,您需要使用Hadoop> = 2.7。不支持低于2.7的版本。因此,请确保在EMR上运行最新的Hadoop版本。