Data synchronization method of database system, storage medium and device
By creating a reference table in the database system to record the reference value of the number of synchronization attempts, the dead loop problem in the circular data synchronization structure is solved, and efficient resource utilization is achieved.
Patent Information
- Application Number
- CN202310218395.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-08
- Publication Date
- 2026-11-06
- Estimated Expiration
- 2043-03-08
AI Technical Summary
In a circular data synchronization structure, the database system may experience a dead loop during data synchronization, leading to wasted resources.
A reference table is created in each database to record the reference value of the number of times synchronization is possible. Transactions are discarded if the modification operations in a transaction meet preset conditions, thus avoiding circular synchronization.
Effectively interrupts loop synchronization, reducing the waste of database system resources.
Smart Images

Figure CN116069867B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of database technology, and in particular to a data synchronization method, storage medium, and device for a database system. Background Technology
[0002] In database systems with multiple databases, data synchronization is required to maintain data consistency across all databases. A ring-shaped data synchronization structure is a special data synchronization architecture used in such systems. Specifically, in a ring-shaped data synchronization structure, data written to each database is synchronized to the other databases sequentially along a ring path.
[0003] However, because synchronization follows a circular path, a database will synchronize back to itself, causing a dead loop in data synchronization and resulting in a waste of database system resources. Summary of the Invention
[0004] One object of the present invention is to provide a data synchronization method, storage medium and device for a database system that can solve any of the above problems.
[0005] Specifically, this invention provides a data synchronization method for a database system, the database system including multiple databases, the data synchronization method comprising:
[0006] Create the same reference table in each database. The reference table is used to record the reference value of the number of times a transaction can be synchronized.
[0007] Retrieve the pending transactions for the target database, where the target database is the one of the two databases to be written to during data synchronization;
[0008] Read the modification operations on the reference table in the transaction to be executed. The modification operations are used to modify the reference value of the number of times the record in the reference table can be synchronized.
[0009] Determine if the reference value for the number of times a modification operation can be synchronized meets the preset conditions. If it does, discard the pending transaction.
[0010] Optionally, the steps for reading modification operations on the reference table in the transaction to be executed include:
[0011] Determine whether the transaction to be executed contains modification operations on the reference table. If so, execute the step of reading the modification operations on the reference table in the transaction to be executed.
[0012] If not, generate an execution transaction based on the transaction to be executed, and add an initial modification operation for the reference table in the execution transaction. The initial modification operation is used to modify the reference value of the number of times that can be synchronized in the reference table to a preset initial value.
[0013] Synchronize the executed transactions to the target database.
[0014] Optionally, after determining whether the number of synchronizations in the modification operation meets preset conditions, the following steps are included:
[0015] If the preset conditions are not met, adjust the reference value of the number of times synchronization can be performed in the modification operation so that the reference value of the number of times synchronization can be performed in the modification operation approaches the preset conditions at a fixed frequency.
[0016] Synchronize the pending transactions to the target database.
[0017] Optionally, the initial value is set to an integer.
[0018] The steps for adjusting the reference value for the number of synchronizations in the modification operation include:
[0019] The reference value for the number of times synchronization can be reduced in the modification operation is reduced according to the first preset fixed value;
[0020] The preset condition is that it is less than or equal to the first preset threshold. The first preset threshold = preset initial value - first preset fixed value × (number of databases in the database system - 2).
[0021] Optionally, the default initial value is equal to the number of databases in the database system minus two;
[0022] The steps for adjusting the synchronization count reference value in the modification operation include:
[0023] Decrement the reference value for the number of times synchronization is possible during the modification operation by 1;
[0024] The first preset threshold is 0.
[0025] Optionally, the initial value is set to an integer.
[0026] The steps for adjusting the synchronization count reference value in the modification operation include:
[0027] The reference value for the number of times that can be synchronized during the modification operation is increased according to the second preset fixed value;
[0028] The preset condition is that it is greater than or equal to the second preset threshold. The second preset threshold = preset initial value + second preset fixed value × (number of databases in the database system - 2).
[0029] Optionally, the default initial value is 1;
[0030] The steps for adjusting the synchronization count reference value in the modification operation include:
[0031] Increment the reference value for the number of times synchronization is possible during the modification operation by 1;
[0032] The second preset threshold is equal to the number of databases in the database system minus one.
[0033] Optionally, the steps of generating an execution transaction based on the transaction to be executed include:
[0034] Temporarily store pending transactions until the number of temporary pending transactions reaches a preset limit;
[0035] Merge all temporarily pending transactions into a single execution transaction.
[0036] According to another aspect of the present invention, a machine-readable storage medium is also provided, on which a machine-executable program is stored, which, when executed by a processor, implements a data synchronization method for a database system according to any one of the preceding claims.
[0037] According to another aspect of the present invention, a computer device is also provided, including a memory, a processor, and a machine-executable program stored in the memory and running on the processor, wherein the processor, when executing the machine-executable program, implements a data synchronization method for a database system according to any of the above claims.
[0038] The data synchronization method of the database system of the present invention creates a reference table in each database to record the number of synchronization attempts. This allows transactions to be marked by adding the synchronization attempt reference value to the reference table. During data synchronization, when acquiring the transaction to be executed for the target database, the modification operations on the reference table contained in the transaction are read. If the synchronization attempt reference value in the modification operation meets a preset condition, the transaction to be executed is discarded. In other words, if the synchronization attempt reference value in the modification operation of a transaction meets the preset condition, it means that the synchronization attempt of this transaction has reached the required number, indicating that the current target database is the database that initially provided this transaction, and there is no need to synchronize this transaction to the current target database again. Therefore, this avoids a transaction being synchronized back to the original database, thereby interrupting circular synchronization and reducing the waste of database system resources.
[0039] The above and other objects, advantages and features of the present invention will become more apparent to those skilled in the art from the following detailed description of specific embodiments of the invention in conjunction with the accompanying drawings. Attached Figure Description
[0040] The following sections will describe some specific embodiments of the invention in detail by way of example and not limitation, with reference to the accompanying drawings. The same reference numerals in the drawings denote the same or similar parts or portions. Those skilled in the art should understand that these drawings are not necessarily drawn to scale. In the drawings:
[0041] Figure 1This is a schematic diagram of a database system according to an embodiment of the present invention;
[0042] Figure 2 This is a schematic flowchart of a data synchronization method for a database system according to an embodiment of the present invention;
[0043] Figure 3 This is a schematic flowchart of a data synchronization method for a database system according to another embodiment of the present invention;
[0044] Figure 4 This is a schematic flowchart of a data synchronization method for a database system according to yet another embodiment of the present invention;
[0045] Figure 5 This is a schematic flowchart of a data synchronization method for a database system according to yet another embodiment of the present invention;
[0046] Figure 6 This is a schematic diagram of a machine-readable storage medium according to an embodiment of the present invention;
[0047] Figure 7 This is a schematic diagram of a computer device according to an embodiment of the present invention. Detailed Implementation
[0048] Those skilled in the art should understand that the embodiments described below are merely a part of the embodiments of the present invention, and not all of the embodiments of the present invention. These partial embodiments are intended to explain the technical principles of the present invention and are not intended to limit the scope of protection of the present invention. Based on the embodiments provided by the present invention, all other embodiments obtained by those skilled in the art without creative effort should still fall within the scope of protection of the present invention.
[0049] It should be noted that the logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be specifically implemented in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus or device (such as a computer-based system, a processor-included system or other system that can fetch and execute instructions from, an instruction execution system, apparatus or device).
[0050] In one embodiment, the database system includes multiple databases forming a ring-shaped synchronization structure, such that data from one database is synchronized sequentially to the other databases along a ring path. Specifically, the database system includes a first database 10, a second database 20, and a third database 30. Data in the first database 10 can be synchronized to the second database 20, data in the second database 20 can be synchronized to the third database 30, and data in the third database 30 can be synchronized to the first database 10.
[0051] It should be noted that the number of databases in the database system can be three or more. The methods described in the following embodiments are not limited to... Figure 1 The database system shown in the diagram.
[0052] like Figure 2 As shown, in one embodiment, the data synchronization method of the database system includes:
[0053] Step S201: Create an identical reference table in each database. This reference table records the number of times a transaction can be synchronized. Specifically, the database system includes multiple databases. Before data synchronization, an identical reference table is created in each database. The reference table may include a flag field and a reference value field. An initial flag is preset under the flag field, and the reference value field is empty. This allows a location to be determined based on the initial flag and the reference value field, and the data at that location represents the synchronization count reference value. The initial flag can be arbitrarily set, such as numbers or letters. Reference Table 1 illustrates one example of an initial reference table. The flag field is named ID (custom name), the reference value field is named CNT (custom name), the initial flag is 1, and the initial synchronization count reference value is empty, awaiting modification by the transaction.
[0054] Table 1
[0055] ID CNT 1
[0056] Step S202: Obtain the transactions to be executed for the target database. The target database is the one of the two databases to which data is to be written during data synchronization. (Refer to...) Figure 1 As shown, exemplarily, if the first database 10 synchronizes data to the second database 20, then the second database 20 is the target database. If the second database 20 synchronizes data to the third database 30, then the third database 30 is the target database. If the third database 30 synchronizes data to the first database 10, then the first database 10 is the target database.
[0057] Specifically, during the data synchronization process between two databases, obtaining the transaction to be executed involves parsing the logs of one database to extract the transaction operations. After reading all the operations of a transaction, all operations belonging to the same transaction can be combined into a transaction, which is then sent to the other database (the target database) for data entry to achieve data synchronization.
[0058] Step S203: Read the modification operations targeting the reference table in the transaction to be executed. These modification operations are used to modify the synchronization count reference value of records in the reference table. Specifically, because each database has a reference table, adding a modification operation targeting the reference table to a transaction will still allow the transaction to execute normally without errors. The modification operation can be configured to modify the synchronization count reference value in the reference table. Since parsing the transaction to be executed involves parsing out the transaction operations and then combining them, obtaining the modification operations in the transaction to be executed is equivalent to obtaining the operations targeting the reference table added to the transaction to be executed.
[0059] Step S204: Determine whether the synchronization count reference value in the modification operation meets the preset conditions. Specifically, since the modification operation can be configured to modify the synchronization count reference value in the reference table, the modification operation can be configured to be an operation added during the first synchronization process of a transaction to modify the synchronization count reference value in the reference table to the initial value and adjust the synchronization count reference value contained therein in each subsequent synchronization, thereby marking the number of transaction synchronizations.
[0060] Therefore, after reading the modification operation of the transaction to be executed, it is determined whether the reference value of the number of times that can be synchronized in the modification operation meets the preset conditions. The number of modifications of the reference value of the number of times that can be synchronized can be obtained, that is, the number of synchronizations with the transaction to be executed can be obtained.
[0061] Step S205: If the preset conditions are met, discard the pending transactions. If the preset conditions are met, it means that the required number of synchronizations for the pending transactions has been reached. Therefore, the pending transactions containing modification operations that meet the preset conditions are discarded, meaning they are not synchronized to the target database.
[0062] In this embodiment, a reference table is created in each database to record the number of times a data can be synchronized. This allows transactions to be marked by adding the synchronization count reference value to the reference table. During data synchronization, when acquiring the transaction to be executed for the target database, the modification operations on the reference table contained in the transaction to be executed are read. If the synchronization count reference value contained in the modification operation meets a preset condition, the transaction to be executed is discarded directly.
[0063] In other words, if the number of synchronization attempts within a transaction meets the preset criteria, it means the transaction has reached the required number of synchronization attempts. This indicates that the current target database is the same database that initially provided the transaction, and there's no need to synchronize the transaction back to the current target database. Therefore, this avoids synchronizing a transaction back to the original database, thus breaking the cycle of synchronization and reducing waste of database system resources.
[0064] like Figure 3 As shown, in one embodiment, a data synchronization method for a database system generally includes:
[0065] Step S301: Create the same reference table in each database.
[0066] Step S302: Obtain the transaction to be executed for the target database.
[0067] Step S303: Determine whether the transaction to be executed contains any modification operations on the reference table. If yes, proceed to step S307; otherwise, proceed to step S304. Specifically, this means determining whether the transaction to be executed contains any modification operations on the reference table.
[0068] Alternatively, each time a transaction operation is parsed, it can be determined whether it is a modification operation on the reference table. If so, the transaction number of the transaction in which the operation is located is marked, thereby determining whether the transaction to be executed contains a modification operation on the reference table.
[0069] Alternatively, after parsing out each complete transaction, the entire transaction can be checked to determine whether it contains any modification operations on the reference table.
[0070] Step S304: Generate an execution transaction based on the pending transaction. Specifically, if a pending transaction does not contain any modification operations on the reference table, it means that this transaction has not yet been synchronized. In this case, the pending transaction can be directly used as the execution transaction.
[0071] Alternatively, pending transactions can be temporarily stored until a preset number of such transactions are reached; then, all temporarily stored pending transactions are merged into a single execution transaction. In other words, after parsing out a pending transaction that does not involve modifications to the reference table, no further operations are performed until the preset number of such pending transactions is reached. Then, all pending transactions are merged into a single large transaction and used as the execution transaction for subsequent operations.
[0072] Step S305: Add an initial modification operation for the reference table within the execution transaction. The initial modification operation modifies the synchronization count reference value in the reference table to a preset initial value. Specifically, before synchronizing the execution transaction to the target database, an initial modification operation for the reference table is added within the execution transaction. After the execution transaction is executed in the target database, the initial modification operation modifies the synchronization count reference value in the target database's reference table to the preset initial value.
[0073] Referring to Table 1, the initial modification operation on the reference table added during the execution of a transaction can be:
[0074] The command `UPDATE 'reference table name' CNT = 'preset initial value' WHERE ID = 1` modifies the value of the CNT column corresponding to ID 1 in the reference table to the preset initial value, which in turn modifies the reference value of the number of times the record can be synchronized to the preset initial value.
[0075] Step S306: Synchronize the transaction to the target database. This means executing the transaction on the target database.
[0076] Step S307: Read the modification operations on the reference table in the transaction to be executed.
[0077] Step S308: Determine whether the reference value of the number of times synchronization can be performed in the modification operation meets the preset conditions. If yes, proceed to step S309; otherwise, proceed to step S310.
[0078] Step S309: Discard the pending transaction.
[0079] Step S310: Adjust the reference value for the number of times a modification operation can be synchronized. Specifically, if the reference value for the number of times a modification operation can be synchronized does not meet the preset conditions, meaning that the transaction to be executed containing this modification operation needs to be synchronized to the target database, then before synchronizing the transaction to be executed to the target database, the reference value for the number of times a modification operation contained in the transaction to be executed is adjusted so that the reference value for the number of times a modification operation can be synchronized towards the preset conditions at a fixed frequency, so that the reference value for the number of times a modification operation can be synchronized to the target database after the same transaction performs a synchronization of the number of databases minus one.
[0080] Step S311: Synchronize the transactions to be executed to the target database.
[0081] Reference Figure 1 As shown, the method of this embodiment is illustrated using a database system with three databases as an example.
[0082] For the first database 10, the transactions it executes include those synchronized from the third database 30 and those written directly from external sources. When the first database 10 executes a transaction written directly from an external source, it needs to synchronize this transaction to the second database 20 and the third database 30.
[0083] During the synchronization of this transaction from the first database 10 to the second database 20 (with the second database 20 as the target database), the transaction is first parsed from the first database 10. This transaction does not contain any modification operations on the reference table. Therefore, before synchronizing this transaction to the second database 20, an initial modification operation on the reference table is added to the transaction, and then the transaction is synchronized to the second database 20. After the transaction is synchronized in the second database 20, the second database 20 writes the original data of the transaction to itself, and also modifies the reference table according to the subsequently added initial modification operation, changing the reference value of the number of synchronization attempts in the reference table to a preset initial value.
[0084] During the synchronization of this transaction from the second database 20 to the third database 30 (i.e., the third database 30 is the target database), after the transaction is parsed from the second database 20, it contains operations on a reference table. Because the preset conditions are not met, the transaction needs to be synchronized to the third database 30. Before synchronizing the transaction to the third database 30, the modification operations on the reference table contained in the transaction are adjusted, and then the transaction is synchronized to the third database 30.
[0085] During the synchronization process from the third database 30 to the first database 10 (i.e., the first database 10 is the target database), after the transaction is parsed from the third database 30, it contains operations on a reference table. Furthermore, the reference value for the number of synchronization operations on the reference table meets the preset condition, so the transaction is discarded and does not need to be synchronized to the first database 10. Since this transaction was initially generated by the first database 10, it indeed does not need to be written to the first database 10 again.
[0086] In this embodiment, a reference table is created in each database to record the number of times a data can be synchronized. This allows transactions to be marked by adding the synchronization count reference value to the reference table. During data synchronization, when a transaction to be executed is obtained, if the transaction does not contain any modification operations to the reference table, it means that the transaction has not yet been synchronized. Therefore, an initial modification operation to the reference table is added to the transaction before synchronization, thereby marking the transaction.
[0087] If the transaction to be executed contains modification operations on the reference table, it means that the transaction has performed at least one synchronization. Therefore, it is determined whether the reference value for the number of synchronizations possible in the modification operations on the reference table within the transaction meets a preset condition. If it does not meet the preset condition, the reference value for the number of synchronizations possible in the modification operations on the reference table within the transaction is adjusted, thus serving as a reference marker for the synchronization count. For a transaction, as the number of synchronizations increases, the reference value for the number of synchronizations possible in the modification operations on the reference table within it continuously approaches the preset condition, eventually reaching the preset condition after performing a synchronization that decrements the database count by one.
[0088] If the preset conditions are met, it means that the transaction has already performed a synchronization of the database count minus one. In other words, starting from the original database, a synchronization has already been performed on all other databases in the database system. This indicates that the current target database is the original database, so no further synchronization is needed, and the transaction can be discarded directly.
[0089] Therefore, by adding modification operations to the reference table within a transaction and adjusting the synchronized count modification value of these operations during the transaction's synchronization process, the synchronization count of a transaction can be marked. By referencing the synchronized count modification value of the reference table modification operations within a transaction, it's possible to determine whether a transaction has completed synchronization with all other databases besides the initial database. After completing synchronization with all other databases, the transaction can be discarded, i.e., synchronization of the transaction can be stopped, preventing the transaction from synchronizing back to the initial database. This breaks circular synchronization and reduces waste of database system resources.
[0090] In one embodiment, the preset initial value is an integer. The step of adjusting the reference value of the number of times synchronization can be performed in the modification operation includes reducing the reference value of the number of times synchronization can be performed in the modification operation by a first preset fixed value; the preset condition is that it is less than or equal to a first preset threshold, the first preset threshold = preset initial value - first preset fixed value × (number of databases in the database system - 2).
[0091] Reference Figure 4 As shown, in this embodiment, the data synchronization method of the database system generally includes:
[0092] Step S401: Determine whether the reference value of the number of times synchronization can be performed in the modification operation is less than or equal to the first preset threshold. If yes, proceed to step S402; otherwise, proceed to step S403.
[0093] Step S402: Discard the pending transaction.
[0094] Step S403: Decrease the reference value for the number of times synchronization is possible in the modification operation by a first preset fixed value. Specifically, if the reference value for the number of times synchronization is possible is greater than the first preset threshold, decrease the reference value for the number of times synchronization is possible in the modification operation by a first preset fixed value.
[0095] Because the initial value is an integer, and the first preset threshold is set to First Preset Threshold = Initial Preset Value - First Preset Fixed Value × (Number of Databases in the Database System - 2), after a transaction undergoes synchronization with the database system's database count minus one, the database count is adjusted by minus two. Therefore, after a transaction undergoes synchronization with the database system's database count minus one, the reference value for the number of times its modification operations can be synchronized will reach the first preset threshold.
[0096] Step S404: Synchronize the transactions to be executed to the target database.
[0097] Specifically, the initial preset value is equal to the number of databases in the database system minus two. The steps for adjusting the synchronization count reference value in modification operations include: decrementing the synchronization count reference value by 1. The first preset threshold is 0.
[0098] Reference Figure 1 As shown in Table 1, taking a database system with three databases as an example, the default initial value is 3-2, which is 1.
[0099] During data synchronization, a transaction is first parsed from the first database 10. This transaction does not contain any modification operations on the reference table. Therefore, before synchronizing this transaction to the second database 20, an initial modification operation on the reference table is added to this transaction:
[0100] The command `UPDATE 'reference table name' SET CNT = 1 WHERE ID = 1` modifies the value of the `CNT` column in the reference table, where `ID` is 1, to 1.
[0101] Then synchronize the transaction to the second database 20. After the transaction is synchronized to the second database 20, the second database 20 will write the original data of the transaction to itself, and at the same time, it will modify the reference table according to the initial modification operations added later, and modify the reference value of the number of synchronizations in the reference table to the preset initial value.
[0102] Then, after parsing the transaction from the second database 20, this transaction contains modification operations on the reference table. At this point, the synchronizable count reference value for the modification operations is 1, which is greater than 0, failing the preset condition, and the transaction needs to be synchronized to the third database 30. Before synchronizing the transaction to the third database 30, the synchronizable count reference value for the modification operations on the reference table contained in the transaction is decremented by 1, that is, the modification operation is modified to: UPDATE 'reference table name' SET CNT = 0 WHERE ID = 1. Then the transaction is synchronized to the third database 30.
[0103] After parsing the transaction from the third database 30, it was found that the transaction contained operations on the reference table. Furthermore, the synchronizable count reference value for the operations on the reference table was 0, which satisfies the condition of being less than or equal to 0. Therefore, the transaction was discarded and does not need to be synchronized to the first database 10. Since this transaction was initially generated by the first database 10, it indeed does not need to be written to the first database 10 again.
[0104] Using integer values as a reference for the number of times synchronization can be performed during modification operations makes the determination easier. Setting the first preset fixed value to 1 makes adjusting the modification operations even easier.
[0105] In one embodiment, the initial value is an integer. The step of adjusting the reference value of the number of times synchronization can be performed in the modification operation includes increasing the reference value of the number of times synchronization can be performed in the modification operation by a second preset fixed value; the preset condition is that it is greater than or equal to a second preset threshold, where the second preset threshold = the initial value + the second preset fixed value × (the number of databases in the database system - 2).
[0106] Reference Figure 5 As shown, in this embodiment, the data synchronization method of the database system generally includes:
[0107] Step S501: Determine whether the reference value of the number of times synchronization can be performed in the modification operation is less than or equal to the first preset threshold. If yes, proceed to step S502; otherwise, proceed to step S503.
[0108] Step S502: Discard the pending transaction.
[0109] Step S503: Increase the reference value for the number of times synchronization can be performed in the modification operation by a second preset fixed value. Specifically, if the reference value for the number of times synchronization can be performed is less than a second preset threshold, increase the reference value for the number of times synchronization can be performed in the modification operation by a second preset fixed value.
[0110] Because the initial value is an integer, and the first synchronization of a transaction only adds initial modification operations, after a transaction undergoes a synchronization that reduces the number of databases in the database system by one, the number of databases is adjusted by reducing it by two. Therefore, the second preset threshold is set as: Second Preset Threshold = Preset Initial Value - Second Preset Fixed Value × (Number of Databases in the Database System - 2).
[0111] Step S504: Synchronize the transactions to be executed to the target database.
[0112] Specifically, the initial value is preset to 1. The steps to adjust the reference value for the number of times synchronization can be performed in the modification operation include: incrementing the reference value for the number of times synchronization can be performed in the modification operation by 1. The second preset threshold is equal to the number of databases in the database system minus one.
[0113] Reference Figure 1 As shown in Table 1, taking a database system with three databases as an example, the preset initial value is 1, and the second preset threshold is 3-1, which is 2.
[0114] During data synchronization, a transaction is first parsed from the first database 10. This transaction does not contain any modification operations on the reference table. Therefore, before synchronizing this transaction to the second database 20, an initial modification operation on the reference table is added to this transaction:
[0115] The command `UPDATE 'reference table name' SET CNT = 1 WHERE ID = 1` modifies the value of the `CNT` column in the reference table, where `ID` is 1, to 1.
[0116] Then synchronize the transaction to the second database 20. After the transaction is synchronized to the second database 20, the second database 20 will write the original data of the transaction to itself, and at the same time, it will modify the reference table according to the initial modification operations added later, and modify the reference value of the number of synchronizations in the reference table to the preset initial value.
[0117] Then, after parsing the transaction from the second database 20, this transaction contains modification operations on the reference table. At this point, the synchronizable count reference value for the modification operations is 1, which is less than 2, failing to meet the preset condition, and the transaction needs to be synchronized to the third database 30. Before synchronizing the transaction to the third database 30, the synchronizable count reference value for the modification operations on the reference table contained in the transaction is incremented by 1, that is, the modification operation is modified to: UPDATE 'reference table name' SET CNT = 2 WHERE ID = 1. Then the transaction is synchronized to the third database 30.
[0118] After parsing the transaction from the third database 30, it was found that the transaction contained operations on the reference table. Furthermore, the reference value for the number of synchronization attempts for the reference table operations was 2, which is greater than or equal to 2. Therefore, the transaction was discarded and does not need to be synchronized to the first database 10. Since this transaction was initially generated by the first database 10, it indeed does not need to be written to the first database 10 again.
[0119] It should be noted that either letter changes or string changes can be used for tagging.
[0120] This embodiment also provides a machine-readable storage medium and a computer device. Figure 6 This is a schematic diagram of a machine-readable storage medium 100 according to an embodiment of the present invention. Figure 7 This is a schematic diagram of a computer device 200 according to an embodiment of the present invention.
[0121] The machine-readable storage medium 100 stores a machine-executable program 110 thereon, which, when executed by a processor, implements the data synchronization method of the database system of any of the above embodiments.
[0122] Computer device 200 may include memory 210, processor 220 and machine-executable program 110 stored on memory 210 and running on processor 220, and processor 220 implements the data synchronization method of the database system of any of the above embodiments when executing machine-executable program 110.
[0123] It should be noted that the logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be specifically implemented in any machine-readable storage medium for use by, or in conjunction with, an instruction execution system, apparatus or device (such as a computer-based system, a processor-based system or other system that can fetch and execute instructions from, an instruction execution system, apparatus or device).
[0124] For the purposes of this embodiment, the machine-readable storage medium 100 can be any means capable of containing, storing, communicating, propagating, or transmitting a program for use by or in conjunction with an instruction execution system, apparatus, or device. More specific examples (a non-exhaustive list) of computer-readable media include: an electrical connection (electronic device) having one or more wires, a portable computer disk drive (magnetic device), random access memory (RAM), read-only memory (ROM), erasable and editable read-only memory (EPROM or flash memory), fiber optic devices, and portable optical disc read-only memory (CDROM). Furthermore, the machine-readable storage medium 100 can even be paper or other suitable media on which the program can be printed, since the program can be obtained electronically, for example, by optically scanning the paper or other medium, followed by editing, interpreting, or otherwise processing as necessary, and then stored in a computer memory.
[0125] It should be understood that various parts of the present invention can be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented using software or firmware stored in memory and executed by a suitable instruction execution system.
[0126] Computer device 200 can be, for example, a server, desktop computer, laptop computer, tablet computer, or smartphone. In some examples, computer device 200 can be a cloud computing node. Computer device 200 can be described in the general context of computer system executable instructions (such as program modules) executed by a computer system. Typically, program modules can include routines, programs, object programs, components, logic, data structures, etc., that perform specific tasks or implement specific abstract data types. Computer device 200 can be implemented in a distributed cloud computing environment where tasks are performed by remote processing devices linked via a communication network. In a distributed cloud computing environment, program modules can reside on local or remote computing system storage media, including storage devices.
[0127] Computer device 200 may include a processor 220 adapted to execute stored instructions and a memory 210 that provides temporary storage space for the operation of said instructions during operation. The processor 220 may be a single-core processor, a multi-core processor, a computing cluster, or any other configuration. The memory 210 may include random access memory (RAM), read-only memory, flash memory, or any other suitable storage system.
[0128] The processor 220 can be connected via a system interconnect (e.g., PCI, PCI-Express, etc.) to an I / O interface (input / output interface) suitable for connecting the computer device 200 to one or more I / O devices (input / output devices). I / O devices may include, for example, a keyboard and indicating devices, where indicating devices may include a touchpad or touchscreen, etc. I / O devices may be built into the computer device 200 or may be external devices connected to the computing device.
[0129] The processor 220 may also be linked via a system interconnect to a display interface suitable for connecting the computer device 200 to a display device. The display device may include a display screen as a built-in component of the computer device 200. The display device may also include an external computer monitor, television, or projector connected to the computer device 200. Furthermore, a network interface controller (NIC) may be adapted to connect the computer device 200 to a network via a system interconnect. In some embodiments, the NIC may use any suitable interface or protocol (such as an Internet Minicomputer System Interface) to transmit data. The network may be a cellular network, a radio network, a wide area network (WAN), a local area network (LAN), or the Internet, etc. Remote devices may connect to the computing device via the network.
[0130] The flowchart provided in this embodiment is not intended to indicate that the operations of the method will be performed in any particular order, or that all operations of the method are included in every case. Furthermore, the method may include additional operations. Within the scope of the technical concept provided by the method in this embodiment, additional variations can be made to the above method.
[0131] Therefore, those skilled in the art should recognize that although numerous exemplary embodiments of the present invention have been shown and described in detail herein, many other variations or modifications conforming to the principles of the present invention can be directly determined or derived from the disclosure of the present invention without departing from the spirit and scope of the invention. Thus, the scope of the present invention should be understood and construed as covering all such other variations or modifications.
Claims
1. A data synchronization method for a database system, the database system comprising multiple databases forming a ring synchronization structure, the data synchronization method comprising: Create the same reference table in each of the databases, and the reference table is used to record a reference value for the number of times a transaction can be synchronized; Obtain the pending transactions for the target database, wherein the target database is one of the two databases to be written to during data synchronization; Read the modification operations on the reference table in the transaction to be executed, wherein the modification operations are used to modify the reference value of the number of times synchronization is recorded in the reference table; Determine whether the reference value of the number of times synchronization is possible in the modification operation meets the preset conditions. If it meets the preset conditions, discard the transaction to be executed. Before the step of reading the modification operations on the reference table in the transaction to be executed, the following are included: Determine whether the transaction to be executed contains modification operations on the reference table. If so, execute the step of reading the modification operations on the reference table in the transaction to be executed. If not, generate an execution transaction based on the transaction to be executed, and add an initial modification operation for the reference table to the execution transaction. The initial modification operation is used to modify the reference value of the number of times that can be synchronized in the reference table to a preset initial value. Synchronize the executed transaction to the target database; Following the step of determining whether the number of synchronizations in the modification operation meets the preset conditions, the following is included: If the preset conditions are not met, adjust the reference value of the number of times the modification operation can be synchronized so that the reference value of the number of times the modification operation can be synchronized approaches the preset conditions at a fixed frequency. Synchronize the pending transactions to the target database.
2. The data synchronization method of a database system according to claim 1, wherein, The preset initial value is an integer; The step of adjusting the reference value for the number of times synchronization can be performed in the modification operation includes: The reference value for the number of times synchronization can be reduced in the modification operation is reduced according to the first preset fixed value; The preset condition is less than or equal to a first preset threshold, where the first preset threshold = the preset initial value - the first preset fixed value × (the number of databases in the database system - 2).
3. The data synchronization method for a database system according to claim 2, wherein, The preset initial value is equal to the number of databases in the database system minus two; The step of adjusting the reference value for the number of times synchronization can be performed in the modification operation includes: Decrement the reference value of the number of times synchronization is possible in the modification operation by 1; The first preset threshold is 0.
4. The data synchronization method for a database system according to claim 1, wherein, The preset initial value is an integer; The step of adjusting the reference value for the number of times synchronization can be performed in the modification operation includes: Increase the reference value for the number of times the modification operation can be synchronized according to the second preset fixed value; The preset condition is greater than or equal to the second preset threshold, where the second preset threshold = the preset initial value + the second preset fixed value × (the number of databases in the database system - 2).
5. The data synchronization method for a database system according to claim 4, wherein, The preset initial value is 1; The step of adjusting the reference value for the number of times synchronization can be performed in the modification operation includes: Increment the reference value for the number of times synchronization is possible in the modification operation by 1; The second preset threshold is equal to the number of databases in the database system minus one.
6. The data synchronization method for a database system according to claim 1, wherein, The step of generating an execution transaction based on the transaction to be executed includes: The pending transactions are temporarily stored until the number of temporarily stored pending transactions reaches a preset number; All temporarily stored pending transactions are merged into the execution transaction.
7. A machine-readable storage medium having a machine-executable program stored thereon, the machine-executable program, when executed by a processor, implementing the data synchronization method of the database system according to any one of claims 1 to 6.
8. A computer device comprising a memory, a processor, and a machine-executable program stored in the memory and running on the processor, wherein the processor, when executing the machine-executable program, implements a data synchronization method for a database system according to any one of claims 1 to 6.
Citation Information
Patent Citations
Method and system for inter-database data synchronization
CN104376017A
Database synchronization method, device and system and electronic equipment
CN112199447A
