[go: up one dir, main page]

CN114925052A - Method, device, equipment and computer readable medium for restarting database - Google Patents

Method, device, equipment and computer readable medium for restarting database Download PDF

Info

Publication number
CN114925052A
CN114925052A CN202210542893.7A CN202210542893A CN114925052A CN 114925052 A CN114925052 A CN 114925052A CN 202210542893 A CN202210542893 A CN 202210542893A CN 114925052 A CN114925052 A CN 114925052A
Authority
CN
China
Prior art keywords
database
library
standby
main
restarting
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202210542893.7A
Other languages
Chinese (zh)
Other versions
CN114925052B (en
Inventor
洪东楗
刘欢
向安杰
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Xi'an Tongxing Hengyao Information Technology Co ltd
Original Assignee
Jingdong Technology Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Jingdong Technology Information Technology Co Ltd filed Critical Jingdong Technology Information Technology Co Ltd
Priority to CN202210542893.7A priority Critical patent/CN114925052B/en
Publication of CN114925052A publication Critical patent/CN114925052A/en
Application granted granted Critical
Publication of CN114925052B publication Critical patent/CN114925052B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/21Design, administration or maintenance of databases
    • G06F16/215Improving data quality; Data cleansing, e.g. de-duplication, removing invalid entries or correcting typographical errors
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/25Integrating or interfacing systems involving database management systems
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/28Databases characterised by their database models, e.g. relational or object models
    • G06F16/284Relational databases
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/547Remote procedure calls [RPC]; Web services
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/54Indexing scheme relating to G06F9/54
    • G06F2209/544Remote

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Software Systems (AREA)
  • Quality & Reliability (AREA)
  • Computing Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a method, a device, equipment and a computer readable medium for restarting a database, and relates to the technical field of computers. One embodiment of the method comprises: stopping and restarting the database backup in response to the remote procedure call request; under the condition that the data in the database main library and the data in the database standby library are consistent, transferring a data request from the database main library to the database standby library; switching the database main library into a new database standby library and switching the database standby library into a new database main library; and restarting the database to prepare the database newly. This embodiment enables the database to shorten the unavailability time period.

Description

重启数据库的方法、装置、设备和计算机可读介质Method, apparatus, device and computer readable medium for restarting a database

技术领域technical field

本发明涉及计算机技术领域,尤其涉及一种重启数据库的方法、装置、设备和计算机可读介质。The present invention relates to the field of computer technologies, and in particular, to a method, apparatus, device and computer-readable medium for restarting a database.

背景技术Background technique

MySQL是一种关系型数据库管理系统,关系数据库将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性。MySQL所使用的SQL语言是用于访问数据库的最常用标准化语言。MySQL is a relational database management system, relational databases keep data in different tables instead of keeping all the data in one big warehouse, which increases speed and improves flexibility. The SQL language used by MySQL is the most commonly used standardized language for accessing databases.

目前,云数据库MySQL的重启方案,通常是把代理(Agent)服务和MySQL服务部署在一个容器中。然后管控系统调用Agent服务暴露的远程过程调用(Remote Procedure Call,RPC)接口去分别重启主库和备库。At present, the restart plan of ApsaraDB for MySQL usually deploys the agent service and the MySQL service in a container. Then the management and control system calls the Remote Procedure Call (RPC) interface exposed by the Agent service to restart the main database and the standby database respectively.

在实现本发明过程中,发明人发现现有技术中至少存在如下问题:MySQL数据库重启方案,常常会导致数据库长时间不可用。In the process of implementing the present invention, the inventor finds that there are at least the following problems in the prior art: the MySQL database restart solution often causes the database to be unavailable for a long time.

发明内容SUMMARY OF THE INVENTION

有鉴于此,本发明实施例提供一种重启数据库的方法、装置、设备和计算机可读介质,能够数据库缩短不可用时长。In view of this, the embodiments of the present invention provide a method, apparatus, device, and computer-readable medium for restarting a database, which can shorten the unavailable time of the database.

为实现上述目的,根据本发明实施例的一个方面,提供了一种重启数据库的方法,包括:To achieve the above object, according to an aspect of the embodiments of the present invention, a method for restarting a database is provided, including:

响应于远程过程调用请求,停止并重启数据库备库;In response to a remote procedure call request, stop and restart the database standby database;

在数据库主库和所述数据库备库中数据一致的情况下,将数据请求从所述数据库主库转移到所述数据库备库;When the data in the main database and the standby database are consistent, transfer the data request from the main database to the standby database;

将所述数据库主库切换为数据库新备库,以及将所述数据库备库切换为数据库新主库;Switching the database main database to a new database standby database, and switching the database standby database to a new database main database;

重启所述数据库新备库。Restart the new standby database of the database.

所述在数据库主库和所述数据库备库中数据一致,包括:The data in the main database database and the database backup database are consistent, including:

加快所述数据库备库的写入速度;Speed up the writing speed of the database standby database;

在所述数据库主库和所述数据库备库的延迟时间小于等于预设延迟阈值,将所述数据库主库设置为只读;When the delay time between the main database and the standby database is less than or equal to a preset delay threshold, the main database is set to read-only;

基于所述数据库主库的位点信息和所述数据库备库的位点信息,确定所述在数据库主库和所述数据库备库中数据一致。Based on the location information of the main database database and the location information of the standby database database, it is determined that the data in the main database database and the standby database database are consistent.

所述将数据请求从所述数据库主库转移到所述数据库备库,包括:The transferring the data request from the main database to the standby database includes:

在负载均衡中,删除所述数据库主库的IP,并将所述数据库备库的IP配置到所述负载均衡中,以将数据请求从所述数据库主库转移到所述数据库备库。In load balancing, the IP of the main database database is deleted, and the IP of the standby database database is configured in the load balancing, so as to transfer data requests from the main database database to the standby database database.

所述将所述数据库主库切换为数据库新备库,包括:The switching of the main database database to the new standby database database includes:

清理所述数据库备库中的同步信息;cleaning up the synchronization information in the database standby database;

连接所述数据库主库,并为所述数据库主库增加复制信息,以将所述数据库主库切换为数据库新备库;Connect the main database database, and add replication information for the main database database, so as to switch the main database database to a new database backup database;

所述将所述数据库备库切换为数据库新主库,包括:The switching of the database standby database to the new main database database includes:

打开所述数据库备库的只读,并重置磁盘写入策略,以所述数据库备库切换为数据库新主库。The read-only of the database standby database is turned on, and the disk write policy is reset, and the database standby database is switched to the new main database of the database.

所述响应于远程过程调用请求,停止并重启数据库备库之前,还包括:Before stopping and restarting the database standby database in response to the remote procedure call request, the method further includes:

所述数据库主库与所述数据库从库的主从延迟,小于预设重启阈值。The master-slave delay between the database master database and the database slave database is less than a preset restart threshold.

所述方法还包括:The method also includes:

所述数据库主库与所述数据库从库的主从延迟,大于或等于预设重启阈值,则强制重启所述数据库主库和所述数据库备库。If the master-slave delay between the master database and the slave database is greater than or equal to a preset restart threshold, the master database and the slave database are forcibly restarted.

所述将所述数据库主库切换为数据库新备库,以及将所述数据库备库切换为数据库新主库之前,还包括:Before switching the main database database to the new standby database, and switching the standby database to the new main database, the method further includes:

支持延迟切换,检测当前时间与指定的切换时间一致。Supports delayed switching, and detects that the current time is consistent with the specified switching time.

根据本发明实施例的第二方面,提供了一种重启数据库的装置,包括:According to a second aspect of the embodiments of the present invention, an apparatus for restarting a database is provided, including:

响应模块,用于响应于远程过程调用请求,停止并重启数据库备库;The response module is used to stop and restart the database standby database in response to the remote procedure call request;

转移模块,用于在数据库主库和所述数据库备库中数据一致的情况下,将数据请求从所述数据库主库转移到所述数据库备库;a transfer module, configured to transfer a data request from the main database database to the standby database database under the condition that the data in the main database database and the standby database database are consistent;

切换模块,用于将所述数据库主库切换为数据库新备库,以及将所述数据库备库切换为数据库新主库;A switching module, used for switching the main database database to a new standby database, and switching the standby database to a new main database;

重启模块,用于重启所述数据库新备库。The restart module is used for restarting the new standby database of the database.

根据本发明实施例的第三方面,提供了一种重启数据库的电子设备,包括:According to a third aspect of the embodiments of the present invention, an electronic device for restarting a database is provided, including:

一个或多个处理器;one or more processors;

存储装置,用于存储一个或多个程序,storage means for storing one or more programs,

当所述一个或多个程序被所述一个或多个处理器执行,使得所述一个或多个处理器实现如上述的方法。The one or more programs, when executed by the one or more processors, cause the one or more processors to implement the method as described above.

根据本发明实施例的第四方面,提供了一种计算机可读介质,其上存储有计算机程序,所述程序被处理器执行时实现如上述的方法。According to a fourth aspect of the embodiments of the present invention, there is provided a computer-readable medium on which a computer program is stored, and when the program is executed by a processor, the above-mentioned method is implemented.

上述发明中的一个实施例具有如下优点或有益效果:响应于远程过程调用请求,停止并重启数据库备库;在数据库主库和所述数据库备库中数据一致的情况下,将数据请求从所述数据库主库转移到所述数据库备库;将所述数据库主库切换为数据库新备库,以及将所述数据库备库切换为数据库新主库;重启所述数据库新备库。在满足数据库主库与数据库备库数据一致的情况下,交换数据库主库和数据库备库,从而减少重启数据库的占用时间,继而能够数据库缩短不可用时长。An embodiment of the above invention has the following advantages or beneficial effects: in response to a remote procedure call request, stop and restart the database standby database; when the data in the main database database and the database standby database are consistent, the data request is sent from all The main database is transferred to the standby database; the main database is switched to the new standby database, and the standby database is switched to the new main database; the new standby database is restarted. Under the condition that the data of the main database database and the database standby database are consistent, the main database database and the database standby database are exchanged, thereby reducing the occupied time of restarting the database, and then shortening the unavailable time of the database.

上述的非惯用的可选方式所具有的进一步效果将在下文中结合具体实施方式加以说明。Further effects of the above non-conventional alternatives will be described below in conjunction with specific embodiments.

附图说明Description of drawings

附图用于更好地理解本发明,不构成对本发明的不当限定。其中:The accompanying drawings are used for better understanding of the present invention and do not constitute an improper limitation of the present invention. in:

图1是根据本发明实施例的重启数据库的方法的主要流程示意图;1 is a schematic flowchart of a main flow of a method for restarting a database according to an embodiment of the present invention;

图2是根据本发明实施例的强制重启数据库的示意图;2 is a schematic diagram of a forced restart of a database according to an embodiment of the present invention;

图3是根据本发明实施例的确定数据库主库和所述数据库备库中数据一致的流程示意图;3 is a schematic flowchart of determining the consistency of data in the main database database and the database standby database according to an embodiment of the present invention;

图4是根据本发明实施例的转移数据请求的示意图;4 is a schematic diagram of a transfer data request according to an embodiment of the present invention;

图5是根据本发明实施例的将数据库主库切换为数据库新备库的流程示意图;5 is a schematic flowchart of switching the main database database to the new standby database database according to an embodiment of the present invention;

图6是根据本发明实施例的切换数据库的示意图;6 is a schematic diagram of a handover database according to an embodiment of the present invention;

图7是根据本发明实施例的重启数据库的流程示意图;7 is a schematic flowchart of restarting a database according to an embodiment of the present invention;

图8是根据本发明实施例的重启数据库的装置的主要结构示意图;8 is a schematic diagram of the main structure of an apparatus for restarting a database according to an embodiment of the present invention;

图9是本发明实施例可以应用于其中的示例性系统架构图;FIG. 9 is an exemplary system architecture diagram to which an embodiment of the present invention may be applied;

图10是适于用来实现本发明实施例的终端设备或服务器的计算机系统的结构示意图。FIG. 10 is a schematic structural diagram of a computer system suitable for implementing a terminal device or a server according to an embodiment of the present invention.

具体实施方式Detailed ways

以下结合附图对本发明的示范性实施例做出说明,其中包括本发明实施例的各种细节以助于理解,应当将它们认为仅仅是示范性的。因此,本领域普通技术人员应当认识到,可以对这里描述的实施例做出各种改变和修改,而不会背离本发明的范围和精神。同样,为了清楚和简明,以下的描述中省略了对公知功能和结构的描述。Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, which include various details of the embodiments of the present invention to facilitate understanding and should be considered as exemplary only. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted from the following description for clarity and conciseness.

目前,MySQL数据库重启方案,常常会导致数据库长时间不可用。如:直接重启,每次重启都会导致服务长时间不可用,影响时长平均需要在2分钟以上,导致用户体验较差。At present, the MySQL database restart scheme often causes the database to be unavailable for a long time. For example, if you restart directly, each restart will cause the service to be unavailable for a long time. The average impact time is more than 2 minutes, resulting in poor user experience.

为了解决MySQL数据库长时间不可用的技术问题,可以采用以下本发明实施例中的技术方案。In order to solve the technical problem that the MySQL database is unavailable for a long time, the following technical solutions in the embodiments of the present invention may be adopted.

参见图1,图1是根据本发明实施例的重启数据库的方法主要流程的示意图,在数据库主库和数据库备库中数据一致的情况下,切换数据库主库和数据库备库。如图1所示,具体包括以下步骤:Referring to FIG. 1 , FIG. 1 is a schematic diagram of the main flow of a method for restarting a database according to an embodiment of the present invention. When the data in the main database database and the database standby database are consistent, the main database database and the database standby database are switched. As shown in Figure 1, it specifically includes the following steps:

S101、响应于远程过程调用请求,停止并重启数据库备库。S101, in response to the remote procedure call request, stop and restart the database standby database.

在本发明实施例中,Agent服务和MySQL服务部署在一个容器中。也就是说,在主库容器中包括代理服务和数据库主库;在备库容器中包括代理服务和数据库备库。数据库主库和数据库备库均是相对而言,均属于数据库。数据库备库作为数据库主库的数据备份。用户通过管控系统负责操控数据库。In this embodiment of the present invention, the Agent service and the MySQL service are deployed in a container. That is to say, the main library container includes the agent service and the database main library; the standby library container includes the agent service and the database standby library. The database master database and the database standby database are both relative and belong to the database. The database standby database serves as the data backup of the database main database. The user is responsible for manipulating the database through the management and control system.

为了重启数据库,管控系统发送RPC请求,调用数据库备库的代理服务,停止使用数据库备库,并重启数据库备库。作为一个示例,重启数据库备库方式包括通过RPC请求,强制重启数据库备库。作为另一个示例,通过RPC请求,强制重启数据库备库失败的情况下,则使用安全外壳协议(SSH)的方式连接备库容器,执行远程命令代替RPC操作。In order to restart the database, the management and control system sends an RPC request, calls the proxy service of the database standby database, stops using the database standby database, and restarts the database standby database. As an example, the method of restarting the database standby database includes forcibly restarting the database standby database through an RPC request. As another example, if the forced restart of the database standby database fails through an RPC request, the Secure Shell Protocol (SSH) is used to connect to the standby database container, and remote commands are executed instead of RPC operations.

参见图2,图2是根据本发明实施例的强制重启数据库的示意图。图2中,管控系统通过RPC请求或SHH操控数据库备库。Referring to FIG. 2, FIG. 2 is a schematic diagram of forcibly restarting a database according to an embodiment of the present invention. In Figure 2, the management and control system controls the database standby database through RPC requests or SHH.

为了重启数据库备库,管控系统发送RPC请求,通过代理服务,先停止数据库备库(systemctl stop mysqld),后启动数据库备库(systemctl start mysqld)。In order to restart the database standby database, the management and control system sends an RPC request, and through the proxy service, first stop the database standby database (systemctl stop mysqld), and then start the database standby database (systemctl start mysqld).

若调用RPC请求失败或调用RPC请求超时,则可以采用SHH的方式连接备库容器,执行远程命令代替RPC操作。使用SSH方式时,可以直接强行kill数据库(pkill-9mysqld)。If the invocation of the RPC request fails or the invocation of the RPC request times out, you can use the SHH method to connect to the standby container and execute remote commands instead of RPC operations. When using SSH, you can directly forcibly kill the database (pkill-9mysqld).

可以理解的是,调用RPC失败才会使用SSH。调用RPC请求,依赖于部署在容器中的代理服务。一旦代理服务出现异常,会导致无法调用代理服务,也就是无法重启数据库备库。所以就会采取备用方案,使用SSH的方式直连容器,并执行操作数据库的SHELL命令。Understandably, SSH is used only if the call to RPC fails. Invoking RPC requests depends on the proxy service deployed in the container. Once the proxy service is abnormal, the proxy service cannot be called, that is, the database standby database cannot be restarted. Therefore, an alternate solution is adopted, using SSH to directly connect to the container, and execute the SHELL command to operate the database.

S102、在数据库主库和数据库备库中数据一致的情况下,将数据请求从数据库主库转移到数据库备库。S102: In the case that the data in the main database and the standby database are consistent, transfer the data request from the main database to the standby database.

在本发明实施例中,重启数据库包括重启数据库备库和数据库主库。为了重启数据库主库,前提是保障数据库主库和数据库备库中的数据一致。在数据库主库和数据库备库中数据一致的情况下,将数据请求从数据库主库转移到数据库备库。In the embodiment of the present invention, restarting the database includes restarting the database standby database and the database main database. In order to restart the database master database, the premise is to ensure that the data in the database master database and the database standby database are consistent. When the data in the main database database and the database standby database are consistent, the data request is transferred from the database main database to the database standby database.

参见图3,图3是根据本发明实施例的确定数据库主库和数据库备库中数据一致的流程示意图。具体包括以下步骤:Referring to FIG. 3, FIG. 3 is a schematic flowchart of determining the consistency of data in the main database database and the database standby database according to an embodiment of the present invention. Specifically include the following steps:

S301、加快数据库备库的写入速度。S301. Speed up the writing speed of the database standby database.

为了缩短重启数据库的耗费时间,通过RPC请求数据库备库的代理服务。代理服务连接数据库备库,并设置磁盘写入策略,以加快数据库备库的写入速度。如:set globalinnodb_flush_log_at_trx_commit=2;set global sync_binlog=0。In order to shorten the time-consuming of restarting the database, the proxy service of the database standby database is requested through RPC. The proxy service connects to the database standby database and sets the disk write policy to speed up the writing speed of the database standby database. For example: set globalinnodb_flush_log_at_trx_commit=2; set global sync_binlog=0.

S302、在数据库主库和数据库备库的延迟时间小于等于预设延迟阈值,将数据库主库设置为只读。S302. The delay time between the main database database and the database standby database is less than or equal to a preset delay threshold, and the database main database is set to read-only.

通常数据库主库与数据库备库之间存储延迟时间。在数据库主库和数据库备库的延迟时间小于等于预设延迟阈值的情况下,说明数据库主库与数据库备库可以同步,则将数据库主库设置为只读。即,set global read_only='on'。设置只读的目的是:数据库主库停止写入,确保数据库备库快速追上主库。Usually the storage delay time between the database master database and the database standby database. If the delay time between the database master database and the database standby database is less than or equal to the preset delay threshold, it means that the database master database and the database standby database can be synchronized, and the database master database is set to read-only. That is, set global read_only='on'. The purpose of setting read-only is to stop writing to the main database database to ensure that the database standby database quickly catches up with the main database.

作为一个示例,预设延迟阈值为10秒。通过发送RPC请求至数据库备库的代理服务,该代理服务连上数据库执行:show slave status,进而获取延迟时间。As an example, the preset delay threshold is 10 seconds. By sending an RPC request to the proxy service of the database standby database, the proxy service connects to the database and executes: show slave status to obtain the delay time.

S303、基于数据库主库的位点信息和数据库备库的位点信息,确定在数据库主库和数据库备库中数据一致。S303. Based on the location information of the main database database and the location information of the standby database database, it is determined that the data in the main database database and the standby database database are consistent.

设置数据库主库为只读之后,需要基于数据库主库的位点信息和数据库备库的位点信息,确定在数据库主库和数据库备库中数据一致。After setting the database master database to be read-only, you need to make sure that the data in the database master database and the database standby database are consistent based on the location information of the database master database and the database standby database.

作为一个示例,通过RPC请求,分别发送至主库容器中的代理服务和备库容器中的代理服务。以通过代理服务连接数据库,分别获取数据库主库的位点信息和数据库备库的位点信息。如:采用select@@global.gtid_executed获取位点信息。位点信息用于记录数据库同步数据的标识。As an example, the RPC request is sent to the proxy service in the main database container and the proxy service in the standby database container respectively. To connect to the database through the proxy service, obtain the location information of the main database database and the location information of the database standby database respectively. For example: use select@@global.gtid_executed to obtain site information. Site information is used to record the identification of database synchronization data.

在具体实现时,数据库主库的位点信息和数据库备库的位点信息的差,即位点差为0,则确定在数据库主库和数据库备库中数据一致。In the specific implementation, if the difference between the location information of the main database database and the location information of the database standby database, that is, the location difference is 0, it is determined that the data in the main database database and the database standby database are consistent.

在图3的实施例中,一方面加快数据库备库的写入速度;一方面设置数据库主库为只读,以提高数据库主库和数据库备库的数据一致的速度。In the embodiment of FIG. 3 , on the one hand, the writing speed of the database backup database is accelerated;

在数据库主库和数据库备库中数据一致的情况下,将数据请求从数据库主库转移到数据库备库。即,数据库主库不再处理数据请求,数据库备库负责处理数据请求。When the data in the main database database and the database standby database are consistent, the data request is transferred from the database main database to the database standby database. That is, the main database database no longer processes data requests, and the database standby database is responsible for processing data requests.

在本发明的一个实施例中,在数据库主库和数据库备库中数据一致的情况下,就可以将数据请求从数据库主库转移到数据库备库。具体地,在负载均衡中,删除数据库主库的IP,并将数据库备库的IP配置到负载均衡中,以将数据请求从数据库主库转移到数据库备库。这样,数据库主库不再直接提供读写服务。In an embodiment of the present invention, when the data in the main database and the standby database are consistent, the data request can be transferred from the main database to the standby database. Specifically, in the load balancing, delete the IP of the database master database, and configure the IP of the database backup database into the load balancing, so as to transfer data requests from the database master database to the database backup database. In this way, the main database library no longer directly provides read and write services.

负载均衡(Load Balance,LB),就是指将负载(工作任务)进行平衡、分摊到多个操作单元上进行运行。从而协同完成工作任务。负载均衡构建在原有网络结构之上,它提供了一种透明且廉价有效的方法扩展服务器和网络设备的带宽、加强网络数据处理能力、增加吞吐量、提高网络的可用性和灵活性。Load Balance (LB) refers to balancing and apportioning loads (work tasks) to multiple operation units for operation. So as to complete the work tasks together. Load balancing is built on the original network structure. It provides a transparent and cheap and effective method to expand the bandwidth of servers and network equipment, strengthen the network data processing capacity, increase the throughput, and improve the availability and flexibility of the network.

参见图4,图4是根据本发明实施例的转移数据请求的示意图。图4中,数据库主库中,通过代理服务(Agent)与MySQL交互数据;数据库备库中,通过Agent与MySQL交互数据。用户在负载均衡过程中,将数据请求从数据库主库转移到数据库备库。数据库主库无需参与负载均衡,数据库备库参与负载均衡。数据库主库与数据库备库实施主从同步,即数据库主库中数据,同步至数据库备库中。Referring to FIG. 4, FIG. 4 is a schematic diagram of a transfer data request according to an embodiment of the present invention. In Figure 4, in the main database of the database, data is exchanged with MySQL through the agent service (Agent); in the standby database of the database, data is exchanged with MySQL through the Agent. During the load balancing process, users transfer data requests from the main database to the standby database. The main database database does not need to participate in load balancing, and the database standby database participates in load balancing. The master-slave synchronization is implemented between the database master database and the database standby database, that is, the data in the database master database is synchronized to the database standby database.

S103、将数据库主库切换为数据库新备库,以及将数据库备库切换为数据库新主库。S103, switch the main database database to the new standby database, and switch the standby database to the new main database of the database.

数据请求已从数据库主库转移到数据库备库,则说明此时的数据库备库作用是主库,此时的数据库主库的作用是备库。进而,需要将数据库主库切换为数据库新备库,以及将数据库备库切换为数据库新主库。The data request has been transferred from the database main database to the database standby database, which means that the role of the database standby database at this time is the main database, and the role of the database main database at this time is the standby database. Further, it is necessary to switch the main database database to the new database standby database, and to switch the database standby database to the new database main database.

参见图5,图5是根据本发明实施例的将数据库主库切换为数据库新备库的流程示意图。具体包括以下步骤:Referring to FIG. 5 , FIG. 5 is a schematic flowchart of switching the main database database to the new standby database database according to an embodiment of the present invention. Specifically include the following steps:

S501、清理数据库备库中的同步信息。S501. Clean up the synchronization information in the database standby database.

通过RPC请求,通过数据库备库的代理服务,清理备库中的同步信息。作为一个示例,同步信息包括slave信息,采用下述指令实现清理:stop slave;reset slave all。Through the RPC request, through the proxy service of the database standby database, the synchronization information in the standby database is cleaned up. As an example, the synchronization information includes slave information, and the following commands are used to implement cleanup: stop slave; reset slave all.

S502、连接数据库主库,并为数据库主库增加复制信息,以将数据库主库切换为数据库新备库。S502: Connect to the main database database, and add replication information to the main database database, so as to switch the main database database to the new standby database database.

通过RPC请求,数据库主库的代理服务,并为数据库主库增加复制信息,以将数据库主库切换为数据库新备库。作为一个示例,通过以下方式为数据库主库增加复制信息:change master to master_host='master_host',master_port='master_port',master_auto_position=1;start slaveuser='replicater'password='replicater'。Through the RPC request, the proxy service of the database master database and the replication information are added to the database master database to switch the database master database to the new database standby database. As an example, add replication information for the database master database in the following manner: change master to master_host='master_host', master_port='master_port', master_auto_position=1; start slaveuser='replicater' password='replicater'.

在图5的实施例中,将数据库主库切换为数据库新备库。In the embodiment of FIG. 5 , the main database database is switched to the new standby database database.

类似地,将数据库备库切换为数据库新主库:打开数据库备库的只读,并重置磁盘写入策略,以数据库备库切换为数据库新主库。具体地,采用下述指令打开数据库新主库:set global read_only='off'。重置磁盘写入策略:set global innodb_flush_log_at_trx_commit=1;set globalsync_binlog=1。Similarly, switch the database standby database to the new primary database: turn on the read-only of the database standby database, and reset the disk write policy to switch the database standby database to the new primary database of the database. Specifically, the following command is used to open the new main database of the database: set global read_only='off'. Reset the disk write policy: set global innodb_flush_log_at_trx_commit=1; set globalsync_binlog=1.

至此,将数据库主库切换为数据库新备库,以及将数据库备库切换为数据库新主库;At this point, switch the database main database to the new database standby database, and switch the database standby database to the new database main database;

参见图6,图6是根据本发明实施例的切换数据库的示意图。图6中,删除下述主从同步,即:删除数据库主库至数据库备库的主从同步。建立下述主从同步,即:建立数据库备库至数据库主库的主从同步。Referring to FIG. 6, FIG. 6 is a schematic diagram of a handover database according to an embodiment of the present invention. In FIG. 6, the following master-slave synchronization is deleted, that is, the master-slave synchronization from the database master database to the database backup database is deleted. Establish the following master-slave synchronization, namely: establish the master-slave synchronization from the database standby database to the database master database.

S104、重启数据库新备库。S104. Restart the database to a new standby database.

由于数据库新备库并未重启,因而需要重启数据库新备库。具体地,采用RPC请求,通过数据库新备库的代理服务器,停止和启动数据库新备库。确保数据库新备库是重启过的。其中,采用RPC请求重启失败或超时,还可以采用图2中的强制重启。Since the new standby database of the database has not been restarted, it is necessary to restart the new standby database of the database. Specifically, an RPC request is used to stop and start the new database standby database through the proxy server of the new database standby database. Make sure that the new standby database of the database has been restarted. Among them, if the RPC request fails to restart or times out, the forced restart in FIG. 2 may also be used.

在本发明的一个实施例中,对于切换数据库还可以支持切换时间。即:支持延迟切换,检测当前时间与指定的切换时间是否一致。在当前时间与指定的切换时间一致的情况下,则将数据库主库切换为数据库新备库,以及将数据库备库切换为数据库新主库;在当前时间与指定的切换时间不一致的情况下,则无需切换数据库。In one embodiment of the present invention, the handover time may also be supported for the handover database. That is, it supports delayed switching and detects whether the current time is consistent with the specified switching time. If the current time is consistent with the specified switching time, the main database will be switched to the new standby database, and the standby database will be switched to the new primary database; if the current time is inconsistent with the specified switching time, There is no need to switch databases.

基于指定的切换时间切换数据库,主要是考虑到重启影响时长已经足够短,只会有几秒的只读时长。但同样不希望上述只读时长,出现在业务高峰期。因此,可以指定一个业务低峰期完成数据库切换。作为一个示例,按照业务低峰期设置指定的切换时间。The database is switched based on the specified switching time, mainly considering that the restart impact time is short enough, and there is only a few seconds of read-only time. But I also don't want the above read-only time to appear during peak business hours. Therefore, you can designate a low business peak period to complete the database switch. As an example, the specified switching time is set according to the low traffic peak period.

在具体实施过程中,再重启数据库备库后,判断当前时间与指定的切换时间不一致,则挂起当前任务,并添加待派发任务。定时检查待派发任务,支持延迟切换,在当前时间与指定的切换时间一致的情况下,则执行待派发任务。In the specific implementation process, after restarting the database standby database, it is determined that the current time is inconsistent with the specified switching time, the current task is suspended, and the task to be dispatched is added. Regularly check tasks to be dispatched, support delayed switching, and execute tasks to be dispatched when the current time is consistent with the specified switching time.

在本发明的一个实施例中,重启数据库的方式有很多种,除采用S101至S104的技术方案之外,还可以直接采用强制重启。In an embodiment of the present invention, there are many ways to restart the database. In addition to the technical solutions of S101 to S104, forced restart may also be directly adopted.

可以基于数据库主库与数据库从库的主从延迟,确定重启数据库的方式。具体来说,数据库主库与数据库从库的主从延迟,小于预设重启阈值,则采用S101至S104的技术方案,这样便于加快数据库主库与数据库从属的数据同步;数据库主库与数据库从库的主从延迟,大于或等于预设重启阈值,则如前文所述的强制重启。The way to restart the database can be determined based on the master-slave delay between the database master database and the database slave database. Specifically, if the master-slave delay between the database master database and the database slave database is less than the preset restart threshold, the technical solutions from S101 to S104 are adopted, which is convenient to speed up the data synchronization between the database master database and the database slave database; the database master database and the database slave database The master-slave delay of the library is greater than or equal to the preset restart threshold, and the forced restart is as described above.

也就是说,当重启数据库时,可以不指定重启方式。采用RPC请求通过数据库从库的代理服务,该代理服务连上数据库从库,并获取延迟时间。如:执行show slave status,以获取延迟时间确定重启数据库的方式。That is to say, when restarting the database, the restart method may not be specified. Use RPC request to pass through the proxy service of the database slave library, the proxy service connects to the database slave library, and obtains the delay time. For example, execute show slave status to get the delay time to determine how to restart the database.

在上述实施例中,响应于远程过程调用请求,停止并重启数据库备库;在数据库主库和所述数据库备库中数据一致的情况下,将数据请求从所述数据库主库转移到所述数据库备库;将所述数据库主库切换为数据库新备库,以及将所述数据库备库切换为数据库新主库;重启所述数据库新备库。在满足数据库主库与数据库备库数据一致的情况下,交换数据库主库和数据库备库,从而减少重启数据库的占用时间,继而能够数据库缩短不可用时长。In the above embodiment, in response to a remote procedure call request, stop and restart the database standby database; if the data in the database main database and the database standby database are consistent, transfer the data request from the database main database to the database standby database. database backup database; switching the main database database to a new database backup database, and switching the database backup database to a new database primary database; restarting the new database backup database. Under the condition that the data of the main database database and the database standby database are consistent, the main database database and the database standby database are exchanged, thereby reducing the occupied time of restarting the database, and then shortening the unavailable time of the database.

参见图7,图7是根据本发明实施例的重启数据库的流程示意图。具体包括以下步骤:Referring to FIG. 7, FIG. 7 is a schematic flowchart of restarting a database according to an embodiment of the present invention. Specifically include the following steps:

S701、重启数据库。S701. Restart the database.

接收到重启指示后,重启数据库。基于主从延迟确定重启数据库的方式。主从延迟大于或等于10秒,则执行S702;主从延迟小于10秒,则执行S704。After receiving the restart instruction, restart the database. Determines the way to restart the database based on the master-slave latency. If the master-slave delay is greater than or equal to 10 seconds, execute S702; if the master-slave delay is less than 10 seconds, execute S704.

S702、重启数据库主库。S702. Restart the main database of the database.

强制重启数据库主库。Force restart of the main database database.

S703、重启数据库备库。S703. Restart the database standby database.

强制重启数据库备库。Force restart the database standby database.

S704、重启数据库备库。S704, restart the database standby database.

采用RPC请求,通过代理服务重启数据库备库。Use RPC request to restart the database standby database through the proxy service.

S705、判断当前时间是否与切换时间一致。S705. Determine whether the current time is consistent with the switching time.

判断当前时间是否与指定的切换时间一致。当前时间与指定的切换时间不一致,则执行S706;当前时间与指定的切换时间一致,则执行S707。Determine whether the current time is consistent with the specified switching time. If the current time is inconsistent with the designated switching time, S706 is executed; if the current time is consistent with the designated switching time, S707 is executed.

S706、挂起当前任务。S706, suspend the current task.

为了避免切换数据库对于业务的影响,需要挂起当前任务。然后,再次判断当前时间是否与指定的切换时间一致。In order to avoid the impact of switching databases on the business, the current task needs to be suspended. Then, it is judged again whether the current time is consistent with the designated switching time.

S707、切换数据库。S707. Switch the database.

将数据库主库切换为数据库新备库,以及将数据库备库切换为数据库新主库。Switch the database primary database to the new database standby database, and switch the database standby database to the new database primary database.

S708、重启数据库新备库。S708. Restart the database and the new standby database.

重启数据库新备库后,完成重启数据库。After restarting the database and the new standby database, restart the database.

在图7的实施例中,S702至S703是强制重启的步骤;S704至S708是平滑重启的步骤。通过S701可以判断采用哪种方式重启数据库。当然,也可以直接采用强制重启或平滑重启。In the embodiment of FIG. 7 , S702 to S703 are steps of forced restart; S704 to S708 are steps of smooth restart. Through S701, it can be judged which way to restart the database. Of course, forced restart or graceful restart can also be used directly.

参见图8,图8是根据本发明实施例的重启数据库的装置的主要结构的示意图,重启数据库的装置可以实现重启数据库的方法,如图8所示,重启数据库的装置具体包括:Referring to FIG. 8, FIG. 8 is a schematic diagram of the main structure of an apparatus for restarting a database according to an embodiment of the present invention. The apparatus for restarting a database can implement a method for restarting a database. As shown in FIG. 8, the apparatus for restarting the database specifically includes:

响应模块801,用于响应于远程过程调用请求,停止并重启数据库备库;The response module 801 is used to stop and restart the database standby database in response to the remote procedure call request;

转移模块802,用于在数据库主库和所述数据库备库中数据一致的情况下,将数据请求从所述数据库主库转移到所述数据库备库;A transfer module 802, configured to transfer a data request from the main database database to the standby database database when the data in the main database database and the standby database database are consistent;

切换模块803,用于将所述数据库主库切换为数据库新备库,以及将所述数据库备库切换为数据库新主库;A switching module 803, configured to switch the main database database to a new standby database, and to switch the standby database to a new main database;

重启模块804,用于重启所述数据库新备库。The restarting module 804 is used for restarting the new standby database of the database.

在本发明的一个实施例中,转移模块802,具体用于加快所述数据库备库的写入速度;In an embodiment of the present invention, the transfer module 802 is specifically configured to speed up the writing speed of the database standby database;

在所述数据库主库和所述数据库备库的延迟时间小于等于预设延迟阈值,将所述数据库主库设置为只读;When the delay time between the main database and the standby database is less than or equal to a preset delay threshold, the main database is set to read-only;

基于所述数据库主库的位点信息和所述数据库备库的位点信息,确定所述在数据库主库和所述数据库备库中数据一致。Based on the location information of the main database database and the location information of the standby database database, it is determined that the data in the main database database and the standby database database are consistent.

在本发明的一个实施例中,转移模块802,具体用于在负载均衡中,删除所述数据库主库的IP,并将所述数据库备库的IP配置到所述负载均衡中,以将数据请求从所述数据库主库转移到所述数据库备库。In an embodiment of the present invention, the transfer module 802 is specifically configured to delete the IP of the main database database in load balancing, and configure the IP of the database backup database into the load balancing, so as to transfer the data The request is transferred from the database master database to the database backup database.

在本发明的一个实施例中,切换模块803,具体用于清理所述数据库备库中的同步信息;In an embodiment of the present invention, the switching module 803 is specifically configured to clear the synchronization information in the database standby database;

连接所述数据库主库,并为所述数据库主库增加复制信息,以将所述数据库主库切换为数据库新备库;Connect the main database database, and add replication information for the main database database, so as to switch the main database database to a new database backup database;

以及,as well as,

打开所述数据库备库的只读,并重置磁盘写入策略,以所述数据库备库切换为数据库新主库。The read-only of the database standby database is turned on, and the disk write policy is reset, and the database standby database is switched to the new main database of the database.

在本发明的一个实施例中,响应模块801,还用于所述数据库主库与所述数据库从库的主从延迟,小于预设重启阈值。In an embodiment of the present invention, the response module 801 is further configured for the master-slave delay between the database master database and the database slave database, which is less than a preset restart threshold.

在本发明的一个实施例中,响应模块801,还用于所述数据库主库与所述数据库从库的主从延迟,大于或等于预设重启阈值,则强制重启所述数据库主库和所述数据库备库。In an embodiment of the present invention, the response module 801 is further configured to forcibly restart the master database and all the master-slave delays between the master database and the slave database if the delay is greater than or equal to a preset restart threshold. Describe the database standby database.

在本发明的一个实施例中,切换模块803,还用于支持延迟切换,检测当前时间与指定的切换时间一致。In an embodiment of the present invention, the switching module 803 is further configured to support delayed switching, and detect that the current time is consistent with the specified switching time.

图9示出了可以应用本发明实施例的重启数据库的方法或重启数据库的装置的示例性系统架构900。FIG. 9 shows an exemplary system architecture 900 of a method for restarting a database or an apparatus for restarting a database to which embodiments of the present invention can be applied.

如图9所示,系统架构900可以包括终端设备901、902、903,网络904和服务器905。网络904用以在终端设备901、902、903和服务器905之间提供通信链路的介质。网络904可以包括各种连接类型,例如有线、无线通信链路或者光纤电缆等等。As shown in FIG. 9 , the system architecture 900 may include terminal devices 901 , 902 , and 903 , a network 904 and a server 905 . The network 904 is a medium used to provide a communication link between the terminal devices 901 , 902 , 903 and the server 905 . Network 904 may include various connection types, such as wired, wireless communication links, or fiber optic cables, among others.

用户可以使用终端设备901、902、903通过网络904与服务器905交互,以接收或发送消息等。终端设备901、902、903上可以安装有各种通讯客户端应用,例如购物类应用、网页浏览器应用、搜索类应用、即时通信工具、邮箱客户端、社交平台软件等(仅为示例)。The user can use the terminal devices 901, 902, 903 to interact with the server 905 through the network 904 to receive or send messages and the like. Various communication client applications may be installed on the terminal devices 901 , 902 and 903 , such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only examples).

