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

By using independent cache middleware in the cross-client room service structure for data synchronization, the problem of data loss in the data synchronization of the main and backup room is solved, and the accuracy and reliability of data synchronization are improved.

CN119766828AActive Publication Date: 2025-04-04MASHANG CONSUMER FINANCE CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202411907191.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-23
Publication Date
2025-04-04
Estimated Expiration
2044-12-23

AI Technical Summary

Technical Problem

In the cross-computer room service structure, data loss is easily caused during the synchronization of the main and backup computer rooms, resulting in low reliability of the cross-computer room service structure.

Method used

By configuring independent cache middleware for multiple devices, we can store newly generated data change statements from other devices in real time, and obtain and execute data change statements from the cache middleware to ensure the accuracy and reliability of data synchronization.

Benefits of technology

It reduces data loss during data synchronization, improves the accuracy and reliability of data synchronization, and ensures that accurate services can still be provided in the event of a failure in the main and backup computer room.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119766828A_ABST
    Figure CN119766828A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of data processing, and provides a data synchronization method and device, equipment, a storage medium and a program product.The data synchronization method comprises the steps that a first data change statement in first cache middleware of first equipment is obtained, and the first data change statement is sent to the first cache middleware by second equipment; executing the first data change statement in a first database of the first equipment, and changing data in the first database; under the condition that the second equipment breaks down, the first data change statement which is not successfully executed is obtained from the first cache middleware, and after data in the first database is changed according to the first data change statement which is not successfully executed, the first equipment is started to provide service for the application program in the second equipment. According to the scheme, the data loss amount in the data synchronization process can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of data processing technology, and in particular to a data synchronization method, a data synchronization device, a computer-readable storage medium, a computer program product, and an electronic device. Background Art

[0002] The cross-computer room service structure adopts the deployment mode of main and standby computer rooms to provide external services. Under normal circumstances, the main computer room provides external services and the standby computer room is in standby state. When the main computer room fails, the standby computer room enters the operating state and temporarily replaces the main computer room to provide external services.

[0003] In the cross-computer room service structure, the data of the main computer room during normal operation needs to be synchronized to the backup computer room so that the backup computer room can provide accurate services to the outside world after the main computer room fails. However, in the related art, the data synchronization process between the main and backup computer rooms is prone to data loss, resulting in low reliability of the cross-computer room service structure.

[0004] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present disclosure, and therefore may include information that does not constitute the prior art known to ordinary technicians in the field. Summary of the invention

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

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

[0007] According to a first aspect of the present disclosure, there is provided a data synchronization method, which is applied to a first device, wherein the first device is configured with a first cache middleware, and the method comprises: obtaining a first data change statement in the first cache middleware, wherein the first data change statement is sent from a second device to the first cache middleware; based on the first data change statement, changing the data in the first database; in the event that the second device fails, obtaining the first data change statement that was not successfully executed from the first cache middleware; based on the first data change statement that was not successfully executed, changing the data in the first database; and starting the first device to provide services to an application in the second device.

[0008] According to a second aspect of the present disclosure, there is provided a data synchronization apparatus, which is applied to a first device, wherein the first device is configured with a first cache middleware, and the apparatus comprises: a first acquisition module, configured to acquire a first data change statement in the first cache middleware, wherein the first data change statement is sent from a second device to the first cache middleware; a first change module, configured to change data in the first database based on the first data change statement; a fault handling module, configured to acquire the first data change statement that has not been successfully executed from the first cache middleware in the event that a fault occurs in the second device; a continue change module, configured to change data in the first database based on the first data change statement that has not been successfully executed; and a fault recovery module, configured to start the first device to provide services to an application in the second device.

[0009] According to a third aspect of the present disclosure, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the data synchronization method as described in the first aspect of the above embodiment is implemented.

[0010] According to a fourth aspect of the present disclosure, a computer program product comprising instructions is provided, which, when executed on a computer, enables the computer to execute the steps of the data synchronization method as described in the first aspect.

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

[0012] It can be seen from the above technical solutions that 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 the present disclosure have at least the following advantages and positive effects:

[0013] In the technical solutions provided 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 in 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 statements that have not been successfully executed from the first cache middleware. After all the first data change statements that have not been successfully executed in the first cache middleware are successfully executed in the first database, the first device provides services to the application of the second device again. Compared with the related art, 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, the present invention realizes 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 obtains 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 obtain 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 the execution is completed, 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 is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] The accompanying drawings herein are incorporated into the specification and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the specification are used to explain the principles of the present disclosure. Obviously, the accompanying drawings described below are only some embodiments of the present disclosure, and for ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without creative work.

[0016] Figure 1 A schematic diagram of a system architecture of cross-computer room disaster recovery in a related technology in an exemplary embodiment of the present disclosure is shown;

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

[0018] Figure 3 A schematic diagram showing a flow chart of a data synchronization method in an exemplary embodiment of the present disclosure;

[0019] Figure 4 A flow chart of a method for acquiring a first data change statement in a first cache middleware based on an order indicated by a first order identifier in an exemplary embodiment of the present disclosure is shown;

[0020] Figure 5 A flow chart showing a method for reading a first data change statement in a first cache middleware according to a first thread and a second thread in an exemplary embodiment of the present disclosure is shown;

[0021] Figure 6 A flowchart diagram showing another method for acquiring a first data change statement in a first cache middleware based on an order indicated by a first order identifier in an exemplary embodiment of the present disclosure is shown;

[0022] Figure 7 A schematic diagram showing a flow chart of reading a second data change statement in an exemplary embodiment of the present disclosure is shown;

[0023] Figure 8 A flowchart diagram showing another method for reading a second data change statement in an exemplary embodiment of the present disclosure is shown;

[0024] Fig. 9 A schematic diagram showing a data synchronization process of a primary and standby computer room device in an exemplary embodiment of the present disclosure;

[0025] Fig.10 A schematic diagram showing the composition of a data synchronization device in an exemplary embodiment of the present disclosure is shown;

[0026] Fig.11 A schematic structural diagram of an electronic device in an exemplary embodiment of the present disclosure is shown. DETAILED DESCRIPTION

[0027] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as being limited to the examples set forth herein; on the contrary, these embodiments are provided so that the present disclosure will be more comprehensive and complete, and the concepts of the example embodiments are fully conveyed to those skilled in the art. The described features, structures, or characteristics may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present disclosure. However, those skilled in the art will appreciate that the technical solutions of the present disclosure may be practiced while omitting one or more of the specific details, or other methods, components, devices, steps, etc. may be adopted. In other cases, known technical solutions are not shown or described in detail to avoid obscuring various aspects of the present disclosure.

[0028] The terms "a", "an", "the" and "said" are used in this specification to indicate the presence of one or more elements / components / etc.; the terms "including" and "having" are used to express an open-ended inclusion and mean that additional elements / components / etc. may exist in addition to the listed elements / components / etc.; the terms "first" and "second" etc. are used only as labels and are not intended to limit the quantity of their objects.

[0029] In addition, the accompanying drawings are only schematic illustrations of the present disclosure and are not necessarily drawn to scale. The same reference numerals in the figures represent the same or similar parts, and their repeated description will be omitted. Some of the block diagrams shown in the accompanying drawings are functional entities and do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software form, or implemented in one or more hardware modules or integrated circuits, or implemented in different networks and / or processor devices and / or microcontroller devices.

[0030] In the scenario where a single server provides business services, if a single server fails, the services provided by the server to the outside world cannot be carried out normally. Therefore, cross-computer room disaster recovery is an indispensable part of software design. Cross-computer room disaster recovery can be understood as under normal circumstances, the main computer room equipment provides services to the outside world. When the main computer room equipment fails, the backup computer room equipment enters the operating state and temporarily replaces the main computer room equipment to provide services to the outside world.

