Data synchronization method, apparatus, device, storage medium, and program product

By configuring caching middleware for devices, data change statements are stored and executed in real time, solving the problem of data loss during cross-data center data synchronization and improving the efficiency and reliability of synchronization.

CN119766828BActive Publication Date: 2026-07-03MASHANG CONSUMER FINANCE CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
MASHANG CONSUMER FINANCE CO LTD
Filing Date
2024-12-23
Publication Date
2026-07-03

AI Technical Summary

Technical Problem

In a cross-data center service architecture, data loss can easily occur during the data synchronization process between the primary and backup data centers, resulting in low reliability of the cross-data center service architecture.

Method used

By configuring independent caching middleware for multiple devices, data change statements from other devices are stored in real time. In the event of a device failure, unexecuted change statements are retrieved from the caching middleware for synchronization, ensuring that the data is executed locally before providing services.

Benefits of technology

It improves the efficiency and accuracy of data synchronization, reduces data loss, and enhances the reliability of data synchronization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119766828B_ABST
    Figure CN119766828B_ABST
Patent Text Reader

Abstract

The present disclosure relates to the technical field of data processing, and provides a data synchronization method, device and equipment, a storage medium and a program product. The data synchronization method comprises the following steps: obtaining a first data change statement in a first cache middleware of a first device, wherein the first data change statement is sent to the first cache middleware by a second device; executing the first data change statement in a first database of the first device to change data in the first database; in the case that the second device fails, obtaining a first data change statement that is not successfully executed from the first cache middleware, and after changing the data in the first database according to the first data change statement that is not successfully executed, starting the first device to provide services for an application program in the second device. The present scheme can reduce the amount of data loss in the data synchronization process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of data processing technology, and more specifically, to a data synchronization method, a data synchronization device, a computer-readable storage medium, a computer program product, and an electronic device. Background Technology

[0002] The cross-data center service structure adopts a primary and backup data center deployment method to provide services to the outside world. Under normal circumstances, the primary data center provides services to the outside world, while the backup data center is in standby mode. When the primary data center fails, the backup data center enters the operating state and temporarily takes over the services provided by the primary data center.

[0003] In a cross-datacenter service architecture, data from the primary datacenter during normal operation needs to be synchronized to the backup datacenter so that the backup datacenter can provide accurate services in the event of a primary datacenter failure. However, data loss can easily occur during the synchronization process between the primary and backup datacenters, resulting in low reliability of the cross-datacenter service architecture.

[0004] It should be noted that the information disclosed in the background section above is only used to enhance the understanding of the background of this disclosure, and therefore may include information that does not constitute prior art known to those skilled in the art. Summary of the Invention

[0005] The purpose of this disclosure is to provide a data synchronization method and apparatus, a computer-readable storage medium, a computer program product, and an electronic device, thereby at least partially improving the problem of data loss during data synchronization.

[0006] Other features and advantages of this disclosure will become apparent from the following detailed description, or may be learned in part from practice of this disclosure.

[0007] According to a first aspect of this disclosure, a data synchronization method is provided, applied to a first device, the first device being configured with a first caching middleware. The method includes: obtaining a first data modification statement from the first caching middleware, wherein the first data modification statement is sent to the first caching middleware by a second device; modifying data in a first database based on the first data modification statement; in the event of a failure in the second device, obtaining a first data modification statement that was not successfully executed from the first caching middleware; modifying data in the first database based on the first data modification statement that was not successfully executed; and starting the first device to provide services to an application in the second device.

[0008] According to a second aspect of this disclosure, a data synchronization apparatus is provided, applied to a first device, the first device being configured with a first caching middleware. The apparatus includes: a first acquisition module configured to acquire a first data modification statement from the first caching middleware, wherein the first data modification statement is sent to the first caching middleware by a second device; a first modification module configured to modify data in a first database based on the first data modification statement; a fault handling module configured to acquire, in the event of a fault in the second device, an unexecuted first data modification statement from the first caching middleware; a continued modification module configured to modify data in the first database based on the unexecuted first data modification statement; and a fault recovery module configured to start the first device to provide services to applications in the second device.

[0009] According to a third aspect of this disclosure, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the data synchronization method as described in the first aspect of the above embodiments.

[0010] According to a fourth aspect of this disclosure, a computer program product comprising instructions is provided that, when run on a computer, causes the computer to perform the steps of the data synchronization method as described in the first aspect.

[0011] According to a fifth aspect of the present disclosure, an electronic device is provided, comprising: a processor; and a storage device for storing one or more programs, which, when executed by the one or more processors, cause the one or more processors to implement the data synchronization method as described in the first aspect of the above embodiments.

[0012] As can be seen from the above technical solutions, the data synchronization method, data synchronization device, and computer-readable storage medium, computer program product, and electronic device implementing the data synchronization method in the exemplary embodiments of this disclosure have at least the following advantages and positive effects:

[0013] In some embodiments of the present disclosure, the first device can obtain the first data change statement synchronized by the second device from the first cache middleware of the first device, and change the data in the first database of the first device according to the first data change statement. In the event of a failure of the second device, before starting the first device to provide services to the application in the second device, the first device continues to obtain the first data change statement that was not successfully executed from the first cache middleware. After all the first data change statements that were not successfully executed in the first cache middleware are successfully executed in the first database, the first device then provides services to the application of the second device. Compared with related technologies, on the one hand, the first data change statement of the second device can be synchronized to the first device in real time through the first cache middleware of the first device. Since the data reading efficiency of the cache middleware is high, the efficiency of data synchronization can be improved. On the other hand, this disclosure achieves data synchronization by first synchronizing the first data change statement of the second device to the first cache middleware of the first device, and then the first device retrieves and executes the first data change statement from the first cache middleware. In this way, since the first data change statement of the second device has been synchronized to the first cache middleware of the first device, even if the second device fails, the first device can still retrieve the first data change statement that has been generated in the second device but has not yet been executed in the first database of the first device from the first cache middleware. After execution, the first device is started to provide services to the application of the second device, thereby reducing data loss and improving the accuracy and reliability of data synchronization.

[0014] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this disclosure. Attached Figure Description

[0015] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure. It is obvious that the drawings described below are merely some embodiments of this disclosure, and those skilled in the art can obtain other drawings based on these drawings without any inventive effort.

[0016] Figure 1 This diagram illustrates a system architecture diagram of cross-data center disaster recovery in a related art according to an exemplary embodiment of this disclosure;

[0017] Figure 2 A schematic diagram of an exemplary system architecture to which embodiments of the present disclosure may be applied is shown;

[0018] Figure 3 A flowchart illustrating a data synchronization method according to an exemplary embodiment of this disclosure is shown.

[0019] Figure 4 This illustration shows a flowchart of a method for obtaining a first data modification statement in a first cache middleware based on the order indicated by a first sequence identifier, according to an exemplary embodiment of the present disclosure.

[0020] Figure 5 This illustration shows a flowchart of a method for reading a first data modification statement from a first cache middleware according to a first thread and a second thread, as shown in an exemplary embodiment of the present disclosure.

[0021] Figure 6 This illustration shows a flowchart of another method for obtaining a first data modification statement in a first cache middleware based on the order indicated by a first sequence identifier, according to an exemplary embodiment of the present disclosure.

[0022] Figure 7 This diagram illustrates a flowchart of reading a second data change statement according to an exemplary embodiment of this disclosure;

[0023] Figure 8 A flowchart illustrating another method for reading a second data change statement according to an exemplary embodiment of this disclosure is shown.

[0024] Figure 9 This diagram illustrates a data synchronization process for primary and backup computer room equipment according to an exemplary embodiment of this disclosure;

[0025] Figure 10 This diagram illustrates the composition of a data synchronization device according to an exemplary embodiment of the present disclosure.

[0026] Figure 11 A schematic diagram of the structure of an electronic device in an exemplary embodiment of this disclosure is shown. Detailed Implementation

[0027] Exemplary embodiments will now be described more fully with reference to the accompanying drawings. However, these exemplary embodiments can be implemented in many forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided to make this disclosure more comprehensive and complete, and to fully convey the concept of the exemplary embodiments to those skilled in the art. The described features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. In the following description, numerous specific details are provided to give a full understanding of embodiments of this disclosure. However, those skilled in the art will recognize that the technical solutions of this disclosure can be practiced with one or more of these specific details omitted, or other methods, components, apparatus, steps, etc., can be employed. In other instances, well-known technical solutions are not shown or described in detail to avoid obscuring various aspects of this disclosure.

[0028] The terms “a,” “an,” “the,” and “the” are used in this specification to indicate the presence of one or more elements / components / etc.; the terms “including” and “having” are used to indicate an open-ended inclusion and to mean that there may be other elements / components / etc. in addition to the listed elements / components / etc.; the terms “first” and “second” are used only as markings and are not a limitation on the number of objects.

[0029] Furthermore, the accompanying drawings are merely illustrative of this disclosure and are not necessarily drawn to scale. The same reference numerals in the drawings denote the same or similar parts, and therefore repeated descriptions of them will be omitted. Some block diagrams shown in the drawings are functional entities and do not necessarily correspond to physically or logically independent entities. These functional entities may be implemented in software, in one or more hardware modules or integrated circuits, or in different network and / or processor devices and / or microcontroller devices.

[0030] In scenarios where a single server provides business services, if that server fails, the services it provides will cease to function properly. Therefore, cross-datacenter disaster recovery is an essential component of software design. Cross-datacenter disaster recovery can be understood as follows: under normal circumstances, the primary datacenter equipment provides services; when the primary datacenter equipment fails, the backup datacenter equipment takes over and temporarily provides services.

