Data processing method and system, medium and product

By using heartbeat detection and playback log points in the database cluster to determine the new main database, and sending lock permission change instructions to the external storage device, the low efficiency of high-availability switching, data consistency, and low resource utilization of domestic database clusters are solved. solve the problem and achieve efficient data switching and resource sharing.

CN118708649APending Publication Date: 2024-09-27INDUSTRIAL AND COMMERCIAL BANK OF CHINA

Patent Information

Application Number
CN202410717938.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-04
Publication Date
2024-09-27

AI Technical Summary

Technical Problem

Domestic database clusters have problems such as low switching efficiency in high availability, inability to guarantee the consistency of primary and backup data, performance loss caused by data replication, and low resource utilization.

Method used

By setting up a primary database and multiple standby databases in the database cluster, using heartbeat detection and playback log points to determine the new primary database, and sending lock permission change instructions to external storage devices, data permission switching is achieved and data duplication and avoidance are avoided. Third-party arbitration is involved, and shared storage improves resource utilization.

Benefits of technology

It improves the efficiency of database high-availability switching, ensures the consistency of primary and secondary data, reduces data replication performance loss, improves resource utilization, and avoids split-brain problems in extreme scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118708649A
    Figure CN118708649A
Patent Text Reader

Abstract

The invention provides a data processing method and system, a medium and a product, and relates to the field of financial science and technology. The database cluster comprises a main library and N standby libraries, and N is a positive integer greater than 1; the main library and the standby library are both in communication connection with the external storage device, the main library is used for performing data reading and writing on data of the external storage device, and the standby library is used for performing data reading on the data of the external storage device. The method comprises the steps that a current standby database judges whether a current main database is available or not according to heartbeat detection results of all database nodes; and if the current playback log point location of each standby library is not available, determining a new main library according to the current playback log point location of each standby library, and sending a lock permission change instruction to the external storage device, so that the external storage device completes data permission switching between the current main library and the new main library according to the received lock permission change instruction. According to the method, the high-availability switching efficiency of the database can be improved, the consistency of main and standby data is ensured, the performance loss is reduced, and the resource utilization rate is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of financial technology, and in particular to a data processing method, system, medium and product. Background Art

[0002] With the continuous advancement of banking and financial digitalization and the transformation of domestic information technology, domestic databases are gradually replacing traditional databases and continuously taking over core banking businesses. Therefore, higher requirements are placed on domestic databases in terms of high availability, high performance, easy scalability, cost reduction and efficiency improvement.

[0003] In the prior art, for high availability considerations, domestic database clusters usually adopt an architecture of 1 master database and 2 backup databases, and each master database / backup database is respectively connected to an external storage communication. The master database processes external business requests and synchronizes data updates to the backup database through a log-based method at the database level. The backup database parses and replays the logs and converts them into actual data. The data is synchronized with the master database to ensure that the backup database can take over with high availability when the master database fails. High-availability disaster recovery switching is based on high-availability third-party arbitration. When the master database fails, it is necessary to select the master through third-party arbitration, and select the one with the latest data from the two backup databases as the new master database to continue external services. The master and backup databases each have a unique copy of data (data+log), which is placed in enterprise-level external storage to provide enterprise-level high-availability support for persistent data. However, domestic database clusters also have the following problems: (1) High-availability switching is subject to third-party arbitration, resulting in low switching efficiency, and the consistency of primary and standby data cannot be guaranteed in extremely special scenarios; (2) Database replication and playback processing will cause loss of computing resources and affect the overall performance of the database; (3) Both the primary and standby databases have exclusive storage resources, resulting in low resource utilization.

[0004] Therefore, there is a need for a data processing solution that can improve the efficiency of database high-availability switching, ensure the consistency of primary and standby data, reduce performance loss caused by data replication, and improve resource utilization. Summary of the invention

[0005] The present application provides a data processing method, system, medium and product to solve the technical problems of low efficiency of high-availability switching of existing databases, inability to ensure consistency of primary and standby data, performance loss caused by data replication, and low resource utilization.

[0006] In a first aspect, the present application provides a data processing method, wherein a database cluster includes a main database and N backup databases, where N is a positive integer greater than 1; the main database and the backup database are both connected to an external storage device for communication, the main database is used to read and write data from the external storage device, and the backup database is used to read data from the external storage device; the method is applied to the current backup database, including:

[0007] Based on the heartbeat detection results of each database node, determine whether the current main database is available;

[0008] If it is not available, a new main library is determined based on the current playback log point of each backup library, and a lock permission change instruction is sent to the external storage device, so that the external storage device completes the data permission switching between the current main library and the new main library according to the received lock permission change instruction.

[0009] In a possible implementation manner, judging whether the current main database is available according to the heartbeat detection results of each database node specifically includes:

[0010] Periodically obtain the heartbeat information sent by the current master database and other standby databases;

[0011] Determine the heartbeat detection result of each database node according to the heartbeat information sent by the current master database and other standby databases, and the heartbeat information of the current standby database, wherein the heartbeat detection result includes an abnormal heartbeat or a normal heartbeat;

[0012] When a target database node whose heartbeat detection result is abnormal is detected, determining whether the target database node is a main database;

[0013] If so, the current main database is unavailable;

[0014] If not, the current main database is available, and standby database failure alarm information is generated according to the ID information of the target database node, and the standby database failure alarm information is sent to the monitoring terminal.

[0015] In a possible implementation, determining a new primary database according to the current playback log point of each standby database specifically includes:

[0016] Get the current playback log point in the local cache of each standby database;

[0017] Sort the current playback log points of each standby database in descending order of log sequence numbers;

[0018] The new primary database is determined by sorting the target standby database that is first in the current playback log point.

[0019] In a possible implementation manner, sending the lock permission change instruction to the external storage device specifically includes:

[0020] Determine whether the new primary database is the current standby database;

