[英]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.