Flink Job上传的jar包保存在哪里
通过 flink UI dashboard提交的 jar 存储在哪个目录下? 一直都有疑惑,之前没做深入的了解,这个问题不解决感觉心里总在惦记着。今天就跟我一起来探寻一下其中的套路吧。
Google大法好
找到了一条关于 Flink Upload Issue, 内容如下:

这不正是想要的么,赶紧看下这哥们儿submit的代码:

打开Flink1.8源码,搜索“jobmanager.web.upload.dir”

点击搜索结果,进入到具体实现类中,

代码中提示 jobmanager.web.upload.dir
配置已经过期了,被 WebOptions
类中的 UPLOAD_DIR
配置所替代。 继续跟进 WebOptions
类:

注意看注释,大体意思:该配置参数定义了上传 Job jar 包的目录。如果没有配置,则使用JOB_MANAGER_WEB_TMPDIR_KEY
指定的目录。
继续从源码中搜索JOB_MANAGER_WEB_TMPDIR_KEY

进去源码中看看

我晕,又过期啦,emmmmm.... 。继续跟进 WebOptions
类

从代码中可以看到,如果配置了web.tmpdir
则会替代掉默认配置java.io.tmpdir
。
服务器配置信息


web.tmpdir 的是由 java.io.tmpdir + “flink-web-” + UUID 组成的!
默认情况下,Job重启后就会删除掉之前上传的jar包。生产环境玩肯定是不行的,所以我们还是要指定一个目录来存储所有的上传 jar 包,并且不能够被删除,要配置固定的目录(Flink 重启也不删除的话)需要配置如下:
web.upload.dir: /usr/local/flink-1.8/jars
这样的话,就可以保证你的 jar 不再会被删除了!
//从配置文件中找 UPLOAD_DIR
final Path uploadDir = Paths.get(
config.getString(WebOptions.UPLOAD_DIR, config.getString(WebOptions.TMP_DIR)),
"flink-web-upload");
return new RestServerEndpointConfiguration(
restAddress,restBindAddress,port,sslEngineFactory,
uploadDir,maxContentLength,responseHeaders);
他就是从配置文件中找 UPLOAD_DIR
,如果为 null
就找 TMP_DIR
目录来当作 jar 上传的路径。
总结
知其然,知其所以然。
参考资料:
https://issues.apache.org/jira/browse/FLINK-4308
https://github.com/apache/flink/pull/2335