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

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

Info

Publication number
CN115004662A
CN115004662A CN202080094721.7A CN202080094721A CN115004662A CN 115004662 A CN115004662 A CN 115004662A CN 202080094721 A CN202080094721 A CN 202080094721A CN 115004662 A CN115004662 A CN 115004662A
Authority
CN
China
Prior art keywords
data
room
slave
target data
target
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.)
Pending
Application number
CN202080094721.7A
Other languages
Chinese (zh)
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
Pending legal-status Critical Current

Links

Images

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

A data synchronization method, a data synchronization device, a data storage system and a computer readable medium relate to the technical field of computers, and the method comprises the following steps: acquiring target data requested to be written into the data storage system (S201); writing the target data into a main computer room (S202); after the target data is successfully written to the master room, the target data is synchronized to a slave room (S203). According to the method, data are written into the main computer room, and the data written into the main computer room are synchronized to the auxiliary computer room based on the data of the main computer room, so that the consistency of the data can be better kept.

Description

Data synchronization method, data synchronization device, data storage system and computer readable medium Technical Field
The present application relates to the field of computer technologies, and in particular, to a data synchronization method, an apparatus, a data storage system, and a computer-readable medium.
Background
With the increasing popularization of network services, the access amount of users is larger and larger, if all the service data are stored in one server, the server often fails due to the large access amount, and due to the limitation of the storage space of the server, in an application scenario with a large service data amount, one server often cannot bear all the service data, so that a plurality of servers are required to provide services for the users together. Therefore, a plurality of servers which are commonly used for providing a certain service can be arranged in the same machine room, then a plurality of machine rooms form a system, and the system provides a data storage function for a service layer.
However, when data storage is performed in the business layer, each room in the system needs to perform a write operation, and then if data of a part of rooms is wrongly written, data inconsistency of the whole system can be caused.
Disclosure of Invention
The present application provides a data synchronization method, apparatus, data storage system and computer readable medium to improve the above-mentioned drawbacks.
In a first aspect, an embodiment of the present application provides a data synchronization method, which is applied to a master computer room of a data storage system, where the data storage system further includes a slave computer room corresponding to the master computer room. The method comprises the following steps: acquiring target data requested to be written into the data storage system; writing the target data into the main computer room; after the target data is successfully written into the master computer room, synchronizing the target data to the slave computer room.
In a second aspect, an embodiment of the present application further provides a data synchronization apparatus, 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 write unit and a synchronization unit. An obtaining unit configured to obtain target data requested to be written in the data storage system. And the writing unit is used for writing the target data into the main computer 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, an embodiment of the present application further provides a data storage system, including: the system comprises a main machine room and a slave machine room corresponding to the main machine room; the host is used for executing the method.
In a fourth aspect, the present application also provides a computer-readable storage medium, where a program code executable by a processor is stored, and when executed by the processor, the program code causes the processor to execute 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, no matter whether the data is requested to be written in a host room or a slave room of the system, the target data is written in the host room first, and then after the target data is successfully written in the host room, the target data is synchronized to the slave room. Therefore, when target data are written into a plurality of computer rooms simultaneously, if data of a certain computer room are wrongly written, the data of each computer room are inconsistent, the data are written into the main computer room firstly, the data written into the main computer room are synchronized to the auxiliary computer room by taking the data of the main computer room as a reference, and the consistency of the data can be better kept.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
FIG. 1 is a schematic diagram illustrating a data storage system provided by an embodiment of the present application;
FIG. 2 is a flow chart of a method for data synchronization according to an embodiment of the present application;
FIG. 3 illustrates a method flow diagram of a data synchronization method provided by 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 illustrates a method flow diagram of a data synchronization method provided by yet another embodiment of the present application;
fig. 6 illustrates a flowchart of 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 apparatus according to another embodiment of the present application;
FIG. 9 is a block diagram illustrating a data synchronization apparatus according to another embodiment of the present application;
FIG. 10 is a block diagram of a data synchronization apparatus according to yet 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 storage unit according to an embodiment of the present application, configured to store or carry program code for implementing a data synchronization method according to an embodiment of the present application.
Detailed Description
In order to make the technical solutions better understood by those skilled in the art, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application.
With the increasing popularization of network services, the access volume of users is larger and larger, if all the service data are stored in one server, the server often fails due to the large access volume, and due to the limitation of the storage space of the server, in an application scenario with a large service data volume, one server often cannot bear all the service data, so that a plurality of servers are required to provide services for the users together. For this purpose, a plurality of servers commonly used for providing a certain service may be provided in the same machine room, and the machine room provides the service to the user.
In the data management service, the memory database is widely applied, the memory database refers to a database in which data is directly operated in a memory, and is generally deployed in a cluster manner, and such a cluster is called a memory database cluster. The memory database cluster comprises a memory database host and a memory database slave, and data synchronization needs to be kept between the memory database host and the memory database slave. Further, the synchronization is divided into full synchronization and incremental synchronization, the full synchronization means that the memory database slave synchronizes all data of the memory database host at one time, and the incremental synchronization means that the memory database slave synchronizes only different partial data between the memory database slave and the memory database host.
The Redis is a high-performance open source database which can be based on a memory, is written by using ANSIC language, provides programming interfaces of multiple languages, and is commonly used for realizing functions of data storage, quick access and the like of software or application; in a production environment, the application of the redis is very wide, for example, to ensure the stability of a service while expanding capacity, a redis cluster supporting distributed high availability and horizontal extension is often used for storing and accessing data. In order to improve the system stability, a master-slave structure is generally adopted by a redis system. During the initialization phase of the redis slave node and when the master node is written with new data, the data on the redis master node needs to be copied for backup, and the event is called the master-slave data synchronization of the redis.
As shown in fig. 1, fig. 1 shows a schematic diagram of a data storage system including a plurality of rooms, including room 1, room 2, and room 3, as shown in fig. 1. Each machine room comprises a master machine and at least one slave machine corresponding to the master machine. As shown in fig. 1, a master 10 and a slave 11 and a slave 12 corresponding to the master are included in a machine room 1, wherein the master 10, the slave 11 and the slave 12 are in a master-slave relationship. Among them, the host is also called a master (master), and the master provides a service to the outside. The slave is also called as slave node (slave), and the slave node copies the data of the Master node in real time to ensure the consistency with the Master node. The slave cannot be written by other devices, and the data in the slave is synchronized to the slave by the master in a data synchronization mode.
In addition, as shown in fig. 1, the machine room 2 includes a master 20 and slaves 21 and 22 corresponding to the master, and the machine room 3 includes a master 30 and slaves 31 and 32 corresponding to the master.
The data storage system formed by each computer room can provide data storage service for the business layer, that is, data generated by the business layer can be stored in the data storage system, or data can 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 computer room in the data storage system, specifically, into a host of any computer room in the data storage system, and then to ensure consistency of the data, the written data needs to be written into each computer room.
However, the inventor finds in research that, in the current implementation of a cross-room multi-activity scheme based on Redis, a multi-write scheme is adopted, that is, when a service layer performs data storage, a write operation needs to be performed on a storage cluster of each room, and after the storage clusters of all rooms are successfully written, the data storage is considered to be successful. However, when data storage is performed in the business layer, each room in the system needs to perform a write operation, and then if data of a part of rooms is wrongly written, data inconsistency of the whole system can be caused.
Therefore, in order to overcome the above-mentioned defects, in the embodiment of the present application, the multiple 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 designated as the slave machine rooms corresponding to the master machine room.
An embodiment of the present application provides a data synchronization method, which is applied to the data storage system, as an implementation manner, each machine room in the data storage system is correspondingly provided with a client, and the client is used for writing data into a certain machine room, and executing an embodiment of the method described in the present application. As an implementation manner, the client may be in a host installed in each machine room, or may be in a terminal independent from the host and installed 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 main computer room described above, and specifically, the execution subject may be a client in the main computer room. Specifically, the method comprises the following steps: s201 to S203.
S201: target data requested to be written into the data storage system is obtained.
As one embodiment, it may be that the data storage system obtains a data write request for writing target data into the data storage system. In particular, it may be that the service layer sends a data write request to the data storage system.
In some embodiments, the data write request may include a label specifying the room to which writing is requested, the label serving as identity information of the room. In this embodiment, the service layer requests to write the target data into the machine room corresponding to the designated label. In other embodiments, the data write request may not include a label specifying the room to which the write request is directed.
Whether the data is written into a certain machine room in a designated mode or written into a certain machine room in an unspecified mode, the data can be used as target data required to be written into the data storage system as long as the data corresponds to a data writing request required to be written into the data storage system.
The host computer room can monitor data written into each computer room (including the host computer room and the slave computer room corresponding to the host computer room), so that the host computer room can obtain target data requested to be written into the data storage system.
As an implementation manner, the master room and the slave rooms each have a corresponding message queue, the master room subscribes to the message queues of all the slave rooms, and each slave room subscribes to the message queue of the master room. The application programs such as the service layer and the like communicate with the machine rooms through Message queues, and particularly, the Message Queue (MQ) is a communication method of the application programs to the application programs. Applications communicate by writing and retrieving queued data (messages) for the application.
For example, when the service layer requests to write target data into a certain computer room, the service layer sends a data write request to a message queue of the computer room, and if the computer room is a slave computer room, because the master computer room subscribes to the message queue of the slave computer room, the master computer room can monitor the operation of the slave computer room on the message queue, so that the data write request can be monitored by the master computer room when being written into the message queue, and further target data requested to be written into the data storage system can be acquired.
S202: and writing the target data into the main computer room.
And after target data which are requested to be written into the data storage system are acquired, writing the target data into the host computer room.
As an embodiment, the master room includes a master and a slave corresponding to the master, and the target data may be written into the master room by writing the target data into the master and then synchronizing the target data with the slave corresponding to the master by the master.
Assume that the machine room 1 is a main machine room and the target data is data. The master 10 synchronizes the data to the slaves 11 and 12 corresponding to the master.
As an implementation manner, a log pipelining function is provided in each computer room, and the log pipelining function is used for recording operations of data written by a host, in a multiple-activity scenario of a Redis cluster across computer rooms based on log pipelining, all data writes of the Redis are stored in log pipelining of a local disk, an external scanning program scans the log pipelining and synchronizes data modification to the Redis clusters of other computer rooms, where each Redis cluster may be understood as the computer room described above. Through the log pipeline, each writing operation of each computer room can be recorded, so that the data synchronization can be realized.
Specifically, taking the above storage system as a Redis system as an example, modifying the source code implementation of a 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 actually received write operations. For example, a plurality of data are written to the host, the plurality of data are respectively data1, data2, data3, data4, data5 and data6, that is, the writing order of the plurality of data is data1, data2, data3, data4, data5 and data6, and then the plurality of data are recorded in a log file, the log recording order is also data1, data2, data3, data4, data5 and data6, wherein data1, data2, data3, data4, data5 and data6 may be identifications of the plurality of data, and the writing time of each written data may be further recorded in the log record.
In addition, both the master and the slave may have corresponding log files, that is, both the master and the slave may perform a log pipelining function for recording write operations of the master and the slave, where the write operation for the slave may be understood as a data synchronization operation of the master to the slave.
Therefore, by recording the write data, it is possible to obtain target data written by the host, where the target data may be a set of a plurality of data to be written continuously or any one of the plurality of data to be written continuously.
S203: after the target data is successfully written into the master computer room, synchronizing the target data to the slave computer room.
Specifically, whether the target data is successfully written into the host computer room is judged, and if the target data is successfully written into the host computer room, the target data is synchronized to the slave computer room.
And judging whether the target data is successfully written into the host computer room or not, and after the target data is written into the host computer, successfully synchronizing the target data into the slave computer corresponding to the host computer or not. Specifically, how to determine whether the target data is successfully synchronized to the slave corresponding to the master may refer to the following embodiments.
After the target data is written into the master room, the target data is stored in the storage space corresponding to the master room, and then a data synchronization operation is performed, specifically, the client sends the target data written into the master room to the slave room corresponding to the master room, so that the data stored in the slave room is also updated. That is, the target data is synchronized from the corresponding storage space of the machine room.
If the target data is successfully synchronized to the slave machine corresponding to the master machine, it can be determined that the target data written into the master machine is successfully synchronized to the slave machine corresponding to the master machine, and then the target data can be synchronized to the slave machine room at this time.
Taking the data storage system as an example, the master 10 of the machine room 1 is written with the target data, the master 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 execute the synchronization operation of the target data. Specifically, the master 10 transmits the target data to the master 20 in the machine room 2 and the master 30 in the machine room 3, the master 20 is written with the target data and synchronizes the target data to the slave 21 and the slave 22 corresponding to the master 20, and the master 30 is written with the target data and synchronizes the target data to the slave 31 and the slave 32 corresponding to the master 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 after the target data is successfully written in the host room, the target data is synchronized to the slave room. Therefore, when target data are written into a plurality of machine rooms simultaneously, if data of a certain machine room are wrongly written, the data of each machine room are inconsistent, the data are written into the main machine room firstly, the data written into the main machine room are synchronized to the auxiliary machine room by taking the data of the main machine room as a reference, and the consistency of the data can be better maintained.
Referring to fig. 3, fig. 3 shows a data synchronization method, where an execution subject of the method may be the host computer room described above, and specifically, the execution subject may be a client in the host computer room. Specifically, the method comprises the following steps: s310 to S340.
S310: and monitoring the writing operation of the master computer room and the slave computer room.
As an implementation manner, a client in a host room can detect write operations for all machine rooms, for example, through the message queues, the host room subscribes the message queues of all slave machine rooms, so that when data is written in any slave machine room, the write operation of the slave machine room can be monitored, and when the host room writes data, the write operation can be written in the message queue of the host room, so that the slave machine room corresponding to the message subscribed to the host room can also know that the data is written in the host room, and any machine room in a data storage system can be regarded as a write operation for the data storage system when the data is written in the host room.
Therefore, through monitoring the message queues of the machine rooms, the current write operation aiming at the data storage system can be detected when data are written into any machine room.
S320: and when the write operation is detected, obtaining the target data according to the write operation.
For example, the write operation may be a data packet, the data packet includes data requested to be written, and when the host room monitors the write operation, the host room can analyze the write operation to obtain the data requested to be written.
In one embodiment, when there is only one write operation, the data requested to be written may be used as the target data.
As another embodiment, if there are multiple write operations, the data requested to be written corresponding to each write operation is determined, and if the data requested to be written of all the write operations are the same, the data requested to be written corresponding to one write operation may be selected as the target data.
As a further 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 write operations for which the data modification request is the same are found. The data modification request may be that the data requested to be written is the same and the data object requested to be modified is the same, where the data object requested to be modified 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.
If the write operation is an update request, the content to be modified may be certain specified data stored in the computer room, and the specified data is modified into the 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 computer room, and the data requested to be written is written in the storage space when the write operation is executed.
Therefore, when the write operation is multiple, the content to be modified corresponding to each write operation is determined, and the multiple write operations are distinguished according to the content to be modified, so as to obtain the write operation corresponding to different content to be modified, namely the write operation of different modification purposes. In addition, if the content to be modified is designated data, each data in each machine room corresponds to an identifier, and the identifiers are unified in each machine room, for example, data1 is included in the data stored in the master machine room, the data stored in the slave machine room also includes data1, and data consistency should be maintained between data1 in the master machine room and data1 in the slave machine room.
Therefore, if the content to be modified is the designated data, the identification of the designated data is acquired, and the write operation with the same identification of the designated data is taken as the write operation with the same modification purpose. If the content to be modified is a storage space, the write operation in which each content to be modified is a storage space may be used as a write operation for modification, or, if the write operation is newly added data, a data identifier may be configured for the write operation, and the data identifier is a newly added identifier, and when the data is written into the computer room, the data identifier also corresponds to the computer room.
For example, the writing operations are operation 1, operation 2, operation 3, operation 4, operation 5, operation 6 and operation 7, respectively, the content to be modified corresponding to operation 1, operation 2 and operation 3 is data1, operation 4 and operation 5 are used for adding one piece of data, the identification of the added data is data7, operation 6 is used for adding one piece of data, the identification of the added data is data8, operation 7 is used for adding one piece of data, and the identification of the added data is data 9.
The above-mentioned 7 write operations can be divided into four modification purposes, namely modification purpose 1, modification purpose 2, modification purpose 3 and modification purpose 4, 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, determining a write operation corresponding to each modification purpose, specifically, determining an implementation of a 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 a write operation corresponding to each modification purpose.
S321: and if the number of the write-in operations is multiple, acquiring a time stamp corresponding to each write-in operation.
And each write-in operation corresponds to specified data and is used for modifying the content to be modified into the specified data. The designated data corresponding to each write operation may be the same or different.
In one 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 requesting to write specified data to the data storage system, the data storage system configures a time stamp for the write request, and treats the write request as a write operation, so that the write operation can be configured with a time stamp.
S322: determining, from within the plurality of write operations, a target write operation according to the timestamp.
The time stamp can be used as the time when the specified data is requested to be written corresponding to the write operation, i.e. can be used as the write time of different write operations. As one embodiment, the target write operations may be determined based on the early-late order of the timestamps of the respective write operations. For example, the write operation corresponding to the earliest or latest timestamp is selected as the target write operation.
Specifically, the timestamps corresponding to the plurality of write operations may be the same or may not be the same, and in the case of being the same or not, the implementation mode determined as the target write operation in the plurality of write operations according to the timestamps may be different.
Specifically, whether timestamps corresponding to the write operations are all the same is judged, and if the timestamps are not all the same, the latest timestamp in all the timestamps is determined to be the target timestamp.
The timestamps are not all the same, and the same timestamp may exist in all timestamps, or different timestamps exist, that is, all timestamps are not all the same. All the timestamps can be sequenced according to the time sequence to obtain a time sequence, and the last timestamp in the time sequence is taken as a target timestamp.
And then, taking the write operation corresponding to the target timestamp as the write operation to be selected. The latest timestamp may include multiple timestamps, that is, multiple latest timestamps may be obtained, and the write operation corresponding to each latest timestamp may be used as the write operation to be selected.
As another implementation, all write operations may be ordered in time order of the time stamps, resulting in a candidate sequence. The candidate sequence includes a plurality of identifiers of write operations, where the identifier of a write operation may be identity information for recording each write operation. And in the sequence to be selected, the identifier of each write operation corresponds to a sequence number, and the earlier the sequence number is, the earlier the time stamp corresponding to the write operation is, that is, the write operations are sequenced according to the time sequence of the time stamps to obtain the sequence to be selected. And then, taking the most front write operation in the candidate sequence as the candidate write operation. If the timestamps of a plurality of write operations are the same, the sequence numbers corresponding to the write operations of the same timestamp are the same, and therefore, a plurality of acquired write operations to be selected may be provided, where the timestamp corresponding to each write operation to be selected is the same, and among the timestamps corresponding to all the write operations, the timestamp corresponding to each write operation to be selected is the latest timestamp.
And then, determining a target write operation from the write operations to be selected. And if the number of the write operations to be selected is 1, taking the write operations to be selected as target write operations. And if the number of the write-in operations to be selected is at least two, determining an operation object corresponding to each write-in operation to be selected, wherein the operation object comprises a master computer room or a slave computer room. The operation object may be a room designated to be written by the service layer when the service layer requests to store data, specifically, when the data write request includes an identifier of the room, and when the master room and the slave room are set in advance, the identifier of each room can be made to correspond to a tag, where the tag includes a master room tag and a slave room tag.
And taking the to-be-selected write operation with the operation object as the main computer room as a target write operation.
For example, taking the above-exemplified plurality of write operations as including operation 1, operation 2, operation 3, operation 4, operation 5, operation 6, and operation 7 as an example, the timestamps 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 t 7. According to the chronological order, the time sequence of each timestamp is time t1, time t2, (time t3 and time t4), (time t5, time t6 and time t7), that is, time t3 and time t4 are the same, and time t5, time t6 and time t7 are the same, it can be understood that operation 1 is acquired first, 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 may be determined from operation 5, operation 6, and operation 7.
As an embodiment, it may be determined that operation objects corresponding to each of operation 5, operation 6, and operation 7 correspond to each other, for example, the operation objects corresponding to each of operation 5, operation 6, and operation 7 are the master room, the slave room 1, and the slave room 2, respectively. The candidate write operation whose operation object is the main room is operation 5, so that it can be determined that the target write operation is 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 timestamps corresponding to each of the write operations are all the same when the write operations are detected, the operation object corresponding to each of the write operations may be directly obtained without performing the write operation for searching the latest timestamp, and the operation object may refer to the foregoing description and is not described herein again.
Specifically, if the timestamps of each write operation are all the same, determining an operation object corresponding to each write operation to be selected, where the operation object includes a master room or a slave room; and taking the to-be-selected write operation with the operation object as the main computer room as a target write operation.
S323: and taking the designated data corresponding to the target write operation as target data.
Exemplarily, it is assumed that the currently obtained write operations collectively include operation 1, operation 2, operation 3, operation 4, operation 5, operation 6, operation 7, operation 8, operation 9 and operation 10, where the content to be modified corresponding to operation 1, operation 2, operation 3, operation 4, operation 5, operation 6 and operation 7 is data1, the content to be modified corresponding to operation 8, operation 9 and operation 10 is data7, and data1 exists in all rooms, the purpose of operation 1, operation 2, operation 3, operation 4, operation 5, operation 6 and operation 7 is to modify data of data1, and the specified data corresponding to operation 1, operation 2, operation 3, operation 4, operation 5, operation 6 and operation 7 are data1, data2, data3, data4, data5, data6 and data7, respectively, and it is assumed that operation 1, operation 2, operation 3, operation 4, data5, data6 and data7 correspond to data1, operation 2, operation 3, operation 4, The operation targets corresponding to operation 5, operation 6, and operation 7 are the slave machine room 1, the slave machine room 2, the master machine room, the slave machine room 3, the master machine room, the slave machine room 1, and the slave machine room 2, respectively. For example, the purpose of operation 1 is to modify data1 stored from the room 1 to data 1.
Then, if the time stamps corresponding to the operation 5, the operation 6, and the operation 7 are latest, it may be determined that the target write operation is the operation 5 whose operation object is the master room, the determined target data is the data5, and finally, the current modification method for the data1 is determined to modify the data1 in the master room into the data5, and synchronize the data5 to other slave rooms, so that all the data1 of the slave rooms are modified into the data 5.
Then, after the operation of modifying the data1 of each room into the data5 is completed, the data7 of all rooms is modified according to the operation 8, the operation 9 and the operation 10, and reference is made to the above method for determining the target data, namely, modifying the data7 in the host computer first and then synchronizing sequentially.
S330: and writing the target data into the main computer room.
S340: after the target data is successfully written into the master computer room, synchronizing the target data to the slave computer room.
Referring to fig. 5, fig. 5 illustrates a data synchronization method, where an execution subject of the method may be the main computer room, and specifically, the execution subject may be a client in the main computer room. Specifically, the method comprises the following steps: s510 to S550.
S510: target data requested to be written to the data storage system is obtained.
S520: and writing the target data into the main computer room.
S530: and after the target data is successfully written into the main computer room, synchronizing the target data to a specified computer room.
Wherein the designated machine room is one of the plurality of slave machine rooms.
As an implementation manner, each slave machine room may be set to have a synchronization state, where the synchronization state includes unsynchronized state and synchronized state, each time one slave machine room is selected from the unsynchronized slave machine rooms as a designated machine room, the target data is synchronized to the designated machine room, and when the target data is successfully synchronized to the designated machine room, the synchronization state corresponding to the designated machine room may be changed, for example, the unsynchronized state is modified to be synchronized.
As an embodiment, a synchronization sequence may be preset, the master room synchronizes the target data to all the slave rooms according to the synchronization sequence, and then one slave room is sequentially selected as the designated room according to the synchronization sequence.
S540: and judging whether the data are successfully synchronized to the specified machine room.
As an embodiment, whether the target data is successfully synchronized to the slave machine room corresponding to the master machine room may be determined according to information replied by the slave machine room, or whether the target data is successfully synchronized to the slave machine room corresponding to the master machine room may be determined according to the data write records of the master machine room and the slave machine room, that is, log files of the master machine room and the slave machine room.
Specifically, the implementation of judging whether to synchronize data to the specified machine room successfully may be to detect whether to receive information that synchronization fed back by the specified machine room is successful; if so, judging that the data is successfully synchronized to the specified machine room; and if not, determining that the data is not successfully synchronized to the specified machine room.
The information that the synchronization is successful may be sent to the master room after the slave room receives the target data and successfully stores the target data, and the master room can determine that the target data is successfully synchronized to the slave room corresponding to the master room after receiving the information.
As an embodiment, it may be determined whether the information that the synchronization fed back by the specified computer room is successful is received within a predetermined time period. Here, a time starting point of a predetermined period of time may be a point of time at which an operation of synchronizing the target data to the slave room corresponding to the master room is performed, and a predetermined length of time of the predetermined period of time may be predetermined, for example, may be set empirically. Specifically, the time length of the slave machine room synchronization data may be counted, and the predetermined time length of the predetermined time period may be determined according to the time length.
As an embodiment, the time length for synchronizing the plurality of data from the machine room may be acquired, and the predetermined time length of the predetermined time period may be determined according to the plurality of time lengths. Specifically, an average value of the plurality of time lengths is calculated as a predetermined time length of a predetermined period.
As another embodiment, the rate of the synchronization 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 synchronization data. For example, the ratio of the data size of the target data to the counted rate of the synchronization data is acquired as the predetermined time length of the predetermined period.
As an embodiment, referring to fig. 6, the determining whether the target data is successfully synchronized to the designated machine room may include: s541 to S543.
S541: and acquiring first recording information corresponding to the host computer room, wherein the first recording information is used for recording the operation of the written target data executed by the host computer room.
As an embodiment, the first record information includes an identifier of data written by the host room each time and an operation time, where the operation time is used for recording a writing time point of the written data, where the identifier of the written data may be an identifier allocated by the host room for each written data, where the identifier may be an identifier determined according to a content of the data, for example, an identifier generated from a data digest of the data, and as an embodiment, a data digest of the target data may be used as the identifier of the target data. The data summary may be a content for describing the target data. The first record information includes the write time corresponding to the target identifier of the target data.
S542: and acquiring second recording information corresponding to the specified machine room, wherein the second recording information is used for recording data synchronization operation of target data executed by the specified machine room.
Similarly, the second record information includes an identifier and an operation time of the data synchronized from the machine room each time, where the operation time may be a time of the data synchronized from the machine room, and the implementation of the identifier of the data may refer to the foregoing embodiment, and is not described herein again. Each slave room corresponds to the second record information, and thus the second record information of each slave room may be the second record information of the designated room.
S543: and judging whether the data are successfully synchronized to the appointed machine room or not according to the first record information and the second record information.
The first record information includes an identifier of data written into the main computer room and a writing time point corresponding to the identifier, and the second record information includes an identifier of data synchronized from the computer room and a synchronization time corresponding to the identifier, so that whether the target data is successfully synchronized to the specified computer room can be judged according to the identifier of the data written into the main computer room, the writing time point corresponding to the identifier, the identifier of the data synchronized in the specified computer room and the synchronization time corresponding to the identifier.
As an embodiment, it is determined whether a first operation time point in the first record information is earlier than a second operation time point in the second record information; if so, judging that the data is successfully synchronized to the appointed machine room; and if not, judging that the data is not successfully synchronized to the specified machine room. The first operation time point is a writing time point corresponding to a target identifier of target data written into the host computer room recorded in the first recording information, the second operation time point is a synchronization time point corresponding to a target identifier of target data synchronized with the specified computer room recorded in the second recording information, whether the synchronization time point is later than the writing time point is judged, if yes, the target data are successfully synchronized to the specified computer room, and if not, the target data are not successfully synchronized to the specified computer room.
Specifically, it may be determined whether a synchronization time corresponding to the identifier of the target data exists in the second recording information, and if the synchronization time exists, the operation of determining whether the synchronization time is later than the writing time point is performed. The implementation manner of determining whether the synchronization time corresponding to the identifier of the target data exists in the second record information may be to determine whether the synchronization time corresponding to the identifier of the target data exists in the second record information within a predetermined time period, where the implementation manner of the predetermined time period may refer to the foregoing example.
As another embodiment, considering that the manner of recording the write operation of the master room and the data synchronization operation of the slave room may be the above-mentioned log file, that is, the write operation of the master room and the data synchronization operation of the slave room are recorded in a log pipelining manner, a sequence number may be set for each of the master room and the slave room, and each write operation of the master room and each data synchronization operation of the slave room are recorded by the sequence number.
Specifically, the first record information is a first serial number, and the first serial number is used to perform an update operation according to a first update rule when the host computer room is successfully written with the target data, specifically, a first serial number may be predefined, and an initial value of the first serial number is a first initial value, and then the value of the first serial number is updated according to the first update rule each time the host computer room is written with data, where the first update rule may be to increase or decrease a certain value, that is, to increase or decrease a certain value on the basis of the first serial number stored last time during each write operation.
For example, the initial value of the first serial number is a first initial value, the first update rule is to increase a first value, when data is written in the host 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 data is written again, the value of the first serial number becomes the sum of the first initial value and 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 present application, it is assumed that the first serial number is seq1, the initial value is 0, the numerical value of the first serial number seq1 becomes 1 after the first data writing, the numerical value of the first serial number seq1 becomes 2 after the second data writing, and so on, if the data to be written includes a plurality of data, which are data1, data2, data3, data4, data5, and data6, respectively, and the corresponding relationship between the data identifier and the numerical value of the serial number seq1 is: sequence numbers seq1 corresponding to data1, data2, data3, data4, data5 and data6 are 1, 2, 3, 4, 5 and 6 in sequence.
Therefore, the writing sequence of each piece of written data and the serial number corresponding to the identifier of each piece of written data can be obtained through the correspondence, and the serial number can be used as the serial number of the written data, so that the target data can be recorded in the whole writing operation process, and the target data is written in the second place.
Similarly, the second record information is a second serial number, and the second serial number is used for executing an update operation according to a second update 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 increased by a second value. Specifically, the initial value of the second serial number is a second initial value, the second update rule is to increase a second numerical value, when the data is synchronized for the first time in the slave computer room, the numerical value of the second serial number becomes the sum of the second initial value and the second numerical value, and after the data is synchronized again, the numerical value of the second serial number becomes the sum of the second initial value and the two second numerical values, that is, the second numerical value is increased on the basis of the second serial number stored last time. The first and second values are the same, for example, both are 1, and the first and second initial values may be the same, for example, both may be 0.
Assuming that the second sequence number is seq2, the initial value is 0, after the first time of the machine room synchronization data, the value of the second sequence number seq2 becomes 1, after the second time of the synchronization data, the value of the second sequence number seq2 becomes 2, and so on, if the synchronized data includes a plurality of data, the plurality of data are data1, data2, data3, data4, data5 and data6, respectively, and the corresponding relationship between the data identifier and the value of the sequence number seq2 is: sequence numbers seq2 corresponding to data1, data2, data3, data4, data5 and data6 are 1, 2, 3, 4, 5 and 6 in sequence.
It should be noted that, if the slave seq2 is the slave which has changed the data of seq2 when the slave is successfully synchronized with the data, it can be determined whether the slave successfully synchronizes the target data by determining the size relationship between the current seq2 and the seq1 corresponding to the target data written by the master.
Therefore, whether to successfully synchronize the data to the specified machine room may be determined according to a size relationship between the first serial number and the second serial number, and specifically, an embodiment of determining whether to successfully synchronize the data to the specified machine room according to the first record information and the second record information may be: acquiring the size relationship between the first serial number and the second serial number; if the size relationship meets a specified condition, determining that the data is successfully synchronized to the specified machine room, wherein the size relationship meets the specified condition, which indicates that the specified machine room successfully synchronizes the target data after the target data is written into the host machine room; and if the size relation does not meet the specified condition, judging that the data is not successfully synchronized to the specified 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 that can represent 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 also be obtained, if the ratio is greater than 1, it indicates that the first sequence number is greater than the second sequence number, and if the ratio is not greater than 1, it indicates that the first sequence number is less than or equal to the second sequence number.
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 the initial value, the size relationship may be whether the first sequence number is smaller than or equal to the second sequence number. If the first update rule and the second update rule are the same and both subtract the same value from the initial value, the magnitude relationship may be whether the first sequence number is greater than or equal to the second sequence number. If the first update rule is different from the second update rule, and the change value corresponding to the first update rule is k times of the change value corresponding to the second update rule, the magnitude relationship may be whether the ratio of the second sequence number to the first sequence number is a positive integer multiple of k.
After the size relationship between the first serial number and the second serial number is obtained, whether the size relationship meets a specified condition is judged.
Wherein the size relationship meeting a specified condition indicates that the specified machine room successfully synchronizes the target data after the target data is written in the host machine room.
If the first update rule and the second update rule are the same or different, the magnitude relationship is different, and the corresponding specification conditions are different.
For example, if the first update rule and the second update rule are the same and both add the same value on the basis of the initial value, the size relationship may be whether the first sequence number is smaller than or equal to the second sequence number, and if the first sequence number is smaller than or equal to the second sequence number, it is determined that the size relationship satisfies the specified condition, otherwise, it is determined that the size relationship does not satisfy the specified condition.
If the first update rule and the second update rule are the same and the same value is subtracted from the initial value, the magnitude relationship may be whether the first sequence number is greater than or equal to the second sequence number, and if the first sequence number is greater than or equal to the second sequence number, the magnitude relationship is determined to satisfy the specified condition, otherwise, the magnitude relationship is determined not to satisfy the specified condition.
If the first update rule and the second update rule are different, and the variation value corresponding to the first update rule is k times of the variation value corresponding to the second update rule, the magnitude relationship may be whether the ratio of the second sequence number to the first sequence number is a positive integer multiple of k, if the ratio of the second sequence number to the first sequence number is a positive integer multiple of k, it is determined that the magnitude relationship satisfies the specified condition, otherwise, it is determined that the magnitude relationship does not satisfy the specified condition.
In the embodiment of the present application, the first update rule and the second update rule may be the same, and both are the same value added based on the initial value, and the size relationship satisfying the specified condition means if the first sequence number is less than or equal to the second sequence number.
As an embodiment, the first sequence number is being changed according to a first update rule, the second sequence number is being changed according to a second update rule, when the master room completes the write operation of the target data, the first value after the first sequence number is updated by the first update rule is a first value, and when the slave machine completes the synchronization operation of the target data, the second value after the second update rule is an second value, and the magnitude relationship between the first value and the second value should satisfy the relationship between the first update rule and the second update rule, for example, if the first update rule and the second update rule are the same, the magnitude relationship between the first value and the second value should be the same. If the first update rule is to increase or decrease the value a, and the second update rule is to increase the value b, the ratio of the value a to the value b is c, and the magnitude relationship between the first value and the second value should also satisfy that the ratio of the value a to the value b is n times of c, where n is a positive integer.
If the first update rule and the second update rule are the same, both the first sequence number and the second sequence number are increased by 1, and the initial value of the first sequence number is the same as the initial value of the second sequence number, and each time a write operation is executed, the first sequence number of the master room and the second sequence number of the slave are initialized, that is, restored to the initial values, and then, in the case that the written data is one, that is, the target data is one data, after the master room writes the target data, the first sequence number should be 1, and after the slave successfully synchronizes the target data, the second sequence number should be 1, that is, the first sequence number and the second sequence number are the same.
In addition, considering that when the number of data written in the master room is multiple, the data synchronization operation of the master room and the master room detecting whether the target data is successfully synchronized to the designated room are being synchronized, there may be a case where the master room determines whether the data1 is successfully synchronized by the slave, the slave has successfully synchronized to the data3, and the data3 is data written after the data1, at this time, the second sequence number of the slave is greater than the first sequence number, and therefore, if the second sequence number is greater than the first sequence number, it can be stated that the data corresponding to the first sequence number has been successfully synchronized to the slave.
The writing order of the data written in the master room may be the same as the synchronization order of synchronizing the written data to the slave, for example, the writing order of the data written in the master room is data1, data2, data3, data4, data5 and data6, and the synchronization order of synchronizing the written data to the slave is data1, data2, data3, data4, data5 and data 6.
Therefore, a first sequence number corresponding to target data written by the master room is obtained, the size of a current second sequence number of the slave is obtained, and if the first sequence number is smaller than or equal to the second sequence number, the slave successfully synchronizes the target data after the target data is written by the master room.
For example, the data written in the master room includes data1, data2, data3, data4, data5 and data6, and when data1, data2, data3, data4, data5 and data6 are successfully written in the master room, where data2 is target data, referring to table 1, the first serial number corresponding to the target data is seq1 equal to 2, the master room synchronizes data1, data2, data3, data4, data5 and data6 to the slave in sequence, when seq2 of the slave is 1, the data indicating that the slave is successfully synchronized is data1, and when the first serial number is greater than the second serial number, it may be determined that the target data is not successfully synchronized to the designated room.
If the seq2 of the slave is 2 at this time, the data indicating that the slave successfully synchronizes is data2, that is, the data successfully synchronized by the slave is target data, and the first sequence number is equal to the second sequence number, it may be determined that the target data is not successfully synchronized to the designated machine room.
If the seq2 of the slave machine at this time is 3, the data indicating that the slave machine successfully synchronizes is data3, that is, the data successfully synchronized by the slave machine is data3 after the target data, and the first sequence number is smaller than the second sequence number, it may be determined that the target data is not successfully synchronized to the designated machine room.
Therefore, when the first sequence number is less than or equal to the second sequence number, it can be determined that the target data is successfully synchronized to the specified machine room.
In addition, when the master machine room corresponds to a plurality of slave machine rooms, each slave machine room corresponds to one second serial number, whether each slave machine room successfully synchronizes the target data can be determined through the detection mode, and therefore whether the target data are successfully synchronized to the slave machine room corresponding to the master machine room is determined.
In some embodiments, the operation of detecting whether the target data is successfully synchronized to the slave machine room corresponding to the master machine room may be named as a scanning operation, and if the first sequence number is greater than the second sequence number, that is, when it is determined that the target data is not successfully synchronized to the slave machine room corresponding to the master machine room, the scanning operation may be continued after a certain period of time, that is, the scanning operation is suspended in the period of time, so that the slave machine room can complete the synchronization operation of the target data within the time.
Specifically, if the size relationship does not satisfy the specified condition, after it is determined that the data is not successfully synchronized to the specified machine room, the method further includes: and after a specified time span, obtaining 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 to the specified computer room is continuously executed within the specified time span. The specified time length may be a preset 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 10 ms.
S550: and taking the slave machine rooms except the appointed machine room in the slave machine rooms as new appointed machine rooms.
After it is determined that the master room synchronizes all the written data to the designated machine room in the above manner, one slave machine room is reselected from the slave machine rooms other than the designated machine room to serve as a new designated machine room, and the step S530 is executed again until all the slave machine rooms are synchronized.
Therefore, the Redis clusters which are independent of each other can be deployed in the multiple machine rooms, the read-write operations of all the machine rooms can be synchronized to other machine rooms, and the clusters of all the machine rooms are mirror images. When part of the computer rooms have faults (including software, hardware and network faults), the service layer can dispatch the read-write request to other normal computer rooms to continue to operate, so that cross-computer-room disaster tolerance is realized, and high availability of service and data safety are guaranteed.
In addition, as shown in fig. 7, the client may include a scanning process and a subscription process. The scanning process is used for executing the operation of judging whether the data are successfully synchronized to the specified machine room, the subscription process is used for monitoring the writing operation of the host machine room and the slave machine room, and when the writing operation is detected, the target data are obtained according to the writing operation.
The data synchronization is carried out through an external program, the service layer is not sensed, the use is simple, namely, the data synchronization is realized through the client, and therefore, cross-machine-room reading and writing do not exist, and the service performance is not influenced. The method supports simultaneous reading and writing of multiple places, supports data synchronization among any number of clusters, can deploy multiple places according to conditions, and is high in expandability. And the final consistency of data when multiple simultaneous writing is carried out is ensured through a master-slave computer room mechanism.
Referring to fig. 8, a block diagram of a data synchronization apparatus 800 according to an embodiment of the present application is shown, where the apparatus may include: an acquisition unit 801, a writing unit 802, and a synchronization unit 803.
An obtaining unit 801, configured to obtain target data requested to be written in the data storage system.
A writing unit 802, configured to write the target data into the main computer room.
A synchronization unit 803, configured to synchronize the target data to the slave machine room after the target data is successfully written into the master machine room.
It can be clearly understood by those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described apparatuses and modules may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
Referring to fig. 9, a block diagram of a data synchronization apparatus 900 according to an embodiment of the present application is shown, where the apparatus may include: an acquisition 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 comprises a monitoring sub-unit 911 and a data determination sub-unit 912.
The monitoring subunit 911 is configured to monitor write operations of the master computer room and the slave computer room.
The data determining 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, if there are multiple write operations, obtain a timestamp corresponding to each write operation, where each write operation corresponds to specified data and is used to modify content to be modified into the specified data; determining a target write operation from within a plurality of the write operations according to the timestamp; and taking the designated data corresponding to the target write operation as target data.
Further, the data determining sub-unit 912 is further configured to determine, if the timestamps are not all the same, a latest timestamp of all the timestamps as the target timestamp; taking the write operation corresponding to the target timestamp as a write operation to be selected; and determining a target write operation from the candidate write operations.
Further, the data determining subunit 912 is further configured to take the candidate write operation as a target write operation if the number of the candidate write operations is 1.
Further, the data determining subunit 912 is further configured to determine, if the number of the to-be-selected write operations is at least two, an operation object corresponding to each to-be-selected write operation, where the operation object includes a master room or a slave room; and taking the to-be-selected write operation with the operation object as the main computer 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 to-be-selected write operation, where the operation object includes a master room or a slave room;
and taking the to-be-selected write operation with the operation object as the main computer room as a target write operation.
A writing unit 920, configured to write the target data into the main computer room.
A synchronizing unit 930, configured to synchronize the target data to the slave machine room after the target data is successfully written into the master machine room.
Wherein, the master computer room and the slave computer rooms are both corresponding to message queues, the master computer room subscribes the message queues of all the slave computer rooms, each slave computer room subscribes the message queue of the master computer room, and after the target data is successfully written into the master computer room, the target data is synchronized to the slave computer rooms, including: and after the target data are successfully written into the master computer room, synchronizing the target data to the slave computer room through a message queue corresponding to the master computer room.
It can be clearly understood by those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described apparatuses and modules may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
Referring to fig. 10, a block diagram of a data synchronization apparatus 1000 according to an embodiment of the present application is shown, where the apparatus may include: an acquisition 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.
A writing unit 1020, configured to write the target data into the main computer room.
A synchronizing unit 1030, configured to synchronize the target data to the slave machine room after the target data is successfully written into the master machine room.
The synchronization unit 1030 includes a selection subunit 1031, a judgment subunit 1032, and a synchronization subunit 1033.
The selecting subunit 1031 is configured to, after the target data is successfully written into the master room, synchronize the target data to a designated machine room, where the designated machine room is one of the plurality of slave machine rooms.
The judgment subunit 1032 is configured to judge whether to synchronize the data to the specified machine room successfully.
In some embodiments, the determining subunit 1032 is further configured to detect whether the information of successful synchronization fed back by the specified machine room is received; if so, judging that the data is successfully synchronized to the specified machine room; and if not, judging that the data is not successfully synchronized to the specified machine room.
In other embodiments, the determining subunit 1032 is further configured to obtain first recording information corresponding to the host computer room, where the first recording information is used to record an operation of writing target data that is executed by the host computer room; acquiring second recording information corresponding to the specified machine room, wherein the second recording information is used for recording data synchronization operation of target data executed by the specified machine room; and judging whether the data are successfully synchronized to the specified machine room or not 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 recording information is earlier than the second operation time point in the second recording information; if so, judging that the data are successfully synchronized to the specified machine room; if not, it is determined that the data is not successfully synchronized to the designated machine room.
The first record information is a first serial number, and the first serial number is used for executing an updating operation according to a first updating rule when the host computer room is successfully written with target data; and 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.
Further, the determining subunit 1032 is further configured to obtain a size relationship between the first sequence number and the second sequence number; if the size relationship meets a specified condition, determining that the data is successfully synchronized to the specified machine room, wherein the size relationship meets the specified condition, which indicates that the specified machine room successfully synchronizes the target data after the target data is written into the host machine room; and if the size relation does not meet the specified condition, judging that the data is not successfully synchronized to the specified machine room.
The first update rule is to increase or decrease the first serial number by a first value when the host computer room is successfully written with target data, the second update rule is to increase or decrease the second serial number by a second value when the specified computer room is successfully synchronized with data, and the first value is the same as the second value.
The size relationship meeting a specified condition means that the first sequence number is less than or equal to the second sequence number.
Further, the determining subunit 1032 is further configured to, after a specified time length, obtain again the size relationship between the first sequence number and the second sequence number and perform subsequent operations, where the operation of synchronizing the target data to the specified machine room is continuously performed within the specified time length.
The synchronization subunit 1033 is configured to, if the data is successfully synchronized to the designated machine room, take the slave machine rooms, other than the designated machine room, in the slave machine room as new designated machine rooms, and return to execute synchronization of the target data to the designated machine room until the target data synchronization operation of all the slave machine rooms is completed.
It can be clearly understood by those skilled in the art that, for convenience and simplicity of description, the specific working processes of the above-described devices and modules may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the several embodiments provided in the present application, the coupling between the modules may be electrical, mechanical or other coupling.
In addition, functional modules in the embodiments of the present application may be integrated into one processing module, or each module may exist alone physically, or two or more modules are integrated into one module. The integrated module can be realized in a hardware mode, and can also be realized in a software functional module mode.
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 other electronic devices capable of running an application. The electronic device 100 in the present application may include one or more of the following components: a processor 110, a memory 120, and one or more applications, wherein the one or more applications may be stored in the memory 120 and configured to be executed by the one or more processors 110, the one or more programs configured to perform a method as described in the aforementioned method embodiments.
Processor 110 may include one or more processing cores. The processor 110 connects various parts within the overall electronic device 100 using various interfaces and lines, and performs various functions of the electronic device 100 and processes data by executing or executing instructions, programs, code sets, or instruction sets stored in the memory 120 and calling data stored in the memory 120. Alternatively, the processor 110 may be implemented in hardware using at least one of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), and Programmable Logic Array (PLA). The processor 110 may integrate one or a combination of a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), a modem, and the like. 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 content; the modem is used to handle wireless communications. It is understood that the modem may not be integrated into the processor 110, but may be implemented by a communication chip.
The Memory 120 may include a Random Access Memory (RAM) or a Read-Only Memory (Read-Only Memory). The 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 various method embodiments described below, and the like. The storage data area may also store data created by the terminal 100 in use, such as a phonebook, audio-video data, chat log data, and the like.
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 a program code which can be called by a processor to execute the method described in the above method embodiments.
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. Alternatively, the computer-readable storage medium 1200 includes a non-volatile computer-readable storage medium. The computer readable storage medium 1200 has storage space for program code 1210 that performs any of the method steps described above. The program code can be read from and written to one or more computer program products. The program code 1210 may be compressed, for example, in a suitable form.
Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present application, and not to limit the same; although the present application has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; such modifications and substitutions do not necessarily depart from the spirit and scope of the corresponding technical solutions in the embodiments of the present application.