[0031] Cross-data center disaster recovery system architecture in related technologies, such as Figure 1 As shown, the specific implementation process can include: Data synchronization tool A in the main data center 11 (a data synchronization tool can be understood as an application in the main data center capable of data synchronization) retrieves the SQL (Structured Query Language) for data modification from the database cluster logs of the main data center 11, such as binlog (binary log file), and then sends the retrieved SQL statement to data synchronization tool B in the disaster recovery backup data center 12. Upon receiving an SQL statement, data synchronization tool B in the disaster recovery backup data center 12 executes the SQL statement in the MySQL database B of the disaster recovery backup data center 12. After execution, it sends a success message to data synchronization tool A in the main data center 11. Upon receiving this message, data synchronization tool A in the main data center 11 retrieves the next SQL statement from the cache of the main data center 11 and sends the next SQL statement to data synchronization tool B in the disaster recovery backup data center 12, and so on.

[0032] Executing SQL in the database of disaster backup server room 12 inevitably takes time. This means that while 1,000 change SQL statements may have been generated and executed in the main data center, only 600 SQL statements may have been executed in the database of the disaster backup server room, leaving 400 waiting to be sent and executed, which means there is a data delay.

[0033] In the event of data synchronization delay, if the equipment in the primary data center fails, causing a network interruption between the equipment in the primary and backup data centers, the business system will be restored using disaster recovery tools in the disaster backup data center. In this case, the delayed data will be lost. For example, the data generated by the 400 SQL statements that were not synchronized to the disaster backup data center mentioned above will be lost. Ultimately, the disaster backup data center may not be able to continue to provide accurate services to the outside world.

[0034] Based on this, this disclosure configures independent caching middleware for multiple devices. The current device's caching middleware stores newly generated data change statements from other devices in real time. The current device then retrieves these statements from its own caching middleware and executes the changes in its own database. Because the newly generated data change statements from other devices are stored in the current device's caching middleware in real time, even if any of the devices fails during data synchronization, the normal devices can still retrieve the change statements generated by the failed device but not yet successfully executed on the normal device from their own caching middleware and execute them. After execution, the normal device then resumes its service to the application of the failed device, thereby reducing data loss due to data synchronization delays and improving the accuracy of data synchronization.

[0035] Figure 2 The diagram illustrates an exemplary system architecture to which embodiments of this disclosure can be applied, namely, a data synchronization method and apparatus provided by this disclosure, which can be applied to... Figure 2 In the system architecture of the exemplary application environment shown.

[0036] like Figure 2As shown, the system architecture 200 may include a first terminal device 210, a first server 220, a second terminal device 230, a second server 240, a first cache middleware 250, and a second cache middleware 260. The first terminal device 210 and the second terminal device 230 may be terminal devices such as smartphones, tablets, desktop computers, laptops, and smart wearable devices. The first server 220 and the second server 240 generally refer to the backend system providing services related to the data synchronization method in this exemplary embodiment, and may be a single server or a cluster of multiple servers. The first terminal device 210, the second terminal device 230, the first server 220, the second server 240, the first cache middleware 250, and the second cache middleware 260 can be connected via wired or wireless communication links to exchange data.

[0037] In one exemplary embodiment, the data synchronization method of this disclosure can be executed by the first server 220. Correspondingly, a data synchronization device can be set in the first server 220 to implement corresponding module functions. For example, when a user operates an application on the second terminal device 230, this operation can generate a first data modification statement that modifies data in the second database of the second server 240. The second server 240 can send the generated first data modification statement to the first cache middleware 250. The first server 220 can obtain the first data modification statement from the first cache middleware 250 and then execute the obtained first data modification statement in the first database of the first server 220 to modify the data in the first database of the first server 220. If the second server 240 fails, the first server 220 can continue to obtain first data modification statements that have not yet been successfully executed from the first cache middleware. After the first data modification statements that have not yet been successfully executed in the first cache middleware are executed, the first server 220 can be restarted to provide services to the application in the second terminal device 230.

[0038] In another exemplary embodiment, the data synchronization method described above can also be executed by the second server 240. Correspondingly, a data synchronization device can also be installed in the second server 240 to implement the corresponding module functions. The specific implementation of the data synchronization method executed by the second server 240 can refer to the specific implementation of the first server 220 described above, except that the technical terms "first terminal device 210" are replaced with "second terminal device 230," "first server 220" with "second server 240," and "first cache middleware 250" with "second cache middleware 260," which will not be elaborated further here.

[0039] It should be understood that Figure 1The number of terminal devices and servers shown is merely illustrative. Depending on implementation needs, any number of terminal devices and servers can be used. For example, the first server 220 or the second server 240 can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms.

[0040] For example, Figure 3 This diagram illustrates a data synchronization method in an exemplary embodiment of the present disclosure, applied to a first device. The first device is configured with a first caching middleware. (Refer to...) Figure 3 The method includes:

[0041] Step S310: Obtain the first data modification statement from the first cache middleware, wherein the first data modification statement is sent to the first cache middleware by the second device;

[0042] Step S320: Based on the first data modification statement, modify the data in the first database;

[0043] Step S330: In the event of a failure of the second device, retrieve the first data modification statement that was not successfully executed from the first cache middleware;

[0044] Step S340: Based on the first data modification statement that was not successfully executed, modify the data in the first database;

[0045] Step S350: Start the first device to provide services to the application in the second device.

[0046] exist Figure 3In the technical solution provided by the embodiment shown, the first device can obtain the first data change statement synchronized by the second device from the first cache middleware of the first device, and change the data in the first database of the first device according to the first data change statement. In the event of a failure of the second device, before starting the first device to provide services to the application in the second device, the first device continues to obtain the first data change statement that was not successfully executed from the first cache middleware. After all the first data change statements that were not successfully executed in the first cache middleware are successfully executed in the first database, the first device then provides services to the application of the second device. Compared with related technologies, on the one hand, the first data change statement of the second device can be synchronized to the first device in real time through the first cache middleware of the first device. Since the data reading efficiency of the cache middleware is high, the efficiency of data synchronization can be improved. On the other hand, this disclosure achieves data synchronization by first synchronizing the first data change statement of the second device to the first cache middleware of the first device, and then the first device retrieves and executes the first data change statement from the first cache middleware. In this way, since the first data change statement of the second device has been synchronized to the first cache middleware of the first device, even if the second device fails, the first device can still retrieve the first data change statement that has been generated in the second device but has not yet been executed in the first database of the first device from the first cache middleware. After execution, the first device is started to provide services to the application of the second device, thereby reducing data loss and improving the accuracy and reliability of data synchronization.

[0047] Below, we will first provide a detailed explanation of the specific implementation method of "step S310, obtaining the first data modification statement in the first cache middleware".

[0048] In one exemplary implementation, the first data change statement is sent to the first cache middleware by the second device after the second device reads the first data change statement generated in the second device in real time. The first data change statement includes the data change statement generated when changing the data in the second database of the second device.

[0049] In one exemplary embodiment, the first device may include a first network device, such as a first server or a first server cluster, and the second device may include a second network device, such as a second server or a second server cluster. In one exemplary embodiment, servers deployed in the same data center belong to the same device, such as a first server cluster including multiple first servers, which can be collectively referred to as the first data center device.

[0050] The first data modification statement can include second database operation statements that add, delete, or modify data in the second database of the second device. It should be noted that the second database operation statements can also include statements that query data in the second database; however, since query operations do not cause any changes to the data in the second database, query operations within the second database operation statements are not considered first data modification statements.

[0051] In one exemplary implementation, in response to a second database operation statement being a first data modification statement and successfully executed in the second database of the second device, the second device sends the first data modification statement to the first device's first cache middleware. That is, the first data modification statement stored in the first device's first cache middleware is a first data modification statement that has already been successfully executed in the second device. This avoids the problem of data synchronization inconsistency between the first and second devices caused by a change that failed to execute successfully in the second device but was synchronized to and executed successfully in the first device, thereby improving the accuracy of data synchronization.

[0052] For example, a second device can monitor its second log file, such as a binlog file. When a new first data change statement is generated in the second log file, it immediately stores this newly generated first data change statement in the first device's first cache middleware. Since the second log file records data change statements corresponding to changes that have already occurred in the second device, the change statements in the second log file are definitely second change statements that have been successfully changed in the second device. Therefore, the second change statement generated in the second log file of the second device can be sent to the first device's first cache middleware.

[0053] For example, a data synchronization tool can be configured in the second device. This tool can enable database RAW mode (in a database, RAW is a variable-length binary data type). When any first data modification statement is executed in the second database of the second device, the corresponding first data modification statement will be recorded in the binlog file. The database and table information that has been changed, such as the database identifier and table identifier, can be parsed from the first data modification statement. The data synchronization tool in the second device can continuously read the first data modification statements from the binlog and send them to the first cache middleware of the first device.

[0054] The specific implementation of the data synchronization tool in the second device reading the first data change statement and sending the read first data change statement to the first cache middleware of the first device can be referred to in steps S710 to S750 and steps S910 to S830 below, which will not be repeated here.

[0055] In one exemplary embodiment, the first caching middleware and the second caching middleware mentioned below can both include any caching middleware that can be deployed independently, such as redis, memcached, Varnish, Ehcache, etc. This exemplary embodiment does not impose any special limitations on this.

[0056] The first cache middleware and the second cache middleware mentioned below can both include a cache middleware cluster. That is, the first cache middleware can include a first cache middleware cluster, and the second cache middleware can include a second cache middleware cluster. This exemplary embodiment does not limit the features in this regard.