[0021] If yes, a lock permission change instruction is sent to the external storage device, and a permission maintenance instruction is sent to each other standby database, so that each other standby database ends the master election action and maintains the current database permission;

[0022] If not, a master database switching instruction is sent to the new master database, so that the new master database sends a lock permission change instruction to the external storage device after receiving the master database switching instruction; and a permission maintenance instruction is sent to each other standby database, so that each other standby database ends the master election action and maintains the current database permissions.

[0023] In a second aspect, the present application provides another data processing method, which is applied to an external storage device, wherein the external storage device is communicatively connected to the primary database and the backup database described in the first aspect; the method comprises:

[0024] Receive a lock permission change instruction sent by the new master library, and forcibly release the file lock of the current master library, so as to switch the data read and write permission of the current master library to the external storage device to the data read permission;

[0025] Changing the file lock to the new main library, so as to switch the data read permission of the new main library to the data read and write permission of the external storage device, and sending permission change completion information to the new main library;

[0026] The file lock is used to maintain the authority to read and write data on the external storage device.

[0027] In a third aspect, the present application provides another data processing method, which is applied to a new main database, wherein the new main database is one of the backup databases described in the first aspect and is communicatively connected to the external storage device described in the second aspect; the method comprises:

[0028] After receiving the permission change completion information sent by the external storage device, obtaining the storage log point of the latest record in the external storage device;

[0029] Determine whether the storage log point is consistent with the current playback log point corresponding to the new main library;

[0030] If not, determine the log point difference between the storage log point and the current playback log point corresponding to the new main library, and replay data according to the log point difference to make the storage log point consistent with the current playback log point corresponding to the new main library.

[0031] In a fourth aspect, the present application provides a data processing system, comprising:

[0032] The standby database selection module is used to determine whether the current master database is available based on the heartbeat detection results of each database node; if it is not available, a new master database is determined based on the current playback log point of each standby database, and a lock permission change instruction is sent to the external storage module;

[0033] The external storage module is used to receive the lock permission change instruction, forcibly release the file lock of the current main library, change the file lock to the new main library, and send permission change completion information to the new main library.

[0034] In a fifth aspect, the present application provides another data processing system, including a database cluster and an external storage device, wherein the database cluster includes a main database and N backup databases, where N is a positive integer greater than 1; the main database and the backup database are both communicatively connected to the external storage device, the main database is used to read and write data from the external storage device, and the backup database is used to read data from the external storage device;

[0035] The primary database / standby database includes a first processor and a first memory in communication with the first processor; the first processor executes computer-executable instructions stored in the first memory to implement the method described in the first aspect above, or implements the method described in the third aspect above;

[0036] The external storage device includes a second processor and a second memory communicatively connected to the second processor; the second processor executes computer-executable instructions stored in the second memory to implement the method described in the second aspect above.

[0037] In a sixth aspect, the present application provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement the method described in the first aspect above, or the method described in the second aspect above, or the method described in the third aspect above.

[0038] In a seventh aspect, the present application provides a computer program product, comprising a computer program, which, when executed by a processor, implements the method described in the first aspect above, or implements the method described in the second aspect above, or implements the method described in the third aspect above.

[0039] The data processing method, system, medium and product provided by the present application, the database cluster includes a main library and N backup libraries, N is a positive integer greater than 1; the main library and the backup library are both connected to the external storage device, the main library is used to read and write data of the external storage device, and the backup library is used to read data of the external storage device. The current backup library can determine whether the current main library is available based on the heartbeat detection results of each database node; if it is not available, the new main library is determined according to the current playback log point of each backup library, and a lock permission change instruction is sent to the external storage device, so that the external storage device completes the data permission switching between the current main library and the new main library according to the received lock permission change instruction. In the method of the present application, the main library and the backup library are connected to the same external storage device, and the backup library does not need to copy the data of the main library. The database-level replication is avoided through shared storage, and the performance loss caused by data replication is reduced. In addition, shared storage also reduces resource investment. Each database only needs to set up a shared external storage device. The more backup libraries there are, the more resources are saved, which solves the problem of idle storage resources of the backup library and improves resource utilization. Furthermore, the heartbeat detection results of each database node can be used to determine whether the current master database is available. When the current master database is unavailable, the current backup database can achieve internal high-availability arbitration to select the master database through log playback comparison, without the need for third-party arbitration, thus solving the consumption caused by third-party network communication, reducing switching time, and thus improving switching efficiency. In addition, after determining the new master database, a lock permission change instruction can be sent to the external storage device to switch the data permissions between the current master database and the new master database, avoiding the brain split problem caused by dual masters in extremely special scenarios, and ensuring the consistency and correctness of the master and backup data. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0041] Figure 1 It is a structural schematic diagram of a data processing system in the prior art;

[0042] Figure 2 A system architecture diagram of an embodiment of the present application;

[0043] Figure 3 A flowchart of a data processing method according to an embodiment of the present application;

[0044] Figure 4 A flowchart of a data processing method according to another embodiment of the present application;

[0045] Figure 5 A schematic diagram of the structure of a data processing system according to an embodiment of the present application;

[0046] Figure 6 This is a schematic diagram of the structure of a data processing system according to another embodiment of the present application.

[0047] Figure numerals: 1. Main database; 2. Backup database; 3. External storage device; 4. Third-party arbitration device.

[0048] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION

[0049] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.

[0050] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use, processing, transmission, provision, disclosure and application of the relevant data comply with the relevant laws, regulations and standards of the relevant countries and regions, take necessary confidentiality measures, do not violate public order and good morals, and provide corresponding operation entrances for users to choose to authorize or refuse.

[0051] In addition, this application involves big data analysis of user information (including but not limited to personal biometrics, identity data, consumption data, asset data, electronic terminal operation data, etc.), and the use of artificial intelligence technology for automated decision-making, and a technical solution for making decisions that have a significant impact on personal rights and interests based on the results of automated decision-making. The application provides users with corresponding operation entrances for them to choose to agree or reject the results of automated decision-making; if the user chooses to reject, the expert decision-making process will be entered.