终端设备901、902、903可以是具有显示屏并且支持网页浏览的各种电子设备,包括但不限于智能手机、平板电脑、膝上型便携计算机和台式计算机等等。The terminal devices 901, 902, 903 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, and the like.

服务器905可以是提供各种服务的服务器,例如对用户利用终端设备901、902、903所浏览的购物类网站提供支持的后台管理服务器(仅为示例)。后台管理服务器可以对接收到的产品信息查询请求等数据进行分析等处理,并将处理结果(例如目标推送信息、产品信息--仅为示例)反馈给终端设备。The server 905 may be a server that provides various services, such as a background management server that supports shopping websites browsed by the terminal devices 901 , 902 , and 903 (just an example). The background management server can analyze and process the received product information query request and other data, and feed back the processing results (such as target push information, product information—just an example) to the terminal device.

需要说明的是,本发明实施例所提供的重启数据库的方法一般由服务器905执行,相应地,重启数据库的装置一般设置于服务器905中。It should be noted that the method for restarting the database provided by the embodiment of the present invention is generally executed by the server 905 , and accordingly, the apparatus for restarting the database is generally set in the server 905 .

应该理解,图9中的终端设备、网络和服务器的数目仅仅是示意性的。根据实现需要,可以具有任意数目的终端设备、网络和服务器。It should be understood that the numbers of terminal devices, networks and servers in FIG. 9 are only illustrative. There can be any number of terminal devices, networks and servers according to implementation needs.

