Database synchronization method and device, equipment and storage medium
By introducing a transaction manager into the database, generating and synchronizing transaction numbers, the problems of data synchronization consistency and low utilization of backup resources in the database primary and backup disaster recovery architecture are solved, and the high availability and resource utilization of the database are improved.
Patent Information
- Application Number
- CN202411994318.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-31
- Publication Date
- 2025-04-29
AI Technical Summary
There are data synchronization consistency defects and waste of backup resources in the existing database primary and backup disaster recovery architecture, which affects the continuity and performance of database services.
By sending a transaction number application instruction to the transaction manager when the local database receives a service request, the transaction manager determines and returns the local transaction number. The database generates a data synchronization instruction based on the number and sends it to the peer database to realize data synchronization between the two databases.
It solves the problems of data synchronization consistency and low resource utilization in the database main and backup disaster recovery architecture, and improves the database's high availability, load balancing, resource utilization and disaster recovery capabilities.
Smart Images

Figure CN119902932A_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the technical field of database management, and in particular to a database synchronization method, apparatus, device and storage medium. Background Art
[0002] In the current disaster recovery architecture of OLTP databases, the master-slave mode is usually adopted. In this mode, the master database provides services to the outside world, and the slave database is consistent with the master database through data synchronization; when the master database fails due to software or hardware reasons, the slave database is upgraded to the master database to ensure the continuity of database services. This architecture has the following defects:
[0003] 1. Failure switching delay. When the primary database fails, it is necessary to detect the failure and switch the standby database to the primary database. This process may require manual intervention or automatic detection and switching. The switching time may be long. In addition, due to inconsistencies between the primary and standby copies, there is a risk of failure in the switch between the primary and standby databases. This affects the continuity of database services.
[0004] 2. Data synchronization delay or inconsistency risk. The master database usually needs to choose between asynchronous or semi-synchronous mode to copy data to the standby database, which inevitably involves the risk of data synchronization delay. Especially in high-concurrency scenarios or cross-region deployments, in order to ensure the sustainability of database services, only the asynchronous mode can be selected. If the master database fails, there is a risk of data loss, affecting data consistency.
[0005] 3. Waste of standby database resources. In the master-slave architecture, the standby database is usually in a "read-only" or idle state, and is only used to synchronize data, but not to participate in the actual business load processing. The standby database resource utilization rate is low; in order to ensure the consistency of the master and standby data copies, the performance of the master database needs to be sacrificed. The overall performance of the system still depends on the processing capacity of the master database, and the performance of multiple machines cannot be fully utilized. Summary of the invention
[0006] The embodiments of the present invention provide a database synchronization method, apparatus, device and storage medium. The technical solution of the embodiments of the present invention solves the problems of consistency defects and waste of standby database resources in data synchronization in the existing database master-standby disaster recovery architecture, can solve the data consistency problem between two databases, and improve the high availability, load balancing, resource utilization and disaster recovery capabilities of the database.
[0007] In a first aspect, an embodiment of the present invention provides a database synchronization method, which is applied in a database synchronization system, wherein the database synchronization system includes a first database, a second database, and a transaction manager, wherein the first database and the second database are in a peer-to-peer relationship, and the method includes:
[0008] When the local database receives a local service request, the local database sends a transaction number application instruction to the transaction manager; when the transaction manager receives the transaction number application instruction, it determines the local transaction number corresponding to the transaction number application instruction and returns the local transaction number to the local database; the local database generates a data synchronization instruction according to the local transaction number, and sends the data synchronization instruction to the peer database, so that the peer database synchronizes the storage data with the local database based on the data synchronization instruction.
[0009] In a second aspect, an embodiment of the present invention provides a database synchronization device, the device comprising:
[0010] A transaction number application module, used for the local database to send a transaction number application instruction to the transaction manager when receiving a local business request; a transaction number determination module, used for the transaction manager to determine the local transaction number corresponding to the transaction number application instruction when receiving the transaction number application instruction, and return the local transaction number to the local database; a data synchronization module, used for the local database to generate a data synchronization instruction according to the local transaction number, and send the data synchronization instruction to the peer database, so that the peer database is synchronized with the storage data of the local database based on the data synchronization instruction.
[0011] In a third aspect, an embodiment of the present invention provides a computer device, the computer device comprising:
[0012] one or more processors;
[0013] A memory for storing one or more programs;
[0014] When the one or more programs are executed by the one or more processors, the one or more processors implement the database synchronization method described in any embodiment.
[0015] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the database synchronization method described in any one of the embodiments.
[0016] The technical solution provided by the embodiment of the present invention is that, when the local database receives a local service request, it sends a transaction number application instruction to the transaction manager; when the transaction manager receives the transaction number application instruction, it determines the local transaction number corresponding to the transaction number application instruction, and returns the local transaction number to the local database; the local database generates a data synchronization instruction according to the local transaction number, and sends the data synchronization instruction to the peer database, so that the peer database synchronizes the storage data with the local database based on the data synchronization instruction. The technical solution of the embodiment of the present invention solves the problem of consistency defects and waste of standby database resources in data synchronization in the existing database master-standby disaster recovery architecture, and can solve the data consistency problem between the two databases, and improve the high availability, load balancing, resource utilization and disaster recovery capabilities of the database. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 is a flow chart of a database synchronization method provided by an embodiment of the present invention;
[0018] Figure 2 is a flow chart of another database synchronization method provided by an embodiment of the present invention;
[0019] Figure 3 is a schematic diagram of a working relationship between a database and a transaction manager provided by an embodiment of the present invention;
[0020] Figure 4 It is a structural diagram of a database synchronization device provided by an embodiment of the present invention;
[0021] Figure 5 It is a structural schematic diagram of a computer device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0022] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0023] S110. When receiving a local service request, the local database sends a transaction number application instruction to the transaction manager.
[0024] Among them, the local database can be a database that receives the data update task. The local business request can be a business processing request sent to the local database. Specifically, the local database can be understood as a database that receives the local business request. Among them, there is a peer relationship between the first database and the second database. That is, both the first database and the second database can be used as local databases. For each business request, the database that receives the business request can be used as the local database for this data update. Another database corresponding to the local database can be called a peer database. For example, when the first database is a local database, the second database can become a peer database. When the local database receives a local business request, it can execute the data update task corresponding to the local business request, and then update the local storage data of the local database, and synchronize the updated storage data to the peer database to ensure that the storage data of the peer database is consistent with the storage data of the local database.
[0025] The transaction number application instruction may be a trigger instruction for applying for a transaction number corresponding to a local service request. When receiving a local service request, the local database may send a transaction number application instruction to the transaction manager so that the transaction manager issues the transaction number of this data update task to the local database.
[0026] Optionally, when receiving a local service request sent by a preset application, the local database may update the stored data in the local database according to the local service request and send a transaction number application instruction to the transaction manager.
[0027] S120. When receiving the transaction number application instruction, the transaction manager determines the local transaction number corresponding to the transaction number application instruction, and returns the local transaction number to the local database.
[0028] The local transaction number may be a transaction number corresponding to a local business request. Specifically, the transaction management may determine the local transaction number based on the application time of the transaction number application instruction and the preset transaction number determination rule, and then return the local transaction number to the local database. By determining the transaction number corresponding to each business request, it is convenient to compare the data versions between databases based on the transaction number.
[0029] S130. The local database generates a data synchronization instruction according to the local transaction number, and sends the data synchronization instruction to the peer database, so that the peer database synchronizes the storage data with the local database based on the data synchronization instruction.
[0030] Specifically, the local database can generate a corresponding data synchronization instruction according to the local transaction number, and send the data synchronization instruction to the peer database, so that the peer database determines whether to synchronize the stored data according to the data synchronization instruction.
[0031] The technical solution provided by the embodiment of the present invention is that, when the local database receives a local service request, it sends a transaction number application instruction to the transaction manager; when the transaction manager receives the transaction number application instruction, it determines the local transaction number corresponding to the transaction number application instruction, and returns the local transaction number to the local database; the local database generates a data synchronization instruction according to the local transaction number, and sends the data synchronization instruction to the peer database, so that the peer database synchronizes the storage data with the local database based on the data synchronization instruction. The technical solution of the embodiment of the present invention solves the problem of consistency defects and waste of standby database resources in data synchronization in the existing database master-standby disaster recovery architecture, and can solve the data consistency problem between the two databases, and improve the high availability, load balancing, resource utilization and disaster recovery capabilities of the database.
[0032] Figure 2 It is another flowchart of a database synchronization method provided by an embodiment of the present invention. The embodiment of the present invention can be applied to the scenario of data synchronization between two databases. Based on the above embodiment, this embodiment further explains how the local database sends a transaction number application instruction to the transaction manager when receiving a local business request; how the transaction manager determines the local transaction number corresponding to the transaction number application instruction when receiving the transaction number application instruction; and how the peer database synchronizes the storage data of the local database based on the data synchronization instruction. The device can be implemented by software and / or hardware and integrated in a computer device with application development function.
[0033] like Figure 2 As shown, the database synchronization method includes the following steps:
[0034] S210: When receiving a local service request, the local database sends a transaction number application instruction to the transaction manager.
[0035] S220: When receiving the transaction number application instruction, the transaction manager determines the local transaction number corresponding to the transaction number application instruction, and returns the local transaction number to the local database.
[0036] The local transaction number may be a transaction number corresponding to a local service request. Specifically, the transaction management may determine the local transaction number according to the application time of the transaction number application instruction and a preset transaction number determination rule, and return the local transaction number to the local database.
[0037] Optionally, when the transaction manager receives a transaction number application instruction, the transaction manager determines the local transaction number corresponding to the transaction number application instruction, including: when the transaction manager receives the transaction number application instruction, the transaction manager determines the local transaction number corresponding to the transaction number application instruction based on the locally generated number; wherein the transaction manager is used to generate a monotonically increasing transaction number when the transaction number application instruction is received.
[0038] Among them, the locally generated number can be a transaction number that has been generated and stored locally by the transaction manager. Specifically, the transaction manager can generate a monotonically increasing transaction number each time it receives a transaction number running instruction. Exemplarily, the transaction manager can add the corresponding tolerance to the maximum number of the locally generated number when it receives a transaction number application instruction, thereby obtaining a local transaction number. For example, when the tolerance of the transaction number generated by the transaction manager is 1, if a transaction number application instruction is received, and the maximum number of locally generated numbers is 5, the value of the local transaction number can be determined to be 6. By determining the transaction number corresponding to each business request, it is convenient to compare the data versions between databases based on the transaction number later.
[0039] For example, Figure 3 FIG. 1 is a schematic diagram of a working relationship between a database and a transaction manager provided by an embodiment of the present invention. Figure 3 As shown, between two databases (hereinafter referred to as A database and B database), a group of global transaction manager modules (Global Transaction Management, referred to as GTM (i.e., the transaction manager in the embodiment of the present invention)) that can generate monotonically increasing IDs are designed. When the two active-active databases A and B (in the following example, A database can be understood as the local database, and B database can be understood as the peer database) write data, they first send a request for an application sequence to GTM. After receiving the request from A database or B database, GTM replies with a monotonically increasing sequence (GTID, i.e., the transaction number in the embodiment of the present invention). GTM produces GTIDs in a cyclic manner, and can be generated from scratch when GTIDs are used up, but GTIDs can be designed to be large enough, for example, designed to be an 8-byte integer, to ensure that even if the database processes tens of thousands of transaction requests per second, it can still be used for decades. In order to ensure the continuity of database services, GTM can be deployed in high-availability mode, but since it is not necessarily related to this patent application, it will not be repeated in this patent.
[0040] S230: The local database generates a data synchronization instruction according to the local transaction number, and sends the data synchronization instruction to the peer database.
[0041] Specifically, the local database can generate a corresponding data synchronization instruction according to the local transaction number, and send the data synchronization instruction to the peer database, so that the peer database determines whether to synchronize the stored data according to the data synchronization instruction.
[0042] In addition to the business data, the written data also adds three hidden columns that are invisible to the business, including GTID, the time when the database receives the business request update (hereinafter referred to as the update time or data update time), and the peer database response identifier (the response identifier can be the system time of receiving the peer ACK). Among them, ACK can include successful ACK and revoked ACK. Successful ACK means that the peer database has successfully verified the local transaction number and completed the data synchronization task corresponding to the data synchronization instruction. Revoked ACK means that the peer database has verified and identified the local transaction number and needs to revoke the data synchronization instruction. At the same time, the transaction log with GTID and update time information is sent to the B database for data synchronization. Before receiving the response identifier of the B database, the record will not be committed and the record will be kept in a locked state; if the B database responds, the peer database response identifier is generated, the record is committed, and the lock is released. At this time, the newly updated record is in a readable and writable state.
[0043] S240: The peer database obtains the local transaction number of the data synchronization instruction.
[0044] S250: When the local transaction number is greater than the current transaction number corresponding to the peer database, synchronize the stored data of the peer database with the stored data of the local database.
[0045] The current transaction number may be the transaction number corresponding to the data currently stored in the peer database. When the local transaction number is greater than the current transaction number, it means that the peer database is storing an old version of data, while the local database is storing a new version of data, so it is necessary to update the stored data in the peer database to the new version of data. Specifically, when the local transaction number is greater than the current transaction number, the stored data in the peer database may be modified to the stored data in the local database, thereby realizing the synchronization process of the stored data.
[0046] For example, 3. After receiving the data synchronization log of database A, database B compares the GTID in the transaction log with the GTID of the record in database B. Judgment logic:
[0047] 1) If the GTID of the data in database A is greater than the GTID of the data in database B, the data in database A is considered to be the latest version, and a success ACK is sent to database A, overwriting the local data in database B.
[0048] 2) If the GTID of the data in database B is greater than that of database A, local data takes precedence and sends the transaction log to database A for data synchronization. After receiving the request, database A cancels the original operation, overwrites the local data in database A with the data in database B, completes the peer response identifier of the record, and writes a failure response back to the business.
[0049] Optionally, the peer database synchronizes the stored data with the local database based on the data synchronization instruction, and also includes: if the peer database is executing the update step of the peer service request, executing the local data synchronization process according to the update status of the peer service request and the peer transaction number.
[0050] Among them, the peer service request may be a service request being executed by the peer database. Among them, there are conflicting tasks between the peer service request and the local service request. For example, the local service request is to modify data a to b, and the peer service request needs to modify the data to c, then there are conflicting tasks between the local service request and the peer service request. The peer transaction number may be the transaction number corresponding to the peer service request. The local data synchronization process may be the data synchronization process corresponding to the local service request. Specifically, it is possible to determine whether it is necessary to update the stored data of the local database to the peer database based on the update status of the peer service request and the peer transaction number, obtain a local determination result, and then use the data synchronization process corresponding to the local determination result as the local data synchronization process.
[0051] Optionally, when the update status is that the update is completed, the local data synchronization process is executed according to the update status of the peer business request and the peer transaction number, including: when the peer database writes the corresponding data of the peer business request within the preset timeout period, if the peer transaction number is smaller than the local transaction number, and the data update time of the peer business request is earlier than the data update time of the local business request, or the peer transaction number is larger than the local transaction number, a revocation instruction corresponding to the data synchronization instruction is fed back, and the storage data of the local database is overwritten based on the current storage data of the peer database; if the peer transaction number is smaller than the local transaction number, and the data update time of the peer business request is later than the data update time of the local business request, the peer database executes the data synchronization operation corresponding to the data synchronization instruction.
[0052] Among them, the preset timeout period can be a preset period for determining whether the data writing has timed out. Specifically, the preset timeout period can be set manually. The opposite-end database writes the corresponding data of the opposite-end service request within the preset timeout period, which can be understood as the opposite-end database has successfully written the data of the opposite-end service request into the opposite-end database within the preset timeout period. Further, if the opposite-end transaction number is smaller than the local transaction number, and the data update time of the opposite-end service request is earlier than the data update time of the local service request, it can be understood that although the stored data version in the local database is newer than the stored data version of the opposite-end database, the initiation time of the opposite-end service request is earlier than the initiation time of the local service request. Therefore, according to the execution logic of the database, the opposite-end service request needs to be executed first, so the revocation instruction corresponding to the data synchronization instruction can be fed back, and the stored data of the local database can be overwritten based on the current stored data of the opposite-end database. Specifically, the stored data of the local database can be replaced with the stored data of the opposite-end database.
[0053] Furthermore, if the peer update change is greater than the local transaction number, it means that the current data version stored in the peer database is newer than the data version stored in the local database. Therefore, the revocation instruction corresponding to the data synchronization instruction can also be fed back, and the data stored in the local database can be overwritten based on the current data stored in the peer database.
[0054] Similarly, if the peer transaction number is smaller than the local transaction number, and the data update time of the peer business request is later than the data update time of the local business request, it means that the storage version of the local database is newer than the storage version of the peer data library, and the initiation time of the peer business request is later than the initiation time of the local business request. Therefore, the peer database can execute the data synchronization operation corresponding to the data synchronization instruction.
[0055] Optionally, when the update status is not completed, the local data synchronization process is executed according to the update status of the peer business request and the peer transaction number, and also includes: when the peer database fails to write the corresponding data of the peer business request within a preset timeout period, if the peer transaction number is smaller than the local transaction number, the peer database ends the update step of the peer business request and starts to execute the data synchronization operation corresponding to the data synchronization instruction; if the peer transaction number is larger than the local transaction number, the revocation instruction corresponding to the data synchronization instruction is fed back, and the storage data of the local database is overwritten based on the current storage data of the peer database.
[0056] For example, when database B receives the synchronization log from database A, if the current data is in a locked state, it means that this record is occupied by a transaction (that is, database B is processing the business request of the other end), then it will retry periodically and make judgments in the following two scenarios:
[0057] 1) Database B is successfully written within the set timeout period. After writing is completed, if: it is found that the GTID is smaller than the GTID in the transaction log sent from the peer database A, but the update time of the peer business request is earlier than the update time of the local business situation (in order to ensure that the machine time error between databases A and B is small enough, clock synchronization protocols such as Chrony and PTP can be used), then it means that the current database B data is the latest version, and the latest record is sent to database A for data synchronization. Since database A has not received a response from database B before, the data has not been committed, the response identifier is empty, and the data is locked. After receiving the synchronized data from database B, the original operation is canceled, and the data is updated to the data from database B, and the response identifier is filled in, giving a response to the business write failure.
[0058] 2) If the B database fails to write successfully within the set timeout period, it is necessary to determine which version of the data to retain. The B database parses the GTID corresponding to the timeout SQL and compares it with the GTID in the transaction log transmitted from the A database: 1. If the B database GTID is smaller than the A database GTID, the B database ends the current transaction, responds to the business recovery write failure, and uses the data transmitted from the A database to overwrite the local data, and returns a successful ACK to the A database. After receiving the ACK, the A database completes the peer response identifier. At this time, the newly updated record is in a readable and writable state. 2. If the B database GTID is larger than the A database GTID, this means that the data version of the A database is older, and the A database replies with a cancel ACK; after receiving the cancel ACK, the A database cancels the current update, responds to the business write failure, and waits for the latest version of the data to be synchronized after the B database completes the write operation, or accepts the latest write request from the business before performing the above process.
[0059] The technical solution provided by the embodiment of the present invention is that, when the local database receives a local service request, it sends a transaction number application instruction to the transaction manager; when the transaction manager receives the transaction number application instruction, it determines the local transaction number corresponding to the transaction number application instruction and returns the local transaction number to the local database; the local database generates a data synchronization instruction according to the local transaction number and sends the data synchronization instruction to the peer database; the peer database obtains the local transaction number of the data synchronization instruction; when the local transaction number is greater than the current transaction number corresponding to the peer database, the storage data of the peer database is synchronized with the storage data of the local database. The technical solution of the embodiment of the present invention solves the problem of consistency defects and waste of standby database resources in data synchronization in the existing database master-standby disaster recovery architecture, can solve the data consistency problem between the two databases, and improve the high availability, load balancing, resource utilization and disaster recovery capabilities of the database.
[0060] Figure 4It is a structural diagram of a database synchronization device provided in an embodiment of the present invention. The embodiment of the present invention can be applied to the scenario of data synchronization between two databases. The device can be implemented by software and / or hardware and integrated into a computer device with application development function.
[0061] like Figure 4 As shown, the database synchronization device includes: a transaction number application module 310, a transaction number determination module 320 and a data synchronization module 330.
[0062] Among them, the transaction number application module 310 is used for the local database to send a transaction number application instruction to the transaction manager when receiving a local business request; the transaction number determination module 320 is used for the transaction manager to determine the local transaction number corresponding to the transaction number application instruction when receiving the transaction number application instruction, and return the local transaction number to the local database; the data synchronization module 330 is used for the local database to generate a data synchronization instruction according to the local transaction number, and send the data synchronization instruction to the peer database, so that the peer database is synchronized with the storage data of the local database based on the data synchronization instruction.
[0063] The technical solution provided by the embodiment of the present invention is that, when the local database receives a local service request, it sends a transaction number application instruction to the transaction manager; when the transaction manager receives the transaction number application instruction, it determines the local transaction number corresponding to the transaction number application instruction, and returns the local transaction number to the local database; the local database generates a data synchronization instruction according to the local transaction number, and sends the data synchronization instruction to the peer database, so that the peer database synchronizes the storage data with the local database based on the data synchronization instruction. The technical solution of the embodiment of the present invention solves the problem of consistency defects and waste of standby database resources in data synchronization in the existing database master-standby disaster recovery architecture, and can solve the data consistency problem between the two databases, and improve the high availability, load balancing, resource utilization and disaster recovery capabilities of the database.
[0064] In an optional embodiment, the transaction number determination module 320 includes: a local transaction number determination unit, used for: when the transaction manager receives the transaction number application instruction, determining the local transaction number corresponding to the transaction number application instruction according to the locally generated number; wherein, when the transaction manager receives the transaction number application instruction, it generates a monotonically increasing transaction number.
[0065] In an optional embodiment, the data synchronization module 330 includes: a first data synchronization unit, used for: the peer database to obtain the local transaction number of the data synchronization instruction; when the local transaction number is greater than the current transaction number corresponding to the peer database, synchronizing the storage data of the peer database with the storage data of the local database.
[0066] In an optional embodiment, the data synchronization module 330 includes: a second data synchronization unit, used to: if the peer database is executing the update step of the peer business request, execute the local data synchronization process according to the update status of the peer business request and the peer transaction number; wherein there is a conflicting task between the peer business request and the local business request.
[0067] In an optional embodiment, the second data synchronization unit includes: a first synchronization analysis subunit, which is used to: when the peer database writes the corresponding data of the peer service request within a preset timeout period, if the peer transaction number is smaller than the local transaction number, and the data update time of the peer service request is earlier than the data update time of the local service request, or the peer transaction number is larger than the local transaction number, feedback a revocation instruction corresponding to the data synchronization instruction, and overwrite the storage data of the local database based on the current storage data of the peer database; if the peer transaction number is smaller than the local transaction number, and the data update time of the peer service request is later than the data update time of the local service request, the peer database executes the data synchronization operation corresponding to the data synchronization instruction.
[0068] In an optional embodiment, the second data synchronization unit also includes: a second synchronization analysis subunit, which is used to: when the peer database fails to write the corresponding data of the peer service request within a preset timeout period, if the peer transaction number is smaller than the local transaction number, the peer database ends the update step of the peer service request and starts to execute the data synchronization operation corresponding to the data synchronization instruction; if the peer transaction number is larger than the local transaction number, a revocation instruction corresponding to the data synchronization instruction is fed back, and the storage data of the local database is overwritten based on the current storage data of the peer database.
[0069] In an optional implementation, the transaction number application module 310 is specifically used for: when the local database receives a local service request sent by a preset application, updating the stored data in the local database according to the local service request, and sending a transaction number application instruction to the transaction manager.
[0070] The database synchronization device provided in the embodiment of the present invention can execute the database synchronization method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0071] Figure 5 A schematic diagram of the structure of a computer device provided in an embodiment of the present invention. Figure 5 A block diagram of an exemplary computer device 12 suitable for use in implementing embodiments of the present invention is shown. Figure 5 The computer device 12 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention. The computer device 12 can be any terminal device with computing capability and can be configured in a database synchronization device.
[0072] like Figure 5 As shown, the computer device 12 is in the form of a general-purpose computing device. The components of the computer device 12 may include, but are not limited to: one or more processors or processing units 16, a system memory 28, and a bus 18 that connects various system components (including the system memory 28 and the processing unit 16).
[0073] The bus 18 may be one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor or a local bus using any of a variety of bus architectures. For example, these architectures include, but are not limited to, an Industry Standard Architecture (ISA) bus, a Micro Channel Architecture (MAC) bus, an Enhanced ISA bus, a Video Electronics Standards Association (VESA) local bus, and a Peripheral Component Interconnect (PCI) bus.
[0074] The computer device 12 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by the computer device 12, including volatile and non-volatile media, removable and non-removable media.
[0075] The system memory 28 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 30 and / or cache 32. The computer device 12 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system 34 may be used to read and write non-removable, non-volatile magnetic media ( Figure 5 not shown, usually called a "hard drive"). Although Figure 5Not shown in the figure, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk"), and an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, a DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to the bus 18 via one or more data medium interfaces. The system memory 28 may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of the various embodiments of the present invention.
[0076] A program / utility 40 having a set (at least one) of program modules 42 may be stored, for example, in system memory 28, such program modules 42 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment. Program modules 42 generally perform the functions and / or methods of the embodiments described herein.
[0077] The computer device 12 may also communicate with one or more external devices 14 (e.g., keyboards, pointing devices, displays 24, etc.), one or more devices that enable a user to interact with the computer device 12, and / or any device that enables the computer device 12 to communicate with one or more other computing devices (e.g., network cards, modems, etc.). Such communication may be performed through an input / output (I / O) interface 22. Furthermore, the computer device 12 may also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) through a network adapter 20. Figure 5 As shown, the network adapter 20 communicates with other modules of the computer device 12 via the bus 18. It should be understood that although Figure 5 Not shown, other hardware and / or software modules may be used in conjunction with computer device 12, including but not limited to microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0078] The processing unit 16 executes various functional applications and data processing by running the program stored in the system memory 28, for example, implementing the database synchronization method provided in the embodiment of the present invention, which includes:
[0079] When the local database receives a local service request, the local database sends a transaction number application instruction to the transaction manager; when the transaction manager receives the transaction number application instruction, it determines the local transaction number corresponding to the transaction number application instruction and returns the local transaction number to the local database; the local database generates a data synchronization instruction according to the local transaction number, and sends the data synchronization instruction to the peer database, so that the peer database synchronizes the storage data with the local database based on the data synchronization instruction.
[0080] This embodiment provides a computer-readable storage medium, on which a computer program is stored. When the program is executed by a processor, the database synchronization method provided by any embodiment of the present invention is implemented, including:
[0081] When the local database receives a local service request, the local database sends a transaction number application instruction to the transaction manager; when the transaction manager receives the transaction number application instruction, it determines the local transaction number corresponding to the transaction number application instruction and returns the local transaction number to the local database; the local database generates a data synchronization instruction according to the local transaction number, and sends the data synchronization instruction to the peer database, so that the peer database synchronizes the storage data with the local database based on the data synchronization instruction.
[0082] The computer storage medium of the embodiment of the present invention can adopt any combination of one or more computer-readable media. The computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium can be, for example, but not limited to: an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, a computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it.
[0083] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, which carry computer-readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0084] The program code embodied on the computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0085] Computer program code for performing the operations of the present invention may be written in one or more programming languages or combinations thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0086] It should be understood by those skilled in the art that the modules or steps of the present invention described above can be implemented by a general-purpose computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, optionally, they can be implemented by a program code executable by a computer device, so that they can be stored in a storage device and executed by the computing device, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present invention is not limited to any specific combination of hardware and software.
[0087] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.
Claims
1. A database synchronization method, applied in a database synchronization system, wherein the database synchronization system comprises a first database, a second database and a transaction manager; wherein: The first database and the second database are in a peer-to-peer relationship, and are characterized by: When receiving a local service request, the local database sends a transaction number application instruction to the transaction manager; Upon receiving the transaction number application instruction, the transaction manager determines a local transaction number corresponding to the transaction number application instruction, and returns the local transaction number to the local database; The local database generates a data synchronization instruction according to the local transaction number, and sends the data synchronization instruction to the peer database, so that the peer database synchronizes the storage data with the local database based on the data synchronization instruction.
2. The method according to claim 1, characterized in that When receiving the transaction number application instruction, the transaction manager determines the local transaction number corresponding to the transaction number application instruction, including: When receiving the transaction number application instruction, the transaction manager determines the local transaction number corresponding to the transaction number application instruction according to the locally generated number; The transaction manager is used to generate a monotonically increasing transaction number when receiving a transaction number application instruction.
3. The method according to claim 2, characterized in that The peer database synchronizes the stored data with the local database based on the data synchronization instruction, including: The peer database obtains the local transaction number of the data synchronization instruction; In the case where the local transaction number is greater than the current transaction number corresponding to the peer database, the stored data of the peer database is synchronized with the stored data of the local database.
4. The method according to claim 2, wherein the peer database synchronizes the stored data with the local database based on the data synchronization instruction, further comprising: If the peer database is executing the update step of the peer service request, execute the local data synchronization process according to the update status of the peer service request and the peer transaction number; There are conflicting tasks between the peer service request and the local service request.
5. The method according to claim 4, characterized in that When the update status is that the update is completed, the local data synchronization process is performed according to the update status of the peer service request and the peer transaction number, including: In the case where the peer database writes the corresponding data of the peer service request within the preset timeout period, if the peer transaction number is smaller than the local transaction number, and the data update time of the peer service request is earlier than the data update time of the local service request, or the peer transaction number is larger than the local transaction number, a revocation instruction corresponding to the data synchronization instruction is fed back, and the storage data of the local database is overwritten based on the current storage data of the peer database; If the peer transaction number is smaller than the local transaction number, and the data update time of the peer service request is later than the data update time of the local service request, the peer database executes the data synchronization operation corresponding to the data synchronization instruction.
6. The method according to claim 4, characterized in that In the case where the update status is not updated, the executing the local data synchronization process according to the update status of the peer service request and the peer transaction number further includes: In the case that the peer database fails to write the corresponding data of the peer service request within the preset timeout period, if the peer transaction number is less than the local transaction number, the peer database ends the update step of the peer service request and starts to execute the data synchronization operation corresponding to the data synchronization instruction; If the peer transaction number is greater than the local transaction number, a revocation instruction corresponding to the data synchronization instruction is fed back, and the storage data of the local database is overwritten based on the current storage data of the peer database.
7. The method according to claim 1, characterized in that When the local database completes data update after locally storing data, it sends a transaction number application instruction to the transaction manager, including: When receiving a local service request sent by a preset application, the local database updates the stored data in the local database according to the local service request, and sends a transaction number application instruction to the transaction manager.
8. A database synchronization device, characterized in that: The device comprises: A transaction number application module, configured for the local database to send a transaction number application instruction to the transaction manager when receiving a local service request; a transaction number determination module, configured for the transaction manager to determine, when receiving the transaction number application instruction, a local transaction number corresponding to the transaction number application instruction, and return the local transaction number to the local database; The data synchronization module is used for the local database to generate a data synchronization instruction according to the local transaction number, and send the data synchronization instruction to the peer database, so that the peer database synchronizes the storage data with the local database based on the data synchronization instruction.
9. A computer device, characterized in that: The computer device comprises: one or more processors; A memory for storing one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the database synchronization method as described in any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the database synchronization method as described in any one of claims 1 to 7 is implemented.
Citation Information
Cited By
Mirror image volume writing control method and device, electronic equipment and storage medium
CN120335732A
High-end equipment operation and maintenance management information tracing method and system based on Internet platform
CN120598537A