A method and apparatus for latency configuration of a database cluster
By monitoring the primary/standby data center switchover in the database cluster and setting a delayed synchronization, the problem of long database recovery time was solved, achieving fast and reliable data recovery and business continuity assurance.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- NETSUNION CLEARING CORP
- Filing Date
- 2021-11-26
- Publication Date
- 2026-06-19
Smart Images

Figure CN116185702B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and more specifically to a delay configuration method and apparatus for database clusters. Background Technology
[0002] Databases have high availability requirements throughout the year, and database recovery is the guarantee of rapid recovery when the database is abnormal. In order to ensure business continuity, data needs to be recovered quickly. Existing database recovery technology uses real-time replication to copy data between the primary database and the backup database. Once the data in the primary database is abnormal, the data in the backup database is also abnormal. It is necessary to restore the data to the point before the failure point using the previous backup files, which results in a long backup recovery time and may affect business continuity. Summary of the Invention
[0003] In view of this, embodiments of the present invention provide a delay configuration method and apparatus for database clusters, which solves the problem that existing database recovery technologies have long recovery backup times, affecting business continuity.
[0004] To achieve the above objectives, the present invention provides the following technical solution:
[0005] In a first aspect, embodiments of the present invention provide a delay configuration method for a database cluster, wherein each database in the database cluster is deployed in multiple data centers, the multiple data centers including a primary data center and a backup data center, the method comprising: upon detecting that the primary data center has been switched to a backup data center, and / or the backup data center has been switched to the primary data center, marking the data center where the switch occurred; determining the current backup data center based on the marking result; determining whether the synchronization parameter of the temporary backup database in the current backup data center is delayed synchronization; if the synchronization parameter of the temporary backup database is not delayed synchronization, then setting the synchronization parameter of the temporary backup database to delayed synchronization.
[0006] In one embodiment, marking the data center that has been switched over includes: modifying the data center identifier of the data center that has been switched over in the primary / backup information table of the database cluster; determining the current backup data center based on the marking result includes: searching out all data centers with the data center identifier set to backup identifier from the primary / backup information table as the current backup data centers.
[0007] In one embodiment, determining whether the synchronization parameters of the temporary backup database in the current backup data center are delayed synchronization includes: finding the IP address of the temporary backup database in the current backup data center from the primary / backup information table; establishing connections with each temporary backup database based on its IP address; obtaining the synchronization parameters in the corresponding temporary backup database based on the connection; and determining whether the parameter value of the synchronization parameter is 0. If the parameter value of the synchronization parameter is not 0, then the synchronization parameters of the corresponding temporary backup database are determined to be delayed synchronization; otherwise, they are real-time synchronization.
[0008] In one embodiment, the delay configuration method for a database cluster provided by the present invention further includes: if the parameter value of the synchronization parameter is not 0, determining whether the parameter value of the synchronization parameter is a preset value; if the parameter value of the synchronization parameter is not a preset value, determining that the delay synchronization of the temporary backup database does not meet the preset requirements, and modifying the parameter value of the synchronization parameter to the preset value.
[0009] In one embodiment, the delay configuration method for a database cluster provided by the present invention further includes: finding the data center with the data center identifier as the primary identifier from the primary / standby information table and designating it as the current primary data center; and setting the synchronization parameters of the temporary standby database corresponding to the current primary data center to real-time synchronization.
[0010] In one embodiment, the monitoring is implemented by: obtaining the arbitration configuration file of the data service using the database cluster; and using the arbitration configuration file to determine whether the main data center has been switched to the backup data center, and / or whether the backup data center has been switched to the main data center.
[0011] In one embodiment, the monitoring is implemented as follows: obtaining the read / write status records of the main databases in each data center; if the read / write status records show that the permissions of a main database have been changed to writable, then it is determined that the data center where the main database is located has been switched from a backup data center to a main data center; if the read / write status records show that the permissions of a main database have been changed to non-writable, then it is determined that the data center where the main database is located has been switched from a main data center to a backup data center.
[0012] Secondly, embodiments of the present invention provide a delay configuration device for a database cluster, comprising: a marking module, used to mark the data center that has been switched when the main data center is detected to be switched to a backup data center, and / or the backup data center is switched to the main data center; a determining module, used to determine the current backup data center based on the marking result; a judging module, used to judge whether the synchronization parameter of the temporary backup database in the current backup data center is delayed synchronization; and a setting module, used to set the synchronization parameter of the temporary backup database to delayed synchronization if the synchronization parameter of the temporary backup database is not delayed synchronization.
[0013] In one embodiment, the marking module includes: a modification submodule, used to modify the data center identifier of the data center that has undergone a switchover in the primary / backup information table of the database cluster; the determining module includes: a search submodule, used to search for all data centers with the data center identifier set to the backup identifier in the primary / backup information table as the current backup data centers.
[0014] In one embodiment, the judgment module further includes: an address lookup submodule, used to look up the IP address of the temporary backup database in the current backup computer room from the primary / backup information table; and a synchronization type judgment submodule, used to establish a connection with each temporary backup database based on the IP address of each temporary backup database, obtain the synchronization parameters in the corresponding temporary backup database based on the connection, and determine whether the parameter value of the synchronization parameter is 0; if the parameter value of the synchronization parameter is not 0, then it is determined that the synchronization parameter of the corresponding temporary backup database is delayed synchronization, otherwise it is real-time synchronization; if the parameter value of the synchronization parameter is not 0, then it is determined whether the parameter value of the synchronization parameter is a preset value; if the parameter value of the synchronization parameter is not a preset value, then it is determined that the delayed synchronization of the temporary backup database does not meet the preset requirements, and the parameter value of the synchronization parameter is modified to the preset value.
[0015] In one embodiment, it further includes: an identifier lookup submodule, used to look up the data center with the data center identifier as the main identifier from the primary and backup information table as the current primary data center; and a real-time synchronization submodule, used to set the synchronization parameters of the temporary backup database corresponding to the current primary data center to real-time synchronization.
[0016] In one embodiment, the marking module further includes: a first acquisition submodule, configured to acquire an arbitration configuration file for data services using the database cluster; and a first switching submodule, configured to use the arbitration configuration file to determine whether a main data center has been switched to a backup data center, and / or whether a backup data center has been switched to a main data center.
[0017] In one embodiment, the marking module further includes: a second acquisition submodule, used to acquire read / write status records of the main databases in each data center; and a second switching submodule, used to determine that the data center where the main database is located is switched from a backup data center to a main data center if the read / write status record shows that the permission of a main database has been changed to writable; and to determine that the data center where the main database is located is switched from a main data center to a backup data center if the read / write status record shows that the permission of a main database has been changed to non-writable.
[0018] Thirdly, embodiments of the present invention provide an electronic device, including: at least one processor, and a memory communicatively connected to the at least one processor, wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to cause the at least one processor to perform the delay configuration method for a database cluster according to the first aspect of the present invention.
[0019] Fourthly, embodiments of the present invention provide a computer-readable storage medium storing computer instructions for causing a computer to execute the delay configuration method for a database cluster according to the first aspect of the present invention.
[0020] The above-described technical solutions adopted in the embodiments of this application can achieve the following beneficial effects:
[0021] The delay configuration method and apparatus for database clusters provided by this invention monitors data services and, when a switch occurs between the main data center and the backup data center, sets a delay synchronization for the temporary backup database in the current backup data center. This ensures the reliability and stability of the database service. By utilizing the delay synchronization function of the temporary backup database, it fully guarantees that when data anomalies occur in the production main database, a reliable data source is provided for fast, accurate, and efficient data recovery, thus ensuring business continuity. Attached Figure Description
[0022] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0023] Figure 1 A flowchart illustrating a delay configuration method for a database cluster provided in an embodiment of the present invention;
[0024] Figure 2 A flowchart illustrating a specific example of a delay configuration method for a database cluster provided in an embodiment of the present invention;
[0025] Figure 3 This is a schematic diagram of the architecture for cross-data center synchronization of a database cluster provided in an embodiment of the present invention;
[0026] Figure 4 A module composition diagram of a specific example of a delay configuration device for a database cluster provided in an embodiment of the present invention;
[0027] Figure 5This is a composition diagram of a specific example of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0028] The technical solution of the present invention will now be clearly and completely described with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0029] In the description of this invention, it should be noted that the terms "center," "upper," "lower," "left," "right," "vertical," "horizontal," "inner," and "outer," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are used only for the convenience of describing the invention and for simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on the invention. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.
[0030] In the description of this invention, it should be noted that, unless otherwise explicitly specified and limited, the terms "installation," "connection," and "linking" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; they can also refer to the internal connection of two components; and they can refer to a wireless connection or a wired connection. Those skilled in the art can understand the specific meaning of the above terms in this invention based on the specific circumstances.
[0031] Furthermore, the technical features involved in the different embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.
[0032] Example 1
[0033] Taking the online payment and clearing platform, one of the national-level financial infrastructures, as an example, the annual availability requirement is 99.99%. Real-time business data is stored in a MySQL database, and the platform is required to ensure stable operation 24 / 7. Database recovery is the guarantee for rapid recovery in the event of database anomalies. To ensure business continuity in the event of catastrophic database failures, such as accidental data deletion, table deletion, or accidental modification, rapid data recovery is necessary. In this context, this application utilizes delayed replication technology for a temporary standby database. This ensures that the temporary standby database is not affected by catastrophic operations, allowing for data recovery through the data in the temporary standby database. This provides a fast and secure recovery, making delayed replication of the temporary standby database a crucial technology.
[0034] This invention provides a delay configuration method for database clusters, specifically for a primary-multiple-standby database cluster scenario. Current database architectures typically include standby databases and temporary standby databases, both employing real-time synchronization strategies. For example, in MySQL databases, current primary-standby replication uses lossless real-time replication, meaning that no delay is set for data synchronization between the standby and temporary standby databases. In this case, if the primary database data becomes abnormal, it needs to be restored using previous backup files, and then the data before the failure point needs to be restored based on the binlog (database log file). This approach results in a long backup recovery time, and the binlog recovery operation carries the risk of operational errors, which can impact business data and potentially affect business continuity.
[0035] Therefore, the latency configuration method for a database cluster provided in this embodiment of the invention involves deploying each database in multiple data centers, including a primary data center and a backup data center. Specifically, the latency configuration method for a database cluster in this embodiment is as follows: Figure 1 As shown, it includes the following steps:
[0036] Step S1: If the main data center is switched to the backup data center and / or the backup data center is switched to the main data center, mark the data center that has been switched.
[0037] In this embodiment, real-time monitoring of data services is required. When a switchover between the primary and backup data centers is detected, the data center involved in the switchover is marked. This switchover includes either the primary data center being switched to the backup data center, and / or the backup data center being switched to the primary data center. For example, the primary data center can be identified as M, and the backup data center as S. Monitoring of data services can be performed using existing monitoring methods, such as monitoring the data center status or monitoring data in the corresponding data center information table. The monitoring methods used in this embodiment are merely illustrative; in practical applications, monitoring methods can be configured according to actual needs, and this embodiment is not limited to these methods.
[0038] Step S3: Determine the current backup server room based on the marking results. In this embodiment, the current backup server room is determined by utilizing the marking results after the switchover between the primary server room and the backup server room. Taking the above identifier as an example, the current backup server room is S. It should be noted that this embodiment only uses the above-mentioned backup server room identifier as an example for explanation. In practical applications, other identifiers can be used, as long as they can uniquely distinguish between the primary server room and the backup server room. This embodiment is not limited to this.
[0039] Step S5: Determine whether the synchronization parameters of the temporary backup database in the current backup computer room are for delayed synchronization. This can be done by using the database information tables to determine the information of the temporary backup database, the backup database, and the primary database, and then determining whether its synchronization parameters are for delayed synchronization after identifying the temporary backup database.
[0040] Step S7: If the synchronization parameter of the temporary standby database is not delayed synchronization, then set the synchronization parameter of the temporary standby database to delayed synchronization. In practical applications, a delay value can be preset. If the synchronization parameter of the temporary standby database is not delayed synchronization, the parameter value of the synchronization parameter of the temporary standby database can be directly set to the preset delay value. For example, taking the MySQL database, the preset parameter value of delayed synchronization is 3600 seconds. It can be determined whether the synchronization parameter (SQL_Delay) of the temporary standby database is 3600 seconds. It should be noted that this embodiment is only an example and is not limited thereto.
[0041] The delay configuration method for database clusters provided by this invention monitors data services and, when a switch occurs between the main data center and the backup data center, sets a delay synchronization setting for the temporary backup database in the current backup data center. This ensures the reliability and stability of the database service. By utilizing the delay synchronization function of the temporary backup database, it fully guarantees that when data anomalies occur in the production main database, a reliable data source is provided for fast, accurate, and efficient data recovery, thus ensuring business continuity.
[0042] In one specific embodiment, marking the data center where the switchover occurs includes the following steps:
[0043] Step S11: Modify the data center identifier of the data center that underwent a switch in the primary / standby information table of the database cluster. Each database cluster maintains a primary / standby information table. The data center identifier of the data center that underwent a switch can be modified, and then the changes can be aggregated into the primary / standby information table of the current database cluster. The updates to the primary / standby information table can be performed in real time or on a scheduled basis. The primary / standby information table of the database cluster can then be directly obtained.
[0044] In this embodiment, determining the current backup computer room based on the marking results includes the following steps:
[0045] Step S31: Find all computer rooms with the standby identifier in the primary / standby information table and use them as the current standby computer rooms.
[0046] In this embodiment, all data centers identified as backup are found from the primary / backup information table, for example, S. All current backup data centers are found in the primary / backup information table using S. Then, the temporary backup database in each backup data center is determined. The determination of the temporary backup database, backup database, and primary database in each data center is also done by querying the database status information table.
[0047] In one specific embodiment, determining whether the synchronization parameters of the temporary backup database in the current backup computer room are for delayed synchronization includes the following steps:
[0048] Step S01: Locate the IP address of the temporary backup database in the current backup data center from the primary / backup information table. After determining the current backup data center, find the IP address of the temporary backup database in the primary / backup information table to facilitate subsequent determination of synchronization parameters.
[0049] Step S02: Based on the IP address of each temporary backup database, establish a connection with each temporary backup database, obtain the synchronization parameters in the corresponding temporary backup database based on the connection, and determine whether the parameter value of the synchronization parameter is 0; if the parameter value of the synchronization parameter is not 0, then determine that the synchronization parameter of the corresponding temporary backup database is delayed synchronization, otherwise it is real-time synchronization.
[0050] In this embodiment, a connection is established with the temporary backup database based on its IP address. The connection is established using the IP address. After connecting to the temporary backup database, the synchronization parameter (MASTER_DELAY) is directly obtained from it, and the database connection is configured with a delayed replication parameter value of 3600 (CHANGEMASTER TO MASTER_DELAY = 3600). Then, it is determined whether the synchronization parameter value is 0. If the synchronization parameter value is 0, it is determined that the temporary backup database is in real-time synchronization mode. Specifically, if the synchronization parameter value is 0, it indicates that the temporary backup database is in real-time synchronization mode.
[0051] Step S03: If the value of the synchronization parameter is not 0, determine whether the value of the synchronization parameter is the preset value. Taking the preset parameter value of 3600 set above as an example, determine whether the value of the synchronization parameter is 3600.
[0052] Step S04: If the value of the synchronization parameter is not the preset value, it is determined that the delayed synchronization of the temporary backup database does not meet the preset requirements, and the value of the synchronization parameter is modified to the preset value.
[0053] Specifically, when the synchronization parameter value is a preset value, the synchronization parameter of the temporary backup database is determined to be delayed synchronization. In this embodiment, when the synchronization parameter value is not a preset value, the parameter needs to be set to a preset value to ensure that the synchronization method of the temporary backup database is delayed synchronization.
[0054] In one specific embodiment, such as Figure 2 As shown, the latency configuration method for database clusters provided by this invention further includes the following steps:
[0055] Step S2: Locate the primary data center from the primary / backup information table and designate the data center with the primary identifier as the current primary data center. Specifically, similar to determining the current backup data center in step S3 above, the current primary data center M can be directly determined.
[0056] Step S4: Set the synchronization parameters of the temporary backup database corresponding to the current main data center to real-time synchronization. After obtaining the temporary backup database corresponding to the current main data center, set the synchronization parameters of the temporary backup database corresponding to the current main data center to real-time synchronization. This is because when a switch occurs between the main data center and the backup data center, for example, when there are three data centers, if the main data center fails, it is necessary to switch the first backup data center to the current main data center and switch the original main data center to the backup data center. In this case, the synchronization parameters of the temporary backup database corresponding to the current main data center are set to real-time synchronization.
[0057] In one specific embodiment, the listening is implemented in the following manner:
[0058] Step S12: Obtain the arbitration configuration file for data services using the database cluster. When data services perform business processing operations, they store data information such as the processing object and process in the arbitration configuration file. First, obtain the arbitration configuration file for the data services.
[0059] Step S14: Use the arbitration configuration file to determine whether the primary data center has been switched to the backup data center, and / or whether the backup data center has been switched to the primary data center. Check whether the data service has undergone a switch between the primary and backup data centers by checking the relevant parameters in the configuration file. When the relevant parameters change, it can be determined that the data service has undergone a switch between the primary and backup data centers. The switch result includes: the primary data center has been switched to the backup data center, and / or whether the backup data center has been switched to the primary data center.
[0060] Specifically, in one embodiment, the monitoring implementation further includes the following steps:
[0061] Step S16: Obtain the read / write status records of the main database in each data center.
[0062] When configuring the master databases of all backup data centers to synchronize with the master database of the new main data center, the master databases of the backup data centers will be set to read-only mode, and the master database of the main data center will be set to read-write mode, and the read-write mode will be recorded.
[0063] Step S18: If the read / write status record shows that the permissions of a primary database have been changed to writable, then it is determined that the data center where the primary database is located has been switched from the backup data center to the primary data center; if the read / write status record shows that the permissions of a primary database have been changed to non-writable, then it is determined that the data center where the primary database is located has been switched from the primary data center to the backup data center.
[0064] In practical applications, when the read / write status records show that the read / write status of the primary database has changed, it can be determined that a switchover between the primary and backup data centers has occurred. At the same time, the delay configuration of the backup database in the primary data center is canceled, and the delay replication configuration of the backup database in the backup data center is added.
[0065] Specifically, taking the data center switchover of a data service as an example, which involves switching between three data centers, namely BJ10, SH20, and SZ31, we first look up the role of the primary data center from the primary and backup data center information table. That is, we query the data center marked with M as the primary data center. The primary databases of each data center are also based on normal real-time synchronization of MySQL to achieve cross-data center data consistency. The temporary backup database of the primary data center is not configured with delayed replication. When the primary database of the primary data center is abnormal, when setting up the HA (high availability) component of the backup database and the temporary backup database, there is no need to cancel the delayed replication operation of the temporary backup database, so as to achieve the fastest support for high availability of services.
[0066] In a cross-datacenter synchronization architecture, the temporary backup database in the backup datacenter is configured for delayed synchronization (delayed data replication), such as... Figure 3 As shown, for example, when BJ10 is the main data center, the temporary backup database of the SH20 and SZ31 data centers is configured to be in a delayed synchronization state, and the delay synchronization (synchronization parameter) time is set to 3600 seconds.
[0067] When a temporary backup database is not used for external services, a delayed synchronization strategy is configured. Since the temporary backup database does not carry any business operations, setting a delayed synchronization has no impact on business operations. When the primary server experiences data anomalies, the delayed synchronization strategy can achieve fast and accurate data recovery, providing a high degree of stability and reliability. Furthermore, the data service uses a multi-datacenter deployment architecture with synchronous replication relationships between the datacenters. After a datacenter switch, to ensure uninterrupted primary / backup switching in the primary datacenter, a delayed synchronization strategy for the temporary backup database in the backup datacenter needs to be configured.
[0068] The delay configuration method for database clusters provided by this invention monitors data services and, when a switch occurs between the main data center and the backup data center, sets a delay synchronization setting for the temporary backup database in the current backup data center. This ensures the reliability and stability of the database service. By utilizing the delay synchronization function of the temporary backup database, it fully guarantees that when data anomalies occur in the production main database, a reliable data source is provided for fast, accurate, and efficient data recovery, thus ensuring business continuity.
[0069] Example 2
[0070] This invention provides a delay configuration device for database clusters, such as... Figure 4 As shown, it includes:
[0071] The marking module 1 is used to mark the data center that has been switched when the main data center is detected to be switched to the backup data center, and / or the backup data center is switched to the main data center. This module performs the method described in step S1 above, which will not be repeated here.
[0072] Module 2 is used to determine the current backup computer room based on the marking results; this module performs the method described in step S3 above, which will not be repeated here.
[0073] The judgment module 3 is used to determine whether the synchronization parameters of the temporary backup database in the current backup computer room are delayed synchronization; this module performs the method described in step S5 above, which will not be repeated here.
[0074] Module 4 is configured to set the synchronization parameters of the temporary backup database to delayed synchronization if the synchronization parameters of the temporary backup database are not delayed synchronization. This module performs the method described in step S5 above, which will not be repeated here.
[0075] The delay configuration device for database clusters provided by this invention monitors data services and, when a switch occurs between the main data center and the backup data center, sets a delay synchronization for the temporary backup database in the current backup data center. This ensures the reliability and stability of the database service. By utilizing the delay synchronization function of the temporary backup database, it fully guarantees that when data anomalies occur in the production main database, a reliable data source is provided for fast, accurate, and efficient data recovery, thus ensuring business continuity.
[0076] In one specific embodiment, the marking module 1 includes: a modification submodule, used to modify the data center identifier of the data center that has undergone a switchover in the primary / standby information table of the database cluster; and a determination module, including: a search submodule, used to search for all data centers with the data center identifier set to standby identifier from the primary / standby information table as the current standby data centers.
[0077] In one embodiment, the judgment module 3 further includes: an address lookup submodule, used to look up the IP address of the temporary backup database in the current backup computer room from the primary / backup information table; and a synchronization type judgment submodule, used to establish a connection with each temporary backup database based on the IP address of each temporary backup database, obtain the synchronization parameters in the corresponding temporary backup database based on the connection, and determine whether the parameter value of the synchronization parameter is 0; if the parameter value of the synchronization parameter is not 0, then it is determined that the synchronization parameter of the corresponding temporary backup database is delayed synchronization, otherwise it is real-time synchronization; if the parameter value of the synchronization parameter is not 0, then it is determined whether the parameter value of the synchronization parameter is a preset value; if the parameter value of the synchronization parameter is not a preset value, then it is determined that the delayed synchronization of the temporary backup database does not meet the preset requirements, and the parameter value of the synchronization parameter is modified to the preset value.
[0078] The delay configuration device for database clusters provided in this embodiment further includes: an identifier lookup submodule, used to look up the data center with the data center identifier as the main identifier from the primary and backup information table and use it as the current primary data center; and a real-time synchronization submodule, used to set the synchronization parameters of the temporary backup database corresponding to the current primary data center to real-time synchronization.
[0079] In one embodiment, the marking module 1 described above further includes: a first acquisition submodule, used to acquire the arbitration configuration file for data services using the database cluster; a first switching submodule, used to determine, using the arbitration configuration file, whether a primary data center has been switched to a backup data center, and / or whether a backup data center has been switched to a primary data center. A second acquisition submodule, used to acquire the read / write status records of the primary databases in each data center; a second switching submodule, used to determine, if the read / write status record shows that the permissions of a primary database have changed to writable, that the data center where the primary database is located has been switched from a backup data center to a primary data center; and if the read / write status record shows that the permissions of a primary database have changed to non-writable, that the data center where the primary database is located has been switched from a primary data center to a backup data center.
[0080] The modules described above in this embodiment execute the methods described in the corresponding steps of the above method embodiments, and will not be repeated here.
[0081] It is understood that the above-described delay configuration device for database clusters can implement each step of the delay configuration method for database clusters provided in the foregoing embodiments. The relevant explanations of the delay configuration method for database clusters are applicable to the delay configuration device for database clusters, and will not be repeated here.
[0082] Example 3
[0083] This invention provides an electronic device, such as... Figure 5 As shown, the system includes: at least one processor 401, such as a CPU (Central Processing Unit), at least one communication interface 403, a memory 404, and at least one communication bus 402. The communication bus 402 is used to enable communication between these components. The communication interface 403 may include a display screen or a keyboard; optionally, the communication interface 403 may also include a standard wired interface or a wireless interface. The memory 404 may be high-speed RAM (Random Access Memory) or non-volatile memory, such as at least one disk storage device. Optionally, the memory 404 may also be at least one storage device located remotely from the processor 401. The processor 401 can execute the delay configuration method for a database cluster according to Embodiment 1. The memory 404 stores a set of program code, and the processor 401 calls the program code stored in the memory 404 to execute the delay configuration method for a database cluster according to Embodiment 1.
[0084] The communication bus 402 can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The communication bus 402 can be divided into an address bus, a data bus, and a control bus, etc. For ease of representation, Figure 5 The symbol is represented by only one line, but this does not mean that there is only one bus or one type of bus.
[0085] The memory 404 may include volatile memory, such as random-access memory (RAM); the memory may also include non-volatile memory, such as flash memory, hard disk drive (HDD) or solid-state drive (SSD); the memory 404 may also include a combination of the above types of memory.
[0086] The processor 401 can be a central processing unit (CPU), a network processor (NP), or a combination of CPU and NP.
[0087] The processor 401 may further include a hardware chip. This hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The PLD may be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.
[0088] Optionally, the memory 404 is also used to store program instructions. The processor 401 can invoke the program instructions to implement the delay configuration method for a database cluster as described in Embodiment 1 of this application.
[0089] This invention also provides a computer-readable storage medium storing computer-executable instructions that can execute the delay configuration method for a database cluster described in Embodiment 1. The storage medium can be a magnetic disk, optical disk, read-only memory (ROM), random access memory (RAM), flash memory, hard disk drive (HDD), or solid-state drive (SSD), etc.; the storage medium may also include combinations of the above types of memory.
[0090] Obviously, the above embodiments are merely illustrative examples for clear explanation and are not intended to limit the implementation. Those skilled in the art will recognize that other variations or modifications can be made based on the above description. It is neither necessary nor possible to exhaustively list all possible implementations here. However, obvious variations or modifications derived therefrom are still within the scope of protection of this invention.
Claims
1. A delay configuration method for a database cluster, characterized in that, The databases in the database cluster are deployed in multiple data centers, including a primary data center and a backup data center. The method includes: If the main data center is switched to the backup data center and / or the backup data center is switched to the main data center, the data center that has been switched will be marked. The current backup computer room is determined based on the marking results; Determine whether the synchronization parameters of the temporary backup database in the current backup computer room are for delayed synchronization; If the synchronization parameters of the temporary backup database are not delayed synchronization, then the synchronization parameters of the temporary backup database are set to delayed synchronization. Find the IP address of the temporary backup database in the current backup computer room from the primary and backup information table; Based on the IP address of each temporary backup database, a connection is established with each temporary backup database. Based on the connection, the synchronization parameters in the corresponding temporary backup database are obtained, and it is determined whether the parameter value of the synchronization parameter is 0. If the parameter value of the synchronization parameter is not 0, it is determined that the synchronization parameter of the corresponding temporary backup database is delayed synchronization; otherwise, it is real-time synchronization. If the value of the synchronization parameter is not 0, then determine whether the value of the synchronization parameter is a preset value; If the value of the synchronization parameter is not a preset value, it is determined that the delayed synchronization of the temporary backup database does not meet the preset requirements, and the value of the synchronization parameter is modified to the preset value.
2. The method for latency configuration of a database cluster according to claim 1, wherein, The step of marking the computer room where the switchover occurs includes: In the primary / standby information table of the database cluster, modify the data center identifier for the data center that experienced the switchover; The step of determining the current standby computer room based on the marking results includes: Find all data centers with the "standby" identifier from the primary / standby information table and designate them as the current standby data centers.
3. The method for latency configuration of a database cluster according to claim 2, wherein, Also includes: Find the computer room with the primary identifier from the primary / backup information table and designate it as the current primary computer room; Set the synchronization parameters of the temporary backup database corresponding to the current main data center to real-time synchronization.
4. The method for latency configuration of database cluster according to claim 1, characterized in that, The monitoring is implemented in the following way: Obtain the arbitration configuration file for data services using the database cluster; The arbitration configuration file is used to determine whether a main data center has been switched to a backup data center, and / or whether a backup data center has been switched to a main data center.
5. The method for latency configuration of database cluster according to claim 1, characterized in that, The monitoring is implemented in the following way: Obtain the read / write status records of the main database in each data center; If the read / write status record shows that the permissions of a primary database have been changed to writable, then it is determined that the data center where the primary database is located has been switched from the backup data center to the primary data center; if the read / write status record shows that the permissions of a primary database have been changed to non-writable, then it is determined that the data center where the primary database is located has been switched from the primary data center to the backup data center.
6. A delay configuration device for a database cluster, characterized in that, include: The tagging module is used to tag the data center that has been switched when the main data center is switched to the backup data center and / or the backup data center is switched to the main data center. The determination module is used to determine the current standby computer room based on the marking results; The judgment module is used to determine whether the synchronization parameters of the temporary backup database in the current backup computer room are delayed synchronization; The setting module is used to set the synchronization parameters of the temporary backup database to delayed synchronization if the synchronization parameters of the temporary backup database are not delayed synchronization. The judgment module also includes: an address lookup submodule, used to find the IP address of the temporary backup database in the current backup computer room from the primary and backup information table; The synchronization type determination submodule is used to establish connections with each temporary backup database based on its IP address, retrieve synchronization parameters from the corresponding temporary backup database based on the connection, and determine whether the parameter value is 0. If the parameter value is not 0, the synchronization parameter of the corresponding temporary backup database is determined to be delayed synchronization; otherwise, it is real-time synchronization. If the parameter value is not 0, it is determined whether the parameter value is a preset value. If the parameter value is not a preset value, it is determined that the delayed synchronization of the temporary backup database does not meet the preset requirements, and the parameter value is modified to the preset value.
7. A computer readable storage medium characterized by The computer-readable storage medium stores computer instructions that, when executed by a processor, implement the delay configuration method for a database cluster as described in any one of claims 1-5.
8. An electronic device, comprising: include: A memory and a processor are communicatively connected, the memory storing computer instructions, and the processor executing the computer instructions to perform the delay configuration method for a database cluster as described in any one of claims 1-5.