[0057] In one exemplary embodiment, the first device may include any one of multiple devices, and the second device may include other devices besides the first device. The multiple devices can be distinguished as primary and backup devices. A primary device can be configured with one or more backup devices. Under normal circumstances, only the primary device provides services. In the event of a failure of the primary device, the backup devices are activated to provide services. Alternatively, the multiple devices may not be distinguished as primary or backup devices; that is, under normal circumstances, all devices can provide services. For example, device 1 provides service 1, device 2 provides service 2, or device 1 provides service 1 to user group 1, and device 2 provides service 1 to user group 2, etc. Each of the multiple devices deploys a database, and each device is configured with a corresponding caching middleware. The databases configured in the multiple devices can be relational databases, such as the aforementioned MySQL database, or non-relational databases, such as document databases or graph databases. This exemplary embodiment does not impose any special limitations on this.

[0058] In one exemplary implementation, the second device is configured with a first domain name pointing to the network address of the first caching middleware. The second device can access the first caching middleware through the first domain name to send the first data change statement to the first caching middleware configured by the first device.

[0059] For example, a first domain name pointing to the network address of the first cache middleware can be pre-configured in the second device. Taking the network protocol address of the first cache middleware, i.e., the IP address, as IP1, as an example, the first domain name "a.redis.db.lo" can be pre-configured in the second device and set to point to the network protocol address IP1 of the first cache middleware.

[0060] In one exemplary implementation, the first data change statement is configured with a first sequence identifier, which indicates the generation time order of the first data change statement in the second device.

[0061] For example, for the first data change statement generated in the second device, an incremental and non-repeating value can be generated as the first sequence identifier of the first data change statement generated in the second device. In other words, the first sequence identifier value of the first data change statement generated earlier is less than the first sequence identifier value of the first data change statement generated later. In this way, the order in which the first data change statements are generated can be determined by the size relationship of the first sequence identifier values.

[0062] For example, a fixed-digit, incrementing, and non-repeating numerical value can be used as the first sequence identifier for the first data change statement generated in the second device. Taking a fixed-digit number of 18 as an example, the first 13 digits can be a millisecond-level generation timestamp, meaning the first 13 digits of the first sequence identifier for the first data change statement can be the millisecond-level generation timestamp of that first data change statement. The last 5 digits can be numbers incrementing from 00000 to 99999. If the maximum value of the last 5 digits reaches 100,000, the first sequence identifier can be automatically extended to 19 digits, and then the last 6 digits can start counting from 000000 again, and so on.

[0063] Of course, other methods can also be used to generate the first sequence identifier, such as the number of digits of the value corresponding to the first sequence identifier being indeterminate, directly setting the first sequence identifier of the first generated first data change statement to 1, and incrementing the value of the first sequence identifier of the subsequently generated first data change statements by 1 unit, etc. The first sequence identifier can also be generated by referring to the method for generating the second sequence identifier described below. This exemplary embodiment does not impose any special limitations on this.

[0064] For example, one specific implementation of step S210 may include: obtaining a first data change statement in the first cache middleware based on the order indicated by the first sequence identifier.

[0065] For a given user, the changes to the database resulting from their actions also follow a specific order. By configuring a first sequence identifier for the first data change statement, both the first data change statement and the order in which they were generated can be stored in the first cache middleware. Thus, when the first device modifies data in its first database based on the first data change statement, the first data change statement is executed in the order it was generated, ensuring accurate data synchronization.

[0066] For example, the second device can access the first device's first cache middleware using the first domain name "a.redis.db.lo" and store the first data modification statement with the first sequence identifier as a string in the first cache middleware. During storage, a ZSET structure can be used. The key is the user account and database identifier corresponding to the database to which the newly generated first data modification statement belongs, the value is the first data modification statement, and the score is the first sequence identifier. For instance, for a specific first data modification statement, the command "zadd key score value" can be used to store it in the first cache middleware.

[0067] Of course, the first data change statement with the first sequence identifier can also be sent to the first cache middleware in other ways, and this exemplary embodiment does not impose any special limitations on this.

[0068] In one exemplary implementation, each of the first data change statements carries a database identifier. Based on this, exemplaryly, Figure 4 This diagram illustrates a flowchart of a method for retrieving a first data modification statement from a first cache middleware based on a first sequence identifier, according to an exemplary embodiment of this disclosure. (See also:) Figure 4 The method may include steps S410 to S440. Wherein:

[0069] In step S410, when the first data change statement in the first cache middleware is obtained for the first time, the first data change statements with the same database identifier in the first cache middleware are divided into the same group to obtain the first group and the first database identifier corresponding to each first group.

[0070] For example, as mentioned earlier, the database identifier corresponding to the first data modification statement in the first cache middleware can be parsed using the key stored at time. When the first device retrieves the first data modification statement from the first cache middleware for the first time, the first data modification statements currently included in the first cache middleware can be divided into the same group, thereby obtaining one or more first groups. The first database identifier corresponding to each first group is the database identifier carried by the first data modification statement in that group. Because the first data modification statements in the same group carry the same database identifier, each first group corresponds to a different database identifier, and the database identifiers corresponding to each group are different.

[0071] For example, at the first moment when the first data modification statement is retrieved from the first cache middleware, there are currently 200 first data modification statements in the first cache middleware. These 200 first data modification statements are divided into 5 groups according to the database identifier, resulting in 5 first group categories. The first database identifier corresponding to each first group category is the database identifier carried by the first data modification statements included in that group category.

[0072] In step S420, the first number of the first group is counted, the first number of first threads are started, each of the first threads corresponds to a first database identifier, and each first thread is instructed to read the first data change statement included in the first group indicated by its corresponding first database identifier.

[0073] For example, the number of first groups can be counted to obtain a first quantity. The first device can start a first quantity of first threads to read the first data modification statements included in each first group. Taking the first quantity as 5 as mentioned above, 5 first threads can be started, and the first database identifiers corresponding to the 5 first groups can be assigned to the 5 first threads respectively. Each first thread corresponds to one first database identifier, and the first database identifiers between different first threads are different. Each first thread can read the first data modification statements included in the first group indicated by the first database identifier assigned to it, according to the first order identifier.

[0074] In step S430, a first database identifier set is obtained based on the first database identifier.

[0075] For example, the set of all first database identifiers obtained when the first data modification statement in the first cache middleware is retrieved for the first time can be used as the first database identifier set. When the first data modification statement in the first cache middleware is retrieved for the i-th time, the first database identifier set needs to be updated. When the first data modification statement in the first cache middleware is retrieved for the (i+1)-th time, the number of newly started threads and the database identifiers corresponding to the newly started threads can be determined based on the updated first database identifier set after the i-th retrieval of the first data modification statement. Here, i is an integer greater than 1.

[0076] In step S440, when the first data change statement in the first cache middleware is obtained for the i-th time, a second thread is started according to the matching situation between the database identifier corresponding to the first data change statement to be read and the first database identifier in the current first database identifier set, so as to read the first data change statement to be read according to the first thread and the second thread.

[0077] In one exemplary implementation, as previously described, i is an integer greater than 1. That is, the process of retrieving the first data modification statement from the first cache middleware for the second time and each subsequent time can be implemented through step S440.

[0078] Below, in conjunction with Figure 5 The specific implementation of step S440 will be described below. For example, Figure 5 This diagram illustrates a flowchart of a method for reading a first data modification statement from a first cache middleware according to a first thread and a second thread, as shown in an exemplary embodiment of this disclosure. (See also:) Figure 5 The method may include steps S510 to S560.

[0079] in:

[0080] In step S510, the first data change statements to be read that have the same database identifier are divided into the same group to obtain the second group and the second database identifier corresponding to each second group.

[0081] In one exemplary implementation, after the first data modification statement in the first cache middleware is successfully executed in the first database of the first device, a first flag can be added to the successfully executed first data modification statement to distinguish between executed and unexecuted first data modification statements. Thus, when the first data modification statement in the first cache middleware is retrieved for the i-th time, the current first data modification statement to be read in the i-th time can be determined based on the next first data modification statement after the last first data modification statement retrieved in the (i-1)-th time (i.e., the previous time) up to the last first data modification statement in the second cache middleware at the i-th retrieval time.

[0082] In another exemplary implementation, after the first data modification statement in the first cache middleware is successfully executed in the first database of the first device, the successfully executed first data modification statement can be deleted from the first cache middleware. Thus, when the first data modification statement in the first cache middleware is retrieved for the i-th time, all the first data modification statements included in the first cache middleware at the i-th retrieval time are the first data modification statements to be read currently.

[0083] For example, when retrieving the first data modification statement from the first cache middleware for the i-th time, the first data modification statements to be read can be grouped according to their database identifiers. Statements with the same database identifier are grouped into the same group, thus obtaining one or more second groups and a second database identifier corresponding to each second group. Similarly, as with the first groups, the second database identifier corresponding to each second group is the database identifier carried by the first data modification statement within that group.

[0084] In step S520, the second database identifier is matched with the first database identifier in the current first database identifier set. If the match is successful, proceed to step S530; otherwise, proceed to step S540.

[0085] For example, as mentioned earlier, the first database identifier must be updated each time the first data modification statement is retrieved from the first cache middleware. When the first data modification statement is retrieved from the first cache middleware for the i-th time, the current set of first database identifiers is the set of first database identifiers updated when the first data modification statement was retrieved for the (i-1)-th time (i.e., the previous time).

[0086] The second database identifier obtained when retrieving the first data modification statement from the first cache middleware for the i-th time is matched with each first database identifier in the current set of first database identifiers. Based on the matching results, the third and fourth database identifiers are determined. Then, the set of first database identifiers is updated according to the fourth database identifier.

[0087] In step S530, the second database identifier is determined as the third database identifier.

[0088] For example, a second database identifier that matches the first database identifier in the current first database identifier set can be used as the third database identifier.

[0089] In step S540, the second database identifier is determined as the fourth database identifier.

[0090] For example, a second database identifier that fails to match the first database identifier in the current first database identifier set can be used as the fourth database identifier.

[0091] In step S550, a second number of the fourth database identifiers is counted, and the second number of second threads are started. Each second thread corresponds to one of the fourth database identifiers, and each second thread is used to read the first data change statement included in the second grouping group indicated by its corresponding fourth database identifier.

[0092] For example, since the fourth database identifier is different from the first database identifier, a new second thread can be configured separately for each fourth database identifier. Each second thread is used to read the first data change statement included in the second group indicated by its corresponding fourth database identifier.

[0093] In one exemplary implementation, after determining the fourth database identifier, the fourth database identifier can be added as a new first database identifier to the first database identifier set to update the first database identifier set.

[0094] For example, after the fourth database identifier is determined during the i-th retrieval of the first data change statement, the first database identifier set can be updated based on the fourth database identifier. The updated first database identifier set can be used as the current first database identifier set during the (i+1)-th retrieval of the first data change statement. In other words, after configuring a second thread for the fourth database identifier, the first data change statement corresponding to the fourth database identifier can be processed by the existing thread.

[0095] In step S560, based on the first thread corresponding to the first database identifier that successfully matches the third database identifier, the third database identifier indicates the first data change statement included in the second group.

[0096] For example, since the third database identifier and the first database identifier are the same, the first data change statement in the second group indicated by the corresponding third database identifier can be read according to the first thread corresponding to the first database identifier that matches the third database identifier.

[0097] In one exemplary implementation, each thread in the first thread and the second thread reads the first data modification statements included in its corresponding group based on the order indicated by the first sequence identifier. That is, when each thread reads the first data modification statement indicated by its corresponding database identifier, it can read the first generated first data modification statement first, and then read the first generated first data modification statement later, according to the order indicated by the second sequence identifier of the first data modification statement. For data with time dependencies, this can ensure the accuracy of data updates.

[0098] In this disclosure, through steps S410 to S440 described above, the number of threads can be started based on the number of database identifier types included in the key of the first data modification statement in the first cache middleware. That is, each thread reads only the first data modification statement corresponding to one type of database identifier; in other words, each thread reads only the first data modification statement corresponding to a specific database identifier. Since data between different database identifiers does not have a specific order, while data with the same database identifier may have a specific order, starting threads according to the number of database identifier types can improve efficiency while ensuring the accuracy of data synchronization.

[0099] For example, Figure 6 This diagram illustrates a flowchart of another method for retrieving a first data modification statement from a first cache middleware based on the order indicated by a first sequence identifier, according to an exemplary embodiment of this disclosure. (See also:) Figure 6 The method includes steps S610 to S630. Wherein:

[0100] In step S610, the first database identifier carried by the first data change statement to be obtained is matched with the set of database identifiers corresponding to the first cache middleware.

[0101] In one exemplary implementation, the database identifier set is determined based on a second database identifier carried by a first data change statement that has been read from the first cache middleware.

[0102] For example, each time the first data change statement is read, the first database identifier carried by the first data change statement to be obtained can be matched with the corresponding set of database identifiers in the first cache middleware. If the match fails, the first database identifier carried by the first data change statement can be added to the set of database identifiers. In this way, the set of database identifiers stores the second database identifiers obtained after deduplication of the first database identifiers carried by the first data change statement that has been read.

[0103] In step S620, if the first database identifier matches the set of database identifiers, the first thread reads the first data change statement based on the second database identifier in the set of database identifiers that matches the first database identifier.

[0104] In one exemplary embodiment, the database in this disclosure includes a database cluster, which includes multiple databases. Each database has a corresponding database identifier, and the first data change statement corresponding to each database also carries the corresponding database identifier. Thus, the database to which the first data change statement belongs is determined by the first database identifier carried by each first data change statement.

[0105] In one exemplary implementation, each database is configured with a dedicated thread, which is used to read the first data modification statement from that database. This allows the first data modification statements from different databases to be read simultaneously by multiple threads, improving data synchronization efficiency. Furthermore, each thread can read the first data modification statements from its corresponding database according to the order in which the modification statements were generated, ensuring the accuracy of data reading and thus guaranteeing the accuracy of data synchronization.

[0106] In one exemplary implementation, when reading the first data change statement, since not all databases may generate new data change statements simultaneously, a corresponding thread can be configured for the databases that have already generated data change statements during the reading process. This allows the corresponding thread to be started to read the already generated data change statements. In other words, some databases have already started their corresponding threads to read the data change statements, while other databases, having not yet generated any data change statements during the reading process, have not yet started their corresponding threads.

[0107] As mentioned earlier, the database identifier set records the database identifiers carried by the first data modification statement that has been read. In other words, the databases indicated by the database identifiers recorded in the database identifier set have all started their corresponding threads. Therefore, when reading subsequent data, for the first data modification statement that carries the database identifiers in the database identifier set, the already started thread can be used to read the first data modification statement directly.

[0108] In other words, if the first database identifier matches the set of database identifiers, it means that a corresponding thread has already been started to read the first data modification statement carrying the first database identifier. Therefore, the first thread corresponding to the first database identifier that has already been started can be used directly to read the first data modification statement.

[0109] In step S630, if the first database identifier does not match the database identifier set, the database identifier set is updated according to the first data identifier, and a second thread is started to read the first data change statement.

[0110] For example, a specific implementation of step S630 may include: counting a first number of first database identifiers that do not match the database identifier set, starting the first number of second threads; assigning the first database identifiers that do not match the database identifier set to the first number of second threads, instructing each second thread to read the first data change statement indicated by the first database identifier assigned to it; adding the first database identifiers that do not match the database identifier set to the database identifier set, thereby updating the database identifier set.

[0111] For ease of description, let's take the first database identifier that matches successfully as the third database identifier and the first database identifier that fails to match as the fourth database identifier. For example, we can first match the first data modification statement to be obtained with the set of first database identifiers. If the match is successful, the third database identifier can be directly assigned to the first thread corresponding to the successfully matched second database identifier, and the first thread is instructed to read the assigned first data modification statement. If the match fails, all fourth database identifiers can be deduplicated. Then, the first number of fourth database identifiers remaining after deduplication is counted, and a first number of new threads (second threads) are started. The first number of fourth database identifiers obtained after deduplication are assigned to the first number of second threads, with each second thread corresponding to one fourth database identifier. Each second thread is instructed to read the first data modification statement carrying its assigned fourth database identifier.

[0112] Since a new thread is started for the fourth database identifier when the match fails, meaning that the database indicated by the fourth database identifier already has a started thread, the fourth database identifier can be added to the above database identifier set to update the database identifier set.

[0113] In one exemplary implementation, each thread reads the first data modification statements according to the order indicated by the first sequence identifier. That is, both the first and second threads read the first data modification statements of their respective databases sequentially according to the order indicated by the first sequence identifier and the chronological order in which the first data modification statements were generated. Thus, since there is no time dependency between the data modification statements of different databases, each first thread and second thread can read the first data modification statements simultaneously, improving data synchronization efficiency. Each database also corresponds to a specific thread, which reads the first data modification statements of that database sequentially according to the generation order, ensuring that the data order within each database is not disrupted, thereby guaranteeing the accuracy of data synchronization. In other words, this disclosure can improve data synchronization efficiency while ensuring data synchronization accuracy.

[0114] For example, the first device is configured with a second domain name pointing to the network address of the first cache middleware. Based on this, an exemplary implementation of step S310 may include: the first device accesses the first cache middleware through the second domain name and obtains the first data modification statement in the first cache middleware.

[0115] For example, a second domain name can be pre-configured in the first device to access the network protocol address IP1 of the first cache middleware. In this way, the first device can access the first cache middleware of the first device through the second domain name, thereby obtaining the first data change statement synchronized from the second device by the first cache middleware.

[0116] For example, the second domain name can be "redis.db.lo", where the network protocol address resolved by the domain name "redis.db.lo" is the network protocol address IP1 of the first caching middleware. The specific content of the second domain name can be customized according to requirements, and this exemplary implementation does not impose any special limitations on it.

[0117] The following describes the specific implementation of "Step S320, modifying the data in the first database based on the first data modification statement".

[0118] In one exemplary embodiment, a first device is configured with a first database, and a second device is configured with a second database. The first database is used to store relevant data in an application on the first device, and the second database is used to store relevant data in an application on the second device.

[0119] For example, after the first device receives the first data modification statement, it can execute the statement in its first database to modify the data there. Similarly, a data synchronization tool can be configured for the first device to execute the first data modification statement in its first database and modify the data there.

[0120] In one exemplary implementation, after executing the first data modification statement in the first database of the first device to modify the data in the first database, the successfully executed first data modification statement is deleted from the first cache middleware, or a first flag is added to the first cache middleware for the successfully executed first data modification statement. This distinguishes between successfully executed and unsuccessfully executed first data modification statements, facilitating data synchronization during subsequent fault recovery. Simultaneously, because some first data modification statements may have been executed but not successfully during the synchronization process, marking the successfully executed first data modification statements, rather than marking the executed first data modification statements, further improves the accuracy of data synchronization.

[0121] For example, a first device can obtain a first data modification statement from a first caching middleware, and then execute the first data modification statement in the first device's first database. After the first data modification statement is successfully executed in the first device's first database, the first device can call the aforementioned second domain name to access the first caching middleware, thereby deleting the successfully executed first data modification statement from the first caching middleware, or adding a first flag to the successfully executed first data modification statement. The first flag can be of any form, and this exemplary embodiment does not impose any special limitations on it.

