Data synchronization method and apparatus, data storage system, and computer-readable medium
By configuring the client in the data storage system to record data written by the host and send it to other subsystems after successful synchronization with the slave, the problem of data inconsistency in the Redis cluster is solved, ensuring data consistency and system stability across multiple data centers.
Patent Information
- Application Number
- CN202080092808.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-02-26
- Publication Date
- 2025-12-23
- Estimated Expiration
- 2040-02-26
AI Technical Summary
In data storage systems across multiple data centers, existing technologies cannot effectively guarantee data consistency, especially during master-slave synchronization in a Redis cluster. Data inconsistency may result when the master fails to synchronize data, causing the slave to fail to synchronize data.
By setting up clients within each subsystem, recording the data written by the host, and only sending the data to other subsystems after the data has been successfully synchronized to the slave, the consistency of data between the host and slave is ensured. Furthermore, when the slave is upgraded to host after the host fails, the data has already been synchronized to other subsystems.
This ensures data consistency across subsystems after the host system crashes, avoiding data inconsistency issues and improving system stability and data synchronization reliability.
Smart Images

Figure CN114981796B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, more particularly, to a data synchronization method and device, a data storage system and a computer readable medium. BACKGROUND
[0002] With the increasing popularity of network services, the access amount of users is increasing. If all business data is stored in one server, the server will often fail due to too large access amount, and due to the limitation of server storage space, in the application scenario where the amount of business data is large, one server often cannot carry all the business data, so multiple servers are needed to provide services for users. For this purpose, multiple servers used for providing a certain service can be set in the same machine room, and the machine room provides the service to users.
[0003] The data in multiple machine rooms needs to be consistent, and once the data in each machine room is inconsistent, it will affect the normal use of users. Since business data often changes, if the data in a machine room changes, other machine rooms do not update in time, which will lead to inconsistent data. Moreover, if multiple machine rooms update at the same time, it is more likely to lead to inconsistent data. Therefore, there is currently no effective mechanism to ensure that the data in multiple machine rooms is completely consistent. SUMMARY
[0004] The present application provides a data synchronization method and device, a data storage system and a computer readable medium to improve the above-mentioned defects.
[0005] In a first aspect, the present application provides a data synchronization method, applied to a data storage system, the data storage system comprising multiple subsystems, each of the subsystems comprising a host and at least one slave corresponding to the host, the method comprising: obtaining target data written to the host; synchronizing the target data to the slave corresponding to the host; if the target data is successfully synchronized to the slave corresponding to the host, sending the target data to other subsystems to instruct the other subsystems to perform a data synchronization operation.
[0006] In a second aspect, the embodiments of the present application further provide a data synchronization apparatus applied to a data storage system, the data storage system comprising a plurality of subsystems, each of the subsystems comprising a host and at least one slave corresponding to the host, the apparatus comprising: an acquisition unit, a synchronization unit and a processing unit. The acquisition unit is configured to acquire target data written into the host. The synchronization unit is configured to synchronize the target data to the slave corresponding to the host. The processing unit is configured to send the target data to other subsystems if the target data is successfully synchronized to the slave corresponding to the host, and instruct the other subsystems to perform a data synchronization operation.
[0007] In a third aspect, the embodiments of the present application further provide a data storage system, comprising: a plurality of subsystems, each of the subsystems comprising a host and at least one slave corresponding to the host; and the host is configured to perform the method of any one of claims 1-17.
[0008] In a fourth aspect, the embodiments of the present application further provide a computer readable medium, the readable storage medium storing a program code executable by a processor, the program code being executed by the processor to cause the processor to perform the method.
[0009] The data synchronization method, apparatus, data storage system and computer readable medium provided by the present application synchronize target data to the slave corresponding to the host when the host is written with the target data, and send the target data to other subsystems if the target data is successfully synchronized to the slave corresponding to the host, and instruct the other subsystems to perform a data synchronization operation. Therefore, the embodiments of the present application can send data to other subsystems after determining that the target data is successfully synchronized to the slave corresponding to the host, i.e. after the data synchronization of the host and the slave is completed, and then the other subsystems perform synchronization, which can avoid the situation that the host sends data to other subsystems for synchronization, but the slave corresponding to the host has not been successfully synchronized, resulting in inconsistent data in each subsystem. BRIEF DESCRIPTION OF DRAWINGS
[0010] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed in the embodiment description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without any creative effort.
[0011] Figure 1 A schematic diagram of the data storage system provided by the embodiments of the present application is shown;
[0012] Figure 2 A method flowchart of the data synchronization method provided by an embodiment of the present application is shown;
[0013] Figure 3 a method flow chart of a data synchronization method provided by another embodiment of the present application is shown;
[0014] Figure 4 a method flow chart of a data synchronization method provided by an embodiment of the present application is shown; Figure 3 a method flow chart of S330 is shown;
[0015] Figure 5 a method flow chart of a data synchronization method provided by another embodiment of the present application is shown; Figure 3 a method flow chart of S330 is shown;
[0016] Figure 6 a method flow chart of a data synchronization method provided by another embodiment of the present application is shown;
[0017] Figure 7 a method flow chart of a data synchronization method provided by another embodiment of the present application is shown;
[0018] Figure 8 a method flow chart of a data synchronization method provided by another embodiment of the present application is shown;
[0019] Figure 9 a module block diagram of a data synchronization apparatus provided by an embodiment of the present application is shown;
[0020] Figure 10 a module block diagram of a data synchronization apparatus provided by another embodiment of the present application is shown;
[0021] Figure 11 a module block diagram of a data synchronization apparatus provided by another embodiment of the present application is shown;
[0022] Figure 12 a module block diagram of a data synchronization apparatus provided by another embodiment of the present application is shown;
[0023] Figure 13 a schematic diagram of an electronic device provided by an embodiment of the present application is shown;
[0024] Figure 14 a storage unit for saving or carrying program codes for implementing the data synchronization method according to the embodiments of the present application. DETAILED DESCRIPTION
[0025] In order to make the personnel in the technical field better understand the present application, the technical solutions in the embodiments of the present application will be described clearly and completely in conjunction with the drawings in the embodiments of the present application.
[0026] With the increasing prevalence of internet services and the growing volume of user traffic, storing all business data on a single server often leads to server failures due to excessive traffic. Furthermore, server storage space is limited, and in applications with large volumes of business data, a single server is often insufficient to handle all the data. Therefore, multiple servers are needed to provide services to users. To address this, multiple servers dedicated to providing a specific service can be located in the same data center, which then provides that service to users.
[0027] Among the aforementioned data management services, in-memory databases are widely used. An in-memory database refers to a database that operates directly on data stored in memory. It is typically deployed in a cluster, known as an in-memory database cluster. An in-memory database cluster consists of an in-memory database master and in-memory database slaves, which need to maintain data synchronization. Furthermore, synchronization is divided into full synchronization and incremental synchronization. Full synchronization means that the in-memory database slave synchronizes all data from the in-memory database master at once, while incremental synchronization means that the in-memory database slave only synchronizes the data that differs from the in-memory database master.
[0028] Redis is a high-performance, open-source, in-memory database written in ANSI C, providing programming interfaces for multiple languages. It is commonly used to implement data storage and fast access in software or applications. In production environments, Redis is widely used. For example, to ensure service stability while scaling business operations, Redis clusters supporting distributed high availability and horizontal scaling are often used for data storage and access. To improve system stability, Redis systems typically employ a master-slave architecture. During the initialization phase of a Redis slave node and when new data is written to the master node, a copy of the data on the master node needs to be created as a backup. This process is called Redis master-slave data synchronization.
[0029] like Figure 1 As shown, Figure 1 A schematic diagram of a data storage system is shown, which includes multiple subsystems, such as... Figure 1 As shown, the multiple subsystems include subsystem 1, subsystem 2, and subsystem 3. Each subsystem includes a master unit and at least one slave unit corresponding to the master unit. Figure 1As shown, the subsystem 1 includes a master 10 and the corresponding slave 11 and slave 12 of the master, wherein the master 10 and the slave 11 and the slave 12 are in a master-slave relationship. The master is also called a master node, which provides services to the outside. The slave is also called a slave node, which replicates the data of the master node in real time to ensure consistency with the master node. The slave cannot perform data write operations by other devices, and the data in the slave is synchronized to the master by the master through data synchronization.
[0030] In addition, as Figure 1 As shown, the subsystem 2 includes a master 20 and the corresponding slave 21 and slave 22 of the master, and the subsystem 3 includes a master 30 and the corresponding slave 31 and slave 32 of the master.
[0031] When the master in one of the subsystems is written with data, in order to ensure the consistency of the data of the entire system, the master in the subsystem will synchronize the written data to the slave corresponding to the master in the subsystem, and will need to send the data to other subsystems. The master in the other subsystem will write the data and synchronize the data to the slave corresponding to the master.
[0032] Taking the master 10 in the above subsystem 1 as an example, the master 10 will synchronize the data data to the slave 11 and the slave 12 corresponding to the master, and the master 10 will send the data data to the subsystem 2 and the subsystem 3. Specifically, it can be sent to the master 20 of the subsystem 2 and the master 30 of the subsystem 3. The master 20 of the subsystem 2 synchronizes the data data to the slave 21 and the slave 22 corresponding to the master 20. The master 30 of the subsystem 3 synchronizes the data data to the slave 31 and the slave 32 corresponding to the master 30.
[0033] As an implementation, a log pipeline function is provided in each subsystem, which is used to record the operation of writing data by the master. In a Redis cluster cross-machine room multi-active solution based on log pipeline, all data writes of Redis are saved to the log pipeline of the local disk. An external scanning program scans the log pipeline and synchronizes the data modification to the Redis cluster in other machine rooms. Each Redis cluster can be understood as the above-mentioned subsystem. Through the log pipeline, each write operation of the master can be recorded to facilitate data synchronization.
[0034] However, the inventors found in research that due to the delay of the master-slave synchronization of the Redis cluster itself, it is possible that a Master node has written data into a log stream and synchronized to other clusters in other rooms, but has not yet synchronized to a Slave node. If the Master node is down at this time, the Slave node is upgraded to a Master node to continue service, then a data inconsistency occurs, that is, the Slave node does not have the last part of the write operation data, but other clusters have this part of the data.
[0035] Taking the above subsystem 1 as an example, the host 10 of the subsystem 1 is written with data data, the host 10 synchronizes the data to the slave 11 and the slave 12, and also sends the data to the subsystem 2 and the subsystem 3. If the host 10 is down at this time, the slaves 11 and 12 have not successfully synchronized the data data, but the subsystem 2 and the subsystem 3 have successfully obtained the data data and successfully written the host and the corresponding slave, that is, the subsystem 2 and the subsystem 3 have successfully synchronized the data data. Since the host 10 is down, the slave 11 is upgraded to a new host 11, so at this time the data in the host 11 does not have the data data, thereby causing the data in the host 11 to be inconsistent with the data in other subsystems, and further causing the data of the subsystem 1 corresponding to the host 11 to be inconsistent with the data of the subsystem 2 and the subsystem 3.
[0036] Therefore, in order to overcome the above-mentioned defects, the embodiment of the present application provides a data synchronization method, which is applied to the above-mentioned data storage system. As an implementation manner, each subsystem in the data storage system is correspondingly provided with a client, which is used to synchronize the data of the host to the slave and execute the embodiment of the method described in the present application. As an implementation manner, the client can be installed in the host of each subsystem, or can be provided in a terminal independent of the host in each subsystem. In the embodiment of the present application, the client can be installed in the host of each subsystem.
[0037] Please refer to Figure 2 , Figure 2 a data synchronization method is shown, and the execution subject of the method can be the above-mentioned client. Specifically, the method comprises S201 to S203.
[0038] S201: obtaining target data written into the host.
[0039] As an implementation, each data written to the host can be recorded, specifically, a data write record can be set, and each data written to the host can be recorded in the data write record, that is, each data written to the host and the write information corresponding to each data are included in the write record. As an implementation, the write information includes the identification of each data written to the host, the time of writing, etc. The identification of the data written to the host can mark the data written each time, and the time of writing can record the time of each data written.
[0040] As an implementation, the write record can be the log stream function described above. Specifically, taking the Redis system as an example, the source code of the Redis component is modified to add the binlog (i.e., log stream) function, and each write operation is recorded to the log file, and the order of the log record is consistent with the order of the actual received write operation. For example, multiple data are written to the host, and the multiple data are data1, data2, data3, data4, data5, and data6, that is, the write order of the multiple data is data1, data2, data3, data4, data5, and data6, and the multiple data are recorded to the log file, and the order of the log record is also data1, data2, data3, data4, data5, and data6, wherein data1, data2, data3, data4, data5, and data6 can be the identification of the multiple data, and the write time of each written data can also be recorded in the log record.
[0041] In addition, the host and the slave can correspond to a log file, that is, the host and the slave can perform the log stream function to record the write operation of the host and the slave, wherein the write operation of the slave can be understood as the data synchronization operation of the host to the slave.
[0042] Therefore, through the above recording of the written data, the target data written to the host can be obtained, wherein the target data can be a collection of multiple data continuously written, or can be a certain data in the multiple data continuously written.
[0043] S202: Synchronize the target data to the slave corresponding to the host.
[0044] After the target data is written to the host, the target data is stored in the storage space corresponding to the host, and then the data synchronization operation is performed, specifically, the client described above can send the target data written to the host to the slave corresponding to the host, so that the data stored in the slave is also updated. That is, the target data is synchronized to the storage space corresponding to the slave.
[0045] The slave corresponding to the master can be a slave in a subsystem, the subsystem including the master and the slave, and the slave in the subsystem is the slave corresponding to the master in the subsystem. For example, the slaves corresponding to the master 10 are the slave 11 and the slave 12.
[0046] S203: If the target data is successfully synchronized to the slave corresponding to the master, the target data is sent to other subsystems to instruct the other subsystems to perform a data synchronization operation.
[0047] It should be noted that the execution subject of the above method can be a master in each subsystem of a plurality of subsystems in a data storage system, which can be named as a target master, and the target master can be a master to which the target data is directly written.
[0048] The client determines whether the target data is successfully synchronized to the slave corresponding to the master. Specifically, how to determine whether the target data is successfully synchronized to the slave corresponding to the master can refer to subsequent embodiments, which will not be described here.
[0049] If the target data is successfully synchronized to the slave corresponding to the master, it can be determined that the target data written to the master has been successfully synchronized to the slave corresponding to the master, and then the target data can be sent to other subsystems. At this time, even if the master is down, the slave corresponding to the master is used as a new master, and the target data is included in the data in the new master. After the other subsystems complete the data synchronization operation, the target data is included in the new master and the other subsystems, which can ensure the consistency of the data.
[0050] Taking the above data storage system as an example, the master 10 of the subsystem 1 is written with the target data, the master 10 synchronizes the target data to the slave 11 and the slave 12, and after determining that the slave 11 and the slave 12 successfully synchronize the target data, the target data is sent to the subsystem 2 and the subsystem 3, and the subsystem 2 and the subsystem 3 perform a synchronization operation of the target data after obtaining the target data. Specifically, the master 10 sends the target data to the master 20 in the subsystem 2 and the master 30 in the subsystem 3, the master 20 is written with the target data, and the target data is synchronized to the slave 21 and the slave 22 corresponding to the master 20, and the master 30 is written with the target data, and the target data is synchronized to the slave 31 and the slave 32 corresponding to the master 20.
[0051] As an implementation manner, the master 10 simultaneously sends the target data to the master 20 in the subsystem 2 and the master 30 in the subsystem 3, and the master 20 and the master 30 each perform a data synchronization operation.
[0052] As another implementation, the host 10 sends the target data to the host 20 in the subsystem 2, the host 20 writes the target data into the host 20 and synchronizes the target data to the slaves 21 and 22 corresponding to the host 20. Then the target data is sent to the host 30 in the subsystem 3, the host 30 writes the target data and synchronizes the target data to the slaves 31 and 32 corresponding to the host 20.
[0053] Referring to Figure 3 , Figure 3 A data synchronization method is shown, and the execution subject of the method can be the client as described above. Specifically, the method comprises S310 to S340.
[0054] S310: obtaining target data written into the host.
[0055] S320: synchronizing the target data to the slaves corresponding to the host.
[0056] S330: determining whether the target data is successfully synchronized to the slaves corresponding to the host.
[0057] Specifically, whether the target data is successfully synchronized to the slaves corresponding to the host can be determined according to the information replied by the slaves, and can also be determined according to the data write records of the host and the slaves, i.e. the log files of the host and the slaves.
[0058] As an implementation, referring to Figure 4 , the implementation of determining whether the target data is successfully synchronized to the slaves corresponding to the host can comprise S331 to S333.
[0059] S331: detecting whether the information of synchronization success replied by the slaves corresponding to the host is received.
[0060] S332: if the information is received, determining that the target data is successfully synchronized to the slaves corresponding to the host.
[0061] S333: if the information is not received, determining that the target data is not successfully synchronized to the slaves corresponding to the host.
[0062] The information of synchronization success can be sent by the slaves to the host after the target data is received and successfully stored, and the host can determine that the target data is successfully synchronized to the slaves corresponding to the host after receiving the information.
[0063] As an implementation, it can be determined whether the slave corresponding to the host receives the information of the synchronization success within a predetermined time period. The time start point of the predetermined time period can be the time point of performing the operation of synchronizing the target data to the slave corresponding to the host, and the predetermined time length of the predetermined time period can be predetermined, for example, can be set according to experience. Specifically, the time length of synchronizing the data by the slave can be counted, and the predetermined time length of the predetermined time period can be determined according to the time length.
[0064] As an implementation, the time length of synchronizing multiple data by the slave can be obtained, and the predetermined time length of the predetermined time period can be determined according to the multiple time lengths. Specifically, the average value of the multiple time lengths can be calculated, and the average value can be taken as the predetermined time length of the predetermined time period.
[0065] As another implementation, the rate of synchronizing the data by the slave can be counted, and the predetermined time length of the predetermined time period can be obtained according to the data size of the target data and the counted rate of synchronizing the data. For example, the ratio of the data size of the target data to the counted rate of synchronizing the data can be taken as the predetermined time length of the predetermined time period.
[0066] As an implementation, the client performs the operation of synchronizing the target data to the slave corresponding to the host, sends the inquiry instruction to the slave corresponding to the host, and the slave feeds back the information of the synchronization success after successfully completing the data synchronization after obtaining the inquiry instruction. Specifically, the inquiry instruction includes the identification of the target data, and the slave judges whether the data synchronization operation corresponding to the identification of the target data is successfully completed, and feeds back the information of the synchronization success if it is successfully completed.
[0067] Specifically, the host judges whether the information of the synchronization success fed back by the slave is obtained within a predetermined time period after sending the inquiry instruction to the slave, and if it is obtained, it is determined that the target data is successfully synchronized to the slave corresponding to the host, and if it is not obtained, it is determined that the target data is not successfully synchronized to the slave corresponding to the host. The operation of synchronizing the target data to the slave corresponding to the host can be performed again, and the above-mentioned judgment of whether the information of the synchronization success fed back by the slave is obtained within a predetermined time period can be performed again. At this time, the time start point of the predetermined time period becomes the time point of performing the operation of synchronizing the target data to the slave corresponding to the host again.
[0068] As an implementation, please refer to Figure 5 The implementation of judging whether the target data is successfully synchronized to the slave corresponding to the host can include S334 to S336.
[0069] S334: obtaining first record information corresponding to the host, the first record information being used to record an operation of the host on the data written to the target.
[0070] As an implementation, the first record information includes an identification of data written by the host each time and an operation time, wherein the operation time is used to record a writing time point of the written data, and the identification of the written data can be an identification assigned by the host to each written data, and the identification can be determined according to the content of the data, for example, the identification of the data can be generated according to a data digest of the data, and as an implementation, the data digest of the target data can be taken as the identification of the target data, wherein the data digest can be used to describe the content of the target data. Then the first record information includes the writing time corresponding to the target identification of the target data.
[0071] S335: obtaining second record information corresponding to the slave, the second record information being used to record an operation of the slave on data synchronization.
[0072] Similarly, the second record information includes an identification of data synchronized by the slave each time and an operation time, wherein the operation time can be a data synchronization time of the data synchronized by the slave, and the implementation of the identification of the data can refer to the foregoing embodiments, which will not be described herein.
[0073] S336: determining whether the target data is successfully synchronized to the slave corresponding to the host according to the first record information and the second record information.
[0074] Wherein the first record information includes an identification of data written by the host and a writing time point corresponding to the identification, and the second record information includes an identification of data synchronized by the slave and a synchronization time corresponding to the identification, and then whether the target data is successfully synchronized to the slave corresponding to the host can be determined according to the identification of data written by the host, the writing time point corresponding to the identification, the identification of data synchronized by the slave, and the synchronization time corresponding to the identification.
[0075] As an implementation, it is judged whether the first operation time point in the first record information is earlier than the second operation time point in the second record information; if yes, it is determined that the target data is successfully synchronized to the slave corresponding to the host; if not, it is determined that the target data is not successfully synchronized to the slave corresponding to the host. Wherein, the first operation time point is the write-in time point of the target identification corresponding to the target data written in the host recorded in the first record information, and the second operation time point is the synchronization time of the target identification corresponding to the target data synchronized in the slave recorded in the second record information, and it is judged whether the synchronization time is later than the write-in time point, if yes, it is determined that the target data is successfully synchronized to the slave corresponding to the host, otherwise, it is determined that the target data is not successfully synchronized to the slave corresponding to the host.
[0076] Specifically, it can be judged whether the synchronization time of the target data identification exists in the second record information, and if yes, the operation of judging whether the synchronization time is later than the write-in time point is further performed. Wherein, the implementation of judging whether the synchronization time of the target data identification exists in the second record information can be judging whether the synchronization time of the target data identification exists in the second record information within a predetermined time period, and the implementation of the predetermined time period can refer to the foregoing embodiments.
[0077] As another implementation, considering the way of recording the write-in operation of the host and the data synchronization operation of the slave can be the above-mentioned log file, that is, recording the write-in operation of the host and the data synchronization operation of the slave in the form of log flow, a sequence number can be set for the host and the slave, and each write-in operation of the host and each data synchronization operation of the slave is recorded through the sequence number.
[0078] Specifically, the first record information is a first sequence number, and the first sequence number is used to perform an update operation according to a first update rule when the host is successfully written in the target data. Specifically, a first sequence number can be defined in advance, and the initial value of the first sequence number is a first initial value. Then, the value of the first sequence number is updated according to the first update rule each time the host is written in data, wherein the first update rule can be to increase or decrease a certain value, that is, each time the write-in operation is performed, the value of the first sequence number saved last time is increased or decreased by a certain value.
[0079] For example, the initial value of the first sequence number is a first initial value, and the first update rule is to increase a first value. When the host is written in data for the first time, the value of the first sequence number becomes the sum of the first initial value and the first value. After writing in data again, the value of the first sequence number becomes the sum of the first initial value and two first values, that is, the value of the first sequence number saved last time is increased by the first value.
[0080] In the embodiment of the present application, it is assumed that the first sequence number is seq1 and the initial value is 0. After the first time of writing data, the value of the first sequence number seq1 becomes 1. After the second time of writing data, the value of the first sequence number seq1 becomes 2. If the data to be written includes multiple data, the multiple data are data1, data2, data3, data4, data5 and data6 respectively. The correspondence between the data identifier and the value of the sequence number seq1 is shown in the following table.
[0081] Table 1
[0082] Data identification data1 data2 data3 data4 data5 data6 Value of sequence number seq1 1 2 3 4 5 6
[0083] Thus, the writing order of each writing data and the sequence number corresponding to the identifier of each writing data can be obtained through the above table 1. The sequence number can be used as the serial number of the writing data, and the target data can be recorded as the data to be written in the whole writing operation process.
[0084] Similarly, the second recording information is a second sequence number, and the second sequence number is used to perform an updating operation according to a second updating rule when the slave successfully synchronizes data. The second updating rule can be the same as the first updating rule, and the second updating rule can also be to increase a second value. Specifically, the initial value of the second sequence number is a second initial value, the second updating rule is to increase the second value, and the value of the second sequence number becomes the sum of the second initial value and the second value after the first time of synchronizing data by the slave. After synchronizing data again, the value of the second sequence number becomes the sum of the second initial value and two second values, i.e., the second value is added to the last saved second sequence number. The first value and the second value are the same, for example, both are 1. The first initial value and the second initial value can also be the same, for example, both can be 0.
[0085] It is assumed that the second sequence number is seq2 and the initial value is 0. After the first time of synchronizing data by the slave, the value of the second sequence number seq2 becomes 1. After the second time of synchronizing data, the value of the second sequence number seq2 becomes 2. If the data to be synchronized includes multiple data, the multiple data are data1, data2, data3, data4, data5 and data6 respectively. The correspondence between the data identifier and the value of the sequence number seq2 is shown in the following table.
[0086] Table 2
[0087] Data identification data1 data2 data3 data4 data5 data6 Value of sequence number seq2 1 2 3 4 5 6
[0088] It should be noted that the seq2 of the slave is changed when the slave successfully synchronizes the data, and the size relationship between the current seq2 and the size of the seq1 corresponding to the target data written by the host can be determined to determine whether the slave successfully synchronizes the target data. Specifically, please refer to the subsequent embodiments.
[0089] S340: If the target data is successfully synchronized to the slave corresponding to the host, the target data is sent to other subsystems, and the other subsystems are instructed to perform data synchronization operations.
[0090] Please refer to Figure 6 , Figure 6 a data synchronization method is shown, and the execution subject of the method can be the client described above. Specifically, the method comprises S601 to S609.
[0091] S601: Obtain target data written to the host.
[0092] S602: Synchronize the target data to the slave corresponding to the host.
[0093] S603: Obtain a first sequence number corresponding to the host.
[0094] The first sequence number is used to perform an update operation according to a first update rule when the host is successfully written with target data.
[0095] S604: Obtain a second sequence number corresponding to the slave.
[0096] The second sequence number is used to perform an update operation according to a second update rule when the slave successfully synchronizes data.
[0097] Wherein, the implementation of the first sequence number and the second sequence number can refer to the foregoing embodiments, which will not be repeated here.
[0098] S605: Obtain the size relationship between the first sequence number and the second sequence number.
[0099] Wherein, the size relationship can be whether the first sequence number is less than or equal to the second sequence number, or other size relationships that can represent whether the first sequence number is less than or equal to the second sequence number, for example, the ratio between the first sequence number and the second sequence number can also be obtained, if the ratio is greater than 1, it indicates that the first sequence number is greater than the second sequence number, and if the ratio is not greater than 1, it indicates that the first sequence number is less than or equal to the second sequence number.
[0100] As an implementation, the size relationship can be determined according to the first update rule and the second update rule. If the first update rule and the second update rule are the same and both are to increase the same value based on the initial value, the size relationship can be whether the first serial number is less than or equal to the second serial number. If the first update rule and the second update rule are the same and both are to subtract the same value based on the initial value, the size relationship can be whether the first serial number is greater than or equal to the second serial number. If the first update rule and the second update rule are not the same, the change value corresponding to the first update rule is k times the change value corresponding to the second update rule, the size relationship can be whether the ratio of the second serial number to the first serial number is a positive integer multiple of k.
[0101] S606: Determine whether the size relationship satisfies a specified condition.
[0102] The size relationship satisfying the specified condition indicates that the slave successfully synchronizes the target data after the master is written with the target data.
[0103] In the case that the first update rule and the second update rule are the same or different, the size relationship described above is also different, and thus the corresponding specified condition is also different.
[0104] For example, if the first update rule and the second update rule are the same and both are to increase the same value based on the initial value, the size relationship can be whether the first serial number is less than or equal to the second serial number. If the first serial number is less than or equal to the second serial number, it is determined that the size relationship satisfies the specified condition, otherwise, it is determined that the size relationship does not satisfy the specified condition.
[0105] If the first update rule and the second update rule are the same and both are to subtract the same value based on the initial value, the size relationship can be whether the first serial number is greater than or equal to the second serial number. If the first serial number is greater than or equal to the second serial number, it is determined that the size relationship satisfies the specified condition, otherwise, it is determined that the size relationship does not satisfy the specified condition.
[0106] If the first update rule and the second update rule are not the same, the change value corresponding to the first update rule is k times the change value corresponding to the second update rule, the size relationship can be whether the ratio of the second serial number to the first serial number is a positive integer multiple of k. If the ratio of the second serial number to the first serial number is a positive integer multiple of k, it is determined that the size relationship satisfies the specified condition, otherwise, it is determined that the size relationship does not satisfy the specified condition.
[0107] In the embodiments of the present application, the first update rule and the second update rule can be the same, and both increase the same value on the basis of the initial value. The specified condition for the size relationship is that if the first sequence number is less than or equal to the second sequence number.
[0108] As an implementation, the first sequence number is changed according to the first update rule, and the second sequence number is changed according to the second update rule. When the host completes the write operation of the target data, the first value of the first sequence number after being updated by the first update rule, and the second value of the second sequence number after being updated by the second update rule when the slave completes the synchronization operation of the target data, the size relationship between the first value and the second value should satisfy the relationship of the first update rule and the second update rule. For example, if the first update rule and the second update rule are the same, the size relationship between the first value and the second value should be the same. If the first update rule is to increase or decrease a value a, and the second update rule is to increase a value b, and the ratio of the value a and the value b is c, then the size relationship between the first value and the second value should also satisfy that the ratio of the value a and the value b is n times of c, where n is a positive integer.
[0109] Suppose that the first update rule and the second update rule are the same, both are to increase 1, and the initial value of the first sequence number and the initial value of the second sequence number are the same, and the first sequence number of the host and the second sequence number of the slave are initialized, i.e. restored to the initial value, each time the write operation is performed. In the case of one data being written, i.e. in the case of one data being the target data, the first sequence number of the host should be 1 after the target data is written, and the second sequence number of the slave should be 1 after the target data is successfully synchronized, i.e. the first sequence number and the second sequence number are the same.
[0110] In addition, considering the case of multiple data being written by the host, the data synchronization operation of the host and the detection by the host whether the target data is successfully synchronized to the slave corresponding to the host are performed synchronously. Therefore, there can be a case that the slave has successfully synchronized to data3 when the host determines whether data1 is successfully synchronized by the slave, and data3 is data written after data1. At this time, the second sequence number of the slave is greater than the first sequence number. Therefore, if the second sequence number is greater than the first sequence number, it can be explained that the data corresponding to the first sequence number has been successfully synchronized to the slave.
[0111] The write order of the data written by the host and the synchronization order of the data written by the host to the slave can be the same. For example, the write order of the data written by the host is data1, data2, data3, data4, data5 and data6, and the synchronization order of the data written by the host to the slave is data1, data2, data3, data4, data5 and data6.
[0112] Therefore, the first sequence number corresponding to the target data written by the host is obtained, and the second sequence number of the slave is obtained. If the first sequence number is less than or equal to the second sequence number, it indicates that the slave successfully synchronizes the target data after the host writes the target data.
[0113] For example, the data written by the host includes data1, data2, data3, data4, data5 and data6, and data1, data2, data3, data4, data5 and data6 are successfully written to the host. At this time, data2 is the target data. Referring to Table 1, the first sequence number corresponding to the target data is seq1 equal to 2. The host synchronizes data1, data2, data3, data4, data5 and data6 to the slave in turn. At this time, the seq2 of the slave is 1, which indicates that the data successfully synchronized by the slave is data1. The first sequence number is greater than the second sequence number, which indicates that the target data is not successfully synchronized to the slave corresponding to the host.
[0114] If the seq2 of the slave at this time is 2, it indicates that the data successfully synchronized by the slave is data2, i.e., the data successfully synchronized by the slave is the target data. The first sequence number is equal to the second sequence number, which indicates that the target data is not successfully synchronized to the slave corresponding to the host.
[0115] If the seq2 of the slave at this time is 3, it indicates that the data successfully synchronized by the slave is data3, i.e., the data successfully synchronized by the slave is the data data3 after the target data. The first sequence number is less than the second sequence number, which indicates that the target data is not successfully synchronized to the slave corresponding to the host.
[0116] Therefore, when the first sequence number is less than or equal to the second sequence number, it can be determined that the target data is successfully synchronized to the slave corresponding to the host.
[0117] In addition, when the host corresponds to multiple slaves, each slave corresponds to a second sequence number. The above detection method can be used to determine whether each slave successfully synchronizes the target data, thereby determining whether the target data is successfully synchronized to the slave corresponding to the host.
[0118] In some embodiments, the operation of detecting whether the target data is successfully synchronized to the slave corresponding to the host can be named as a scanning operation, and if the first sequence number is greater than the second sequence number, i.e., it is determined that the target data is not successfully synchronized to the slave corresponding to the host, a certain time period can be waited before the scanning operation is continued to be executed, i.e., the scanning operation is paused during the time period so that the slave can complete the synchronization operation of the target data during the time period.
[0119] Specifically, if the size relationship does not satisfy the specified condition, the method further includes, after it is determined that the target data is not successfully synchronized to the slave corresponding to the host, acquiring again the size relationship between the first sequence number and the second sequence number and subsequent operations after a specified time length, wherein the operation of synchronizing the target data to the slave corresponding to the host is continued to be executed during the specified time length. The specified time length can be a preset time length, e.g., the specified time length can be the same as the preset time length corresponding to the above-mentioned predetermined time period, and specifically, the specified time length can be 10 ms.
[0120] S607: It is determined that the target data is successfully synchronized to the slave corresponding to the host.
[0121] S608: It is determined that the target data is not successfully synchronized to the slave corresponding to the host.
[0122] S609: The target data is sent to other subsystems to instruct the other subsystems to perform a data synchronization operation.
[0123] Exemplarily, a host is written with target data, then, an operation of synchronizing the target data to the slave corresponding to the host is performed, a first sequence number corresponding to the host is acquired, a second sequence number corresponding to the slave is acquired, it is determined whether the first sequence number is less than or equal to the size relationship of the second sequence number, if the first sequence number is less than or equal to the second sequence number, it is determined that the target data is successfully synchronized to the slave corresponding to the host, then the target data is sent to other subsystems to instruct the other subsystems to perform a data synchronization operation, and the other subsystems also perform the data synchronization operation and the above-mentioned scanning operation. If the first sequence number is greater than the second sequence number, it is determined that the target data is not successfully synchronized to the slave corresponding to the host, a specified time length is delayed, and after the specified time length, the size relationship between the first sequence number and the second sequence number is acquired again and subsequent operations, wherein the operation of synchronizing the target data to the slave corresponding to the host is continued to be executed during the specified time length.
[0124] Please refer to Figure 7 , Figure 7A data synchronization method is shown, and the execution subject of the method can be the client described above. Specifically, the method comprises S701-S705.
[0125] S701: Obtain target data written to the host.
[0126] S702: Synchronize the target data to the slave corresponding to the host.
[0127] S703: According to a preset order, sequentially detect whether each sub-data is successfully synchronized to the slave corresponding to the host.
[0128] As an implementation manner, the host is sequentially written with multiple data, i.e., the target data is multiple sub-data, wherein the multiple sub-data can be the data1, data2, data3, data4, data5 and data6 described above, and the preset order can be the order in which the multiple sub-data are sequentially written to the host. For example, the order in which the multiple sub-data are sequentially written to the host is data1, data2, data3, data4, data5 and data6. Then, the order in which the host synchronizes the multiple sub-data to the slave is also data1, data2, data3, data4, data5 and data6, and the client sequentially detects whether data1, data2, data3, data4, data5 and data6 are all synchronized to the slave according to data1, data2, data3, data4, data5 and data6.
[0129] S704: If the detection result of each sub-data is that it is successfully synchronized to the slave corresponding to the host, it is determined that the target data is successfully synchronized to the slave corresponding to the host.
[0130] As an implementation manner, when the host is sequentially written with multiple sub-data according to a preset order, the client can sequentially check whether each sub-data is successfully written to the slave according to the preset order.
[0131] Specifically, when the host corresponds to multiple slaves, it can be sequentially detected whether the detection result of each sub-data is that it is successfully synchronized in the multiple sub-data synchronized to each slave. Of course, according to the data of the sub-data, it can be determined whether each sub-data is successfully synchronized to each slave according to a preset order.
[0132] In the embodiment of the application, the scanning manner can be to determine whether each sub-data is successfully synchronized to each slave according to a preset order. For example, the host 10 corresponds to the slave 11 and the slave 12.
[0133] The client first detects whether the sub-data data1 is successfully synchronized to the slave 1 and the slave 2, and if yes, then detects whether the sub-data data2 is successfully synchronized to the slave 1 and the slave 2, and so on. In some embodiments, if the detection result of each of the sub-data in the slave 11 and the slave 12 is successfully synchronized, it is determined that the target data is successfully synchronized to the slave corresponding to the host. Of course, in the case of considering a relatively large number of slaves, it can be determined that the target data is successfully synchronized to the slave corresponding to the host when the detection result of each of the sub-data in a partial number of slaves is successfully synchronized, thereby reducing the scanning time and improving the speed of data synchronization of the entire system.
[0134] In addition, the operation data of the plurality of sub-data is stored, wherein the operation data includes at least one of the detection result of whether the sub-data is successfully synchronized to the slave corresponding to the host and the write information written to the host. In the embodiments of the present application, the operation data includes the detection result of whether the sub-data is successfully synchronized to the slave corresponding to the host and the write information written to the host, wherein the write information includes the data written to the host. In addition, taking the first sequence number and the second sequence number corresponding to the host as an example, the detection result of being synchronized to the slave corresponding to the host can correspond to the sequence number.
[0135] For example, taking the above table 1 as an example, when it is determined that a certain data is successfully synchronized to the slave, a result flag information can be set for the identification of the data, and the result flag information can include a first flag and a second flag, wherein the first flag is used to indicate that the data corresponding to the identification has been successfully synchronized to the slave, and the second flag is used to indicate that the data corresponding to the identification has not been successfully synchronized to the slave.
[0136] Through the above-mentioned stored operation data, when the host is down, the new host can continue to scan the data synchronization result of the slave according to the operation data, so as to avoid the inconsistency of the data when the host is down. Specifically, the method further includes: if the host is down, taking the slave corresponding to the host as a new host; obtaining the latest sub-data corresponding to a specified result as a target sub-data, wherein the specified result is successfully synchronized to the slave corresponding to the host; and according to the preset order, continuing to detect whether the sub-data after the target sub-data is successfully synchronized to the slave corresponding to the host from the target sub-data.
[0137] As an implementation, the slave currently being scanned is taken as a new host. For example, the slave 11 and the slave 12 mentioned above, if the client first scans the slave 11, and then scans the slave 12 after the scanning is completed, the slave currently being scanned is the slave 11, and the slave 11 can be taken as a new host, thereby reducing the scanning process of the new host.
[0138] Wherein, the latest detected sub-data corresponding to the specified result refers to that the host detects each sub-data whether successfully synchronized to the slave corresponding to the host according to the preset order one by one, and the latest detection result is the data identification of the successfully synchronized data, named as sub-data.
[0139] Specifically, the host corresponding to the written multiple sub-data of data1, data2, data3, data4, data5 and data6 shown in the above table 1, the first sequence number seq1 corresponding to the multiple sub-data is 1, 2, 3, 4, 5 and 6 in turn, then scan data first, get the value of the second sequence number seq2 of the slave, and judge whether seq2 is greater than or equal to 1, if yes, determine that the detection result of the sub-data data is successful synchronization, and set the first flag corresponding, and in turn, get the corresponding detection result of each sub-data.
[0140] Then, get the identification of the sub-data with the latest detection result as successful synchronization, for example, data3, which indicates that the target sub-data is data3, then continue to detect whether the sub-data after the target sub-data is successfully synchronized to the slave corresponding to the host according to the preset order, that is, continue to scan whether data4, data5 and data6 are successfully synchronized to the slave.
[0141] Thus, when the host determines that data3 is successfully synchronized to the slave, if the host is down, the slave can be used as a new host, and continue to scan whether the sub-data after data3 is successfully synchronized to the slave, so as to avoid that a certain sub-data is not scanned, resulting in unsuccessful synchronization, so as to ensure the consistency of data.
[0142] Taking the storage system as the Redis system, the scanning program requests all Redis nodes through the background thread at intervals of fixed time, judges whether the current is a Master node or a Slave node, and is used for detecting the master-slave switching state. When it is found that a Slave node is upgraded to a Master node, the sequence number saved by the previous Master node last time is obtained from the database, the new Master node log flow position is located according to the sequence number, and the scanning is continued from the position, so as to realize accurate connection in the master-slave switching process, and avoid the situation of data inconsistency or data loss caused by master-slave switching.
[0143] S705: If the target data is successfully synchronized to the slave corresponding to the host, the target data is sent to other subsystems, and the other subsystems are instructed to perform data synchronization operation.
[0144] Please refer to Figure 8 , Figure 8A data synchronization method is shown, and an execution subject of the method can be the client described above. Specifically, the method comprises S801 to S705.
[0145] S801: Obtain target data written to the host.
[0146] S802: Synchronize the target data to the slave corresponding to the host.
[0147] S803: If the number of slaves successfully synchronizing the target data is N, determine that the target data is successfully synchronized to the slave corresponding to the host.
[0148] The number of slaves corresponding to the host is M, where N is less than M, and M is a positive integer greater than 2, and N is a positive integer less than M.
[0149] As an implementation, the client obtains the detection result of whether each slave successfully synchronizes to the target data in sequence, and if N detection results are successfully synchronized, it is determined that the target data is successfully synchronized to the slave corresponding to the host. Specifically, taking the first sequence number and the second sequence number described above as an example, the client obtains the first sequence number corresponding to the target data, and obtains the second sequence number of each slave, determines the size relationship between each second sequence number and the first sequence number, and if the number of size relationships meeting the specified condition is greater than or equal to N, it is determined that the target data is successfully synchronized to the slave corresponding to the host.
[0150] In addition, S803 is also applicable to the detection of the plurality of sub-data described above, that is, when determining whether each sub-data is successfully synchronized to the slave corresponding to the host, the first sequence number corresponding to the sub-data and the second sequence number of each slave are obtained, the size relationship between each second sequence number and the first sequence number is determined, and if the number of size relationships meeting the specified condition is greater than or equal to N, it is determined that the sub-data is successfully synchronized to the slave corresponding to the host, and then the next sub-data is continuously scanned.
[0151] S804: If the target data is successfully synchronized to the slave corresponding to the host, send the target data to other subsystems to instruct the other subsystems to perform data synchronization operations.
[0152] Please refer to Figure 9 which shows a structural block diagram of a data synchronization device 900 provided by an embodiment of the application, which is applied to the data storage system described above, and the data synchronization device can comprise an obtaining unit 901, a synchronization unit 902, and a processing unit 903.
[0153] The obtaining unit 901 is configured to obtain target data written to the host.
[0154] The synchronization unit 902 is configured to synchronize the target data to the slave corresponding to the host.
[0155] The processing unit 903 is configured to, if the target data is successfully synchronized to the slave corresponding to the host, send the target data to other subsystems, and instruct the other subsystems to perform a data synchronization operation.
[0156] Please refer to Figure 10 which shows a structural block diagram of a data synchronization apparatus 1000 provided by an embodiment of the present application. The apparatus is applied to the data storage system mentioned above, and can include an acquisition unit 1010, a synchronization unit 1020, a judgment unit 1030, and a processing unit 1040.
[0157] The acquisition unit 1010 is configured to acquire target data written into the host.
[0158] The synchronization unit 1020 is configured to synchronize the target data to the slave corresponding to the host.
[0159] The judgment unit 1030 is configured to judge whether the target data is successfully synchronized to the slave corresponding to the host.
[0160] In some embodiments, the judgment unit 1030 is specifically configured to detect whether information of synchronization success fed back by the slave corresponding to the host is received; if yes, it is determined that the target data is successfully synchronized to the slave corresponding to the host; if not, it is determined that the target data is not successfully synchronized to the slave corresponding to the host.
[0161] In other embodiments, the judgment unit 1030 includes an acquisition sub-unit 1031 and a judgment sub-unit 1032.
[0162] The acquisition sub-unit 1031 is configured to acquire first record information corresponding to the host, and second record information corresponding to the slave.
[0163] The judgment sub-unit 1032 is configured to judge, according to the first record information and the second record information, whether the target data is successfully synchronized to the slave corresponding to the host.
[0164] As an implementation, the record information is used to record an operation time point of an operation, and the judging subunit 1032 is further configured to judge whether a first operation time point in the first record information is earlier than a second operation time point in the second record information; if yes, it is determined that the target data is successfully synchronized to the slave corresponding to the host; if not, it is determined that the target data is not successfully synchronized to the slave corresponding to the host.
[0165] As another implementation, the first record information is a first sequence number, the first sequence number is used to perform an updating operation according to a first updating rule when the host is successfully written with target data; the second record information is a second sequence number, the second sequence number is used to perform an updating operation according to a second updating rule when the slave successfully synchronizes data, and the first updating rule and the second updating rule are the same. The judging subunit 1032 is further configured to obtain a size relationship between the first sequence number and the second sequence number; if the size relationship satisfies a specified condition, it is determined that the target data is successfully synchronized to the slave corresponding to the host, wherein the size relationship satisfying the specified condition indicates that the slave successfully synchronizes the target data after the host is written with the target data; if the size relationship does not satisfy the specified condition, it is determined that the target data is not successfully synchronized to the slave corresponding to the host.
[0166] The first updating rule is to increase or decrease the first sequence number by a first value when the host is successfully written with target data, and the second updating rule is to increase or decrease the second sequence number by a second value when the slave successfully synchronizes data, and the first value and the second value are the same. The size relationship satisfying the specified condition means that the first sequence number is less than or equal to the second sequence number.
[0167] Further, the judging subunit 1032 is further configured to, after a specified time length, obtain a size relationship between the first sequence number and the second sequence number and a subsequent operation again, wherein the operation of synchronizing the target data to the slave corresponding to the host is continued within the specified time length.
[0168] The processing unit 1040 is configured to, if the target data is successfully synchronized to the slave corresponding to the host, send the target data to other subsystems, and instruct the other subsystems to perform a data synchronization operation.
[0169] Please refer to Figure 11 which shows a structural block diagram of a data synchronization device 1100 provided by an embodiment of the present application, the device is applied to the data storage system mentioned above, and the data synchronization device can include an obtaining unit 1101, a synchronizing unit 1102, a judging unit 1103 and a processing unit 1104.
[0170] The acquisition unit 1101 is configured to acquire target data written to the host.
[0171] The synchronization unit 1102 is configured to synchronize the target data to a slave corresponding to the host.
[0172] The judgment unit 1103 is configured to judge whether the target data is successfully synchronized to the slave corresponding to the host.
[0173] Specifically, the target data is a plurality of sub-data, and the judgment unit 1103 is further configured to sequentially detect, according to a preset order, whether each sub-data is successfully synchronized to the slave corresponding to the host; if the detection result of each sub-data is that the sub-data is successfully synchronized to the slave corresponding to the host, it is determined that the target data is successfully synchronized to the slave corresponding to the host.
[0174] Further, the judgment unit 1103 is further configured to, if the host is down, take the slave corresponding to the host as a new host; acquire a sub-data corresponding to a specified result as a target sub-data, where the specified result is that the sub-data is successfully synchronized to the slave corresponding to the host; and continue to detect, according to the preset order, whether a sub-data after the target sub-data is successfully synchronized to the slave corresponding to the host from the target sub-data. The preset order is an order in which the plurality of sub-data are sequentially written to the host.
[0175] Further, the judgment unit 1103 is further configured to store operation data of the plurality of sub-data, where the operation data includes at least one of a detection result of whether the sub-data is successfully synchronized to the slave corresponding to the host and write information of writing to the host.
[0176] The processing unit 1104 is configured to, if the target data is successfully synchronized to the slave corresponding to the host, send the target data to other subsystems, and instruct the other subsystems to perform a data synchronization operation.
[0177] Referring to Figure 12 , which shows a structural block diagram of a data synchronization device 1200 provided by an embodiment of the present application. The device is applied to the data storage system described above, and can include an acquisition unit 1201, a synchronization unit 1202, a judgment unit 1203, and a processing unit 1204.
[0178] The acquisition unit 1201 is configured to acquire target data written to the host.
[0179] The synchronization unit 1202 is configured to synchronize the target data to a slave corresponding to the host.
[0180] The judging unit 1203 is configured to judge whether the target data is successfully synchronized to the slave corresponding to the host.
[0181] Specifically, the number of the slaves corresponding to the host is M, and the judging unit 1203 is further configured to determine that the target data is successfully synchronized to the slave corresponding to the host if it is detected that the number of the slaves to which the target data is successfully synchronized is N, where N is less than M, M is a positive integer greater than 2, and N is a positive integer less than M. Here, N is M / 2.
[0182] The processing unit 1204 is configured to send the target data to other subsystems and instruct the other subsystems to perform data synchronization operations if the target data is successfully synchronized to the slave corresponding to the host.
[0183] Those skilled in the art can clearly understand the specific working process of the above-described devices and modules for the convenience and brevity of description, and the corresponding process in the foregoing method embodiments can be referred to, which will not be described herein.
[0184] In several embodiments provided in the present application, the coupling between the modules can be electrical, mechanical or other forms of coupling.
[0185] In addition, each functional module in each embodiment of the present application can be integrated in one processing module, or each module can exist physically independently, or two or more modules can be integrated in one module. The integrated module can be realized in the form of hardware or in the form of a software functional module.
[0186] Please refer to Figure 13 which shows a structural block diagram of an electronic device provided in an embodiment of the present application. The electronic device 100 can be a smart phone, a tablet computer, an electronic book, etc. capable of running an application program. In the present application, the electronic device 100 can be the host described above, and the electronic device 100 can include one or more of the following components: a processor 110, a memory 120, and the client described above, which includes one or more application programs, where the one or more application programs can be stored in the memory 120 and configured to be executed by the one or more processors 110, and the one or more programs are configured to perform the method as described in the foregoing method embodiments.
[0187] The processor 110 can include one or more processing cores. The processor 110 connects various parts within the entire electronic device 100 with various interfaces and lines, performs various functions of the electronic device 100 and processes data by running or executing instructions, programs, code sets or instruction sets stored in the memory 120, and calling data stored in the memory 120. Alternatively, the processor 110 can be implemented in at least one of a hardware form of a digital signal processing (DSP), a field-programmable gate array (FPGA), a programmable logic array (PLA). The processor 110 can integrate a combination of one or several of a central processing unit (CPU), a graphics processor (GPU), and a modem, etc. Among them, the CPU mainly processes an operating system, a user interface, and an application program, etc.; the GPU is responsible for rendering and drawing display content; and the modem is used for processing wireless communication. It can be understood that the above-mentioned modem can also not be integrated into the processor 110, but be implemented by a separate communication chip.
[0188] The memory 120 can include a random access memory (RAM) and can also include a read-only memory (ROM). The memory 120 can be used to store instructions, programs, codes, code sets or instruction sets. The memory 120 can include a program storage area and a data storage area, wherein the program storage area can store instructions for implementing an operating system, instructions for implementing at least one function (such as a touch function, a sound playing function, an image playing function, etc.), instructions for implementing each of the method embodiments described below, etc. The data storage area can also store data created by the electronic device 100 in use (such as a phone book, audio and video data, chat record data), etc.
[0189] Please refer to Figure 14 which shows a structural block diagram of a computer readable storage medium provided by the embodiments of the present application. The computer readable medium 1400 stores program codes therein, and the program codes can be called and executed by a processor to perform the methods described in the above method embodiments.
[0190] The computer-readable storage medium 1400 can be an electronic memory such as a flash memory, an EEPROM (electrically erasable programmable read-only memory), an EPROM, a hard disk or a ROM. Optionally, the computer-readable storage medium 1400 comprises a non-transitory computer-readable medium. The computer-readable storage medium 1400 has storage space for program codes 1410 for carrying out any of the method steps described above. These program codes can be read from or written to one or more computer program products. The program codes 1410 can be compressed, for example, in an appropriate form.
[0191] To sum up, the data synchronization method, device, data storage system and computer readable medium provided by the application, when the target data is written into the host, the target data is synchronized to the slave corresponding to the host, if the target data is successfully synchronized to the slave corresponding to the host, the target data is sent to other subsystems, and the other subsystems are instructed to perform data synchronization operations. Therefore, the embodiments of the application can send data to other subsystems after determining that the target data is successfully synchronized to the slave corresponding to the host, i.e., after the data synchronization of the host and the slave is completed, and then the other subsystems perform synchronization, which can avoid the situation that the host sends data to other subsystems for synchronization, but the slave corresponding to the host has not been successfully synchronized, resulting in inconsistent data in each subsystem.
[0192] Further, in the Redis cluster cross-machine room multi-active system using the embodiments of the application, after the master-slave switching caused by the failure of part of the Redis nodes, the synchronization can still be continued from the interrupted position, and the situation of data loss or data inconsistency will not be caused.
[0193] Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the application, and not to limit them; although the application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacement for part of the technical features; and these modifications or replacements do not drive the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the application.
Claims
1. A data synchronization method, characterized in that, A client is applied within a host of one of multiple subsystems of a data storage system, wherein each subsystem includes the host and at least one slave corresponding to the host, the method comprising: Obtain the target data to be written to the host, wherein the target data comprises multiple sub-data; After the target data is stored in the storage space corresponding to the host, the target data is synchronized to the slave device corresponding to the host. According to a preset order, each sub-data is checked sequentially to see whether it has been successfully synchronized to the slave device corresponding to the host. If the detection result of each of the sub-data is that it has been successfully synchronized to the slave corresponding to the host, then it is determined that the target data has been successfully synchronized to the slave corresponding to the host. If the target data is successfully synchronized to the slave device corresponding to the host, the target data is sent to other subsystems, instructing the other subsystems to perform data synchronization operations; The step of detecting whether each piece of sub-data has been successfully synchronized to the slave device corresponding to the host includes: Obtain the first serial number corresponding to the host. The first serial number is used to perform an update operation based on the initial value of the first serial number and the first update rule when the host is successfully written with data. Obtain the second serial number corresponding to the slave device. The second serial number is used to perform an update operation based on the initial value of the second serial number and the second update rule when the slave device successfully synchronizes data. The first update rule is the same as the second update rule, and the initial value of the first serial number is the same as the initial value of the second serial number. Obtain the size relationship between the first serial number and the second serial number; If the first sequence number is less than or equal to the second sequence number, then the sub-data is determined to have been successfully synchronized to the slave device corresponding to the host. The synchronization of target data between the master and slave devices and the master's detection of whether the target data has been successfully synchronized to the slave device corresponding to the master are executed simultaneously.
2. The method according to claim 1, characterized in that, The first update rule is to increment or decrement the first sequence number by a first value when the host is successfully written to the target data. The second update rule is to increment or decrement the second sequence number by a second value when the slave is successfully synchronized with the data. The first value and the second value are the same.
3. The method according to claim 1, characterized in that, If the detection result of each of the sub-data is a successful synchronization to the slave device corresponding to the host, then before determining that the target data has been successfully synchronized to the slave device corresponding to the host, the process further includes: If the host fails, the slave device corresponding to the host will be used as the new host. Obtain the latest sub-data corresponding to the detected specified result as the target sub-data, wherein the specified result is the successful synchronization to the slave corresponding to the host; According to the preset order, the target sub-data continues to detect whether the sub-data following the target sub-data has been successfully synchronized to the slave device corresponding to the host.
4. The method according to claim 3, characterized in that, The preset order is the order in which the multiple sub-data are written to the host.
5. The method according to any one of claims 1-4, characterized in that, Also includes: The operation data of the plurality of sub-data is stored, wherein the operation data includes at least one of the detection results of whether the sub-data has been successfully synchronized to the slave corresponding to the host and the write information written to the host.
6. The method according to claim 1, characterized in that, The number of slave devices corresponding to the host is M. Determining that the target data has been successfully synchronized to the slave devices corresponding to the host includes: If the number of slave devices that have successfully synchronized the target data is N, then the target data is determined to have been successfully synchronized to the slave device corresponding to the master device, where N is less than M, M is a positive integer greater than 2, and N is a positive integer less than M.
7. The method according to claim 6, characterized in that, The N is M / 2.
8. A data synchronization device, characterized in that, A client application within a host of one of multiple subsystems of a data storage system, wherein each subsystem includes the host and at least one slave corresponding to the host, the device comprising: An acquisition unit is used to acquire target data to be written to the host, wherein the target data is multiple sub-data; The synchronization unit is used to synchronize the target data to the slave device corresponding to the host after the target data is stored in the storage space corresponding to the host; and to detect whether each piece of sub-data has been successfully synchronized to the slave device corresponding to the host in a preset order; if the detection result of each piece of sub-data is that it has been successfully synchronized to the slave device corresponding to the host, then it is determined that the target data has been successfully synchronized to the slave device corresponding to the host. The processing unit is configured to, if the target data is successfully synchronized to the slave device corresponding to the host, send the target data to other subsystems and instruct the other subsystems to perform data synchronization operations; The step of detecting whether each piece of sub-data has been successfully synchronized to the slave device corresponding to the host includes: Obtain the first serial number corresponding to the host. The first serial number is used to perform an update operation based on the initial value of the first serial number and the first update rule when the host is successfully written with data. Obtain the second serial number corresponding to the slave device. The second serial number is used to perform an update operation based on the initial value of the second serial number and the second update rule when the slave device successfully synchronizes data. The first update rule is the same as the second update rule, and the initial value of the first serial number is the same as the initial value of the second serial number. Obtain the size relationship between the first serial number and the second serial number; If the first sequence number is less than or equal to the second sequence number, then the sub-data is determined to have been successfully synchronized to the slave device corresponding to the host. The synchronization of target data between the master and slave devices and the master's detection of whether the target data has been successfully synchronized to the slave device corresponding to the master are executed simultaneously.
9. A data storage system, characterized in that, include: Multiple subsystems, each of which includes a host and at least one slave corresponding to the host; The host is used to perform the method described in any one of claims 1-7.
10. A computer-readable medium, characterized in that, The computer-readable medium stores processor-executable program code, which, when executed by the processor, causes the processor to perform the method according to any one of claims 1-7.
Citation Information
Patent Citations
Distributed key value database system with strong consistency and read-write method thereof
CN103268318A
Multiple-node hot standby method of metadata service nodes in cloud storage service
CN104765661A
Data synchronization method and device
CN106713487A