简体   繁体   English

在本地模式和纱线群集上运行Flink的结果不同

[英]Different result on running Flink in local mode and Yarn cluster

I run a code using Flink Java API that gets some bytes from Kafka and parses it following by inserting into Cassandra database using another library static method (both parsing and inserting results is done by the library). 我使用Flink Java API运行代码,该代码从Kafka获取一些字节,然后使用另一种库静态方法将其插入Cassandra数据库中进行解析(解析和插入结果均由该库完成)。 Running code on local in IDE, I get the desired answer, but running on YARN cluster the parse method didn't work as expected! 我在IDE的本地运行代码,得到了所需的答案,但是在YARN群集上运行时,解析方法未按预期工作!

public class Test {
    static HashMap<Integer, Object> ConfigHashMap = new HashMap<>();

    public static void main(String[] args) throws Exception {

        CassandraConnection.connect();
        Parser.setInsert(true);

        stream.flatMap(new FlatMapFunction<byte[], Void>() {
            @Override
            public void flatMap(byte[] value, Collector<Void> out) throws Exception {
                Parser.parse(ByteBuffer.wrap(value), ConfigHashMap);
                // Parser.parse(ByteBuffer.wrap(value));
            }
        });
        env.execute();
    }
}

There is a static HashMap field in the Parser class that configuration of parsing data is based on its information, and data will insert it during the execution. Parser类中有一个静态HashMap字段,解析数据的配置基于其信息,并且数据将在执行期间插入。 The problem running on YARN was this data was not available for taskmanagers and they just print config is not available! 在YARN上运行的问题是该数据不适用于taskmanagers而他们只是print config is not available!

So I redefine that HashMap as a parameter for parse method, but no differences in results! 因此,我将HashMap重新定义为parse方法的参数,但结果没有差异!

How can I fix the problem? 我该如何解决该问题?

I changed static methods and fields to non-static and using RichFlatMapFunction solved the problem. 我将静态方法和字段更改为非静态,并使用RichFlatMapFunction解决了该问题。

stream.flatMap(new RichFlatMapFunction<byte[], Void>() {
            CassandraConnection con = new CassandraConnection();
            int i = 0 ;

            @Override
            public void open(Configuration parameters) throws Exception {
                super.open(parameters);
                con.connect();
            }

            @Override
            public void flatMap(byte[] value, Collector<Void> out) throws Exception {

                ByteBuffer tb = ByteBuffer.wrap(value);
                np.parse(tb, ConfigHashMap, con);
            }
        });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过flink yarn集群上的maven运行带有随附配置的Java Jar - Running Java Jar with included config via maven on flink yarn cluster 在flink YARN集群作业中使用JNI - Using JNI in flink YARN cluster jobs Flink:以集群模式加载资源文件 - Flink : Load resource file in cluster mode 在群集上运行时Flink Avro 1.8.1 NoSuchMethodError - Flink Avro 1.8.1 NoSuchMethodError when running on cluster 在IDEA中的本地计算机上运行mapreduce时,在集群上的hadoop中输出不同的输出 - Different output while running mapreduce on local machine in IDEA and in hadoop on cluster 在集群模式下将Spark从eclipse部署到YARN时出错 - Error when deploying Spark from eclipse to YARN in cluster mode 在纱线群集模式下的Apache Spark正在抛出Hadoop FileAlreadyExistsException - Apache Spark in yarn-cluster mode is throwing Hadoop FileAlreadyExistsException Apache SPARK:广播变量的-Nullpointer异常(YARN群集模式) - Apache SPARK:-Nullpointer Exception on broadcast variables (YARN Cluster mode) Spark 在 Yarn Cluster 模式下提交,并将配置文件放入 HDFS 问题 - Spark submit on Yarn Cluster mode with config file put into HDFS issue 远程 flink 作业查询 Hive 上的纱线集群错误:NoClassDefFoundError: org/apache/hadoop/mapred/JobConf - remote flink job with query to Hive on yarn-cluster error:NoClassDefFoundError: org/apache/hadoop/mapred/JobConf
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM