如何解决Atomikos 事务超时和 spring 重试
我们使用 atomikos 进行分布式事务管理。 对于非常大的文件处理,我可以在进程启动 300 秒后在日志中看到以下条目。
"message" : "Transaction xxxxxxxx.tm123 has timed out and will rollback.","logger_name" : "com.atomikos.icatch.imp.ActiveStateHandler","thread_name" : "Atomikos:1234",
我们已将超时设置为 300 秒。 com.atomikos.icatch.default_jta_timeout=300000
但是对于需要将每一行保存到数据库的非常大的文件(一年一次),它甚至在 300 秒后继续保存到表中。进程结束大约 30 分钟后,我们可以在短短几毫秒内看到数千次日志文件中的以下警告。
"message" : "Forcing close of pending statement: oracle.jdbc.driver.OraclePreparedStatementWrapper","logger_name" : "com.atomikos.jdbc.AbstractConnectionProxy",
具有使用 org.springframework.retry.annotation.Retryable
重试机制的 Rest 服务再次运行,但由于 Hibernate 缓存,这次运行速度要快得多。但是重试有副作用,比如部分进程会像发送文件一样运行两次,从而导致一些问题。我已经实现了一个基本的解决方案,例如维护文件是否正在发送的标志,或者在事务管理级别寻找更好的解决方案。
有没有人在使用 atomikos 时遇到过类似的问题?你是怎么处理的
以下是休息服务代码。我们没有看到它进入异常块,因为日志中没有看到错误。 尚未尝试将@Transactional 移至 mainProcess() 方法。
@RequestMapping("someProcess/")
@Transactional
@Retryable(
include = {Exception.class,JpaSystemException.class,IOException.class},maxAttemptsExpression = "#{${retry.maxAttempts}}",backoff = @Backoff(
delayExpression = "#{${retry.retryDelay}}",maxDelayExpression = "#{${retry.maxDelay}}",multiplierExpression = "#{${retry.multiplier}}"
)
)
public void someProcess() throws Exception {
try {
mainProcess();
} catch (Exception e) {
logError(e);
throw e;
}
我们使用 atomikos 4.0.6 和 spring boot 2.1.4。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。