flink實戰--開發中常見的錯誤與問題

常見錯誤集

1.Checkpoint失敗:Checkpoint expired before completing

        env.enableCheckpointing(1000L)
        val checkpointConf = env.getCheckpointConfig
        checkpointConf.setMinPauseBetweenCheckpoints(30000L)
        checkpointConf.setCheckpointTimeout(8000L)

原因是因爲checkpointConf.setCheckpointTimeout(8000L)設置的太小了,默認是10min,這裏只設置了8sec。當一個Flink App背壓的時候(例如由外部組件異常引起),Barrier會流動的非常緩慢,導致Checkpoint時長飆升。

2.在Flink中,資源的隔離是通過Slot進行的,也就是說多個Slot會運行在同一個JVM中,這種隔離很弱,尤其對於生產環境。Flink App上線之前要在一個單獨的Flink集羣上進行測試,否則一個不穩定、存在問題的Flink App上線,很可能影響整個Flink集羣上的App。

3 .Flink App拋出The assigned slot container_e08_1539148828017_15937_01_003564_0 was removed.此類異常,通過查看日誌,一般就是某一個Flink App內存佔用大,導致TaskManager(在Yarn上就是Container)被Kill掉。但是並不是所有的情況都是這個原因,還需要進一步看yarn的日誌( 查看yarn任務日誌:yarn logs -applicationId   -appOwner),如果代碼寫的沒問題,就確實是資源不夠了,其實1G Slot跑多個Task(Slot Group Share)其實挺容易出現的。因此有兩種選擇。可以根據具體情況,權衡選擇一個。

  • 將該Flink App調度在Per Slot內存更大的集羣上。
  • 通過slotSharingGroup("xxx"),減少Slot中共享Task的個數
org.apache.flink.util.FlinkException: The assigned slot container_e08_1539148828017_15937_01_003564_0 was removed.
    at org.apache.flink.runtime.resourcemanager.slotmanager.SlotManager.removeSlot(SlotManager.java:786)
    at org.apache.flink.runtime.resourcemanager.slotmanager.SlotManager.removeSlots(SlotManager.java:756)
    at 。。。。。。。。。。。。
此處省略n行
akka.actor.UntypedActor$$anonfun$receive$1.applyOrElse(UntypedActor.scala:165)
    at akka.actor.Actor$class.aroundReceive(Actor.scala:502)
    at akka.actor.UntypedActor.aroundReceive(UntypedActor.scala:95)
    at akka.actor.ActorCell.receiveMessage(ActorCell.scala:526)
    at akka.actor.ActorCell.invoke(ActorCell.scala:495)
    at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:257)
    at akka.dispatch.Mailbox.run(Mailbox.scala:224)
    at akka.dispatch.Mailbox.exec(Mailbox.scala:234)
    at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
    at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
    at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
    at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

4.拋出Caused by: java.io.IOException: Too many open files異常,一般是因爲存在Flink App在結束的時候沒有釋放資源,這裏指的是例如忘記關閉連接池,線程池等資源。如果一個Flink App結束的時候沒有釋放資源,又因爲異常被重啓多次後,很容易出現Too many open files異常,從而拖垮整個TaskManager上的Flink App。

  • 重寫RichFunction的Close()方法,加上例如:suishenRedisTemplate.quit()hbaseClient.shutdown().join(TimeUnit.SECONDS.toMillis(30))等。由於現在Scala Api不支持RichAsyncFunction,沒有Close方法,無法釋放資源,這是一件很蛋疼的事情。。。
    at org.apache.flink.streaming.runtime.tasks.StreamTask.invoke(StreamTask.java:296)
    at org.apache.flink.runtime.taskmanager.Task.run(Task.java:712)
    at java.lang.Thread.run(Thread.java:748)
Caused by: io.netty.channel.ChannelException: failed to open a new selector
    at io.netty.channel.nio.NioEventLoop.openSelector(NioEventLoop.java:156)
    at io.netty.channel.nio.NioEventLoop.<init>(NioEventLoop.java:147)
    at io.netty.channel.nio.NioEventLoopGroup.newChild(NioEventLoopGroup.java:126)
    at io.netty.channel.nio.NioEventLoopGroup.newChild(NioEventLoopGroup.java:36)
    at io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:84)
    ... 21 more
Caused by: java.io.IOException: Too many open files
    at sun.nio.ch.IOUtil.makePipe(Native Method)
    at sun.nio.ch.EPollSelectorImpl.<init>(EPollSelectorImpl.java:65)
    at sun.nio.ch.EPollSelectorProvider.openSelector(EPollSelectorProvider.java:36)
    at io.netty.channel.nio.NioEventLoop.openSelector(NioEventLoop.java:154)
    ... 25 more