[0031] The cross-computer room disaster recovery system architecture in related technologies is as follows: Figure 1 As shown, the specific implementation process may include: the data synchronization tool A in the main data room 11 (the data synchronization tool can be understood as an application in the main data room that can realize the data synchronization function) obtains the SQL (Structured Query Language) for data change from the database cluster log of the main data room 11, such as binlog (binary log file), and then sends the obtained SQL statement to the data synchronization tool B in the disaster backup room 12. After receiving an SQL statement, the data synchronization tool B in the disaster backup room 12 executes the SQL statement in the Mysql database B in the disaster backup room 12. After the execution is completed, a message of successful execution is sent to the data synchronization tool A in the main data room 11. After receiving the message, the data synchronization tool A in the main data room 11 obtains the next SQL statement from the cache of the main data room 11 to send the next SQL statement to the data synchronization tool B in the disaster backup room 12, and so on.

[0032] Executing SQL in the database of the disaster backup computer room 12 inevitably takes time, which may result in 1,000 change SQLs being generated and executed in the equipment in the main data computer room, but only 600 SQL statements may have been executed in the database of the disaster backup computer room, and 400 are waiting to be sent and executed, that is, there is data delay.

[0033] In the case of data synchronization delay, if the equipment in the primary data room fails, causing the network between the equipment in the primary and backup rooms to be interrupted, the disaster recovery tool will be used in the disaster backup room to restore the business system, and the delayed data will be lost. For example, the data generated by the aforementioned 400 SQL statements that have not been synchronized to the disaster backup room will be lost, and ultimately the disaster backup room may not be able to continue to provide accurate services to the outside world.

[0034] Based on this, the present disclosure configures independent cache middleware for multiple devices respectively, so that the cache middleware of the current device can store the newly generated data change statements of other devices in real time, and the current device then obtains the data change statements of other devices from the cache middleware and executes the changes in its own database. In this way, since the newly generated data change statements of other devices have been stored in the cache middleware of the current device in real time, even if any of the multiple devices fails during the data synchronization process, the normal device can still continue to obtain the change statements that have been generated by the faulty device but have not been successfully executed in the normal device from its own cache middleware, and continue to execute the change statements in the normal device. After the execution is completed, the normal device restarts the function of providing services to the application of the faulty device, thereby reducing the amount of data loss caused by data synchronization delay and improving the accuracy of data synchronization.

[0035] Figure 2 A schematic diagram showing an exemplary system architecture to which the present disclosure can be applied, that is, a data synchronization method and device provided by the present disclosure 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 smart phones, tablet computers, desktop computers, laptop computers, and smart wearable devices. The first server 220 and the second server 240 generally refer to the background system that provides services related to the data synchronization method in this exemplary embodiment, and may be a cluster formed by one server or 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 may be connected through a wired or wireless communication link to perform data interaction.

[0037] In an exemplary embodiment, the data synchronization method of the present disclosure may be executed by the first server 220. Accordingly, the data synchronization device may be set in the first server 220 to implement the corresponding module functions. For example, the user operates the application in the second terminal device 230, and the operation may generate a first data change statement for changing the data in the second database of the second server 240. The second server 240 may send the generated first data change statement to the first cache middleware 250. The first server 220 may obtain the first data change statement in the first cache middleware 250, and then execute the obtained first data change statement in the first database of the first server 220 to change the data in the first database of the first server 220. When the second server 240 fails, the first server 220 may continue to obtain the first data change statement that has not been successfully executed from the first cache middleware, and after the first data change statement that has not been successfully executed in the first cache middleware is executed, the first server 220 is started to provide services to the application in the second terminal device 230.

[0038] In another exemplary embodiment, the above-mentioned data synchronization method may also be executed by the second server 240. Accordingly, the data synchronization device may also be set in the second server 240 to implement the corresponding module functions. Among them, the specific implementation of the above-mentioned data synchronization method executed by the second server 240 can refer to the specific implementation of the above-mentioned first server 220, and the technical terms "first terminal device 210" are replaced by "second terminal device 230", "first server 220" is replaced by "second server 240", and "first cache middleware 250" is replaced by "second cache middleware 260", which will not be repeated here.

[0039] It should be understood that Figure 1The number of terminal devices and servers in the example is only illustrative. Any number of terminal devices and servers may be provided as required. For example, server 220 or server 240 may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms.

[0040] For example, Figure 3 A schematic diagram showing a flow chart of a data synchronization method in an exemplary embodiment of the present disclosure is applied to a first device, wherein the first device is configured with a first cache middleware, and a reference Figure 3 , the method comprising:

[0041] Step S310, obtaining a first data change statement in the first cache middleware, wherein the first data change statement is sent by the second device to the first cache middleware;

[0042] Step S320, based on the first data change statement, change the data in the first database;

[0043] Step S330: when the second device fails, obtaining the first data change statement that has not been successfully executed from the first cache middleware;

[0044] Step S340, based on the first data change statement that was not successfully executed, change 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 illustrated embodiment, the first device can obtain the first data change statement synchronized with 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 in 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 statements that have not been successfully executed from the first cache middleware. After all the first data change statements that have not been successfully executed in the first cache middleware are successfully executed in the first database, the first device provides services to the application of the second device again. Compared with the related art, 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, the present invention realizes 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 obtains 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 obtain 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 the execution is completed, 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] Next, the specific implementation of "step S310, obtaining the first data change statement in the first cache middleware" is described in detail.

[0048] In an exemplary embodiment, the first data change statement is sent to the first cache middleware after the second device reads the first data change statement generated in the second device in real time. The first data change statement includes a data change statement generated when the data in the second database of the second device is changed.

[0049] In an 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 an exemplary embodiment, servers deployed in the same computer room belong to the same device, such as a first server cluster includes multiple first servers, and these multiple first servers can be collectively referred to as first computer room devices.

[0050] The first data change statement may include a second database operation statement for adding, deleting, or modifying data in the second database of the second device. It should be noted that the second database operation statement may also include a statement for querying the data in the second database, but since the query operation will not cause any change to the data in the second database, the query operation statement in the second database operation statement does not belong to the first data change statement.

[0051] In an exemplary embodiment, in response to the second database operation statement being a first data change statement and being successfully executed in the second database of the second device, the second device sends the first data change statement to the first cache middleware of the first device. In other words, the first data change statement stored in the first cache middleware of the first device is the first data change statement that has been successfully executed in the second device. In this way, the problem of inconsistent data synchronization between the first device and the second device caused by a change that is not successfully executed in the second device but is synchronized to the first device and successfully executed in the first device can be avoided, thereby improving the accuracy of data synchronization.

[0052] For example, the second device can monitor the second log file of the second device, such as a binlog file, and when a new first data change statement is detected in the second log file of the second device, the new first data change statement is immediately stored in the first cache middleware of the first device. Since the second log file records the data change statements corresponding to the changes that have occurred in the second device, the change statements in the second log file must be the 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 cache middleware of the first device.

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

[0054] Among them, 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 refer to the following steps S710 to S750 and steps S910 to S830, which will not be repeated here.

[0055] In an exemplary embodiment, the first cache middleware and the second cache middleware mentioned below may include any cache middleware that can be deployed independently, such as redis, Memcached, Varnish, Ehcache, etc. This exemplary embodiment does not specifically limit this.

[0056] Among them, 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 characteristics of this.

