Method, apparatus, device and computer-readable medium for restarting a database
By stopping and restarting the backup library when the main library and backup library data are consistent in the MySQL database, transferring data requests and switching the library roles, the problem of long-term unavailability of the database is solved, and the efficiency and availability of the database restart process is improved.
Patent Information
- Application Number
- CN202210542893.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-18
- Publication Date
- 2025-08-19
- Estimated Expiration
- 2042-05-18
AI Technical Summary
In the prior art, MySQL database restart scheme often causes the database to be unavailable for a long time, affecting the user experience.
When the data in the database main library and the backup library are consistent, the database backup library is stopped and restarted through a remote procedure call request, transfer the data request to the backup library, switch the main library and backup library roles, and restart the new backup library.
It shortens the unavailability time during the database restart process and improves the availability and user experience of database services.
Smart Images

Figure CN114925052B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method, apparatus, device, and computer-readable medium for restarting a database. Background Art
[0002] MySQL is a relational database management system. Relational databases store data in different tables instead of placing all data in one large warehouse, which increases speed and flexibility. The SQL language used by MySQL is the most commonly used standardized language for accessing databases.
[0003] Currently, the restart solution for MySQL in the cloud database typically deploys the agent service and the MySQL service in a single container. The management system then calls the remote procedure call (RPC) interface exposed by the agent service to restart the primary and standby databases respectively.
[0004] In the process of implementing the present invention, the inventors discovered 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
[0005] In view of this, embodiments of the present invention provide a method, apparatus, device, and computer-readable medium for restarting a database, which can shorten the unavailability period of the database.
[0006] To achieve the above object, according to one aspect of an embodiment of the present invention, a method for restarting a database is provided, comprising:
[0007] In response to remote procedure call requests, stop and restart the database standby database;
[0008] When the data in the database master database and the database standby database are consistent, transferring the data request from the database master database to the database standby database;
[0009] Switching the database master database to the new database standby database, and switching the database standby database to the new database master database;
[0010] Restart the new standby database.
[0011] The data in the primary database and the backup database are consistent, including:
[0012] Accelerate the writing speed of the backup database;
[0013] When the delay time between the primary database and the secondary database is less than or equal to a preset delay threshold, setting the primary database to read-only;
[0014] Based on the location information of the database master and the location information of the database standby, it is determined that the data in the database master and the database standby are consistent.
[0015] Transferring the data request from the primary database to the secondary database includes:
[0016] In the load balancing, the IP address of the primary database is deleted, and the IP address of the secondary database is configured in the load balancing to transfer data requests from the primary database to the secondary database.
[0017] Switching the database master database to the database new standby database includes:
[0018] Cleaning up synchronization information in the standby database;
[0019] Connecting to the database master database and adding replication information to the database master database to switch the database master database to the new database standby database;
[0020] Switching the standby database to the new primary database includes:
[0021] The read-only function of the standby database is enabled, and the disk write policy is reset to switch the standby database to the new primary database.
[0022] Before stopping and restarting the standby database in response to the remote procedure call request, the method further includes:
[0023] The master-slave delay between the database master library and the database slave library is less than a preset restart threshold.
[0024] The method further comprises:
[0025] If the master-slave delay between the database master database and the database slave database is greater than or equal to a preset restart threshold, the database master database and the database slave database are forcibly restarted.
[0026] The method further includes: switching the database master database to the new database standby database, and before switching the database standby database to the new database master database:
[0027] Supports delayed switching and detects whether the current time is consistent with the specified switching time.
[0028] According to a second aspect of an embodiment of the present invention, there is provided an apparatus for restarting a database, comprising:
[0029] A response module is used to stop and restart the database standby database in response to a remote procedure call request;
[0030] a transfer module, configured to transfer a data request from the primary database to the standby database when the data in the primary database and the standby database are consistent;
[0031] A switching module, configured to switch the database master database to the new database standby database, and vice versa;
[0032] The restart module is used to restart the new standby database.
[0033] According to a third aspect of an embodiment of the present invention, there is provided an electronic device for restarting a database, including:
[0034] one or more processors;
[0035] a storage device for storing one or more programs,
[0036] When the one or more programs are executed by the one or more processors, the one or more processors implement the above-described method.
[0037] According to a fourth aspect of an embodiment of the present invention, a computer-readable medium is provided, on which a computer program is stored. When the program is executed by a processor, the method described above is implemented.
[0038] One embodiment of the above invention has the following advantages or beneficial effects: in response to a remote procedure call request, stopping and restarting a standby database; transferring data requests from the master database to the standby database if the data in the master database and the standby database are consistent; switching the master database to a new standby database, and then switching the standby database to the new master database; and restarting the new standby database. When the data in the master database and the standby database are consistent, the master database and the standby database are swapped, thereby reducing the time it takes to restart the database and, in turn, shortening the database's unavailability period.
[0039] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with specific embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] The accompanying drawings are provided for a better understanding of the present invention and are not intended to limit the present invention.
[0041] Figure 1 This is a schematic diagram of the main flow of a method for restarting a database according to an embodiment of the present invention;
[0042] Figure 2 is a schematic diagram of a forced restart of a database according to an embodiment of the present invention;
[0043] Figure 31 is a schematic diagram of a process for determining data consistency between a primary database and a backup database according to an embodiment of the present invention;
[0044] Figure 4 is a schematic diagram of a data transfer request according to an embodiment of the present invention;
[0045] Figure 5 1 is a flow chart of switching a primary database to a new standby database according to an embodiment of the present invention;
[0046] Figure 6 is a schematic diagram of a switching database according to an embodiment of the present invention;
[0047] Figure 7 is a schematic diagram of a process for restarting a database according to an embodiment of the present invention;
[0048] Figure 8 is a schematic diagram of the main structure of an apparatus for restarting a database according to an embodiment of the present invention;
[0049] Figure 9 is an exemplary system architecture diagram in which embodiments of the present invention may be applied;
[0050] Figure 10 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0051] The following description of exemplary embodiments of the present invention is made in conjunction with the accompanying drawings, in which various details of the embodiments of the present invention are included to facilitate understanding. These details should be considered as merely exemplary. Therefore, it should be appreciated by those skilled in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.
[0052] Currently, restarting MySQL databases often results in prolonged database unavailability. For example, a direct restart can cause prolonged service unavailability, lasting an average of more than two minutes each time, resulting in a poor user experience.
[0053] In order to solve the technical problem of the MySQL database being unavailable for a long time, the following technical solution in the embodiment of the present invention can be adopted.
[0054] See also Figure 1 , Figure 1 This is a schematic diagram of the main process of the method for restarting a database according to an embodiment of the present invention. When the data in the primary database and the secondary database are consistent, the primary database and the secondary database are switched. Figure 1 As shown, the specific steps include:
[0055] S101: In response to a remote procedure call request, stop and restart the database standby database.
[0056] In this embodiment of the present invention, the Agent service and MySQL service are deployed in a single container. That is, the primary database container contains the Agent service and the primary database, while the backup database container contains the Agent service and the backup database. The terms "primary database" and "backup database" are relative terms and both belong to the database. The backup database serves as a data backup for the primary database. Users are responsible for controlling the database through the management and control system.
[0057] To restart the database, the management and control system sends an RPC request to invoke the proxy service of the standby database, deactivates the standby database, and then restarts it. For example, restarting the standby database involves forcibly restarting it via an RPC request. Alternatively, if forcibly restarting the standby database via an RPC request fails, Secure Shell (SSH) is used to connect to the standby container and execute remote commands instead of RPC operations.
[0058] See also Figure 2 , Figure 2 2 is a schematic diagram of forcibly restarting a database according to an embodiment of the present invention. Figure 2 In the process, the management and control system controls the database standby database through RPC requests or SSH.
[0059] To restart the standby database, the management and control system sends an RPC request through the proxy service to first stop the standby database (systemctl stop mysqld) and then start the standby database (systemctl start mysqld).
[0060] If the RPC request fails or times out, you can use SSH to connect to the standby container and execute remote commands instead of RPC operations. When using SSH, you can directly kill the database (pkill -9mysqld).
[0061] Understandably, SSH is used only when RPC calls fail. RPC calls rely on a proxy service deployed in the container. If the proxy service fails, it will be unable to be called, and thus, the database standby database cannot be restarted. Therefore, a fallback is implemented: connecting directly to the container using SSH and executing shell commands for database operations.
[0062] S102: When the data in the primary database and the backup database are consistent, the data request is transferred from the primary database to the backup database.
[0063] In this embodiment of the present invention, restarting a database includes restarting both the standby database and the primary database. Restarting the primary database requires ensuring data consistency between the primary and standby databases. If data consistency exists between the primary and standby databases, data requests are transferred from the primary database to the standby database.
[0064] See also Figure 3 , Figure 3 This is a flow chart of determining data consistency between a primary database and a backup database according to an embodiment of the present invention. Specifically, the following steps are included:
[0065] S301. Accelerate the writing speed of the backup database.
[0066] To shorten the time it takes to restart the database, use RPC to request the proxy service of the standby database. The proxy service connects to the standby database and sets a disk write policy to speed up writes to the standby database. For example, set globalinnodb_flush_log_at_trx_commit = 2 and set globalsync_binlog = 0.
[0067] S302: When the delay time between the primary database and the backup database is less than or equal to a preset delay threshold, the primary database is set to read-only.
[0068] Typically, there's a storage delay between the primary and standby databases. If the delay between the primary and standby databases is less than or equal to the preset delay threshold, indicating that the two databases are synchronized, the primary database is set to read-only. Specifically, set global read_only to 'on'. The purpose of setting read-only is to stop writes to the primary database, ensuring that the standby database quickly catches up with the primary.
[0069] For example, if the preset delay threshold is 10 seconds, an RPC request is sent to the proxy service of the database slave. The proxy service connects to the database and executes the command "show slave status" to obtain the delay time.
[0070] S303: Based on the site information of the primary database and the site information of the backup database, determine whether the data in the primary database and the backup database are consistent.
[0071] After setting the master database to read-only, you need to ensure that the data in the master and standby databases are consistent based on the site information of the master database and the site information of the standby database.
[0072] As an example, RPC requests are sent to the proxy services in the primary and backup database containers, respectively. The proxy services connect to the databases and retrieve the master and backup database location information. For example, select@@global.gtid_executed is used to retrieve location information. Location information is used to identify database synchronization data.
[0073] In a specific implementation, if the difference between the site information of the primary database and the site information of the backup database, that is, the site difference is 0, it is determined that the data in the primary database and the backup database are consistent.
[0074] exist Figure 3 In the embodiment of the present invention, on the one hand, the writing speed of the database standby database is accelerated; on the other hand, the database master database is set to read-only to improve the speed of data consistency between the database master database and the database standby database.
[0075] When the data in the primary and standby databases are consistent, data requests are transferred from the primary database to the standby database. That is, the primary database no longer processes data requests, and the standby database becomes responsible for processing them.
[0076] In one embodiment of the present invention, if the data in the primary and standby databases is consistent, data requests can be transferred from the primary database to the standby database. Specifically, the IP address of the primary database is deleted from the load balancing system, and the IP address of the standby database is configured in the load balancing system to transfer data requests from the primary database to the standby database. In this way, the primary database no longer directly provides read and write services.
[0077] Load balancing (LB) involves balancing and distributing the load (work tasks) across multiple operating units, thereby enabling collaborative completion of tasks. Built on existing network structures, load balancing provides a transparent, cost-effective method for expanding the bandwidth of servers and network devices, enhancing network data processing capabilities, increasing throughput, and improving network availability and flexibility.
[0078] See also Figure 4 , Figure 4 FIG. 4 is a schematic diagram of a data transfer request according to an embodiment of the present invention. Figure 4 In this scenario, the primary database interacts with MySQL through an agent; the secondary database interacts with MySQL through an agent. During load balancing, users transfer data requests from the primary database to the secondary database. The primary database does not participate in load balancing, while the secondary database does. The primary and secondary databases implement master-slave synchronization, synchronizing data from the primary database to the secondary database.
[0079] S103: Switch the database master database to the new database standby database, and switch the database standby database to the new database master database.
[0080] If data requests have been transferred from the primary database to the standby database, the standby database now functions as the primary database, and the primary database now functions as the standby database. Therefore, the primary database needs to be switched to the new standby database, and vice versa.
[0081] See also Figure 5 , Figure 5 This is a flow chart of switching a primary database to a new standby database according to an embodiment of the present invention. Specifically, the following steps are included:
[0082] S501: Clear the synchronization information in the standby database.
[0083] Through RPC requests, the proxy service of the standby database clears synchronization information in the standby database. For example, if the synchronization information includes slave information, the following commands can be used to clear it: stop slave; reset slave all.
[0084] S502: Connect to the database master database and add replication information to the database master database to switch the database master database to the new database standby database.
[0085] Through RPC requests, the database master's proxy service adds replication information to the database master, switching the database master to the new standby database. For example, add replication information to the database master using the following method: change master to master_host = 'master_host', master_port = 'master_port', master_auto_position = 1; start slave user = 'replicater' password = 'replicater'.
[0086] exist Figure 5 In the embodiment of the present invention, the database master database is switched to the database new standby database.
[0087] Similarly, switch the standby database to the new primary database: enable read-only access on the standby database and reset the disk write policy. This will switch the standby database to the new primary database. Specifically, use the following commands to enable the new primary database: set global read_only = 'off' . Reset the disk write policy: set global innodb_flush_log_at_trx_commit = 1; set globalsync_binlog = 1 .
[0088] At this point, the database master database is switched to the new database standby database, and the database standby database is switched to the new database master database;
[0089] See also Figure 6 , Figure 6 is a schematic diagram of a handover database according to an embodiment of the present invention. Figure 6 Delete the following master-slave synchronization: that is, delete the master-slave synchronization from the primary database to the standby database. Establish the following master-slave synchronization: that is, establish the master-slave synchronization from the standby database to the primary database.
[0090] S104. Restart the new standby database.
[0091] Since the new standby database has not been restarted, it is necessary to restart the new standby database. Specifically, use RPC request to stop and start the new standby database through the proxy server of the new standby database. Ensure that the new standby database has been restarted. If the RPC request fails or times out, you can also use Figure 2 Force restart in .
[0092] In one embodiment of the present invention, database switching can also support switching time. Specifically, delayed switching is supported, and the system detects whether the current time matches a specified switching time. If the current time matches the specified switching time, the primary database is switched to the new standby database, and vice versa. If the current time does not match the specified switching time, no database switching is required.
[0093] Switching the database based on a specified switchover time is primarily designed to minimize the impact of a restart, resulting in only a few seconds of read-only operation. However, this read-only period is undesirable during peak business hours. Therefore, you can specify a low-peak business period to complete the database switchover. For example, you can set a switchover time based on a low-peak business period.
[0094] During implementation, if the current time on the standby database is inconsistent with the specified switchover time after restarting the standby database, the current task will be suspended and a pending task will be added. The pending task will be checked periodically, supporting delayed switchover. If the current time is consistent with the specified switchover time, the pending task will be executed.
[0095] In one embodiment of the present invention, there are many ways to restart the database. In addition to adopting the technical solutions of S101 to S104, a forced restart may also be directly adopted.
[0096] The method for restarting the database can be determined based on the master-slave delay between the database master and the database slave. Specifically, if the master-slave delay between the database master and the database slave is less than a preset restart threshold, the technical solutions of S101 to S104 are adopted, which facilitates faster data synchronization between the database master and the database slave. If the master-slave delay between the database master and the database slave is greater than or equal to the preset restart threshold, a forced restart is performed as described above.
[0097] In other words, when restarting a database, you don't need to specify a restart method. Instead, an RPC request is sent through the database slave's proxy service. The proxy service connects to the database slave and obtains the delay time. For example, you can execute "show slave status" to obtain the delay time and determine the restart method.
[0098] In the above embodiment, in response to a remote procedure call request, the standby database is stopped and restarted; if the data in the primary database and the standby database are consistent, the data request is transferred from the primary database to the standby database; the primary database is switched to the new standby database, and then the standby database is switched to the new primary database; and the new standby database is restarted. If the data in the primary and standby databases are consistent, the primary and standby databases are swapped, thereby reducing the time it takes to restart the database and, in turn, shortening the database's unavailability period.
[0099] See also Figure 7 , Figure 7 This is a flowchart of restarting a database according to an embodiment of the present invention. Specifically, it includes the following steps:
[0100] S701. Restart the database.
[0101] After receiving the restart instruction, the database is restarted. The restart method is determined based on the master-slave delay. 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.
[0102] S702. Restart the main database.
[0103] Force restart of the database master.
[0104] S703. Restart the standby database.
[0105] Forcefully restart the standby database.
[0106] S704. Restart the standby database.
[0107] Use RPC requests to restart the database standby database through the proxy service.
[0108] S705: Determine whether the current time is consistent with the switching time.
[0109] Determine whether the current time is consistent with the specified switching time. If the current time is inconsistent with the specified switching time, execute S706; if the current time is consistent with the specified switching time, execute S707.
[0110] S706: Suspend the current task.
[0111] To avoid the impact of database switching on business, you need to suspend the current task and then check again whether the current time is consistent with the specified switch time.
[0112] S707: Switch database.
[0113] Switch the database master database to the new database standby database, and switch the database standby database to the new database master database.
[0114] S708. Restart the new standby database.
[0115] After restarting the new standby database, the database is restarted.
[0116] exist Figure 7 In the embodiment, S702 to S703 are the forced restart steps; S704 to S708 are the smooth restart steps. S701 can be used to determine which method to use to restart the database. Of course, forced restart or smooth restart can also be used directly.
[0117] See also Figure 8 , Figure 8 Schematic diagram of the main structure of the device for restarting a database according to an embodiment of the present invention. The device for restarting a database can implement a method for restarting a database, such as Figure 8 As shown, the device for restarting the database specifically includes:
[0118] The response module 801 is used to stop and restart the database standby database in response to the remote procedure call request;
[0119] A transfer module 802 is configured to transfer a data request from the primary database to the standby database when the data in the primary database and the standby database are consistent;
[0120] A switching module 803 is configured to switch the database master database to the new database standby database, and vice versa.
[0121] The restart module 804 is used to restart the new standby database.
[0122] In one embodiment of the present invention, the transfer module 802 is specifically configured to accelerate the writing speed of the standby database;
[0123] When the delay time between the primary database and the secondary database is less than or equal to a preset delay threshold, setting the primary database to read-only;
[0124] Based on the location information of the database master and the location information of the database standby, it is determined that the data in the database master and the database standby are consistent.
[0125] In one embodiment of the present invention, the transfer module 802 is specifically used to delete the IP address of the database master database in the load balancing, and configure the IP address of the database slave database into the load balancing, so as to transfer the data request from the database master database to the database slave database.
[0126] In one embodiment of the present invention, the switching module 803 is specifically configured to clean up synchronization information in the standby database;
[0127] Connecting to the database master database and adding replication information to the database master database to switch the database master database to the new database standby database;
[0128] as well as,
[0129] The read-only function of the standby database is enabled, and the disk write policy is reset to switch the standby database to the new primary database.
[0130] In one embodiment of the present invention, the response module 801 is further configured to detect that the master-slave delay between the database master and the database slave is less than a preset restart threshold.
[0131] In one embodiment of the present invention, the response module 801 is further configured to forcibly restart the database master database and the database slave database if the master-slave delay between the database master database and the database slave database is greater than or equal to a preset restart threshold.
[0132] In one embodiment of the present invention, the switching module 803 is further configured to support delayed switching and detect whether the current time is consistent with the specified switching time.
[0133] Figure 9An exemplary system architecture 900 is shown to which the method for restarting a database or the apparatus for restarting a database according to an embodiment of the present invention may be applied.
[0134] like Figure 9 As shown, system architecture 900 may include terminal devices 901, 902, 903, a network 904, and a server 905. Network 904 is used to provide a medium for communication links between terminal devices 901, 902, 903 and server 905. Network 904 may include various connection types, such as wired or wireless communication links or fiber optic cables.
[0135] Users can use terminal devices 901, 902, and 903 to interact with server 905 via network 904 to receive or send messages, etc. Various communication client applications can be installed on 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 as examples).
[0136] The terminal devices 901 , 902 , and 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, and desktop computers.
[0137] Server 905 may be a server that provides various services, such as a backend management server (for example only) that supports shopping websites browsed by users using terminal devices 901, 902, and 903. The backend management server may analyze and process received data such as product information query requests, and feed back processing results (for example, target push information and product information—for example only) to the terminal device.
[0138] It should be noted that the method for restarting the database provided in the embodiment of the present invention is generally executed by the server 905 , and accordingly, the device for restarting the database is generally provided in the server 905 .
[0139] It should be understood that Figure 9 The number of terminal devices, networks and servers in the embodiment is merely illustrative. Any number of terminal devices, networks and servers may be provided as required.
[0140] Reference below Figure 10 , which shows a schematic structural diagram of a computer system 1000 of a terminal device suitable for implementing an embodiment of the present invention. Figure 10 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0141] like Figure 10As shown, the computer system 1000 includes a central processing unit (CPU) 1001, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1002 or a program loaded from a storage unit 1008 into a random access memory (RAM) 1003. Various programs and data required for the operation of the system 1000 are also stored in the RAM 1003. The CPU 1001, the ROM 1002, and the RAM 1003 are connected to each other via a bus 1004. An input / output (I / O) interface 1005 is also connected to the bus 1004.
[0142] The following components are connected to the I / O interface 1005: an input section 1006 including a keyboard, a mouse, and the like; an output section 1007 including devices such as a cathode ray tube (CRT), a liquid crystal display (LCD), and a speaker; a storage section 1008 including a hard disk; and a communication section 1009 including a network interface card such as a LAN card or a modem. 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, or a semiconductor memory, is installed in the drive 1010 as needed, so that computer programs read therefrom can be installed into the storage section 1008 as needed.
[0143] In particular, according to the embodiments disclosed herein, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, the embodiments disclosed herein include a computer program product comprising a computer program carried on a computer-readable medium, the computer program comprising program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 1009, and / or installed from a removable medium 1011. When the computer program is executed by the central processing unit (CPU) 1001, the above-mentioned functions defined in the system of the present invention are performed.
[0144] It should be noted that the computer-readable medium described in the present invention can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A 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 any combination thereof. More specific examples of computer-readable storage media can include, but are not limited to, an electrical connection having one or more conductors, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present invention, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In the present invention, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. This propagated data signal can take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in conjunction with an 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, or any suitable combination thereof.
[0145] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present invention. In this regard, each box in the flowchart or block diagram can represent a module, program segment, or a part of code, and the above-mentioned module, program segment, or a part of code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0146] The modules described in the embodiments of the present invention may be implemented in software or hardware. The modules described may also be provided within a processor. For example, a processor may be described as comprising a response module, a transfer module, a switching module, and a restart module. In some cases, the names of these modules do not limit the modules themselves. For example, the response module may be described as "for stopping and restarting a standby database in response to a remote procedure call request."
[0147] As another aspect, the present invention further provides a computer-readable medium, which may be included in the device described in the above embodiments, or may exist independently without being incorporated into the device. The computer-readable medium carries one or more programs, and when the one or more programs are executed by the device, the device includes:
[0148] In response to remote procedure call requests, stop and restart the database standby database;
[0149] When the data in the database master database and the database standby database are consistent, transferring the data request from the database master database to the database standby database;
[0150] Switching the database master database to the new database standby database, and switching the database standby database to the new database master database;
[0151] Restart the new standby database.
[0152] According to the technical solution of an embodiment of the present invention, in response to a remote procedure call request, a standby database is stopped and restarted; if the data in the primary database and the standby database are consistent, the data request is transferred from the primary database to the standby database; the primary database is switched to the new standby database, and the standby database is switched to the new primary database; and the new standby database is restarted. If the data in the primary and standby databases are consistent, the primary and standby databases are swapped, thereby reducing the time it takes to restart the database and, in turn, shortening the database's unavailability period.
[0153] The above specific embodiments do not limit the scope of protection of the present invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions may occur depending on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention are intended to be included within the scope of protection of the present invention.
Claims
1. A method for restarting a database, characterized in that: include: If the master-slave delay between the master and slave databases is less than the preset restart threshold, the slave database is stopped and restarted in response to the remote procedure call request. When the data in the database master database and the database standby database are consistent, transferring the data request from the database master database to the database standby database; Switching the database master database to the new database standby database, and switching the database standby database to the new database master database; Restart the new standby database of the database; If the master-slave delay between the database master database and the database slave database is greater than or equal to a preset restart threshold, the database master database and the database slave database are forcibly restarted.
2. The method for restarting a database according to claim 1, characterized in that: The data in the primary database and the backup database are consistent, including: Accelerate the writing speed of the backup database; When the delay time between the primary database and the secondary database is less than or equal to a preset delay threshold, setting the primary database to read-only; Based on the location information of the database master and the location information of the database standby, it is determined that the data in the database master and the database standby are consistent.
3. The method for restarting a database according to claim 1, wherein: Transferring the data request from the primary database to the secondary database includes: In the load balancing, the IP address of the primary database is deleted, and the IP address of the secondary database is configured in the load balancing to transfer data requests from the primary database to the secondary database.
4. The method for restarting a database according to claim 1, wherein: Switching the database master database to the database new standby database includes: Cleaning up synchronization information in the standby database; Connecting to the database master database and adding replication information to the database master database to switch the database master database to the new database standby database; Switching the standby database to the new primary database includes: The read-only function of the standby database is enabled, and the disk write policy is reset to switch the standby database to the new primary database.
5. The method for restarting a database according to claim 1, wherein: The method further includes: switching the database master database to the new database standby database, and before switching the database standby database to the new database master database: Supports delayed switching and detects whether the current time is consistent with the specified switching time.
6. A device for restarting a database, characterized in that: include: A response module is used to stop and restart the standby database in response to a remote procedure call request when the master-slave delay between the master and slave databases is less than a preset restart threshold; Furthermore, 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; a transfer module, configured to transfer a data request from the primary database to the standby database when the data in the primary database and the standby database are consistent; A switching module, configured to switch the database master database to the new database standby database, and vice versa; The restart module is used to restart the new standby database.
7. An electronic device for restarting a database, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 5.
8. A computer-readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Data synchronization method, apparatus and system
CN105159795A
Database management method, system and device and storage medium
CN111125060A
Automated self-healing database system and method for implementing the same
US20180239677A1