问题1:bin/config.sh: line 32: syntax error near unexpected token
执行 sh start-cluster.sh脚本启动集群,报错:
/xxx/bin/config.sh:行32: syntax error near unexpected token `(`
/xxx/bin/config.sh:行32: ` done << (find "$FLINK_LIB_DIR" ! -type d -name '*.jar' -print0 | sort -z)'
解决
不要使用sh来启动,使用 bash start-cluster.sh 或 ./start-cluster.sh来启动。
这是因为start-cluster.sh文件中有sh不支持的语法。下面说明下bash和sh的区别:
bash是sh的增强版,sh全称是Bourne Shell,bash全称是Bourne Again Shell,linux系统默认使用的就是bash的posix模式。可以查看 echo $SHELL。值为/bin/bash。虽然sh是个软连接,指向了bash,但是还是有区别的,sh执行的相当于bash -posix xxx.sh,也就是说xxx.sh脚本必须遵守posix的规则,如果不然就会报错。
shell script一般第一行指定解释器,所以还是指定#!/bin/bash好,不要再用#!/bin/sh了。
sh是一个shell。运行sh a.sh,表示我使用sh来解释这个脚本;如果我直接运行./a.sh,首先你会查找脚本第一行是否指定了解释器,如果没指定,那么就用当前系统默认的shell(大多数linux默认是bash),如果指定了解释器,那么就将该脚本交给指定的解释器。
问题2:执行./stop-cluster.sh 关闭集群,报
No taskexecutor daemon to stop on host xxx
No standalonesession daemon to stop on host xxx
解决
在flink的安装目录下的 /bin 目录下有个 config.sh 脚本文件,里面有一项配置用来配置flink服务的pid文件目录,配置名称为: DEFAULT_ENV_PID_DIR ,默认值为 /tmp 。而由于/tmp 会被系统定期清理,所以存放的ID就找不到了,也就没法关闭集群了。所以这里最好修改为flink集群安装的位置下再加个目录 pids 即可。
问题3:Unexpected error in InitProducerIdResponse; The transaction timeout is larger than the maximum value allowed by the broker (as configured by transaction.max.timeout.ms).
解决
当FlinkKafkaProducer.Semantic指定为FlinkKafkaProducer.Semantic.AT_LEAST_ONCE时,执行没有问题。
当FlinkKafkaProducer.Semantic指定为FlinkKafkaProducer.Semantic.EXACTLY_ONCE时,执行报上面的错误。
官网关于Kafka Producers and Fault Tolerance有一段说明
Kafka brokers by default have transaction.max.timeout.ms set to 15 minutes.
This property will not allow to set transaction timeouts for the producers larger than it’s value.
FlinkKafkaProducer011 by default sets the transaction.timeout.ms property in producer config to 1 hour, thus transaction.max.timeout.ms should be increased before using the Semantic.EXACTLY_ONCE mode.
Kafka brokers 默认的最大事务超时(transaction.max.timeout.ms)为15 minutes,生产者设置事务超时不允许大于这个值。所以在使用EXACTLY_ONCE语义的时候需要改小transaction.max.timeout.ms的值,
kafkaPro.setProperty("transaction.timeout.ms",1000*60*10+"")
问题4:org.apache.flink.table.api.ValidationException: Could not find any factory for identifier 'jdbc' that implements 'org.apache.flink.table.factories.DynamicTableFactory' in the classpath.
解决:缺少flink-connector-jdbc_xxx.jar,下载放置到lib下
问题5:Flink InvalidTypesException: The return type of function could not be determined automatically...
解决:大致意思是,lambda写法无法提供足够的类型信息,无法推断出正确的类型,建议要么改成匿名类写法,要么用type information提供明细的类型信息。我们可以在转换的算子之后调用returns(...)方法来显示指明要返回的数据类型信息。
比如:map((MapFunction<String, Tuple2<String, Integer>>) filterRecord -> {
return new Tuple2(filterRecord, 1);
}).returns(Types.TUPLE(Types.STRING, Types.INT))
问题6:在idea环境中,执行env.execute()启动flink以后,发现程序似乎运行着,但一直卡着
解决:很可能是报错了,但是由于StreamExecutionEnvironment本身的重启策略是固定延迟但是不限重启次数的策略,所以错误才会一直无法报出来。可以先设置不重启策略来看下。env.setRestartStrategy(RestartStrategies.noRestart());
问题7:Flink SQL 创建 TableEnvironment 对象失败
现象:No factory implements 'org.apache.flink.table.delegation.ExecutorFactory'
解决:除了引入:
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-table-api-java-bridge_2.11</artifactId>
<version>${flink.version}</version>
<scope>provided</scope>
</dependency>
以外,还需要引入:
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-table-planner_2.11</artifactId>
<version>${flink.version}</version>
<scope>provided</scope>
</dependency>
问题8:Table sink doesn't support consuming update changes which is produced
将Table转化为DataStream的时候,调用了api:toDataStream或toAppendStream,这是因为sql里些了比如 count(xxx) group by 这种形成的不是append stream,所以无法转化,需要使用toChangelogStream或toRetractStream
问题9:Exception in thread “Thread-6” java.lang.IllegalStateException: Trying to access closed classloader. Please check if you store classloaders directly or indirectly in static fields
这是一个hadoop3和flink导致的一个bug,详见:
https://issues.apache.org/jira/browse/FLINK-19916
这并不影响当前功能,所以可以先不用关注。
问题10:IF(condition,true_value,false_value)时使用null,报错org.apache.calcite.sql.validate.SqlValidatorException: Illegal use of 'NULL'
比如:IF(5>3,'12321',NULL),这时会报错可以写成IF(5>3,'12321',cast(NULL as STRING))
问题11:Could not start rest endpoint on any port in port range 32446
原因:无法绑定端口,可以将rest.bind-port配置为一个范围,比如10000-20000
问题12:Connector 'print' can only be used as a sink. It cannot be used as a source.
原因:即print connector不能作为source端,比如:CREATE TABLE print_table (xxx) like kafkaTable; 就会报上面的错。因为kafka-connecter既可以作为source又可以作sink,而print-connector只能作sink端。另外就像mysql-cdc不能作为sink端一样。