[0052] It should also be noted that the data processing methods, systems, media and products of the present application can be used in the field of financial technology, and can also be used in any field other than the field of financial technology, such as the field of data processing, etc. The application field of the data processing methods, systems, media and products of the present application is not limited.

[0053] The data processing method, system, medium and product of the present application can be applied to scenarios where the database re-selects a master due to a master database failure or network partition. The data processing method, system, medium and product of the present application can be applied to any related scenarios involving database master database switching.

[0054] First, the terms involved in this application are explained:

[0055] Enterprise-class disk drives: Enterprise-class or data center-class disk drives refer to disk drives that can provide continuous service in a data center environment. Enterprise-class disk drives have the ability to operate 24 / 7. Compared with ordinary disk drives, the most important difference between enterprise-class disk drives is reliability, long-term operation, and high MTBF (Mean Time Between Failure).

[0056] SCSI: SCSI is the interface protocol of the hard disk, short for Small Computer System Interface. Compared with ordinary hard disks, hard disks using the SCSI protocol have many advantages: high IO performance, fast hard disk speed, large cache capacity, and low CPU usage. They are mainly used in servers.

[0057] SCSI file lock / reservation mechanism: SCSI lock is the basic mechanism used by multiple hosts to operate disks. In a shared storage environment, multiple service hosts may access the same disk at the same time. If multiple hosts write to the disk at the same time, the disk will not know which data is written first and which data is written later. Therefore, in order to prevent data corruption caused by this situation, the concept of SCSI lock is introduced to prevent the data disk from being double-written and causing brain split.

[0058] Disk array: A disk array (Redundant Arrays of Independent Disks, RAID) is composed of many independent disks, which are combined into a disk group with huge capacity. The performance of the entire disk system is improved by the additive effect of data provided by individual disks; or the high availability of the entire disk system is improved by mirroring between disks.

[0059] High Availability (HA) is an important indicator for measuring system reliability and stability. It aims to reduce downtime and maintain high service availability through system design. High availability is achieved through redundant design, automatic failover, load balancing, etc. Redundant design ensures that when the original system fails, the backup system can quickly take over and maintain service continuity by establishing a backup system; automatic failover technology can automatically identify and transfer services when a failure occurs, further reducing downtime; load balancing technology ensures the overall performance and stability of the system by distributing the load.

[0060] Figure 1 It is a structural diagram of a data processing system in the prior art, such as Figure 1 As shown, the data processing system includes a main database 1 and two standby databases 2, and each main database / standby database is connected to a different external storage device 3, and each main database / standby database is connected to a third-party arbitration device 4. The main database 1 processes external business requests and stores the updated business system data in the corresponding external storage device 3. The main database 1 also synchronously copies the updated business system data to the two standby databases 2 in the form of logs. After receiving the log, the standby database 2 parses and replays the log to convert it into actual data, and stores the actual data in the corresponding external storage device 3 to achieve data synchronization between the main and standby databases. The third-party arbitration device 4 is connected to the main database 1 and the standby database 2 to monitor whether the main database is normal in real time. When the main database 1 is detected to have a fault, the third-party arbitration device 4 detects the standby database 2 and compares the data to select a new main database from the standby database 2 for high-availability switching of the database.

[0061] High-availability disaster recovery switching is based on high-availability third-party arbitration. When the primary database fails, a third-party arbitration is required to select the primary database, and the database with the latest data is selected from the two backup databases as the new primary database to continue external services. The primary and backup databases each have a unique copy of data (data+log), which is placed in enterprise-level external storage, providing enterprise-level high-availability support for persistent data.

[0062] However, domestic database clusters also have the following problems:

[0063] (I) High availability. Mainly restricted by third parties, since most domestic databases are evolved from foreign open source stand-alone databases, and since they are stand-alone data and domestic databases started late, high availability requires third-party arbitration. The high-availability switching solution based on third-party arbitration cannot guarantee the consistency of master and standby data in extremely special scenarios. For example, when the master database is isolated by network partition, the third-party arbitration and the standby database cannot perceive whether the master database is normal, and will re-select the master. However, the master database is still normal at this time and can process data updates. At this time, there will be two masters. The simultaneous data updates of the two masters lead to inconsistent data, which is commonly known as the "brain split" problem in the industry. In terms of high-availability switching time, since the master needs to be selected through third-party arbitration, the third party's database detection, data comparison, and master selection all have remote communication losses, which increases the switching time and increases the impact of failures on business operations.

[0064] (II) High performance: Currently, logical replication based on database logs, database replication and playback processing will cause loss of computing resources. Since database access processing and data high-availability replication share computing resources, the performance efficiency of the database itself in processing access is affected.

[0065] (III) Resource investment. In the current high-availability basic master-slave mode, both the master and the slave databases have exclusive storage resources. However, under normal operation, only the master database processes database business, and the slave database only performs data synchronization. Resources are idle, resulting in low resource utilization.

[0066] Based on this technical problem, the inventive concept of this application is: how to provide a data processing method that can improve the efficiency of high-availability switching of the database, ensure the consistency of primary and standby data, reduce the performance loss caused by data replication, and improve resource utilization.