5.啓動報錯,提示找不到 jersey 的類java.lang.NoClassDefFoundError: com/sun/jersey/core/util/FeaturesAndProperties解決辦法進入yarn中 把lib目中的一下兩個問價拷貝到flink的lib中

hadoop/share/hadoop/yarn/lib/jersey-client-1.9.jar
/hadoop/share/hadoop/yarn/lib/jersey-core-1.9.jar

6.Scala版本衝突--java.lang.NoSuchMethodError:scala.collection.immutable.HashSet$.empty()Lscala/collection/

解決辦法:添加import org.apache.flink.api.scala._

7.SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]Could not build the program from JAR file.
或者Could not identify hostname and port in 'yarn-cluster' 

解決:flink1.8需要在lib中添加一下jar包

8.Creating the input splits caused an error: tried to access method com.google.common.base.Stopwatch.<init>()V from class org.apache.hadoop.mapreduce.lib.input.FileInputFormat或者 tried to access method com.google.common.base.Stopwatch.<init>()V from class org.apache.hadoop.mapreduce.lib.input.FileInputFormat

解決方式:導入以下依賴即可   

        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-common</artifactId>
            <version>2.7.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-mapreduce-client-core</artifactId>
            <version>2.7.1</version>
        </dependency>

9.Table is not an append一only table. Use the toRetractStream() in order to handle add and retract messages.這個是因爲動態表不是append一only模式的,需要用toRetractStream(回撤流)處理就好了.
tableEnv. toRet ractSt ream [Person](result) .print()

10.啓動Flink任務的時候報錯Caused by: java.lang.RuntimeException: Couldn't deploy Yarn cluster,然後仔細看發現裏面有這麼一句system times on machines may be out of sync,意思說是機器上的系統時間可能不同步.
已置
(1)安裝ntpdate工具

yum 一y install ntp ntpdate

(2)設置系統時間與網絡時間同步

ntpdate cn.pool.ntp.org

在三臺機器上分別執行完這個,在啓動任務,發現可以了. 

9.oom問題

java.lang.OutOfMemoryError: GC overhead limit exceeded

java.lang.OutOfMemoryError: GC overhead limit exceeded
        at java.util.Arrays.copyOfRange(Arrays.java:3664)
        at java.lang.String.<init>(String.java:207)
        at com.esotericsoftware.kryo.io.Input.readString(Input.java:466)
        at com.esotericsoftware.kryo.serializers.DefaultSerializers$StringSerializer.read(DefaultSerializers.java:177)
        。。。。。。。。
        at org.apache.flink.streaming.runtime.tasks.OperatorChain$CopyingChainingOutput.collect(OperatorChain.java:524)

解決方案如下:

1.檢查slot槽位夠不夠或者slot分配的數量有沒有生效
2.程序起的並行是否都正常分配了(會有這樣的情況出現,假如5個並行,但是隻有2個在幾點上生效了,另外3個沒有數據流動)
3.檢查flink程序有沒有數據傾斜,可以通過flink的ui界面查看每個分區子節點處理的數據量

10.The proctime attribute can only be appended to the table schema and not replace anexisting field. Please move 'proctime' to the end of the schema
這個報錯的翻譯爲, proctime屬性只能附加到表模式,而不能替換現有字段。請將proctime'移到架構的末尾,我們在用proctime的時候要把他放到字段的最後一個位置.而不能放到其他的位置.

11.flink. table. TableJob$person$3(name: String, id: Integer, timestamp: Long)' must bestatic and globally accessible
這個報錯是因爲我們定義的case class類型必須是靜態的,全局可訪問的,就是說要把它放到main方法的外面就可以了

12.Could not retrieve the redirect address of the current leader. Please try to refresh,Flink任務在運行了一段時間後,進程還在但是刷新UI界面提示報錯你把這個job殺掉重新啓動,還是會報這個錯.
解決方法是把這個目錄下的文件刪除,重啓就可以了
high一availability.zookeeper.path.root: /flink
ZooKeeper節點根目錄,其下放置所有集羣節點的namespace.

13.hadoop的jar包衝突,導致寫入hdfs報錯