[0057] In an exemplary embodiment, the first device may include any device among the multiple devices, and the second device may include other devices among the multiple devices except the first device. The multiple devices may be distinguished between primary and backup devices, and a primary device may be configured with one or more backup devices. Under normal circumstances, only the primary device provides services to the outside. In the event of a failure of the primary device, the backup device is started to provide services to the outside. The multiple devices may not be distinguished between primary and backup devices, that is, under normal circumstances, multiple devices can provide services to the outside, such as device 1 provides service 1 to the outside, device 2 provides service 2 to the outside, or device 1 provides service 1 for user group 1, and device 2 provides service 1 for user group 2, etc. Each of the multiple devices is deployed with a database, and each device is configured with corresponding cache middleware. The database configured in the multiple devices may be a relational database, such as the above-mentioned Mysql database, etc., or it may be a non-relational database, such as a document database, a graph database, etc., and this exemplary embodiment does not make any special restrictions on this.

[0058] In an exemplary embodiment, a first domain name pointing to a network address of a first cache middleware is configured in the second device, and the second device can access the first cache middleware through the first domain name to send the first data change statement to the first cache middleware configured in 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, that is, the IP address IP1 as an example, the first domain name "a.redis.db.lo" can be pre-configured in the second device, and the first domain name is set to point to the network protocol address IP1 of the first cache middleware.

[0060] In an exemplary implementation, the first data change statement is configured with a first sequence identifier, and the first sequence identifier is used to indicate the generation time sequence of the first data change statement in the second device.

[0061] Exemplarily, for the first data change statement generated in the second device, an increasing and non-repeating value may 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 first is smaller than the first sequence identifier value of the first data change statement generated later. In this way, the order of the generation time of the first data change statements can be determined through the magnitude relationship of the first sequence identifier values.

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

[0063] Of course, the first sequence identifier may also be generated in other ways, such as when the number of digits of the numerical value corresponding to the first sequence identifier is uncertain, the first sequence identifier of the first generated first data change statement is directly set to 1, and the values ​​of the first sequence identifiers of the first data change statements generated subsequently are incremented by 1 unit, etc. The first sequence identifier may also be generated by referring to the method for generating the second sequence identifier described below, and this exemplary embodiment does not make any special limitation on this.

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

[0065] For a certain user, the changes to the database caused by the user's operations are also in a certain order. By configuring the first sequence identifier for the first data change statement, the first data change statement and the order in which it is generated can be stored in the first cache middleware. In this way, when the first device changes the data in the first database of the first device according to the first data change statement, the first data change statement is also executed in the order of the generation time of the first data change statement, thereby ensuring the accuracy of data synchronization.

[0066] For example, the second device can use the above-mentioned first domain name "a.redis.db.lo" to access the first cache middleware of the first device, and store the first data change statement with the first sequence identifier in the first cache middleware in the form of a string. When storing, the ZSET structure can be used, and the stored keyword key is: the user account and the database identifier corresponding to the database to which the newly generated first data change statement belongs, the value corresponding to the keyword value is: the first data change statement, and the score value score is: the first sequence identifier. For example, for a first data change statement, the first data change statement can be stored in the first cache middleware through the command "zadd key score value".

[0067] Of course, the first data change statement with the first sequence identifier may also be sent to the first cache middleware in other ways, and this exemplary embodiment does not specifically limit this.

[0068] In an exemplary embodiment, each of the first data change statements carries a database identifier. Based on this, exemplarily, Figure 4 A flowchart of a method for obtaining a first data change statement in a first cache middleware based on an order indicated by a first order identifier in an exemplary embodiment of the present disclosure is shown. Figure 4 , the method may include steps S410 to S440. Wherein:

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

[0070] For example, as mentioned above, the database identifier corresponding to the first data change statement in the first cache middleware can be parsed through the key used during storage. When the first device obtains the first data change statement from the first cache middleware for the first time, the first data change statements currently included in the first cache middleware can be divided into the same group, thereby obtaining one or more first grouping groups, and the first database identifier corresponding to each first grouping group is the database identifier carried by the first data change statement in the grouping group. Because the database identifiers carried by the first data change statements in the same grouping group are the same, each first group corresponds to a database identifier, and the database identifiers corresponding to each grouping group are different.

[0071] For example, at the first moment when the first data change statement is obtained from the first cache middleware for the first time, there are currently 200 first data change statements in the first cache middleware, and these 200 first data change statements are divided into 5 groups according to the database identifier, thus obtaining 5 first grouping groups. The first database identifier corresponding to each first grouping group is the database identifier carried by the first data change statement included in the grouping group.

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

[0073] For example, the number of first grouping groups can be counted to obtain the first number. The first device can start a first number of first threads to read the first data change statement included in each first grouping group. Taking the first number as 5 as an example, 5 first threads can be started, and the first database identifiers corresponding to the 5 first grouping groups are respectively assigned to the 5 first threads, each first thread corresponds to a first database identifier, and the first database identifiers of different first threads are different. Each first thread can read the first data change statement included in the first grouping group indicated by the first database identifier assigned to it according to the first sequence identifier.

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

[0075] For example, the set formed by all the first database identifiers obtained when the first data change statement in the first cache middleware is obtained for the first time can be used as the first database identifier set. When the first data change statement in the first cache middleware is obtained for the i-th time, the first database identifier set needs to be updated. When the first data change statement in the first cache middleware is obtained for the i+1th time, the number of threads that need to be newly started and the database identifiers corresponding to the newly started threads can be determined based on the first database identifier set updated after the first data change statement in the first cache middleware is obtained for the i-th time. Wherein, 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, the 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 an exemplary implementation, as mentioned above, i is an integer greater than 1. That is, the second and subsequent processes of obtaining the first data change statement from the first cache middleware can be implemented through step S440.

[0078] Next, combine Figure 5 The specific implementation of step S440 is described. For example, Figure 5 A flowchart of a method for reading a first data change statement in a first cache middleware according to a first thread and a second thread in an exemplary embodiment of the present disclosure is shown. 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 second grouping groups and second database identifiers corresponding to each second grouping group.

[0081] In an exemplary embodiment, after the first data change statement in the first cache middleware is successfully executed in the first database of the first device, a first mark can be added to the first data change statement that is successfully executed, and the first data change statement that has been executed can be distinguished from the first data change statement that has not been executed by the first mark. In this way, when the first data change statement in the first cache middleware is obtained for the i-th time, the first data change statement to be read for the i-th time can be determined based on the next first data change statement of the last first data change statement obtained for the i-1th time (i.e., the last time) to the last first data change statement in the second cache middleware at the time of the i-th acquisition.

[0082] In another exemplary embodiment, after the first data change statement in the first cache middleware is successfully executed in the first database of the first device, the successfully executed first data change statement can be deleted from the first cache middleware. In this way, when the first data change statement in the first cache middleware is obtained for the i-th time, all the first data change statements included in the first cache middleware at the i-th time of the acquisition are the first data change statements to be read currently.

[0083] For example, when the first data change statement in the first cache middleware is obtained for the i-th time, the first data change statement to be read can be grouped according to the database identifier, and the first data change statements to be read with the same database identifier are divided into the same group, thereby obtaining one or more second grouping groups and the second database identifier corresponding to each second grouping group. Similarly, similar to the first grouping, the second database identifier corresponding to each second grouping is the database identifier carried by the first data change statement in the grouping 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, the process goes to step S530; otherwise, the process goes to step S540.

[0085] For example, as described above, each time the first data change statement is obtained from the first cache middleware, the first database identifier is updated. When the first data change statement in the first cache middleware is obtained for the i-th time, the current first database identifier set is the first database identifier set updated when the first data change statement is obtained for the i-1th time (i.e., the last time).

[0086] The second database identifier obtained when the first data change statement in the first cache middleware is obtained for the i-th time is matched with each first database identifier in the current first database identifier set, and the third database identifier and the fourth database identifier are determined according to the matching situation. Then, the first database identifier set is updated according to the fourth database identifier.

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

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

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

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

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