[0067] Specifically, the database cluster includes a main database and N backup databases, where N is a positive integer greater than 1; both the main database and the backup database are connected to the external storage device, the main database is used to read and write data from the external storage device, and the backup database is used to read data from the external storage device. The current backup database can determine whether the current main database is available based on the heartbeat detection results of each database node; if it is not available, the new main database is determined based on the current playback log point of each backup database, and a lock permission change instruction is sent to the external storage device, so that the external storage device completes the data permission switching between the current main database and the new main database according to the received lock permission change instruction. In the method of the present application, the main database and the backup database are connected to the same external storage device, and the backup database does not need to copy the data of the main database. The database-level replication is avoided through shared storage, reducing the performance loss caused by data replication. In addition, shared storage also reduces resource investment. Each database only needs to set up a shared external storage device. The more backup databases there are, the more resources are saved, which solves the problem of idle storage resources in the backup database and improves resource utilization. Furthermore, the heartbeat detection results of each database node can be used to determine whether the current master database is available. When the current master database is unavailable, the current backup database can achieve internal high-availability arbitration to select the master database through log playback comparison, without the need for third-party arbitration, thus solving the consumption caused by third-party network communication, reducing switching time, and thus improving switching efficiency. In addition, after determining the new master database, a lock permission change instruction can be sent to the external storage device to switch the data permissions between the current master database and the new master database, avoiding the brain split problem caused by dual masters in extremely special scenarios, and ensuring the consistency and correctness of the master and backup data.

[0068] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.

[0069] Figure 2 This is a system architecture diagram of an embodiment of the present application, such as Figure 2As shown, the data processing system of the present application includes a main library 1 and two backup libraries 2, and each main library / backup library is connected to the same external storage device 3 in communication. The main library 1 can read and write data from the external storage device 3, and the backup library 2 can only read data from the external storage device 3. The main library 1 processes external business requests, generates new logs and data and stores them in the local cache. The main library 1 also stores new logs and data in the shared external storage device 3. The backup library 2 reads logs from the external storage device 3, replays the logs in the local cache, and generates new data. High-availability components are provided in both the main library 1 and the backup library 2. The high-availability components can normally receive heartbeat information sent by other database nodes, and send the heartbeat information of this node to other database nodes. The high availability component of the current standby database (one of the standby databases 2) can determine whether the current main database (main database 1) is available based on the heartbeat detection results of each database node; if it is not available, the high availability component of the current standby database determines the new main database based on the current playback log points of each standby database 2, and sends a lock permission change instruction to the external storage device 3; the external storage device 3 receives the lock permission change instruction sent by the new main database, and forcibly releases the file lock of the current main database to switch the data read and write permissions of the current main database to the external storage device 3 to data read permissions; the file lock is changed to the new main database to switch the data read permissions of the new main database to the external storage device 3 to data read and write permissions, and a permission change completion message is sent to the new main database.

[0070] Embodiment 1

[0071] Figure 3 Flow chart of a data processing method according to an embodiment of the present application. Figure 3 As shown, the data processing method may include the following steps:

[0072] S101: The current standby database determines whether the current primary database is available based on the heartbeat detection results of each database node.

[0073] In this embodiment, the database cluster includes a main database and N backup databases, where N is a positive integer greater than 1; the main database and the backup database are both connected to the external storage device for communication, the main database is used to read and write data from the external storage device, and the backup database is used to read data from the external storage device.

[0074] In this embodiment, the current standby database may be any standby database with a healthy heartbeat in the database cluster, and those skilled in the art may flexibly set the current standby database.

[0075] In this embodiment, in order to prevent the problem of split brain under data sharing, it is necessary to ensure that only the primary database can read and write data, and the backup database can only read but not change data. This is achieved through a file lock / reservation mechanism (such as SCSI lock and other technologies). The primary database obtains read and write permissions by applying for a file lock.

[0076] In this embodiment, high-availability components may be provided in both the primary database and the standby database. The high-availability components may normally receive heartbeat information sent by other database nodes and send the heartbeat information of the local node to other database nodes.

[0077] In this embodiment, the external storage device may be an enterprise-level disk drive, or a disk array composed of enterprise-level disk drives.

[0078] In a possible implementation, judging whether the current main database is available according to the heartbeat detection results of each database node in the above step S101 may include:

[0079] S11: Periodically obtain the heartbeat information sent by the current master database and other standby databases.

[0080] S12: Determine the heartbeat detection result of each database node according to the heartbeat information sent by the current master database and other standby databases, and the heartbeat information of the current standby database. The heartbeat detection result includes abnormal heartbeat or normal heartbeat.

[0081] S13: When the heartbeat detection result is detected as a target database node with abnormal heartbeat, it is determined whether the target database node is a master database.

[0082] S14: If yes, the current main database is unavailable.

[0083] S15: If not, the current main database is available, and standby database failure alarm information is generated according to the ID information of the target database node, and the standby database failure alarm information is sent to the monitoring terminal.

[0084] In this embodiment, the high-availability components in each master database / backup database can receive heartbeat information from other nodes outside the current node. The current backup database can periodically obtain the heartbeat information received by the high-availability components of the current master database and other backup databases, and comprehensively determine the heartbeat detection results of each database node by combining the heartbeat information received by the high-availability components of the current backup database.

[0085] For a certain database node, if other nodes do not receive the heartbeat of this node, it can be considered that the heartbeat of this database node is abnormal (database failure or network shard cannot communicate). If other nodes can receive the heartbeat of this node, it can be considered that the heartbeat of this database node is normal.

[0086] For example, a database cluster includes a main database, standby database 1 and standby database 2. The current standby database is standby database 1. The high-availability component of standby database 1 obtains the heartbeat information received by the high-availability components of the main database and standby database 2 respectively, and finds that the heartbeat information sent by the high-availability component of the main database cannot be obtained. The heartbeat information received by the high-availability component of standby database 2 is: it can receive the heartbeat information of standby database 1, but not the heartbeat information of the main database, and the heartbeat information received by the high-availability component of standby database 1 itself is: it can receive the heartbeat information of standby database 2, but not the heartbeat information of the main database. The heartbeat detection result can be comprehensively obtained as follows: the heartbeat of the main database is abnormal, and the heartbeats of standby databases 1 and 2 are normal.

[0087] In this embodiment, if the current master database is available and a backup database has an abnormal heartbeat (database failure or network sharding cannot communicate), it is only necessary to output an alarm message to prompt the monitoring terminal to repair the abnormal backup database without re-selecting the master.