[0122] The following is a detailed description of the specific implementation of "step S330, in the event of a failure of the second device, obtaining the first data change statement that was not successfully executed from the first cache middleware".

[0123] In one exemplary implementation, under normal circumstances, services can be provided to applications on the first device through the first device, and services can be provided to applications on the second device through the second device. In the event of a failure of the second device, the first device can be activated to replace the second device and continue to provide services to applications on the second device.

[0124] For example, if the second device malfunctions and cannot provide services, the application on the second device can be launched from the first device, and the application on the second device can continue to provide services through the first device.

[0125] In this disclosure, before starting the application of the second device on the first device, the first device may first determine whether there is a first data modification statement that has not been successfully executed in the first cache middleware. If there is, the first device will continue to retrieve the first data modification statement that has not been successfully executed in the first database when the second device fails from the first cache middleware.

[0126] The specific implementation of retrieving the first data modification statement that failed to be executed from the first cache middleware can be found in the relevant content of retrieving the first data modification statement from the first cache middleware in step S310 above, and will not be repeated here.

[0127] The following is a detailed description of the specific implementation of "step S340, modifying the data in the first database based on the first data modification statement that was not successfully executed".

[0128] For example, the first database may include a first database cluster. After obtaining a first data change statement that was not successfully executed in the first database from the first cache middleware, the first device may execute the first data change statement in the database indicated by the target database identifier in the first database cluster of the first device according to the target database identifier carried by the obtained first data change statement, thereby changing the data in the first database.

[0129] For example, other details regarding the modification of data in the first database based on the first data modification statement that failed to execute can be found in step S320 above, and will not be repeated here.

[0130] The following is a detailed description of the specific implementation of "step S350, starting the first device to provide services to the application in the second device".

[0131] For example, after all the first data change statements that were not successfully executed in the first cache middleware have been successfully executed, the application in the second device can be started in the first device, and the services in the second device can continue to be provided through the first device.

[0132] In other words, in this disclosure, after the second device fails, before starting the first device to perform disaster recovery on the second device, a first data change statement compensation operation can be performed on the first device. This means that all first data change statements that have been synchronized to the first cache middleware of the first device but were not successfully executed in the first database of the first device when the second device failed are successfully executed before the first device is started to provide services to the applications in the second device. In this way, even if there is a data synchronization delay due to the slow execution of the first data change statements, it can ensure that more first data change statements are successfully executed in the first database to the greatest extent possible, reducing the amount of data loss caused by data synchronization delays.

[0133] In one exemplary scenario, after the second device's malfunction is resolved, the service of the application originally provided by the second device can be switched back to the second device. During the second device's malfunction recovery process, newly generated second data modification statements in the first device must also be synchronized to the second device's second cache middleware, so that the second device can modify the data in the second database according to the second data modification statements synchronized from the first device to the second cache middleware. After all the second data modification statements generated in the first device during the second device's malfunction have been successfully executed in the second device, the second device can be started to continue providing services to the application originally provided by the second device.

[0134] In another exemplary embodiment, the first device and the second device can provide different services to the outside world at the same time. When both the first device and the second device are operating normally, the first device and the second device can synchronize each other's data change statements so that if either one fails, the other can continue to provide services to the application of the failed device at any time.

[0135] Based on this, in an exemplary embodiment, the first device may also read a second data modification statement from the first device's first log file and send the read second data modification statement to the second device's second cache middleware; wherein, the second data modification statement includes a statement generated in the first device that modifies data in the first database of the first device.

[0136] For example, the first device can generate a first database operation statement in response to operation instructions from an application on the first device. Based on this first database operation statement, it can manipulate the data in the first database. After successful operation, it determines whether the first database operation statement is a first data modification statement that modifies the data in the first database. If so, the first modification statement is stored in the first device's first log file, such as the first device's binlog file. For instance, the type of the first database operation statement can be used to determine whether it is a first data modification statement. If the type of the first database operation statement is any one of add, delete, or modify, then it is determined to be a second data modification statement and can be recorded in the first device's first log file. The first device can monitor its first log file. When a new second data modification statement is detected in the first log file, it can immediately read the newly generated second data modification statement and send it to the second device's second cache middleware.

[0137] For example, Figure 7 This diagram illustrates a flowchart of a method for reading a second data change statement according to an exemplary embodiment of this disclosure. (See also:) Figure 7 The method may include steps S710 to S750. Wherein:

[0138] In step S710, at the first read time, a third number of second data change statements generated in the first log file between the second read time and the first read time is determined.

[0139] In one exemplary implementation, the first read time and the second read time are adjacent, and the first read time is located after the second read time.

[0140] In one exemplary implementation, the first device can read the second data change statement from the first device's first log file in real time.

[0141] Real-time reading can be understood as continuously monitoring the first log file, and when a new second data change statement is detected, it reads the newly generated second data change statement from the first log file.

[0142] Real-time reading can also be understood as continuously reading newly generated second data change statements from the first log file at the minimum reading interval supported by the computer device. Different devices have different hardware and performance characteristics; therefore, the time interval for continuously reading second data change statements from the first log file will also differ. For example, a high-performance computer device can support a minimum time interval of 0.05 seconds, meaning it can continuously read second data change statements from the first log file in real time at 0.05-second intervals. A low-performance computer device may support a minimum time interval of 0.1 seconds, meaning it can continuously read second data change statements from the first log file in real time at 0.1-second intervals.

[0143] For example, the first device can determine the second data change statement generated in the first log file between the first and second read times at the first read time, and count the number of the second data change statements to obtain the third number.

[0144] In step S720, if the third quantity is greater than or equal to the first preset value, the fourth quantity of the third thread is obtained based on the third quantity and the preset amount of data read by each third thread.

[0145] For example, if the third quantity is greater than or equal to the first preset value, it indicates that there are a large number of second data change statements that need to be read. In this case, multi-threaded simultaneous reading can be used to improve reading efficiency, thereby improving data synchronization efficiency, reducing data loss due to synchronization delay, and improving the accuracy of data synchronization.

[0146] However, due to the sequential nature of the second data modification statements, the first data modification statement generated later must be executed before the second data modification statement generated later can be executed, thus avoiding data synchronization errors caused by an incorrect order. Therefore, multiple threads need to be allocated to ensure that the reading order of the second data modification statements remains unchanged. At the same time, considering that increasing the number of threads can improve data reading efficiency, it also increases computer overhead; therefore, the number of threads needs to be reasonably arranged according to the actual situation.

[0147] Based on this, if the third quantity is less than the first preset value, the first device can directly use a single thread to read the second data change statement. If the third quantity is greater than or equal to the first preset value, the first device can determine the aforementioned fourth quantity by rounding up the quotient between the third quantity of the second data change statement to be read and the preset amount of data that each third thread can read. Then, the number of third threads is determined based on the fourth quantity.

[0148] For example, if the third quantity of the second data change statement to be read is 550, and the preset data quantity read by each third thread is 100, then the fourth quantity is 6, which means the quantity of the third thread can be determined to be 6.

[0149] In step S730, the line in the first log file where the second data change statement generated between the second read time and the first read time is located is determined, and the first line interval is determined based on the line where it is located.

[0150] For example, the line in the first log file containing the second data change statement generated between the second and first read times can be determined. Based on the line interval consisting of the minimum and maximum values ​​within that line, the first line interval is determined. That is, the first line interval can be used to characterize the position of the second data change statement that the first device needs to read in the first log file at the first read time.

[0151] In step S740, according to the preset data volume, the rows in the first row interval are divided sequentially to obtain the fourth number of second row intervals with sequential identifiers.

[0152] In this case, the largest row in the first second row interval is smaller than the smallest row in the second subsequent row interval.

[0153] Taking a preset data volume of 100 as an example, with the first row interval being rows 100 to 570, the fourth quantity is 5. The row interval consisting of rows 100 to 199 is the first second row interval, the row interval consisting of rows 200 to 299 is the second second row interval, the row interval consisting of rows 300 to 399 is the third second row interval, the row interval consisting of rows 400 to 499 is the fourth second row interval, and the row interval consisting of rows 500 to 570 is the fifth second row interval.

[0154] In this sequence, the first second row interval precedes the second, the second precedes the third, the third precedes the fourth, and the fourth precedes the fifth. That is, the order of these five second row intervals is: first, second, third, fourth, and fifth. Each second row interval can be assigned a sequence identifier to indicate its order. For example, the sequence identifiers can be configured according to the ascending direction of natural numbers, such as the first second row interval having a sequence identifier of 1, the second having a sequence identifier of 2, and so on. The order of the second row intervals can be indicated by the magnitude of the natural numbers; that is, the second row interval with the smaller sequence identifier comes first, and the second row interval with the larger sequence identifier comes later.

[0155] In step S750, the fourth number of third threads are started, and the fourth number of second row intervals with sequential identifiers are assigned to the fourth number of third threads. The second data change statement is read according to the third threads.

[0156] Below, for reference Figure 8 A specific implementation of step S750 will be described. For example, Figure 8 A flowchart illustrating another method for reading a second data change statement according to an exemplary embodiment of this disclosure is shown. (See reference...) Figure 8 The method may include steps S910 to S830. Wherein:

[0157] In step S910, a thread identifier is configured for each of the third threads.

[0158] In one exemplary implementation, a thread identifier is used to indicate the third sequence identifier of the second row interval corresponding to the third thread.