[0092] For example, since the fourth database identifier is different from the first database identifier, a second thread may be newly configured for each fourth database identifier, and 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 an exemplary implementation, after the fourth database identifier is determined, the fourth database identifier may be added to the first database identifier set as a new first database identifier to update the first database identifier set.

[0094] For example, after the fourth database identifier is determined during the process of obtaining the first data change statement for the i-th time, the first database identifier set may be updated according to the fourth database identifier. The updated first database identifier set may be used as the current first database identifier set when the first data change statement is obtained for the i+1th time. In other words, after the second thread is configured for the fourth database identifier, the first data change statement corresponding to the fourth database identifier may 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 first data change statement included in the second grouping group indicated by the third database identifier is read.

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

[0097] In an exemplary embodiment, each of the first thread and the second thread reads the first data change statement included in the corresponding grouping group based on the order indicated by the first sequence identifier. That is, when each thread reads the first data change statement indicated by the corresponding database identifier, it can read the first data change statement generated first and then read the first data change statement generated later according to the order indicated by the second sequence identifier of the first data change statement, which can ensure the accuracy of data update for data with time dependency.

[0098] In the present disclosure, through the above-mentioned steps S410 to S440, the corresponding number of threads can be started according to the number of types of database identifiers included in the key of the first data change statement in the first cache middleware. That is, each thread only reads the first data change statement corresponding to one database identifier. In other words, each thread only reads the first data change statement corresponding to a specific database identifier. This is because there is no order of precedence between data with different database identifiers, and there may be an order of precedence for data with the same database identifier. Starting the corresponding thread according to the number of types of database identifiers can improve efficiency while ensuring the accuracy of data synchronization.

[0099] For example, Figure 6 A flowchart of another method for obtaining a first data change statement in a first cache middleware based on the sequence indicated by a first sequence identifier in an exemplary embodiment of the present disclosure is shown. 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 a database identifier set corresponding to the first cache middleware.

[0101] In an exemplary implementation, the database identifier set is determined according to the second database identifier carried by the first data change statement 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 database identifier set in the first cache middleware. If the match is unsuccessful, the first database identifier carried by the read first data change statement can be added to the database identifier set. In this way, what is stored in the database identifier set is the second database identifier obtained after deduplication processing of the first database identifier carried by the first data change statement that has been read.

[0103] In step S620, when the first database identifier matches the database identifier set, the first data change statement is read based on a first thread corresponding to a second database identifier in the database identifier set that matches the first database identifier.

[0104] In an exemplary embodiment, the database in the present 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 will also carry the corresponding database identifier, so that 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 an exemplary implementation, each database is configured with a thread, and the thread configured for each database is used to read the first data change statement in the database. In this way, the first data change statements of different databases can be read by multiple threads at the same time, which can improve the efficiency of data synchronization, and each thread can read the first data change statement in its corresponding database according to the order in which the change statements are generated, thereby ensuring the accuracy of data reading and thus ensuring the accuracy of data synchronization.

[0106] In an exemplary implementation, when reading the first data change statement, since all databases may not generate new data change statements at the same time, corresponding threads may be configured for databases that have generated data change statements during reading, thereby starting corresponding threads to read the generated data change statements. In other words, some databases have started corresponding threads to read the data change statements in the databases, while other databases have not generated any data change statements during reading, so the threads corresponding to them have not been started.

[0107] As mentioned above, what is recorded in the database identification set is the database identification carried by the first data change statement that has been read, that is, the databases indicated by the database identifications recorded in the database identification set have all started corresponding threads. Therefore, when reading subsequently, for the first data change statement carrying the database identification in the database identification set, the first data change statement can be directly read using the already started thread.

[0108] In other words, when the first database identifier matches the database identifier set, it means that the corresponding thread has been started to read the first data change statement carrying the first database identifier, so the first thread corresponding to the first database identifier that has been started can be used directly to read the first data change statement.

[0109] In step S630, when 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] Exemplarily, a specific implementation of step S630 may include: counting a first number of first database identifiers that do not match the database identifier set, and starting the first number of second threads; assigning the first database identifier that does not match the database identifier set to the first number of second threads, indicating each second read of a first data change statement indicated by the first database identifier assigned to the second thread; and adding the first database identifier that does not match the database identifier set to the database identifier set to update the database identifier set.

[0111] For ease of description, taking the first database identifier that successfully matches as the third database identifier and the first database identifier that failed to match as the fourth database identifier as an example, for example, the first data change statement to be obtained can be matched with the first database identifier set. If the match is successful, the third database identifier can be directly assigned to the first thread corresponding to the second database identifier that successfully matches, and the first thread is instructed to read the first data change statement assigned to it. If the match fails, all fourth database identifiers can be deduplicated first, and then the first number of fourth database identifiers remaining after deduplication is counted, and the first number of new threads, i.e., second threads, are started, and the first number of fourth database identifiers obtained after deduplication are assigned to the first number of second threads, each second thread corresponds to a fourth database identifier, and each second thread is instructed to read the first data change statement carrying the fourth database identifier assigned to it.

[0112] Since a new thread is restarted for the fourth database identifier when the match fails, that is, 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 an exemplary embodiment, each thread reads the first data change statement based on the order indicated by the first sequence identifier. That is, the first thread and the second thread read the first data change statement of the corresponding database in sequence according to the order indicated by the first sequence identifier and the time sequence in which the first data change statement was generated. In this way, since there is no time dependency between the data change statements of different databases, each first thread and the second thread can read the first data change statement at the same time, thereby improving the efficiency of data synchronization. Each database corresponds to a specific thread, and the first data change statement of the database is read in sequence by the specific thread according to the generation order, thereby ensuring that the data order within each database is not disrupted, thereby ensuring the accuracy of data synchronization. In other words, the present disclosure can improve the efficiency of data synchronization while ensuring the accuracy of data synchronization.

[0114] Exemplarily, 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 to obtain the first data change statement in the first cache middleware.

[0115] For example, a second domain name for accessing the network protocol address IP1 of the first cache middleware can be pre-configured in the first device. 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 received by the first cache middleware.

[0116] For example, the second domain name may be "redis.db.lo", where the network protocol address resolved from the domain name "redis.db.lo" is the network protocol address IP1 of the first cache middleware. The specific content of the second domain name can be customized according to demand, and this exemplary embodiment does not specifically limit this.

[0117] The specific implementation of "step S320, changing the data in the first database based on the first data change statement" is described below.

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

[0119] For example, after the first device obtains the first data change statement, the first device can execute the first data change statement in the first database of the first device to change the data in the first database of the first device. Similarly, a data synchronization tool can be configured for the first device, and the data synchronization tool of the first device executes the first data change statement on the data in the first database of the first device to change the data in the first database of the first device.

[0120] In an exemplary embodiment, after executing the first data change statement in the first database of the first device to change the data in the first database, the first data change statement that is successfully executed is deleted from the first cache middleware, or a first mark is added to the first data change statement that is successfully executed in the first cache middleware. In this way, the first data change statement that is successfully executed and the first data change statement that is not successfully executed can be distinguished, which is convenient for data synchronization during subsequent fault recovery. At the same time, because there are some first data change statements that have been executed but not successfully executed during the synchronization process, the accuracy of data synchronization can be further improved by marking the first data change statement that is successfully executed instead of marking the first data change statement that has been executed.

[0121] For example, the first device can obtain the first data change statement from the first cache middleware, and then execute the first data change statement in the first database of the first device. After the first data change statement is successfully executed in the first database of the first device, the first device can call the second domain name to access the first cache middleware, thereby deleting the successfully executed first data change statement from the first cache middleware, or adding a first mark to the successfully executed first data change statement. The first mark can be in any form, and this exemplary embodiment does not specifically limit this.

[0122] The specific implementation of "step S330, when the second device fails, obtaining the first data change statement that has not been successfully executed from the first cache middleware" is described in detail below.