Caused by: java.io.IOException: The given file system URI (hdfs:///data/checkpoint-data/abtest) did not describe the authority (like for example HDFS NameNode address/port or S3 host). The attempt to use a configured default authority failed: Hadoop configuration did not contain an entry for the default file system ('fs.defaultFS').
        at org.apache.flink.runtime.fs.hdfs.HadoopFsFactory.create(HadoopFsFactory.java:135)
        at org.apache.flink.core.fs.FileSystem.getUnguardedFileSystem(FileSystem.java:399)
        at org.apache.flink.core.fs.FileSystem.get(FileSystem.java:318)
        at org.apache.flink.core.fs.Path.getFileSystem(Path.java:298)

原因:pom文件中添加和hadoop先關的依賴 去掉就好了

14.解析返回值類型失敗報錯

 The return type of function 'main(RemoteEnvironmentTest.java:27)' could not be determined automatically

Exception in thread "main" org.apache.flink.api.common.functions.InvalidTypesException: The return type of function 'main(RemoteEnvironmentTest.java:27)' could not be determined automatically, due to type erasure. You can give type information hints by using the returns(...) method on the result of the transformation call, or by letting your function implement the 'ResultTypeQueryable' interface.
	at org.apache.flink.api.java.DataSet.getType(DataSet.java:178)
	at org.apache.flink.api.java.DataSet.collect(DataSet.java:410)
	at org.apache.flink.api.java.DataSet.print(DataSet.java:1652)

解決方案:產生這種現象的原因一般是使用lambda表達式沒有明確返回值類型,或者使用特使的數據結構flink無法解析其類型,這時候我們需要在方法的後面添加返回值類型,比如字符串

input.flatMap((Integer number, Collector<String> out) -> {
   。。。。。。
})
// 提供返回值類型
.returns(Types.STRING)

常見問題集

1.如何處理checkpoint設置RocksDBStateBackend方式,且當數據量大時,執行checkpoint會很慢的問題

原因分析

由於窗口使用自定義窗口,這時窗口的狀態使用ListState,且同一個key值下,value的值非常多,每次新的value值到來都要使用RocksDB的merge()操作;觸發計算時需要將該key值下所有的value值讀出。RocksDB的方式爲merge()->merge()....->merge()->read(),該方式讀取數據時非常耗時

  source算子在瞬間發送了大量數據,所有數據的key值均相等,導致window算子處理速度過慢,使barrier在緩存中積壓,快照的製作時間過長,導致window算子在規定時間內沒有向CheckpointCoordinator報告快照製作完成,CheckpointCoordinator認爲快照製作失敗         

回答

Flink引入了第三方軟件包RocksDB的缺陷問題導致該現象的發生。建議用戶將checkpoint設置爲FsStateBackend方式。

用戶需要在應用代碼中將checkpoint設置爲FsStateBackend。例如:

 env.setStateBackend(new FsStateBackend("hdfs://hacluster/flink-checkpoint/checkpoint/"));

2.如何處理blob.storage.directory配置/home目錄時,啓動yarn-session失敗的問題

當用戶設置“blob.storage.directory”爲“/home”時,用戶沒有權限在“/home”下創建“blobStore-UUID”的文件,導致yarn-session啓動失敗。

1.  建議將"blob.storage.directory"配置選項設置成“/tmp”或者“/opt/huawei/Bigdata/tmp”。

2.  當用戶將"blob.storage.directory"配置選項設置成自定義目錄時,需要手動賦予用戶該目錄的owner權限。以下以FusionInsight的admin用戶爲例。

               A. 修改Flink客戶端配置文件conf/flink-conf.yaml,配置blob.storage.directory:  /home/testdir/testdirdir/xxx。

               B. 創建目錄/home/testdir(創建一層目錄即可),設置該目錄爲admin用戶所屬。

說明:

                /home/testdir/下的testdirdir/xxx目錄在啓動Flink集羣時會在每個節點下自動創建。

               C. 進入客戶端路徑,執行命令

               ./bin/yarn-session.sh -n 3 -jm 2048 -tm 3072,可以看到yarn-session正常啓動並且成功創建目錄。            

3.爲什麼Flink Web頁面無法直接連接

問題:無法通過“http://JobManager IP:JobManager的端口”訪問Web頁面。

回答

由於瀏覽器所在的計算機IP地址未加到Web訪問白名單導致。用戶可以通過以下步驟來解決問題。

1.          查看客戶端的配置文件“conf/flink-conf.yaml”。

2.          確認配置項“jobmanager.web.ssl.enabled”的值是“false”。如果不是,請修改配置項的值爲“false”。如果是,請執行3

3.          確認配置項“jobmanager.web.access-control-allow-origin”和“jobmanager.web.allow-access-address”

               中是否已經添加瀏覽器所在的計算機IP地址。如果沒有添加,可以通過這兩項配置項進行添加。例如:

       jobmanager.web.access-control-allow-origin: 192.168.252.35,192.168.24.216 
        jobmanager.web.allow-access-address: 192.168.252.35,192.168.24.216

持續更細中。。。。。。。。

掃一掃加入大數據公衆號和技術交流羣,瞭解更多大數據技術,還有免費資料等你哦

掃一掃加入大數據公衆號和技術交流羣,瞭解更多大數據技術,還有免費資料等你哦

掃一掃加入大數據公衆號和技術交流羣,瞭解更多大數據技術,還有免費資料等你哦

 

 

 

發佈了92 篇原創文章 · 獲贊 115 · 訪問量 14萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章