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

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

Info

Publication number
WO2021212493A1
WO2021212493A1 PCT/CN2020/086773 CN2020086773W WO2021212493A1 WO 2021212493 A1 WO2021212493 A1 WO 2021212493A1 CN 2020086773 W CN2020086773 W CN 2020086773W WO 2021212493 A1 WO2021212493 A1 WO 2021212493A1
Authority
WO
WIPO (PCT)
Prior art keywords
data
room
host
computer room
target data
Prior art date
Application number
PCT/CN2020/086773
Other languages
French (fr)
Chinese (zh)
Inventor
汤见乐
Original Assignee
深圳市欢太科技有限公司
Oppo广东移动通信有限公司
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 深圳市欢太科技有限公司, Oppo广东移动通信有限公司 filed Critical 深圳市欢太科技有限公司
Priority to CN202080094721.7A priority Critical patent/CN115004662A/en
Priority to PCT/CN2020/086773 priority patent/WO2021212493A1/en
Publication of WO2021212493A1 publication Critical patent/WO2021212493A1/en

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

Definitions

  • This application relates to the field of computer technology, and more specifically, to a data synchronization method, device, data storage system, and computer readable medium.
  • This application proposes a data synchronization method, device, data storage system, and computer readable medium to improve the above-mentioned defects.
  • an embodiment of the present application also provides a data synchronization device, which is applied to a host room of a data storage system, and the data storage system further includes a slave computer room corresponding to the host room.
  • the device includes: an acquisition unit, a writing unit, and a synchronization unit.
  • the obtaining unit is configured to obtain the target data requested to be written into the data storage system.
  • the writing unit is used to write the target data into the host room.
  • the synchronization unit is configured to synchronize the target data to the slave computer room after successfully writing the target data into the host room.
  • the embodiments of the present application also provide a computer-readable medium, the readable storage medium storing a program code executable by a processor, and when the program code is executed by the processor, the processor Perform the above method.
  • the data synchronization method, device, data storage system and computer readable medium provided in this application will be used when the data storage system is requested to write target data, that is, whether it is requested to write data in the host room of the system or from the computer room.
  • the target data is written into the host room first, and then, after the target data is successfully written into the host room, the target data is synchronized to the slave computer room. Therefore, not only can it avoid that when the target data is written into multiple computer rooms at the same time, if the data in a certain computer room is written incorrectly, it will cause the data in each computer room to be inconsistent.
  • the data is subject to the synchronization of the data written in the host room to the slave room, which can better maintain data consistency.
  • Figure 1 shows a schematic diagram of a data storage system provided by an embodiment of the present application
  • FIG. 2 shows a method flowchart of a data synchronization method provided by an embodiment of the present application
  • FIG. 3 shows a method flowchart of a data synchronization method provided by another embodiment of the present application
  • FIG. 5 shows a method flowchart of a data synchronization method provided by another embodiment of the present application.
  • FIG. 6 shows a flowchart of the method S540 in FIG. 5 provided by an embodiment of the present application
  • FIG. 7 shows a schematic diagram of a client in a data storage system provided by an embodiment of the present application.
  • FIG. 8 shows a block diagram of a data synchronization device provided by another embodiment of the present application.
  • FIG. 9 shows a block diagram of a data synchronization device provided by 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 for storing or carrying program code for implementing the data synchronization method according to the embodiment of the present application according to an embodiment of the present application.
  • In-memory databases refer to databases that put data in memory and operate directly, and are generally deployed in a cluster. Such clusters are called in-memory database clusters.
  • An in-memory database cluster includes an in-memory database master and an in-memory database slave, and data needs to be synchronized between the two. Further, synchronization is divided into full synchronization and incremental synchronization.
  • Full synchronization means that the in-memory database slave synchronizes all the data of the in-memory database host at one time.
  • Incremental synchronization means that the in-memory database slave only synchronizes it with the in-memory database host. Synchronize the different parts of the data.
  • Redis is a high-performance open source database that can be based on memory. It is written in ANSIC language and provides programming interfaces in multiple languages. It is often used to implement functions such as software or application data storage and fast access; in a production environment, redis applications It is very extensive. For example, in order to ensure the stability of the service while expanding the business, the redis cluster that supports distributed high availability and horizontal expansion is often used for data storage and access. In order to improve the stability of the system, the redis system usually adopts the master-slave structure. In the initialization phase of the redis slave node and when the master node is writing new data, it is necessary to copy the data on the redis master node for backup. This event is called redis master-slave data synchronization.
  • FIG. 1 shows a schematic diagram of a data storage system.
  • the data storage system includes multiple computer rooms.
  • the multiple computer rooms include a computer room 1, a computer room 2 and a computer room 3.
  • Each computer room includes a host computer and at least one slave computer corresponding to the host computer.
  • the computer room 1 includes a host 10 and a slave 11 and a slave 12 corresponding to the host.
  • the host 10 and the slave 11 and the slave 12 are in a master-slave relationship.
  • the host is also called the master node (master), which provides external services.
  • the slave is also called the slave.
  • the slave replicates the data of the Master node in real time to ensure that it is consistent with the Master node.
  • the slave machine cannot be performed by other devices to perform data writing operations.
  • the data in the slave machine is synchronized by the master to the slave machine through data synchronization.
  • the computer room 2 includes a host 20 and slaves 21 and 22 corresponding to the host
  • the computer room 3 includes a host 30 and slaves 31 and 32 corresponding to the host.
  • the data storage system formed by each computer room can provide data storage services for the business layer, that is, the data generated by the business layer can be stored in the data storage system, and data can also be read from the data storage system.
  • the business layer can write data into the data storage system.
  • the way of writing can be to write the data into any computer room in the data storage system. Specifically, it can be to write data into the data storage system. In the host computer of any computer room, in order to ensure the consistency of the data, the written data needs to be written in each computer room.
  • multiple computer rooms in the data storage system are divided into a host room and a slave computer room, that is, among multiple computer rooms in the data storage system, one computer room is designated as the host room,
  • the other computer rooms are the slave computer rooms corresponding to the host room.
  • the embodiment of the present application provides a data synchronization method, which is applied to the above-mentioned data storage system.
  • each computer room in the data storage system is provided with a client corresponding to the data synchronization method. Write to a certain computer room, and execute the embodiment of the method described in this application.
  • the client may be installed in a host in each computer room, or may be installed in a terminal independent of the host in each computer room. In the embodiment of the present application, the client is installed in the host.
  • FIG. 2 shows a data synchronization method.
  • the execution subject of the method may be the above-mentioned host room. Specifically, the execution subject may be a client in the host room. Specifically, the method includes: S201 to S203.
  • the data storage system may obtain a data write request, and the data write request is used to write the target data into the data storage system.
  • the business layer may send a data write request to the data storage system.
  • the data writing request may include a label designating the computer room requested to be written, and the label is used as the identity information of the computer room. Then in this embodiment, the business layer requests to write the target data into the computer room corresponding to the designated label. In other embodiments, the data write request may not include a label designating the computer room where the write is requested.
  • the host room can monitor and write data in each computer room (including the host room and the slave room corresponding to the host room), so that the host room can obtain the target data requested to be written into the data storage system.
  • both the master room and the slave computer room have message queues, the master room subscribes to the message queues of all the slave computer rooms, and each of the slave computer rooms subscribes to the message queue of the master room.
  • Communication between each computer room and between application programs such as the business layer and each computer room is through a message queue.
  • the message queue is an application-to-application communication method.
  • Application programs communicate by writing and retrieving application-specific data (messages) in and out of the queue.
  • the business layer when the business layer requests to write target data to a certain computer room, it will send a data write request to the message queue of the computer room.
  • the computer room is a slave computer room, because the master room subscribes to the message queue of the slave computer room, the host The room can monitor the operation of the slave computer room on the message queue, so that when a data writing request is written into the message queue, it can be monitored by the host room, and then the target data requested to be written into the data storage system can be obtained.
  • the target data is written into the host room.
  • the host room includes a host computer and a slave device corresponding to the host computer.
  • the implementation manner of writing the target data into the host computer room may be to write the target data into the host computer, and then by The master synchronizes the target data to the slave corresponding to the master.
  • the aforementioned computer room 1 is a host room and the target data is data data.
  • the host 10 will synchronize the data to the slave 11 and the slave 12 corresponding to the host.
  • the multiple data are data1, data2, data3, data4, data5, and data6 respectively, that is, the writing order of the multiple data is data1, data2, data3, data4, data5, and data6 .
  • the multiple data are recorded in the log file, and the order of the log recording is also data1, data2, data3, data4, data5, and data6.
  • data1, data2, data3, data4, data5, and data6 can be the multiple
  • the identification of the data can also record the writing time of each written data in the log record.
  • both the master and the slave can have log files, that is, both the master and the slave can execute the log pipelining function, which is used to record the write operations of the master and the slave.
  • the write operation for the slave can be understood as a master pair The data synchronization operation of the slave.
  • the target data written by the host can be obtained, where the target data can be a collection of multiple data continuously written, or multiple data continuously written One of the data in.
  • the target data is synchronized to the slave computer room.
  • the target data is stored in the storage space corresponding to the host room, and then the data synchronization operation is performed.
  • the above-mentioned client may send the target data written in the host room to the host
  • the slave room corresponding to the room allows the data stored in the slave room to be updated.
  • the target data is synchronized from the storage space corresponding to the computer room.
  • the target data is successfully synchronized to the slave corresponding to the master, it can be determined that the target data written to the master has been successfully synchronized to the slave corresponding to the master, and then the target data can be synchronized to the slave at this time. From the computer room.
  • the host 10 in the computer room 1 writes target data, and the host 10 synchronizes the target data to the slave 11 and the slave 12. After determining that the slave 11 and the slave 12 successfully synchronize the target data, The target data is sent to the computer room 2 and the computer room 3, and the computer room 2 and the computer room 3 execute the synchronization operation of the target data after obtaining the target data.
  • the host 10 sends target data to the host 20 in the computer room 2 and the host 30 in the computer room 3.
  • the host 20 writes the target data, and synchronizes the target data to the slave 21 and the slave 22 corresponding to the host 20.
  • the host 30 is written with target data, and the target data is synchronized to the slave 31 and the slave 32 corresponding to the host 20.
  • the target data when the data storage system is requested to write target data, that is, whether it is requested to write data in the host room of the system or from the computer room, the target data will be written to the host room first, and then, after the target is successfully written After the data is written into the host room, the target data is synchronized to the slave computer room. Therefore, not only can it avoid that when the target data is written into multiple computer rooms at the same time, if the data in a certain computer room is written incorrectly, it will cause the data in each computer room to be inconsistent.
  • the data is subject to the synchronization of the data written in the host room to the slave room, which can better maintain data consistency.
  • the execution subject of the method may be the above-mentioned host room. Specifically, the execution subject may be a client in the host room. Specifically, the method includes: S310 to S340.
  • the client in the host in the host room can detect write operations for all computer rooms. For example, through the above message queue, the host room subscribes to the message queues of all slave rooms, and then writes in any slave room.
  • the write operation from the computer room can be monitored, and when the host room itself is writing data, the write operation will also be written to the message queue of the host room, thus subscribing to the message of the host room.
  • the corresponding slave computer room can also know that data is written in the host room, and any computer room in the data storage system can be regarded as a write operation to the data storage system.
  • the write operation can specify the data requested to be written.
  • the write operation can be a data packet that includes the data requested to be written.
  • the host room can analyze the data when the write operation is monitored.
  • the write operation obtains the data requested to be written.
  • the data requested to be written may be used as the target data.
  • the content to be modified may be certain designated data stored in the computer room, and when the write operation is performed, the designated data is modified to the data requested to be written. If the write operation is newly added data, the content to be modified is the storage space in the computer room, and when the write operation is performed, the data requested to be written is written in the storage space.
  • the identifier of the designated data is obtained, and a write operation with the same identifier of the designated data is regarded as a write operation with the same modification purpose.
  • each write operation in which the content to be modified is a storage space can be used as a modification purpose write operation, or if the write operation is a newly added data, it will be The write operation configures a data identifier, and the data identifier is a newly added identifier. When data is written into the computer room, the data identifier also corresponds to the computer room.
  • the write operations are operation 1, operation 2, operation 3, operation 4, operation 5, operation 6, and operation 7.
  • the content to be modified corresponding to operation 1, operation 2, and operation 3 is data1, and operation 4 and operation 5 are used
  • the identifier of the added data is data7
  • operation 6 is used to add a piece of data
  • the identifier of the added data is data8
  • operation 7 is used to add a piece of data
  • the identifier of the added data is data9.
  • the write operations corresponding to modification goal 1 are operation 1, operation 2, and operation. 3.
  • the write operations corresponding to modification purpose 2 are operations 4 and 5, the write operation corresponding to modification purpose 3 is operation 6, and the write operation corresponding to modification purpose 4 is operation 7.
  • the write operation corresponding to each modification purpose is determined. Specifically, for the implementation of determining the write operation corresponding to each modification purpose, reference may be made to steps S321 to S323 in FIG. 4. For each modification purpose, S321 to S323 can be executed to determine the write operation corresponding to each modification purpose.
  • each of the write operations corresponds to designated data, and is used to modify the content to be modified into designated data.
  • the designated data corresponding to each write operation can be the same or different.
  • each write operation corresponds to a time stamp
  • the time stamp is used to record the time corresponding to the write operation.
  • the data storage system configures a timestamp for the write request and treats the write request as a write operation, thereby , Can configure a time stamp for the write operation.
  • S322 Determine the target write operation from among the multiple write operations according to the timestamp.
  • the timestamp can be used as the time when the specified data is requested to be written corresponding to the write operation, that is, it can be used as the write time of a different write operation.
  • the target write operation may be determined according to the order of the time stamp of each write operation. For example, select the write operation corresponding to the earliest or latest time stamp as the target write operation.
  • the timestamps corresponding to multiple write operations may be the same or may not be all the same, so for all the same and not all the same, according to the timestamp, the target write operation is determined from the multiple write operations.
  • the implementation can be different.
  • the time stamps are not all the same, and it may be that all time stamps have the same time stamp or different time stamps, that is, not all time stamps are the same. Then, all the time stamps can be sorted in chronological order to obtain a time series, and the last time stamp in the time series can be used as the target time stamp.
  • the write operation corresponding to the target timestamp is used as a write operation to be selected.
  • the latest time stamp may include multiple time stamps, that is, multiple latest time stamps can be obtained, and the write operation corresponding to each latest time stamp can be used as a write operation to be selected.
  • all the write operations may be sorted according to the time sequence of the timestamp to obtain the candidate sequence.
  • the sequence to be selected includes multiple write operation identifiers, and the write operation identifiers may be used to record the identity information of each write operation.
  • the identifier of each write operation corresponds to a serial number, and the earlier the serial number the write operation corresponds to the earlier the timestamp, that is, the write operations are sorted according to the chronological order of the timestamps, Get the candidate sequence. Then, the first write operation in the sequence to be selected is regarded as the write operation to be selected.
  • the sequence numbers corresponding to the write operations of the same time stamp are the same. Therefore, the obtained candidate write operations can be multiple, where each The timestamps corresponding to the write operations to be selected are the same, and among the timestamps corresponding to all write operations, the timestamp corresponding to each write operation to be selected is the latest timestamp.
  • the target write operation is determined from the to-be-selected write operation. If the number of the write operation to be selected is 1, then the write operation to be selected is taken as the target write operation. If the number of the write operations to be selected is at least two, an operation object corresponding to each write operation to be selected is determined, and the operation object includes a host room or a slave computer room.
  • the operation object can be the computer room designated to be written when the business layer requests to store data.
  • the data write request includes the identifier of the computer room, and when the host room and the slave computer room are preset, the computer room can be The identification of each computer room corresponds to a tag, which includes the host room tag and the slave computer room tag.
  • the tag of the computer room corresponding to the identification of the computer room is the host room tag or From the computer room tag, it can then be determined whether the computer room requested to write data is the host room or the slave computer room, that is, the operation object corresponding to each write operation can be determined.
  • the write operation to be selected in the host room as the operation object is taken as the target write operation.
  • time stamps corresponding to operation 6 and operation 7 are time t1, time t2, time t3, time t4, time t5, time t6, and time t7.
  • time sequence of each time stamp is time t1, time t2, (time t3 and time t4), (time t5, time t6, and time t7) respectively, that is, time t3 and time t4 are the same, time t5, Time t6 and time t7 are the same time, it can be understood that operation 1 is obtained first, operation 2 is obtained later, operation 3 and operation 4 are obtained at the same time, and operation 5, operation 6 and operation are obtained at the same time. 7.
  • the write operations to be selected are operation 5, operation 6, and operation 7, and then, a target write operation is determined from operation 5, operation 6 and operation 7.
  • the operation object corresponding to operation 5, operation 6 and operation 7 may be determined.
  • the operation objects corresponding to operation 5, operation 6 and operation 7 are master room, slave room 1 and slave room 2 respectively. . Then, the write operation to be selected in the host room as the operation object is operation 5, so that it can be determined that the target write operation is operation 5.
  • the operation object corresponding to the write operation can refer to the foregoing description, which will not be repeated here.
  • operation 1 operation 2, operation 3, operation 4, operation 5, operation 6 and operation 7 correspond to the operation
  • the objects are slave room 1, slave room 2, master room, slave room 3, master room, slave room 1 and slave room 2.
  • the purpose of operation 1 is to modify data1 stored in computer room 1 to data 1.
  • the timestamps corresponding to operation 5, operation 6 and operation 7 are the latest, it can be determined that the target write operation is operation 5 in the host room, and the determined target data is data 5. Finally, the modification of data1 is performed this time The method is determined to modify the data data1 in the master room to data 5, and synchronize the data 5 to other slave computer rooms, so that all data1 in the slave computer rooms are modified to data 5.
  • the method of determining the target data can refer to the foregoing, and the modification method is also to modify the host computer first data7, and then synchronize sequentially.
  • the designated machine room is one of the plurality of slave machine rooms.
  • each slave room can be set to a synchronization state, the synchronization state includes unsynchronized and synchronized, then each time a slave room is selected from the unsynchronized slave room as the designated room, the target data Synchronize to the specified computer room.
  • the target data is successfully synchronized to the specified computer room, the synchronization status corresponding to the specified computer room will be changed, for example, change the synchronization status from unsynchronized to synchronized.
  • a synchronization sequence may be preset, and the host room synchronizes the target data to all the slave computer rooms according to the synchronization sequence, and then selects a slave computer room as the designated computer room in sequence according to the synchronization sequence.
  • an implementation manner for determining whether the data is successfully synchronized to the designated computer room may be to detect whether the synchronization success information fed back by the designated computer room is received; if it is received, it is determined that the data is successfully synchronized to the designated computer room. ; If it is not received, it is determined that the data has not been successfully synchronized to the designated computer room.
  • the successful synchronization information may be sent from the computer room to the host room after the target data is received and successfully stored. After receiving the information, the host room can determine that the target data is successfully synchronized to the corresponding slave in the host room. engine room.
  • the time starting point of the predetermined time period may be the time point at which the operation of synchronizing the target data to the slave computer room corresponding to the host room is performed
  • the predetermined time length of the predetermined time period may be predetermined, for example, It is set based on experience. Specifically, it may be to count the length of time for synchronizing data from the computer room, and determine the predetermined time length of the predetermined time period according to the time length.
  • the time length for synchronizing multiple data from the computer room may be acquired, and the predetermined time length of the predetermined time period is determined according to the multiple time lengths. Specifically, the average value of the multiple time lengths is calculated, and the average value is used as the predetermined time length of the predetermined time period.
  • the implementation manner of determining whether the target data is successfully synchronized to the designated computer room may include: S541 to S543.
  • S541 Acquire first record information corresponding to the host room, where the first record information is used to record the operation performed by the host room to write target data.
  • the first recording information includes the identification and operation time of the data written each time in the host room, where the operation time is used to record the writing time point of the written data, wherein the writing
  • the identification of the data may be an identification assigned by the host room for each written data, where the identification may be an identification determined according to the content of the data, for example, it may be an identification of the data generated based on the data summary of the data
  • the data summary of the target data may be used as the identifier of the target data. Among them, the data summary can be used to describe the content of the target data.
  • the first record information includes the writing time corresponding to the target identifier of the target data.
  • S542 Acquire second record information corresponding to the designated computer room, where the second record information is used to record the data synchronization operation of the target data performed by the designated computer room.
  • the second record information includes the identifier and operation time of the data synchronized each time from the computer room, where the operation time may be the time when the data is synchronized from the computer room, and the implementation of the data identifier can refer to the foregoing The embodiments are not repeated here.
  • Each slave computer room corresponds to the second record information. Therefore, each second record information of the slave computer room can be the second record information of the designated computer room.
  • S543 Determine whether the data is successfully synchronized to the designated computer room according to the first record information and the second record information.
  • the first record information includes the identifier of the data being written in the host room and the writing time point corresponding to the identifier
  • the second record information includes the identifier of the data synchronized from the computer room and the synchronization time corresponding to the identifier. Determine whether the target data is successfully synchronized to the designated computer room according to the identifier of the data written in the host room and the write time point corresponding to the identifier, and the identifier of the data synchronized to the designated computer room and the synchronization time corresponding to the identifier.
  • the first operation time point is the writing time point corresponding to the target identifier of the target data written in the host room recorded in the first record information
  • the second operation time point is the designated computer room data recorded in the second record information.
  • Synchronize the synchronization time corresponding to the target identifier of the synchronization target data determine whether the synchronization time is later than the writing time point, if yes, determine that the target data is successfully synchronized to the designated computer room, otherwise, determine that the target data is not successfully synchronized Go to the designated computer room.
  • the implementation 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 period of time, where the predetermined time
  • the method of recording the write operation of the host room and the data synchronization operation of the slave computer room can be the above-mentioned log file, that is, the write operation of the host and the data synchronization of the slave are recorded in a log stream. Operation, you can set a serial number for both the master room and the slave room, and each write operation of the master and every data synchronization operation of the slave can be recorded through the serial number.
  • the first record information is a first serial number
  • the first serial number is used to perform an update operation according to a first update rule when the host room is successfully written into the target data.
  • a first update rule can be predefined
  • the first serial number, the initial value of the first serial number is the first initial value, then every time data is written in the host room, the value of the first serial number is updated according to the first update rule, where the The first update rule can be to increase or decrease a certain value, that is, each time a write operation is performed, a certain value is increased or decreased on the basis of the first serial number saved last time.
  • the initial value of the first serial number is the first initial value
  • the first update rule is to increase the first value.
  • the value of the first serial number becomes the first The sum of the initial value and the first value.
  • the value of the first serial number becomes the sum of the first initial value and two first values, that is, on the basis of the first serial number saved last time Increased the first value.
  • the first sequence number is seq1 and the initial value is 0, then after the data is written for the first time, the value of the first sequence number seq1 becomes 1, and after the data is written for the second time, the first The value of the serial number seq1 becomes 2, and so on, if the data to be written includes multiple data, the multiple data are data1, data2, data3, data4, data5, and data6, respectively, the data identifier and the value of the serial number seq1
  • the sequence numbers seq1 corresponding to data1, data2, data3, data4, data5, and data6 are 1, 2, 3, 4, 5, and 6 in order.
  • the writing sequence of each written data and the serial number corresponding to the identifier of each written data can be obtained through the above-mentioned correspondence relationship.
  • the serial number can be used as the serial number of the written data and can be recorded in the entire During the write operation, which target data is written first.
  • the second record information is a second serial number
  • the second serial number is used to perform an update operation according to a second update rule when the designated computer room successfully synchronizes data.
  • the second update rule may be the same as the above-mentioned first update rule, and the second update rule may also be to increase the second value.
  • the initial value of the second serial number is the second initial value
  • the second update rule is to increase the second value.
  • the value of the second serial number becomes the second The sum of the initial value and the second value.
  • the value of the second serial number becomes the sum of the second initial value and two second values, that is, it is added to the second serial number saved last time.
  • the second value wherein, the first value and the second value are the same, for example, both are 1, and the first initial value and the second initial value may also be the same, for example, both may be 0.
  • the initial value is 0.
  • the value of the second sequence number seq2 becomes 1
  • the value of the second sequence number seq2 The value becomes 2, and so on.
  • the synchronized data includes multiple data
  • the multiple data are data1, data2, data3, data4, data5, and data6 respectively.
  • the corresponding relationship between the data identifier and the value of the serial number seq2 is: data1
  • the sequence numbers seq2 corresponding to, data2, data3, data4, data5, and data6 are 1, 2, 3, 4, 5, and 6, respectively.
  • the seq2 of the slave is only changed when the data is successfully synchronized by the slave, and the size relationship of the seq1 corresponding to the target data written by the host is determined by determining the size of the current seq2 , Can determine whether the slave successfully synchronizes the target data.
  • the implementation manner of synchronizing to the designated computer room may be: obtaining the size relationship between the first serial number and the second serial number; if the size relationship satisfies a specified condition, it is determined that the data is successfully synchronized to the A designated computer room, wherein the size relationship satisfies a specified condition indicates that the designated computer room successfully synchronizes the target data after the host room is written with the target data; if the size relationship does not meet the specified condition, it is determined not to The data is successfully synchronized to the designated computer room.
  • the size relationship can be whether the first serial number is less than or equal to the second serial number, or another size relationship that can characterize whether the first serial number is less than or equal to the second serial number, for example, it can also be to obtain the first serial number.
  • the ratio between the serial number and the second serial number If the ratio is greater than 1, it indicates that the first serial number is greater than the second serial number; if the ratio is not greater than 1, it indicates that the first serial number is less than or equal to the second serial number. No.
  • that the size relationship satisfies a specified condition indicates that the specified computer room successfully synchronizes the target data after the host room is written into the target data.
  • the size relationship may be whether the first serial number is less than or equal to the second serial number, then if If the first serial number is less than or equal to the second serial number, it is determined that the size relationship meets the specified condition; otherwise, it is determined that the size relationship does not meet the specified condition.
  • the magnitude relationship can be whether the first serial number is greater than or equal to the second serial number, then if the first serial number is greater than or equal to the second serial number, If a serial number is greater than or equal to the second serial number, it is determined that the size relationship meets the specified condition; otherwise, it is determined that the size relationship does not meet the specified condition.
  • the magnitude relationship may be the second sequence number and the first sequence Whether the ratio of the number is a positive integer multiple of k, then if the ratio of the second serial number to the first serial number is a positive integer multiple of k, it is determined that the size relationship meets the specified condition, otherwise, it is determined that the size relationship does not meet Specify the conditions.
  • the first update rule and the second update rule may be the same, and the same value is added to the initial value.
  • the size relationship meets the specified condition means that if the first serial number is less than or equal to The second serial number.
  • the first serial number is changed according to the first update rule
  • the second serial number is changed according to the second update rule.
  • the first serial number The first value of the serial number after the first update rule is updated
  • the second serial number is the second value after the second update rule is updated
  • the first value and The size relationship between 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 size relationship between the first value and the second value should be same.
  • the ratio of the value a to the value b is c, then the magnitude relationship between the first value and the second value should also satisfy the value a
  • the ratio to the value b is n times c, where n is a positive integer.
  • the host room The first serial number of the slave and the second serial number of the slave will be initialized, that is, it will be restored to the initial value. If there is only one data to be written, that is, if the target data is one data, the host room writes the After the target data, the first serial number should be 1, and after the slave successfully synchronizes the target data, the second serial number should be 1, that is, the first serial number and the second serial number are the same.
  • the slave has successfully synchronized to data3, and data3 is the data written after data1.
  • the second sequence number of the slave is greater than the first sequence Therefore, if the second serial number is greater than the first serial number, it can indicate that the data corresponding to the first serial number has been successfully synchronized to the slave.
  • the first serial number corresponding to the target data written in the master room is acquired, and the current second serial number of the slave is acquired. If the first serial number is less than or equal to the second serial number, it means that the slave is in all locations. After the host room is written into the target data, the target data is successfully synchronized.
  • the data written in the host room includes data1, data2, data3, data4, data5, and data6.
  • data1, data2, data3, data4, data5, and data6 are successfully written into the host room, where data2 is the target data, then Referring to the above table 1, the first sequence 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.
  • the seq2 of the slave is 1, then It indicates that the data successfully synchronized by the slave is data1, and the first serial number is greater than the second serial number, and it can be determined that the target data has not been successfully synchronized to the designated computer room.
  • the seq2 of the slave machine is 2
  • the first serial number is equal to the second serial number
  • the seq2 of the slave is 3 at this time, it means that the data successfully synchronized by the slave is data3, that is, the data successfully synchronized by the slave is data3 after the target data, and the first serial number is less than the second serial number, then It can be determined that the target data is not successfully synchronized to the designated computer room.
  • the first serial number is less than or equal to the second serial number, it can be determined that the target data is successfully synchronized to the designated computer room.
  • the above detection method can be used to determine whether each slave room has successfully synchronized the target data, so as to determine the target data Whether to successfully synchronize to the slave computer room corresponding to the host room.
  • the operation of detecting whether the target data is successfully synchronized to the slave computer room corresponding to the host room may be named a scanning operation, and if the first serial number is greater than the second serial number, it is determined that the target When the data is not successfully synchronized to the slave computer room corresponding to the host room, you can wait for a certain period of time before continuing to perform the scanning operation, that is, pause the scanning operation during this time period, so that the slave computer room can complete the scan within this time period. Synchronization operation of target data.
  • the method further includes: obtaining the first serial number and the second serial number again after a specified length of time.
  • the specified time length may be a preset time length.
  • the specified time length may be the same as the predetermined time length corresponding to the aforementioned predetermined time period. Specifically, the specified time length may be 10 ms.
  • S550 Use a slave room other than the designated machine room among the slave machine rooms as a new designated machine room.
  • a slave computer room other than the designated computer room is re-selected as the new designated computer room, and the execution of S530 is returned. , Until all slave rooms are synchronized.
  • mutually independent Redis clusters can be deployed in multiple computer rooms, and the read and write operations of all computer rooms can be synchronized to other computer rooms, that is, the clusters of each computer room are mirror images of each other.
  • the business layer can dispatch read and write requests to other normal computer rooms to continue running, thereby achieving cross-computer room disaster recovery and ensuring high service availability and data security.
  • the above-mentioned client may include a scanning process and a subscription process.
  • the scanning process is used to perform the operation of judging whether the data is successfully synchronized to the designated computer room, and the subscription process is used to monitor the write operation of the master room and the slave computer room.
  • the The write operation obtains the target data.
  • Data synchronization through external programs has no perception of the business layer and is simple to use, that is, data synchronization is achieved through the above-mentioned client. Therefore, there will be no cross-machine room reading and writing, and business performance will not be affected. Supports simultaneous read and write in multiple locations, supports data synchronization between any number of clusters, and services can be deployed in multiple locations according to the situation, with strong scalability. Through the master-slave machine room mechanism, the final consistency of the data when writing in multiple places is guaranteed at the same time.
  • FIG. 8 shows a structural block diagram of a data synchronization device 800 provided by an embodiment of the present application.
  • the device may include: an acquiring unit 801, a writing unit 802, and a synchronization unit 803.
  • the obtaining unit 801 is configured to obtain target data requested to be written into the data storage system.
  • the writing unit 802 is configured to write the target data into the host room.
  • the synchronization unit 803 is configured to synchronize the target data to the slave computer room after successfully writing the target data into the host room.
  • FIG. 9 shows a structural block diagram of a data synchronization device 900 provided by an embodiment of the present application.
  • the device may include: an acquiring unit 910, a writing unit 920, and a synchronization unit 930.
  • the obtaining unit 910 is configured to obtain the target data requested to be written into the data storage system.
  • the acquiring unit 910 also includes a monitoring subunit 911 and a data determining subunit 912.
  • the monitoring subunit 911 is used to monitor the write operation of the host room and the slave computer room.
  • the data determining subunit 912 is further configured to obtain the target data according to the write operation when the write operation is detected.
  • 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 designated data and is used to The content to be modified is modified to designated data; the target write operation is determined from the plurality of write operations according to the timestamp; the designated data corresponding to the target write operation is used as the target data.
  • the data determining subunit 912 is further configured to determine the latest timestamp among all the timestamps as the target timestamp if the timestamps are not all the same; use the write operation corresponding to the target timestamp as the candidate Write operation; the target write operation is determined from the to-be-selected write operation.
  • the data determining subunit 912 is further configured to, if the number of the write operations to be selected is 1, set the write operations to be selected as the target write operation.
  • the data determining subunit 912 is further configured to determine the operation object corresponding to each of the writing operation to be selected if the number of the writing operation to be selected is at least two, and the operation object includes the host room or the slave Computer room; take the write operation to be selected in the host room where the operation object is the target write operation.
  • the data determining subunit 912 is further configured to determine the operation object corresponding to each of the write operations to be selected if the time stamps are all the same, and the operation object includes the host room or the slave computer room;
  • the write operation to be selected in the host room as the operation object is taken as the target write operation.
  • the writing unit 920 is configured to write the target data into the host room.
  • the master room and the slave room each have a message queue
  • the master room subscribes to the message queues of all the slave computer rooms
  • each of the slave computer rooms subscribes to the message queue of the master room
  • the After the target data is written into the host room, synchronizing the target data to the slave computer room includes: after successfully writing the target data into the host room, passing through a message queue corresponding to the host room To synchronize the target data to the slave computer room.
  • FIG. 10 shows a structural block diagram of a data synchronization device 1000 provided by an embodiment of the present application.
  • the device may include: an acquiring unit 1010, a writing unit 1020, and a synchronization unit 1030.
  • the obtaining unit 1010 is configured to obtain the target data requested to be written into the data storage system.
  • the writing unit 1020 is configured to write the target data into the host room.
  • the synchronization unit 1030 is configured to synchronize the target data to the slave computer room after successfully writing the target data into the host room.
  • the synchronization unit 1030 includes a selection subunit 1031, a judgment subunit 1032, and a synchronization subunit 1033.
  • the judging subunit 1032 is also used to detect whether the synchronization success information fed back by the designated computer room is received; if it is received, it is determined that the data is successfully synchronized to the designated computer room; if it is not received, then It is determined that the data is not successfully synchronized to the designated computer room.
  • the judging subunit 1032 is further configured to obtain the first record information corresponding to the host room, and the first record information is used to record the operation performed by the host room to write target data; The second record information corresponding to the designated computer room, where the second record information is used to record the data synchronization operation of the target data performed by the designated computer room; determine whether or not according to the first record information and the second record information The data is successfully synchronized to the designated computer room.
  • the judging subunit 1032 is also used to judge whether the first operation time point in the first record information is earlier than the second operation time point in the second record information; if it is earlier, it is judged that the data is successfully transferred Synchronize to the designated computer room; if it is not earlier, it is determined that the data is not successfully synchronized to the designated computer room.
  • 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 room is successfully written into target data;
  • the second record information It is a second serial number, and the second serial number is used to perform an update operation according to a second update rule when the designated computer room successfully synchronizes data.
  • the judging subunit 1032 is also used to obtain the size relationship between the first serial number and the second serial number; if the size relationship meets a specified condition, it is determined that the data is successfully synchronized to the specified computer room , Wherein the size relationship satisfies the specified condition indicates that the specified computer room successfully synchronizes the target data after the host room is written into the target data; if the size relationship does not meet the specified condition, it is determined that the transfer is unsuccessful The data is synchronized to the designated computer room.
  • the first update rule is to increase or decrease the first serial number by a first value when the target data is successfully written in the host room, and the second update rule is to successfully synchronize data in the designated computer room,
  • the second serial number is increased or decreased by a second value, and the first value is the same as the second value.
  • the fact that the size relationship satisfies a specified condition means that the first serial number is less than or equal to the second serial number.
  • the judging subunit 1032 is further configured to obtain the size relationship between the first serial number and the second serial number again and perform subsequent operations after a specified length of time, wherein, within the specified length of time Continue to perform the operation of synchronizing the target data to the designated computer room.
  • the coupling between the modules may be electrical, mechanical or other forms of coupling.
  • the electronic device 100 may be an electronic device capable of running application programs, such as a smart phone, a tablet computer, or an e-book.
  • the electronic device 100 in this application may include one or more of the following components: a processor 110, a memory 120, and one or more application programs, where one or more application programs may be stored in the memory 120 and configured to be configured by One or more processors 110 execute, and one or more programs are configured to execute the methods described in the foregoing method embodiments.
  • the processor 110 may include one or more processing cores.
  • the processor 110 uses various interfaces and lines to connect various parts of the entire electronic device 100, and executes by running or executing instructions, programs, code sets, or instruction sets stored in the memory 120, and calling data stored in the memory 120.
  • Various functions and processing data of the electronic device 100 may adopt at least one of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), and Programmable Logic Array (PLA).
  • DSP Digital Signal Processing
  • FPGA Field-Programmable Gate Array
  • PDA Programmable Logic Array
  • the processor 110 may be integrated with one or a combination of a central processing unit (CPU), a graphics processing unit (GPU), a modem, and the like.
  • the CPU mainly processes the operating system, user interface, and application programs; the GPU is used for rendering and drawing of display content; the modem is used for processing wireless communication. It is understandable that the above-mentioned modem may not be integrated into the processor 110, but may be implemented by a communication chip alone.
  • the memory 120 may include random access memory (RAM) or read-only memory (Read-Only Memory).
  • the memory 120 may be used to store instructions, programs, codes, code sets or instruction sets.
  • the memory 120 may include a program storage area and a data storage area, where the program storage area may store instructions for implementing the operating system and instructions for implementing at least one function (such as touch function, sound playback function, image playback function, etc.) , Instructions used to implement the following various method embodiments, etc.
  • the data storage area can also store data (such as phone book, audio and video data, chat record data) created by the terminal 100 during use.
  • FIG. 12 shows a structural block diagram of a computer-readable storage medium provided by an embodiment of the present application.
  • the computer-readable medium 1200 stores program code, and the program code can be invoked by a processor to execute the method described in the foregoing method embodiment.
  • the computer-readable storage medium 1200 may be an electronic memory such as flash memory, EEPROM (Electrically Erasable Programmable Read Only Memory), EPROM, hard disk, or ROM.
  • the computer-readable storage medium 1200 includes a non-transitory computer-readable storage medium.
  • the computer-readable storage medium 1200 has storage space for the program code 1210 for executing any method steps in the above-mentioned methods. These program codes can be read from or written into one or more computer program products.
  • the program code 1210 may be compressed in an appropriate form, for example.