[0123] In an exemplary embodiment, under normal circumstances, services can be provided to applications in the first device through the first device, and services can be provided to applications in the second device through the second device. In the event of a failure in the second device, the first device can be started and the first device can replace the second device to continue providing services to applications in the second device.

[0124] For example, when the second device fails and cannot provide external services, the application in the second device can be started in the first device, and the first device continues to provide services to the application in the second device.

[0125] In the present disclosure, before starting an application of a second device in a first device, the first device may first determine whether there is a first data change statement that has not been successfully executed in the first cache middleware. If so, the first device continues to obtain from the first cache middleware the first data change statement that has not been successfully executed in the first database when a failure occurs in the second device.

[0126] The specific implementation of obtaining the first data change statement that has not been successfully executed from the first cache middleware may refer to the relevant content of obtaining the first data change statement from the first cache middleware in the above step S310, which will not be described in detail here.

[0127] The specific implementation of "step S340, changing the data in the first database based on the first data change statement that was not successfully executed" is described in detail below.

[0128] For example, the first database may include a first database cluster. After obtaining a first data change statement that has not been 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] Exemplarily, other details of changing the data in the first database based on the unsuccessfully executed first data change statement may refer to the above-mentioned step S320, which will not be described in detail here.

[0130] The specific implementation of "step S350, starting the first device to provide services to the application in the second device" is described in detail below.

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

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

[0133] In an exemplary scenario, after the fault of the second device is repaired, the service of the application originally provided by the second device can be switched back to the second device to continue to provide services. During the fault repair process of the second device, the second data change statement newly generated in the first device should also be synchronized to the second cache middleware of the second device, so that the second device changes the data in the second database according to the second data change statement synchronized from the first device to the second cache middleware. After all the second data change statements generated in the first device during the fault of the second device are successfully executed in the second device, the second device can be started to continue to provide services for 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 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 after a failure occurs on either party, the other party can continue to provide services to the application of the failed party at any time.

[0135] Based on this, in an exemplary embodiment, the first device can also read a 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; wherein the second data change statement includes a statement generated in the first device to change the data in the first database of the first device.

[0136] For example, the first device may generate a first database operation statement in response to an operation instruction of an application in the first device, operate the data in the first database according to the first database operation statement, and after the operation is successful, determine whether the first database operation statement is a first data change statement for changing the data in the first database, and if so, store the first change statement in the first log file of the first device, such as the binlog file of the first device. Exemplarily, it is possible to determine whether the first database operation statement is a first data change statement according to the type of the first database operation statement, and if the type of the first database operation statement is any one of the new type, the deletion type, or the modification type, determine that the first database operation statement is a second data change statement, and then record it in the first log file of the first device. The first device may monitor the first log file of the first device, and when a new second data change statement is generated in the first log file, the newly generated second data change statement may be read immediately to send it to the second cache middleware of the second device.

[0137] For example, Figure 7 A flow chart showing a method for reading a second data change statement in an exemplary embodiment of the present disclosure is shown. Figure 7 The method may include steps S710 to S750. Wherein:

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

[0139] In an exemplary embodiment, the first reading time point and the second reading time point are adjacent to each other, and the first reading time point is located after the second reading time point.

[0140] In an exemplary implementation, the first device may read the second data change statement from the first log file of the first device 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 to be generated, the newly generated second data change statement is read from the first log file.

[0142] Real-time reading can also be understood as continuously reading the newly generated second data change statement from the first log file at the minimum reading time interval supported by the computer device. Different devices have different hardware and performance. Therefore, the time interval for continuously reading the second data change statement from the first log file is different for different devices. For example, for a high-performance computer device, the minimum time interval it can support is 0.05 seconds, that is, it can read the second data change statement from the first log file in real time at a time interval of 0.05 seconds. For a low-performance computer device, the minimum time interval it may support is 0.1 seconds, so it can read the second data change statement from the first log file in real time at a time interval of 0.1 seconds.

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

[0144] In step S720, when the third number is greater than or equal to the first preset value, a fourth number of the third threads is obtained according to the third number and a preset amount of data read by each third thread.

[0145] For example, when the third number is greater than or equal to the first preset value, it indicates that a large number of second data change statements need to be read this time, and multi-threaded simultaneous reading can be used to improve reading efficiency, thereby improving data synchronization efficiency, reducing data loss caused by synchronization delays, and improving data synchronization accuracy.

[0146] However, due to the order of the second data change statements, the first data change statement generated later can only be executed after the second data change statement generated earlier is executed, thereby avoiding the situation where the wrong order causes data synchronization errors. Based on this, it is necessary to allocate and process multiple threads to ensure that the time order of the read second data change statements remains unchanged. At the same time, considering the increase in the number of threads, although it can improve the efficiency of data reading, it also increases the cost of the computer. Therefore, it is also necessary to reasonably arrange the number of threads according to the actual situation.

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

[0148] For example, the third number of second data change statements to be read is 550, and the preset amount of data read by each third thread is 100. Then the fourth number is 6, that is, the number of third threads can be determined to be 6.

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

[0150] For example, the row in the first log file where the second data change statement generated between the second reading time and the first reading time is located can be determined, and the first row interval can be determined based on the row interval consisting of the minimum value and the maximum value in the row. That is, the first row interval can be used to represent the position of the second data change statement that the first device needs to read at the first reading time in the first log file.

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

[0152] The maximum row in the preceding second row interval is smaller than the minimum row in the succeeding second row interval.

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

[0154] Among them, the first second-row interval is located before the second second-row interval, the second second-row interval is located before the third second-row interval, the third second-row interval is located before the fourth second-row interval, and the fourth second-row interval is located before the fifth second-row interval. That is, the order of these five second-row intervals is: the first second-row interval, the second second-row interval, the third second-row interval, the fourth second-row interval, and the fifth second-row interval. A sequence identifier can be configured for each second-row interval, and the order of different second-row intervals can be represented by the sequence identifier. For example, sequence identifiers can be configured for different second-row intervals according to the direction of increasing natural numbers, such as the sequence identifier of the first second-row interval is 1, the sequence identifier of the second second-row interval is 2, and so on. The order of the second-row intervals can be indicated by the size relationship between natural numbers, that is, the second-row interval with a smaller sequence identifier is the first second-row interval, and the second-row interval with a larger sequence identifier is the second-row interval.

[0155] In step S750, the fourth number of third threads are started, the fourth number of second row intervals with sequence identifiers are correspondingly allocated to the fourth number of third threads, and the second data change statements are read according to the third threads.

[0156] Below, reference Figure 8 A specific implementation of step S750 is described. For example, Figure 8 A flowchart diagram showing another method for reading a second data change statement in an exemplary embodiment of the present disclosure is shown. 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 an exemplary implementation, the thread identifier is used to indicate a 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, so as to configure the thread identifier for each third thread. For example, if there are 5 third threads in total, these 5 third threads correspond to the above 5 second row intervals respectively, and the thread identifiers of these 5 third threads can be the above sequence identifiers 1, 2, 3, 4, and 5 respectively. In this way, the third thread can determine its corresponding second row interval according to the thread identifier. For example, the third thread with a thread identifier of 1 corresponds to the first second row interval with a third sequence identifier of 1, the third thread with a thread identifier of 2 corresponds to the second second row interval with a third sequence identifier of 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 having a sequential order are allocated to corresponding third threads, and the second line interval read by each third thread in the first log file is determined.

[0161] As described above, the second row interval corresponding to each thread can be determined according to the third sequence identifier indicated by the thread identifier, so that the corresponding second row interval is allocated to the corresponding third thread. In this way, each third thread can obtain the position range of the second data change statement read in the first log file according to its corresponding second row interval.

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

