Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TTL Agent的使用方式下,PriorityBlockingQueue(非PriorityBlockingQueue<Runnable>)抛出ClassCastException #361

Closed
fzdwx opened this issue Mar 8, 2022 · 10 comments
Assignees
Labels
🐞 bug Something isn't working ttl agent

Comments

@fzdwx
Copy link

fzdwx commented Mar 8, 2022

就是powerjob worker(应用)启动的时候会初始化一个h2数据库

image
image
image

具体报错

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'initPowerJob' defined in class path resource [tech/powerjob/worker/autoconfigure/PowerJobAutoConfiguration.class]: Invocation of init method failed; nested exception is org.h2.jdbc.JdbcSQLNonTransientConnectionException: The database has been closed [90098-200]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:765)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:445)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:338)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1354)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343)
	at com.huofutp.HfScrmSysApplication.main(HfScrmSysApplication.java:25)
Caused by: org.h2.jdbc.JdbcSQLNonTransientConnectionException: The database has been closed [90098-200]
	at org.h2.message.DbException.getJdbcSQLException(DbException.java:622)
	at org.h2.message.DbException.getJdbcSQLException(DbException.java:429)
	at org.h2.message.DbException.get(DbException.java:194)
	at org.h2.engine.Session.getTransaction(Session.java:1792)
	at org.h2.engine.Session.getStatementSavepoint(Session.java:1804)
	at org.h2.engine.Session.setSavepoint(Session.java:915)
	at org.h2.command.Command.executeUpdate(Command.java:244)
	at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:228)
	at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:201)
	at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:94)
	at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java)
	at tech.powerjob.worker.persistence.TaskDAOImpl.initTable(TaskDAOImpl.java:34)
	at tech.powerjob.worker.persistence.TaskPersistenceService.init(TaskPersistenceService.java:48)
	at tech.powerjob.worker.PowerJobWorker.init(PowerJobWorker.java:140)
	at tech.powerjob.worker.PowerJobWorker.afterPropertiesSet(PowerJobWorker.java:67)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800)
	... 16 common frames omitted
Caused by: java.lang.IllegalStateException: java.lang.ClassCastException: org.h2.mvstore.MVStore$RemovedPageInfo cannot be cast to java.lang.Runnable [1.4.200/3]
	at org.h2.mvstore.DataUtils.newIllegalStateException(DataUtils.java:950)
	at org.h2.mvstore.MVStore.store(MVStore.java:1338)
	at org.h2.mvstore.MVStore.store(MVStore.java:1312)
	at org.h2.mvstore.MVStore.tryCommit(MVStore.java:1272)
	at org.h2.mvstore.MVStore.writeInBackground(MVStore.java:2780)
	at org.h2.mvstore.MVStore$BackgroundWriterThread.run(MVStore.java:3290)
Caused by: java.lang.ClassCastException: org.h2.mvstore.MVStore$RemovedPageInfo cannot be cast to java.lang.Runnable
	at com.alibaba.ttl.threadpool.TtlRunnableUnwrapComparator.compare(TtlRunnableUnwrapComparator.java:15)
	at java.util.concurrent.PriorityBlockingQueue.siftUpUsingComparator(PriorityBlockingQueue.java:374)
	at java.util.concurrent.PriorityBlockingQueue.offer(PriorityBlockingQueue.java:491)
	at java.util.concurrent.PriorityBlockingQueue.add(PriorityBlockingQueue.java:463)
	at org.h2.mvstore.MVStore.accountForRemovedPage(MVStore.java:2237)
	at org.h2.mvstore.Page.removePage(Page.java:861)
	at org.h2.mvstore.CursorPos.processRemovalInfo(CursorPos.java:72)
	at org.h2.mvstore.MVMap.operate(MVMap.java:1909)
	at org.h2.mvstore.MVMap.put(MVMap.java:151)
	at org.h2.mvstore.MVStore.storeNow(MVStore.java:1366)
	at org.h2.mvstore.MVStore.store(MVStore.java:1334)
	... 4 common frames omitted

请问有没有办法排除这个?或者您有没有更好的解决办法。。。

@fzdwx
Copy link
Author

fzdwx commented Mar 8, 2022

2.就为什么我再主线程中remove了,但是其他的线程还是能获取到值?并且这个线程还是一个早就启动了的线程,比如说rocketmq中的RocketmqRemoting
8CFF200C-24FC-4d0f-BF62-868C4FD98660(1)

@fzdwx
Copy link
Author

fzdwx commented Mar 8, 2022

用了agent包装还是这样...

@fzdwx
Copy link
Author

fzdwx commented Mar 8, 2022

就是存入一次context后,其他任意线程都能获取到,然后remove之后,set的线程获取不到,其他线程还是能获取到
image

image

image

@fzdwx
Copy link
Author

fzdwx commented Mar 8, 2022

我是不是哪里用的姿势不对 😭

@oldratlee
Copy link
Member

oldratlee commented Mar 8, 2022

就是powerjob worker(应用)启动的时候会初始化一个h2数据库
……
具体报错
……

@fzdwx 问题收到。

PriorityBlockingQueue相关的问题;PriorityBlockingQueue的支持 在版本v2.12.3中实现的:
https://github.com/alibaba/transmittable-thread-local/releases/tag/v2.12.3


因为不能方便的修改org.h2.mvstore.MVStore中使用PriorityBlockingQueue的代码,
推荐使用2.3 使用Java Agent来修饰JDK线程池实现类的方式 来解决;


请给一下 可以复现问题的、极简可运行的Demo工程 ❤️;推荐:

有一个可以说明/复现问题的、极简可运行的Demo工程,也可以排除可能的使用上的问题。

相关 Issue

@oldratlee oldratlee added the 😖 no runnable reproducible demo 😵 please provide a simple runnable demo that reproduce the problem label Mar 8, 2022
@oldratlee
Copy link
Member

oldratlee commented Mar 8, 2022

@fzdwx 问题已经确定了,正在修复中。

尽快发一个版本出来之后,你可以用新版本解决这个问题。

复现Test Case及其结果

@Test
fun test_fixed_ClassCastException_of_issue_361() {
val queue = PriorityBlockingQueue<Int>()
queue.put(1)
queue.put(100)
queue.put(2)
assertEquals(1, queue.poll())
assertEquals(2, queue.poll())
assertEquals(100, queue.poll())
}
}

CI结果:
https://ci.appveyor.com/project/oldratlee/transmittable-thread-local/builds/42829044/job/risbd5a8oclhui1s#L556

java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.lang.Runnable (java.lang.Integer and java.lang.Runnable are in module java.base of loader 'bootstrap')
	at com.alibaba.ttl.threadpool.TtlRunnableUnwrapComparator.compare(TtlRunnableUnwrapComparator.java:15)
	at java.base/java.util.concurrent.PriorityBlockingQueue.siftUpUsingComparator(PriorityBlockingQueue.java:377)
	at java.base/java.util.concurrent.PriorityBlockingQueue.offer(PriorityBlockingQueue.java:488)
	at java.base/java.util.concurrent.PriorityBlockingQueue.put(PriorityBlockingQueue.java:508)
	at com.alibaba.ttl.threadpool.TtlExecutorsTest.test_fixed_ClassCastException_of_issue_361(TtlExecutorsTest.kt:288)

Fix后 CI 通过

https://ci.appveyor.com/project/oldratlee/transmittable-thread-local/builds/42829181

@oldratlee
Copy link
Member

oldratlee commented Mar 8, 2022

发布了 v2.12.5 @fzdwx
https://github.com/alibaba/transmittable-thread-local/releases/tag/v2.12.5

试一下 看看你的问题解决了吗 ❤️

@oldratlee oldratlee self-assigned this Mar 8, 2022
@oldratlee oldratlee added 🐞 bug Something isn't working and removed 😖 no runnable reproducible demo 😵 please provide a simple runnable demo that reproduce the problem labels Mar 8, 2022
@oldratlee oldratlee changed the title agent方式与powerjob冲突? TTL Agent的使用方式下,非PriorityBlockingQueue<Runnable>抛ClassCastException Mar 8, 2022
@oldratlee
Copy link
Member

oldratlee commented Mar 8, 2022

2.就为什么我再主线程中remove了,但是其他的线程还是能获取到值?并且这个线程还是一个早就启动了的线程,比如说rocketmq中的RocketmqRemoting
就是存入一次context后,其他任意线程都能获取到,然后remove之后,set的线程获取不到,其他线程还是能获取到

对于第二问题,和 使用方式与逻辑流程相关,可能涉及很多组件。
不能简单看看给你反馈是什么问题。

你提取成了一个可以复现问题的、极简可运行的Demo工程后,
可以开一下新的独立Issue,再跟进。 @fzdwx

@oldratlee oldratlee changed the title TTL Agent的使用方式下,非PriorityBlockingQueue<Runnable>抛ClassCastException TTL Agent的使用方式下,PriorityBlockingQueue(非PriorityBlockingQueue<Runnable>)抛出ClassCastException Mar 8, 2022
@fzdwx
Copy link
Author

fzdwx commented Mar 9, 2022

ok,收到,我测试一下第一个问题,稍后给您答复。


用最新的2.12.5版本 agent 没问题了。


关于第二个问题,我发现我新搭一个项目确实没出现这个问题,我再仔细研究研究,看是不是有什么其他组件干扰了。

@fzdwx fzdwx closed this as completed Mar 9, 2022
@fzdwx
Copy link
Author

fzdwx commented Mar 9, 2022

复现了。。我马上提一个新的issue @oldratlee

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working ttl agent
Projects
None yet
Development

No branches or pull requests

2 participants