Claims (20)

  1. A data synchronization method is applied to a master room of a data storage system, the data storage system further comprises a slave room corresponding to the master room, and the method comprises the following steps:
    acquiring target data requested to be written into the data storage system;
    writing the target data into the main computer room;
    after the target data is successfully written into the master computer room, synchronizing the target data to the slave computer room.
  2. The method of claim 1, wherein the obtaining target data for writing to the data storage system comprises:
    monitoring the writing operation of the master computer room and the slave computer room;
    and when the write operation is detected, obtaining the target data according to the write operation.
  3. The method of claim 2, wherein obtaining target data according to the write operation when the write operation is detected comprises:
    if the number of the write-in operations is multiple, acquiring a timestamp corresponding to each write-in operation, wherein each write-in operation corresponds to designated data and is used for modifying the content to be modified into the designated data;
    determining a target write operation from within a plurality of the write operations according to the timestamp;
    and taking the designated data corresponding to the target write operation as target data.
  4. The method of claim 3, wherein the determining from the timestamp as a target write operation within the plurality of write operations comprises:
    if the timestamps are not all the same, determining the latest timestamp in all the timestamps as a target timestamp;
    taking the write operation corresponding to the target timestamp as a write operation to be selected;
    and determining a target write operation from the candidate write operations.
  5. The method of claim 4, wherein the determining a target write operation from within the candidate write operations comprises:
    and if the number of the write operations to be selected is 1, taking the write operations to be selected as target write operations.
  6. The method of claim 4, wherein the determining a target write operation from within the candidate write operations comprises:
    if the number of the write-in operations to be selected is at least two, determining an operation object corresponding to each write-in operation to be selected, wherein the operation object comprises a master computer room or a slave computer room;
    and taking the to-be-selected write operation of which the operation object is the main computer room as a target write operation.
  7. The method of claim 3, further comprising:
    if the timestamps are all the same, determining an operation object corresponding to each write operation to be selected, wherein the operation object comprises a master computer room or a slave computer room;
    and taking the to-be-selected write operation of which the operation object is the main computer room as a target write operation.
  8. The method of claim 1, wherein the slave machine room is multiple, and wherein synchronizing the target data to the slave machine room after successfully writing the target data to the master machine room comprises:
    after the target data are 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;
    judging whether the data are successfully synchronized to the specified machine room or not;
    and if the data are successfully synchronized to the appointed machine room, taking the slave machine rooms in the slave machine room and the slave machine rooms outside the appointed machine room as new appointed machine rooms, and returning to execute the target data synchronization to the appointed machine room until the target data synchronization operation of all the slave machine rooms is completed.
  9. The method of claim 8, wherein the determining whether the data was successfully synchronized to the designated room comprises:
    detecting whether the information of successful synchronization fed back by the specified machine room is received;
    if so, judging that the data is successfully synchronized to the specified machine room;
    and if not, judging that the data is not successfully synchronized to the specified machine room.
  10. The method of claim 8, wherein the determining whether the data was successfully synchronized to the designated room comprises:
    acquiring first recording information corresponding to the host computer room, wherein the first recording information is used for recording the operation of written target data executed by the host computer room;
    acquiring second recording information corresponding to the specified machine room, wherein the second recording information is used for recording data synchronization operation of target data executed by the specified machine room;
    and judging whether the data are successfully synchronized to the appointed machine room or not according to the first record information and the second record information.
  11. The method according to claim 10, wherein the recording information is used to record an operation time point of an operation; the determining whether to successfully synchronize the data to the designated machine room according to the first record information and the second record information includes:
    judging whether a first operation time point in the first recording information is earlier than a second operation time point in the second recording information;
    if so, judging that the data are successfully synchronized to the specified machine room;
    and if not, judging that the data is not successfully synchronized to the specified machine room.
  12. The method according to claim 10, wherein the first record information is a first sequence number, and the first sequence number is used for performing an update operation according to a first update 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 an updating operation according to a second updating rule when the specified machine room successfully synchronizes data.
  13. The method of claim 10, wherein the determining whether to successfully synchronize data to the designated room according to the first log information and the second log information comprises:
    acquiring the size relationship between the first serial number and the second serial number;
    if the size relationship meets a specified condition, determining that the data are successfully synchronized to the specified machine room, wherein the size relationship meets the specified condition, which indicates that the specified machine room successfully synchronizes the target data after the target data are written into the host machine room;
    and if the size relation does not meet the specified condition, judging that the data is not successfully synchronized to the specified machine room.
  14. The method of claim 13, 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, and wherein the first value and the second value are the same.
  15. The method of claim 14, wherein the size relationship satisfying a specified condition means that the first sequence number is less than or equal to the second sequence number.
  16. The method of claim 13, wherein determining that the data is not successfully synchronized to the specified room if the size relationship does not satisfy a specified condition further comprises:
    and after a specified time length, obtaining the size relationship between the first sequence number and the second sequence number again and executing subsequent operations, wherein the operation of synchronizing the target data with the specified computer room is continuously executed within the specified time length.
  17. The method according to any one of claims 1 to 16, wherein the master room and the slave rooms each have a message queue, the master room subscribes to the message queues of all the slave rooms, each slave room subscribes to the message queue of the master room, and the synchronizing the target data to the slave room after the target data is successfully written into the master room comprises:
    and after the target data are successfully written into the master computer room, synchronizing the target data to the slave computer room through a message queue corresponding to the master computer room.
  18. A data synchronization apparatus applied to a master room of a data storage system, the data storage system further including a slave room corresponding to the master room, the apparatus comprising:
    an acquisition unit configured to acquire target data requested to be written in the data storage system;
    the writing unit is used for writing the target data into the main computer 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.
  19. A data storage system, comprising:
    the system comprises a main machine room and a slave machine room corresponding to the main machine room;
    the host is configured to perform the method of any of claims 1-17. .
  20. A computer-readable medium having stored program code executable by a processor, the program code causing the processor to perform the method of any one of claims 1-17 when executed by the processor.
