Data synchronization method and device, equipment, storage medium and program product
Through the redis cluster topology update mechanism and task recovery function, the high availability problem of data synchronization between redis clusters is solved, real-time data synchronization and data consistency across regions are achieved, and it is suitable for long-term cross-region scenarios.
Patent Information
- Application Number
- CN202411043816.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-31
- Publication Date
- 2024-12-17
AI Technical Summary
The existing redis intercluster data synchronization tools cannot guarantee high availability, especially in the case of network jitter or node changes, resulting in data synchronization failure and interruption, unable to flexibly retry or compensate, and cannot be applied to long-term cross-region master-subsidized redis Data synchronization scenario between clusters.
Through the redis cluster topology update mechanism and task recovery function, abnormally interrupted data synchronization tasks are monitored and rebuilt, breakpoint relay is used to use PSYNC instructions, and corresponding compensation policies are executed according to the data consistency level.
It realizes high availability and data consistency of cross-regional real-time data synchronization among redis clusters, ensuring automatic recovery and compensation of data in case of single node failure or network jitter, and is suitable for long-term cross-regional data synchronization scenarios.
Smart Images

Figure CN119149187A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data analysis technology, and in particular to a data synchronization method, apparatus, device, storage medium, and program product. Background Art
[0002] Redis is an in-memory database with insufficient availability. If you want to further improve the availability of the Redis cluster, you can deploy the same standby Redis cluster across regions and synchronize the data of the primary Redis cluster to the standby Redis cluster in real time. Currently, the mainstream synchronization tools between Redis clusters are: redis-shake tool and redis-replicator tool. The above tools can be used to synchronize data between Redis clusters, but the high availability of the synchronization process cannot be guaranteed. If network jitter occurs during the synchronization process, or nodes in the Redis cluster are changed, data synchronization may fail or be interrupted, and retry or compensation cannot be performed flexibly. Therefore, the above tools for data synchronization between Redis clusters are only suitable for scenarios such as data migration, and cannot be used in scenarios where data synchronization between primary and standby Redis clusters across regions requires a long time. Summary of the invention
[0003] The main purpose of this application is to provide a data synchronization method, device, equipment, storage medium and program product, aiming to solve the technical problem of real-time data synchronization between cross-regional Redis clusters.
[0004] To achieve the above objectives, the present application proposes a data synchronization method, which includes:
[0005] Start the pre-created data synchronization task;
[0006] Acquire a task recovery function of the data synchronization task based on the offset of the master node data in the data synchronization task;
[0007] When it is detected that the data synchronization task is abnormally interrupted, the redis cluster topology update mechanism and the task recovery function are used to reconstruct the abnormally interrupted data synchronization task.
[0008] In one embodiment, the step of obtaining the task recovery function of the data synchronization task based on the offset of the master node data in the data synchronization task includes:
[0009] Split the master node data of the main redis cluster into multiple data synchronization subtasks through the data synchronization task;
[0010] Cache the offset of the corresponding master node data through each of the data synchronization subtasks, and store the unique identifier of the master node data and the offset of the master node data in the database;
[0011] The task recovery function of the data synchronization task is executed according to the unique identifier of the master node data and the offset of the master node data.
[0012] In one embodiment, when the data synchronization task is detected to be abnormally interrupted, the step of using the redis cluster topology update mechanism and the task recovery function to reconstruct the abnormally interrupted synchronization task includes:
[0013] When a data synchronization task is detected to be abnormally interrupted, the abnormally interrupted data synchronization task is reconnected according to the redis cluster topology update mechanism, and a synchronization PSYNC instruction is sent to the redis node to start the task recovery function;
[0014] Data breakpoint resume transmission is performed according to the task recovery function.
[0015] In one embodiment, the step of reconnecting the data in the abnormally interrupted data synchronization task according to the redis cluster topology update mechanism includes:
[0016] Get the current node topology of the main redis cluster through the redis cluster node command;
[0017] Based on the current node topology of the main redis cluster, query the currently available data nodes;
[0018] Reestablish a connection for data in the abnormally interrupted data synchronization task through the currently available data nodes.
[0019] In one embodiment, it is characterized in that before the step of sending a synchronous PSYNC instruction to the redis node to start the task recovery function, it also includes:
[0020] The corresponding master node data synchronization offset is queried from the database through the unique identifier of the master node data;
[0021] The unique identifier of the master node data and the offset of the master node data are sent to the corresponding redis node as parameters of the PSYNC instruction.
[0022] In one embodiment, the step of resuming data breakpoint transmission according to the task recovery function includes:
[0023] Verify the unique identifier of the master node data and the offset of the master node data in the redis node to determine whether the master node data is executing the data synchronization task for the first time;
[0024] If it is determined that the master node data is executing the data synchronization task for the first time, full and incremental data synchronization processing is performed according to the first preset command;
[0025] If it is determined that the master node data is not executing the data synchronization task for the first time, data incremental synchronization processing is performed according to the second preset command.
[0026] In one embodiment, after the step of using the redis cluster topology update mechanism and the task recovery function to reconstruct the abnormally interrupted data synchronization task when the data synchronization task is detected to be abnormally interrupted, the process further includes:
[0027] When it is detected that the data synchronization task fails to execute, the data consistency level of the redis cluster is used to execute a corresponding data synchronization compensation strategy for each failed data synchronization task.
[0028] In one embodiment, when the data synchronization task fails to be executed, the step of using the data consistency level of the redis cluster to execute a corresponding data synchronization compensation strategy for each failed data synchronization task includes:
[0029] When it is detected that the data synchronization task fails to execute, the data consistency level of the redis cluster is confirmed;
[0030] If the data consistency level of the redis cluster is a high consistency requirement, the data in the data synchronization task that failed to synchronize is persistently recorded based on the first preset command, and the data in the data synchronization task that failed to synchronize is resent to the standby redis cluster;
[0031] If the data consistency level of the redis cluster meets the general consistency requirement, the data synchronization task that failed to synchronize is re-executed according to the preset maximum number of retries.
[0032] In one embodiment, after the step of starting the pre-created data synchronization task, the method further includes:
[0033] Deploy the data synchronization task to the application instance for execution;
[0034] When the data synchronization task starts to execute, the corresponding state of the data synchronization task in the database is set to be turned on, and the application instance is used to check whether the data synchronization task in the database with the state of being turned on is executed healthily;
[0035] If so, the data synchronization task in the database in the enabled state is exclusively locked and restarted through the application instance.
[0036] In addition, to achieve the above purpose, the present application also proposes a data synchronization device, the data synchronization device comprising:
[0037] The start module is used to start the pre-created data synchronization task;
[0038] An acquisition module, used for acquiring a task recovery function of the data synchronization task based on an offset of the master node data in the data synchronization task;
[0039] The reconstruction module is used to rebuild the abnormally interrupted data synchronization task by using the redis cluster topology update mechanism and the task recovery function when the data synchronization task is detected to be abnormally interrupted.
[0040] In addition, to achieve the above objectives, the present application also proposes a data synchronization device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the data synchronization method described above.
[0041] In addition, to achieve the above objectives, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the data synchronization method described above are implemented.
[0042] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the data synchronization method described above are implemented.
[0043] The embodiment of the present application provides a data synchronization method, including starting a pre-created data synchronization task; obtaining a task recovery function of the data synchronization task based on an offset; and when an abnormal interruption of the data synchronization task is detected, using the redis cluster topology update mechanism and the task recovery function to rebuild the abnormally interrupted data synchronization task. The solution implements the automatic recovery function of the synchronization task through the redis cluster topology update mechanism, solves the problem that a single node failure in the redis cluster affects data synchronization, and ensures real-time synchronization across regions between redis clusters. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0045] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0046] Figure 1 A flowchart of the first embodiment of the data synchronization method of the present application is provided;
[0047] Figure 2 This is a schematic diagram of the workflow of the visual management background involved in Example 1 of the present application;
[0048] Figure 3 A schematic diagram of the data synchronization task recovery process involved in the first embodiment of the present application;
[0049] Figure 4 A flowchart of the second embodiment of the data synchronization method of the present application is provided;
[0050] Figure 5 This is a schematic diagram of the synchronization failure data compensation process involved in the second embodiment of the present application;
[0051] Figure 6 A flowchart of the third embodiment of the data synchronization method of the present application is provided;
[0052] Figure 7 This is a schematic diagram of a simple process for normally executing a data synchronization task in an application example involved in Embodiment 3 of the present application;
[0053] Figure 8 This is a schematic diagram of the module structure of the data synchronization device according to an embodiment of the present application;
[0054] Fig. 9 A schematic diagram of the device structure of the hardware operating environment involved in the data synchronization method in the embodiment of the present application.
[0055] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0056] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.
[0057] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0058] The main solutions of the embodiments of the present application are: creating and starting a data synchronization task; obtaining the task recovery function of the data synchronization task based on the offset; when it is detected that the data synchronization task is abnormally interrupted, using the redis cluster topology update mechanism and the task recovery function to rebuild the abnormally interrupted data synchronization task; when it is detected that the data synchronization task fails to execute, using the data consistency level of the redis cluster, executing a corresponding data synchronization compensation strategy for each failed data synchronization task.
[0059] In this embodiment, for the convenience of description, the following description is made by taking identification data synchronization as the execution subject.
[0060] At present, the mainstream synchronization tools between Redis clusters are: redis-shake tool and edis-replicator tool. The above tools can be used to synchronize data between Redis clusters, but the high availability of the synchronization process cannot be guaranteed. If network jitter occurs during the synchronization process, or nodes in the Redis cluster are changed, data synchronization may fail or be interrupted, and retry or compensation cannot be performed flexibly. Therefore, the above tools are only suitable for scenarios such as data migration, and cannot be used in scenarios where data synchronization between active and standby Redis clusters across regions requires a long time.
[0061] This application provides a solution, which effectively solves the problem of abnormal interruption of data synchronization tasks caused by single node failure of redis cluster through redis cluster topology update mechanism and task automatic recovery function. At the same time, through personalized configuration of different data synchronization compensation strategies, it can more flexibly handle the problem of data loss caused by network jitter, and can ensure the final consistency of master and standby redis cluster data in the scenario of long-term cross-regional data synchronization.
[0062] It should be noted that the execution subject of this embodiment can be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device capable of realizing the above functions, etc. The following takes a personal computer as an example to illustrate this embodiment and the following embodiments.
[0063] Based on this, the present application embodiment provides a data synchronization method, referring to Figure 1 , Figure 1 This is a flowchart of the first embodiment of the data synchronization method of the present application.
[0064] In this embodiment, the data synchronization method includes steps S10 to S30:
[0065] Step S10, creating and starting a data synchronization task;
[0066] Compared with the one-time operation of the command line of the data synchronization tool in the prior art, this embodiment provides a more functional visual management background to operate the data synchronization between redis clusters. Figure 2 , Figure 2 This is a diagram of the workflow of the visual management background.
[0067] The visual management background provides the following functions:
[0068] (1) It provides the function of saving data synchronization tasks. After the task is created, it is automatically saved and can be modified or deleted.
[0069] (2) It provides personalized configuration of synchronization tasks, including the whitelist and blacklist of synchronization keys, the number of retries after synchronization failure, etc.
[0070] (3) Provide task process monitoring, and you can view various data statistics during the task process.
[0071] (4) Save the execution records and detailed data statistics of each task, including the information of the master and standby cluster nodes, the number of successful and failed keys, the number of commands, and the detailed data of failed keys.
[0072] Step S20, obtaining a task recovery function of the data synchronization task based on the offset of the master node data in the data synchronization task;
[0073] It should be noted that the offset of the master node data in the data synchronization task refers to the unique identifier of a specific data point in the data stream. It can be the position index of the message in the message queue, or the byte position in the log file, or any other value that can uniquely determine the data position.
[0074] When a data synchronization task is interrupted for some reason, such as crash or maintenance, the visual management background can record the offset of the last successfully processed data. When the task is restarted, it can continue processing from this offset, thereby realizing task recovery and avoiding the risk of duplicate data processing or data loss.
[0075] In a scenario where data synchronization between cross-regional redis clusters is performed for a long time, in order to avoid the interruption of the data synchronization task due to a failure of a node in the redis cluster, this embodiment implements the automatic recovery function of the data synchronization task by executing step S20.
[0076] In a feasible embodiment, step S20 may include steps S21 to S23:
[0077] Step S21, splitting the master node data of the main redis cluster into multiple data synchronization subtasks through the data synchronization task;
[0078] It should be noted that the main redis cluster is a collection of servers that undertakes the main write and read operations in the redis cluster architecture.
[0079] The master node data refers to the node responsible for receiving write operations in the redis replication architecture, which stores the latest status of the complete data set.
[0080] The data synchronization task is split into multiple subsets according to the data set on the master node of the main redis cluster. Each subset is a data synchronization subtask and can be processed by different working nodes, which improves data synchronization efficiency and resource utilization, and also provides a basis for parallel processing and fault tolerance.
[0081] Step S22, caching the offset of the corresponding master node data through each of the data synchronization subtasks, and storing the unique identifier of the master node data and the offset of the master node data in a database;
[0082] During the data synchronization process, each data synchronization subtask will record the latest position of the processed data, that is, the offset. In this embodiment, the offset of the master node data is recorded as repl offset. This can be the last character position of the data key, the number of data entries, etc., depending on the structure of the data and the synchronization strategy.
[0083] Every few seconds, the corresponding master node data offset of each data synchronization subtask and its corresponding unique identifier (repl ID) of the master node data are persisted and stored in a reliable database. This is usually a persistent storage visualization management background, such as MySQL, PostgreSQL, or another redis application instance, to ensure that this information will not be lost even if the visualization management background fails.
[0084] This step records the progress of data synchronization so that it can be restored from the interruption point after the task fails or is interrupted.
[0085] Step S23: implementing the task recovery function of the data synchronization task according to the unique identifier of the master node data and the offset of the master node data.
[0086] When the data synchronization task is restarted, the visual management background will query the reploffset and repl ID stored in the database to find the last successful synchronization point of each subtask.
[0087] Based on the repl offset and repl ID, each subtask will continue to synchronize from its last known repl offset, thus ensuring the integrity and continuity of the data and avoiding duplicate processing or omission of data.
[0088] This step ensures that after a data synchronization task is interrupted, data synchronization can be continued from the interruption point instead of restarting or skipping data.
[0089] Step S30, when it is detected that the data synchronization task is abnormally interrupted, the redis cluster topology update mechanism and the task recovery function are used to reconstruct the abnormally interrupted data synchronization task;
[0090] It should be noted that the topology update mechanism in the Redis cluster environment refers to an automatically triggered mechanism used to update information between nodes in the cluster, including node status, connections between nodes, and data distribution.
[0091] In addition, it should be noted that the slave node is a copy of the master node, and maintains consistency with the master node data by copying the master node data.
[0092] During the cross-region master-slave redis cluster data synchronization process, if a data node of the redis cluster fails, the master redis cluster switches the failed node to the slave node. If a general synchronization tool is used, the synchronization subtask corresponding to the failed data node will be interrupted, resulting in the inability to perform the entire data synchronization task.
[0093] Therefore, this embodiment monitors the progress of the data synchronization task through the visual management background. Once the data synchronization task is detected to be abnormally interrupted, the corresponding recovery task process is immediately triggered. Figure 3 , Figure 3 A data synchronization task recovery process diagram provided for the data synchronization method of the present application.
[0094] Further, in a feasible implementation manner, step S30 may include steps S31 to S32:
[0095] Step S31, when it is detected that the data synchronization task is abnormally interrupted, the abnormally interrupted data synchronization task is reconnected according to the redis cluster topology update mechanism, and a synchronization PSYNC instruction is sent to the redis node to start the task recovery function;
[0096] It should be noted that the PSYNC (Partial synchronization) instruction is a command used for master-slave replication in redis. It supports partial resynchronization and allows data synchronization between the slave server and the master server.
[0097] When the visual management background detects that a redis data node in the main redis cluster fails and causes the data synchronization subtask to be abnormally interrupted, the topology update mechanism of the redis cluster will be used to re-establish the connection with the corresponding redis master node for each interrupted data synchronization subtask. And send a PSYNC instruction to the master node, which carries the replication repl offset and repl ID of the slave node. After receiving the PSYNC instruction, the master node will check its own status and the information provided by the slave node, and then decide whether to perform full synchronization or incremental synchronization, that is, breakpoint resumption.
[0098] Further, in a feasible implementation manner, step S31 may include steps A11 to A13:
[0099] Step A11, obtain the current node topology of the main redis cluster through the red cluster cluster node command;
[0100] Get the current node topology of the main redis cluster through the redis cluster cluster node (redis CLUSTER NODES) command. The redis CLUSTER NODES command is used to list the information of all nodes in the cluster, including node ID, host name, port number, role (master node or slave node), etc.
[0101] Use the redis CLUSTER NODES command, which returns detailed information of all nodes in the cluster, including topology information such as ID, address, status, slot information, etc.
[0102] Step A12, querying currently available data nodes based on the current node topology of the main redis cluster;
[0103] In the topology information obtained in step A11, nodes in the "master" state are selected. These nodes are the main sources of data synchronization.
[0104] It then checks the connectivity and health status of these nodes, excludes any nodes reported as failed or migrated, and then creates a list of currently available data nodes for subsequent connection reconstruction.
[0105] Step A13: reestablishing the connection of the data in the abnormally interrupted data synchronization task through the currently available data nodes.
[0106] Determine each faulty node in each abnormally interrupted data synchronization task, as well as the ID of each faulty node, and find the currently available master node corresponding to each interrupted data synchronization task by comparing it with the currently available data node list. And for each interrupted data synchronization task, re-establish the connection with the corresponding master node.
[0107] Step S32, performing data breakpoint resume transmission according to the task recovery function.
[0108] When the connection is established, a PSYNC instruction is sent to the master node to pass the unique identifier of the master node data before the interruption and the offset of the master node data to achieve breakpoint resumption of data.
[0109] In a feasible implementation, step S32 may include steps S321 to S323:
[0110] Step S321, verifying the unique identifier of the master node data and the offset of the master node data in the redis node to determine whether the master node data is executing the data synchronization task for the first time;
[0111] Check and compare the unique identifier of the master node data stored in the database with the identifier of the master node data currently to be synchronized.
[0112] Check the offset of the master node data stored in the database. If the offset is an initial value (such as 0 or a specific uninitialized mark), it indicates that this is the first synchronization; if the offset has a specific value, it indicates that there is a synchronization history.
[0113] If the unique identifier of the master node data does not exist or the offset of the master node data is the initial value, it is determined that the data synchronization task is executed for the first time. If the unique identifier of the master node data exists and the offset of the master node data is not the initial value, it is determined that the data synchronization task is not executed for the first time.
[0114] Step S322: If it is determined that the master node data is performing a data synchronization task for the first time, full data synchronization and incremental data synchronization are performed according to a first preset command;
[0115] It should be noted that, in this embodiment, the first preset command includes RDB (redis Database Backup) and write command. Among them, RDB is a persistence method provided by redis for generating a database, and write command refers to all commands that can modify data in redis.
[0116] After the first data synchronization task starts, the master node data will execute the BGSAVE (Background Save) command to asynchronously create an RDB snapshot file. This RDB snapshot file contains a complete copy of all current data on the master node.
[0117] When the RDB is created, the master node data will send the RDB snapshot to the slave node through the network. After receiving the RDB file, the slave node data will load the data into the memory to establish the same data state as the master node data. During the RDB snapshot creation and transmission process, the master node data may receive write commands from the client. To ensure data consistency, these write commands will be cached and sent to the slave node data after the RDB file transmission is completed.
[0118] After the RDB file is transferred, the master node data will send the cached write commands to the slave node data. After receiving these write commands, the slave node data will execute these commands in sequence to update its data status to make it completely consistent with the master node data.
[0119] Through the above steps, the first data synchronization task is implemented, and the complete data of the master node is copied to the slave node, ensuring that the slave node can obtain the full data status of the master node, achieving the purpose of full and incremental data synchronization.
[0120] Step S323: If it is determined that the master node data is not executing the data synchronization task for the first time, perform data incremental synchronization processing according to the second preset command.
[0121] It should be noted that, in this embodiment, the second preset command includes a write command after an offset (repl offset).
[0122] After the first data synchronization task is completed, the slave node will record the offset of the last write command received (repl offset).
[0123] When a non-initial data synchronization task is started, the slave node sends a PSYNC command to the master node, including the slave node's repl ID and the last recorded repl offset. The master node checks the repl offset to determine whether there is any data change since the last synchronization.
[0124] If the master node detects new write commands after the repl offset, it sends these write commands to the slave node. The slave node receives and executes these write commands to update its own data status.
[0125] And after the data synchronization task is completed, the slave node will update the repl offset to reflect the latest synchronization point.
[0126] Through the above steps, the first synchronization ensures that the data of the slave node is completely consistent with the master node, while the non-first synchronization uses the incremental synchronization mechanism to only transmit the data changes since the last synchronization, thereby achieving efficient data synchronization.
[0127] The above-mentioned embodiment method includes starting a pre-created data synchronization task; obtaining the task recovery function of the data synchronization task based on the offset; and when the data synchronization task is detected to be abnormally interrupted, using the redis cluster topology update mechanism and the task recovery function to rebuild the abnormally interrupted data synchronization task. This solution realizes the automatic recovery function of synchronization tasks through the redis cluster topology update mechanism, solves the problem that a single node failure in the redis cluster affects data synchronization, and ensures cross-regional real-time synchronization between redis clusters.
[0128] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as those in the above-mentioned embodiment 1 can be referred to the above introduction, and will not be repeated in the following. Figure 4 After step S30, the data synchronization method further includes step S40:
[0129] Step S40: When it is detected that the data synchronization task fails to execute, the data consistency level of the redis cluster is used to execute a corresponding data synchronization compensation strategy for each failed data synchronization task.
[0130] It should be noted that the backup Redis cluster usually refers to another cluster that keeps data synchronized with the primary Redis cluster.
[0131] After the application or tool performing the data synchronization task successfully receives the RDB and write commands of the primary redis cluster, network jitter, supermarkets and other abnormal situations may occur during the synchronization process to the backup redis cluster, resulting in the failure of synchronization of some data.
[0132] Therefore, this embodiment specifies the data synchronization task processing measures for synchronization failure according to different data consistency requirements of the redis cluster. Figure 5 , Figure 5 A schematic diagram of the synchronization failure data compensation process provided by the method of this embodiment.
[0133] Further, in a feasible implementation manner, step S40 may include steps S41 to S43:
[0134] Step S41, when it is monitored that the data synchronization task fails to execute, confirming the data consistency level of the redis cluster;
[0135] It should be noted that the data consistency level of the redis cluster refers to the degree and method of maintaining consistency between multiple nodes in a distributed system.
[0136] Step S42: if the data consistency level of the redis cluster is a high consistency requirement, the data in the data synchronization task that failed to synchronize is persistently recorded based on a first preset command, and the data in the data synchronization task that failed to synchronize is resent to the standby redis cluster;
[0137] When it is detected that the data consistency level of the redis cluster is a high consistency requirement, the compensation mechanism can be used. To prevent repeated synchronization, RDB and write command resending, the application will persistently record the data, RDB and write commands in the data synchronization tasks that failed to synchronize, and provide synchronization failure data query and compensation resending. The compensation resending is resent to the standby redis cluster in the form of commands.
[0138] Step S43: if the data consistency level of the redis cluster is a general consistency requirement, re-execute the data synchronization task that failed to synchronize with the preset maximum number of retries.
[0139] When it is detected that the data consistency level of the redis cluster is the general consistency requirement or the resending command is idempotent, the failed task will be added to the retry queue and retried according to the preset maximum number of retries.
[0140] Through the above steps, the recovery strategies for data synchronization failures vary according to the data consistency levels of different redis clusters. Under high consistency requirements, data persistence and redundancy are prioritized to ensure data recovery even under extreme conditions. Under general consistency requirements, the retry mechanism is relied upon to improve the success rate of data synchronization, while reducing resource consumption and the impact on system performance, and can flexibly handle data loss problems caused by network jitter.
[0141] Based on the first embodiment of the present application, in the third embodiment of the present application, the same or similar contents as those in the above-mentioned embodiment 1 can be referred to the above introduction, and will not be repeated in the following. Figure 6 After step S10, the data synchronization method further includes steps B11 to B13:
[0142] Step B11, deploying the data synchronization task to the application instance for execution;
[0143] In order to ensure high availability, this embodiment adopts a two-point deployment method of multiple AZs (deployment areas) and multiple application instances, and allocates different data synchronization tasks to different application instances for execution.
[0144] Step B12, when the data synchronization task starts to execute, the corresponding state of the data synchronization task in the database is set to open, and the data synchronization task in the database with the open state is checked through the application instance to see whether it is executed healthily;
[0145] Please refer to Figure 7 , Figure 7 A simple flowchart of the normal execution of data synchronization tasks for an application instance.
[0146] Specifically, when some application instances fail, this embodiment will automatically migrate the data synchronization tasks executed on the failed application instances to normal instances for execution. The implementation method is: after the data synchronization task starts to execute, the corresponding task status field in the database is updated to "on", and the normal and available application instances will regularly check whether the data synchronization tasks in the database with the status of "on" are executing healthily.
[0147] Step B13: If yes, the data synchronization task in the database in the enabled state is exclusively locked and restarted through the application instance.
[0148] It should be noted that an exclusive lock, also known as a mutex lock or a write lock, is a synchronization mechanism used to control access to shared resources by multiple threads or processes. Adding an exclusive lock to the data synchronization task in the database ensures that only one application instance can handle the task and avoid race conditions.
[0149] If it is checked that the status of the data synchronization task is turned on but no application instance is executing this data synchronization task, the application instance attempts to obtain the lock associated with the data synchronization task, which usually involves creating a lock record for the task in the database, or updating an existing lock record to indicate that the task is being processed and the lock is held. Before trying to obtain the lock, the application instance checks the status of the lock. If the lock is already held by another application instance, the current application instance will wait until the lock is released. When the data synchronization task is completed or interrupted, the application instance releases the lock so that other application instances can try to obtain the lock and process the data synchronization task, and then restart the data synchronization task to ensure correct synchronization of the data.
[0150] In summary, the high availability mechanism can ensure the orderly and correct execution of data synchronization tasks, and maintain data integrity and consistency even in distributed and concurrent environments.
[0151] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the data synchronization method of the present application. More simple transformations based on this technical concept are all within the scope of protection of the present application.
[0152] This application also provides a data synchronization device, please refer to Figure 8 , the data synchronization device comprises:
[0153] The start module 10 is used to start the pre-created data synchronization task;
[0154] An acquisition module 20, configured to acquire a task recovery function of the data synchronization task based on an offset of the master node data in the data synchronization task;
[0155] The reconstruction module 30 is used to rebuild the abnormally interrupted data synchronization task by using the redis cluster topology update mechanism and the task recovery function when the data synchronization task is detected to be abnormally interrupted.
[0156] The data synchronization device provided by the present application adopts the data synchronization method in the above embodiment, which can solve the technical problem of real-time data synchronization between redis clusters across regions. Compared with the prior art, the beneficial effects of the data synchronization device provided by the present application are the same as the beneficial effects of the data synchronization method provided by the above embodiment, and the other technical features in the data synchronization device are the same as the features disclosed in the above embodiment method, which will not be repeated here.
[0157] The present application provides a data synchronization device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the data synchronization method in the above-mentioned embodiment one.
[0158] Reference below Fig. 9 , which shows a schematic diagram of the structure of a data synchronization device suitable for implementing an embodiment of the present application. The data synchronization device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), etc., and fixed terminals such as digital TVs, desktop computers, etc. Fig. 9 The data synchronization device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0159] like Fig. 9As shown, the data synchronization device may include a processing device 1001 (e.g., a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the data synchronization device are also stored. The processing device 1001, ROM1002, and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following visual management backgrounds can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the data synchronization device to communicate with other devices wirelessly or by wire to exchange data. Although the figure shows a data synchronization device with various visual management backends, it should be understood that it is not required to implement or have all the visual management backends shown. More or fewer visual management backends can be implemented or provided instead.
[0160] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0161] The data synchronization device provided by the present application adopts the data synchronization method in the above embodiment, which can solve the technical problem of real-time data synchronization between redis clusters across regions. Compared with the prior art, the beneficial effects of the data synchronization device provided by the present application are the same as the beneficial effects of the data synchronization method provided by the above embodiment, and the other technical features in the data synchronization device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.
[0162] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0163] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0164] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, wherein the computer-readable program instructions are used to execute the data synchronization method in the above-mentioned embodiment.
[0165] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor visual management background, visual management background or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM: Random Access Memory), a read-only memory (ROM: ReadOnly Memory), an erasable programmable read-only memory (EPROM: Erasable Programmable Read Only Memory or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM: CD-Read Only Memory), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution visual management background, a visual management background or a device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency: Radio Frequency), etc., or any suitable combination of the above.
[0166] The computer-readable storage medium may be included in the data synchronization device; or may exist independently without being assembled into the data synchronization device.
[0167] The computer-readable storage medium carries one or more programs. When the one or more programs are executed by the data synchronization device, the data synchronization device:
[0168] Start the pre-created data synchronization task;
[0169] Acquire a task recovery function of the data synchronization task based on the offset of the master node data in the data synchronization task;
[0170] When it is detected that the data synchronization task is abnormally interrupted, the redis cluster topology update mechanism and the task recovery function are used to reconstruct the abnormally interrupted data synchronization task.
[0171] Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0172] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the visualization management background, method and computer program product according to various embodiments of the present application. In this regard, each box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the box can also occur in a sequence different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or the flow chart, and the combination of the boxes in the block diagram and / or the flow chart can be implemented with a dedicated hardware-based visualization management background that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0173] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.
[0174] The readable storage medium provided in this application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned data synchronization method, and can solve the technical problem of real-time data synchronization between redis clusters across regions. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as the beneficial effects of the data synchronization method provided in the above-mentioned embodiment, and will not be repeated here.
[0175] The present application also provides a computer program product, including a computer program, which implements the steps of the above-mentioned data synchronization method when executed by a processor.
[0176] The computer program product provided by this application can solve the technical problem of real-time data synchronization between redis clusters across regions. Compared with the prior art, the beneficial effects of the computer program product provided by this application are the same as the beneficial effects of the data synchronization method provided by the above embodiment, which will not be repeated here.
[0177] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A data synchronization method, characterized in that: The method comprises: Start the pre-created data synchronization task; Acquire a task recovery function of the data synchronization task based on the offset of the master node data in the data synchronization task; When it is detected that the data synchronization task is abnormally interrupted, the redis cluster topology update mechanism and the task recovery function are used to reconstruct the abnormally interrupted data synchronization task.
2. The method according to claim 1, characterized in that The step of obtaining the task recovery function of the data synchronization task based on the offset of the master node data in the data synchronization task includes: Split the master node data of the main redis cluster into multiple data synchronization subtasks through the data synchronization task; Cache the offset of the corresponding master node data through each of the data synchronization subtasks, and store the unique identifier of the master node data and the offset of the master node data in the database; The task recovery function of the data synchronization task is executed according to the unique identifier of the master node data and the offset of the master node data.
3. The method according to claim 2, characterized in that When the data synchronization task is detected to be abnormally interrupted, the steps of using the redis cluster topology update mechanism and the task recovery function to reconstruct the abnormally interrupted synchronization task include: When a data synchronization task is detected to be abnormally interrupted, the abnormally interrupted data synchronization task is reconnected according to the redis cluster topology update mechanism, and a partial synchronization PSYNC instruction is sent to the redis node to start the task recovery function; Data breakpoint resume transmission is performed according to the task recovery function.
4. The method according to claim 3, characterized in that The step of reconnecting the data in the abnormally interrupted data synchronization task according to the redis cluster topology update mechanism includes: Get the current node topology of the main redis cluster through the redis cluster node command; Based on the current node topology of the main redis cluster, query the currently available data nodes; Reestablish a connection for data in the abnormally interrupted data synchronization task through the currently available data nodes.
5. The method according to claim 2, characterized in that Before the step of sending a synchronous PSYNC instruction to the redis node to start the task recovery function, the step further includes: The corresponding master node data synchronization offset is queried from the database through the unique identifier of the master node data; The unique identifier of the master node data and the offset of the master node data are sent to the corresponding redis node as parameters of the PSYNC instruction.
6. The method according to claim 5, characterized in that The step of performing data breakpoint resuming according to the task recovery function comprises: Verify the unique identifier of the master node data and the offset of the master node data in the redis node to determine whether the master node data is executing the data synchronization task for the first time; If it is determined that the master node data is executing the data synchronization task for the first time, full data synchronization and incremental data synchronization processing are performed according to the first preset command; If it is determined that the master node data is not executing the data synchronization task for the first time, data incremental synchronization processing is performed according to the second preset command.
7. The method according to claim 1, characterized in that After the step of using the redis cluster topology update mechanism and the task recovery function to rebuild the abnormally interrupted data synchronization task when the data synchronization task is detected to be abnormally interrupted, the method further includes: When it is detected that the data synchronization task fails to execute, the data consistency level of the redis cluster is used to execute a corresponding data synchronization compensation strategy for each failed data synchronization task.
8. The method according to claim 7, characterized in that When the data synchronization task fails to be executed, the step of using the data consistency level of the redis cluster to execute a corresponding data synchronization compensation strategy for each failed data synchronization task includes: When it is detected that the data synchronization task fails to execute, the data consistency level of the redis cluster is confirmed; If the data consistency level of the redis cluster is a high consistency requirement, the data in the data synchronization task that failed to synchronize is persistently recorded based on the first preset command, and the data in the data synchronization task that failed to synchronize is resent to the standby redis cluster; If the data consistency level of the redis cluster meets the general consistency requirement, the data synchronization task that failed to synchronize is re-executed according to the preset maximum number of retries.
9. The method according to claim 1, characterized in that After the step of starting the pre-created data synchronization task, the method further includes: Deploy the data synchronization task to the application instance for execution; When the data synchronization task starts to execute, the corresponding state of the data synchronization task in the database is set to be turned on, and the application instance is used to check whether the data synchronization task in the database with the state of being turned on is executed healthily; If so, the data synchronization task in the database in the enabled state is exclusively locked and restarted through the application instance.
10. A data synchronization device, characterized in that: The data synchronization device comprises: The start module is used to start the pre-created data synchronization task; An acquisition module, used for acquiring a task recovery function of the data synchronization task based on an offset of the master node data in the data synchronization task; The reconstruction module is used to rebuild the abnormally interrupted data synchronization task by using the redis cluster topology update mechanism and the task recovery function when the data synchronization task is detected to be abnormally interrupted.
11. A data synchronization device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the data synchronization method according to any one of claims 1 to 9.
12. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the data synchronization method according to any one of claims 1 to 9 are implemented.
13. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the data synchronization method according to any one of claims 1 to 9 are implemented.
