<tfoot id='8l2vi'></tfoot>
      <bdo id='8l2vi'></bdo><ul id='8l2vi'></ul>

      <i id='8l2vi'><tr id='8l2vi'><dt id='8l2vi'><q id='8l2vi'><span id='8l2vi'><b id='8l2vi'><form id='8l2vi'><ins id='8l2vi'></ins><ul id='8l2vi'></ul><sub id='8l2vi'></sub></form><legend id='8l2vi'></legend><bdo id='8l2vi'><pre id='8l2vi'><center id='8l2vi'></center></pre></bdo></b><th id='8l2vi'></th></span></q></dt></tr></i><div id='8l2vi'><tfoot id='8l2vi'></tfoot><dl id='8l2vi'><fieldset id='8l2vi'></fieldset></dl></div>
      <legend id='8l2vi'><style id='8l2vi'><dir id='8l2vi'><q id='8l2vi'></q></dir></style></legend>
    1. <small id='8l2vi'></small><noframes id='8l2vi'>

    2. 配置 GlassFish JDBC 连接池以处理 Amazon RDS 多可用区故障转移

      时间:2023-06-24

          <tbody id='y0UwG'></tbody>

        1. <legend id='y0UwG'><style id='y0UwG'><dir id='y0UwG'><q id='y0UwG'></q></dir></style></legend>

          • <i id='y0UwG'><tr id='y0UwG'><dt id='y0UwG'><q id='y0UwG'><span id='y0UwG'><b id='y0UwG'><form id='y0UwG'><ins id='y0UwG'></ins><ul id='y0UwG'></ul><sub id='y0UwG'></sub></form><legend id='y0UwG'></legend><bdo id='y0UwG'><pre id='y0UwG'><center id='y0UwG'></center></pre></bdo></b><th id='y0UwG'></th></span></q></dt></tr></i><div id='y0UwG'><tfoot id='y0UwG'></tfoot><dl id='y0UwG'><fieldset id='y0UwG'></fieldset></dl></div>

            <small id='y0UwG'></small><noframes id='y0UwG'>

              <bdo id='y0UwG'></bdo><ul id='y0UwG'></ul>
              • <tfoot id='y0UwG'></tfoot>
                本文介绍了配置 GlassFish JDBC 连接池以处理 Amazon RDS 多可用区故障转移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个在 EC2 上的 GlassFish 中运行的 Java EE 应用程序,在 Amazon RDS 上有一个 MySQL 数据库.我正在尝试将 JDBC 连接池配置为以最大限度地减少数据库故障转移时的停机时间.

                I have a Java EE application running in GlassFish on EC2, with a MySQL database on Amazon RDS. I am trying to configure the JDBC connection pool to in order to minimize downtime in case of database failover.

                在多可用区故障转移期间,我的当前配置无法正常工作,因为备用数据库实例似乎在几分钟后可用(根据 AWS 控制台),而我的 GlassFish 实例仍然卡住了很长时间(大约 15 分钟),然后再开始工作.

                My current configuration isn't working correctly during a Multi-AZ failover, as the standby database instance appears to be available in a couple of minutes (according to the AWS console) while my GlassFish instance remains stuck for a long time (about 15 minutes) before resuming work.

                连接池是这样配置的:

                asadmin create-jdbc-connection-pool --restype javax.sql.ConnectionPoolDataSource 
                --datasourceclassname com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource 
                --isconnectvalidatereq=true --validateatmostonceperiod=60 --validationmethod=auto-commit 
                --property user=$DBUSER:password=$DBPASS:databaseName=$DBNAME:serverName=$DBHOST:port=$DBPORT 
                MyPool
                

                如果我使用 Single-AZ db.m1.small 实例并从控制台重新启动数据库,GlassFish 将使断开的连接无效,抛出一些异常,然后数据库可用后立即重新连接.在此设置中,我的停机时间不到 1 分钟.

                If I use a Single-AZ db.m1.small instance and reboot the database from the console, GlassFish will invalidate the broken connections, throw some exceptions and then reconnect as soon the database is available. In this setup I get less than 1 minute of downtime.

                如果我使用 多可用区 db.m1.small 实例并从 AWS 控制台通过故障转移重新启动,我看不到任何异常.服务器完全停止,所有传入请求都超时.15 分钟后,我终于明白了:

                If I use a Multi-AZ db.m1.small instance and reboot with failover from the AWS console, I see no exception at all. The server halts completely, with all incoming requests timing out. After 15 minutes I finally get this:

                Communication failure detected when attempting to perform read query outside of a transaction. Attempting to retry query. Error was: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
                Internal Exception: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
                
                The last packet successfully received from the server was 940,715 milliseconds ago.  The last packet sent successfully to the server was 935,598 milliseconds ago.
                

                看起来好像每个 HTTP 线程都在无效连接上被阻塞而没有出现异常,因此没有机会执行连接验证.

                It appears as if each HTTP thread gets blocked on an invalid connection without getting an exception and so there's no chance to perform connection validation.

                多可用区情况下的停机时间始终在 15-16 分钟之间,因此看起来像是某种超时,但我无法更改它.

                Downtime in the Multi-AZ case is always between 15-16 minutes, so it looks like a timeout of some sort but I was unable to change it.

                我尝试过但没有成功的事情:

                Things I have tried without success:

                • 连接泄漏超时/回收
                • 语句泄漏超时/回收
                • 语句超时
                • 使用不同的验证方法
                • 使用 MysqlDataSource 而不是 MysqlConnectionPoolDataSource

                如何为卡住的查询设置超时,以便重用、验证和替换池中的连接?或者如何让 GlassFish 检测到数据库故障转移?

                How can I set a timeout on stuck queries so that connections in the pool are reused, validated and replaced? Or how can I let GlassFish detect a database failover?

                推荐答案

                正如我之前评论过的,这是因为打开并连接到数据库的套接字没有意识到连接已经丢失,所以它们保持连接直到操作系统套接字超时被触发,我读到它通常在大约 30 分钟内.

                As I commented before, it is because the sockets that are open and connected to the database don't realize the connection has been lost, so they stayed connected until the OS socket timeout is triggered, which I read might be usually in about 30 minutes.

                要解决此问题,您需要覆盖 JDBC 连接字符串或 JDNI 连接配置/属性中的套接字超时,以将 socketTimeout 参数定义为更短的时间.

                To solve the issue you need to override the socket Timeout in your JDBC Connection String or in the JDNI COnnection Configuration/Properties to define the socketTimeout param to a smaller time.

                请记住,任何比定义的值长的连接都将被终止,即使它正在被使用(我无法确认这一点,这是我读到的).

                Keep in mind that any connection longer than the value defined will be killed, even if it is being used (I haven't been able to confirm this, is what I read).

                我在评论中提到的另外两个参数是 connectTimeoutautoReconnect.

                The other two parameters I mention in my comment are connectTimeout and autoReconnect.

                这是我的 JDBC 连接字符串:

                Here's my JDBC Connection String:

                jdbc:(...)&connectTimeout=15000&socketTimeout=60000&autoReconnect=true 
                

                我还通过执行禁用了 Java 的 DNS 缓存

                I also disabled Java's DNS cache by doing

                 java.security.Security.setProperty("networkaddress.cache.ttl" , "0"); 
                 java.security.Security.setProperty("networkaddress.cache.negative.ttl" , "0"); 
                

                我这样做是因为 Java 不遵守 TTL,并且当发生故障转移时,DNS 是相同的,但 IP 会发生变化.

                I do this because Java doesn't honor the TTL's, and when the failover takes place, the DNS is the same but the IP changes.

                由于您使用的是应用服务器,因此在使用 -Dnet 启动 glassfish 时必须将禁用 DNS 缓存的参数传递给 JVM,而不是应用程序本身.

                Since you are using an Application Server, the parameters to disable DNS cache must be passed to the JVM when starting the glassfish with -Dnet and not the application itself.

                这篇关于配置 GlassFish JDBC 连接池以处理 Amazon RDS 多可用区故障转移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何在亚马逊 RDS 上“加载数据文件"? 下一篇:Amazon RDS 无法执行 SET GLOBAL 命令

                相关文章

                  <bdo id='6yDPW'></bdo><ul id='6yDPW'></ul>

                  <tfoot id='6yDPW'></tfoot>
                    <i id='6yDPW'><tr id='6yDPW'><dt id='6yDPW'><q id='6yDPW'><span id='6yDPW'><b id='6yDPW'><form id='6yDPW'><ins id='6yDPW'></ins><ul id='6yDPW'></ul><sub id='6yDPW'></sub></form><legend id='6yDPW'></legend><bdo id='6yDPW'><pre id='6yDPW'><center id='6yDPW'></center></pre></bdo></b><th id='6yDPW'></th></span></q></dt></tr></i><div id='6yDPW'><tfoot id='6yDPW'></tfoot><dl id='6yDPW'><fieldset id='6yDPW'></fieldset></dl></div>
                  1. <small id='6yDPW'></small><noframes id='6yDPW'>

                  2. <legend id='6yDPW'><style id='6yDPW'><dir id='6yDPW'><q id='6yDPW'></q></dir></style></legend>