limng06 opened a new issue, #32859:
URL: https://github.com/apache/shardingsphere/issues/32859

   
   ## 关于读写分离,从库的健康检查
   
   A question regarding read-write splitting and health checks for the slave 
database
   
   ### 描述
   
   场景是这样的,我的数据库采用了 
1主多从的设计,连接主库采用的是VIP虚地址,那么这里主库有了故障恢复能力,从库没有,所以我希望通过自定义的带健康检查功能的从库负载均衡算法来实现故障隔离和自动恢复。
   
   
实际我看了代码,我必须要获取到ContextManager的实例,我才能检查从库的连接是否可用,但是我发现我没有地方可以获取这个实例,唯一的方式是通过反射的方式从ShardingSphereDataSource中获取
 contextManger字段。
   
   ```java
     try (Connection conn = DriverStateContext.getConnection(slaveDataSource, 
contextManager)) {
         isHealthy = conn.isValid(2); // 超时2秒
         return isHealthy; // 超时2秒
     }
   ```
   
   ```xml
   <!-- 
https://mvnrepository.com/artifact/org.apache.shardingsphere/shardingsphere-jdbc
 -->
   <dependency>
       <groupId>org.apache.shardingsphere</groupId>
       <artifactId>shardingsphere-jdbc</artifactId>
       <version>5.5.0</version>
   </dependency>
   ```
   
   最终再通过DriverStateContext判断连接是否可用,请问有没有更好的方式? 
   
   真心求教 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: 
[email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to