[0163] For example, each third thread can read the first data change statement in the second line interval corresponding to it. Each third thread reads the second data change statement in the second line interval corresponding to it in order from small to large in line number. In the first log file, the second data change statement generated first is first stored in the first log file. Therefore, the size of the line number can determine the order of the generation time of the second data change statement, so that the second data change statement is read in order from small to large in line number.

[0164] Exemplarily, a second sequence identifier can be configured for the second data change statement read by the third thread according to the third sequence identifier indicated by the thread identifier corresponding to the third thread, wherein the second sequence identifier in the last second data change statement read by the fourth thread is smaller than the second sequence identifier of the first second data change statement read by the fifth thread, the fourth thread is the third thread having the first third sequence identifier indicated by the thread identifier, and the fifth thread is the third thread having the last third sequence identifier indicated by the thread identifier; and the second data change statement with the second sequence identifier is sent to the second cache middleware of the second device.

[0165] For example, between different third threads, the second sequence identifier can be configured for the read second data change statements in order from small to large according to the thread identifier. Within each third thread, the second sequence identifier of the read second data change statement can be determined according to the reading order, that is, the second sequence identifier of the second data change statement read first is smaller than the second sequence identifier of the second data change statement 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, respectively, the second sequence identifiers of the 100 second data change statements read by the second third thread are 100 to 199, respectively, and so on.

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

[0168] Taking the preset data amount of each third thread as 100 as an example, when reading for the first time, 3 third threads are generated, then 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; when reading for the second time, 2 third threads D and E are generated, the thread identifier of D is 1, and the thread identifier of E is 2, then 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; when reading for the third time, 2 third threads F and G are generated, the thread identifier of F is 1, 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 an exemplary embodiment, the third sequence identifier of the last second data change statement read by the last third thread at the second reading time is smaller than the third sequence identifier of the first second data change statement read by the first third thread at the first reading time.

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

[0171] In this way, the reading efficiency can be improved through multiple third threads, thereby helping to improve the data synchronization efficiency. Through the size relationship of the second sequence identifier, the order of generation time of the second data change statements read by different third threads can be determined, that is, the second data change statement with a smaller second sequence identifier is generated first, and the second data change statement with a larger second sequence identifier is generated later. Furthermore, in the second device, the second data change statements can be obtained in sequence according to the order of generation time indicated by the second sequence identifier, and the obtained second data change statements can be executed in the second database to ensure the accuracy of data synchronization.

[0172] In an exemplary implementation, after each third thread reads the second data change statement, it can also determine whether it needs to be synchronized according to the preset database identifier. If the database identifier corresponding to the database to which the second data change statement belongs is different from the preset database identifier, it can be determined that it does not need to be synchronized, and the second data change statement can be ignored, and the next second data change statement can be read. Otherwise, the read second data change statement is temporarily stored in the data file. After all third threads have finished reading, the second data change statement temporarily stored in the data file is configured with a second sequence identifier, and the data file configured with the second sequence identifier is sent to the second cache middleware.

[0173] The preset database identifier includes a database identifier corresponding to a database that needs to be synchronized with data, which is customized according to user needs and is not particularly limited in this exemplary embodiment.

[0174] If the second sequence identifier is determined according to the above-mentioned target value, 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 data change statement can be configured with the second sequence identifier according to the target value, and the second data change statement configured with the second sequence identifier can be directly sent to the second cache middleware without waiting for other third threads to complete 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 implementation, the second device may also perform the above steps S310 to S350, so that in the event of a failure of the first device, the second device continues to provide services to the application of the first device. The specific implementation of the second device performing steps S310 to S350 can refer to the first device, and all technical terms related to the first device in the above step S310 can be interchanged with technical terms related to the second device, which will not be repeated here.

[0176] That is to say, in the above-mentioned embodiment corresponding to step S310 to step S350, the first device is described as a backup room for the second device. In practice, the first device and the second device can be in a master-backup relationship with each other, that is, the second device can be a backup 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, the first device is the main computer room device, and the second device is the standby computer room device. A set of redis clusters are independently deployed in the main computer room device and the standby computer room device. The IP of redis cluster 1 of the main computer room device is IP1, and the IP of redis cluster 2 of the standby computer room device is IP2. Two domain name resolution addresses are pre-added for the main computer room device: redis.db.lo->IP1 and b.redis.db.lo->IP2, that is, the main computer room device can access redis cluster 1 through the domain name redis.db.lo, and the main computer room device can access redis cluster 2 through b.redis.db.lo. Two domain name resolution addresses are pre-added for the standby computer room device: redis.db.lo->IP2 and a.redis.db.lo->IP1, that is, the standby computer room device can access redis cluster 2 through the domain name redis.db.lo, and the standby computer room device can access redis cluster 1 through the domain name a.redis.db.lo. The data change statements generated in the main computer room device are stored in the binary log file binlog of the main computer room device. The database is a Mysql database as an example. Fig. 9 , the process of a method for synchronizing data from a main computer room device to a backup computer room device disclosed in the present invention is described.

[0178] Exemplarily, during the data synchronization process, for the main computer room equipment 91, the data synchronization tool 911 in the main computer room equipment 91 can continuously parse the newly generated change statement for changing the data in the MysqlA database of the main computer room from the log file binlog of the main computer room equipment 91, and the data synchronization tool 911 can read the second data change statement generated in the main computer room equipment 91 and configure the second data change statement with a second sequence identifier according to the above-mentioned steps S710 to S750. Then, the main computer room equipment uses the domain name b.redis.db.lo to access the redis cluster 2 of the standby computer room 92, and stores the second data change statement with the second sequence identifier generated in the main computer room equipment in the redis cluster 2 in the form of a string. When storing, the ZSET structure is used, the stored 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 value is the second sequence identifier. When the data change statement is executed, for a certain user, there is a sequence requirement. In the present disclosure, the ZSET structure of redis is selected to save the data change statement, and the ZSET structure has the ability to automatically sort according to the score value. The command to add a record to the ZSET structure is: zadd key scorevalue.

[0179] For the standby computer room device 92, the data synchronization tool 921 of the standby computer room device can access the redis cluster 2 of the standby computer room through the redis.db.lo domain name, and obtain the second data change statement synchronized from the main computer room device from the redis cluster 2 according to the above-mentioned steps S410 to S440 or according to the above-mentioned steps S610 to S630, and execute the obtained second data change statement in the MysqlB database of the standby computer room device. After successful execution, delete the successfully executed data change statement from the redis cluster 2.

[0180] For the disaster recovery tool 922 of the standby computer room device 92, before the standby computer room device 92 starts the application, the data synchronization tool 921 of the standby computer room device is called to perform the data change statement compensation operation. Specifically, the disaster recovery tool 921 calls the data synchronization tool 921. After receiving the call request, the data synchronization tool 921 accesses the redis.db.lo domain name to obtain the data change statement that is synchronized to the standby computer room device 92 but has not yet been executed from the redis cluster 2. During the execution process, under the same account with the same database identifier, the second data change statement is sorted according to the score value, and the second data change statement synchronized from the main computer room device is executed on the MysqlB cluster of the standby computer room device 92 in the order of the score value from small to large. Each time a second data change statement is successfully executed, the corresponding second data change statement can be deleted from the redis cluster 2. Until the second data change statements in the redis cluster 2 of the standby computer room device are all executed successfully, the standby computer room device 92 can perform basic condition checks, such as whether the domain name network used by the application can be connected, etc., and then after the check is passed, the application program of the main computer room device is started in the standby computer room device 92, and the standby computer room device 92 continues to provide services for the application program of the main computer room device.

[0181] Fig. 9 The process of data synchronization from the equipment in the backup room to the equipment in the main room is also shown in FIG. Fig. 9 As shown by the dotted line in , the specific process can refer to the synchronization process from the main computer room equipment to the standby computer room equipment, which will not be repeated here.