[0159] For example, the third sequence identifier of the second row interval can be assigned to the third thread, thus configuring a thread identifier for each third thread. If there are 5 third threads, these 5 threads correspond to the 5 second row intervals mentioned above, and their thread identifiers can be the sequence identifiers 1, 2, 3, 4, and 5 respectively. In this way, the third thread can determine its corresponding second row interval based on its thread identifier. For example, the third thread with thread identifier 1 corresponds to the first second row interval with third sequence identifier 1, the third thread with thread identifier 2 corresponds to the second second row interval with third sequence identifier 2, and so on.

[0160] In step S920, according to the third sequence identifier indicated by the thread identifier, the fourth number of second line intervals with sequential order are assigned to the corresponding third threads, and the second line intervals read by each third thread in the first log file are determined.

[0161] As mentioned earlier, the second row interval corresponding to each thread can be determined based on the third sequence identifier indicated by the thread identifier, and thus the corresponding second row interval can be assigned to the corresponding third thread. In this way, each third thread can obtain the location range of the second data modification statement it reads from the first log file based on its corresponding second row interval.

[0162] In step S830, each third thread is instructed to read the second data change statement in its corresponding second row interval.

[0163] For example, each third thread can read the first data modification statement within its corresponding second row interval. Each third thread then reads the second data modification statements within its corresponding second row interval in ascending order of row number. In the first log file, the second data modification statements generated first are stored there. Therefore, the row number determines the chronological order of the second data modification statements' generation, allowing them to be read sequentially according to their row numbers.

[0164] For example, a second order identifier can be configured for the second data change statement read by the third thread according to the third order identifier indicated by the thread identifier corresponding to the third thread. The second order identifier in the last second data change statement read by the fourth thread is less than the second order identifier in the first second data change statement read by the fifth thread. The fourth thread is the third thread whose third order identifier is earlier, and the fifth thread is the third thread whose third order identifier is later. The second data change statement with the second order identifier is sent to the second cache middleware of the second device.

[0165] For example, between different third threads, the second order identifier can be configured for the read second data modification statements in ascending order of thread identifier. Within each third thread, the second order identifier of the read second data modification statements can be determined according to the reading order, that is, the second order identifier of the second data modification statements read first is less than the second order identifier of the second data modification statements read later.

[0166] For example, the second sequence identifiers of the 100 second data change statements read by the first third thread are 0 to 99, the second sequence identifiers of the 100 second data change statements read by the second third thread are 100 to 199, and so on.

[0167] For example, each third thread is numbered sequentially starting from 1 according to the reading order to obtain the candidate second order identifier of the second data change statement read within each third thread. Then, the thread identifier of the thread and the sum of the number of all previously generated third threads are added before the highest bit of each candidate second order identifier to obtain a new target value. This new target value is used as the second order identifier of each second data change statement.

[0168] Taking a preset data volume of 100 for each third thread as an example, during the first read, three third threads are generated. The second sequence identifiers of the second data change statements read by the first third thread are 100 to 199, the second sequence identifiers of the second data change statements read by the second third thread are 200 to 299, and the second sequence identifiers of the second data change statements read by the third third thread are 300 to 399. During the second read, two third threads, D and E, are generated. The thread identifier of D is 1, and the thread identifier of E is 2. The second sequence identifiers of the second data change statements read by the third thread D are 400 to 499, and the second sequence identifiers of the second data change statements read by the third thread E are 500 to 599. During the third read, two third threads, F and G, are generated. The thread identifier of F is 1, and the thread identifier of G is 2. The second sequence identifiers of the second data change statements read by the third thread F are 600 to 699, and the second sequence identifiers of the second data change statements read by the third thread G are 700 to 799, and so on.

[0169] In one exemplary implementation, the third sequence identifier of the last second data change statement read by the last third thread at the second read time is less than the third sequence identifier of the first second data change statement read by the first third thread at the first read time.

[0170] That is, the third sequence identifier of the last second data change statement read by the last third thread at the second read time can be increased by 1 unit, and used as the third sequence identifier of the first second data change statement read by the first third thread at the first read time.

[0171] In this way, multiple third threads can improve reading efficiency, thereby helping to improve data synchronization efficiency. The size relationship of the second sequence identifiers can also determine the order in which the second data change statements read by different third threads are generated; that is, second data change statements with smaller second sequence identifiers are generated first, and those with larger second sequence identifiers are generated later. Therefore, in the second device, the second data change statements can be obtained sequentially according to the generation time indicated by the second sequence identifiers, and the obtained second data change statements can be executed in the second database to ensure the accuracy of data synchronization.

[0172] In one exemplary implementation, after each third thread reads the second data change statement, it can determine whether synchronization is needed based on a preset database identifier. If the database identifier corresponding to the database to which the read second data change statement belongs is different from the preset database identifier, it can be determined that synchronization is not needed, and the second data change statement can be ignored, continuing to read the next second data change statement. Otherwise, the read second data change statement is temporarily stored in a data file. After all third threads have finished reading, a second sequence identifier is configured for the second data change statements temporarily stored in the data file, and the data file configured with the second sequence identifier is sent to the second cache middleware.

[0173] The preset database identifier includes the database identifier corresponding to the database that needs to be synchronized. It is customized according to user needs, and this exemplary embodiment does not impose any special limitations on it.

[0174] If the second sequence identifier is determined based on the target value mentioned above, each third thread can read a second data change statement. If it is determined that the database identifier of the second data change statement is the same as the preset database identifier, the second sequence identifier can be configured for the second data change statement according to the target value. Then, the second data change statement with the configured second sequence identifier can be directly sent to the second cache middleware without waiting for other third threads to finish reading before configuring the second sequence identifier and sending it to the second cache middleware, thereby further improving data synchronization efficiency.

[0175] In another exemplary embodiment, the second device may also perform steps S310 to S350 as described above. In this way, even if the first device malfunctions, the second device can continue to provide services to the application of the first device. The specific implementation of steps S310 to S350 by the second device can be referenced to the first device; simply interchange all the technical terms related to the first device and the second device in step S310. Further details will not be provided here.

[0176] In other words, in the embodiments corresponding to steps S310 to S350 above, the first device is described as a backup server room for the second device. In practice, the first device and the second device can have a primary and backup relationship, that is, the second device can be a backup server room for the first device, and the data of the first device can also be synchronized to the second device. In this way, when the first device fails, the second device can continue to provide services for the application of the first device.

[0177] Below, we'll use a scenario where the first device is the primary data center device and the second device is the backup data center device. Each device independently deploys a Redis cluster. The IP address for Redis cluster 1 on the primary data center device is IP1, and the IP address for Redis cluster 2 on the backup data center device is IP2. Two DNS resolution addresses are pre-added to the primary data center device: `redis.db.lo->IP1` and `b.redis.db.lo->IP2`. This means the primary data center device can access Redis cluster 1 via `redis.db.lo` and Redis cluster 2 via `b.redis.db.lo`. Similarly, two DNS resolution addresses are pre-added to the backup data center device: `redis.db.lo->IP2` and `a.redis.db.lo->IP1`. This means the backup data center device can access Redis cluster 2 via `redis.db.lo` and Redis cluster 1 via `a.redis.db.lo`. Data modification statements generated on the primary data center device are stored in its binary log file (binlog). The database used is MySQL. (See reference...) Figure 9 This paper describes the process of a method for synchronizing data from main server room equipment to backup server room equipment, as disclosed in this paper.

[0178] For example, during data synchronization, for the main data center device 91, the data synchronization tool 911 in the main data center device 91 can continuously parse newly generated change statements that modify data in the MySQL A database of the main data center from the binlog file of the main data center device 91. The data synchronization tool 911 can read the second data change statement generated in the main data center device 91 and configure a second sequence identifier for the second data change statement according to the above steps S710 to S750. Then, the main data center device uses the domain name b.redis.db.lo to access the Redis cluster 2 of the backup data center device 92, and stores the second data change statement with the second sequence identifier generated in the main data center device into the Redis cluster 2 in the form of a string. When storing, a ZSET structure is used, where the key is the account and database identifier to which the current data change statement belongs, the value is the current data change statement, and the score is the second sequence identifier. When the data change statement is executed, there is an order requirement for a certain user. In this disclosure, the Redis ZSET structure is selected to store the data change statement. The ZSET structure has the ability to automatically sort according to the score value. The command to add a record to a ZSET structure is: zadd keyscorevalue.

[0179] For the backup data center device 92, the data synchronization tool 921 of the backup data center device can access the Redis cluster 2 of the backup data center through the redis.db.lo domain name. According to the methods in steps S410 to S440 above or according to the methods in steps S610 to S630 above, it obtains the second data change statement synchronized from the main data center device from the Redis cluster 2, executes the obtained second data change statement in the MysqlB database of the backup data center device, and deletes the successfully executed data change statement from the Redis cluster 2 after successful execution.

[0180] For the disaster recovery tool 922 of the standby data center device 92, before starting the application on the standby data center device 92, it calls the data synchronization tool 921 of the standby data center device to perform data change statement compensation operations. Specifically, the disaster recovery tool 922 calls the data synchronization tool 921. After receiving the call request, the data synchronization tool 921 accesses the redis.db.lo domain name and retrieves the data change statements synchronized to the standby data center device 92 but not yet executed from Redis cluster 2. During execution, under the same account with the same database identifier, the second data change statements are sorted according to their score values, and executed on the MySQLB cluster of the standby data center device 92 in ascending order of score value. After each successful execution of a second data change statement, the corresponding second data change statement can be deleted from Redis cluster 2. Once all the second data change statements in the Redis cluster 2 of the backup data center device have been successfully executed, the backup data center device 92 can perform basic condition checks, such as whether the domain name network used by the application is reachable. After the checks are passed, the application of the main data center device is started in the backup data center device 92, and the backup data center device 92 continues to provide services to the application of the main data center device.

