我的应用程序是基于 hibernate 从 mysql 服务器获取数据。此 mysql 服务器被复制到另一个 mysql 服务器实例。今天,由于主数据库服务器在没有任何通知的情况下关闭,我遇到了停机时间。为避免将来出现任何意外问题,我计划添加一项功能,使系统能够在发现主数据库关闭时连接到辅助数据库。
有没有一种方法可以利用 hibernate 库来启用此功能?
Today, I got a downtime as the primary database server was gone down without any notice.
嗯,这是您应该解决的第一件事(通过适当的监控)。
(...) Is there exists a way by which, I can leverage hibernate library to enable this functionality?
据我所知,Hibernate 并没有为此提供任何便利。就个人而言,我会研究 MySQL 及其 JDBC 驱动程序的故障转移支持。我无法提供非常具体的答案,因为我还没有用 MySQL 实现这个,但这里有一些提示:
并且,如上文最新链接底部所述(以及 this comment 中):
You may also want to investigate the Load Balancing JDBC Pool (lbpol) tool, which provides a wrapper around the standard JDBC driver and enables you to use DB connection pools that includes checks for system failures and uneven load distribution. For more information, see Load Balancing JDBC Pool (lbpool).
Tôi là một lập trình viên xuất sắc, rất giỏi!