Abstract

A data synchronization method and device, a data storage system and a computer-readable medium, which relates to the technical field of computers, the method comprising: acquiring target data requested to be written into the data storage system (S201); writing the target data to a master room (S202); and after successfully writing the target data to the master room, synchronizing the target data to a slave room (S203). The method first writes data to the master room, and on the basis of the data in the master room, synchronizes, to the slave room, the data written to the master room, which may better maintain data consistency.

Description

数据同步方法、装置、数据存储系统及计算机可读介质Data synchronization method, device, data storage system and computer readable medium 技术领域Technical field
本申请涉及计算机技术领域,更具体地,涉及一种数据同步方法、装置、数据存储系统及计算机可读介质。This application relates to the field of computer technology, and more specifically, to a data synchronization method, device, data storage system, and computer readable medium.
背景技术Background technique
随着网络服务的日益普及,用户的访问量越来越大,如果将业务数据全部存储在一台服务器上,该服务器往往会由于访问量过大而出现故障,而且,受到服务器存储空间的限制,在业务数据量很大的应用场景中,一台服务器往往无法承载全部的业务数据,因此,需要多台服务器共同为用户提供服务。为此,可以将多台共同用于提供某一服务的服务器设置在同一机房内,然后再由多个机房构成一个系统,又该系统为业务层提供数据存储功能。With the increasing popularity of network services, the amount of user visits is increasing. If all business data is stored on a server, the server will often fail due to excessive visits, and is limited by the storage space of the server In an application scenario with a large amount of business data, one server often cannot carry all the business data. Therefore, multiple servers are required to provide services for users together. To this end, multiple servers that are commonly used to provide a service can be set up in the same computer room, and then multiple computer rooms form a system, and the system provides data storage functions for the business layer.
但是,在业务层进行数据存储时,需要将系统内的每个机房都执行一次写入操作,然后,如果部分机房的数据写入错误,会导致整个系统的数据不一致。However, when data is stored in the business layer, each computer room in the system needs to be written once. Then, if the data in some computer rooms is written incorrectly, the data in the entire system will be inconsistent.
发明内容Summary of the invention
本申请提出了一种数据同步方法、装置、数据存储系统及计算机可读介质,以改善上述缺陷。This application proposes a data synchronization method, device, data storage system, and computer readable medium to improve the above-mentioned defects.
第一方面,本申请实施例提供了一种数据同步方法,应用于数据存储系统的主机房,该数据存储系统还包括与所述主机房对应的从机房。所述方法包括:获取请求写入所述数据存储系统的目标数据;将所述目标数据写入所述主机房;在成功将所述目标数据写入所述主机房之后,将所述目标数据同步至所述从机房。In the first aspect, an embodiment of the present application provides a data synchronization method, which is applied to a host room of a data storage system, and the data storage system further includes a slave computer room corresponding to the host room. The method includes: obtaining target data requested to be written into the data storage system; writing the target data into the host room; after successfully writing the target data into the host room, writing the target data Synchronize to the slave room.
第二方面,本申请实施例还提供了一种数据同步装置,应用于数据存储系统的主机房,该数据存储系统还包括与所述主机房对应的从机房。所述装置包括:获取单元、写入单元和同步单元。获取单元,用于获取请求写入所述数据存储系统的目标数据。写入单元,用于将所述目标数据写入所述主机房。同步单元,用于在成功将所述目标数据写入所述主机房之后,将所述目标数据同步至所述从机房。In a second aspect, an embodiment of the present application also provides a data synchronization device, which is applied to a host room of a data storage system, and the data storage system further includes a slave computer room corresponding to the host room. The device includes: an acquisition unit, a writing unit, and a synchronization unit. The obtaining unit is configured to obtain the target data requested to be written into the data storage system. The writing unit is used to write the target data into the host room. The synchronization unit is configured to synchronize the target data to the slave computer room after successfully writing the target data into the host room.
第三方面,本申请实施例还提供了一种数据存储系统,包括:主机房和与所述主机房对应的从机房;所述主机用于执行上述方法。In a third aspect, an embodiment of the present application also provides a data storage system, including: a host room and a slave computer room corresponding to the host room; the host is used to execute the above method.
第四方面,本申请实施例还提供了一种计算机可读介质,所述可读存储介质存储有处理器可执行的程序代码,所述程序代码被所述处理器执行时使所述处理器执行上述方法。In a fourth aspect, the embodiments of the present application also provide a computer-readable medium, the readable storage medium storing a program code executable by a processor, and when the program code is executed by the processor, the processor Perform the above method.
本申请提供的数据同步方法、装置、数据存储系统及计算机可读介质,在数据存储系统被请求写入目标数据的时候,即不论是请求在系统的主机房还是从机房内写入数据,都会先将目标数据写入主机房,然后,在成功将所述目标数据写入所述主机房之后,再将目标数据同步至所述从机房。因此,不仅能够避免同时将目标数据写入多个机房的时候,如果某个机房的数据写入出错,会导致各个机房的数据不一致,而是先对主机房写入数据,并且以主机房的数据为准将所写入主机房的数据同步至从机房,能够更好的保持数据的一致性。The data synchronization method, device, data storage system and computer readable medium provided in this application will be used when the data storage system is requested to write target data, that is, whether it is requested to write data in the host room of the system or from the computer room. The target data is written into the host room first, and then, after the target data is successfully written into the host room, the target data is synchronized to the slave computer room. Therefore, not only can it avoid that when the target data is written into multiple computer rooms at the same time, if the data in a certain computer room is written incorrectly, it will cause the data in each computer room to be inconsistent. The data is subject to the synchronization of the data written in the host room to the slave room, which can better maintain data consistency.
附图说明Description of the drawings
为了更清楚地说明本申请实施例中的技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly describe the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings that need to be used in the description of the embodiments. Obviously, the drawings in the following description are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
图1示出了本申请实施例提供的数据存储系统的示意图;Figure 1 shows a schematic diagram of a data storage system provided by an embodiment of the present application;
图2示出了本申请一实施例提供的数据同步方法的方法流程图;FIG. 2 shows a method flowchart of a data synchronization method provided by an embodiment of the present application;
图3示出了本申请另一实施例提供的数据同步方法的方法流程图;FIG. 3 shows a method flowchart of a data synchronization method provided by another embodiment of the present application;
图4示出了本申请一实施例提供的图3中S320的方法流程图;FIG. 4 shows a flowchart of the method S320 in FIG. 3 according to an embodiment of the present application;
图5示出了本申请又一实施例提供的数据同步方法的方法流程图;FIG. 5 shows a method flowchart of a data synchronization method provided by another embodiment of the present application;
图6示出了本申请一实施例提供的图5中S540的方法流程图;FIG. 6 shows a flowchart of the method S540 in FIG. 5 provided by an embodiment of the present application;
图7示出了本申请实施例提供的数据存储系统内客户端的示意图;FIG. 7 shows a schematic diagram of a client in a data storage system provided by an embodiment of the present application;
图8示出了本申请另一实施例提供的数据同步装置的模块框图;FIG. 8 shows a block diagram of a data synchronization device provided by another embodiment of the present application;
图9示出了本申请又一实施例提供的数据同步装置的模块框图;FIG. 9 shows a block diagram of a data synchronization device provided by another embodiment of the present application;
图10示出了本申请再一实施例提供的数据同步装置的模块框图;FIG. 10 shows a block diagram of modules of a data synchronization device provided by still another embodiment of the present application;
图11示出了本申请实施例提供的电子设备的示意图;FIG. 11 shows a schematic diagram of an electronic device provided by an embodiment of the present application;
图12是本申请实施例的用于保存或者携带实现根据本申请实施例的数据同步方法的程序代码的存储单元。Fig. 12 is a storage unit for storing or carrying program code for implementing the data synchronization method according to the embodiment of the present application according to an embodiment of the present application.
具体实施方式Detailed ways
为了使本技术领域的人员更好地理解本申请方案,下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述。In order to enable those skilled in the art to better understand the solutions of the present application, the technical solutions in the embodiments of the present application will be described clearly and completely in conjunction with the accompanying drawings in the embodiments of the present application.
随着网络服务的日益普及,用户的访问量越来越大,如果将业务数据全部存储在一台服务器上,该服务器往往会由于访问量过大而出现故障,而且,受到服务器存储空间的限制,在业务数据量很大的应用场景中,一台服务器往往无法承载全部的业务数据,因此,需要多台服务器共同为用户提供服务。为此,可以将多台共同用于提供某一服务的服务器设置在同一机房内,由该机房向用户提供该项服务。With the increasing popularity of network services, the amount of user visits is increasing. If all business data is stored on a server, the server will often fail due to excessive visits, and is limited by the storage space of the server In an application scenario with a large amount of business data, one server often cannot carry all the business data. Therefore, multiple servers are required to provide services for users together. To this end, multiple servers that are commonly used to provide a service can be set up in the same computer room, and the computer room can provide the service to users.
其中,上述数据管理服务中,内存数据库应用较为广泛,内存数据库是指将数据放在内存中直接操作的数据库,一般以集群的方式部署,这样的集群称为内存数据库集群。内存数据库集群包括内存数据库主机和内存数据库从机,两者之间需要保持数据的同步。进一步地,同步分为全量同步和增量同步,全量同步是指内存数据库从机一次性将内存数据库主机的全部数据进行同步,增量同步是指内存数据库从机只对其与内存数据库主机之间不同的部分数据进行同步。Among the above-mentioned data management services, in-memory databases are widely used. In-memory databases refer to databases that put data in memory and operate directly, and are generally deployed in a cluster. Such clusters are called in-memory database clusters. An in-memory database cluster includes an in-memory database master and an in-memory database slave, and data needs to be synchronized between the two. Further, synchronization is divided into full synchronization and incremental synchronization. Full synchronization means that the in-memory database slave synchronizes all the data of the in-memory database host at one time. Incremental synchronization means that the in-memory database slave only synchronizes it with the in-memory database host. Synchronize the different parts of the data.
其中,Redis是一个可基于内存的高性能开源数据库,使用ANSIC语言编写,提供多种语言的编程接口,常用于实现软件或应用的数据存储和快速访问等功能;在生产环境中,redis的应用十分广泛,例如为了在扩容业务的同时保证服务的稳定性,常使用支持分布式高可用和横向扩展的redis集群来进行数据的存储和访问。为了提高系统稳定性,redis系统通常采用的主从结构。在redis从节点的初始化阶段以及主节点被写入新的数据的时候,需要将redis主节点上的数据复制一份,以作备用这一事件称为redis的主从数据同步。Among them, Redis is a high-performance open source database that can be based on memory. It is written in ANSIC language and provides programming interfaces in multiple languages. It is often used to implement functions such as software or application data storage and fast access; in a production environment, redis applications It is very extensive. For example, in order to ensure the stability of the service while expanding the business, the redis cluster that supports distributed high availability and horizontal expansion is often used for data storage and access. In order to improve the stability of the system, the redis system usually adopts the master-slave structure. In the initialization phase of the redis slave node and when the master node is writing new data, it is necessary to copy the data on the redis master node for backup. This event is called redis master-slave data synchronization.
如图1所示,图1示出了数据存储系统的示意图,该数据存储系统包括多个机房个,如图1所示,该多个机房包括机房1、机房2和机房3。每个机房内包括主机和与主机对应的至少一个从机。如图1所示,机房1内包括主机10和该主机对应的从机11和从机12,其中,主机10和从机11以及从机12均为主从关系。其中,主机也称为主节点(master),主节点,对外提供服务。从机也称为从节点(slave),从节点,实时复制Master节点的数据,保证与Master节点一致。从机无法被其他设备执行数据写入操作,从机内的数据,由主机通过数据同步的方式,将写入主机的数据同步到从机。As shown in FIG. 1, FIG. 1 shows a schematic diagram of a data storage system. The data storage system includes multiple computer rooms. As shown in FIG. 1, the multiple computer rooms include a computer room 1, a computer room 2 and a computer room 3. Each computer room includes a host computer and at least one slave computer corresponding to the host computer. As shown in FIG. 1, the computer room 1 includes a host 10 and a slave 11 and a slave 12 corresponding to the host. The host 10 and the slave 11 and the slave 12 are in a master-slave relationship. Among them, the host is also called the master node (master), which provides external services. The slave is also called the slave. The slave replicates the data of the Master node in real time to ensure that it is consistent with the Master node. The slave machine cannot be performed by other devices to perform data writing operations. The data in the slave machine is synchronized by the master to the slave machine through data synchronization.
另外,如图1所示,该机房2包括主机20和该主机对应的从机21和从机22,机房3包括主机30和该主机对应的从机31和从机32。In addition, as shown in FIG. 1, the computer room 2 includes a host 20 and slaves 21 and 22 corresponding to the host, and the computer room 3 includes a host 30 and slaves 31 and 32 corresponding to the host.
需要说明的是,各个机房构成的数据存储系统能够为业务层提供数据存储服务,即 业务层产生的数据能够存储至数据存储系统内,也可以从数据存储系统内读取数据。It should be noted that the data storage system formed by each computer room can provide data storage services for the business layer, that is, the data generated by the business layer can be stored in the data storage system, and data can also be read from the data storage system.
在一些实施例中,业务层可以将数据写入数据存储系统内,写入的方式可以是,将数据写入数据存储系统内的任意机房内,具体地,可以是将写入数据存储系统内的任意机房的主机内,然后为了保证数据的一致性,需要将所写入的数据在每个机房内都写入。In some embodiments, the business layer can write data into the data storage system. The way of writing can be to write the data into any computer room in the data storage system. Specifically, it can be to write data into the data storage system. In the host computer of any computer room, in order to ensure the consistency of the data, the written data needs to be written in each computer room.
然而,发明人在研究中发现,目前基于Redis实现跨机房多活方案均采用多地写入的方案,即业务层在进行数据存储时,需要对每一个机房的存储集群执行一次写入操作,所有机房的存储集群均写成功后才认为数据存储成功。但是,在业务层进行数据存储时,需要将系统内的每个机房都执行一次写入操作,然后,如果部分机房的数据写入错误,会导致整个系统的数据不一致。However, the inventor found in his research that the current implementation of cross-computer room multi-active solutions based on Redis adopts multi-write solutions, that is, when the business layer is storing data, it needs to perform a write operation on the storage clusters of each computer room. Data storage is considered successful only after all storage clusters in the computer room have been successfully written. However, when data is stored in the business layer, each computer room in the system needs to be written once. Then, if the data in some computer rooms is written incorrectly, the data in the entire system will be inconsistent.
因此,为了克服上述缺陷,本申请实施例中,将数据存储系统内的多个机房被划分为主机房和从机房,即在数据存储系统内的多个机房中,指定一个机房为主机房,其他的机房为与该主机房对应的从机房。Therefore, in order to overcome the above shortcomings, in the embodiment of the present application, multiple computer rooms in the data storage system are divided into a host room and a slave computer room, that is, among multiple computer rooms in the data storage system, one computer room is designated as the host room, The other computer rooms are the slave computer rooms corresponding to the host room.
本申请实施例提供了一种数据同步方法,该方法应用于上述的数据存储系统,作为一种实施方式,该数据存储系统内的每个机房对应设置一个客户端,该客户端用于将数据写入某个机房,以及执行本申请所述的方法的实施例。作为一种实施方式,该客户端可以是在安装在每个机房的主机内,也可以是设置于每个机房国内的与主机独立的终端内。于本申请实施例中,该客户端安装在主机内。The embodiment of the present application provides a data synchronization method, which is applied to the above-mentioned data storage system. As an implementation manner, each computer room in the data storage system is provided with a client corresponding to the data synchronization method. Write to a certain computer room, and execute the embodiment of the method described in this application. As an implementation manner, the client may be installed in a host in each computer room, or may be installed in a terminal independent of the host in each computer room. In the embodiment of the present application, the client is installed in the host.
如图2所示,图2示出了一种数据同步方法,该方法的执行主体可以是上述的主机房,具体地,该执行主体可以是主机房内的客户端。具体地,该方法包括:S201至S203。As shown in FIG. 2, FIG. 2 shows a data synchronization method. The execution subject of the method may be the above-mentioned host room. Specifically, the execution subject may be a client in the host room. Specifically, the method includes: S201 to S203.
S201:获取请求写入所述数据存储系统的目标数据。S201: Obtain target data requested to be written to the data storage system.
作为一种实施方式,可以是数据存储系统获取到数据写入请求,该数据写入请求用于将目标数据写入数据存储系统内。具体地,可以是由业务层发送数据写入请求至数据存储系统。As an implementation manner, the data storage system may obtain a data write request, and the data write request is used to write the target data into the data storage system. Specifically, the business layer may send a data write request to the data storage system.
在一些实施例中,该数据写入请求可以包括指定请求写入的机房的标号,该标号作为该机房的身份信息。则在该实施例中,业务层请求将目标数据写入所指定的标号对应的机房内。在另一些实施例中,该数据写入请求可以未包括指定请求写入的机房的标号。In some embodiments, the data writing request may include a label designating the computer room requested to be written, and the label is used as the identity information of the computer room. Then in this embodiment, the business layer requests to write the target data into the computer room corresponding to the designated label. In other embodiments, the data write request may not include a label designating the computer room where the write is requested.
而不论是指定写入某个机房还是未指定写入某个机房,只要是请求写入数据存储系统的数据写入请求对应的数据,都可以作为请求写入所述数据存储系统的目标数据。Regardless of whether it is specified to be written to a certain computer room or not specified to be written to a certain computer room, as long as the data corresponding to the data write request requesting to be written to the data storage system, it can be used as the target data requested to be written to the data storage system.
其中,主机房能够监听写入每个机房(包括主机房和与该主机房对应的从机房)的数据,以便主机房能够获取请求写入所述数据存储系统的目标数据。Wherein, the host room can monitor and write data in each computer room (including the host room and the slave room corresponding to the host room), so that the host room can obtain the target data requested to be written into the data storage system.
作为一种实施方式,所述主机房和从机房均对应有消息队列,所述主机房订阅所有所述从机房的消息队列,每个所述从机房均订阅所述主机房的消息队列。各个机房之间以及业务层等应用程序与各个机房之间通过消息队列通信,具体地,该消息队列(Message Queue,MQ)是一种应用程序对应用程序的通信方法。应用程序通过写和检索出入列队的针对应用程序的数据(消息)来通信。As an implementation manner, both the master room and the slave computer room have message queues, the master room subscribes to the message queues of all the slave computer rooms, and each of the slave computer rooms subscribes to the message queue of the master room. Communication between each computer room and between application programs such as the business layer and each computer room is through a message queue. Specifically, the message queue (MQ) is an application-to-application communication method. Application programs communicate by writing and retrieving application-specific data (messages) in and out of the queue.
例如,业务层请求写入目标数据至某个机房的时候,会发送数据写入请求至机房的消息队列,而如果该机房是从机房的话,由于主机房订阅了该从机房的消息队列,主机房能够监听到从机房对于消息队列的操作,从而能够在数据写入请求被写入消息队列的时候,被主机房监听到,进而能够获取到请求写入所述数据存储系统的目标数据。For example, when the business layer requests to write target data to a certain computer room, it will send a data write request to the message queue of the computer room. If the computer room is a slave computer room, because the master room subscribes to the message queue of the slave computer room, the host The room can monitor the operation of the slave computer room on the message queue, so that when a data writing request is written into the message queue, it can be monitored by the host room, and then the target data requested to be written into the data storage system can be obtained.
S202:将所述目标数据写入所述主机房。S202: Write the target data into the host room.
获取到请求写入数据存储系统的目标数据之后,将该目标数据写入该主机房内。After obtaining the target data requested to be written into the data storage system, the target data is written into the host room.
作为一种实施方式,主机房内包括主机和与该主机对应的从机,则将所述目标数据写入所述主机房的实施方式可以是,将目标数据写入该主机,然后,再由主机将该目标数据同步至与该主机对应的从机内。As an implementation manner, the host room includes a host computer and a slave device corresponding to the host computer. The implementation manner of writing the target data into the host computer room may be to write the target data into the host computer, and then by The master synchronizes the target data to the slave corresponding to the master.
假设上述的机房1为主机房且目标数据为数据data。该主机10会将该数据data同步至该主机对应的从机11和从机12。Assume that the aforementioned computer room 1 is a host room and the target data is data data. The host 10 will synchronize the data to the slave 11 and the slave 12 corresponding to the host.
作为一种实施方式,每个机房内设置有日志流水功能,该日志流水功能用于记录主机被写入数据的操作,在基于日志流水的Redis集群跨机房多活方案中,所有Redis的数据写入都会保存到本地磁盘的日志流水中,外部扫描程序扫描该日志流水,将数据的修改同步到其他机房的Redis集群,其中,每个Redis集群可以理解为上述的机房。通过该日志流水能够记录各个机房的每次写入操作,以便于将实现数据的同步。As an implementation manner, each computer room is provided with a log pipelining function, which is used to record the operation of the host writing data. In the Redis cluster cross-computer room multiple activity solution based on log pipelining, all Redis data writes The input will be saved in the log stream of the local disk. The external scanner scans the log stream and synchronizes the data modification to the Redis clusters of other computer rooms. Each Redis cluster can be understood as the aforementioned computer room. The log stream can record each write operation of each computer room, so as to realize data synchronization.
具体地,以上述存储系统为Redis系统为例,修改Redis组件的源代码实现,增加binlog(即日志流水)功能,将每一个写操作记录到日志文件中,并保证日志记录的顺序与实际接收到的写操作顺序一致。例如,将多个数据写入到主机,该多个数据分别为data1、data2、data3、data4、data5和data6,即该多个数据的写入顺序为data1、data2、data3、data4、data5和data6,则该多个数据被记录到日志文件中,该日志记录的顺序也为data1、data2、data3、data4、data5和data6,其中,data1、data2、data3、data4、data5和data6可以是该多个数据的标识,在日志记录中还可以记录每个被写入的数据的写入时刻。Specifically, taking the above storage system as the Redis system as an example, modify the source code implementation of the Redis component, add the binlog (ie log pipeline) function, record each write operation in the log file, and ensure the order of log records and the actual reception The sequence of the write operations is the same. For example, to write multiple data to the host, the multiple data are data1, data2, data3, data4, data5, and data6 respectively, that is, the writing order of the multiple data is data1, data2, data3, data4, data5, and data6 , The multiple data are recorded in the log file, and the order of the log recording is also data1, data2, data3, data4, data5, and data6. Among them, data1, data2, data3, data4, data5, and data6 can be the multiple The identification of the data can also record the writing time of each written data in the log record.
另外,主机和从机都可以对应有日志文件,即主机和从机都可以执行日志流水功能,用于记录主机和从机的写操作,其中,针对从机的写操作可以理解为是主机对从机的数据同步操作。In addition, both the master and the slave can have log files, that is, both the master and the slave can execute the log pipelining function, which is used to record the write operations of the master and the slave. Among them, the write operation for the slave can be understood as a master pair The data synchronization operation of the slave.
因此,通过上述对写入数据的记录,就能够得到主机被写入的目标数据,其中,目标数据可以是连续被写入的多个数据的集合,也可以是连续被写入的多个数据中的某一个数据。Therefore, through the above-mentioned recording of the written data, the target data written by the host can be obtained, where the target data can be a collection of multiple data continuously written, or multiple data continuously written One of the data in.
S203:在成功将所述目标数据写入所述主机房之后,将所述目标数据同步至所述从机房。S203: After successfully writing the target data into the host room, synchronize the target data to the slave computer room.
具体地,判断是否成功将所述目标数据写入所述主机房,如果成功将所述目标数据写入所述主机房,则将所述目标数据同步至所述从机房。Specifically, it is determined whether the target data is successfully written into the host room, and if the target data is successfully written into the host room, the target data is synchronized to the slave computer room.
其中,判断是否成功将所述目标数据写入所述主机房的实施方式,判断主机被写入目标数据之后,是否成功将目标数据同步至所述主机对应的从机内。具体地,如何判断所述目标数据是否成功同步到所述主机对应的从机的操作可以参考后续实施例。Wherein, it is determined whether the target data is successfully written into the host room in the implementation manner, and after the target data is written into the host, it is determined whether the target data is successfully synchronized to the slave machine corresponding to the host. Specifically, how to determine whether the target data is successfully synchronized to the slave machine corresponding to the master can refer to the subsequent embodiments.
在主机房被写入目标数据之后,该目标数据被存储在主机房对应的存储空间内,然后执行数据同步操作,具体地,可以是上述客户端将主机房被写入的目标数据发送至主机房对应的从机房,使得从机房内所存储的数据也被更新。也就是说,目标数据同步从机房对应的存储空间内。After the target data is written in the host room, the target data is stored in the storage space corresponding to the host room, and then the data synchronization operation is performed. Specifically, the above-mentioned client may send the target data written in the host room to the host The slave room corresponding to the room allows the data stored in the slave room to be updated. In other words, the target data is synchronized from the storage space corresponding to the computer room.
如果所述目标数据成功同步到所述主机对应的从机,则可以确定写入主机的目标数据已经成功同步到该主机对应的从机内,则此时可以将所述目标数据同步至所述从机房。If the target data is successfully synchronized to the slave corresponding to the master, it can be determined that the target data written to the master has been successfully synchronized to the slave corresponding to the master, and then the target data can be synchronized to the slave at this time. From the computer room.
以上述的数据存储系统为例,机房1的主机10被写入目标数据,主机10将目标数据同步至从机11和从机12,在判定从机11和从机12成功同步目标数据之后,将目标数据发送至机房2和机房3,机房2和机房3在获取到目标数据之后,执行该目标数据的同步操作。具体地,主机10将目标数据发送至机房2内的主机20和机房3内的主机30,主机20被写入目标数据,并且将目标数据同步至主机20对应的从机21和从机22,主机30被写入目标数据,并且将目标数据同步至主机20对应的从机31和从机32。Taking the above-mentioned data storage system as an example, the host 10 in the computer room 1 writes target data, and the host 10 synchronizes the target data to the slave 11 and the slave 12. After determining that the slave 11 and the slave 12 successfully synchronize the target data, The target data is sent to the computer room 2 and the computer room 3, and the computer room 2 and the computer room 3 execute the synchronization operation of the target data after obtaining the target data. Specifically, the host 10 sends target data to the host 20 in the computer room 2 and the host 30 in the computer room 3. The host 20 writes the target data, and synchronizes the target data to the slave 21 and the slave 22 corresponding to the host 20. The host 30 is written with target data, and the target data is synchronized to the slave 31 and the slave 32 corresponding to the host 20.
因此,在数据存储系统被请求写入目标数据的时候,即不论是请求在系统的主机房还是从机房内写入数据,都会先将目标数据写入主机房,然后,在成功将所述目标数据写入所述主机房之后,再将目标数据同步至所述从机房。因此,不仅能够避免同时将目 标数据写入多个机房的时候,如果某个机房的数据写入出错,会导致各个机房的数据不一致,而是先对主机房写入数据,并且以主机房的数据为准将所写入主机房的数据同步至从机房,能够更好的保持数据的一致性。Therefore, when the data storage system is requested to write target data, that is, whether it is requested to write data in the host room of the system or from the computer room, the target data will be written to the host room first, and then, after the target is successfully written After the data is written into the host room, the target data is synchronized to the slave computer room. Therefore, not only can it avoid that when the target data is written into multiple computer rooms at the same time, if the data in a certain computer room is written incorrectly, it will cause the data in each computer room to be inconsistent. The data is subject to the synchronization of the data written in the host room to the slave room, which can better maintain data consistency.
请参阅图3,图3示出了一种数据同步方法,该方法的执行主体可以是上述的主机房,具体地,该执行主体可以是主机房内的客户端。具体地,该方法包括:S310至S340。Please refer to FIG. 3, which shows a data synchronization method. The execution subject of the method may be the above-mentioned host room. Specifically, the execution subject may be a client in the host room. Specifically, the method includes: S310 to S340.
S310:监测所述主机房和所述从机房的写入操作。S310: Monitoring the write operation of the host room and the slave computer room.
作为一种实施方式,主机房内的主机内的客户端能够检测针对所有机房的写入操作,例如,通过上述消息队列,主机房订阅所有从机房的消息队列,则在任意从机房被写入数据的时候,都能够监测到从机房的写入操作,而在主机房自己被写入数据的时候,该写入操作也会被写入主机房的消息队列内,从而订阅了主机房的消息对应的从机房也能够知晓主机房被写入数据,数据存储系统内的任意机房被写入数据,都可以看作是对数据存储系统的写入操作。As an implementation manner, the client in the host in the host room can detect write operations for all computer rooms. For example, through the above message queue, the host room subscribes to the message queues of all slave rooms, and then writes in any slave room When data, the write operation from the computer room can be monitored, and when the host room itself is writing data, the write operation will also be written to the message queue of the host room, thus subscribing to the message of the host room The corresponding slave computer room can also know that data is written in the host room, and any computer room in the data storage system can be regarded as a write operation to the data storage system.
因此,通过对各个机房的消息队列的监测,能够在任意机房被写入数据的时候,检测到当前针对数据存储系统的写入操作。Therefore, by monitoring the message queues of each computer room, it is possible to detect the current write operation for the data storage system when data is written in any computer room.
S320:当检测到所述写入操作时,根据该写入操作得到所述目标数据。S320: When the write operation is detected, obtain the target data according to the write operation.
其中,写入操作能够指定请求写入的数据,例如,写入操作可以是一个数据包,在该数据包内包括请求写入的数据,主机房在监测到该写入操作的时候,能够解析该写入操作得到请求写入的数据。Among them, the write operation can specify the data requested to be written. For example, the write operation can be a data packet that includes the data requested to be written. The host room can analyze the data when the write operation is monitored. The write operation obtains the data requested to be written.
作为一种实施方式,在写入操作只有一个的时候,可以将该请求写入的数据作为目标数据。As an implementation manner, when there is only one write operation, the data requested to be written may be used as the target data.
作为另一种实施方式,如果写入操作有多个,则确定每个写入操作对应的请求写入的数据,如果所有写入操作的请求写入的数据都相同,则可以任选一个写入操作对应的请求写入的数据,作为目标数据。As another implementation manner, if there are multiple write operations, the data requested to be written corresponding to each write operation is determined. If the data requested to be written for all write operations are the same, you can choose one to write. The data requested to be written corresponding to the input operation is used as the target data.
作为又一种实施方式,如果写入操作有多个,然后,确定每个写入操作的数据修改请求是相同,查找出数据修改请求相同的写入操作。其中,数据修改请求可以是所请求写入的数据相同并且所请求更改的数据对象相同,其中,所请求更改的数据对象可以是主机房或从机房内存储的某个待修改内容,也可以是新增加的数据。具体地,写入操作对应待修改内容和请求写入的数据,则该写入操作用于将待修改内容修改为请求写入的数据。As yet another implementation manner, if there are multiple write operations, then it is determined that the data modification request of each write operation is the same, and a write operation with the same data modification request is found. Among them, the data modification request can be that the data requested to be written is the same and the data object requested to be modified is the same. The data object requested to be modified can be a certain content to be modified stored in the host room or the slave computer room, or it can 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 designated data stored in the computer room, and when the write operation is performed, the designated data is modified to the data requested to be written. If the write operation is newly added data, the content to be modified is the storage space in the computer room, and when the write operation is performed, the data requested to be written is written in the storage space.
因此,在写入操作为多个的时候,确定每个写入操作对应的待修改内容,根据该待修改内容将多个写入操作区分,以得到对应不同待修改内容的写入操作,即不同的修改目的的写入操作。另外,如果该待修改内容为指定数据,则在各个机房内的每个数据都对应有标识,且该标识是在各个机房内统一,例如,主机房内存储的数据中包括data1,则在从机房内所存储的数据被也包括data1,并且,在主机房内的data1和从机房内的data1应当保持数据一致性。Therefore, when there are multiple write operations, the content to be modified corresponding to each write operation is determined, and multiple write operations are distinguished according to the content to be modified to obtain write operations corresponding to different content to be modified, that is, Write operations for different modification purposes. In addition, if the content to be modified is specified data, each data in each computer room has a corresponding identifier, and the identifier is unified in each computer room. For example, if the data stored in the host room includes data1, The data stored in the computer room is also included in data1, and data1 in the host room and data1 in the slave computer room should maintain data consistency.
因此,如果该待修改内容为指定数据,则获取该指定数据的标识,将指定数据的标识相同的写入操作作为相同修改目的的写入操作。而如果待修改内容为存储空间,则可以将每个待修改内容为存储空间的写入操作作为一个修改目的的写入操作,也可以是,如果写入操作为新增加数据,则会为该写入操作配置一个数据标识,该数据标识为新增加的标识,则在数据写入到机房内的时候,数据标识也对应到机房内。Therefore, if the content to be modified is designated data, the identifier of the designated data is obtained, and a write operation with the same identifier of the designated data is regarded as a write operation with the same modification purpose. If the content to be modified is a storage space, each write operation in which the content to be modified is a storage space can be used as a modification purpose write operation, or if the write operation is a newly added data, it will be The write operation configures a data identifier, and the data identifier is a newly added identifier. When data is written into the computer room, the data identifier also corresponds to the computer room.
例如,写入操作分别为操作1、操作2、操作3、操作4、操作5、操作6和操作7,操作1、操作2、操作3对应的待修改内容是data1,操作4和操作5用于增加一个数据,所增加的数据的标识为data7,操作6用于增加一个数据,所增加的数据的标识为data8,操作7用于增加一个数据,所增加的数据的标识为data9。For example, the write operations are operation 1, operation 2, operation 3, operation 4, operation 5, operation 6, and operation 7. The content to be modified corresponding to operation 1, operation 2, and operation 3 is data1, and operation 4 and operation 5 are used For adding a piece of data, the identifier of the added data is data7, operation 6 is used to add a piece of data, the identifier of the added data is data8, operation 7 is used to add a piece of data, and the identifier of the added data is data9.
则上述的7个写入操作可以分为四个修改目的,分别为修改目的1、修改目的2、修改目的3和修改目的4,修改目的1对应的写入操作为操作1、操作2和操作3,修改目的2对应的写入操作为操作4和操作5,修改目的3对应的写入操作为操作6,修改目的4对应的写入操作为操作7。Then the above-mentioned 7 write operations can be divided into four modification goals, namely modification goal 1, modification goal 2, modification goal 3, and modification goal 4. The write operations corresponding to modification goal 1 are operation 1, operation 2, and operation. 3. The write operations corresponding to modification purpose 2 are operations 4 and 5, the write operation corresponding to modification purpose 3 is operation 6, and the write operation corresponding to modification purpose 4 is operation 7.
从而,针对不同的修改目的,确定每个修改目的对应的写入操作,具体地,确定每个修改目的对应的写入操作的实施方式可以参考图4中的步骤S321至S323。而针对每个修改目的,均可以执行S321至S323,确定每个修改目的对应的写入操作。Therefore, for different modification purposes, the write operation corresponding to each modification purpose is determined. Specifically, for the implementation of determining the write operation corresponding to each modification purpose, reference may be made to steps S321 to S323 in FIG. 4. For each modification purpose, S321 to S323 can be executed to determine the write operation corresponding to each modification purpose.
S321:若所述写入操作为多个,获取每个所述写入操作对应的时间戳。S321: If there are multiple write operations, obtain a timestamp corresponding to each write operation.
其中,每个所述写入操作对应指定数据,用于将待修改内容修改为指定数据。每个写入操作对应的指定数据可以相同,也可以不相同。Wherein, each of the write operations corresponds to designated data, and is used to modify the content to be modified into designated data. The designated data corresponding to each write operation can be the same or different.
作为一种实施方式,每个写入操作对应一个时间戳,该时间戳用于记录该写入操作对应的时刻。具体地,在业务层输入一个请求写入指定数据的写入请求至数据存储系统的时候,数据存储系统为该写入请求配置一个时间戳,并且将该写入请求作为一次写入操作,从而,能够为该写入操作配置一个时间戳。As an implementation manner, each write operation corresponds to a time stamp, and the time stamp is used to record the time corresponding to the write operation. Specifically, when a write request requesting to write specified data is input to the data storage system at the business layer, the data storage system configures a timestamp for the write request and treats the write request as a write operation, thereby , Can configure a time stamp for the write operation.
S322:根据所述时间戳由多个所述写入操作内确定为目标写入操作。S322: Determine the target write operation from among the multiple write operations according to the timestamp.
其中,该时间戳能够作为写入操作对应的请求写入指定数据的时刻,即能够作为不同的写入操作的写入时刻。作为一种实施方式,可以根据各个写入操作的时间戳的早晚顺序确定目标写入操作。例如,选择最早或最晚的时间戳对应的写入操作作为目标写入操作。Wherein, the timestamp can be used as the time when the specified data is requested to be written corresponding to the write operation, that is, it can be used as the write time of a different write operation. As an implementation manner, the target write operation may be determined according to the order of the time stamp of each write operation. For example, select the write operation corresponding to the earliest or latest time stamp as the target write operation.
具体地,多个写入操作对应的时间戳可能相同,也可能不全相同,则针对全相同和不全相同的情况,根据所述时间戳由多个所述写入操作内确定为目标写入操作的实施方式可以不同。Specifically, the timestamps corresponding to multiple write operations may be the same or may not be all the same, so for all the same and not all the same, according to the timestamp, the target write operation is determined from the multiple write operations. The implementation can be different.
具体地,判断各个所述写入操作对应的时间戳是否全相同,如果若所述时间戳不全相同,确定所有的时间戳中最晚的时间戳,作为目标时间戳。Specifically, it is determined whether the time stamps corresponding to each of the write operations are all the same, and if the time stamps are not all the same, the latest time stamp among all the time stamps is determined as the target time stamp.
其中,时间戳不全相同,可以是所有的时间戳中,存在相同的时间戳,也存在不相同的时间戳,即并非所有的时间戳全都一样。则可以将所有的时间戳按照时间先后顺序排序,得到时间序列,将时间序列中最后的时间戳作为目标时间戳。Among them, the time stamps are not all the same, and it may be that all time stamps have the same time stamp or different time stamps, that is, not all time stamps are the same. Then, all the time stamps can be sorted in chronological order to obtain a time series, and the last time stamp in the time series can be used as the target time stamp.
然后,将所述目标时间戳对应的写入操作作为待选写入操作。其中,最晚的时间戳可能包括多个时间戳,即可以得到多个最晚的时间戳,则每个最晚的时间戳对应的写入操作,都可以作为待选写入操作。Then, the write operation corresponding to the target timestamp is used as a write operation to be selected. Among them, the latest time stamp may include multiple time stamps, that is, multiple latest time stamps can be obtained, and the write operation corresponding to each latest time stamp can be used as a write operation to be selected.
作为另一种实施方式,可以将所有的写入操作按照时间戳的时间顺序排序,得到待选序列。其中,待选序列内包括多个写入操作的标识,该写入操作的标识可以是用于记录每个写入操作的身份信息。且在该待选序列内,每个写入操作的标识对应一个序号,且序号越靠前的写入操作所对应的时间戳越早,即按照时间戳的时间先后顺序对写入操作排序,得到该待选序列。然后,将待选序列内,最靠前的写入操作作为待选写入操作。其中,如果有多个写入操作的时间戳是相同的,则相同的时间戳的写入操作对应的序号是相同的,因此,所获取的待选写入操作可以是多个,其中,每个待选写入操作对应的时间戳相同,且在所有的写入操作对应的时间戳中,每个待选写入操作对应的时间戳均为最晚的时间戳。As another implementation manner, all the write operations may be sorted according to the time sequence of the timestamp to obtain the candidate sequence. Wherein, the sequence to be selected includes multiple write operation identifiers, and the write operation identifiers may be used to record the identity information of each write operation. And in the candidate sequence, the identifier of each write operation corresponds to a serial number, and the earlier the serial number the write operation corresponds to the earlier the timestamp, that is, the write operations are sorted according to the chronological order of the timestamps, Get the candidate sequence. Then, the first write operation in the sequence to be selected is regarded as the write operation to be selected. Among them, if there are multiple write operations with the same time stamp, the sequence numbers corresponding to the write operations of the same time stamp are the same. Therefore, the obtained candidate write operations can be multiple, where each The timestamps corresponding to the write operations to be selected are the same, and among the timestamps corresponding to all write operations, the timestamp corresponding to each write operation to be selected is the latest timestamp.
然后,由所述待选写入操作内确定目标写入操作。若所述待选写入操作的数量为1, 则将所述待选写入操作作为目标写入操作。若所述待选写入操作的数量为至少两个,确定每个所述待选写入操作对应的操作对象,所述操作对象包括主机房或从机房。其中,操作对象可以是业务层在请求存储数据的时候,所指定写入的机房,具体地,在数据写入请求包括机房的标识,并且在预先设定主机房和从机房的时候,能够将每个机房的标识对应一个标签,该标签包括主机房标签和从机房标签,因此,通过数据写入请求内包括的机房的标识,能够确定该机房的标识对应的机房的标签是主机房标签还是从机房标签,进而能够确定被请求写入数据的机房为主机房还是从机房,即确定每个写入操作对应的操作对象。Then, the target write operation is determined from the to-be-selected write operation. If the number of the write operation to be selected is 1, then the write operation to be selected is taken as the target write operation. If the number of the write operations to be selected is at least two, an operation object corresponding to each write operation to be selected is determined, and the operation object includes a host room or a slave computer room. Among them, the operation object can be the computer room designated to be written when the business layer requests to store data. Specifically, the data write request includes the identifier of the computer room, and when the host room and the slave computer room are preset, the computer room can be The identification of each computer room corresponds to a tag, which includes the host room tag and the slave computer room tag. Therefore, through the identification of the computer room included in the data write request, it can be determined whether the tag of the computer room corresponding to the identification of the computer room is the host room tag or From the computer room tag, it can then be determined whether the computer room requested to write data is the host room or the slave computer room, that is, the operation object corresponding to each write operation can be determined.
将所述操作对象为主机房的待选写入操作作为目标写入操作。The write operation to be selected in the host room as the operation object is taken as the target write operation.
例如,以上述所举例的多个写入操作包括操作1、操作2、操作3、操作4、操作5、操作6和操作7为例,且操作1、操作2、操作3、操作4、操作5、操作6和操作7对应的时间戳为时间t1、时间t2、时间t3、时间t4、时间t5、时间t6、时间t7。按照时间先后顺序,各个时间戳的时间早晚顺序分别为时间t1、时间t2、(时间t3和时间t4)、(时间t5、时间t6和时间t7),即时间t3和时间t4相同,时间t5、时间t6和时间t7的时间相同,则可以理解为,最先获取操作1,之后获取到操作2,再之后,同时获取到操作3和操作4,最后又同时获取到操作5、操作6和操作7。For example, take the above-mentioned multiple write operations including operation 1, operation 2, operation 3, operation 4, operation 5, operation 6 and operation 7 as an example, and operation 1, operation 2, operation 3, operation 4, operation 5. The time stamps corresponding to operation 6 and operation 7 are time t1, time t2, time t3, time t4, time t5, time t6, and time t7. In chronological order, the time sequence of each time stamp is time t1, time t2, (time t3 and time t4), (time t5, time t6, and time t7) respectively, that is, time t3 and time t4 are the same, time t5, Time t6 and time t7 are the same time, it can be understood that operation 1 is obtained first, operation 2 is obtained later, operation 3 and operation 4 are obtained at the same time, and operation 5, operation 6 and operation are obtained at the same time. 7.
则可以确定待选写入操作为操作5、操作6和操作7,然后,从操作5、操作6和操作7确定一个目标写入操作。Then, it can be determined that the write operations to be selected are operation 5, operation 6, and operation 7, and then, a target write operation is determined from operation 5, operation 6 and operation 7.
作为一种实施方式,可以是确定操作5、操作6和操作7各自对应的操作对象,例如,操作5、操作6和操作7各自对应的操作对象分别为主机房、从机房1和从机房2。则操作对象为主机房的待选写入操作为操作5,从而可以确定目标写入操作为操作5。As an implementation manner, the operation object corresponding to operation 5, operation 6 and operation 7 may be determined. For example, the operation objects corresponding to operation 5, operation 6 and operation 7 are master room, slave room 1 and slave room 2 respectively. . Then, the write operation to be selected in the host room as the operation object is operation 5, so that it can be determined that the target write operation is operation 5.
另外,如果所确定的待选写入操作只有一个,例如,是操作1,则可以直接将操作1作为目标写入操作。In addition, if there is only one write operation to be selected, for example, operation 1, then operation 1 can be directly used as the target write operation.
作为另一种实施方式,如果检测到所述写入操作时,每个所述写入操作对应的时间戳全相同,则可以不必执行查找最晚的时间戳的写入操作,而直接获取每个写入操作对应的操作对象,该操作对象可以参考前述描述,在此不再赘述。As another implementation manner, if the time stamps corresponding to each of the write operations are all the same when the write operation is detected, it is not necessary to perform the write operation of finding the latest time stamp, and directly obtain each time stamp. For the operation object corresponding to the write operation, the operation object can refer to the foregoing description, which will not be repeated here.
具体地,若每个写入操作的时间戳全相同,确定每个所述待选写入操作对应的操作对象,所述操作对象包括主机房或从机房;将所述操作对象为主机房的待选写入操作作为目标写入操作。Specifically, if the timestamps of each write operation are all the same, the operation object corresponding to each of the write operations to be selected is determined, and the operation object includes the host room or the slave computer room; and the operation object is the host room's The write operation to be selected is regarded as the target write operation.
S323:将所述目标写入操作对应的指定数据作为目标数据。S323: Use the designated data corresponding to the target write operation as target data.
示例性地,假设,当前所获取的写入操作一共包括操作1、操作2、操作3、操作4、操作5、操作6、操作7、操作8、操作9和操作10,其中,操作1、操作2、操作3、操作4、操作5、操作6和操作7对应的待修改内容为data1,操作8、操作9和操作10对应的待修改内容为data7,且data1存在于所有的机房内,操作1、操作2、操作3、操作4、操作5、操作6和操作7的目的是修改data1的数据,假设操作1、操作2、操作3、操作4、操作5、操作6和操作7对应的指定数据分别为数据1、数据2、数据3、数据4、数据5、数据6、数据7,假设操作1、操作2、操作3、操作4、操作5、操作6和操作7对应的操作对象分别为从机房1、从机房2、主机房、从机房3、主机房、从机房1和从机房2。例如,操作1的目的是将从机房1中存储的data1修改为数据1。Exemplarily, suppose that the currently acquired write operation includes operation 1, operation 2, operation 3, operation 4, operation 5, operation 6, operation 7, operation 8, operation 9 and operation 10, in which operation 1, The content to be modified corresponding to operation 2, operation 3, operation 4, operation 5, operation 6 and operation 7 is data1, and the content to be modified corresponding to operation 8, operation 9 and operation 10 is data7, and data1 exists in all computer rooms, The purpose of operation 1, operation 2, operation 3, operation 4, operation 5, operation 6 and operation 7 is to modify the data of data1, assuming that operation 1, operation 2, operation 3, operation 4, operation 5, operation 6 and operation 7 correspond The specified data are data 1, data 2, data 3, data 4, data 5, data 6, and data 7. Assume that operation 1, operation 2, operation 3, operation 4, operation 5, operation 6 and operation 7 correspond to the operation The objects are slave room 1, slave room 2, master room, slave room 3, master room, slave room 1 and slave room 2. For example, the purpose of operation 1 is to modify data1 stored in computer room 1 to data 1.
然后,操作5、操作6和操作7对应的时间戳最晚,则可以确定目标写入操作为操作对象为主机房的操作5,确定的目标数据为数据5,最终本次在对data1的修改方式确定为将主机房内的数据data1修改为数据5,并且将数据5同步至其他的从机房,使得所有的从机房的data1都被修改为数据5。Then, if the timestamps corresponding to operation 5, operation 6 and operation 7 are the latest, it can be determined that the target write operation is operation 5 in the host room, and the determined target data is data 5. Finally, the modification of data1 is performed this time The method is determined to modify the data data1 in the master room to data 5, and synchronize the data 5 to other slave computer rooms, so that all data1 in the slave computer rooms are modified to data 5.
然后,在完成各个机房的data1修改为数据5的操作之后,再依据操作8、操作9 和操作10修改所有机房的data7,则确定目标数据的方式可以参考前述,修改方式也是先修改主机内的data7,然后再依次同步。Then, after completing the operation of modifying data1 of each computer room to data 5, and then modify data7 of all computer rooms according to operation 8, operation 9 and operation 10, the method of determining the target data can refer to the foregoing, and the modification method is also to modify the host computer first data7, and then synchronize sequentially.
S330:将所述目标数据写入所述主机房。S330: Write the target data into the host room.
S340:在成功将所述目标数据写入所述主机房之后,将所述目标数据同步至所述从机房。S340: After successfully writing the target data into the host room, synchronize the target data to the slave computer room.
请参阅图5,图5示出了一种数据同步方法,该方法的执行主体可以是上述的主机房,具体地,该执行主体可以是主机房内的客户端。具体地,该方法包括:S510至S550。Please refer to FIG. 5. FIG. 5 shows a data synchronization method. The execution subject of the method may be the aforementioned host room. Specifically, the execution subject may be a client in the host room. Specifically, the method includes: S510 to S550.
S510:获取请求写入所述数据存储系统的目标数据。S510: Obtain the target data requested to be written to the data storage system.
S520:将所述目标数据写入所述主机房。S520: Write the target data into the host room.
S530:在成功将所述目标数据写入所述主机房之后,将所述目标数据同步至指定机房。S530: After successfully writing the target data into the host room, synchronize the target data to the designated computer room.
其中,指定机房为多个所述从机房中的一个从机房。Wherein, the designated machine room is one of the plurality of slave machine rooms.
作为一种实施方式,可以将每个从机房设置一个同步状态,该同步状态包括未同步和已同步,则每次从未同步的从机房中选中一个从机房作为指定机房,将所述目标数据同步至指定机房,在成功将该目标数据同步至指定机房的时候,会更改指定机房对应的同步状态,比如,将未同步修改为已同步。As an implementation manner, each slave room can be set to a synchronization state, the synchronization state includes unsynchronized and synchronized, then each time a slave room is selected from the unsynchronized slave room as the designated room, the target data Synchronize to the specified computer room. When the target data is successfully synchronized to the specified computer room, the synchronization status corresponding to the specified computer room will be changed, for example, change the synchronization status from unsynchronized to synchronized.
作为一种实施方式,可以预先设定一个同步顺序,主机房按照该同步顺序将目标数据同步至所有的从机房,则按照该同步顺序依次选择一个从机房作为指定机房。As an implementation manner, a synchronization sequence may be preset, and the host room synchronizes the target data to all the slave computer rooms according to the synchronization sequence, and then selects a slave computer room as the designated computer room in sequence according to the synchronization sequence.
S540:判断是否成功将数据同步至所述指定机房。S540: Determine whether the data is successfully synchronized to the designated computer room.
作为一种实施方式,可以根据从机房回复的信息来确定是否所述目标数据成功同步到所述主机房对应的从机房,还可以是根据上述的主机房和从机房的数据写入记录,即主机房和从机房的日志文件来确定是否所述目标数据成功同步到所述主机房对应的从机房。As an implementation manner, it can be determined whether the target data is successfully synchronized to the slave computer room corresponding to the master room according to the information replies from the computer room, or it can be based on the above-mentioned data writing record of the master room and the slave computer room, that is, The log files of the host room and the slave computer room are used to determine whether the target data is successfully synchronized to the slave computer room corresponding to the host room.
具体地,判断是否成功将数据同步至所述指定机房的实施方式可以是,检测是否接收到所述指定机房反馈的同步成功的信息;如果接收到,则判定成功将数据同步至所述指定机房;如果未接收到,则判定未成功将数据同步至所述指定机房。Specifically, an implementation manner for determining whether the data is successfully synchronized to the designated computer room may be to detect whether the synchronization success information fed back by the designated computer room is received; if it is received, it is determined that the data is successfully synchronized to the designated computer room. ; If it is not received, it is determined that the data has not been successfully synchronized to the designated computer room.
其中,同步成功的信息可以是从机房在收到目标数据并且成功存储之后发送至主机房的,主机房在接收到该信息之后就能够判定所述目标数据成功同步到所述主机房对应的从机房。The successful synchronization information may be sent from the computer room to the host room after the target data is received and successfully stored. After receiving the information, the host room can determine that the target data is successfully synchronized to the corresponding slave in the host room. engine room.
作为一种实施方式,可以是判定在预定时间段内是否接收到指定机房反馈的同步成功的信息。其中,预定时间段的时间起点可以是执行将所述目标数据同步到与所述主机房对应的从机房的操作的时间点,该预定时间段的预定时间长度可以是预先确定的,例如,可以是根据经验而设置的。具体地,可以是统计从机房同步数据的时间长度,根据该时间长度确定预定时间段的预定时间长度。As an implementation manner, it may be determined whether the synchronization success information fed back by the designated computer room is received within a predetermined period of time. Wherein, the time starting point of the predetermined time period may be the time point at which the operation of synchronizing the target data to the slave computer room corresponding to the host room is performed, and the predetermined time length of the predetermined time period may be predetermined, for example, It is set based on experience. Specifically, it may be to count the length of time for synchronizing data from the computer room, and determine the predetermined time length of the predetermined time period according to the time length.
作为一种实施方式,可以是获取从机房同步多个数据的时间长度,根据多个时间长度确定预定时间段的预定时间长度。具体地,计算得到该多个时间长度的平均值,将该平均值作为预定时间段的预定时间长度。As an implementation manner, the time length for synchronizing multiple data from the computer room may be acquired, and the predetermined time length of the predetermined time period is determined according to the multiple time lengths. Specifically, the average value of the multiple time lengths is calculated, and the average value is used as the predetermined time length of the predetermined time period.
作为另一种实施方式,可以是统计得到从机房同步数据的速率,根据该目标数据的数据大小和所统计得到的同步数据的速率得到该预定时间段的预定时间长度。例如,获取目标数据的数据大小与所统计得到的同步数据的速率的比值作为该预定时间段的预定时间长度。As another implementation manner, the rate of synchronizing data from the computer room may be obtained by statistics, and the predetermined time length of the predetermined period of time may be obtained according to the data size of the target data and the rate of the synchronized data obtained by the statistics. For example, the ratio of the data size of the acquired target data to the rate of the synchronized data obtained by statistics is used as the predetermined time length of the predetermined time period.
作为一种实施方式,请参阅图6,判断是否所述目标数据成功同步到所述指定机房的实施方式可以包括:S541至S543。As an implementation manner, referring to FIG. 6, the implementation manner of determining whether the target data is successfully synchronized to the designated computer room may include: S541 to S543.
S541:获取所述主机房对应的第一记录信息,所述第一记录信息用于记录所述主机 房执行的被写入目标数据的操作。S541: Acquire first record information corresponding to the host room, where the first record information is used to record the operation performed by the host room to write target data.
作为一种实施方式,该第一记录信息包括主机房每次被写入的数据的标识和操作时刻,其中,该操作时刻用于记录该写入数据的写入时间点,其中,该写入的数据的标识可以是主机房为每个写入数据分配的标识,其中,该标识可以是根据该数据的内容而确定的标识,例如,可以是根据该数据的数据摘要而生成该数据的标识,作为一种实施方式,可以是将该目标数据的数据摘要作为该目标数据的标识。其中,数据摘要可以是用于描述该目标数据的内容。则该第一记录信息内包括目标数据的目标标识对应的写入时间。As an implementation manner, the first recording information includes the identification and operation time of the data written each time in the host room, where the operation time is used to record the writing time point of the written data, wherein the writing The identification of the data may be an identification assigned by the host room for each written data, where the identification may be an identification determined according to the content of the data, for example, it may be an identification of the data generated based on the data summary of the data As an implementation manner, the data summary of the target data may be used as the identifier of the target data. Among them, the data summary can be used to describe the content of the target data. Then the first record information includes the writing time corresponding to the target identifier of the target data.
S542:获取所述指定机房对应的第二记录信息,所述第二记录信息用于记录所述指定机房执行的目标数据的数据同步的操作。S542: Acquire second record information corresponding to the designated computer room, where the second record information is used to record the data synchronization operation of the target data performed by the designated computer room.
同理,该第二记录信息内包括从机房每次被同步的数据的标识和操作时刻,其中,该操作时刻可以是从机房被同步的数据的时刻,该数据的标识的实施方式可以参考前述实施例,在此不再赘述。每个从机房均对应第二记录信息,因此,每次从机房的第二记录信息都可以是指定机房的第二记录信息。In the same way, the second record information includes the identifier and operation time of the data synchronized each time from the computer room, where the operation time may be the time when the data is synchronized from the computer room, and the implementation of the data identifier can refer to the foregoing The embodiments are not repeated here. Each slave computer room corresponds to the second record information. Therefore, each second record information of the slave computer room can be the second record information of the designated computer room.
S543:根据所述第一记录信息和所述第二记录信息判断是否成功将数据同步至所述指定机房。S543: Determine whether the data is successfully synchronized to the designated computer room according to the first record information and the second record information.
其中,第一记录信息内包括主机房被写入数据的标识和该标识对应的写入时间点,第二记录信息内包括从机房被同步的数据的标识和该标识对应的同步时刻,则能够根据该主机房被写入数据的标识和该标识对应的写入时间点以及指定机房被同步的数据的标识和该标识对应的同步时刻判断是否所述目标数据成功同步到所述指定机房。Wherein, the first record information includes the identifier of the data being written in the host room and the writing time point corresponding to the identifier, and the second record information includes the identifier of the data synchronized from the computer room and the synchronization time corresponding to the identifier. Determine whether the target data is successfully synchronized to the designated computer room according to the identifier of the data written in the host room and the write time point corresponding to the identifier, and the identifier of the data synchronized to the designated computer room and the synchronization time corresponding to the identifier.
作为一种实施方式,判断所述第一记录信息内的第一操作时间点是否早于所述第二记录信息内的第二操作时间点;若早于,则判定成功将数据同步至所述指定机房;若未早于,则判定未成功将数据同步至所述指定机房。其中,第一操作时间点为第一记录信息内所记录的主机房被写入目标数据的目标标识对应的写入时间点,第二操作时间点为第二记录信息内所记录的指定机房被同步目标数据的目标标识对应的同步时刻,判断该同步时刻是否晚于写入时间点,如果是,则判定所述目标数据成功同步到所述指定机房,否则,判定所述目标数据未成功同步到所述指定机房。As an implementation manner, it is determined whether the first operation time point in the first record information is earlier than the second operation time point in the second record information; if it is earlier, it is determined that the data is successfully synchronized to the Designated computer room; if it is not earlier, it is determined that the data has not been successfully synchronized to the designated computer room. Among them, the first operation time point is the writing time point corresponding to the target identifier of the target data written in the host room recorded in the first record information, and the second operation time point is the designated computer room data recorded in the second record information. Synchronize the synchronization time corresponding to the target identifier of the synchronization target data, determine whether the synchronization time is later than the writing time point, if yes, determine that the target data is successfully synchronized to the designated computer room, otherwise, determine that the target data is not successfully synchronized Go to the designated computer room.
具体地,可以是判断第二记录信息内是否存在目标数据的标识对应的同步时刻,如果存在,再执行判断该同步时刻是否晚于写入时间点的操作。其中,判断第二记录信息内是否存在目标数据的标识对应的同步时刻的实施方式可以是在预定时间段内判断第二记录信息内是否存在目标数据的标识对应的同步时刻,其中,该预定时间段的实施方式可以参考前述实施例。Specifically, it may be judged whether the synchronization time corresponding to the identifier of the target data exists in the second record information, and if it exists, the operation of judging whether the synchronization time is later than the writing time point is performed. Wherein, the implementation 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 period of time, where the predetermined time For the implementation of the segments, reference may be made to the foregoing embodiments.
作为另一种实施方式,考虑到记录主机房的写入操作和从机房的数据同步操作的方式可以是上述的日志文件,即通过日志流水的方式记录主机的写入操作和从机的数据同步操作,则可以为主机房和从机房均设置一个序列号,通过该序列号记录主机的每个写入操作和从机的每个数据同步操作。As another implementation manner, it is considered that the method of recording the write operation of the host room and the data synchronization operation of the slave computer room can be the above-mentioned log file, that is, the write operation of the host and the data synchronization of the slave are recorded in a log stream. Operation, you can set a serial number for both the master room and the slave room, and each write operation of the master and every data synchronization operation of the slave can be recorded through the serial 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 room is successfully written into the target data. Specifically, one can be predefined The first serial number, the initial value of the first serial number is the first initial value, then every time data is written in the host room, the value of the first serial number is updated according to the first update rule, where the The first update rule can be to increase or decrease a certain value, that is, each time a write operation is performed, a certain value is increased or decreased on the basis of the first serial number saved last time.
例如,该第一序列号的初始值为第一初始值,第一更新规则为增加第一数值,在主机房的第一次写入数据的时候,该第一序列号的数值变为第一初始值与第一数值之和, 再次写入数据之后,该第一序列号的数值变为第一初始值与两个第一数值之和,即在上次保存的第一序列号的基础上增加了第一数值。For example, the initial value of the first serial number is the first initial value, and the first update rule is to increase the first value. When the host room writes data for the first time, the value of the first serial number becomes the first The sum of the initial value and the first value. After the 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, on the basis of the first serial number saved last time Increased the first value.
于本申请实施例中,假设第一序列号为seq1,初始值为0,则第一次写数据之后,该第一序列号seq1的数值变为1,第二次写数据之后,该第一序列号seq1的数值变为2,依次类推,如果被写入的数据包括多个数据,该多个数据分别为data1、data2、data3、data4、data5和data6,数据标识和序列号seq1的数值的对应关系为:data1、data2、data3、data4、data5和data6对应的序列号seq1依次为1、2、3、4、5和6。In the embodiment of the present application, assuming that the first sequence number is seq1 and the initial value is 0, then after the data is written for the first time, the value of the first sequence number seq1 becomes 1, and after the data is written for the second time, the first The value of the serial number seq1 becomes 2, and so on, if the data to be written includes multiple data, the multiple data are data1, data2, data3, data4, data5, and data6, respectively, the data identifier and the value of the serial number seq1 The corresponding relationship is: the sequence numbers seq1 corresponding to data1, data2, data3, data4, data5, and data6 are 1, 2, 3, 4, 5, and 6 in order.
由此,通过上述对应关系能够得到每个写入数据的写入顺序,以及每个写入数据的标识对应的序列号,则该序列号可以作为该写入数据的流水号,能够记录在整个写入操作过程中,目标数据是第几个被写入的。Therefore, the writing sequence of each written data and the serial number corresponding to the identifier of each written data can be obtained through the above-mentioned correspondence relationship. The serial number can be used as the serial number of the written data and can be recorded in the entire During the write operation, which target data is written first.
同理,所述第二记录信息为第二序列号,所述第二序列号用于在所述指定机房成功同步数据时,根据第二更新规则执行更新操作。其中,第二更新规则可以与上述第一更新规则相同,则第二更新规则也可以是增加第二数值。具体地,该第二序列号的初始值为第二初始值,第二更新规则为增加第二数值,在从机房的第一次同步数据的时候,该第二序列号的数值变为第二初始值与第二数值之和,再次同步数据之后,该第二序列号的数值变为第二初始值与两个第二数值之和,即在上次保存的第二序列号的基础上增加了第二数值。其中,第一数值和第二数值相同,例如,都是1,第一初始值和第二初始值也可以相同,例如,都可以是0。Similarly, the second record information is a second serial number, and the second serial number is used to perform an update operation according to a second update rule when the designated computer room successfully synchronizes data. Wherein, the second update rule may be the same as the above-mentioned first update rule, and the second update rule may also be to increase the second value. Specifically, the initial value of the second serial number is the second initial value, and the second update rule is to increase the second value. When synchronizing data from the computer room for the first time, the value of the second serial number becomes the second The sum of the initial value and the second value. After synchronizing the data again, the value of the second serial number becomes the sum of the second initial value and two second values, that is, it is added to the second serial number saved last time. The second value. Wherein, the first value and the second value are the same, for example, both are 1, and the first initial value and the second initial value may also be the same, for example, both may be 0.
假设第二序列号为seq2,则初始值为0,则第一次从机房同步数据之后,该第二序列号seq2的数值变为1,第二次同步数据之后,该第二序列号seq2的数值变为2,依次类推,如果被同步的数据包括多个数据,该多个数据分别为data1、data2、data3、data4、data5和data6,数据标识和序列号seq2的数值的对应关系为:data1、data2、data3、data4、data5和data6对应的序列号seq2依次为1、2、3、4、5和6。Assuming that the second sequence number is seq2, the initial value is 0. After synchronizing data from the computer room for the first time, the value of the second sequence number seq2 becomes 1, and after the second time synchronizing data, the value of the second sequence number seq2 The value becomes 2, and so on. If the synchronized data includes multiple data, the multiple data are data1, data2, data3, data4, data5, and data6 respectively. The corresponding relationship between the data identifier and the value of the serial number seq2 is: data1 The sequence numbers seq2 corresponding to, data2, data3, data4, data5, and data6 are 1, 2, 3, 4, 5, and 6, respectively.
需要说明的是,从机的seq2是在从机被成功同步数据的时候,该seq2的数据才会更改,则通过确定当前的seq2的大小与主机被写入的目标数据对应的seq1的大小关系,能够确定从机是否将目标数据成功同步。It should be noted that the seq2 of the slave is only changed when the data is successfully synchronized by the slave, and the size relationship of the seq1 corresponding to the target data written by the host is determined by determining the size of the current seq2 , Can determine whether the slave successfully synchronizes the target data.
因此,可以根据第一序列号和第二序列号的大小关系确定是否成功将数据同步至所述指定机房,具体地,根据所述第一记录信息和所述第二记录信息判断是否成功将数据同步至所述指定机房的实施方式可以是:获取所述第一序列号和所述第二序列号之间的大小关系;如果所述大小关系满足指定条件,则判定成功将数据同步至所述指定机房,其中,所述大小关系满足指定条件表明所述指定机房在所述主机房被写入所述目标数据之后成功同步所述目标数据;如果所述大小关系不满足指定条件,则判定未成功将数据同步至所述指定机房。Therefore, it can be determined whether the data is successfully synchronized to the designated computer room according to the size relationship between the first serial number and the second serial number. Specifically, it is determined whether the data is successfully synchronized according to the first record information and the second record information. The implementation manner of synchronizing to the designated computer room may be: obtaining the size relationship between the first serial number and the second serial number; if the size relationship satisfies a specified condition, it is determined that the data is successfully synchronized to the A designated computer room, wherein the size relationship satisfies a specified condition indicates that the designated computer room successfully synchronizes the target data after the host room is written with the target data; if the size relationship does not meet the specified condition, it is determined not to The data is successfully synchronized to the designated computer room.
其中,该大小关系可以是第一序列号是否小于或等于第二序列号,或者其他的能够表征第一序列号是否小于或等于第二序列号的大小关系,例如,也可以是获取该第一序列号和所述第二序列号之间比值,如果该比值大于1,则表明第一序列号大于第二序列号,如果该比值不大于1,则表明第一序列号小于或等于第二序列号。Wherein, the size relationship can be whether the first serial number is less than or equal to the second serial number, or another size relationship that can characterize whether the first serial number is less than or equal to the second serial number, for example, it can also be to obtain the first serial number. The ratio between the serial number and the second serial number. If the ratio is greater than 1, it indicates that the first serial number is greater than the second serial number; if the ratio is not greater than 1, it indicates that the first serial number is less than or equal to the second serial number. No.
作为一种实施方式,该大小关系可以根据第一更新规则和第二更新规则而确定,如果该第一更新规则和第二更新规则相同,且都是在初始值的基础上增加相同的数值,则该大小关系可以是第一序列号是否小于或等于第二序列号。如果该第一更新规则和第二更新规则相同,且都是在初始值的基础上减去相同的数值,则该大小关系可以是第一序列号是否大于或等于第二序列号。如果该第一更新规则和第二更新规则不相同,该第一更新规则对应的变化值与第二更新规则对应的变化值的k倍,则该大小关系可以是第二序列号与第一序列号的比值是否为k的正整数倍。As an implementation manner, the magnitude relationship can be determined according to the first update rule and the second update rule. If the first update rule and the second update rule are the same, and both are increased by the same value on the basis of the initial value, The size relationship may be whether the first serial number is less than or equal to the second serial number. If the first update rule and the second update rule are the same, and the same value is subtracted from the initial value, the magnitude relationship may be whether the first serial number is greater than or equal to the second serial number. If the first update rule and the second update rule are not the same, and the change value corresponding to the first update rule is k times the change value corresponding to the second update rule, the magnitude relationship may be the second sequence number and the first sequence Whether the ratio of the number is a positive integer multiple of k.
在获取所述第一序列号和所述第二序列号之间的大小关系之后,判断所述大小关系是否满足指定条件。After obtaining the size relationship between the first serial number and the second serial number, it is determined whether the size relationship satisfies a specified condition.
其中,所述大小关系满足指定条件表明所述指定机房在所述主机房被写入所述目标数据之后成功同步所述目标数据。Wherein, that the size relationship satisfies a specified condition indicates that the specified computer room successfully synchronizes the target data after the host room is written into the target data.
则在第一更新规则和第二更新规则相同或者不同的情况下,上述的大小关系也不同,因此所对应的指定条件也不同。Then, when the first update rule and the second update rule are the same or different, the above-mentioned magnitude relationship is also different, and therefore the corresponding designated conditions are also different.
例如,如果该第一更新规则和第二更新规则相同,且都是在初始值的基础上增加相同的数值,则该大小关系可以是第一序列号是否小于或等于第二序列号,则如果第一序列号小于或等于第二序列号,则判定所述大小关系满足指定条件,否则,判定所述大小关系不满足指定条件。For example, if the first update rule and the second update rule are the same, and the same value is added to the initial value, the size relationship may be whether the first serial number is less than or equal to the second serial number, then if If the first serial number is less than or equal to the second serial number, it is determined that the size relationship meets the specified condition; otherwise, it is determined that the size relationship does not meet 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 can be whether the first serial number is greater than or equal to the second serial number, then if the first serial number is greater than or equal to the second serial number, If a serial number is greater than or equal to the second serial number, it is determined that the size relationship meets the specified condition; otherwise, it is determined that the size relationship does not meet the specified condition.
如果该第一更新规则和第二更新规则不相同,该第一更新规则对应的变化值与第二更新规则对应的变化值的k倍,则该大小关系可以是第二序列号与第一序列号的比值是否为k的正整数倍,则如果第二序列号与第一序列号的比值为k的正整数倍,则判定所述大小关系满足指定条件,否则,判定所述大小关系不满足指定条件。If the first update rule and the second update rule are not the same, and the change value corresponding to the first update rule is k times the change value corresponding to the second update rule, the magnitude relationship may be the second sequence number and the first sequence Whether the ratio of the number is a positive integer multiple of k, then if the ratio of the second serial number to the first serial number is a positive integer multiple of k, it is determined that the size relationship meets the specified condition, otherwise, it is determined that the size relationship does not meet Specify the conditions.
于本申请实施例中,第一更新规则和第二更新规则可以相同,且都是在初始值的基础上增加相同的数值,所述大小关系满足指定条件是指如果第一序列号小于或等于第二序列号。In the embodiment of the present application, the first update rule and the second update rule may be the same, and the same value is added to the initial value. The size relationship meets the specified condition means that if the first serial number is less than or equal to The second serial number.
作为一种实施方式,第一序列号根据第一更新规则在被改变,第二序列号根据第二更新规则在被改变,则在主机房完成目标数据的写入操作的时候,该第一序列号经过第一更新规则被更新之后的第一数值,与从机完成该目标数据的同步操作的时候,该第二序列号经过第二更新规则被更新之后的第二数值,该第一数值和第二数值之间的大小关系应当满足第一更新规则和第二更新规则的关系,例如,如果第一更新规则和第二更新规则相同,则第一数值和第二数值之间的大小关系应当相同。如果第一更新规则是增减数值a,第二更新规则为增加数值b,则数值a和数值b的比值为c,则该第一数值和第二数值之间的大小关系也应当满足数值a和数值b的比值为c的n倍,其中,n为正整数。As an implementation manner, the first serial number is changed according to the first update rule, and the second serial number is changed according to the second update rule. When the host room completes the write operation of the target data, the first serial number The first value of the serial number after the first update rule is updated, and when the slave completes the synchronization operation of the target data, the second serial number is the second value after the second update rule is updated, the first value and The size relationship between 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 size relationship between the first value and the second value should be 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, then the ratio of the value a to the value b is c, then the magnitude relationship between the first value and the second value should also satisfy the value a The ratio to the value b is n times c, where n is a positive integer.
假设,第一更新规则和第二更新规则相同,则均是增加1,且第一序列号的初始值和第二序列号的初始值相同,并且在每次执行写入操作的时候,主机房的第一序列号和从机的第二序列号都会初始化,即恢复到初始值,则在被写入的数据为一个的情况下,即目标数据为一个数据的情况下,主机房写入该目标数据之后,该第一序列号应当为1,从机成功同步该目标数据之后,该第二序列号应当为1,即第一序列号和第二序列号相同。Assuming that the first update rule and the second update rule are the same, they are both increased by 1, and the initial value of the first serial number is the same as the initial value of the second serial number, and each time a write operation is performed, the host room The first serial number of the slave and the second serial number of the slave will be initialized, that is, it will be restored to the initial value. If there is only one data to be written, that is, if the target data is one data, the host room writes the After the target data, the first serial number should be 1, and after the slave successfully synchronizes the target data, the second serial number should be 1, that is, the first serial number and the second serial number are the same.
另外,考虑到主机房被写入的数据为多个的时候,主机房的数据同步操作和主机房检测是否所述目标数据成功同步到所述指定机房是同步在执行的,则可能存在主机房在确定数据data1是否被从机成功同步的时候,从机已经在成功同步到了data3,而data3是在data1之后被写入的数据,则此时,从机的第二序列号是大于第一序列号的,因此,如果第二序列号大于第一序列号,则能够说明第一序列号对应的数据已经被成功同步到从机。In addition, considering that when there are multiple data written in the host room, the data synchronization operation of the host room and the host room's detection of whether the target data is successfully synchronized to the designated computer room are synchronized in execution, there may be a host room When determining whether data data1 is successfully synchronized by the slave, the slave has successfully synchronized to data3, and data3 is the data written after data1. At this time, the second sequence number of the slave is greater than the first sequence Therefore, if the second serial number is greater than the first serial number, it can indicate that the data corresponding to the first serial number has been successfully synchronized to the slave.
主机房被写入的数据的写入顺序,将该被写入的数据同步至从机的同步顺序可以是相同的,例如,主机房被写入的数据的写入顺序为data1、data2、data3、data4、data5 和data6,将该被写入的数据同步至从机的同步顺序为data1、data2、data3、data4、data5和data6。The writing sequence of the data written in the master room, the synchronization sequence of synchronizing the written data to the slave machine can be the same, for example, the writing sequence of the data written in the master room is data1, data2, data3 , Data4, data5 and data6, the synchronization sequence of synchronizing the written data to the slave is data1, data2, data3, data4, data5 and data6.
因此,获取主机房写入目标数据对应的第一序列号,以及获取从机当前的第二序列号的大小,如果第一序列号小于或等于第二序列号,则表示所述从机在所述主机房被写入所述目标数据之后成功同步所述目标数据。Therefore, the first serial number corresponding to the target data written in the master room is acquired, and the current second serial number of the slave is acquired. If the first serial number is less than or equal to the second serial number, it means that the slave is in all locations. After the host room is written into the target data, the target data is successfully synchronized.
例如,主机房被写入的数据包括data1、data2、data3、data4、data5和data6,此时data1、data2、data3、data4、data5和data6被成功写入主机房,其中,data2为目标数据,则参考上述表1,该目标数据对应的第一序列号为seq1等于2,主机房将data1、data2、data3、data4、data5和data6依次同步至从机,此时,从机的seq2为1,则表示该从机成功同步的数据为data1,则第一序列号大于第二序列号,则可以判定所述目标数据未成功同步到所述指定机房。For example, the data written in the host room includes data1, data2, data3, data4, data5, and data6. At this time, data1, data2, data3, data4, data5, and data6 are successfully written into the host room, where data2 is the target data, then Referring to the above table 1, the first sequence 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. At this time, the seq2 of the slave is 1, then It indicates that the data successfully synchronized by the slave is data1, and the first serial number is greater than the second serial number, and it can be determined that the target data has not been successfully synchronized to the designated computer room.
则如果此时从机的seq2为2,则表示该从机成功同步的数据为data2,即从机成功同步的数据为目标数据,则第一序列号等于第二序列号,则可以判定所述目标数据未成功同步到所述指定机房。Then, if the seq2 of the slave machine is 2, it means that the data successfully synchronized by the slave machine is data2, that is, the data successfully synchronized by the slave machine is the target data, and the first serial number is equal to the second serial number, then it can be determined that the The target data is not successfully synchronized to the designated computer room.
则如果此时从机的seq2为3,则表示该从机成功同步的数据为data3,即从机成功同步的数据为目标数据之后的数据data3,则第一序列号小于第二序列号,则可以判定所述目标数据未成功同步到所述指定机房。Then if the seq2 of the slave is 3 at this time, it means that the data successfully synchronized by the slave is data3, that is, the data successfully synchronized by the slave is data3 after the target data, and the first serial number is less than the second serial number, then It can be determined that the target data is not successfully synchronized to the designated computer room.
因此,在所述第一序列号小于或等于所述第二序列号的时候,可以判定所述目标数据成功同步到所述指定机房。Therefore, when the first serial number is less than or equal to the second serial number, it can be determined that the target data is successfully synchronized to the designated computer room.
另外,在主机房对应多个从机房的时候,每个从机房对应一个第二序列号,则可以通过上述检测方式,确定每个从机房是否成功同步了该目标数据,从而确定所述目标数据是否成功同步到所述主机房对应的从机房。In addition, when the master room corresponds to multiple slave rooms, and each slave room corresponds to a second serial number, the above detection method can be used to determine whether each slave room has successfully synchronized the target data, so as to determine the target data Whether to successfully synchronize to the slave computer room corresponding to the host room.
在一些实施例中,可以将上述检测所述目标数据是否成功同步到所述主机房对应的从机房的操作命名为扫描操作,则如果第一序列号大于第二序列号,即判定所述目标数据未成功同步到所述主机房对应的从机房的时候,可以等待一定时间段之后,再继续执行扫描操作,即在该时间段暂停执行该扫描操作,以便在该时间内,从机房能够完成目标数据的同步操作。In some embodiments, the operation of detecting whether the target data is successfully synchronized to the slave computer room corresponding to the host room may be named a scanning operation, and if the first serial number is greater than the second serial number, it is determined that the target When the data is not successfully synchronized to the slave computer room corresponding to the host room, you can wait for a certain period of time before continuing to perform the scanning operation, that is, pause the scanning operation during this time period, so that the slave computer room can complete the scan within this time period. Synchronization operation of target data.
具体地,如果所述大小关系不满足指定条件,则判定未成功将数据同步至所述指定机房之后,方法还包括:在指定时间长度之后,再次获取所述第一序列号和所述第二序列号之间的大小关系以及执行后续操作,其中,在所述指定时间长度内继续执行将所述目标数据同步到与所述指定机房的操作。其中,所述指定时间长度可以是预先设定的时间长度,例如,该指定时间长度可以是与上述的预定时间段对应的预定时间长度相同,具体地,该该指定时间长度可以是10ms。Specifically, if the size relationship does not meet the specified condition, after determining that the data is not successfully synchronized to the specified computer room, the method further includes: obtaining the first serial number and the second serial number again after a specified length of time. The size relationship between the serial numbers and the execution of subsequent operations, wherein the operation of synchronizing the target data to the specified computer room is continued to be executed within the specified length of time. 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 aforementioned predetermined time period. Specifically, the specified time length may be 10 ms.
S550:将所述从机房中,所述指定机房之外的从机房作为新的指定机房。S550: Use a slave room other than the designated machine room among the slave machine rooms as a new designated machine room.
在通过上述方式确定主机房将所有的被写入的数据均同步至所述指定机房之后,再由指定机房之外的从机房中重新选择一个从机房,作为新的指定机房,并返回执行S530,直至所有的从机房均同步完成。After it is determined by the above method that the host room has synchronized all the written data to the designated computer room, a slave computer room other than the designated computer room is re-selected as the new designated computer room, and the execution of S530 is returned. , Until all slave rooms are synchronized.
因此,本申请实施例可以在多地机房部署相互独立的Redis集群,且所有机房的读写操作均能够同步到其他机房,即各个机房的集群相互为镜像。当部分机房出现故障(包括软件、硬件、网络故障)时,业务层可以将读写请求调度到其他正常的机房继续运行,从而实现跨机房容灾,保证服务的高可用性和数据的安全性。Therefore, in the embodiment of the present application, mutually independent Redis clusters can be deployed in multiple computer rooms, and the read and write operations of all computer rooms can be synchronized to other computer rooms, that is, the clusters of each computer room are mirror images of each other. When part of the computer room fails (including software, hardware, and network failures), the business layer can dispatch read and write requests to other normal computer rooms to continue running, thereby achieving cross-computer room disaster recovery and ensuring high service availability and data security.
另外,如图7所示,上述的客户端可以包括扫描进程和订阅进程。扫描进程用于执行判断是否成功将数据同步至所述指定机房的操作,订阅进程用于监测所述主机房和所述从机房的写入操作,当检测到所述写入操作时,根据该写入操作得到所述目标 数据。In addition, as shown in FIG. 7, the above-mentioned client may include a scanning process and a subscription process. The scanning process is used to perform the operation of judging whether the data is successfully synchronized to the designated computer room, and the subscription process is used to monitor the write operation of the master room and the slave computer room. When the write operation is detected, the The write operation obtains the target data.
通过外部程序进行数据同步,对业务层无感知,使用简单,即通过上述的客户端实现数据的同步,所以后,不存在跨机房读写,不会影响业务性能。支持多地同时读写,支持任意数量集群之间的数据同步,业务可以根据情况进行多地部署,可扩展性强。通过主从机房机制,保证在多地同时进行写入时的数据最终一致性。Data synchronization through external programs has no perception of the business layer and is simple to use, that is, data synchronization is achieved through the above-mentioned client. Therefore, there will be no cross-machine room reading and writing, and business performance will not be affected. Supports simultaneous read and write in multiple locations, supports data synchronization between any number of clusters, and services can be deployed in multiple locations according to the situation, with strong scalability. Through the master-slave machine room mechanism, the final consistency of the data when writing in multiple places is guaranteed at the same time.
请参阅图8,其示出了本申请实施例提供的一种数据同步装置800的结构框图,该装置可以包括:获取单元801、写入单元802和同步单元803。Please refer to FIG. 8, which shows a structural block diagram of a data synchronization device 800 provided by an embodiment of the present application. The device may include: an acquiring unit 801, a writing unit 802, and a synchronization unit 803.
获取单元801,用于获取请求写入所述数据存储系统的目标数据。The obtaining unit 801 is configured to obtain target data requested to be written into the data storage system.
写入单元802,用于将所述目标数据写入所述主机房。The writing unit 802 is configured to write the target data into the host room.
同步单元803,用于在成功将所述目标数据写入所述主机房之后,将所述目标数据同步至所述从机房。The synchronization unit 803 is configured to synchronize the target data to the slave computer room after successfully writing the target data into the host room.
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述装置和模块的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that, for the convenience and conciseness of the description, the specific working process of the device and module described above can refer to the corresponding process in the foregoing method embodiment, which will not be repeated here.
请参阅图9,其示出了本申请实施例提供的一种数据同步装置900的结构框图,该装置可以包括:获取单元910、写入单元920和同步单元930。Please refer to FIG. 9, which shows a structural block diagram of a data synchronization device 900 provided by an embodiment of the present application. The device may include: an acquiring unit 910, a writing unit 920, and a synchronization unit 930.
获取单元910,用于获取请求写入所述数据存储系统的目标数据。The obtaining unit 910 is configured to obtain the target data requested to be written into the data storage system.
获取单元910还包括监测子单元911和数据确定子单元912。The acquiring unit 910 also includes a monitoring subunit 911 and a data determining subunit 912.
监测子单元911用于监测所述主机房和所述从机房的写入操作。The monitoring subunit 911 is used to monitor the write operation of the host room and the slave computer room.
数据确定子单元912还用于当检测到所述写入操作时,根据该写入操作得到所述目标数据。The data determining subunit 912 is further configured to obtain the target data according to the write operation when the write operation is detected.
具体地,数据确定子单元912还用于若所述写入操作为多个,获取每个所述写入操作对应的时间戳,其中,每个所述写入操作对应指定数据,用于将待修改内容修改为指定数据;根据所述时间戳由多个所述写入操作内确定为目标写入操作;将所述目标写入操作对应的指定数据作为目标数据。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 designated data and is used to The content to be modified is modified to designated data; the target write operation is determined from the plurality of write operations according to the timestamp; the designated data corresponding to the target write operation is used as the target data.
进一步地,数据确定子单元912还用于若所述时间戳不全相同,确定所有的时间戳中最晚的时间戳,作为目标时间戳;将所述目标时间戳对应的写入操作作为待选写入操作;由所述待选写入操作内确定目标写入操作。Further, the data determining subunit 912 is further configured to determine the latest timestamp among all the timestamps as the target timestamp if the timestamps are not all the same; use the write operation corresponding to the target timestamp as the candidate Write operation; the target write operation is determined from the to-be-selected write operation.
进一步地,数据确定子单元912还用于若所述待选写入操作的数量为1,则将所述待选写入操作作为目标写入操作。Further, the data determining subunit 912 is further configured to, if the number of the write operations to be selected is 1, set the write operations to be selected as the target write operation.
进一步地,数据确定子单元912还用于若所述待选写入操作的数量为至少两个,确定每个所述待选写入操作对应的操作对象,所述操作对象包括主机房或从机房;将所述操作对象为主机房的待选写入操作作为目标写入操作。Further, the data determining subunit 912 is further configured to determine the operation object corresponding to each of the writing operation to be selected if the number of the writing operation to be selected is at least two, and the operation object includes the host room or the slave Computer room; take the write operation to be selected in the host room where the operation object is the target write operation.
进一步地,数据确定子单元912还用于若所述时间戳全相同,确定每个所述待选写入操作对应的操作对象,所述操作对象包括主机房或从机房;Further, the data determining subunit 912 is further configured to determine the operation object corresponding to each of the write operations to be selected if the time stamps are all the same, and the operation object includes the host room or the slave computer room;
将所述操作对象为主机房的待选写入操作作为目标写入操作。The write operation to be selected in the host room as the operation object is taken as the target write operation.
写入单元920,用于将所述目标数据写入所述主机房。The writing unit 920 is configured to write the target data into the host room.
同步单元930,用于在成功将所述目标数据写入所述主机房之后,将所述目标数据同步至所述从机房。The synchronization unit 930 is configured to synchronize the target data to the slave computer room after successfully writing the target data into the host room.
其中,所述主机房和从机房均对应有消息队列,所述主机房订阅所有所述从机房的消息队列,每个所述从机房均订阅所述主机房的消息队列,所述在成功将所述目标数据写入所述主机房之后,将所述目标数据同步至所述从机房,包括:在成功将所述目标数据写入所述主机房之后,通过所述主机房对应的消息队列,将所述目标数据同步至所述从机房。Wherein, the master room and the slave room each have a message queue, the master room subscribes to the message queues of all the slave computer rooms, each of the slave computer rooms subscribes to the message queue of the master room, and the After the target data is written into the host room, synchronizing the target data to the slave computer room includes: after successfully writing the target data into the host room, passing through a message queue corresponding to the host room To synchronize the target data to the slave computer room.
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述装置和模 块的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that, for the convenience and conciseness of the description, the specific working process of the above described device and module can be referred to the corresponding process in the foregoing method embodiment, which will not be repeated here.
请参阅图10,其示出了本申请实施例提供的一种数据同步装置1000的结构框图,该装置可以包括:获取单元1010、写入单元1020和同步单元1030。Please refer to FIG. 10, which shows a structural block diagram of a data synchronization device 1000 provided by an embodiment of the present application. The device may include: an acquiring unit 1010, a writing unit 1020, and a synchronization unit 1030.
获取单元1010,用于获取请求写入所述数据存储系统的目标数据。The obtaining unit 1010 is configured to obtain the target data requested to be written into the data storage system.
写入单元1020,用于将所述目标数据写入所述主机房。The writing unit 1020 is configured to write the target data into the host room.
同步单元1030,用于在成功将所述目标数据写入所述主机房之后,将所述目标数据同步至所述从机房。The synchronization unit 1030 is configured to synchronize the target data to the slave computer room after successfully writing the target data into the host room.
同步单元1030包括选择子单元1031、判断子单元1032和同步子单元1033。The synchronization unit 1030 includes a selection subunit 1031, a judgment subunit 1032, and a synchronization subunit 1033.
选择子单元1031用于在成功将所述目标数据写入所述主机房之后,将所述目标数据同步至指定机房,所述指定机房为多个所述从机房中的一个从机房。The selection subunit 1031 is configured to synchronize the target data to a designated computer room after successfully writing the target data into the host room, and the designated computer room is one of the multiple slave computer rooms.
判断子单元1032用于判断是否成功将数据同步至所述指定机房。The judging subunit 1032 is used to judge whether the data is successfully synchronized to the designated computer room.
在一些实施例中,判断子单元1032还用于检测是否接收到所述指定机房反馈的同步成功的信息;如果接收到,则判定成功将数据同步至所述指定机房;如果未接收到,则判定未成功将数据同步至所述指定机房。In some embodiments, the judging subunit 1032 is also used to detect whether the synchronization success information fed back by the designated computer room is received; if it is received, it is determined that the data is successfully synchronized to the designated computer room; if it is not received, then It is determined that the data is not successfully synchronized to the designated computer room.
在另一些实施例中,判断子单元1032还用于获取所述主机房对应的第一记录信息,所述第一记录信息用于记录所述主机房执行的被写入目标数据的操作;获取所述指定机房对应的第二记录信息,所述第二记录信息用于记录所述指定机房执行的目标数据的数据同步的操作;根据所述第一记录信息和所述第二记录信息判断是否成功将数据同步至所述指定机房。In other embodiments, the judging subunit 1032 is further configured to obtain the first record information corresponding to the host room, and the first record information is used to record the operation performed by the host room to write target data; The second record information corresponding to the designated computer room, where the second record information is used to record the data synchronization operation of the target data performed by the designated computer room; determine whether or not according to the first record information and the second record information The data is successfully synchronized to the designated computer room.
进一步地,判断子单元1032还用于判断所述第一记录信息内的第一操作时间点是否早于所述第二记录信息内的第二操作时间点;若早于,则判定成功将数据同步至所述指定机房;若未早于,则判定未成功将数据同步至所述指定机房。Further, the judging subunit 1032 is also used to judge whether the first operation time point in the first record information is earlier than the second operation time point in the second record information; if it is earlier, it is judged that the data is successfully transferred Synchronize to the designated computer room; if it is not earlier, it is determined that the data is not successfully synchronized to the designated computer room.
其中,所述第一记录信息为第一序列号,所述第一序列号用于在所述主机房被成功写入目标数据时,根据第一更新规则执行更新操作;所述第二记录信息为第二序列号,所述第二序列号用于在所述指定机房成功同步数据时,根据第二更新规则执行更新操作。Wherein, 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 room is successfully written into target data; the second record information It is a second serial number, and the second serial number is used to perform an update operation according to a second update rule when the designated computer room successfully synchronizes data.
进一步地,判断子单元1032还用于获取所述第一序列号和所述第二序列号之间的大小关系;如果所述大小关系满足指定条件,则判定成功将数据同步至所述指定机房,其中,所述大小关系满足指定条件表明所述指定机房在所述主机房被写入所述目标数据之后成功同步所述目标数据;如果所述大小关系不满足指定条件,则判定未成功将数据同步至所述指定机房。Further, the judging subunit 1032 is also used to obtain the size relationship between the first serial number and the second serial number; if the size relationship meets a specified condition, it is determined that the data is successfully synchronized to the specified computer room , Wherein the size relationship satisfies the specified condition indicates that the specified computer room successfully synchronizes the target data after the host room is written into the target data; if the size relationship does not meet the specified condition, it is determined that the transfer is unsuccessful The data is synchronized to the designated computer room.
其中,第一更新规则为在所述主机房被成功写入目标数据时,将所述第一序列号增减第一数值,所述第二更新规则为在所述指定机房成功同步数据时,将所述第二序列号增减第二数值,所述第一数值和所述第二数值相同。Wherein, the first update rule is to increase or decrease the first serial number by a first value when the target data is successfully written in the host room, and the second update rule is to successfully synchronize data in the designated computer room, The second serial number is increased or decreased by a second value, and the first value is the same as the second value.
所述大小关系满足指定条件是指所述第一序列号小于或等于所述第二序列号。The fact that the size relationship satisfies a specified condition means that the first serial number is less than or equal to the second serial number.
进一步地,判断子单元1032还用于在指定时间长度之后,再次获取所述第一序列号和所述第二序列号之间的大小关系以及执行后续操作,其中,在所述指定时间长度内继续执行将所述目标数据同步到与所述指定机房的操作。Further, the judging subunit 1032 is further configured to obtain the size relationship between the first serial number and the second serial number again and perform subsequent operations after a specified length of time, wherein, within the specified length of time Continue to perform the operation of synchronizing the target data to the designated computer room.
同步子单元1033用于若成功将数据同步至所述指定机房,将所述从机房中,所述指定机房之外的从机房作为新的指定机房,并返回执行将所述目标数据同步至指定机房,直至完成所有所述从机房的目标数据同步操作。The synchronization subunit 1033 is configured to, if the data is successfully synchronized to the designated computer room, set the secondary computer room, the secondary computer room outside the designated computer room as the new designated computer room, and return to execute the synchronization of the target data to the designated computer room. Computer room, until all the target data synchronization operations of the slave computer rooms are completed.
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述装置和模块的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that, for the convenience and conciseness of the description, the specific working process of the device and module described above can refer to the corresponding process in the foregoing method embodiment, which will not be repeated here.
在本申请所提供的几个实施例中,模块相互之间的耦合可以是电性,机械或其它形 式的耦合。In the several embodiments provided in this application, the coupling between the modules may be electrical, mechanical or other forms of coupling.
另外,在本申请各个实施例中的各功能模块可以集成在一个处理模块中,也可以是各个模块单独物理存在,也可以两个或两个以上模块集成在一个模块中。上述集成的模块既可以采用硬件的形式实现,也可以采用软件功能模块的形式实现。In addition, the functional modules in the various embodiments of the present application may be integrated into one processing module, or each module may exist alone physically, or two or more modules may be integrated into one module. The above-mentioned integrated modules can be implemented in the form of hardware or software functional modules.
请参考图11,其示出了本申请实施例提供的一种电子设备的结构框图。该电子设备100可以是智能手机、平板电脑、电子书等能够运行应用程序的电子设备。本申请中的电子设备100可以包括一个或多个如下部件:处理器110、存储器120、以及一个或多个应用程序,其中一个或多个应用程序可以被存储在存储器120中并被配置为由一个或多个处理器110执行,一个或多个程序配置用于执行如前述方法实施例所描述的方法。Please refer to FIG. 11, which shows a structural block diagram of an electronic device provided by an embodiment of the present application. The electronic device 100 may be an electronic device capable of running application programs, such as a smart phone, a tablet computer, or an e-book. The electronic device 100 in this application may include one or more of the following components: a processor 110, a memory 120, and one or more application programs, where one or more application programs may be stored in the memory 120 and configured to be configured by One or more processors 110 execute, and one or more programs are configured to execute the methods described in the foregoing method embodiments.
处理器110可以包括一个或者多个处理核。处理器110利用各种接口和线路连接整个电子设备100内的各个部分,通过运行或执行存储在存储器120内的指令、程序、代码集或指令集,以及调用存储在存储器120内的数据,执行电子设备100的各种功能和处理数据。可选地,处理器110可以采用数字信号处理(Digital Signal Processing,DSP)、现场可编程门阵列(Field-Programmable Gate Array,FPGA)、可编程逻辑阵列(Programmable Logic Array,PLA)中的至少一种硬件形式来实现。处理器110可集成中央处理器(Central Processing Unit,CPU)、图像处理器(Graphics Processing Unit,GPU)和调制解调器等中的一种或几种的组合。其中,CPU主要处理操作系统、用户界面和应用程序等;GPU用于负责显示内容的渲染和绘制;调制解调器用于处理无线通信。可以理解的是,上述调制解调器也可以不集成到处理器110中,单独通过一块通信芯片进行实现。The processor 110 may include one or more processing cores. The processor 110 uses various interfaces and lines to connect various parts of the entire electronic device 100, and executes by running or executing instructions, programs, code sets, or instruction sets stored in the memory 120, and calling data stored in the memory 120. Various functions and processing data of the electronic device 100. Optionally, the processor 110 may adopt at least one of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), and Programmable Logic Array (PLA). A kind of hardware form to realize. The processor 110 may be integrated with one or a combination of a central processing unit (CPU), a graphics processing unit (GPU), a modem, and the like. Among them, the CPU mainly processes the operating system, user interface, and application programs; the GPU is used for rendering and drawing of display content; the modem is used for processing wireless communication. It is understandable that the above-mentioned modem may not be integrated into the processor 110, but may be implemented by a communication chip alone.
存储器120可以包括随机存储器(Random Access Memory,RAM),也可以包括只读存储器(Read-Only Memory)。存储器120可用于存储指令、程序、代码、代码集或指令集。存储器120可包括存储程序区和存储数据区,其中,存储程序区可存储用于实现操作系统的指令、用于实现至少一个功能的指令(比如触控功能、声音播放功能、图像播放功能等)、用于实现下述各个方法实施例的指令等。存储数据区还可以存储终端100在使用中所创建的数据(比如电话本、音视频数据、聊天记录数据)等。The memory 120 may include random access memory (RAM) or read-only memory (Read-Only Memory). The memory 120 may be used to store instructions, programs, codes, code sets or instruction sets. The memory 120 may include a program storage area and a data storage area, where the program storage area may store instructions for implementing the operating system and instructions for implementing at least one function (such as touch function, sound playback function, image playback function, etc.) , Instructions used to implement the following various method embodiments, etc. The data storage area can also store data (such as phone book, audio and video data, chat record data) created by the terminal 100 during use.
请参考图12,其示出了本申请实施例提供的一种计算机可读存储介质的结构框图。该计算机可读介质1200中存储有程序代码,所述程序代码可被处理器调用执行上述方法实施例中所描述的方法。Please refer to FIG. 12, which shows a structural block diagram of a computer-readable storage medium provided by an embodiment of the present application. The computer-readable medium 1200 stores program code, and the program code can be invoked by a processor to execute the method described in the foregoing method embodiment.
计算机可读存储介质1200可以是诸如闪存、EEPROM(电可擦除可编程只读存储器)、EPROM、硬盘或者ROM之类的电子存储器。可选地,计算机可读存储介质1200包括非易失性计算机可读介质(non-transitory computer-readable storage medium)。计算机可读存储介质1200具有执行上述方法中的任何方法步骤的程序代码1210的存储空间。这些程序代码可以从一个或者多个计算机程序产品中读出或者写入到这一个或者多个计算机程序产品中。程序代码1210可以例如以适当形式进行压缩。The computer-readable storage medium 1200 may be an electronic memory such as flash memory, EEPROM (Electrically Erasable Programmable Read Only Memory), EPROM, hard disk, or ROM. Optionally, the computer-readable storage medium 1200 includes a non-transitory computer-readable storage medium. The computer-readable storage medium 1200 has storage space for the program code 1210 for executing any method steps in the above-mentioned methods. These program codes can be read from or written into one or more computer program products. The program code 1210 may be compressed in an appropriate form, for example.
最后应说明的是:以上实施例仅用以说明本申请的技术方案,而非对其限制;尽管参照前述实施例对本申请进行了详细的说明,本领域的普通技术人员当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不驱使相应技术方案的本质脱离本申请各实施例技术方案的精神和范围。Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the application, not to limit them; although the application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: The technical solutions recorded in the foregoing embodiments are modified, or some of the technical features thereof are equivalently replaced; these modifications or replacements do not drive the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims (20)

  1. 一种数据同步方法,其特征在于,应用于数据存储系统的主机房,该数据存储系统还包括与所述主机房对应的从机房,所述方法包括:A data synchronization method, characterized in that it is applied to a host room of a data storage system, the data storage system further includes a slave computer room corresponding to the host room, and the method includes:
    获取请求写入所述数据存储系统的目标数据;Acquiring the target data requested to be written to the data storage system;
    将所述目标数据写入所述主机房;Writing the target data into the host room;
    在成功将所述目标数据写入所述主机房之后,将所述目标数据同步至所述从机房。After successfully writing the target data into the host room, synchronize the target data to the slave computer room.
  2. 根据权利要求1所述的方法,其特征在于,所述获取请求写入所述数据存储系统的目标数据,包括:The method according to claim 1, wherein the obtaining the target data written in the data storage system by the request comprises:
    监测所述主机房和所述从机房的写入操作;Monitoring the write operations of the host room and the slave computer room;
    当检测到所述写入操作时,根据该写入操作得到所述目标数据。When the write operation is detected, the target data is obtained according to the write operation.
  3. 根据权利要求2所述的方法,其特征在于,所述当检测到所述写入操作时,根据该写入操作得到目标数据,包括:The method according to claim 2, wherein when the writing operation is detected, obtaining target data according to the writing operation comprises:
    若所述写入操作为多个,获取每个所述写入操作对应的时间戳,其中,每个所述写入操作对应指定数据,用于将待修改内容修改为指定数据;If there are multiple write operations, obtain a time stamp corresponding to each write operation, where each write operation corresponds to designated data and is used to modify the content to be modified into designated data;
    根据所述时间戳由多个所述写入操作内确定为目标写入操作;Determined as a target write operation from among the multiple write operations according to the timestamp;
    将所述目标写入操作对应的指定数据作为目标数据。The designated data corresponding to the target write operation is used as the target data.
  4. 根据权利要求3所述的方法,其特征在于,所述根据所述时间戳由多个所述写入操作内确定为目标写入操作,包括:The method according to claim 3, wherein the determining as a target write operation from a plurality of the write operations according to the timestamp comprises:
    若所述时间戳不全相同,确定所有的时间戳中最晚的时间戳,作为目标时间戳;If the time stamps are not all the same, determine the latest time stamp among all time stamps as the target time stamp;
    将所述目标时间戳对应的写入操作作为待选写入操作;Take the write operation corresponding to the target timestamp as a write operation to be selected;
    由所述待选写入操作内确定目标写入操作。The target write operation is determined from the to-be-selected write operation.
  5. 根据权利要求4所述的方法,其特征在于,所述由所述待选写入操作内确定目标写入操作,包括:The method according to claim 4, wherein the determining a target write operation from the to-be-selected write operation comprises:
    若所述待选写入操作的数量为1,则将所述待选写入操作作为目标写入操作。If the number of the write operation to be selected is 1, the write operation to be selected is taken as the target write operation.
  6. 根据权利要求4所述的方法,其特征在于,所述由所述待选写入操作内确定目标写入操作,包括:The method according to claim 4, wherein the determining a target write operation from the to-be-selected write operation comprises:
    若所述待选写入操作的数量为至少两个,确定每个所述待选写入操作对应的操作对象,所述操作对象包括主机房或从机房;If the number of the write operations to be selected is at least two, determine an operation object corresponding to each write operation to be selected, and the operation object includes a host room or a slave computer room;
    将所述操作对象为主机房的待选写入操作作为目标写入操作。The write operation to be selected in the host room as the operation object is taken as the target write operation.
  7. 根据权利要求3所述的方法,其特征在于,还包括:The method according to claim 3, further comprising:
    若所述时间戳全相同,确定每个所述待选写入操作对应的操作对象,所述操作对象包括主机房或从机房;If the timestamps are all the same, determine the operation object corresponding to each of the to-be-selected write operations, and the operation object includes the host room or the slave computer room;
    将所述操作对象为主机房的待选写入操作作为目标写入操作。The write operation to be selected in the host room as the operation object is taken as the target write operation.
  8. 根据权利要求1所述的方法,其特征在于,所述从机房为多个,所述在成功将所述目标数据写入所述主机房之后,将所述目标数据同步至所述从机房,包括:The method according to claim 1, wherein there are multiple slave computer rooms, and after successfully writing the target data into the host room, synchronizing the target data to the slave computer room, include:
    在成功将所述目标数据写入所述主机房之后,将所述目标数据同步至指定机房,所述指定机房为多个所述从机房中的一个从机房;After successfully writing the target data into the host room, synchronize the target data to a designated computer room, where the designated computer room is one of the multiple slave computer rooms;
    判断是否成功将数据同步至所述指定机房;Determine whether the data is successfully synchronized to the designated computer room;
    若成功将数据同步至所述指定机房,将所述从机房中,所述指定机房之外的从机房作为新的指定机房,并返回执行将所述目标数据同步至指定机房,直至完成所有所述从机房的目标数据同步操作。If the data is successfully synchronized to the designated machine room, the slave machine room and the slave machine room other than the designated machine room will be used as the new designated machine room, and the execution will be returned to synchronize the target data to the designated machine room until all the data is completed. The target data synchronization operation from the computer room is described.
  9. 根据权利要求8所述的方法,其特征在于,所述判断是否成功将数据同步至所述指定机房,包括:The method according to claim 8, wherein the determining whether the data is successfully synchronized to the designated computer room comprises:
    检测是否接收到所述指定机房反馈的同步成功的信息;Detecting whether the synchronization success information fed back by the designated computer room is received;
    如果接收到,则判定成功将数据同步至所述指定机房;If it is received, it is determined that the data is successfully synchronized to the designated computer room;
    如果未接收到,则判定未成功将数据同步至所述指定机房。If it is not received, it is determined that the data has not been successfully synchronized to the designated computer room.
  10. 根据权利要求8所述的方法,其特征在于,所述判断是否成功将数据同步至所述指定机房,包括:The method according to claim 8, wherein the determining whether the data is successfully synchronized to the designated computer room comprises:
    获取所述主机房对应的第一记录信息,所述第一记录信息用于记录所述主机房执行的被写入目标数据的操作;Acquiring first record information corresponding to the host room, where the first record information is used to record the operation performed by the host room to write target data;
    获取所述指定机房对应的第二记录信息,所述第二记录信息用于记录所述指定机房执行的目标数据的数据同步的操作;Acquiring second record information corresponding to the designated computer room, where the second record information is used to record the data synchronization operation of the target data performed by the designated computer room;
    根据所述第一记录信息和所述第二记录信息判断是否成功将数据同步至所述指定机房。Determine whether the data is successfully synchronized to the designated computer room according to the first record information and the second record information.
  11. 根据权利要求10所述的方法,其特征在于,所述记录信息用于记录操作的操作时间点;所述根据所述第一记录信息和所述第二记录信息判断是否成功将数据同步至所述指定机房,包括:The method according to claim 10, wherein the recording information is used to record the operation time point of the operation; the judging whether the data is successfully synchronized to the The designated computer room includes:
    判断所述第一记录信息内的第一操作时间点是否早于所述第二记录信息内的第二操作时间点;Determining whether the first operation time point in the first record information is earlier than the second operation time point in the second record information;
    若早于,则判定成功将数据同步至所述指定机房;If it is earlier, it is determined that the data is successfully synchronized to the designated computer room;
    若未早于,则判定未成功将数据同步至所述指定机房。If it is not earlier, it is determined that the data has not been successfully synchronized to the designated computer room.
  12. 根据权利要求10所述的方法,其特征在于,所述第一记录信息为第一序列号,所述第一序列号用于在所述主机房被成功写入目标数据时,根据第一更新规则执行更新操作;所述第二记录信息为第二序列号,所述第二序列号用于在所述指定机房成功同步数据时,根据第二更新规则执行更新操作。The method according to claim 10, wherein the first record information is a first serial number, and the first serial number is used when the host room is successfully written into the target data, according to the first update The update operation is performed according to the rule; the second record information is a second serial number, and the second serial number is used to perform the update operation according to the second update rule when the designated computer room successfully synchronizes data.
  13. 根据权利要求10所述的方法,其特征在于,所述根据所述第一记录信息和所述第二记录信息判断是否成功将数据同步至所述指定机房,包括:The method according to claim 10, wherein the judging whether the data is successfully synchronized to the designated computer room according to the first record information and the second record information comprises:
    获取所述第一序列号和所述第二序列号之间的大小关系;Acquiring the size relationship between the first serial number and the second serial number;
    如果所述大小关系满足指定条件,则判定成功将数据同步至所述指定机房,其中,所述大小关系满足指定条件表明所述指定机房在所述主机房被写入所述目标数据之后成功同步所述目标数据;If the size relationship meets the specified condition, it is determined that the data is successfully synchronized to the specified computer room, where the size relationship meets the specified condition indicates that the specified computer room successfully synchronizes after the host room is written with the target data The target data;
    如果所述大小关系不满足指定条件,则判定未成功将数据同步至所述指定机房。If the size relationship does not meet the specified condition, it is determined that the data is not successfully synchronized to the specified computer room.
  14. 根据权利要求13所述的方法,其特征在于,第一更新规则为在所述主机房被成功写入目标数据时,将所述第一序列号增减第一数值,所述第二更新规则为在所述指定机房成功同步数据时,将所述第二序列号增减第二数值,所述第一数值和所述第二数值相同。The method according to claim 13, wherein the first update rule is to increase or decrease the first serial number by a first value when the host room is successfully written into the target data, and the second update rule In order to increase or decrease the second serial number by a second value when the designated computer room successfully synchronizes data, the first value and the second value are the same.
  15. 根据权利要求14所述的方法,其特征在于,所述大小关系满足指定条件是指所述第一序列号小于或等于所述第二序列号。The method according to claim 14, wherein the size relationship satisfying a specified condition means that the first serial number is less than or equal to the second serial number.
  16. 根据权利要求13所述的方法,其特征在于,所述如果所述大小关系不满足指定条件,则判定未成功将数据同步至所述指定机房之后,还包括:The method according to claim 13, characterized in that, after determining that the data is not successfully synchronized to the specified computer room if the size relationship does not satisfy a specified condition, the method further comprises:
    在指定时间长度之后,再次获取所述第一序列号和所述第二序列号之间的大小关系以及执行后续操作,其中,在所述指定时间长度内继续执行将所述目标数据同步到与所述指定机房的操作。After the specified length of time, the size relationship between the first serial number and the second serial number is obtained again and subsequent operations are performed, wherein the synchronization of the target data to the The operation of the designated computer room.
  17. 根据权利要求1-16任一所述的方法,其特征在于,所述主机房和从机房均对应有消息队列,所述主机房订阅所有所述从机房的消息队列,每个所述从机房均订阅所述主机房的消息队列,所述在成功将所述目标数据写入所述主机房之后,将所述目标数据同步至所述从机房,包括:The method according to any one of claims 1-16, wherein the master room and the slave room each have a message queue, the master room subscribes to the message queues of all the slave rooms, and each slave room Both subscribing to the message queue of the host room, and synchronizing the target data to the slave computer room after successfully writing the target data into the host room includes:
    在成功将所述目标数据写入所述主机房之后,通过所述主机房对应的消息队列, 将所述目标数据同步至所述从机房。After successfully writing the target data into the host room, synchronize the target data to the slave computer room through a message queue corresponding to the host room.
  18. 一种数据同步装置,其特征在于,应用于数据存储系统的主机房,该数据存储系统还包括与所述主机房对应的从机房,所述装置包括:A data synchronization device, characterized in that it is applied to a host room of a data storage system, the data storage system further includes a slave room corresponding to the host room, and the device includes:
    获取单元,用于获取请求写入所述数据存储系统的目标数据;An obtaining unit, configured to obtain the target data requested to be written into the data storage system;
    写入单元,用于将所述目标数据写入所述主机房;A writing unit for writing the target data into the host room;
    同步单元,用于在成功将所述目标数据写入所述主机房之后,将所述目标数据同步至所述从机房。The synchronization unit is configured to synchronize the target data to the slave computer room after successfully writing the target data into the host room.
  19. 一种数据存储系统,其特征在于,包括:A data storage system is characterized in that it comprises:
    主机房和与所述主机房对应的从机房;The host room and the slave room corresponding to the host room;
    所述主机用于执行上述权利要求1-17任一项所述方法。。The host is used to execute the method described in any one of claims 1-17. .
  20. 一种计算机可读介质,其特征在于,所述计算机可读介质存储有处理器可执行的程序代码,所述程序代码被所述处理器执行时使所述处理器执行权利要求1-17任一项所述方法。A computer-readable medium, wherein the computer-readable medium stores program code executable by a processor, and when the program code is executed by the processor, the processor executes any of claims 1-17. One of the methods described.