下面参考图10,其示出了适于用来实现本发明实施例的终端设备的计算机系统1000的结构示意图。图10示出的终端设备仅仅是一个示例,不应对本发明实施例的功能和使用范围带来任何限制。Referring to FIG. 10 below, it shows a schematic structural diagram of a computer system 1000 suitable for implementing a terminal device according to an embodiment of the present invention. The terminal device shown in FIG. 10 is only an example, and should not impose any limitations on the functions and scope of use of the embodiments of the present invention.

如图10所示,计算机系统1000包括中央处理单元(CPU)1001,其可以根据存储在只读存储器(ROM)1002中的程序或者从存储部分1008加载到随机访问存储器(RAM)1003中的程序而执行各种适当的动作和处理。在RAM 1003中,还存储有系统1000操作所需的各种程序和数据。CPU 1001、ROM 1002以及RAM 1003通过总线1004彼此相连。输入/输出(I/O)接口1005也连接至总线1004。As shown in FIG. 10, a computer system 1000 includes a central processing unit (CPU) 1001, which can be loaded into a random access memory (RAM) 1003 according to a program stored in a read only memory (ROM) 1002 or a program from a storage section 1008 Instead, various appropriate actions and processes are performed. In the RAM 1003, various programs and data necessary for the operation of the system 1000 are also stored. The CPU 1001 , the ROM 1002 , and the RAM 1003 are connected to each other through a bus 1004 . An input/output (I/O) interface 1005 is also connected to the bus 1004 .

以下部件连接至I/O接口1005:包括键盘、鼠标等的输入部分1006;包括诸如阴极射线管(CRT)、液晶显示器(LCD)等以及扬声器等的输出部分1007;包括硬盘等的存储部分1008;以及包括诸如LAN卡、调制解调器等的网络接口卡的通信部分1009。通信部分1009经由诸如因特网的网络执行通信处理。驱动器1010也根据需要连接至I/O接口1005。可拆卸介质1011,诸如磁盘、光盘、磁光盘、半导体存储器等等,根据需要安装在驱动器1010上,以便于从其上读出的计算机程序根据需要被安装入存储部分1008。The following components are connected to the I/O interface 1005: an input section 1006 including a keyboard, a mouse, etc.; an output section 1007 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 1008 including a hard disk, etc. ; and a communication section 1009 including a network interface card such as a LAN card, a modem, and the like. The communication section 1009 performs communication processing via a network such as the Internet. A drive 1010 is also connected to the I/O interface 1005 as needed. A removable medium 1011, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is mounted on the drive 1010 as needed so that a computer program read therefrom is installed into the storage section 1008 as needed.

特别地,根据本发明公开的实施例,上文参考流程图描述的过程可以被实现为计算机软件程序。例如,本发明公开的实施例包括一种计算机程序产品,其包括承载在计算机可读介质上的计算机程序,该计算机程序包含用于执行流程图所示的方法的程序代码。在这样的实施例中,该计算机程序可以通过通信部分1009从网络上被下载和安装,和/或从可拆卸介质1011被安装。在该计算机程序被中央处理单元(CPU)1001执行时,执行本发明的系统中限定的上述功能。In particular, the processes described above with reference to the flowcharts may be implemented as computer software programs in accordance with the disclosed embodiments of the present invention. For example, embodiments disclosed herein include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the method illustrated in the flowchart. In such an embodiment, the computer program may be downloaded and installed from the network via the communication portion 1009, and/or installed from the removable medium 1011. When the computer program is executed by the central processing unit (CPU) 1001, the above-described functions defined in the system of the present invention are executed.