[0088] In this embodiment, the main library / standby library can normally receive the heartbeat information sent by other database nodes, and send the heartbeat information of this node to other database nodes. Therefore, based on the heartbeat information sent by the current main library and other standby libraries, and the heartbeat information of the current standby library, the heartbeat detection results of each database node can be simply and accurately determined, and then whether the current main library is available can be determined. Through such a setting, internal monitoring of the database cluster can be achieved, and there is no need for third-party arbitration to monitor whether the current main library is available, avoiding the brain split problem caused by dual masters in extremely special scenarios (network fragmentation causes the main library to be unable to communicate), while solving the consumption caused by third-party network communication and reducing switching time.

[0089] S102: If it is unavailable, the current standby database determines a new primary database according to the current playback log point of each standby database, and sends a lock authority change instruction to the external storage device.

[0090] In this embodiment, the current playback log point may be the latest log point at which the standby database reads data from an external storage device and plays back the generated data in the cache. The log point may be a log sequence number, which is globally incremented and unique.

[0091] In this embodiment, under normal operation, the primary database processes business and writes logs and data to the cache and then to the external storage (logs are synchronous / data are asynchronous). The backup database reads logs from the storage and replays the generated data in the cache to achieve synchronization between the primary and backup databases in the cache.

[0092] In a possible implementation, determining a new primary database according to the current playback log point of each standby database in the above step S102 may include:

[0093] S21: Obtain the current playback log point in the local cache of each standby database.

[0094] S22: Sort the current playback log points of each standby database in descending order of log sequence numbers.

[0095] S23: Determine the new primary database based on the target standby database that is first sorted according to the current playback log point.

[0096] In this implementation, the target standby database (new primary database) may be the current standby database or may not be the current standby database.

[0097] Exemplarily, the data of standby database 1 is played back to log N (the current playback log point), and the data of standby database 2 is played back to log M. If M>N, standby database 2 is selected as the new primary database and enters the preparation stage.

[0098] In this implementation, because all nodes of the database are shared storage, any node can theoretically take over as the new master database. However, the update and write of database data interact with the local cache, and will first write to the local cache and then write to the disk. If the new master database does not have local cache data or the local cache data is different from the original master database, it is necessary to read the cache from the external storage device before taking over. If the data difference is too large, it will affect the takeover time. Therefore, the principle of selecting a new master is to use the latest data playback (current playback log point) as the new master. Through such a setting, the internal high-availability arbitration selection is realized through log playback comparison, which not only avoids the consumption and interference caused by the third-party arbitration selection, but also selects the standby database with the least data playback (the latest current playback log point) as the new master database, which greatly reduces the database switching takeover time.

[0099] In a possible implementation, sending the lock permission change instruction to the external storage device in the above step S102 may include:

[0100] S31: Determine whether the new primary database is the current standby database.

[0101] S32: If yes, a lock permission change instruction is sent to the external storage device, and a permission maintenance instruction is sent to each other standby database, so that each other standby database ends the master election action and maintains the current database permission.

[0102] S33: If not, a master database switching instruction is sent to the new master database, so that the new master database sends a lock permission change instruction to the external storage device after receiving the master database switching instruction; and a permission maintenance instruction is sent to each other standby database, so that each other standby database ends the master election action and maintains the current database permissions.

[0103] In this embodiment, the lock permission change instruction can enable the external storage device to switch the data read and write permission of the current main library to the data read permission, and switch the data read and write permission of the current main library to the data read permission.

[0104] In this implementation, the new master database may be the current standby database or not, and the data read and write permissions require the new master database to apply to the external storage device. Therefore, it is first necessary to determine whether the new master database is the current standby database. If the new master database is not the current standby database, the current standby database also needs to send a master database switching instruction to the new master database, so that the new master database sends a lock permission change instruction to the external storage device after receiving the master database switching instruction. In addition, the current standby database also needs to send a permission maintenance instruction to each other standby database, so that each other standby database ends the master election action and maintains the current database permissions, thereby ending this master election operation.

[0105] S103: The external storage device receives the lock permission change instruction sent by the new master library, and forcibly releases the file lock of the current master library, so as to switch the data read and write permission of the current master library to the external storage device to the data read permission.

[0106] In this embodiment, the file lock is used to maintain the authority to read and write data on the external storage device.

[0107] In this embodiment, after the external storage device receives the lock permission change instruction sent by the new master library, it can forcibly release the file lock of the current master library to switch the data read and write permission of the current master library to the external storage device to the data read permission. At this time, regardless of whether the original master library is really faulty, the data cannot be updated, avoiding the brain split problem caused by dual masters and ensuring the consistency and correctness of the master and backup data.

[0108] S104: The external storage device changes the file lock to the new main library, so as to switch the data read permission of the new main library to the data read and write permission of the external storage device, and sends permission change completion information to the new main library.

[0109] In this embodiment, when a master-slave switch occurs, the old master database releases the lock and the new master database applies for lock permission; when a high-availability switch is performed, the old master database may fail and cannot issue a lock release command. Therefore, after the database completes re-election of the master, the new master database can issue a command to the external storage device to force the lock to be released from the external storage device, and the new master database reapplies for the lock.

[0110] In this embodiment, the main database and the standby database can be connected to the same external storage device for communication. The standby database does not need to copy the data of the main database. The database-level replication is avoided through shared storage, and the performance loss caused by data replication is reduced. In addition, shared storage also reduces resource investment. Each database only needs to set up a shared external storage device. The more standby databases there are, the more resources are saved, which solves the problem of idle storage resources in the standby database and improves resource utilization. Further, the heartbeat detection results of each database node can be used to determine whether the current main database is available. When the current main database is not available, the current standby database can realize internal high-availability arbitration selection through log playback comparison, without the participation of third-party arbitration, solving the consumption caused by third-party network communication, reducing switching time, and thus improving switching efficiency. In addition, after determining the new main database, a lock permission change instruction can also be sent to the external storage device to switch the data permissions between the current main database and the new main database, avoiding the brain split problem caused by the dual master in extreme special scenarios, and ensuring the consistency and correctness of the main and standby data.

