您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.
处理暂时性错误并有效地连接到 Azure Database for MySQLHandle transient errors and connect efficiently to Azure Database for MySQL
3/18/2020
本文内容
本文介绍如何处理暂时性错误并有效地连接到 Azure Database for MySQL。This article describes how to handle transient errors and connect efficiently to Azure Database for MySQL.
暂时性错误Transient errors
暂时性错误也称为暂时性故障,是一种可以自行解决的错误。A transient error, also known as a transient fault, is an error that will resolve itself. 这些错误往往表现为与数据库服务器的连接断开。Most typically these errors manifest as a connection to the database server being dropped. 此外,无法与服务器建立的新连接。Also new connections to a server can't be opened. 例如,在发生硬件或网络故障时,可能会出现暂时性错误。Transient errors can occur for example when hardware or network failure happens. 另一个可能的原因是正在推出 PaaS 服务的新版本。系统在 60 秒以内可自动解决其中的大部分事件。Another reason could be a new version of a PaaS service that is being rolled out. Most of these events are automatically mitigated by the system in less than 60 seconds. 设计和开发云中的应用程序时,预料到会出现暂时性错误是最佳做法。A best practice for designing and developing applications in the cloud is to expect transient errors. 假设这些错误随时可能在任意组件中发生,并部署相应的逻辑来应对这种情况。Assume they can happen in any component at any time and to have the appropriate logic in place to handle these situations.
处理暂时性错误Handling transient errors
应使用重试逻辑来处理暂时性错误。Transient errors should be handled using retry logic. 必须考虑的情况包括:Situations that must be considered:
尝试打开连接时出错An error occurs when you try to open a connection
服务器端的空闲连接断开。An idle connection is dropped on the server side. 尝试发出的命令无法执行When you try to issue a command it can't be executed
当前正在用于执行命令的活动连接断开。An active connection that currently is executing a command is dropped.
第一种和第二种情况的处理方式非常直接。The first and second case are fairly straight forward to handle. 可以再试打开连接。Try to open the connection again. 如果连接成功,则表示系统解决了暂时性错误。When you succeed, the transient error has been mitigated by the system. 可以再次使用 Azure Database for MySQL。You can use your Azure Database for MySQL again. 我们建议在重试连接之前等待一段时间。We recommend having waits before retrying the connection. 如果初始重试失败,则回退。Back off if the initial retries fail. 这样,系统便可以使用所有可用资源来解决错误局面。This way the syst