需要说明的是,本发明所示的计算机可读介质可以是计算机可读信号介质或者计算机可读存储介质或者是上述两者的任意组合。计算机可读存储介质例如可以是——但不限于——电、磁、光、电磁、红外线、或半导体的系统、装置或器件,或者任意以上的组合。计算机可读存储介质的更具体的例子可以包括但不限于:具有一个或多个导线的电连接、便携式计算机磁盘、硬盘、随机访问存储器(RAM)、只读存储器(ROM)、可擦式可编程只读存储器(EPROM或闪存)、光纤、便携式紧凑磁盘只读存储器(CD-ROM)、光存储器件、磁存储器件、或者上述的任意合适的组合。在本发明中,计算机可读存储介质可以是任何包含或存储程序的有形介质,该程序可以被指令执行系统、装置或者器件使用或者与其结合使用。而在本发明中,计算机可读的信号介质可以包括在基带中或者作为载波一部分传播的数据信号,其中承载了计算机可读的程序代码。这种传播的数据信号可以采用多种形式,包括但不限于电磁信号、光信号或上述的任意合适的组合。计算机可读的信号介质还可以是计算机可读存储介质以外的任何计算机可读介质,该计算机可读介质可以发送、传播或者传输用于由指令执行系统、装置或者器件使用或者与其结合使用的程序。计算机可读介质上包含的程序代码可以用任何适当的介质传输,包括但不限于:无线、电线、光缆、RF等等,或者上述的任意合适的组合。It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium, or any combination of the above two. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus or device, or a combination of any of the above. More specific examples of computer readable storage media may include, but are not limited to, electrical connections with one or more wires, portable computer disks, hard disks, random access memory (RAM), read only memory (ROM), erasable Programmable read only memory (EPROM or flash memory), fiber optics, portable compact disk read only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing. In the present invention, a computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In the present invention, however, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code therein. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the foregoing. A computer-readable signal medium can also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport the program for use by or in connection with the instruction execution system, apparatus, or device . Program code embodied on a computer readable medium may be transmitted using any suitable medium including, but not limited to, wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.