[0181] Figure 9 The document also illustrates the data synchronization process from backup equipment to main equipment, such as... Figure 9 As shown by the dotted line, the specific process can be referred to as the synchronization process from the main equipment room to the backup equipment room, which will not be elaborated here.

[0182] Using asynchronous synchronous data, it is difficult to ensure that data is not lost due to physical factors (such as network transmission time). However, compared with related technologies, this disclosure deploys caching middleware in multiple data centers, storing each other's data change statements in real time. Since the time consumed in storing the data change statements in the caching middleware is almost negligible compared to the time consumed in executing the data change statements, even in the event of abnormal changes such as lack of indexes that cause the execution time of change statements to increase, the amount of data loss during the data synchronization process is minimized, and the accuracy of data synchronization is improved.

[0183] Meanwhile, this disclosure employs a multi-threaded approach to improve data synchronization efficiency when reading data from both primary and backup data center equipment. Furthermore, to ensure accuracy, the multi-threading mode has been optimized based on factors such as data volume and data generation order, thus improving both efficiency and accuracy in data synchronization.

[0184] Furthermore, it should be noted that the above figures are merely illustrative representations of the processes included in the method according to exemplary embodiments of the present invention, and are not intended to be limiting. It is readily understood that the processes shown in the above figures do not indicate or limit the temporal order of these processes. Additionally, it is readily understood that these processes may be executed synchronously or asynchronously, for example, in multiple modules.

[0185] Furthermore, exemplary embodiments of this disclosure also provide a data synchronization apparatus applied to a first device, the first device being configured with a first caching middleware, referencing... Figure 10 As shown, the first acquisition module 1010 is configured to acquire a first data modification statement from the first cache middleware, wherein the first data modification statement is sent to the first cache middleware by the second device; the first modification module 1020 is configured to modify data in the first database based on the first data modification statement; the fault handling module 1030 is configured to acquire the first data modification statement that was not successfully executed from the first cache middleware when the second device fails; the continued modification module 1040 is configured to modify data in the first database based on the first data modification statement that was not successfully executed; and the fault recovery module 1050 is configured to start the first device to provide services to the application in the second device.

[0186] In one exemplary implementation, the first data change statement is configured with a first sequence identifier, which is used to indicate the generation time order of the first data change statement in the second device; obtaining the first data change statement in the first cache middleware includes: obtaining the first data change statement in the first cache middleware based on the order indicated by the first sequence identifier.

[0187] In one exemplary implementation, each first data change statement carries a database identifier; the step of obtaining the first data change statements in the first cache middleware based on the order indicated by the first sequence identifier includes: matching the first database identifier carried by the first data change statement to be obtained with a set of database identifiers corresponding to the first cache middleware, wherein the set of database identifiers is determined based on the second database identifier carried by the first data change statements already read from the first cache middleware; if the first database identifier matches the set of database identifiers, reading the first data change statement based on a first thread corresponding to the second database identifier in the set of database identifiers that matches the first database identifier, wherein the first thread is a started thread; if the first database identifier does not match the set of database identifiers, updating the set of database identifiers based on the first data identifier, and starting a second thread to read the first data change statement; wherein each thread reads the first data change statements based on the order indicated by the first sequence identifier.

[0188] In one exemplary implementation, when the first database identifier does not match the database identifier set, updating the database identifier set according to the first database identifier and starting a second thread to read the first data change statement includes: counting a first number of first database identifiers that do not match the database identifier set, starting the first number of second threads; assigning the first database identifiers that do not match the database identifier set to the first number of second threads, and instructing each second thread to read the first data change statement indicated by the first database identifier assigned to the second thread; adding the first database identifiers that do not match the database identifier set to the database identifier set, and updating the database identifier set.

[0189] In one exemplary embodiment, the apparatus further includes a first sending module, which can be configured to: read a second data modification statement from a first log file of a first device, and send the read second data modification statement to a second cache middleware of a second device; wherein the second data modification statement includes a statement generated in the first device that modifies data in the first database.

[0190] In one exemplary implementation, reading the second data change statement from the first log file of the first device includes: at a first reading time, determining a third number of second data change statements generated in the first log file between a second reading time and the first reading time, wherein the first reading time and the second reading time are adjacent and the first reading time is after the second reading time; if the third number is greater than or equal to a first preset value, obtaining a fourth number of third threads based on the third number and a preset amount of data read by each third thread; determining the line in the first log file where the second data change statement generated between the second reading time and the first reading time is located, and determining a first line interval based on the line; dividing the lines in the first line interval sequentially according to the preset amount of data to obtain the fourth number of second line intervals with sequential identifiers; starting the fourth number of third threads, assigning the fourth number of second line intervals with sequential identifiers to the fourth number of third threads, and reading the second data change statement according to the third threads.

[0191] In one exemplary implementation, the step of assigning the fourth number of second line intervals with sequential identifiers to the fourth number of third threads for real-time reading of second data change statements by the third threads includes: configuring a thread identifier for each third thread, the thread identifier indicating a third sequential identifier of the second line interval corresponding to the third thread; assigning the fourth number of second line intervals with sequential identifiers to the corresponding third threads according to the third sequential identifier indicated by the thread identifier, determining the second line interval read by each third thread in the first log file; and instructing each third thread to read the second data change statement within the second line interval corresponding to the third thread.

[0192] In one exemplary implementation, the step of sending the read second data change statement to the second cache middleware of the second device includes: configuring a second order identifier for the second data change statement read by the third thread according to a third order identifier indicated by the thread identifier corresponding to the third thread, wherein the second order identifier in the last second data change statement read by the fourth thread is less than the second order identifier in the first second data change statement read by the fifth thread, the fourth thread is the third thread whose third order identifier is earlier than the thread identifier, and the fifth thread is the third thread whose third order identifier is later than the thread identifier; and sending the second data change statement with the second order identifier to the second cache middleware of the second device.

[0193] The specific details of each part of the above-mentioned device have been described in detail in the method section of the implementation plan. For any undisclosed details, please refer to the implementation plan of the method section, and therefore will not be repeated here.

[0194] It should be noted that although several modules or units for the device used to perform actions have been mentioned in the detailed description above, this division is not mandatory. In fact, according to exemplary embodiments of this disclosure, the features and functions of two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided and embodied by multiple modules or units.

[0195] Furthermore, although the steps of the method in this disclosure are described in a specific order in the accompanying drawings, this does not require or imply that the steps must be performed in that specific order, or that all the steps shown must be performed to achieve the desired result. Additional or alternative steps may be omitted, multiple steps may be combined into one step, and / or a step may be broken down into multiple steps.

[0196] Exemplary embodiments of this disclosure also provide a computer program product. The computer program product includes a computer program that, when executed by a processor, implements the data synchronization method described above.

[0197] In one embodiment, the computer program product can be a tangible product containing a computer program, such as a computer-readable storage medium storing the computer program. The readable storage medium can be a storage medium based on electrical, magnetic, optical, electromagnetic, infrared, or other signals, including but not limited to: random access memory (RAM), read-only memory (ROM), magnetic tape, floppy disk, flash memory, hard disk drive (HDD), solid-state drive (SSD), etc. For example, the computer program product can be implemented as a non-volatile storage medium storing the computer program, such as read-only memory, NAND flash memory, etc.

[0198] In one implementation, the computer program product can be an intangible product containing a computer program. For example, the computer program product can be implemented as a virtual digital product, such as an executable file, installation package, or other digital file storing the computer program.

[0199] Computer program code can be written in one or more programming languages. Examples of programming languages ​​include C, Java, C++, and Python. Program code can execute entirely on the user's computing device, partially on the user's computing device, or as a standalone software package. It can also execute partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving remote computing devices, the remote computing device can be connected to the user's computing device via any type of network, such as a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computing device (e.g., via an internet connection provided by a mobile network operator).

[0200] Computer programs can be carried or transmitted via signals such as electricity, magnetism, light, electromagnetic fields, and infrared radiation. Electronic devices can convert signals carrying computer programs into digital signals, thereby running the computer programs. When a computer program runs on an electronic device, its code causes the electronic device to execute (more specifically, the processor of the electronic device to execute) the method steps of various exemplary embodiments of this disclosure. For example, the data synchronization method described above can be executed, which includes the following steps: obtaining a first data modification statement from a first cache middleware, wherein the first data modification statement is sent to the first cache middleware by a second device; modifying data in the first database based on the first data modification statement; in the event of a failure of the second device, obtaining the first data modification statement that was not successfully executed from the first cache middleware; modifying the data in the first database based on the first data modification statement that was not successfully executed; and starting the first device to provide services to the application in the second device.

[0201] By executing the above method steps through a computer program, on the one hand, the first data change statement of the second device can be synchronized to the first device in real time through the first cache middleware of the first device, thereby improving the efficiency of data synchronization; on the other hand, by first synchronizing the first data change statement of the second device to the first cache middleware of the first device in real time, and then the first device retrieves and executes the first data change statement from the first cache middleware to achieve data synchronization, since the first data change statement of the second device has been synchronized to the first cache middleware of the first device in real time, even if the second device fails, the first device can still retrieve the first data change statement generated by the second device but not yet executed in the first database of the first device from the first cache middleware. After execution, the first device can then start providing services to the application of the second device, thereby reducing data loss.

[0202] Exemplary embodiments of this disclosure also provide an electronic device, such as the first terminal device 210, the second terminal device 230, the first server 220, or the second server 240 described above. The electronic device may include a processor and a memory. The memory stores executable instructions for the processor, such as computer programs. The processor executes these executable instructions to perform the method steps of the various exemplary embodiments of this disclosure. Furthermore, the electronic device may also include a display for displaying a graphical user interface.