[0182] When using asynchronous data synchronization, it is difficult to prevent data loss due to the influence of physical laws (network transmission time, etc.). However, compared with the related art, the present invention deploys cache middleware in multiple computer rooms to store respective data change statements in real time in the other party's cache middleware. Since the time consumption of storing data change statements in the cache middleware is almost negligible compared to the time consumption of executing data change statements, even in the case of abnormal changes such as lack of indexes that cause the execution time of change statements to be longer, the amount of data loss in the data synchronization process is reduced as much as possible, thereby improving the accuracy of data synchronization.

[0183] At the same time, the present disclosure adopts a multi-threaded approach to improve the efficiency of data synchronization when the main and standby equipment in the computer room reads data. In order to ensure the accuracy of reading, the multi-threaded mode is optimized according to the amount of data, the order of data generation, etc., which improves the efficiency of data synchronization while ensuring the accuracy of data synchronization.

[0184] In addition, it should be noted that the above-mentioned figures are only schematic illustrations of the processes included in the method according to an exemplary embodiment of the present invention, and are not intended to be limiting. It is easy to understand that the processes shown in the above-mentioned figures do not indicate or limit the time sequence of these processes. In addition, it is also easy to understand that these processes can be performed synchronously or asynchronously, for example, in multiple modules.

[0185] Furthermore, an exemplary embodiment of the present disclosure further provides a data synchronization device, which is applied to a first device, wherein the first device is configured with a first cache middleware, referring to Fig.10 As shown, the first acquisition module 1010 is configured to obtain the first data change statement in the first cache middleware, wherein the first data change statement is sent by the second device to the first cache middleware; the first change module 1020 is configured to change the data in the first database based on the first data change statement; the fault handling module 1030 is configured to obtain the first data change statement that has not been successfully executed from the first cache middleware in the event that a fault occurs in the second device; the continue change module 1040 is configured to change the data in the first database based on the first data change statement that has not been 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 an exemplary embodiment, the first data change statement is configured with a first sequence identifier, and the first sequence identifier is used to indicate the generation time sequence 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 an exemplary embodiment, each of the first data change statements carries a database identifier; the obtaining of the first data change statement 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 database identifier set corresponding to the first cache middleware, the database identifier set being determined based on a second database identifier carried by the first data change statement read from the first cache middleware; when the first database identifier matches the database identifier set, reading the first data change statement based on a first thread corresponding to a second database identifier in the database identifier set matching the first database identifier, the first thread being a started thread; when the first database identifier does not match the database identifier set, updating the database identifier set according to the first data identifier, and starting a second thread to read the first data change statement; wherein each thread reads the first data change statement based on the order indicated by the first sequence identifier.

[0188] In an exemplary implementation, when the first database identifier does not match the database identifier set, updating the database identifier set according to the first data 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, and starting the first number of second threads; assigning the first database identifier that does 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 identifier that does not match the database identifier set to the database identifier set, and updating the database identifier set.

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

[0190] In an exemplary embodiment, the reading of the second data change statement from the first log file of the first device includes: at a first reading moment, determining a third number of second data change statements generated in the first log file between a second reading moment and the first reading moment, the first reading moment and the second reading moment being adjacent, and the first reading moment being located after the second reading moment; when the third number is greater than or equal to a first preset value, obtaining a fourth number of the third threads according to the third number and a preset amount of data read by each third thread; determining a row in the first log file where the second data change statement generated between the second reading moment and the first reading moment is located, and determining a first row interval according to the row; dividing the rows in the first row interval in sequence according to the preset amount of data to obtain the fourth number of second row intervals with sequence identifiers; starting the fourth number of third threads, assigning the fourth number of second row intervals with sequence identifiers to the fourth number of third threads, and reading the second data change statement according to the third threads.

[0191] In an exemplary embodiment, the fourth number of second row intervals with sequence identifiers are assigned to the fourth number of third threads so as to read the second data change statement in real time according to the third threads, including: configuring a thread identifier for each of the third threads, the thread identifier being used to indicate the third sequence identifier of the second row interval corresponding to the third thread; assigning the fourth number of second row intervals with sequence identifiers to corresponding third threads according to the third sequence identifier indicated by the thread identifier, and determining the second row interval read by each third thread in the first log file; and instructing each third thread to read the second data change statement in the second row interval corresponding to the third thread.

[0192] In an exemplary embodiment, the sending of the read second data change statement to the second cache middleware of the second device includes: configuring a second sequence identifier for the second data change statement read by the third thread according to the third sequence identifier indicated by the thread identifier corresponding to the third thread, wherein the second sequence identifier in the last second data change statement read by the fourth thread is less than the second sequence identifier of the first second data change statement read by the fifth thread, the fourth thread is the third thread having the first third sequence identifier indicated by the thread identifier, and the fifth thread is the third thread having the last third sequence identifier indicated by the thread identifier; and sending the second data change statement with the second sequence 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 implementation method of the method part. The undisclosed details can be found in the implementation method of the method part, so they will not be repeated here.

[0194] It should be noted that, although several modules or units of the device for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the exemplary embodiments of the present 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 into multiple modules or units to be embodied.

[0195] In addition, although the steps of the method in the present disclosure are described in a specific order in the drawings, this does not require or imply that the steps must be performed in this specific order, or that all the steps shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps, etc.

[0196] The exemplary embodiments of the present disclosure also provide a computer program product, which includes a computer program, and when the computer program is executed by a processor, the above-mentioned data synchronization method is implemented.

[0197] In one embodiment, the computer program product may be a tangible product containing a computer program, such as a computer-readable storage medium storing a computer program. The readable storage medium may 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 (Flash), mechanical hard disk (HDD), solid-state drive (SSD), and the like. Exemplarily, the computer program product may be implemented as a non-volatile storage medium storing a computer program, such as a read-only memory, a NAND flash memory, and the like.

[0198] In one embodiment, the computer program product may be an intangible product including a computer program. Exemplarily, the computer program product may be implemented as a virtual digital product, such as a digital file storing an executable file, an installation package, etc. of the computer program.

[0199] The code of the computer program can be written in one or more programming languages. Programming languages ​​such as C language, Java, C++, Python, etc. The program code can be executed entirely on the user computing device, or partially on the user computing device, or as a separate software package, or partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In the case of a remote computing device, the remote computing device can be connected to the user computing device through any type of network, such as a local area network (LAN), a wide area network (WAN), etc., or can be connected to an external computing device (e.g., an Internet connection provided by an operator).

[0200] Computer programs can be carried or transmitted through electrical, magnetic, optical, electromagnetic, infrared and other signals. Electronic devices can convert signals carrying computer programs into digital signals to run computer programs. When a computer program runs on an electronic device, its code is used to enable the electronic device to execute (more specifically, it can enable the processor of the electronic device to execute) the method steps of various exemplary embodiments of the present disclosure, such as the above-mentioned data synchronization method, which includes the following steps: obtaining a first data change statement in the first cache middleware, wherein the first data change statement is sent to the first cache middleware by the second device; based on the first data change statement, changing the data in the first database; 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; based on the first data change statement that was not successfully executed, changing the data in the first database; 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 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 obtains and executes the first data change statement from the first cache middleware to achieve data synchronization. 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 in real time, even if the second device fails, the first device can still obtain the first data change statement that has been generated by the second device but has not yet been executed in the first database of the first device from the first cache middleware. After the execution is completed, the first device is started to provide services to the application of the second device, thereby reducing data loss.

[0202] The exemplary embodiments of the present 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 of the processor, such as a computer program. The processor executes the method steps of various exemplary embodiments of the present disclosure by executing the executable instructions. In addition, the electronic device may also include a display for displaying a graphical user interface.