附图中的流程图和框图,图示了按照本发明各种实施例的系统、方法和计算机程序产品的可能实现的体系架构、功能和操作。在这点上,流程图或框图中的每个方框可以代表一个模块、程序段、或代码的一部分,上述模块、程序段、或代码的一部分包含一个或多个用于实现规定的逻辑功能的可执行指令。也应当注意,在有些作为替换的实现中,方框中所标注的功能也可以以不同于附图中所标注的顺序发生。例如,两个接连地表示的方框实际上可以基本并行地执行,它们有时也可以按相反的顺序执行,这依所涉及的功能而定。也要注意的是,框图或流程图中的每个方框、以及框图或流程图中的方框的组合,可以用执行规定的功能或操作的专用的基于硬件的系统来实现,或者可以用专用硬件与计算机指令的组合来实现。The flowchart and block diagrams in the Figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code that contains one or more logical functions for implementing the specified functions executable instructions. It should also be noted that, in some alternative implementations, the functions noted in the blocks may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It is also noted that each block of the block diagrams or flowchart illustrations, and combinations of blocks in the block diagrams or flowchart illustrations, can be implemented in special purpose hardware-based systems that perform the specified functions or operations, or can be implemented using A combination of dedicated hardware and computer instructions is implemented.

描述于本发明实施例中所涉及到的模块可以通过软件的方式实现,也可以通过硬件的方式来实现。所描述的模块也可以设置在处理器中,例如,可以描述为:一种处理器包括响应模块、转移模块、切换模块和重启模块。其中,这些模块的名称在某种情况下并不构成对该模块本身的限定,例如,响应模块还可以被描述为“用于响应于远程过程调用请求,停止并重启数据库备库”。The modules involved in the embodiments of the present invention may be implemented in a software manner, and may also be implemented in a hardware manner. The described modules can also be provided in the processor, for example, it can be described as: a processor includes a response module, a transfer module, a switch module and a restart module. Among them, the names of these modules do not constitute a limitation of the module itself under certain circumstances. For example, the response module can also be described as "used to stop and restart the database standby database in response to a remote procedure call request".