[0203] The following is for reference. Figure 11 The electronic device is illustrated by way of a general-purpose computing device. It should be understood that... Figure 11 The electronic device 11000 shown is merely an example and should not be construed as limiting the functionality and scope of the embodiments disclosed herein.

[0204] like Figure 11 As shown, the electronic device 1100 may include: a processor 1110, a memory 1120, a bus 1130, an I / O (input / output) interface 1140, a network adapter 1150, and a display 1160.

[0205] Memory 1120 may include volatile memory, such as RAM 1121 and cache unit 1122, and may also include non-volatile memory, such as ROM 1123. Memory 1120 may also include one or more program modules 1124, such program modules 1124 including, but not limited to: operating system, one or more application programs, other program modules, and program data. Each or some combination of these examples may include an implementation of a network environment. For example, program module 1124 may include the modules in the above-described apparatus.

[0206] The processor 1110 may include one or more processing units, such as an AP (Application Processor), a modem processor, a GPU (Graphics Processing Unit), an ISP (Image Signal Processor), a controller, an encoder, a decoder, a DSP (Digital Signal Processor), a baseband processor, and / or an NPU (Neural-Network Processing Unit).

[0207] The processor 1110 can be used to execute executable instructions stored in the memory 1120, such as the data synchronization method described above, which includes the following steps: obtaining a first data modification statement from the first cache middleware, wherein the first data modification statement is sent to the first cache middleware by the second device; modifying data in the first database based on the first data modification statement; in the event of a failure of the second device, obtaining the first data modification statement that was not successfully executed from the first cache middleware; modifying data in the first database based on the first data modification statement that was not successfully executed; and starting the first device to provide services to the application in the second device.

[0208] The above method is implemented by a computer program, and the steps of the method are executed by the computer program. On the one hand, the first data change statement of the second device can be synchronized to the first device in real time through the first cache middleware of the first device, so as to improve the efficiency of data synchronization. On the other hand, by first synchronizing the first data change statement of the second device to the first cache middleware of the first device in real time, and then the first device retrieves and executes the first data change statement from the first cache middleware to achieve data synchronization, since the first data change statement of the second device has been synchronized to the first cache middleware of the first device in real time, even if the second device fails, the first device can still retrieve the first data change statement generated by the second device but not yet executed in the first database of the first device from the first cache middleware. After execution, the first device can then start to provide services to the application of the second device, thereby reducing data loss.

[0209] Bus 1130 is used to connect different components of electronic device 1100 and may include a data bus, an address bus and a control bus.

[0210] Electronic device 1100 can communicate with one or more external devices 1200 (e.g., keyboard, mouse, external controller, etc.) through I / O interface 1140.

[0211] Electronic device 1100 can communicate with one or more networks via network adapter 1150. For example, network adapter 1150 can provide mobile communication solutions such as 3G / 4G / 5G, or wireless communication solutions such as wireless LAN, Bluetooth, and near-field communication. Network adapter 1150 can communicate with other modules of electronic device 1100 via bus 1130.

[0212] Electronic device 1100 can display a graphical user interface via display 1160, such as displaying the graphical user interface of an application in a first device or a second device.

[0213] although Figure 11 As not shown in the diagram, other hardware and / or software modules may also be configured in the electronic device 1100, including but not limited to: microcode, device drivers, redundant processors, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.

[0214] Furthermore, the above figures are merely illustrative of the processes included in the method according to exemplary embodiments of this disclosure and are not intended to be limiting. It is readily understood that the processes shown in the above figures do not indicate or limit the temporal order of these processes. Additionally, it is readily understood that these processes may be executed synchronously or asynchronously, for example, in multiple modules.

[0215] As can be seen from the above, the technical solutions disclosed herein can be implemented as methods, apparatus, systems, computer program products, storage media, electronic devices, etc. Those skilled in the art will understand that various aspects of this disclosure can be specifically implemented in the following forms: a completely hardware implementation, a completely software implementation (including firmware, microcode, etc.), or a combination of hardware and software implementations, which may be referred to as "circuit," "module," or "system," respectively.

[0216] It should be understood that this disclosure is not limited to the specific methods, steps, or structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. Those skilled in the art will readily conceive of other embodiments based on the specific implementations provided in this disclosure. Therefore, the specific implementations provided in this disclosure are merely exemplary, and the scope and spirit of this disclosure are indicated by the claims, and should cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary technical means in the art not disclosed in this disclosure.

Claims

1. A data synchronization method, characterized in that, Applied to a first device, the first device being configured with a first caching middleware, the method includes: Obtain the first data modification statement from the first cache middleware, wherein the first data modification statement is sent to the first cache middleware by the second device; Based on the first data modification statement, the data in the first database is modified; In the event of a failure of the second device, retrieve the first data modification statement that was not successfully executed from the first cache middleware; Based on the first data modification statement that failed to execute, the data in the first database is modified; The first device is started to provide services to the application in the second device.

2. The data synchronization method according to claim 1, characterized in that, The first data change statement is configured with a first sequence identifier, which is used to indicate the generation time order of the first data change statement in the second device; The step of obtaining the first data modification statement in the first cache middleware includes: Based on the order indicated by the first sequence identifier, the first data modification statement in the first cache middleware is obtained.

3. The data synchronization method according to claim 2, characterized in that, Each of the first data modification statements carries a database identifier; the step of retrieving the first data modification statements from the first cache middleware based on the order indicated by the first sequence identifier includes: The first database identifier carried by the first data change statement to be obtained is matched with the database identifier set corresponding to the first cache middleware. The database identifier set is determined according to the second database identifier carried by the first data change statement that has been read from the first cache middleware. If the first database identifier matches the set of database identifiers, the first data modification statement is read based on the first thread corresponding to the second database identifier that matches the first database identifier, where the first thread is a started thread; If the first database identifier does not match the database identifier set, the database identifier set is updated according to the first data identifier, and a second thread is started to read the first data change statement; Each thread reads the first data modification statement in the order indicated by the first sequence identifier.

4. The data synchronization method according to claim 3, characterized in that, If the first database identifier does not match the database identifier set, updating the database identifier set according to the first data identifier and starting the second thread to read the first data change statement includes: Count the first number of first database identifiers that do not match the database identifier set, and start the first number of second threads; Assign a first database identifier that does not match the set of database identifiers to the first number of second threads, and instruct each second thread to read the first data change statement indicated by the first database identifier assigned to the second thread; A first database identifier that does not match the database identifier set is added to the database identifier set, and the database identifier set is updated.

5. The data synchronization method according to claim 1, characterized in that, The method further includes: Read the second data change statement from the first log file of the first device and send the read second data change statement to the second cache middleware of the second device; The second data modification statement includes statements generated in the first device that modify data in the first database.

6. The data synchronization method according to claim 5, characterized in that, The step of reading the second data change statement from the first log file of the first device includes: At the first read time, determine the third number of second data change statements generated in the first log file between the second read time and the first read time, wherein the first read time and the second read time are adjacent and the first read time is after the second read time; If the third quantity is greater than or equal to the first preset value, the fourth quantity of the third thread is obtained based on the third quantity and the preset amount of data read by each third thread; Determine the line in the first log file where the second data change statement generated between the second read time and the first read time is located, and determine the first line interval based on the line where it is located; Based on the preset data volume, the rows in the first row interval are divided sequentially to obtain the fourth number of second row intervals with sequential identifiers; Start the fourth number of third threads, assign the fourth number of second row intervals with sequential identifiers to the fourth number of third threads, and read the second data change statement according to the third threads.

7. The data synchronization method according to claim 6, characterized in that, The step of assigning the fourth number of second row intervals with sequential identifiers to the fourth number of third threads, so as to read the second data change statement in real time according to the third thread, includes: configuring a thread identifier for each third thread, wherein the thread identifier is used to indicate the third sequential identifier of the second row interval corresponding to the third thread; Based on the third sequence identifier indicated by the thread identifier, the fourth number of second line intervals with sequential order are assigned to the corresponding third threads, thereby determining the second line interval read by each third thread in the first log file; Instruct each third thread to read the second data modification statement within the second row range corresponding to the third thread.

8. The data synchronization method according to claim 6, characterized in that, The second cache middleware that sends the read second data modification statement to the second device includes: According to the third sequence identifier indicated by the thread identifier corresponding to the third thread, a second sequence identifier is configured for the second data change statement read by the third thread. The second sequence identifier in the last second data change statement read by the fourth thread is less than the second sequence identifier in the first second data change statement read by the fifth thread. The fourth thread is the third thread whose third sequence identifier is earlier than the thread identifier, and the fifth thread is the third thread whose third sequence identifier is later than the thread identifier. The second data change statement with the second sequence identifier is sent to the second cache middleware of the second device.

9. A data synchronization device, characterized in that, Applied to a first device, the first device being configured with a first cache middleware, the apparatus includes: The first acquisition module is configured to acquire a first data modification statement in the first cache middleware, wherein the first data modification statement is sent to the first cache middleware by the second device; The first modification module is configured to modify the data in the first database based on the first data modification statement; The fault handling module is configured to retrieve the first data modification statement that was not successfully executed from the first cache middleware in the event of a fault in the second device. The continuing change module is configured to modify the data in the first database based on the first data change statement that was not successfully executed. The fault recovery module is configured to enable the first device to provide services to the application in the second device.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the data synchronization method as described in any one of claims 1 to 8.

11. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the data synchronization method according to any one of claims 1 to 8.

12. An electronic device, characterized in that, include: One or more processors; A storage device for storing one or more programs, which, when executed by one or more processors, cause the one or more processors to implement the data synchronization method as described in any one of claims 1 to 8.