CN202080094721.7A 2020-04-24 2020-04-24 Data synchronization method, data synchronization device, data storage system and computer readable medium Pending CN115004662A (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 (1)

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

Family

ID=78270983

Family Applications (1)

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

Country Status (2)

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

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
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 equipment

Citations (4)

* 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
CN104980519A (en) * 2015-06-29 2015-10-14 北京奇虎科技有限公司 Multi-computer room storage system
CN108055343A (en) * 2017-12-26 2018-05-18 北京奇虎科技有限公司 For the method for data synchronization and device of computer room
CN110673941A (en) * 2019-09-27 2020-01-10 掌阅科技股份有限公司 Migration method of micro-services in multiple computer rooms, electronic equipment and storage medium

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
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 (4)

* 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
CN104980519A (en) * 2015-06-29 2015-10-14 北京奇虎科技有限公司 Multi-computer room storage system
CN108055343A (en) * 2017-12-26 2018-05-18 北京奇虎科技有限公司 For the method for data synchronization and device of computer room
CN110673941A (en) * 2019-09-27 2020-01-10 掌阅科技股份有限公司 Migration method of micro-services in multiple computer rooms, electronic equipment and storage medium

Also Published As

Publication number Publication date
WO2021212493A1 (en) 2021-10-28

Similar Documents

Publication Publication Date Title
US11698885B2 (en) System and method for content synchronization
US11221995B2 (en) Data replication from a cloud-based storage resource
JP6273927B2 (en) Information processing system, monitoring device, monitoring program, and monitoring method
US20150213100A1 (en) Data synchronization method and system
CN105468718B (en) Data consistency processing method, device and system
CN106874281B (en) Method and device for realizing database read-write separation
JP5686034B2 (en) Cluster system, synchronization control method, server device, and synchronization control program
US20160261459A1 (en) Package dependency maps for distributed computing
CN103067485A (en) Disk monitoring method for cloud storage system
CN111399764B (en) Data storage method, data reading device, data storage equipment and data storage medium
CN115599747B (en) Metadata synchronization method, system and equipment of distributed storage system
CN113094430B (en) Data processing method, device, equipment and storage medium
CN111049928A (en) Data synchronization method, system, electronic device and computer readable storage medium
CN115004662A (en) Data synchronization method, data synchronization device, data storage system and computer readable medium
CN109600430A (en) A kind of data managing method, system and electronic equipment and storage medium
CN112000850B (en) Method, device, system and equipment for processing data
CN110798358B (en) Distributed service identification method and device, computer readable medium and electronic equipment
CN115104295A (en) Data processing method, data processing device, electronic device and storage medium
CN116049306A (en) Data synchronization method, device, electronic equipment and readable storage medium
CN114981796A (en) Data synchronization method, data synchronization device, data storage system and computer readable medium
US20210306239A1 (en) Determining Operational Status of Internet of Things Devices
CN116737764A (en) Method and device for data synchronization, electronic equipment and storage medium
US20170091253A1 (en) Interrupted synchronization detection and recovery
CN111147226B (en) Data storage method, device and storage medium
CN112559568A (en) Virtual article determination method and device and computer readable 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