[0111] Embodiment 2

[0112] Figure 4 This is a flow chart of a data processing method according to another embodiment of the present application. Figure 4 As shown, the data processing method may include the following steps:

[0113] S201: The current standby database determines whether the current primary database is available based on the heartbeat detection results of each database node.

[0114] In this embodiment, the database cluster includes a main database and N backup databases, where N is a positive integer greater than 1; the main database and the backup database are both connected to the external storage device for communication, the main database is used to read and write data from the external storage device, and the backup database is used to read data from the external storage device.

[0115] In this embodiment, the current standby database may be any standby database with a healthy heart rate in the database cluster, and those skilled in the art may flexibly set the current standby database.

[0116] In this embodiment, in order to prevent the problem of split brain under data sharing, it is necessary to ensure that only the primary database can read and write data, and the backup database can only read but not change data. This is achieved through a file lock / reservation mechanism (such as SCSI lock and other technologies). The primary database obtains read and write permissions by applying for a file lock.

[0117] In this embodiment, high-availability components may be provided in both the primary database and the standby database. The high-availability components may normally receive heartbeat information sent by other database nodes and send the heartbeat information of the local node to other database nodes.

[0118] In this embodiment, the external storage device may be an enterprise-level disk drive, or a disk array composed of enterprise-level disk drives.

[0119] In this embodiment, the specific implementation of the above step S201 can refer to step S101 in the first embodiment, and will not be described in detail here.

[0120] S202: If it is unavailable, the current standby database determines a new primary database according to the current playback log point of each standby database, and sends a lock authority change instruction to the external storage device.

[0121] In this embodiment, the current playback log point may be the latest log point at which the standby database reads data from an external storage device and plays back the generated data in the cache. The log point may be a log sequence number, which is globally incremented and unique.

[0122] In this embodiment, under normal operation, the primary database processes business and writes logs and data to the cache and then to the external storage (logs are synchronous / data are asynchronous). The backup database reads logs from the storage and replays the generated data in the cache to achieve synchronization between the primary and backup databases in the cache.

[0123] In this embodiment, the specific implementation of the above step S202 can refer to step S102 in the first embodiment, and will not be described in detail here.

[0124] S203: The external storage device receives the lock permission change instruction sent by the new master library, and forcibly releases the file lock of the current master library, so as to switch the data read and write permission of the current master library to the external storage device to the data read permission.

[0125] In this embodiment, the file lock is used to maintain the authority to read and write data on the external storage device.

[0126] In this embodiment, after the external storage device receives the lock permission change instruction sent by the new master library, it can forcibly release the file lock of the current master library to switch the data read and write permission of the current master library to the external storage device to the data read permission. At this time, regardless of whether the original master library is really faulty, the data cannot be updated, avoiding the brain split problem caused by dual masters and ensuring the consistency and correctness of the master and backup data.

[0127] S204: The external storage device changes the file lock to the new main library, so as to switch the data read permission of the new main library to the data read and write permission of the external storage device, and sends permission change completion information to the new main library.

[0128] In this embodiment, when a primary-standby switch occurs, the old primary database releases the lock, and the new primary database applies for lock permission; when a high-availability switch occurs, the old primary database may have failed and been unable to issue a lock release command. Therefore, after the database completes re-election of the primary, the new primary database can issue a command to the external storage device to forcibly release the lock from the external storage device, and the new primary database re-applies for the lock.

[0129] S205: After the new primary database receives the permission change completion information sent by the external storage device, it obtains the storage log position of the latest record in the external storage device.

[0130] In this embodiment, the storage log position of the latest record in the external storage device can be the latest log position written by the original primary database to the external storage device.

[0131] S206: The new primary database determines whether the storage log position is consistent with the current playback log position corresponding to the new primary database.

[0132] In this embodiment, the current playback log position corresponding to the new primary database can be the latest log position that the new primary database reads from the external storage device and replays in the cache to generate data.

[0133] S207: If not, the new primary database determines the log position difference between the storage log position and the current playback log position corresponding to the new primary database, and performs data playback according to the log position difference so that the storage log position is consistent with the current playback log position corresponding to the new primary database.

[0134] In this embodiment, if the storage log position is consistent with the current playback log position corresponding to the new primary database, the new primary database can directly connect to the business system to process new business system data; if the storage log position is inconsistent with the current playback log position corresponding to the new primary database, the new primary database needs to perform data playback according to the log position difference, and then connect to the business system to process new business system data after the storage log position is consistent with the current playback log position corresponding to the new primary database.

[0135] Exemplarily, the current playback log position of the new primary database is LOG M, and the storage log position of the latest record in the external storage device is LOG X. If M = X, it means that the cached data of the new primary database has been consistent with the data on the storage, and the new primary database can directly process the business. If M < X, the new primary database needs to read the log difference from the storage for data playback, and after the playback is completed, it enters the new primary completion stage and then processes the database business.

[0136] In this embodiment, the main database and the standby database can be connected to the same external storage device for communication. The standby database does not need to copy the data of the main database. The database-level replication is avoided through shared storage, and the performance loss caused by data replication is reduced. In addition, shared storage also reduces resource investment. Each database only needs to set up a shared external storage device. The more standby databases there are, the more resources are saved, which solves the problem of idle storage resources in the standby database and improves resource utilization. Further, the heartbeat detection results of each database node can be used to determine whether the current main database is available. When the current main database is not available, the current standby database can realize internal high-availability arbitration selection through log playback comparison, without the participation of third-party arbitration, solving the consumption caused by third-party network communication, reducing switching time, and thus improving switching efficiency. In addition, after determining the new main database, a lock permission change instruction can also be sent to the external storage device to switch the data permissions between the current main database and the new main database, avoiding the brain split problem caused by the dual master in extreme special scenarios, and ensuring the consistency and correctness of the main and standby data. Furthermore, after determining the new master database, it is also necessary to compare the current playback log point of the new master database with the storage log point of the latest record in the external storage device to avoid data updates in the original master database during the master selection phase, so that the storage log point is consistent with the current playback log point corresponding to the new master database, further ensuring the consistency and integrity of the master-slave data.