PCT/CN2020/086773 2020-04-24 2020-04-24 Data synchronization method and device, data storage system and computer-readable medium WO2021212493A1 (en)

Priority Applications (2)

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

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
WO2021212493A1 true WO2021212493A1 (en) 2021-10-28

Family

ID=78270983

Family Applications (1)

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

Country Status (2)

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

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115174682A (en) * 2022-06-17 2022-10-11 中国银联股份有限公司 Data distribution method, system, center, device and computer readable storage medium

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
CN110633175A (en) * 2019-09-27 2019-12-31 掌阅科技股份有限公司 Multi-computer-room data processing method based on micro-service, electronic equipment and storage medium

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110673941B (en) * 2019-09-27 2020-07-17 掌阅科技股份有限公司 Migration method of micro-services in multiple computer rooms, 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
CN110633175A (en) * 2019-09-27 2019-12-31 掌阅科技股份有限公司 Multi-computer-room data processing method based on micro-service, electronic equipment and storage medium

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115174682A (en) * 2022-06-17 2022-10-11 中国银联股份有限公司 Data distribution method, system, center, device and computer readable storage medium

Also Published As

Publication number Publication date
CN115004662A (en) 2022-09-02

Similar Documents

Publication Publication Date Title
US11379461B2 (en) Multi-master architectures for distributed databases
US20220239602A1 (en) Scalable leadership election in a multi-processing computing environment
US11221995B2 (en) Data replication from a cloud-based storage resource
US20130346366A1 (en) Front end and backend replicated storage
CN112084258A (en) Data synchronization method and device
JP5548829B2 (en) Computer system, data management method, and data management program
WO2019091324A1 (en) Data synchronization method and device, and electronic device
CN105493474B (en) System and method for supporting partition level logging for synchronizing data in a distributed data grid
JP5686034B2 (en) Cluster system, synchronization control method, server device, and synchronization control program
CN111143382A (en) Data processing method, system and computer readable storage medium
CN113094430B (en) Data processing method, device, equipment and storage medium
US9998544B2 (en) Synchronization testing of active clustered servers
WO2021212493A1 (en) Data synchronization method and device, data storage system and computer-readable medium
CN115104295A (en) Data processing method, data processing device, electronic device and storage medium
CN114925078A (en) Data updating method, system, electronic device and storage medium
CN111294231B (en) Resource management method and system
WO2021168697A1 (en) Data synchronization method and apparatus, data storage system, and computer readable medium
CN111522688B (en) Data backup method and device for distributed system
CN112052104A (en) Message queue management method based on multi-computer-room realization and electronic equipment
CN113423095B (en) Information interaction method and device and electronic equipment
CN113760934B (en) Data reading method and terminal
US11334455B2 (en) Systems and methods for repairing a data store of a mirror node
US20230138900A1 (en) Systems and methods for managing cloud environments
CN117112690A (en) Data synchronization method of distributed cluster and related equipment thereof
CN114168359A (en) Resource data processing method and device, electronic equipment and storage medium

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20932326

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 17/03/2023)

122 Ep: pct application non-entry in european phase

Ref document number: 20932326

Country of ref document: EP

Kind code of ref document: A1