作为另一方面,本发明还提供了一种计算机可读介质,该计算机可读介质可以是上述实施例中描述的设备中所包含的;也可以是单独存在,而未装配入该设备中。上述计算机可读介质承载有一个或者多个程序,当上述一个或者多个程序被一个该设备执行时,使得该设备包括:As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiments; or may exist alone without being assembled into the device. The above-mentioned computer-readable medium carries one or more programs, and when the above-mentioned one or more programs are executed by a device, the device includes:

响应于远程过程调用请求,停止并重启数据库备库;In response to a remote procedure call request, stop and restart the database standby database;

在数据库主库和所述数据库备库中数据一致的情况下,将数据请求从所述数据库主库转移到所述数据库备库;When the data in the main database and the standby database are consistent, transfer the data request from the main database to the standby database;

将所述数据库主库切换为数据库新备库,以及将所述数据库备库切换为数据库新主库;Switching the database main database to a new database standby database, and switching the database standby database to a new database main database;

重启所述数据库新备库。Restart the new standby database of the database.

根据本发明实施例的技术方案,响应于远程过程调用请求,停止并重启数据库备库;在数据库主库和所述数据库备库中数据一致的情况下,将数据请求从所述数据库主库转移到所述数据库备库;将所述数据库主库切换为数据库新备库,以及将所述数据库备库切换为数据库新主库;重启所述数据库新备库。在满足数据库主库与数据库备库数据一致的情况下,交换数据库主库和数据库备库,从而减少重启数据库的占用时间,继而能够数据库缩短不可用时长。According to the technical solution of the embodiment of the present invention, in response to a remote procedure call request, stop and restart the database standby database; when the data in the database main database and the database standby database are consistent, transfer the data request from the database main database to the database standby database; switching the database main database to a new database standby database, and switching the database standby database to a new database main database; restarting the new database standby database. Under the condition that the data of the main database database and the database standby database are consistent, the main database database and the database standby database are exchanged, thereby reducing the occupied time of restarting the database, and then shortening the unavailable time of the database.

上述具体实施方式,并不构成对本发明保护范围的限制。本领域技术人员应该明白的是,取决于设计要求和其他因素,可以发生各种各样的修改、组合、子组合和替代。任何在本发明的精神和原则之内所作的修改、等同替换和改进等,均应包含在本发明保护范围之内。The above-mentioned specific embodiments do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modifications, equivalent replacements and improvements made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.

Claims (10)