[0137] The data processing method of the present application is described below with reference to a specific embodiment.

[0138] Embodiment 3

[0139] In a specific embodiment, a bank's data processing system includes a main database, backup database 1, backup database 2 and an external storage device. The main database, backup database 1 and backup database 2 are all connected to the external storage device, and the main database, backup database 1 and backup database 2 are all equipped with high-availability components. The high-availability components can normally receive heartbeat information sent by other database nodes and send the heartbeat information of this node to other database nodes. The main database is connected to the business system to process and back up the business system data. The specific data processing process is as follows:

[0140] In the first step, the current main database processes external business requests and writes updated business system data to the external storage device.

[0141] In the second step, the high-availability component of the current standby database (standby database 1) periodically obtains the heartbeat information sent by the current main database and other standby databases (standby database 2), and determines the heartbeat detection results of each database node based on the heartbeat information sent by the current main database and other standby databases and the heartbeat information of the current standby database.

[0142] In the third step, the high availability component of the current standby database detects the target database node with an abnormal heartbeat detection result, and determines that the target database node is the current master database, and enters the re-election master stage.

[0143] In the fourth step, the high availability component of the current standby database determines that the new master database is standby database 2 according to the current playback log point of each standby database, sends a master database switching instruction to the new master database, and sends a permission maintenance instruction to each other standby database to complete the master election action of each other standby database and maintain the current database permissions.

[0144] Step 5: After receiving the master database switch instruction, the new master database (standby database 2) sends a lock permission change instruction to the external storage device.

[0145] In the sixth step, the external storage device receives the lock permission change instruction sent by the new main library, forcibly releases the file lock of the current main library, and switches the data read and write permission of the current main library to the data read permission of the external storage device; changes the file lock to the new main library, and switches the data read permission of the new main library to the data read and write permission of the external storage device, and sends the permission change completion information to the new main library.

[0146] In the seventh step, after the new main library receives the permission change completion information sent by the external storage device, it obtains the storage log point of the latest record in the external storage device; and determines whether the storage log point is inconsistent with the current playback log point corresponding to the new main library.

[0147] In the eighth step, the new master library determines the log point difference between the storage log point and the current playback log point corresponding to the new master library, and plays back the data according to the log point difference to make the storage log point consistent with the current playback log point corresponding to the new master library.

[0148] Step 9: The new main database connects to the business system to process external business requests.

[0149] Figure 5 FIG. 1 is a schematic diagram of the structure of a data processing system according to an embodiment of the present application. Figure 5 As shown, the data processing system includes: a standby database selection module 51, which is used to determine whether the current main database is available based on the heartbeat detection results of each database node; if it is not available, a new main database is determined based on the current playback log point of each standby database, and a lock permission change instruction is sent to the external storage module; an external storage module 52 is used to receive the lock permission change instruction, forcibly release the file lock of the current main database, change the file lock to the new main database, and send permission change completion information to the new main database. In one embodiment, the description of the specific implementation function of the data processing system can refer to steps S101-S104 in Example 1 and steps S201-S207 in Example 2, which will not be repeated here.

[0150] Figure 6 FIG. 1 is a schematic diagram of the structure of a data processing system according to an embodiment of the present application. Figure 6 As shown, the data processing system includes: a database cluster A and an external storage device 3, the database cluster A includes a main library 1 and N backup libraries 2, N is a positive integer greater than 1; the main library 1 and the backup library 2 are both communicatively connected to the external storage device 3, the main library 1 is used to read and write data from the external storage device 3, and the backup library 2 is used to read data from the external storage device 3.

[0151] The primary database / backup database includes a first processor 101 and a first memory 102 that is communicatively connected to the first processor 101; the first processor 101 executes computer execution instructions stored in the first memory 102 to implement the method of steps S101-S102 in embodiment 1 and steps S201-S202, S205-S207 in embodiment 2.

[0152] The external storage device 3 includes a second processor 201 and a second memory 202 communicatively connected to the second processor 201; the second processor 201 executes the computer execution instructions stored in the second memory 202 to implement the method of steps S103-S104 in embodiment 1 and steps S203-S204 in embodiment 2.

[0153] In the above data processing system, the memory 102 / 202 and the processor 101 / 201 are electrically connected directly or indirectly to realize data transmission or interaction. For example, these elements can be electrically connected to each other through one or more communication buses or signal lines, such as through a bus connection. The memory 102 / 202 stores computer-executable instructions for implementing the data access control method, including at least one software function module that can be stored in the memory 102 / 202 in the form of software or firmware. The processor 101 / 201 executes various functional applications and data processing by running the software programs and modules stored in the memory 102 / 202.

[0154] The memory 102 / 202 may be, but is not limited to, a random access memory (RAM), a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), etc. The memory 102 / 202 is used to store programs, and the processor 101 / 201 executes the programs after receiving the execution instruction. Furthermore, the software programs and modules in the above-mentioned memory 102 / 202 may also include an operating system, which may include various software components and / or drivers for managing system tasks (such as memory management, storage device control, power management, etc.), and may communicate with various hardware or software components to provide an operating environment for other software components.

[0155] The processor 101 / 201 may be an integrated circuit chip having the ability to process signals. The above-mentioned processor 101 / 201 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc. The disclosed methods, steps and logic block diagrams in the embodiments of the present application may be implemented or executed. The general-purpose processor may be a microprocessor or the processor may be any conventional processor, etc.

[0156] An embodiment of the present application further provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement the steps of each method embodiment of the present application.

[0157] An embodiment of the present application further provides a computer program product, including a computer program, which implements the steps of each method embodiment of the present application when executed by a processor.

[0158] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily required by the present application.

[0159] It should be further noted that, although the various steps in the flow chart are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the flow chart may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these sub-steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.

[0160] It should be understood that the above-mentioned device embodiments are only illustrative, and the device of the present application can also be implemented in other ways. For example, the division of units / modules in the above-mentioned embodiments is only a logical function division, and there may be other division methods in actual implementation. For example, multiple units, modules or components can be combined, or can be integrated into another system, or some features can be ignored or not executed.

[0161] In addition, unless otherwise specified, each functional unit / module in each embodiment of the present application may be integrated into one unit / module, each unit / module may exist physically separately, or two or more units / modules may be integrated together. The above-mentioned integrated unit / module may be implemented in the form of hardware or in the form of a software program module.

[0162] In the above embodiments, the description of each embodiment has its own emphasis. For the part not described in detail in a certain embodiment, please refer to the relevant description of other embodiments. The technical features of the above embodiments can be combined arbitrarily. In order to make the description concise, all possible combinations of the technical features in the above embodiments are not described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0163] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the appended claims.

[0164] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.

Claims

1. A data processing method, characterized in that: The database cluster includes a main database and N backup databases, where N is a positive integer greater than 1; the main database and the backup database are both connected to the external storage device for communication, the main database is used to read and write data from the external storage device, and the backup database is used to read data from the external storage device; The method is applied to the current standby database, including: Based on the heartbeat detection results of each database node, determine whether the current main database is available; If it is not available, a new main library is determined based on the current playback log point of each backup library, and a lock permission change instruction is sent to the external storage device, so that the external storage device completes the data permission switching between the current main library and the new main library according to the received lock permission change instruction.

2. The method according to claim 1, characterized in that The determination of whether the current main database is available based on the heartbeat detection results of each database node specifically includes: Periodically obtain the heartbeat information sent by the current master database and other standby databases; Determine the heartbeat detection result of each database node according to the heartbeat information sent by the current master database and other standby databases, and the heartbeat information of the current standby database, wherein the heartbeat detection result includes an abnormal heartbeat or a normal heartbeat; When a target database node whose heartbeat detection result is abnormal is detected, determining whether the target database node is a main database; If so, the current main database is unavailable; If not, the current main database is available, and standby database failure alarm information is generated according to the ID information of the target database node, and the standby database failure alarm information is sent to the monitoring terminal.

3. The method according to claim 2, characterized in that Determining a new master database according to the current playback log point of each standby database specifically includes: Get the current playback log point in the local cache of each standby database; Sort the current playback log points of each standby database in descending order of log sequence numbers; The new primary database is determined by sorting the target standby database that is first in the current playback log point.

4. The method according to claim 3, characterized in that The sending of the lock permission change instruction to the external storage device specifically includes: Determine whether the new primary database is the current standby database; If yes, a lock permission change instruction is sent to the external storage device, and a permission maintenance instruction is sent to each other standby database, so that each other standby database ends the master election action and maintains the current database permission; If not, a master database switching instruction is sent to the new master database, so that the new master database sends a lock permission change instruction to the external storage device after receiving the master database switching instruction; and a permission maintenance instruction is sent to each other standby database, so that each other standby database ends the master election action and maintains the current database permissions.

5. A data processing method, characterized in that: Applied to an external storage device, the external storage device is communicatively connected to the primary database and the backup database according to claim 1; the method comprises: Receive a lock permission change instruction sent by the new master library, and forcibly release the file lock of the current master library, so as to switch the data read and write permission of the current master library to the external storage device to the data read permission; Changing the file lock to the new main library, so as to switch the data read permission of the new main library to the data read and write permission of the external storage device, and sending permission change completion information to the new main library; The file lock is used to maintain the authority to read and write data on the external storage device.

6. A data processing method, characterized in that: Applied to a new main library, the new main library is one of the backup libraries described in claim 1 and is communicatively connected to the external storage device described in claim 5; the method comprises: After receiving the permission change completion information sent by the external storage device, obtaining the storage log point of the latest record in the external storage device; Determine whether the storage log point is consistent with the current playback log point corresponding to the new main library; If not, determine the log point difference between the storage log point and the current playback log point corresponding to the new main library, and replay data according to the log point difference to make the storage log point consistent with the current playback log point corresponding to the new main library.

7. A data processing system, characterized in that: include: The standby database selection module is used to determine whether the current master database is available based on the heartbeat detection results of each database node; If it is unavailable, a new master database is determined based on the current playback log point of each backup database, and a lock permission change instruction is sent to the external storage module; The external storage module is used to receive the lock permission change instruction, forcibly release the file lock of the current main library, change the file lock to the new main library, and send permission change completion information to the new main library.

8. A data processing system, comprising a database cluster and an external storage device, wherein the database cluster comprises a main database and N backup databases, where N is a positive integer greater than 1; the main database and the backup database are both connected to the external storage device for communication, the main database is used to read and write data from the external storage device, and the backup database is used to read data from the external storage device; The primary database / standby database includes a first processor and a first memory in communication with the first processor; the first processor executes computer-executable instructions stored in the first memory to implement the method according to any one of claims 1 to 4, or the method according to claim 6; The external storage device includes a second processor and a second memory communicatively connected to the second processor; the second processor executes the computer-executable instructions stored in the second memory to implement the method according to claim 5.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the method according to any one of claims 1 to 4, or the method according to claim 5, or the method according to claim 6.

10. A computer program product, characterized in that The invention comprises a computer program, which, when executed by a processor, implements the method according to any one of claims 1 to 4, or implements the method according to claim 5, or implements the method according to claim 6.

Citation Information

Patent Citations

  • MySQL database master-slave synchronization method and device, equipment and medium

    CN115292408A

  • High availability database through distributed store

    US20190042638A1

Cited By

  • Database management method, high-availability component and system for semiconductor manufacturing

    CN121681685A