[0203] Reference below Fig.11 , the electronic device is exemplarily described in the form of a general-purpose computing device. It should be understood that Fig.11 The electronic device 11000 shown is merely an example and should not limit the functions and scope of use of the embodiments of the present disclosure.

[0204] like Fig.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] The memory 1020 may include a volatile memory, such as a RAM 1121, a cache unit 1122, and may also include a non-volatile memory, such as a ROM 1123. The memory 1120 may also include one or more program modules 1124, such program modules 1124 include but are not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or a combination thereof may include the implementation of a network environment. For example, the program module 1124 may include each module in the above-mentioned device.

[0206] Processor 1110 may include one or more processing units. For example, processor 1110 may include 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), etc.

[0207] The processor 1110 can be used to execute executable instructions stored in the memory 1120, such as the above-mentioned data synchronization method, which includes the following steps: obtaining a first data change statement in the first cache middleware, wherein the first data change statement is sent by the second device to the first cache middleware; based on the first data change statement, changing the data in the first database; 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; based on the first data change statement that was not successfully executed, changing the data in the first database; 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 above method are executed by 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 to improve the efficiency of data synchronization; on the other hand, the first data change statement of the second device is first synchronized to the first cache middleware of the first device in real time, and then the first device obtains and executes the first data change statement from the first cache middleware to achieve data synchronization. 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 in real time, even if the second device fails, the first device can still obtain the first data change statement that has been generated by the second device but has not yet been executed in the first database of the first device from the first cache middleware. After the execution is completed, the first device is started to provide services to the application of the second device, thereby reducing data loss.

[0209] The bus 1130 is used to realize the connection between different components of the electronic device 1100, and may include a data bus, an address bus, and a control bus.

[0210] The electronic device 1100 can communicate with one or more external devices 1200 (eg, a keyboard, a mouse, an external controller, etc.) through the I / O interface 1140 .

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

[0212] The electronic device 1100 may display a graphical user interface through the display 1160 , such as a graphical user interface of an application in the first device or the second device.

[0213] although Fig.11 Not shown, other hardware and / or software modules may also be provided 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] In addition, the above-mentioned figures are only schematic illustrations of the processes included in the method according to the exemplary embodiments of the present disclosure, and are not intended to be limiting. It is easy to understand that the processes shown in the above-mentioned figures do not indicate or limit the time sequence of these processes. In addition, it is also easy to understand that these processes can be performed synchronously or asynchronously, for example, in multiple modules.

[0215] As can be seen from the above, the technical solution of the present disclosure can be implemented as a method, an apparatus, a system, a computer program product, a storage medium, an electronic device, etc. Those skilled in the art can understand that various aspects of the present disclosure can be specifically implemented in the following forms, namely: a complete hardware implementation, a complete software implementation (including firmware, microcode, etc.), or an implementation combining hardware and software, such as being respectively referred to as a "circuit", "module" or "system".

[0216] It should be understood that the present disclosure is not limited to the specific method steps or structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from the scope thereof. Those skilled in the art will easily think of other embodiments based on the specific embodiments provided by the present disclosure. Therefore, the specific embodiments provided by the present disclosure are only exemplary, and the scope and spirit of the present disclosure are indicated by the claims, and any variations, uses or adaptive changes of the present disclosure should be covered, which follow the general principles of the present disclosure and include common knowledge or customary technical means in the technical field that are not disclosed in the present disclosure.

Claims

1. A data synchronization method, characterized in that: Applied to a first device, the first device is configured with a first cache middleware, the method includes: Acquire a first data change statement in the first cache middleware, wherein the first data change statement is sent by the second device to the first cache middleware; Based on the first data change statement, change the data in the first database; In the case where the second device fails, obtaining the first data change statement that was not successfully executed from the first cache middleware; Based on the first data change statement that was not successfully executed, change the data in the first database; 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, and the first sequence identifier is used to indicate the generation time sequence of the first data change statement in the second device; The obtaining of the first data change statement in the first cache middleware includes: Based on the sequence indicated by the first sequence identifier, a first data change 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 change statements carries a database identifier; and obtaining the first data change statements in the first cache middleware based on the sequence indicated by the first sequence identifier includes: Matching the first database identifier carried by the first data change statement to be obtained with a database identifier set corresponding to the first cache middleware, the database identifier set being determined according to the second database identifier carried by the first data change statement read from the first cache middleware; In a case where the first database identifier matches the database identifier set, reading the first data change statement based on a first thread corresponding to a second database identifier matching the first database identifier, the first thread being a started thread; In the case where 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 change statement based on the order indicated by the first sequence identifier.

4. The data synchronization method according to claim 3, characterized in that: When the first database identifier does not match the database identifier set, updating the database identifier set according to the first data 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, and starting the first number of second threads; assigning a first database identifier that does not match the database identifier set to the first number of second threads, and instructing each second thread to read a 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 comprises: Reading a second data change statement from a first log file of the first device, and sending the read second data change statement to a second cache middleware of the second device; The second data change statement includes a statement generated in the first device for changing the data in the first database.

6. The data synchronization method according to claim 5, characterized in that: The reading the second data change statement from the first log file of the first device includes: determining, at a first reading time, a third number of second data change statements generated in the first log file between a second reading time and the first reading time, the first reading time being adjacent to the second reading time, and the first reading time being after the second reading time; When the third number is greater than or equal to the first preset value, obtaining a fourth number of the third threads according to the third number and a preset amount of data read by each third thread; Determine a row in the first log file where a second data change statement generated between the second reading time and the first reading time is located, and determine a first row interval according to the row where the second data change statement is located; According to the preset data amount, the rows in the first row interval are divided in sequence to obtain the fourth number of second row intervals with sequential identifiers; The fourth number of third threads are started, the fourth number of second row intervals with sequence identifiers are correspondingly allocated to the fourth number of third threads, and the second data change statements are read according to the third threads.

7. The data synchronization method according to claim 6, characterized in that: The 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 threads includes: configuring a thread identifier for each of the third threads, the thread identifier being used to indicate a third sequential identifier of the second row interval corresponding to the third thread; Allocating the fourth number of second line intervals having a sequential order to corresponding third threads according to the third sequence identifier indicated by the thread identifier, and determining the second line interval read by each third thread in the first log file; Instruct each third thread to read the second data change statement in the second row interval corresponding to the third thread.

8. The data synchronization method according to claim 6, characterized in that: The step of sending the read second data change statement to the second cache middleware of 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, wherein the second sequence identifier in the last second data change statement read by the fourth thread is smaller than the second sequence identifier of the first second data change statement read by the fifth thread, the fourth thread is the third thread whose third sequence identifier indicated by the thread identifier is earlier, and the fifth thread is the third thread whose third sequence identifier indicated by the thread identifier is later; Sending the second data change statement having the second sequence identifier 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 is configured with a first cache middleware, the apparatus comprises: A first acquisition module is configured to acquire a first data change statement in the first cache middleware, wherein the first data change statement is sent by the second device to the first cache middleware; A first change module is configured to change the data in the first database based on the first data change statement; a fault processing module, configured to obtain the first data change statement that was not successfully executed from the first cache middleware when the second device fails; a continuing change module, configured to change 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 start 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, the data synchronization method according to any one of claims 1 to 8 is implemented.

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

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 the one or more processors, enables the one or more processors to implement the data synchronization method as described in any one of claims 1 to 8.

Citation Information

Patent Citations

  • Cache data synchronization method, server, application system and storage device

    CN109800272A

  • Data synchronization processing method, system and device, electronic equipment and storage medium

    CN117319416A

  • Data synchronization method, data center, data synchronization system and electronic equipment

    CN117539957A

  • Database change processing method and device

    CN118503267A

  • Application-independent data synchronization technique

    US6505200B1