1. A method of restarting a database, comprising:
stopping and restarting the database backup in response to the remote procedure call request;
under the condition that the data in the database main library and the data in the database standby library are consistent, transferring the data request from the database main library to the database standby library;
switching the database main library into a new database standby library and switching the database standby library into a new database main library;
and restarting the new database.
2. The method for restarting the database according to claim 1, wherein the data in the database master library and the database backup library are consistent, comprising:
accelerating the writing speed of the database standby library;
setting the database master library as read-only when the delay time of the database master library and the database standby library is less than or equal to a preset delay threshold;
and determining that the data in the database main library and the data in the database standby library are consistent based on the site information of the database main library and the site information of the database standby library.
3. The method of restarting a database according to claim 1 wherein said transferring a data request from said database master library to said database backup library comprises:
and in the load balancing, deleting the IP of the database main library, and configuring the IP of the database standby library into the load balancing so as to transfer the data request from the database main library to the database standby library.
4. The method for restarting the database according to claim 1, wherein said switching the database master library to the database backup library comprises:
cleaning the synchronous information in the database standby database;
connecting the database master library, and adding replication information for the database master library to switch the database master library into a new database standby library;
the switching the database standby database into a new database main database comprises the following steps:
and opening the read-only of the database standby library, resetting a disk write strategy, and switching the database standby library into a new database main library.
5. The method of restarting a database according to claim 1, wherein before stopping and restarting the database library in response to a remote procedure call request, further comprising:
and the master-slave delay of the database master library and the database slave library is less than a preset restart threshold value.
6. The method of restarting a database according to claim 1, wherein the method further comprises:
and if the master-slave delay of the database master library and the database slave library is greater than or equal to a preset restart threshold, forcibly restarting the database master library and the database slave library.
7. The method of restarting a database according to claim 1, wherein before switching the database master library to a database new backup library and switching the database backup library to a database new master library, further comprising:
and supporting delayed switching, and detecting that the current time is consistent with the specified switching time.
8. An apparatus for restarting a database, comprising:
the response module is used for responding to the remote procedure call request, and stopping and restarting the database standby library;
the transfer module is used for transferring the data request from the database main library to the database standby library under the condition that the data in the database main library and the data in the database standby library are consistent;
the switching module is used for switching the database main library into a database standby library and switching the database standby library into a database new main library;
and the restarting module is used for restarting the new standby database of the database.
9. An electronic device that reboots a database, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-7.
10. A computer-readable medium, on which a computer program is stored which, when being executed by a processor, carries out the method according to any one of claims 1-7.
CN202210542893.7A 2022-05-18 2022-05-18 Method, apparatus, device and computer readable medium for restarting database Active CN114925052B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210542893.7A CN114925052B (en) 2022-05-18 2022-05-18 Method, apparatus, device and computer readable medium for restarting database

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210542893.7A CN114925052B (en) 2022-05-18 2022-05-18 Method, apparatus, device and computer readable medium for restarting database

Publications (2)

Publication Number Publication Date
CN114925052A true CN114925052A (en) 2022-08-19
CN114925052B CN114925052B (en) 2025-08-19

Family

ID=82807993

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210542893.7A Active CN114925052B (en) 2022-05-18 2022-05-18 Method, apparatus, device and computer readable medium for restarting database

Country Status (1)

Country Link
CN (1) CN114925052B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116414916A (en) * 2023-04-03 2023-07-11 上海中通吉网络技术有限公司 Database high-availability master-slave switching method, system, storage medium and equipment
CN120277058A (en) * 2025-06-09 2025-07-08 阿里云计算有限公司 Main and standby database switching method of cloud database, cloud database and computing device

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105159795A (en) * 2015-08-21 2015-12-16 小米科技有限责任公司 Data synchronization method, apparatus and system
CN106570021A (en) * 2015-10-10 2017-04-19 阿里巴巴集团控股有限公司 Database connection establishment method and device
US20180081910A1 (en) * 2016-09-22 2018-03-22 Bank Of America Corporation Database Shutdown and Restart Stability Optimizer
US20180239677A1 (en) * 2017-02-23 2018-08-23 Salesforce.Com, Inc. Automated self-healing database system and method for implementing the same
US20200097556A1 (en) * 2018-09-24 2020-03-26 Salesforce.Com, Inc. Automated self-scaling database system and method for implementing the same
CN111125060A (en) * 2019-12-17 2020-05-08 中国联合网络通信集团有限公司 Database management method, system, device and storage medium
CN111966520A (en) * 2020-08-10 2020-11-20 上海中通吉网络技术有限公司 Database high availability switching method, device and system
CN112000745A (en) * 2020-09-03 2020-11-27 中国建设银行股份有限公司 Database high-availability method and device

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105159795A (en) * 2015-08-21 2015-12-16 小米科技有限责任公司 Data synchronization method, apparatus and system
CN106570021A (en) * 2015-10-10 2017-04-19 阿里巴巴集团控股有限公司 Database connection establishment method and device
US20180081910A1 (en) * 2016-09-22 2018-03-22 Bank Of America Corporation Database Shutdown and Restart Stability Optimizer
US20180239677A1 (en) * 2017-02-23 2018-08-23 Salesforce.Com, Inc. Automated self-healing database system and method for implementing the same
US20200097556A1 (en) * 2018-09-24 2020-03-26 Salesforce.Com, Inc. Automated self-scaling database system and method for implementing the same
CN111125060A (en) * 2019-12-17 2020-05-08 中国联合网络通信集团有限公司 Database management method, system, device and storage medium
CN111966520A (en) * 2020-08-10 2020-11-20 上海中通吉网络技术有限公司 Database high availability switching method, device and system
CN112000745A (en) * 2020-09-03 2020-11-27 中国建设银行股份有限公司 Database high-availability method and device

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116414916A (en) * 2023-04-03 2023-07-11 上海中通吉网络技术有限公司 Database high-availability master-slave switching method, system, storage medium and equipment
CN120277058A (en) * 2025-06-09 2025-07-08 阿里云计算有限公司 Main and standby database switching method of cloud database, cloud database and computing device
CN120277058B (en) * 2025-06-09 2025-08-29 阿里云计算有限公司 Main and standby database switching method of cloud database, cloud database and computing device

Also Published As

Publication number Publication date
CN114925052B (en) 2025-08-19

Similar Documents

Publication Publication Date Title
US10735509B2 (en) Systems and methods for synchronizing microservice data stores
US20190235979A1 (en) Systems and methods for performing computing cluster node switchover
US20230305936A1 (en) Methods and systems for a non-disruptive automatic unplanned failover from a primary copy of data at a primary storage system to a mirror copy of the data at a cross-site secondary storage system
CN106716378B (en) Secure data access after storage failure
US9582532B2 (en) Management and synchronization of batch workloads with active/active sites OLTP workloads
US20230385244A1 (en) Facilitating immediate performance of volume resynchronization with the use of passive cache entries
CN108352995B (en) A kind of SMB service fault processing method and storage device
US12158824B2 (en) Methods and systems to improve input/output (I/O) resumption time by batching multiple non-conflicting operations during a non-disruptive automatic unplanned failover from a primary copy of data at a primary storage system to a mirror copy of the data at a cross-site secondary storage system
CN114925052B (en) Method, apparatus, device and computer readable medium for restarting database
WO2016107443A1 (en) Snapshot processing method and related device
AU2014321418A1 (en) Email webclient notification queuing
US20160328460A1 (en) Idling individually specified objects during data replication
CN112860505A (en) Method and device for regulating and controlling distributed clusters
CN118708645A (en) Database access method, device and computer readable storage medium
CN115878269A (en) Cluster migration method, related device and storage medium
CN118673078A (en) A method for synchronizing a logical replication slot and a related device
CN116560904A (en) NAS data backup disaster recovery method, system, terminal and storage medium
CN110162326A (en) The method of firmware upgrade and system comprising hard disk
CN111770176A (en) Traffic scheduling method and device
CN119557373A (en) Data storage method, device, system and storage medium
US8621260B1 (en) Site-level sub-cluster dependencies
CN107818027B (en) Method and device for switching main name node and standby name node and distributed system
CN117785059A (en) Database log real-time management method, system, equipment and storage medium
CN113761075B (en) Method, device, apparatus and computer-readable medium for switching database
CN115914375A (en) Disaster recovery processing method and device for distributed message platform

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
TA01 Transfer of patent application right
TA01 Transfer of patent application right

Effective date of registration: 20250813

Address after: 710076 Shaanxi Province, Xi'an City, High-tech Development Zone, Tangu 8th Road, No. 156, Xi'an Software Park R&D Base Phase II, Building C2, Room 1302

Applicant after: Xi'an Tongxing Hengyao Information Technology Co.,Ltd.

Country or region after: China

Address before: 100176 Beijing Economic and Technological Development Zone No. 18 Courtyard, Kechuang 11th Street, 6th Floor 601

Applicant before: Jingdong Technology Information Technology Co.,Ltd.

Country or region before: China