CN115004662B - Data synchronization method, device, data storage system and computer readable medium - Google Patents

Data synchronization method, device, data storage system and computer readable medium Download PDF

Info

Publication number
CN115004662B
CN115004662B CN202080094721.7A CN202080094721A CN115004662B CN 115004662 B CN115004662 B CN 115004662B CN 202080094721 A CN202080094721 A CN 202080094721A CN 115004662 B CN115004662 B CN 115004662B
Authority
CN
China
Prior art keywords
data
room
machine room
slave
target data
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202080094721.7A
Other languages
Chinese (zh)
Other versions
CN115004662A (en
Inventor
汤见乐
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Guangdong Oppo Mobile Telecommunications Corp Ltd
Shenzhen Huantai Technology Co Ltd
Original Assignee
Guangdong Oppo Mobile Telecommunications Corp Ltd
Shenzhen Huantai Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Guangdong Oppo Mobile Telecommunications Corp Ltd, Shenzhen Huantai Technology Co Ltd filed Critical Guangdong Oppo Mobile Telecommunications Corp Ltd
Publication of CN115004662A publication Critical patent/CN115004662A/en
Application granted granted Critical
Publication of CN115004662B publication Critical patent/CN115004662B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L51/00User-to-user messaging in packet-switching networks, transmitted according to store-and-forward or real-time protocols, e.g. e-mail
    • H04L51/42Mailbox-related aspects, e.g. synchronisation of mailboxes

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

一种数据同步方法、装置、数据存储系统及计算机可读介质,涉及计算机技术领域,所述方法包括:获取请求写入所述数据存储系统的目标数据(S201);将所述目标数据写入主机房(S202);在成功将所述目标数据写入所述主机房之后,将所述目标数据同步至从机房(S203)。所述方法先对主机房写入数据,并且以主机房的数据为准将所写入主机房的数据同步至从机房,能够更好的保持数据的一致性。

A data synchronization method, device, data storage system and computer-readable medium, relating to the field of computer technology, the method comprising: obtaining target data requested to be written into the data storage system (S201); writing the target data into a main computer room (S202); after successfully writing the target data into the main computer room, synchronizing the target data into a slave computer room (S203). The method first writes data into the main computer room, and synchronizes the data written into the main computer room to the slave computer room based on the data in the main computer room, so as to better maintain data consistency.

Description

Data synchronization method, device, data storage system and computer readable medium
Technical Field
The present application relates to the field of computer technology, and more particularly, to a data synchronization method, apparatus, data storage system, and computer readable medium.
Background
With the increasing popularity of network services, the access amount of users is increased, if all service data is stored in one server, the server often fails due to the excessively large access amount, and in an application scene with large service data amount, one server often cannot bear all service data due to the limitation of the storage space of the server, so that a plurality of servers are required to jointly provide services for users. Therefore, a plurality of servers commonly used for providing a certain service can be arranged in the same machine room, and then a plurality of machine rooms form a system which provides a data storage function for a business layer.
However, when the service layer stores data, each machine room in the system needs to perform a write operation once, and then if the data of part of the machine rooms are written in error, the data of the whole system is inconsistent.
Disclosure of Invention
The application provides a data synchronization method, a data synchronization device, a data storage system and a computer readable medium, so as to improve the defects.
In a first aspect, an embodiment of the present application provides a data synchronization method, which is applied to a master room of a data storage system, where the data storage system further includes a slave room corresponding to the master room. The method comprises the steps of obtaining target data requested to be written into the data storage system, writing the target data into the host computer room, and synchronizing the target data to the slave computer room after the target data are successfully written into the host computer room.
In a second aspect, an embodiment of the present application further provides a data synchronization device, which is applied to a master room of a data storage system, where the data storage system further includes a slave room corresponding to the master room. The device comprises an acquisition unit, a writing unit and a synchronization unit. And the acquisition unit is used for acquiring target data which is requested to be written into the data storage system. And the writing unit is used for writing the target data into the main machine room. And the synchronization unit is used for synchronizing the target data to the slave computer room after the target data is successfully written into the master computer room.
In a third aspect, the embodiment of the application also provides a data storage system, which comprises a main machine room and a slave machine room corresponding to the main machine room, wherein the main machine is used for executing the method.
In a fourth aspect, embodiments of the present application also provide a computer readable storage medium storing program code executable by a processor, the program code when executed by the processor causing the processor to perform the above method.
According to the data synchronization method, the data synchronization device, the data storage system and the computer readable medium, when the data storage system is requested to write target data, namely, whether the data is requested to be written in a host computer room or a slave computer room of the system, the target data is written in the host computer room first, and then the target data is synchronized to the slave computer room after the target data is successfully written in the host computer room. Therefore, when target data are written into a plurality of machine rooms at the same time, if the data of a certain machine room are written into errors, the data of each machine room are inconsistent, the data are written into the main machine room, and the data of the main machine room are synchronized to the slave machine room based on the data of the main machine room, so that the consistency of the data can be better maintained.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are needed in the description of the embodiments will be briefly described below, it being obvious that the drawings in the following description are only some embodiments of the present application, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a schematic diagram of a data storage system provided by an embodiment of the present application;
FIG. 2 is a flow chart of a method for synchronizing data according to an embodiment of the present application;
FIG. 3 is a flow chart of a method for synchronizing data according to another embodiment of the present application;
FIG. 4 is a flowchart illustrating a method of S320 in FIG. 3 according to an embodiment of the present application;
FIG. 5 is a flow chart of a method for synchronizing data according to another embodiment of the present application;
FIG. 6 is a flowchart illustrating a method of S540 in FIG. 5 according to an embodiment of the present application;
FIG. 7 is a schematic diagram of a client in a data storage system according to an embodiment of the present application;
FIG. 8 is a block diagram of a data synchronization device according to another embodiment of the present application;
FIG. 9 is a block diagram of a data synchronization device according to another embodiment of the present application;
FIG. 10 is a block diagram of a data synchronization device according to another embodiment of the present application;
FIG. 11 shows a schematic diagram of an electronic device provided by an embodiment of the present application;
Fig. 12 is a memory unit for storing or carrying program codes for implementing a data synchronization method according to an embodiment of the present application.
Detailed Description
In order to enable those skilled in the art to better understand the present application, the following description will make clear and complete descriptions of the technical solutions according to the embodiments of the present application with reference to the accompanying drawings.
With the increasing popularity of network services, the access amount of users is increased, if all service data is stored in one server, the server often fails due to the excessively large access amount, and in an application scene with large service data amount, one server often cannot bear all service data due to the limitation of the storage space of the server, so that a plurality of servers are required to jointly provide services for users. For this purpose, a plurality of servers commonly used for providing a certain service may be provided in the same machine room, and the service may be provided to the user by the machine room.
In the above data management service, the application of the memory database is relatively wide, and the memory database refers to a database that is directly operated by placing data in a memory, and is generally deployed in a cluster manner, where such a cluster is called a memory database cluster. The memory database cluster comprises a memory database host and a memory database slave, and the synchronization of data needs to be kept between the memory database host and the memory database slave. Further, synchronization is divided into full synchronization and incremental synchronization, wherein full synchronization refers to that a memory database slave synchronizes all data of a memory database host at one time, and incremental synchronization refers to that the memory database slave only synchronizes different partial data between the memory database slave and the memory database host.
The Redis is a high-performance open source database based on a memory, is written by ANSIC languages, provides programming interfaces of multiple languages, is commonly used for realizing functions such as data storage and quick access of software or application, and has wide application in a production environment, for example, in order to ensure the stability of service while expanding the service, a Redis cluster supporting distributed high availability and transverse expansion is commonly used for data storage and access. To improve system stability, the redis system typically employs a master-slave architecture. The data on the redis master node needs to be copied in one copy at the initialization stage of the redis slave node and when the master node is written with new data, so as to be used as master-slave data synchronization of the standby event called redis.
As shown in fig. 1, fig. 1 shows a schematic diagram of a data storage system comprising a plurality of machine rooms, including machine room 1, machine room 2, and machine room 3, as shown in fig. 1. Each machine room comprises a host machine and at least one slave machine corresponding to the host machine. As shown in fig. 1, the machine room 1 includes a master machine 10 and a slave machine 11 and a slave machine 12 corresponding to the master machine, where the master machine 10, the slave machine 11 and the slave machine 12 are in a master-slave relationship. The host is also called a master node (master), and the master node provides services to the outside. The slave is also called slave node (slave), and the slave node copies the data of the Master node in real time to ensure consistency with the Master node. The slave cannot be subjected to data writing operation by other devices, and the data in the slave is synchronized to the slave by the host through a data synchronization mode.
As shown in fig. 1, the machine room 2 includes a master 20 and a slave 21 and a slave 22 corresponding to the master, and the machine room 3 includes a master 30 and a slave 31 and a slave 32 corresponding to the master.
It should be noted that, the data storage system formed by each machine room can provide data storage service for the service layer, that is, the data generated by the service layer can be stored in the data storage system, and the data can also be read from the data storage system.
In some embodiments, the service layer may write data into the data storage system in a manner that the data is written into any machine room in the data storage system, specifically, into a host of any machine room in the data storage system, and then in order to ensure consistency of the data, the written data needs to be written into each machine room.
However, the inventor finds that the scheme of multi-address writing is adopted for realizing multi-address scheme based on Redis at present, namely when a business layer stores data, a write operation needs to be executed on a storage cluster of each machine room, and the data storage is considered successful after the storage clusters of all the machine rooms are successfully written. However, when the service layer stores data, each machine room in the system needs to perform a write operation once, and then if the data of part of the machine rooms are written in error, the data of the whole system is inconsistent.
Therefore, in order to overcome the above-mentioned drawbacks, in the embodiment of the present application, a plurality of machine rooms in the data storage system are divided into a master machine room and a slave machine room, that is, one machine room is designated as the master machine room, and the other machine rooms are slave machine rooms corresponding to the master machine room.
The embodiment of the application provides a data synchronization method which is applied to the data storage system, and as an implementation mode, each machine room in the data storage system is correspondingly provided with a client which is used for writing data into a certain machine room, and the embodiment of the method is implemented. As an implementation manner, the client may be installed in a host installed in each machine room, or may be installed in a terminal independent of the host in each machine room. In the embodiment of the application, the client is installed in the host.
As shown in fig. 2, fig. 2 illustrates a data synchronization method, and an execution subject of the method may be the host room described above, and in particular, the execution subject may be a client in the host room. Specifically, the method includes S201 to S203.
S201, obtaining target data which is requested to be written into the data storage system.
As one implementation, it may be that the data storage system obtains a data write request for writing target data into the data storage system. In particular, a data write request may be sent by the service layer to the data storage system.
In some embodiments, the data write request may include a reference number designating the room to which the request was written as the identity information of the room. In this embodiment, the service layer requests that the target data be written into the room corresponding to the designated label. In other embodiments, the data write request may not include a designation specifying the room in which the request was written.
Whether the data is written in a certain machine room or not, the data can be used as target data for writing the data into the data storage system as long as the data is corresponding to a data writing request for writing the data into the data storage system.
The host room can monitor and write the data of each machine room (comprising a host machine room and a slave machine room corresponding to the host machine room), so that the host machine room can acquire target data required to be written into the data storage system.
As an implementation manner, the host computer room and the slave computer room are respectively provided with a message queue, the host computer room subscribes to the message queues of all the slave computer rooms, and each slave computer room subscribes to the message queue of the host computer room. The application programs such as the service layer and the like communicate with each machine room through a Message Queue, and specifically, the Message Queue (MQ) is a communication method of the application programs from application program to application program. The applications communicate by writing and retrieving queued data (messages) for the applications.
For example, when the service layer requests to write target data into a certain machine room, the service layer sends a data writing request to a message queue of the machine room, and if the machine room is a slave machine room, since the host machine room subscribes to the message queue of the slave machine room, the host machine room can monitor the operation of the slave machine room on the message queue, so that when the data writing request is written into the message queue, the host machine room can monitor the operation, and thus can acquire the target data requested to be written into the data storage system.
And S202, writing the target data into the main machine room.
After target data requested to be written into the data storage system is obtained, the target data is written into the host computer room.
As an implementation manner, the host computer room includes a host computer and a slave computer corresponding to the host computer, and the implementation manner of writing the target data into the host computer room may be that the target data is written into the host computer, and then the host computer synchronizes the target data into the slave computer corresponding to the host computer.
Assume that the machine room 1 described above is a main machine room and the target data is data. The host 10 synchronizes the data to the corresponding slave 11 and slave 12.
As one implementation mode, a log stream function is arranged in each machine room and is used for recording the operation of writing data into a host, in a multi-activity scheme of Redis clusters across machine rooms based on log stream, all data writing of Redis can be stored into the log stream of a local disk, an external scanning program scans the log stream, and data modification is synchronized to the Redis clusters of other machine rooms, wherein each Redis cluster can be understood as the machine room. Each write operation of each machine room can be recorded through the log stream, so that synchronization of data is realized.
Specifically, taking the above storage system as a Redis system as an example, modifying the source code implementation of the Redis component, adding a binlog (i.e. log pipelining) function, recording each write operation into a log file, and ensuring that the sequence of log records is consistent with the sequence of write operations actually received. For example, a plurality of data are written to the host, the plurality of data being data1, data2, data3, data4, data5, and data6, respectively, i.e., the writing order of the plurality of data is data1, data2, data3, data4, data5, and data6, the plurality of data are recorded in a log file, the order of the log recording is also data1, data2, data3, data4, data5, and data6, wherein data1, data2, data3, data4, data5, and data6 may be an identification of the plurality of data, and the writing time of each written data may also be recorded in the log recording.
In addition, the master and the slave can be corresponding to log files, that is, the master and the slave can execute log stream functions for recording write operations of the master and the slave, wherein the write operations for the slave can be understood as data synchronization operations of the master to the slave.
Therefore, by recording the write data, the target data written by the host can be obtained, and the target data may be a set of a plurality of data to be written continuously or may be any one of a plurality of data to be written continuously.
And S203, synchronizing the target data to the slave computer room after the target data is successfully written into the master computer room.
Specifically, whether the target data is successfully written into the master machine room is judged, and if the target data is successfully written into the master machine room, the target data is synchronized to the slave machine room.
And judging whether the implementation mode of writing the target data into the host computer room is successful, and judging whether the target data is successfully synchronized into the slave computer corresponding to the host computer after the host computer is written with the target data. Specifically, how to determine whether the target data is successfully synchronized to the operation of the slave corresponding to the master may refer to the following embodiments.
After the host computer room is written with the target data, the target data is stored in a storage space corresponding to the host computer room, and then a data synchronization operation is performed, specifically, the client sends the target data written in the host computer room to a slave computer room corresponding to the host computer room, so that the data stored in the slave computer room is updated. That is, the target data is synchronized from the storage space corresponding to the machine room.
If the target data is successfully synchronized to the slave corresponding to the host, it can be determined that the target data written into the host has been successfully synchronized to the slave corresponding to the host, and then the target data can be synchronized to the slave room.
Taking the above-described data storage system as an example, the host 10 of the machine room 1 is written with target data, the host 10 synchronizes the target data to the slave 11 and the slave 12, after determining that the slave 11 and the slave 12 successfully synchronize the target data, the target data is sent to the machine room 2 and the machine room 3, and after acquiring the target data, the machine room 2 and the machine room 3 perform the synchronization operation of the target data. Specifically, the host 10 transmits target data to the host 20 in the machine room 2 and the host 30 in the machine room 3, the host 20 is written with the target data and synchronizes the target data to the slave 21 and the slave 22 corresponding to the host 20, and the host 30 is written with the target data and synchronizes the target data to the slave 31 and the slave 32 corresponding to the host 20.
Therefore, when the data storage system is requested to write target data, that is, whether the data is requested to be written in the host room or the slave room of the system, the target data is written in the host room first, and then the target data is synchronized to the slave room after the target data is successfully written in the host room. Therefore, when target data are written into a plurality of machine rooms at the same time, if the data of a certain machine room are written into errors, the data of each machine room are inconsistent, the data are written into the main machine room, and the data of the main machine room are synchronized to the slave machine room based on the data of the main machine room, so that the consistency of the data can be better maintained.
Referring to fig. 3, fig. 3 illustrates a data synchronization method, where an execution body of the method may be the host computer room described above, and specifically, the execution body may be a client in the host computer room. Specifically, the method includes S310 to S340.
And S310, monitoring write operations of the master machine room and the slave machine room.
As an implementation manner, a client in a host room can detect write operations for all the host rooms, for example, through the message queues, the host room subscribes to the message queues of all the slave rooms, so that when any slave room is written with data, the write operations of the slave room can be monitored, and when the host room is written with data, the write operations can also be written into the message queues of the host room, so that the slave room corresponding to the message subscribing to the host room can also know that the host room is written with data, and any room in the data storage system is written with data, which can be regarded as write operations of the data storage system.
Therefore, by monitoring the message queues of the respective machine rooms, it is possible to detect the current write operation for the data storage system when any machine room is written with data.
And S320, when the writing operation is detected, obtaining the target data according to the writing operation.
The write operation can specify the data requested to be written, for example, the write operation can be a data packet, the data requested to be written is included in the data packet, and the host room can parse the write operation to obtain the data requested to be written when the write operation is monitored.
As an embodiment, when there is only one write operation, the data requested to be written may be the target data.
As another embodiment, if there are a plurality of write operations, the data requested to be written corresponding to each write operation is determined, and if the data requested to be written for all write operations are the same, the data requested to be written corresponding to one write operation may be selected as the target data.
As yet another embodiment, if there are multiple write operations, then, it is determined that the data modification request for each write operation is the same, and the same write operation is found for the data modification request. The data modification request may be that the data requested to be written is the same and the data requested to be changed is the same, where the data requested to be changed may be some content to be modified stored in the master room or the slave room, or may be newly added data. Specifically, the write operation corresponds to the content to be modified and the data requested to be written, and the write operation is used to modify the content to be modified into the data requested to be written.
The content to be modified may be some specified data stored in the room if the write operation is an update request, and the specified data is modified to data requested to be written when the write operation is performed. If the write operation is newly added data, the content to be modified is a storage space in the room, and the requested write data is written in the storage space when the write operation is performed.
Therefore, when the writing operation is multiple, the content to be modified corresponding to each writing operation is determined, and the writing operations are distinguished according to the content to be modified, so that the writing operations corresponding to different content to be modified, namely the writing operations with different modification purposes, are obtained. In addition, if the content to be modified is specified data, each data in each machine room corresponds to an identification, and the identification is unified in each machine room, for example, data1 is included in the data stored in the host machine room, data1 is also included in the data stored in the slave machine room, and data1 in the host machine room and data1 in the slave machine room should maintain data consistency.
Therefore, if the content to be modified is the specified data, the identification of the specified data is acquired, and the write operation with the same identification of the specified data is used as the write operation with the same modification purpose. If the content to be modified is a storage space, a write operation of which each content to be modified is a storage space can be used as a write operation for modification purposes, or if the write operation is newly added data, a data identifier is configured for the write operation, and the data identifier is the newly added identifier, so that when the data is written into the machine room, the data identifier also corresponds to the machine room.
For example, the write operations are operation 1, operation 2, operation 3, operation 4, operation 5, operation 6, and operation 7, respectively, the contents to be modified corresponding to operation 1, operation 2, and operation 3 are data1, operation 4, and operation 5 are for adding one data, the identification of the added data is data7, operation 6 is for adding one data, the identification of the added data is data8, and operation 7 is for adding one data, and the identification of the added data is data9.
The 7 write operations may be divided into four modification purposes, namely modification purpose 1, modification purpose 2, modification purpose 3 and modification purpose 4, wherein the write operation corresponding to modification purpose 1 is operation 1, operation 2 and operation 3, the write operation corresponding to modification purpose 2 is operation 4 and operation 5, the write operation corresponding to modification purpose 3 is operation 6, and the write operation corresponding to modification purpose 4 is operation 7.
Thus, for different modification purposes, the write operation corresponding to each modification purpose is determined, and in particular, the embodiment of determining the write operation corresponding to each modification purpose may refer to steps S321 to S323 in fig. 4. For each modification purpose, S321 to S323 may be performed to determine the write operation corresponding to each modification purpose.
S321, if the number of the write operations is multiple, obtaining a time stamp corresponding to each write operation.
Each writing operation corresponds to the specified data and is used for modifying the content to be modified into the specified data. The designated data corresponding to each writing operation may be the same or different.
As an embodiment, each write operation corresponds to a timestamp, and the timestamp is used for recording the time corresponding to the write operation. Specifically, when the service layer inputs a write request for writing specified data to the data storage system, the data storage system configures a time stamp for the write request and uses the write request as a write operation, so that a time stamp can be configured for the write operation.
S322, determining the target writing operation from the plurality of writing operations according to the time stamp.
The time stamp can be used as the time of writing the specified data corresponding to the writing operation, namely, the writing time of different writing operations. As one implementation, the target write operation may be determined according to the early-late order of the time stamps of the individual write operations. For example, the write operation corresponding to the earliest or latest timestamp is selected as the target write operation.
Specifically, the time stamps corresponding to the plurality of write operations may be the same or may not be the same, and for the case of the same or different, the implementation of determining the write operation as the target write operation from among the plurality of write operations according to the time stamps may be different.
Specifically, whether the time stamps corresponding to the write operations are all the same is judged, and if the time stamps are not all the same, the latest time stamp in all the time stamps is determined to be the target time stamp.
The time stamps are not identical, but all time stamps are identical, and different time stamps exist, that is, not all time stamps are identical. All the time stamps can be ordered according to the time sequence to obtain a time sequence, and the last time stamp in the time sequence is used as the target time stamp.
Then, the write operation corresponding to the target timestamp is used as a candidate write operation. The latest time stamp may include a plurality of time stamps, i.e. a plurality of latest time stamps may be obtained, and then the write operation corresponding to each latest time stamp may be used as the candidate write operation.
As another embodiment, all write operations may be ordered in time order of the time stamps, resulting in a candidate sequence. Wherein the candidate sequence includes a plurality of write operation identifiers, which may be identity information for recording each write operation. And in the sequence to be selected, the identifier of each writing operation corresponds to a serial number, and the time stamp corresponding to the writing operation with the earlier serial number is earlier, namely, the writing operation is ordered according to the time sequence of the time stamp, so as to obtain the sequence to be selected. Then, the top write operation in the candidate sequence is taken as the candidate write operation. If the time stamps of the plurality of write operations are the same, the sequence numbers corresponding to the write operations of the same time stamp are the same, so that the plurality of obtained candidate write operations can be obtained, wherein the time stamp corresponding to each candidate write operation is the same, and the time stamp corresponding to each candidate write operation is the latest time stamp in the time stamps corresponding to all write operations.
Then, a target write operation is determined from within the candidate write operation. And if the number of the candidate write operations is 1, taking the candidate write operation as a target write operation. And if the number of the to-be-selected writing operations is at least two, determining an operation object corresponding to each to-be-selected writing operation, wherein the operation object comprises a master machine room or a slave machine room. The operation object may be a machine room designated for writing when the service layer requests to store data, specifically, when the data writing request includes an identifier of the machine room, and when the master machine room and the slave machine room are preset, the identifier of each machine room can be corresponding to one label, where the label includes a master machine room label and a slave machine room label, so that, by using the identifier of the machine room included in the data writing request, it can be determined whether the label of the machine room corresponding to the identifier of the machine room is the master machine room label or the slave machine room label, and further it can be determined whether the machine room requested to write data is the master machine room or the slave machine room, that is, it is determined that the operation object corresponding to each writing operation.
And taking the operation object as the candidate write operation of the main machine room as a target write operation.
For example, the above-exemplified plurality of write operations include operation 1, operation 2, operation 3, operation 4, operation 5, operation 6, and operation 7 as examples, and the time stamps corresponding to operation 1, operation 2, operation 3, operation 4, operation 5, operation 6, and operation 7 are time t1, time t2, time t3, time t4, time t5, time t6, and time t7. According to the time sequence, the time early-late sequence of each time stamp is respectively time t1, time t2, (time t3 and time t 4), (time t5, time t6 and time t 7), namely time t3 is the same as time t4, time t5, time t6 and time t7 are the same, and then it can be understood that operation 1 is firstly acquired, then operation 2 is acquired, then operation 3 and operation 4 are acquired at the same time, and finally operation 5, operation 6 and operation 7 are acquired at the same time.
Then the candidate write operations may be determined to be operation 5, operation 6, and operation 7, and then a target write operation is determined from operation 5, operation 6, and operation 7.
As an embodiment, it may be determined that the operation objects corresponding to each of the operation 5, the operation 6, and the operation 7 are, for example, the host room, the slave room 1, and the slave room 2, respectively. The operation target is the operation 5 of the candidate write operation of the host room, so that the target write operation can be determined to be operation 5.
In addition, if only one of the determined candidate write operations is, for example, operation 1 may be directly taken as the target write operation.
As another embodiment, if the time stamp corresponding to each write operation is the same when the write operation is detected, the operation object corresponding to each write operation may be directly obtained without performing the write operation of searching for the latest time stamp, and the operation object may be referred to the foregoing description and will not be described herein.
Specifically, if the time stamp of each writing operation is the same, determining an operation object corresponding to each writing operation to be selected, wherein the operation object comprises a main machine room or a slave machine room, and taking the operation object as the writing operation to be selected of the main machine room as a target writing operation.
S323, taking the designated data corresponding to the target write operation as target data.
For example, it is assumed that the currently acquired write operations include operations 1, 2, 3, 4, 5, 6, 7, 8, 9, and 10 altogether, wherein the contents to be modified corresponding to operations 1, 2, 3, 4, 5, 6, and 7 are data1, the contents to be modified corresponding to operations 8, 9, and 10 are data7, and data1 exists in all the rooms, the purpose of operations 1, 2, 3, 4, 5, 6, and 7 is to modify the data of data1, and the specified data corresponding to operations 1, 2, 3, 4, 5, 6, and 7 are data1, data 2, data 3, data 4, data 5, data 6, data7, and the operation objects corresponding to operations 1, 2, 3, 4, 5, 6, and 7 are slave 1, slave room 2, master room, slave room 3, master room 1, and slave room 2, respectively. For example, the purpose of operation 1 is to modify data1 stored from the room 1 to data 1.
Then, the timestamp corresponding to the operation 5, the operation 6 and the operation 7 is the latest, and it can be determined that the target write operation is the operation 5 of the main computer room, the determined target data is the data 5, and finally the modification mode of the data1 in the main computer room is determined to be the modification of the data1 into the data 5, and the data 5 is synchronized to other slave computer rooms, so that the data1 of all the slave computer rooms are modified into the data 5.
Then, after the data1 of each machine room is modified into data 5, the data7 of all the machine rooms are modified according to operations 8, 9 and 10, and the method for determining the target data can refer to the foregoing method, and the modification method is to modify the data7 in the host first and then synchronize sequentially.
And S330, writing the target data into the main machine room.
And S340, synchronizing the target data to the slave computer room after the target data is successfully written into the master computer room.
Referring to fig. 5, fig. 5 illustrates a data synchronization method, where an execution body of the method may be the host computer room described above, and specifically, the execution body may be a client in the host computer room. Specifically, the method includes S510 to S550.
S510, obtaining target data which is requested to be written into the data storage system.
And S520, writing the target data into the main machine room.
And S530, after the target data is successfully written into the host room, synchronizing the target data to a designated machine room.
The machine room is designated as one of the plurality of slave machine rooms.
As an implementation manner, each slave computer room may be set to a synchronization state, where the synchronization state includes an unsynchronized state and a synchronized state, and each time one slave computer room is selected from the unsynchronized slave computer rooms as a designated computer room, the target data is synchronized to the designated computer room, and when the target data is successfully synchronized to the designated computer room, the corresponding synchronization state of the designated computer room is changed, for example, the unsynchronized state is changed to the synchronized state.
As an embodiment, a synchronization order may be preset, and the master room synchronizes the target data to all the slave rooms according to the synchronization order, and then sequentially selects one slave room as the designated room according to the synchronization order.
S540, judging whether the data is successfully synchronized to the designated machine room.
As an implementation manner, whether the target data is successfully synchronized to the slave computer room corresponding to the master computer room may be determined according to the information replied from the slave computer room, or whether the target data is successfully synchronized to the slave computer room corresponding to the master computer room may be determined according to the data writing records of the master computer room and the slave computer room, that is, the log files of the master computer room and the slave computer room.
The method for judging whether the data is successfully synchronized with the designated machine room can be implemented by detecting whether the information of successful synchronization fed back by the designated machine room is received, judging that the data is successfully synchronized with the designated machine room if the information of successful synchronization is received, and judging that the data is not successfully synchronized with the designated machine room if the information of successful synchronization is not received.
The information of successful synchronization may be sent to the master computer room after the slave computer room receives the target data and successfully stores the target data, and the master computer room can determine that the target data is successfully synchronized to the slave computer room corresponding to the master computer room after receiving the information.
As one embodiment, it may be information for determining whether or not synchronization fed back by a specified machine room is successful is received within a predetermined period of time. Wherein the time start point of the predetermined time period may be a time point at which the synchronization of the target data to the operation of the slave room corresponding to the master room is performed, and the predetermined time length of the predetermined time period may be predetermined, for example, may be empirically set. Specifically, the time length of the synchronous data of the slave machine room may be counted, and the predetermined time length of the predetermined time period is determined according to the time length.
As an embodiment, a time length for synchronizing a plurality of data from the machine room may be acquired, and a predetermined time length of the predetermined time period may be determined based on the plurality of time lengths. Specifically, an average value of the plurality of time lengths is calculated, and the average value is taken as a predetermined time length of a predetermined time period.
As another embodiment, the rate of obtaining the synchronous data from the machine room may be counted, and the predetermined time length of the predetermined time period may be obtained according to the data size of the target data and the counted rate of the synchronous data. For example, a ratio of the data size of the target data to the statistically obtained rate of the synchronous data is acquired as a predetermined time length of the predetermined time period.
As an embodiment, referring to fig. 6, an embodiment of determining whether the target data is successfully synchronized to the designated machine room may include S541 to S543.
S541, first record information corresponding to the host computer room is obtained, wherein the first record information is used for recording the operation which is executed by the host computer room and is written with target data.
As an embodiment, the first record information includes an identifier of data written in the host computer room each time and an operation time, where the operation time is used to record a writing time point of the written data, where the identifier of the written data may be an identifier allocated to each written data by the host computer room, where the identifier may be an identifier determined according to a content of the data, for example, may be an identifier that generates the data according to a data digest of the data, and as an embodiment, may be an identifier that uses the data digest of the target data as the target data. Wherein the data summary may be the content used to describe the target data. The first record information includes a write time corresponding to a target identification of the target data.
S542, acquiring second record information corresponding to the appointed machine room, wherein the second record information is used for recording the data synchronization operation of the target data executed by the appointed machine room.
Similarly, the second record information includes an identifier of the data synchronized by the slave machine room and an operation time, where the operation time may be a time of the data synchronized by the slave machine room, and an embodiment of the identifier of the data may refer to the foregoing embodiment and will not be described herein. Each slave room corresponds to the second recorded information, and thus, each time the second recorded information of the slave room may be the second recorded information of the designated room.
S543, judging whether the data is successfully synchronized to the appointed machine room according to the first record information and the second record information.
The first record information comprises an identifier of data written in a main machine room and a writing time point corresponding to the identifier, and the second record information comprises an identifier of data synchronized in a slave machine room and a synchronizing time corresponding to the identifier, so that whether the target data is successfully synchronized to the appointed machine room can be judged according to the identifier of the data written in the main machine room and the writing time point corresponding to the identifier and the synchronizing time corresponding to the identifier of the data synchronized in the appointed machine room.
As one implementation mode, whether a first operation time point in the first recorded information is earlier than a second operation time point in the second recorded information is judged, if so, data is judged to be successfully synchronized to the appointed machine room, and if not, data is judged to be not successfully synchronized to the appointed machine room. The first operation time point is a writing time point corresponding to a target identifier of the target data written in the host computer room recorded in the first recording information, the second operation time point is a synchronization time corresponding to a target identifier of the target data synchronized in the designated computer room recorded in the second recording information, whether the synchronization time is later than the writing time point is judged, if yes, the target data is judged to be successfully synchronized to the designated computer room, and if not, the target data is judged to be unsuccessfully synchronized to the designated computer room.
Specifically, it may be determined whether or not there is a synchronization time corresponding to the identification of the target data in the second recording information, and if there is, an operation of determining whether or not the synchronization time is later than the writing time point is performed. The embodiment of determining whether the synchronization time corresponding to the identifier of the target data exists in the second record information may be that of determining whether the synchronization time corresponding to the identifier of the target data exists in the second record information in a predetermined period of time, where the embodiment of the predetermined period of time may refer to the foregoing embodiment.
As another embodiment, considering that the manner of recording the write operation of the master computer room and the data synchronization operation of the slave computer room may be the log file described above, that is, the write operation of the master computer and the data synchronization operation of the slave computer are recorded by means of log pipelining, a serial number may be set for each of the master computer room and the slave computer room, and each write operation of the master computer and each data synchronization operation of the slave computer may be recorded by the serial number.
Specifically, the first record information is a first serial number, where the first serial number is used to perform an update operation according to a first update rule when the host room is successfully written into the target data, specifically, a first serial number may be predefined, where an initial value of the first serial number is a first initial value, and then, when the host room is written into the target data each time, a value of the first serial number is updated according to the first update rule, where the first update rule may be to increase or decrease a certain value, that is, when each write operation is performed, a certain value is increased or decreased based on the first serial number saved last time.
For example, the initial value of the first serial number is a first initial value, the first updating rule is to increase the first value, when the data is written into the host computer room for the first time, the value of the first serial number becomes the sum of the first initial value and the first value, and after the data is written again, the value of the first serial number becomes the sum of the first initial value and the two first values, that is, the first value is increased on the basis of the first serial number saved last time.
In the embodiment of the application, assuming that the first sequence number is seq1 and the initial value is 0, after the first data writing, the value of the first sequence number seq1 becomes 1, after the second data writing, the value of the first sequence number seq1 becomes 2, and so on, if the written data comprises a plurality of data, the data are respectively data1, data2, data3, data4, data5 and data6, and the corresponding relationship between the data identifier and the value of the sequence number seq1 is that the sequence number seq1 corresponding to the data1, data2, data3, data4, data5 and data6 is sequentially 1, 2, 3, 4, 5 and 6.
Therefore, the writing sequence of each writing data and the serial number corresponding to the identification of each writing data can be obtained through the corresponding relation, the serial number can be used as the serial number of the writing data, and the number of the target data which is written in the whole writing operation process can be recorded.
Similarly, the second record information is a second serial number, and the second serial number is used for executing updating operation according to a second updating rule when the specified machine room successfully synchronizes data. The second update rule may be the same as the first update rule, and the second update rule may be an increase in the second value. Specifically, the initial value of the second serial number is a second initial value, the second updating rule is to increase the second value, when the data is synchronized for the first time from the machine room, the value of the second serial number becomes the sum of the second initial value and the second value, and after the data is synchronized again, the value of the second serial number becomes the sum of the second initial value and the two second values, that is, the second value is increased on the basis of the second serial number saved last time. Wherein the first and second values are the same, e.g., both are 1, and the first and second initial values may be the same, e.g., both are 0.
Assuming that the second serial number is seq2, the initial value is 0, after the first time of synchronizing data from the machine room, the value of the second serial number seq2 becomes 1, after the second time of synchronizing data, the value of the second serial number seq2 becomes 2, and so on, if the synchronized data comprises a plurality of data, the plurality of data are respectively data1, data2, data3, data4, data5 and data6, and the corresponding relationship between the data identification and the value of the serial number seq2 is that the serial number seq2 corresponding to the data1, data2, data3, data4, data5 and data6 is sequentially 1, 2, 3,4, 5 and 6.
It should be noted that, when the slave is successfully synchronized with the data, the data of the seq2 is changed, and it can be determined whether the slave successfully synchronizes with the target data by determining the size relationship between the current seq2 and the seq1 corresponding to the target data written by the host.
Therefore, whether the data is successfully synchronized to the designated machine room can be determined according to the size relation between the first serial number and the second serial number, specifically, whether the data is successfully synchronized to the designated machine room is determined according to the first record information and the second record information, the size relation between the first serial number and the second serial number can be obtained, if the size relation meets a designated condition, the data is determined to be successfully synchronized to the designated machine room, wherein the size relation meets the designated condition, the designated machine room is indicated to successfully synchronize the target data after the target data is written into the host machine room, and if the size relation does not meet the designated condition, the data is determined to be unsuccessfully synchronized to the designated machine room.
The size relationship may be whether the first sequence number is less than or equal to the second sequence number, or other size relationships capable of characterizing whether the first sequence number is less than or equal to the second sequence number, for example, a ratio between the first sequence number and the second sequence number may 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.
As an embodiment, the size relationship may be determined according to a first update rule and a second update rule, and if the first update rule and the second update rule are the same and are both increased by the same value on the basis of an initial value, the size relationship may be whether the first sequence number is less than or equal to the second sequence number. If the first update rule and the second update rule are the same and are both subtracting the same value from the initial value, the size relationship may be whether the first sequence number is greater than or equal to the second sequence number. If the first update rule and the second update rule are different, the change value corresponding to the first update rule is k times of the change value corresponding to the second update rule, and the size relationship may be whether the ratio of the second serial number to the first serial number is a positive integer multiple of k.
After the size relation between the first serial number and the second serial number is acquired, whether the size relation meets a specified condition is judged.
The size relation satisfies a specified condition, which indicates that the specified machine room successfully synchronizes the target data after the host room is written with the target data.
If the first update rule and the second update rule are the same or different, the above-described size relationship is also different, and therefore the corresponding specified conditions are also different.
For example, if the first update rule and the second update rule are the same and are both increased by the same value on the basis of the initial value, the size relationship may be whether the first sequence number is less than or equal to the second sequence number, if the first sequence number is less than or equal to the second sequence number, the size relationship is determined to satisfy the specified condition, otherwise, the size relationship is determined to not satisfy the specified condition.
If the first updating rule and the second updating rule are the same and are both subtracting the same value on the basis of the initial value, the size relation can be whether the first serial number is larger than or equal to the second serial number, if the first serial number is larger than or equal to the second serial number, the size relation is judged to meet the specified condition, otherwise, the size relation is judged not to meet the specified condition.
If the first updating rule and the second updating rule are different, the change value corresponding to the first updating rule is k times of the change value corresponding to the second updating rule, the size relation 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, the size relation is judged to meet the appointed condition, otherwise, the size relation is judged to not meet the appointed condition.
In the embodiment of the present application, the first updating rule and the second updating rule may be the same, and both the first updating rule and the second updating rule are added with the same value based on the initial value, and the size relation satisfies the specified condition means that if the first serial number is smaller than or equal to the second serial number.
As an embodiment, the first serial number is changed according to the first updating rule, the second serial number is changed according to the second updating rule, and when the host computer room completes the writing operation of the target data, the first serial number is updated by the first updating rule, and when the slave computer completes the synchronizing operation of the target data, the second serial number is updated by the second updating rule, and the magnitude relation between the first numerical value and the second numerical value should satisfy the relation between the first updating rule and the second updating rule, for example, if the first updating rule and the second updating rule are the same, the magnitude relation between the first numerical value and the second numerical value should be the same. If the first updating rule is increasing or decreasing the value a and the second updating rule is increasing the value b, the ratio of the value a to the value b is c, and the magnitude relation between the first value and the second value should also satisfy n times the ratio of the value a to the value b is c, wherein n is a positive integer.
Assuming that the first update rule and the second update rule are the same, the first update rule is increased by 1, the initial value of the first sequence number is the same as the initial value of the second sequence number, and the first sequence number of the master computer room and the second sequence number of the slave computer are initialized, i.e., restored to the initial values, each time a write operation is performed, the first sequence number should be 1 after the master computer room writes the target data in the case that the data to be written is one, i.e., the target data is one, and the second sequence number should be 1 after the slave computer successfully synchronizes the target data, i.e., the first sequence number and the second sequence number are the same.
In addition, considering that when the data written in the host computer room is plural, the data synchronization operation of the host computer room and the host computer room detection of whether the target data is successfully synchronized to the specified computer room are being performed, there may be a case where the host computer room has been successfully synchronized to data3 when determining whether the data1 is successfully synchronized by the slave computer, and the data3 is the data written after the data1, at this time, the second serial number of the slave computer is larger than the first serial number, and therefore, if the second serial number is larger than the first serial number, it can be explained that the data corresponding to the first serial number has been successfully synchronized to the slave computer.
The write order of the data written by the master room, the synchronization order of synchronizing the written data to the slaves may be the same, for example, the write orders of the data written by the master room are data1, data2, data3, data4, data5, and data6, and the synchronization orders of the written data to the slaves are data1, data2, data3, data4, data5, and data6.
Therefore, the first serial number corresponding to the target data written in the main machine room is obtained, the current second serial number of the slave machine is obtained, and if the first serial number is smaller than or equal to the second serial number, the slave machine is indicated to successfully synchronize the target data after the target data is written in the main machine room.
For example, the data written in the host computer room includes data1, data2, data3, data4, data5 and data6, at this time, data1, data2, data3, data4, data5 and data6 are successfully written in the host computer room, wherein data2 is target data, and then, referring to table 1, the first sequence number corresponding to the target data is seq1 equal to 2, the host computer room synchronizes data1, data2, data3, data4, data5 and data6 to the slave computer in sequence, at this time, seq2 of the slave computer is 1, the data indicating that the slave computer is successfully synchronized is data1, the first sequence number is greater than the second sequence number, and it can be determined that the target data is not successfully synchronized to the designated computer room.
And if the seq2 of the slave is 2 at the moment, the data which indicates that the slave is successfully synchronized is data2, namely, the data which indicates that the slave is successfully synchronized is target data, and the first serial number is equal to the second serial number, the target data can be judged to be unsuccessfully synchronized to the appointed machine room.
And if the seq2 of the slave is 3 at this time, the data which indicates that the slave is successfully synchronized is data3, namely, the data3 after the data which is successfully synchronized by the slave is target data, the first serial number is smaller than the second serial number, and the target data can be judged to be unsuccessfully synchronized to the designated machine room.
Therefore, when the first serial number is smaller than or equal to the second serial number, it can be determined that the target data is successfully synchronized to the designated machine room.
In addition, when the host computer room corresponds to a plurality of slave computer rooms, each slave computer room corresponds to a second serial number, whether each slave computer room successfully synchronizes the target data can be determined through the detection mode, so that whether the target data is successfully synchronized to the slave computer room corresponding to the host computer room is determined.
In some embodiments, the operation of detecting whether the target data is successfully synchronized to the slave computer room corresponding to the host computer room may be named as a scanning operation, and if the first serial number is greater than the second serial number, that is, when it is determined that the target data is not successfully synchronized to the slave computer room corresponding to the host computer room, the scanning operation may be continued after a certain period of time, that is, the scanning operation is suspended during the period of time, so that the slave computer room can complete the synchronization operation of the target data in the certain period of time.
Specifically, if the size relationship does not meet a specified condition, after determining that the data is not successfully synchronized to the specified machine room, the method further comprises the steps of acquiring the size relationship between the first serial number and the second serial number again after a specified time length, and executing subsequent operations, wherein the operation of synchronizing the target data to the specified machine room is continuously executed within the specified time length. The specified time length may be a predetermined time length, for example, the specified time length may be the same as the predetermined time length corresponding to the predetermined time period, and specifically, the specified time length may be 10ms.
S550, taking the slave machine room outside the appointed machine room as a new appointed machine room.
After determining that the master computer room synchronizes all the written data to the designated computer room in the above manner, reselecting a slave computer room from the slave computer rooms outside the designated computer room as a new designated computer room, and returning to execute S530 until all the slave computer rooms are completed synchronously.
Therefore, the embodiment of the application can deploy mutually independent Redis clusters in multiple machine rooms, and the read-write operation of all the machine rooms can be synchronized to other machine rooms, namely, the clusters of all the machine rooms are mirror images. When part of the machine rooms fail (including software, hardware and network failures), the service layer can dispatch the read-write request to other normal machine rooms to continue running, so that disaster recovery across the machine rooms is realized, and high availability of service and safety of data are ensured.
In addition, as shown in fig. 7, the above-described clients may include a scanning process and a subscription process. And the scanning process is used for executing the operation of judging whether the data is successfully synchronized to the appointed machine room, the subscribing process is used for monitoring the writing operation of the master machine room and the slave machine room, and when the writing operation is detected, the target data is obtained according to the writing operation.
The data synchronization is carried out through the external program, the service layer is not perceived, the use is simple, namely, the data synchronization is realized through the client, so that after that, the cross-machine-room read-write is not existed, and the service performance is not influenced. The system supports simultaneous reading and writing in multiple places, supports data synchronization among any number of clusters, can deploy multiple places according to the situation, and has strong expandability. And the final consistency of data when writing is performed simultaneously in multiple places is ensured through a master-slave machine room mechanism.
Referring to fig. 8, a block diagram of a data synchronization apparatus 800 according to an embodiment of the present application may include an obtaining unit 801, a writing unit 802, and a synchronization unit 803.
An obtaining unit 801, configured to obtain target data requested to be written into the data storage system.
And a writing unit 802, configured to write the target data into the host room.
And the synchronization unit 803 is configured to synchronize the target data to the slave room after the target data is successfully written into the master room.
It will be clearly understood by those skilled in the art that, for convenience and brevity of description, the specific working process of the apparatus and modules described above may refer to the corresponding process in the foregoing method embodiment, which is not repeated herein.
Referring to fig. 9, a block diagram of a data synchronization apparatus 900 according to an embodiment of the present application may include an obtaining unit 910, a writing unit 920, and a synchronization unit 930.
An obtaining unit 910, configured to obtain target data requested to be written into the data storage system.
The acquisition unit 910 further includes a monitoring subunit 911 and a data determination subunit 912.
The monitoring subunit 911 is configured to monitor write operations of the master room and the slave room.
The data determination subunit 912 is further configured to, when the write operation is detected, obtain the target data according to the write operation.
Specifically, the data determining subunit 912 is further configured to obtain, if the number of write operations is multiple, a timestamp corresponding to each write operation, where each write operation corresponds to specified data, and is configured to modify content to be modified into specified data, determine, according to the timestamp, that the write operation is a target write operation from among the multiple write operations, and use the specified data corresponding to the target write operation as target data.
Further, the data determining subunit 912 is further configured to determine, if the timestamps are not all the same, the latest timestamp of all the timestamps as a target timestamp, use a write operation corresponding to the target timestamp as a candidate write operation, and determine a target write operation in the candidate write operation.
Further, the data determination subunit 912 is further configured to take the candidate write operation as a target write operation if the number of candidate write operations is 1.
Further, the data determining subunit 912 is further configured to determine, if the number of the candidate write operations is at least two, an operation object corresponding to each candidate write operation, where the operation object includes a master room or a slave room, and take the candidate write operation of which the operation object is the master room as a target write operation.
Further, the data determining subunit 912 is further configured to determine, if the timestamps are all the same, an operation object corresponding to each of the candidate write operations, where the operation object includes a master room or a slave room;
And taking the operation object as the candidate write operation of the main machine room as a target write operation.
And a writing unit 920, configured to write the target data into the host room.
And the synchronizing unit 930 is configured to synchronize the target data to the slave room after the target data is successfully written into the master room.
The method comprises the steps that a main machine room and a slave machine room are respectively provided with a message queue corresponding to the main machine room, the main machine room subscribes to the message queues of all the slave machine rooms, each slave machine room subscribes to the message queues of the main machine room, and after target data are successfully written into the main machine room, the target data are synchronized to the slave machine room, and after the target data are successfully written into the main machine room, the target data are synchronized to the slave machine room through the message queues corresponding to the main machine room.
It will be clearly understood by those skilled in the art that, for convenience and brevity of description, the specific working process of the apparatus and modules described above may refer to the corresponding process in the foregoing method embodiment, which is not repeated herein.
Referring to fig. 10, a block diagram of a data synchronization apparatus 1000 according to an embodiment of the application is shown, where the apparatus may include an obtaining unit 1010, a writing unit 1020, and a synchronization unit 1030.
An obtaining unit 1010, configured to obtain target data requested to be written into the data storage system.
And a writing unit 1020, configured to write the target data into the host room.
And the synchronizing unit 1030 is configured to synchronize the target data to the slave room after the target data is successfully written into the master room.
The synchronization unit 1030 includes a selection subunit 1031, a determination subunit 1032, and a synchronization subunit 1033.
The selecting subunit 1031 is configured to synchronize the target data to a designated room after successfully writing the target data to the host room, where the designated room is one of the plurality of slave rooms.
The judging subunit 1032 is configured to judge whether to synchronize the data to the designated machine room successfully.
In some embodiments, the judging subunit 1032 is further configured to detect whether the information of successful synchronization fed back by the specified room is received, if so, determine that the data is successfully synchronized to the specified room, and if not, determine that the data is not successfully synchronized to the specified room.
In other embodiments, the judging subunit 1032 is further configured to obtain first record information corresponding to the host room, where the first record information is used to record an operation performed by the host room and written into target data, obtain second record information corresponding to the specified machine room, where the second record information is used to record an operation performed by the specified machine room and used to synchronize data of the target data, and judge whether to synchronize the data to the specified machine room successfully according to the first record information and the second record information.
Further, the judging subunit 1032 is further configured to judge 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 so, judge that the data is successfully synchronized to the designated machine room, and if not, judge that the data is not successfully synchronized to the designated machine room.
The first record information is a first serial number, the first serial number is used for executing updating operation according to a first updating rule when the host computer room is successfully written with target data, the second record information is a second serial number, and the second serial number is used for executing updating operation according to a second updating rule when the designated computer room is successfully synchronized with data.
Further, the judging subunit 1032 is further configured to obtain a size relation between the first serial number and the second serial number, determine that data is successfully synchronized to the specified machine room if the size relation satisfies a specified condition, where the size relation satisfies the specified condition to indicate that the specified machine room successfully synchronizes the target data after the host room is written with the target data, and determine that data is not successfully synchronized to the specified machine room if the size relation does not satisfy the specified condition.
The first updating rule is to increase or decrease the first serial number by a first value when the main machine room is successfully written with target data, the second updating rule is to increase or decrease the second serial number by a second value when the appointed machine room is successfully synchronized with data, and the first value and the second value are the same.
The size relation meeting a specified condition means that the first sequence number is smaller than or equal to the second sequence number.
Further, the judging subunit 1032 is further configured to acquire the size relationship between the first sequence number and the second sequence number again after a specified time period, and perform subsequent operations, where the operations of synchronizing the target data with the specified machine room are performed continuously for the specified time period.
And the synchronization subunit 1033 is configured to, if the data is successfully synchronized to the designated machine room, take the slave machine room outside the designated machine room as a new designated machine room, and return to perform synchronization of the target data to the designated machine room until all target data synchronization operations of the slave machine rooms are completed.
It will be clearly understood by those skilled in the art that, for convenience and brevity of description, the specific working process of the apparatus and modules described above may refer to the corresponding process in the foregoing method embodiment, which is not repeated herein.
In several embodiments provided by the present application, the coupling of the modules to each other may be electrical, mechanical, or other.
In addition, each functional module in each embodiment of the present application may be integrated into one processing module, or each module may exist alone physically, or two or more modules may be integrated into one module. The integrated modules may be implemented in hardware or in software functional modules.
Referring to fig. 11, a block diagram of an electronic device according to an embodiment of the present application is shown. The electronic device 100 may be a smart phone, a tablet computer, an electronic book, or the like capable of running an application program. The electronic device 100 of the present application may include one or more processors 110, a memory 120, and one or more application programs, wherein the one or more application programs may be stored in the memory 120 and configured to be executed by the one or more processors 110, the one or more program(s) configured to perform the methods as described in the foregoing method embodiments.
Processor 110 may include one or more processing cores. The processor 110 utilizes various interfaces and lines to connect various portions of the overall electronic device 100, perform various functions of the electronic device 100, and process data by executing or executing instructions, programs, code sets, or instruction sets stored in the memory 120, and invoking data stored in the memory 120. Alternatively, the processor 110 may be implemented in at least one hardware form of digital signal Processing (DIGITAL SIGNAL Processing, DSP), field-Programmable gate array (Field-Programmable GATE ARRAY, FPGA), programmable logic array (Programmable Logic Array, PLA). The processor 110 may integrate one or a combination of several of a central processing unit (Central Processing Unit, CPU), an image processor (Graphics Processing Unit, GPU), a modem, etc. The CPU mainly processes an operating system, a user interface, an application program and the like, the GPU is used for rendering and drawing display contents, and the modem is used for processing wireless communication. It will be appreciated that the modem may not be integrated into the processor 110 and may be implemented solely by a single communication chip.
Memory 120 may include random access Memory (Random Access Memory, RAM) or Read-Only Memory (ROM). Memory 120 may be used to store instructions, programs, code, sets of codes, or sets of instructions. The memory 120 may include a stored program area and a stored data area, wherein the stored program area may 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 the various method embodiments described below, etc. The storage data area may also store data created by the terminal 100 in use (such as phonebook, audio-video data, chat-record data), etc.
Referring to fig. 12, a block diagram of a computer readable storage medium according to an embodiment of the present application is shown. The computer readable medium 1200 has stored therein program code that can be invoked by a processor to perform the methods described in the method embodiments described above.
The computer readable storage medium 1200 may 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 1200 includes a non-volatile computer readable medium (non-transitory computer-readable storage medium). The computer readable storage medium 1200 has memory space for program code 1210 that performs any of the method steps described above. The program code can be read from or written to one or more computer program products. Program code 1210 may be compressed, for example, in a suitable form.
It should be noted that the above-mentioned embodiments are merely for illustrating the technical solution of the present application and not for limiting the same, and although the present application has been described in detail with reference to the above-mentioned embodiments, it will be understood by those skilled in the art that the technical solution described in the above-mentioned embodiments may be modified or some technical features may be equivalently replaced, and these modifications or replacements do not drive the essence of the corresponding technical solution to deviate from the spirit and scope of the technical solution of the embodiments of the present application.

Claims (12)

1. A data synchronization method, applied to a master room of a data storage system, the data storage system further comprising a plurality of slave rooms corresponding to the master room, the method comprising:
monitoring write operations of the master machine room and the slave machine room;
if the number of the writing operations is multiple, a time stamp corresponding to each writing operation is obtained, wherein each writing operation corresponds to specified data and is used for modifying the content to be modified into the specified data;
Determining a target write operation from a plurality of write operations according to the time stamp;
taking the designated data corresponding to the target write operation as target data;
Writing the target data into the main machine room;
After determining that the target data is successfully written into the host computer room, synchronizing the target data to a designated computer room, wherein the designated computer room is one of a plurality of slave computer rooms;
Acquiring a size relation between a first serial number corresponding to the host computer room and a second serial number corresponding to the appointed computer room, wherein the first serial number is used for executing updating operation according to a first updating rule when the host computer room is successfully written with target data, the second serial number is used for executing updating operation according to a second updating rule when the slave computer room is successfully synchronized with data, and each slave computer room corresponds to one second serial number;
If the size relation meets the specified condition, judging that the target data is successfully synchronized to the specified machine room, wherein the size relation meets the specified condition to indicate that the specified machine room successfully synchronizes the target data after the host room is written with the target data;
If the size relation does not meet the specified condition, judging that the data is not successfully synchronized to the specified machine room;
And if the data is successfully synchronized to the appointed machine room, taking the slave machine room outside the appointed machine room as a new appointed machine room in the slave machine rooms, and returning to perform the synchronization of the target data to the appointed machine room until the target data synchronization operation of all the slave machine rooms is completed.
2. The method of claim 1, wherein the determining from within a plurality of the write operations the timestamp as the target write operation comprises:
If the time stamps are not identical, determining the latest time stamp in all the time stamps as a target time stamp;
taking the write operation corresponding to the target timestamp as a write operation to be selected;
a target write operation is determined from within the candidate write operation.
3. The method of claim 2, wherein the determining, from within the candidate write operations, a target write operation comprises:
and if the number of the candidate write operations is 1, taking the candidate write operation as a target write operation.
4. The method of claim 2, wherein the determining, from within the candidate write operations, a target write operation comprises:
If the number of the to-be-selected writing operations is at least two, determining an operation object corresponding to each to-be-selected writing operation, wherein the operation object comprises a master machine room or a slave machine room;
And taking the operation object as the candidate write operation of the main machine room as a target write operation.
5. The method as recited in claim 1, further comprising:
If the time stamps are the same, determining an operation object corresponding to each write operation to be selected, wherein the operation object comprises a master machine room or a slave machine room;
And taking the operation object as the candidate write operation of the main machine room as a target write operation.
6. The method of claim 1, wherein a first update rule is to increase or decrease the first sequence number by a first value when the host room is successfully written with target data, and wherein a second update rule is to increase or decrease the second sequence number by a second value when the specified room is successfully synchronized with data, the first and second values being the same.
7. The method of claim 6, wherein the size relationship satisfying a specified condition means that the first sequence number is less than or equal to the second sequence number.
8. The method of claim 1, wherein if the size relationship does not satisfy a specified condition, after determining that the data is not successfully synchronized to the specified machine room, further comprising:
And after a specified time length, acquiring the size relation between the first serial number and the second serial number again and executing subsequent operations, wherein the operation of synchronizing the target data with the specified machine room is continuously executed within the specified time length.
9. The method of claim 1, wherein the master room and the slave room each have a message queue, the master room subscribes to all the message queues of the slave rooms, each of the slave rooms subscribes to the message queues of the master room, and wherein synchronizing the target data to the slave room after determining that the target data is successfully written to the master room comprises:
and after the target data is successfully written into the host computer room, synchronizing the target data to the slave computer room through a message queue corresponding to the host computer room.
10. A data synchronization device, characterized in that it is applied to a main room of a data storage system, the data storage system further includes a plurality of slave rooms corresponding to the main room, the device includes:
An acquisition unit for monitoring write operations of the master machine room and the slave machine room; if the number of the write operations is multiple, acquiring a time stamp corresponding to each write operation, wherein each write operation corresponds to specified data and is used for modifying the content to be modified into specified data;
the writing unit is used for writing the target data into the main machine room;
The system comprises a host room, a synchronization unit, a size relation, a first sequence number and a second sequence number, wherein the host room is used for writing target data into the host room, the target data is synchronized to a designated machine room after being judged to be successfully written into the host room, the designated machine room is one of a plurality of slave machine rooms, the size relation between the first sequence number corresponding to the host room and the second sequence number corresponding to the designated machine room is obtained, the first sequence number is used for executing updating operation according to a first updating rule when the host room is successfully written into the target data, the second sequence number is used for executing updating operation according to a second updating rule when the slave machine room is successfully synchronized into the data, each slave machine room corresponds to one second sequence number when the slave machine room is successfully synchronized into the data, if the size relation meets a designated condition, the target data is judged to be successfully synchronized to the designated machine room, the designated machine room is successfully synchronized after the target data is written into the host room, if the size relation does not meet the designated condition, the designated machine room is judged to be unsuccessful in synchronizing the data to the designated machine room, and all the data are returned from the designated machine room to the target machine room after the designated machine room is successfully synchronized.
11. A data storage system, comprising:
a master machine room and a slave machine room corresponding to the master machine room;
the host computer room being adapted to perform the method of any of the preceding claims 1-9.
12. A computer readable medium, characterized in that the computer readable medium stores a program code executable by a processor, which program code, when executed by the processor, causes the processor to perform the method of any of claims 1-9.
CN202080094721.7A 2020-04-24 2020-04-24 Data synchronization method, device, data storage system and computer readable medium Active CN115004662B (en)

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2020/086773 WO2021212493A1 (en) 2020-04-24 2020-04-24 Data synchronization method and device, data storage system and computer-readable medium

Publications (2)

Publication Number Publication Date
CN115004662A CN115004662A (en) 2022-09-02
CN115004662B true CN115004662B (en) 2025-02-28

Family

ID=78270983

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202080094721.7A Active CN115004662B (en) 2020-04-24 2020-04-24 Data synchronization method, device, data storage system and computer readable medium

Country Status (2)

Country Link
CN (1) CN115004662B (en)
WO (1) WO2021212493A1 (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114328739B (en) * 2021-12-30 2025-12-30 北京百度网讯科技有限公司 Data synchronization, reading methods and devices, electronic devices, storage media and products
CN115174682B (en) * 2022-06-17 2023-07-28 中国银联股份有限公司 Data distribution method, system, center, device and computer readable storage medium
CN116701526B (en) * 2022-12-05 2024-06-21 荣耀终端有限公司 Data synchronization method and electronic device
CN116089471A (en) * 2023-02-09 2023-05-09 北京奇艺世纪科技有限公司 Cache data updating method, system, equipment and medium for multiple machine rooms
CN118368297B (en) * 2024-06-20 2024-09-13 杭州宇信数字科技有限公司 Heterogeneous data real-time synchronization method, device and system crossing data centers

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104794155A (en) * 2015-03-12 2015-07-22 北京奇虎科技有限公司 Data loading method, device and system
CN108055343A (en) * 2017-12-26 2018-05-18 北京奇虎科技有限公司 For the method for data synchronization and device of computer room

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104765661B (en) * 2014-12-30 2018-04-13 深圳市安云信息科技有限公司 The multinode hot spare method of Metadata Service node in a kind of cloud storage service
CN104980519B (en) * 2015-06-29 2019-03-05 北京奇虎科技有限公司 Multimachine room storage system
CN110673941B (en) * 2019-09-27 2020-07-17 掌阅科技股份有限公司 Migration method of micro-services in multiple computer rooms, electronic equipment and storage medium
CN110633175B (en) * 2019-09-27 2020-07-28 掌阅科技股份有限公司 Multi-computer-room data processing method based on micro-service, electronic equipment and storage medium

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104794155A (en) * 2015-03-12 2015-07-22 北京奇虎科技有限公司 Data loading method, device and system
CN108055343A (en) * 2017-12-26 2018-05-18 北京奇虎科技有限公司 For the method for data synchronization and device of computer room

Also Published As

Publication number Publication date
WO2021212493A1 (en) 2021-10-28
CN115004662A (en) 2022-09-02

Similar Documents

Publication Publication Date Title
CN115004662B (en) Data synchronization method, device, data storage system and computer readable medium
US20230315690A1 (en) System and method for content synchronization
US11221995B2 (en) Data replication from a cloud-based storage resource
CN113297201B (en) Index data synchronization method, system and device
US10331625B2 (en) Managing sequential data store
US12572561B2 (en) Method and apparatus for synchronously updating metadata in distributed database
CN108762982B (en) A database recovery method, device and system
CN105468718B (en) Data consistency processing method, device and system
CN114238495A (en) Method and device for switching main cluster and standby cluster of database, computer equipment and storage medium
CN104424283A (en) Data migration system and data migration method
CN112286723B (en) Computer room disaster recovery control method, terminal and storage medium
CN114443341B (en) Methods for detecting downed servers, and methods and devices for high-availability recovery of databases.
CN116049306B (en) Data synchronization methods, devices, electronic devices, and readable storage media
WO2014087287A1 (en) Replication control using eventually consistent meta-data
CN107657027B (en) Data storage method and device
CN105162879A (en) Method, device and system for realizing data consistency among plurality of machine rooms
CN114981796B (en) Data synchronization method, device, data storage system and computer readable medium
CN118796932A (en) Data synchronization method, device, equipment and storage medium
CN116737724B (en) Method and apparatus for full synchronization of cached data
CN106855869B (en) Method, device and system for realizing high availability of database
CN114675986B (en) Message processing method, device, apparatus, storage medium and computer program product
CN112000850B (en) Methods, devices, systems and equipment for data processing
CN118796566B (en) Distributed service system, instance splitting method, device, medium and program product
CN115104295B (en) Data processing method, device, electronic device and storage medium
CN115756521B (en) Cloud application processing method, device, computer equipment, and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant