【详述】为了在JAVA UDF中从mysql加载一些动态数据配置数据,希望在自定函数中引入JDBC驱动mysql-connector-j-8.0.31.jar,同时打入了函数依赖包中。在实际使用过程中,函数调用日志中,有以下现象:
- 有些线程能正常加载驱动,有些则不行
- 同一个线程,有时候可以加载到驱动,有时候不行
驱动加载代码:
加载驱动成功与为空打印的日志情况:
分析过 java.sql.DriverManager.getDrivers()
源码,怀疑是starrocks动态jar加载与jvm安全机制相关
java udf 集成 jdbc 加载配置数据是否可行?
下面附上驱动加载失败时的报错堆栈:
2024-09-03 16:19:52.823 [Cog] [Thread-39-61] WARN xxx.yyy.starrocks.common.dao.DaoStarrocks.printDrivers(DaoStarrocks.java:56) - driver : is empty
2024-09-03 16:19:52.823 [Cog] [Thread-39-61] WARN xxx.yyy.starrocks.common.dao.DaoStarrocks.printDrivers(DaoStarrocks.java:56) - driver : is empty
2024-09-03 16:19:52.824 [Cog] [Thread-39-61] ERROR xxx.yyy.starrocks.func.model.ICache.getICache(ICache.java:153) - load cache from db failed: STARROCKS:SZ_longhua_001:URL_SOURCE
java.sql.SQLException: No suitable driver found for jdbc:mysql://xx.xx.xx.xx:xx/xx?useUnicode=truequeryTimeout=0characterEncoding=utf-8allowMultiQueries=truezeroDateTimeBehavior=convertToNulluseTi
mezone=trueserverTimezone=GMT%2B8useSSL=falseuseAffectedRows=true
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at xxx.yyy.starrocks.common.dao.DaoStarrocks.<init>(DaoStarrocks.java:83)
at xxx.yyy.starrocks.func.model.ICache.getICache(ICache.java:148)
at xxx.yyy.starrocks.func.model.UrlReportDataCache.search(UrlReportDataCache.java:86)
at xxx.yyy.starrocks.func.udf.db.UdfGetUrlReportSource.evaluate(UdfGetUrlReportSource.java:17)
at com.starrocks.udf.gen.CallStub.batchCallV(Unknown Source)
starrocks.driverClassName:com.mysql.cj.jdbc.Driver