简体   繁体   English

Spring Boot JPA PostgreSQL重试策略

[英]Spring Boot JPA PostgreSQL Retry Policy

I have a spring-boot application which has a POST REST API which intern inserts data to Postgresql using JPA and Hikari. 我有一个带有POST REST API的spring-boot应用程序,该应用程序使用JPA和Hikari将数据插入到Postgresql中。 Since the Post requests huge in numbers, I am planning to implement Spring Retry on JPA built-in methods like save(),saveAll(),findAll() etc., 由于Post请求的数量众多,因此我计划在JPA内置方法(如save(),saveAll(),findAll()等)上实现Spring Retry,

My question is that is it good idea to do retry when there is time-out/connection failure from database ? 我的问题是,数据库超时/连接失败时重试是个好主意吗? (or) spring-boot or JPA already does this? (或)spring-boot或JPA已经这样做了吗? if so please share the reference which mentions this. 如果是这样,请分享提及此的参考。

The responsibility of giving you a healthy connection is that of the connection pool which constantly monitors the available connections. 建立健康连接的责任是不断地监视可用连接的连接池。 Before handing over a connection to you HikariCP tests the connection using either a test query or API ( in case the jdbc driver is JDBC4 compliant). 在将连接移交给您之前,HikariCP使用测试查询或API(如果jdbc驱动程序兼容JDBC4的话)对连接进行测试。 More info here and here . 更多信息在这里这里

However once a connection is handed over and if there is a network issue while executing the query , the client would get an Execption. 但是,一旦连接被移交,并且在执行查询时出现网络问题,客户端将获得执行权。 Is retry then a good idea ? 重试是个好主意吗? I think for read queries this should be fine but for queries which changes data may not be good. 我认为对于读取查询来说应该没问题,但对于更改数据的查询可能就不好了。 For eg, your insert is successful but before the client gets the acknowledgement of transaction commit, a network issue occurs. 例如,您的插入成功,但是在客户端获得事务提交的确认之前,发生了网络问题。 So now the data is inserted. 因此,现在已插入数据。 If you try again you will end up inserting twice. 如果重试,将最终插入两次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM