Data synchronization method, device, data storage system and computer readable medium
By first writing data to the host room in the multi-computer room data storage system and then synchronizing it to the slave room, the inconsistency problem of data writing in multiple computer rooms is solved, and the overall consistency of the data is improved.
Patent Information
- Application Number
- CN202080094721.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-04-24
- Publication Date
- 2025-02-28
- Estimated Expiration
- 2040-04-24
AI Technical Summary
In multi-computer room data storage systems, the prior art requires writing data to each computer room, which leads to inconsistent data in the entire system if the data is written incorrectly in a certain computer room.
A data synchronization method is proposed, first write the target data to the host room, and then after successful writing, the data is synchronized to the slave room to ensure the consistency of the data.
By writing to the host room first and then synchronizing to the slave room, the data inconsistency problem when multiple computer rooms are written at the same time is avoided, and the overall consistency of the data is improved.
Smart Images

Figure 00000000_0000_ABST
Abstract
Description
Technical Field
[0001] The present 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 Art
[0002] With the increasing popularity of network services, the number of users' visits is increasing. If all business data is stored on one server, the server will often fail due to excessive visits. In addition, due to the limitation of server storage space, in application scenarios with large amounts of business data, one server often cannot carry all business data. Therefore, multiple servers are needed to provide services to users. To this end, multiple servers that are used to provide a certain service can be set up in the same computer room, and then multiple computer rooms form a system, which provides data storage functions for the business layer.
[0003] However, when storing data at the business layer, a write operation needs to be performed on each computer room in the system. Then, if data in some computer rooms is written incorrectly, data in the entire system will be inconsistent. Summary of the invention
[0004] The present application proposes a data synchronization method, device, data storage system and computer-readable medium to improve the above-mentioned defects.
[0005] In a first aspect, an embodiment of the present application provides a data synchronization method, which is applied to a main computer room of a data storage system, and the data storage system also includes a slave computer room corresponding to the main computer room. The method includes: obtaining target data requested to be written into the data storage system; writing the target data into the main computer room; after successfully writing the target data into the main computer room, synchronizing the target data to the slave computer room.
[0006] In a second aspect, an embodiment of the present application further provides a data synchronization device, which is applied to a main computer room of a data storage system, and the data storage system also includes a slave computer room corresponding to the main computer room. The device includes: an acquisition unit, a write unit and a synchronization unit. The acquisition unit is used to acquire target data requested to be written into the data storage system. The write unit is used to write the target data into the main computer room. The synchronization unit is used to synchronize the target data to the slave computer room after successfully writing the target data into the main computer room.
[0007] In a third aspect, an embodiment of the present application further provides a data storage system, including: a main computer room and a slave computer room corresponding to the main computer room; the host is used to execute the above method.
[0008] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, wherein the readable storage medium stores a program code executable by a processor, and when the program code is executed by the processor, the processor executes the above method.
[0009] The data synchronization method, device, data storage system and computer-readable medium provided by the present application, when the data storage system is requested to write target data, that is, whether the data is requested to be written in the main computer room or the slave computer room of the system, the target data will be written to the main computer room first, and then, after the target data is successfully written to the main computer room, the target data will be synchronized to the slave computer room. Therefore, it can not only avoid that when the target data is written to multiple computer rooms at the same time, if the data in a certain computer room is written incorrectly, the data in each computer room will be inconsistent, but the data is written to the main computer room first, and the data written to the main computer room is synchronized to the slave computer room based on the data in the main computer room, which can better maintain the consistency of the data. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below 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.
[0011] Figure 1 A schematic diagram of a data storage system provided by an embodiment of the present application is shown;
[0012] Figure 2 A method flow chart of a data synchronization method provided by an embodiment of the present application is shown;
[0013] Figure 3 A method flow chart of a data synchronization method provided by another embodiment of the present application is shown;
[0014] Figure 4 It shows that an embodiment of the present application provides Figure 3 The method flow chart of S320;
[0015] Figure 5 A method flow chart of a data synchronization method provided by another embodiment of the present application is shown;
[0016] Figure 6 It shows that an embodiment of the present application provides Figure 5 The method flow chart of S540;
[0017] Figure 7 A schematic diagram of a client in a data storage system provided by an embodiment of the present application is shown;
[0018] Figure 8 A module block diagram of a data synchronization device provided by another embodiment of the present application is shown;
[0019] Fig. 9 A module block diagram of a data synchronization device provided by another embodiment of the present application is shown;
[0020] Fig.10 A module block diagram of a data synchronization device provided by another embodiment of the present application is shown;
[0021] Fig.11 A schematic diagram of an electronic device provided by an embodiment of the present application is shown;
[0022] Fig.12 It is a storage unit of an embodiment of the present application for storing or carrying program codes for implementing the data synchronization method according to an embodiment of the present application. DETAILED DESCRIPTION
[0023] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application.
[0024] With the increasing popularity of network services, the number of users' visits is increasing. If all business data is stored on one server, the server will often fail due to excessive visits. In addition, due to the limitation of server storage space, in application scenarios with large amounts of business data, one server often cannot carry all business data. Therefore, multiple servers are needed to provide services to users. To this end, multiple servers that are used to provide a certain service can be set up in the same computer room, and the computer room provides the service to users.
[0025] Among the above data management services, in-memory databases are widely used. In-memory databases refer to databases that store data in memory and operate directly. They are generally deployed in clusters, and such clusters are called in-memory database clusters. In-memory database clusters include in-memory database hosts and in-memory database slaves, and data synchronization needs to be maintained between the two. Furthermore, 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, and incremental synchronization means that the in-memory database slave only synchronizes the different parts of the data between it and the in-memory database host.
[0026] Among them, Redis is a high-performance open source database based on memory, written in ANSI C language, and provides programming interfaces in multiple languages. It is often used to implement functions such as data storage and fast access of software or applications. In production environments, redis is widely used. For example, in order to ensure the stability of services while expanding business capacity, redis clusters that support distributed high availability and horizontal expansion are often used to store and access data. In order to improve system stability, the redis system usually adopts a master-slave structure. During the initialization phase of the redis slave node and when new data is written to the master node, a copy of the data on the redis master node needs to be made for backup. This event is called redis master-slave data synchronization.
[0027] like Figure 1 As shown, Figure 1 A schematic diagram of a data storage system is shown, which includes multiple computer rooms, such as Figure 1 As shown, the multiple computer rooms include computer room 1, computer room 2 and computer room 3. Each computer room includes a host and at least one slave corresponding to the host. Figure 1 As shown, the computer room 1 includes a host 10 and slaves 11 and 12 corresponding to the host, wherein the host 10 and the slaves 11 and 12 are all in a master-slave relationship. The host is also called a master node, which provides services to the outside. The slave is also called a slave node, which copies the data of the Master node in real time to ensure consistency with the Master node. The slave cannot be written to by other devices. The data in the slave is synchronized to the slave by the host through data synchronization.
[0028] In addition, if Figure 1 As shown, 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.
[0029] 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.
[0030] In some embodiments, the business layer can write data into the data storage system. The writing method can be to write the data into any computer room in the data storage system. Specifically, the data can be written into the host of any computer room in the data storage system. Then, in order to ensure the consistency of the data, the written data needs to be written in each computer room.
[0031] However, the inventors found in their research that the current Redis-based multi-active solutions for cross-computer room multi-sites all use a multi-site write solution, that is, when the business layer performs data storage, it needs to perform a write operation on the storage cluster of each computer room, and the data storage is considered successful only after the storage clusters of all computer rooms have been successfully written. However, when the business layer performs data storage, it is necessary to perform a write operation on each computer room in the system, and then, if the data in some computer rooms is written incorrectly, the data of the entire system will be inconsistent.
[0032] Therefore, in order to overcome the above-mentioned defects, in an embodiment of the present application, multiple computer rooms within the data storage system are divided into a main computer room and a slave computer room, that is, among the multiple computer rooms within the data storage system, one computer room is designated as the main computer room, and the other computer rooms are slave computer rooms corresponding to the main computer room.
[0033] The embodiment of the present application provides a data synchronization method, which is applied to the above-mentioned data storage system. As an implementation method, each computer room in the data storage system is provided with a client, and the client is used to write data to a certain computer room and execute the implementation method described in the present application. As an implementation method, the client can be installed in a host in each computer room, or it can be set 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.
[0034] like Figure 2 As shown, Figure 2 A data synchronization method is shown, and the execution subject of the method may be the above-mentioned main computer room, and specifically, the execution subject may be a client in the main computer room. Specifically, the method includes: S201 to S203.
[0035] S201: Acquire target data requested to be written into the data storage system.
[0036] As an implementation, 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 the data write request to the data storage system.
[0037] In some embodiments, the data write request may include a number of a computer room to which the data is requested to be written, and the number is used as the identity information of the computer room. In this embodiment, the business layer requests to write the target data into the computer room corresponding to the specified number. In other embodiments, the data write request may not include a number of a computer room to which the data is requested to be written.
[0038] Regardless of whether the data is designated to be written into a certain computer room or not, as long as the data corresponds to the data write request to be written into the data storage system, it can be used as the target data requested to be written into the data storage system.
[0039] The main computer room can monitor the data written into each computer room (including the main computer room and the slave computer rooms corresponding to the main computer room) so that the main computer room can obtain the target data requested to be written into the data storage system.
[0040] As an implementation method, the host computer room and the slave computer room each have a corresponding message queue, the host computer room subscribes to the message queues of all the slave computer rooms, and each slave computer room subscribes to the message queue of the host computer room. The computer rooms and the application programs such as the business layer communicate with each computer room through message queues. Specifically, the message queue (MessageQueue, MQ) is an application-to-application communication method. Application programs communicate by writing and retrieving data (messages) for the application programs in and out of the queue.
[0041] 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, since the main computer room has subscribed to the message queue of the slave computer room, the main computer room can monitor the operations of the slave computer room on the message queue. Therefore, when the data write request is written to the message queue, it can be monitored by the main computer room, and then the target data requested to be written to the data storage system can be obtained.
[0042] S202: Writing the target data into the computer room.
[0043] After obtaining the target data requested to be written into the data storage system, the target data is written into the main computer room.
[0044] As an implementation method, the main computer room includes a main computer and a slave corresponding to the main computer. The implementation method of writing the target data into the main computer room may be to write the target data into the main computer, and then the host synchronizes the target data to the slave corresponding to the main computer.
[0045] Assuming that the above-mentioned computer room 1 is a main computer room and the target data is data data, the host 10 will synchronize the data data to the slaves 11 and 12 corresponding to the host.
[0046] As an implementation method, a log flow function is provided in each computer room, and the log flow function is used to record the operation of writing data to the host. In the Redis cluster cross-computer room multi-active solution based on log flow, all Redis data writes will be saved in the log flow of the local disk. The external scanning program scans the log flow and synchronizes the data modification to the Redis clusters of other computer rooms, where each Redis cluster can be understood as the above-mentioned computer room. Through the log flow, each write operation of each computer room can be recorded to facilitate data synchronization.
[0047] Specifically, taking the above storage system as a Redis system as an example, modify the source code implementation of the Redis component, add a binlog (i.e., log flow) function, record each write operation in a log file, and ensure that the order of the log record is consistent with the order of the write operation actually received. For example, write multiple data to the host, the multiple data are data1, data2, data3, data4, data5, and data6, that is, the write order of the multiple data is data1, data2, data3, data4, data5, and data6, then the multiple data are recorded in the log file, and the order of the log record is also data1, data2, data3, data4, data5, and data6, wherein data1, data2, data3, data4, data5, and data6 can be the identifiers of the multiple data, and the write time of each written data can also be recorded in the log record.
[0048] In addition, both the host and the slave can have corresponding log files, that is, the host and the slave can perform the log flow function to record the write operations of the host and the slave, where the write operation for the slave can be understood as the data synchronization operation of the host to the slave.
[0049] Therefore, through the above-mentioned recording of the written data, the target data written by the host can be obtained, wherein the target data can be a collection of multiple data written continuously, or can be a certain data among multiple data written continuously.
[0050] S203: After the target data is successfully written into the main computer room, the target data is synchronized to the slave computer room.
[0051] Specifically, it is determined whether the target data is successfully written into the main computer room. If the target data is successfully written into the main computer room, the target data is synchronized to the slave computer room.
[0052] The implementation method of determining whether the target data is successfully written into the host room is to determine whether the target data is successfully synchronized to the slave corresponding to the host after the target data is written into the host. Specifically, how to determine whether the target data is successfully synchronized to the slave corresponding to the host can refer to the subsequent embodiments.
[0053] After the target data is written into the main computer room, the target data is stored in the storage space corresponding to the main computer room, and then a data synchronization operation is performed. Specifically, the client sends the target data written into the main computer room to the slave computer room corresponding to the main computer room, so that the data stored in the slave computer room is also updated. In other words, the target data is synchronized into the storage space corresponding to the slave computer room.
[0054] If the target data is successfully synchronized to the slave corresponding to the host, it can be determined that the target data written to the host has been successfully synchronized to the slave corresponding to the host, and the target data can be synchronized to the slave room at this time.
[0055] Taking the above data storage system as an example, the host 10 in the computer room 1 is written with the target data, and the host 10 synchronizes the target data to the slaves 11 and 12. After determining that the slaves 11 and 12 have successfully synchronized the target data, the target data is sent to the computer room 2 and the computer room 3. After obtaining the target data, the computer room 2 and the computer room 3 perform the synchronization operation of the target data. Specifically, the host 10 sends the target data to the host 20 in the computer room 2 and the host 30 in the computer room 3, the host 20 is written with the target data, and the target data is synchronized to the slaves 21 and 22 corresponding to the host 20, and the host 30 is written with the target data, and the target data is synchronized to the slaves 31 and 32 corresponding to the host 20.
[0056] Therefore, when the data storage system is requested to write target data, that is, whether the data is requested to be written in the main computer room or the slave computer room of the system, the target data will be written to the main computer room first, and then, after the target data is successfully written to the main computer room, the target data will be synchronized to the slave computer room. Therefore, it can not only avoid that when writing target data to multiple computer rooms at the same time, if the data in a certain computer room is written incorrectly, the data in each computer room will be inconsistent, but the data is written to the main computer room first, and the data written to the main computer room is synchronized to the slave computer room based on the data in the main computer room, which can better maintain the consistency of data.
[0057] See also Figure 3 , Figure 3 A data synchronization method is shown, and the execution subject of the method may be the above-mentioned main computer room, and specifically, the execution subject may be a client in the main computer room. Specifically, the method includes: S310 to S340.
[0058] S310: Monitor the write operations of the main computer room and the slave computer room.
[0059] As an implementation method, the client in the host in the main computer room can detect write operations for all computer rooms. For example, through the above-mentioned message queue, the main computer room subscribes to the message queues of all slave computer rooms. Then, when data is written to any slave computer room, the write operation of the slave computer room can be monitored. When data is written to the main computer room itself, the write operation will also be written to the message queue of the main computer room, so that the corresponding slave computer room that has subscribed to the message of the main computer room can also know that data has been written to the main computer room. Data written to any computer room in the data storage system can be regarded as a write operation to the data storage system.
[0060] Therefore, by monitoring the message queues of each computer room, it is possible to detect the current write operation to the data storage system when data is written to any computer room.
[0061] S320: When the write operation is detected, the target data is obtained according to the write operation.
[0062] The write operation can specify the data requested to be written. For example, the write operation can be a data packet, which includes the data requested to be written. When the computer room detects the write operation, it can parse the write operation to obtain the data requested to be written.
[0063] As an implementation mode, when there is only one write operation, the data requested to be written can be used as the target data.
[0064] As another implementation, 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, the data requested to be written corresponding to any write operation can be selected as the target data.
[0065] As another implementation, if there are multiple write operations, then determine whether the data modification request of each write operation is the same, and find out the write operations with the same data modification request. The data modification request can be the same as the data requested to be written and the same as the data object requested to be changed, wherein the data object requested to be changed can be a certain content to be modified stored in the main computer room or in 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 to the data requested to be written.
[0066] If the write operation is an update request, the content to be modified can be a certain specified data stored in the computer room, and when the write operation is executed, the specified data is modified to the data requested to be written. If the write operation is a newly added data, the content to be modified is the storage space in the computer room, and when the write operation is executed, the data requested to be written is written into the storage space.
[0067] 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 contents to be modified, that is, write operations with 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 main computer room includes data1, the data stored in the slave computer room also includes data1, and data1 in the main computer room and data1 in the slave computer room should maintain data consistency.
[0068] Therefore, if the content to be modified is the specified data, the identifier of the specified data is obtained, and the write operation with the same identifier of the specified data is used as the write operation with the same modification purpose. If the content to be modified is the storage space, each write operation of the content to be modified as the storage space can be used as a write operation with the same modification purpose. Alternatively, if the write operation is the newly added data, a data identifier will be configured for the write operation, and the data identifier will be a newly added identifier. When the data is written into the computer room, the data identifier will also correspond to the computer room.
[0069] 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. Operation 4 and operation 5 are used to add a data, and the added data is identified as data7. Operation 6 is used to add a data, and the added data is identified as data8. Operation 7 is used to add a data, and the added data is identified as data9.
[0070] The above-mentioned 7 write operations can be divided into four modification purposes, namely modification purpose 1, modification purpose 2, modification purpose 3 and modification purpose 4. The write operations corresponding to modification purpose 1 are operation 1, operation 2 and operation 3, the write operations corresponding to modification purpose 2 are operation 4 and operation 5, the write operation corresponding to modification purpose 3 is operation 6, and the write operation corresponding to modification purpose 4 is operation 7.
[0071] Therefore, for different modification purposes, the write operation corresponding to each modification purpose is determined. Specifically, the implementation method of determining the write operation corresponding to each modification purpose can refer to Figure 4Steps S321 to S323 in the embodiment. For each modification purpose, S321 to S323 can be performed to determine the write operation corresponding to each modification purpose.
[0072] S321: If there are multiple write operations, obtain a timestamp corresponding to each write operation.
[0073] Each of the write operations corresponds to designated data, which is used to modify the content to be modified into the designated data. The designated data corresponding to each of the write operations may be the same or different.
[0074] As an implementation method, each write operation corresponds to a timestamp, and the timestamp is used to record the time corresponding to the write operation. Specifically, when the business layer inputs a write request to write specified data to the data storage system, the data storage system configures a timestamp for the write request and treats the write request as a write operation, so that a timestamp can be configured for the write operation.
[0075] S322: Determine a target write operation from among the multiple write operations according to the timestamp.
[0076] The timestamp can be used as the time when the request to write the specified data corresponding to the write operation is made, that is, it can be used as the writing time of different write operations. As an implementation method, the target write operation can be determined according to the order of the timestamps of each write operation. For example, the write operation corresponding to the earliest or latest timestamp is selected as the target write operation.
[0077] Specifically, the timestamps corresponding to the multiple write operations may be the same or may not be completely the same. In the case of completely the same or not completely the same, the implementation method of determining the target write operation from among the multiple write operations according to the timestamp may be different.
[0078] Specifically, it is determined whether the timestamps corresponding to the various write operations are all the same; if the timestamps are not all the same, the latest timestamp among all the timestamps is determined as the target timestamp.
[0079] Among them, the timestamps are not all the same, that is, among all the timestamps, there may be the same timestamps and different timestamps, that is, not all the timestamps are the same. Then, all the timestamps can be sorted in chronological order to obtain a time series, and the last timestamp in the time series is used as the target timestamp.
[0080] Then, the write operation corresponding to the target timestamp is used as the write operation to be selected. The latest timestamp may include multiple timestamps, that is, multiple latest timestamps can be obtained, and the write operation corresponding to each latest timestamp can be used as the write operation to be selected.
[0081] As another implementation, all write operations may be sorted in the time order of the timestamps to obtain a sequence to be selected. The sequence to be selected includes multiple identifiers of write operations, and the identifier of the write operation may be identity information for recording each write operation. In the sequence to be selected, each identifier of the write operation corresponds to a sequence number, and the write operation with an earlier sequence number has an earlier timestamp, that is, the write operations are sorted in the time order of the timestamps to obtain the sequence to be selected. Then, the frontmost write operation in the sequence to be selected is used as the write operation to be selected. If there are multiple write operations with the same timestamp, the sequence numbers corresponding to the write operations with the same timestamp are the same, and therefore, the obtained write operations to be selected may be multiple, wherein the timestamp corresponding to each write operation to be selected is the same, and among the timestamps corresponding to all the write operations, the timestamp corresponding to each write operation to be selected is the latest timestamp.
[0082] Then, the target write operation is determined from the candidate write operations. If the number of the candidate write operations is 1, the candidate write operation is used as the target write operation. If the number of the candidate write operations is at least two, the operation object corresponding to each of the candidate write operations is determined, and the operation object includes the main computer room or the slave computer room. Among them, the operation object can be the computer room specified for writing when the business layer requests to store data. Specifically, when the data write request includes the identifier of the computer room, and when the main computer room and the slave computer room are pre-set, the identifier of each computer room can be corresponded to a label, and the label includes the main computer room label and the slave computer room label. Therefore, through the identifier of the computer room included in the data write request, it can be determined whether the label of the computer room corresponding to the identifier of the computer room is the main computer room label or the slave computer room label, and then it can be determined whether the computer room requested to write data is the main computer room or the slave computer room, that is, the operation object corresponding to each write operation is determined.
[0083] The candidate write operation whose operation object is the main computer room is taken as the target write operation.
[0084] For example, the multiple write operations mentioned above include operation 1, operation 2, operation 3, operation 4, operation 5, operation 6 and operation 7, and the timestamps corresponding to operation 1, operation 2, operation 3, operation 4, operation 5, operation 6 and operation 7 are time t1, time t2, time t3, time t4, time t5, time t6 and time t7. In the order of time, the time sequence of each timestamp is time t1, time t2, (time t3 and time t4), (time t5, time t6 and time t7), that is, time t3 and time t4 are the same, and time t5, time t6 and time t7 are the same. It can be understood that operation 1 is obtained first, then operation 2 is obtained, and then operation 3 and operation 4 are obtained at the same time, and finally operation 5, operation 6 and operation 7 are obtained at the same time.
[0085] Then, the candidate write operations may be determined to be operation 5 , operation 6 , and operation 7 , and then a target write operation is determined from operations 5 , 6 , and 7 .
[0086] As an implementation method, the operation objects 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 respectively the main computer room, slave computer room 1 and slave computer room 2. Then the candidate write operation whose operation object is the main computer room is operation 5, so the target write operation may be determined to be operation 5.
[0087] In addition, if there is only one write operation to be selected, for example, operation 1, operation 1 can be directly used as the target write operation.
[0088] As another implementation, if when the write operation is detected, the timestamps corresponding to each write operation are all the same, then it is not necessary to perform a write operation to find the latest timestamp, but the operation object corresponding to each write operation can be directly obtained. The operation object can refer to the above description and will not be repeated here.
[0089] Specifically, if the timestamps of each write operation are all the same, determine the operation object corresponding to each of the candidate write operations, the operation object includes the main computer room or the slave computer room; and take the candidate write operation whose operation object is the main computer room as the target write operation.
[0090] S323: Use the designated data corresponding to the target write operation as target data.
[0091] Exemplarily, assume that the write operations currently obtained include operation 1, operation 2, operation 3, operation 4, operation 5, operation 6, operation 7, operation 8, operation 9 and operation 10, wherein the content to be modified corresponding to operation 1, 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, and 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. Assume that the specified data corresponding to operation 1, operation 2, operation 3, operation 4, operation 5, operation 6 and operation 7 are data 1, data 2, data 3, data 4, data 5, data 6 and data 7 respectively, and assume that the operation objects corresponding to operation 1, operation 2, operation 3, operation 4, operation 5, operation 6 and operation 7 are slave computer room 1, slave computer room 2, master computer room, slave computer room 3, master computer room, slave computer room 1 and slave computer room 2 respectively. For example, the purpose of operation 1 is to modify data1 stored in computer room 1 to data1.
[0092] Then, the timestamps corresponding to operations 5, 6, and 7 are the latest, so it can be determined that the target write operation is operation 5 whose operation object is the main computer room, and the determined target data is data 5. Finally, the modification method of data1 this time is determined to modify the data data1 in the main computer room to data 5, and synchronize data 5 to other slave computer rooms, so that data1 in all slave computer rooms is modified to data 5.
[0093] Then, after completing the operation of modifying data1 in each computer room to data 5, modify data7 in all computer rooms according to operations 8, 9, and 10. The method of determining the target data can refer to the above, and the modification method is to modify data7 in the host first, and then synchronize them one by one.
[0094] S330: Writing the target data into the computer room.
[0095] S340: After the target data is successfully written into the main computer room, the target data is synchronized to the slave computer room.
[0096] See also Figure 5 , Figure 5 A data synchronization method is shown, and the execution subject of the method may be the above-mentioned main computer room, and specifically, the execution subject may be a client in the main computer room. Specifically, the method includes: S510 to S550.
[0097] S510: Acquire target data requested to be written into the data storage system.
[0098] S520: Writing the target data into the computer room.
[0099] S530: After the target data is successfully written into the main computer room, the target data is synchronized to the designated computer room.
[0100] The designated computer room is one of the multiple slave computer rooms.
[0101] As an implementation method, a synchronization state can be set for each slave computer room, and the synchronization state includes unsynchronized and synchronized. Then, each time a slave computer room is selected from the unsynchronized slave computer rooms as the designated computer room, the target data is synchronized to the designated computer room, and when the target data is successfully synchronized to the designated computer room, the synchronization state corresponding to the designated computer room will be changed, for example, changing the unsynchronized state to the synchronized state.
[0102] As an implementation method, a synchronization sequence may be preset, and the main computer room synchronizes the target data to all slave computer rooms according to the synchronization sequence, and then one slave computer room is selected in turn as the designated computer room according to the synchronization sequence.
[0103] S540: Determine whether the data is successfully synchronized to the designated computer room.
[0104] As an implementation method, it is possible to determine whether the target data is successfully synchronized to the slave computer room corresponding to the main computer room based on the information replied from the slave computer room, or it is possible to determine whether the target data is successfully synchronized to the slave computer room corresponding to the main computer room based on the data writing records of the above-mentioned main computer room and slave computer room, that is, the log files of the main computer room and slave computer room.
[0105] Specifically, the implementation method 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 received, it is determined that the data is successfully synchronized to the designated computer room; if not received, it is determined that the data is not successfully synchronized to the designated computer room.
[0106] The successful synchronization information may be sent from the slave computer room to the main computer room after the target data is received and successfully stored. After receiving the information, the main computer room can determine that the target data is successfully synchronized to the slave computer room corresponding to the main computer room.
[0107] As an implementation method, it may be determined whether the synchronization success information fed back by the designated computer room is received within the predetermined time period. The starting point of the predetermined time period may be the time point when the operation of synchronizing the target data to the slave computer room corresponding to the master computer room is executed, and the predetermined time length of the predetermined time period may be predetermined, for example, it may be set based on experience. Specifically, the time length of the slave computer room synchronization data may be counted, and the predetermined time length of the predetermined time period may be determined based on the time length.
[0108] As an implementation method, the time lengths for synchronizing multiple data from the machine room may be obtained, and the predetermined time length of the predetermined time period may be determined according to the multiple time lengths. Specifically, the average value of the multiple time lengths may be calculated and used as the predetermined time length of the predetermined time period.
[0109] As another implementation, the rate of synchronizing data from the computer room may be obtained by statistics, and the predetermined time length of the predetermined time period may be obtained according to the data size of the target data and the rate of synchronizing data obtained by statistics. For example, the ratio of the data size of the target data to the rate of synchronizing data obtained by statistics may be obtained as the predetermined time length of the predetermined time period.
[0110] As an implementation, see Figure 6 , the implementation method of determining whether the target data is successfully synchronized to the designated computer room may include: S541 to S543.
[0111] S541: Acquire first record information corresponding to the computer room, where the first record information is used to record an operation performed by the computer room to write target data.
[0112] As an implementation mode, the first record information includes the identifier and operation time of each data written to the main computer room, wherein the operation time is used to record the writing time point of the written data, wherein the identifier of the written data may be an identifier assigned by the main computer room to each written data, wherein the identifier may be an identifier determined according to the content of the data, for example, the identifier of the data may be generated according to the data summary of the data, and as an implementation mode, the data summary of the target data may be used as the identifier of the target data. The data summary may 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.
[0113] 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.
[0114] Similarly, the second record information includes the identification and operation time of the data synchronized from the computer room each time, wherein the operation time may be the time when the data is synchronized from the computer room, and the implementation method of the identification of the data may refer to the aforementioned embodiment, which will not be described in detail here. Each slave computer room corresponds to the second record information, so the second record information from the computer room each time may be the second record information of the specified computer room.
[0115] S543: Determine whether the data is successfully synchronized to the designated computer room according to the first record information and the second record information.
[0116] Among them, the first record information includes the identifier of the data written to the main computer 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. It is possible to judge whether the target data is successfully synchronized to the designated computer room based on the identifier of the data written to the main computer room and the writing 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.
[0117] As an implementation method, 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 is not successfully synchronized to the designated computer room. The first operation time point is the write time point corresponding to the target identifier of the target data written to the main computer room recorded in the first record information, and the second operation time point is the synchronization time corresponding to the target identifier of the target data synchronized to the designated computer room recorded in the second record information. It is determined whether the synchronization time is later than the write time point. If so, it is determined that the target data is successfully synchronized to the designated computer room; otherwise, it is determined that the target data is not successfully synchronized to the designated computer room.
[0118] Specifically, it can be determined whether there is a synchronization moment corresponding to the identifier of the target data in the second record information, and if so, then an operation of determining whether the synchronization moment is later than the writing time point is performed. The implementation method of determining whether there is a synchronization moment corresponding to the identifier of the target data in the second record information can be to determine whether there is a synchronization moment corresponding to the identifier of the target data in the second record information within a predetermined time period, wherein the implementation method of the predetermined time period can refer to the above-mentioned embodiment.
[0119] As another implementation, considering that the method of recording the write operation of the main computer room and the data synchronization operation of the slave computer room can be the above-mentioned log file, that is, recording the write operation of the host and the data synchronization operation of the slave computer in the form of log flow, a serial number can be set for both the main computer room and the slave computer room, and each write operation of the host and each data synchronization operation of the slave computer can be recorded by the serial number.
[0120] 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 target data is successfully written into the computer room. Specifically, a first serial number can be pre-defined, and the initial value of the first serial number is a first initial value. Then, each time data is written into the computer room, the value of the first serial number is updated according to the first update rule, wherein 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 based on the first serial number saved last time.
[0121] 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 numerical value. When data is written for the first time in the main computer room, the value of the first serial number becomes the sum of the first initial value and the first numerical value. After the data is written again, the value of the first serial number becomes the sum of the first initial value and the two first numerical values, that is, the first numerical value is added on the basis of the first serial number saved last time.
[0122] In the embodiment of the present application, assuming that the first sequence number is seq1 and its initial value is 0, 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 value of the first sequence number seq1 becomes 2, and so on. If the written data includes multiple data, the multiple data are data1, data2, data3, data4, data5 and data6, and the correspondence between the data identifier and the value of the sequence number seq1 is: the sequence numbers seq1 corresponding to data1, data2, data3, data4, data5 and data6 are 1, 2, 3, 4, 5 and 6 respectively.
[0123] Therefore, the writing order of each written data and the serial number corresponding to the identifier of each written data can be obtained through the above correspondence. The serial number can be used as the serial number of the written data and can record which target data is written in the entire writing operation.
[0124] 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 numerical 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 numerical value. When synchronizing data from the computer room for the first time, the value of the second serial number becomes the sum of the second initial value and the second numerical value. After synchronizing data again, the value of the second serial number becomes the sum of the second initial value and the two second numerical values, that is, the second numerical value is added on the basis of the second serial number saved last time. Wherein, the first numerical value and the second numerical 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.
[0125] Assuming that the second sequence number is seq2, the initial value is 0. After the data is synchronized from the computer room for the first time, the value of the second sequence number seq2 becomes 1. After the data is synchronized for the second time, the value of the second sequence number seq2 becomes 2, and so on. If the synchronized data includes multiple data, the multiple data are data1, data2, data3, data4, data5 and data6, and the correspondence between the data identifier and the value of the sequence number seq2 is: the sequence numbers seq2 corresponding to data1, data2, data3, data4, data5 and data6 are 1, 2, 3, 4, 5 and 6 respectively.
[0126] It should be noted that the data of seq2 of the slave will only be changed when the slave is successfully synchronized with the data. By determining the relationship between the size of the current seq2 and the size of seq1 corresponding to the target data written by the host, it can be determined whether the slave has successfully synchronized the target data.
[0127] Therefore, it can be determined whether the data is successfully synchronized to the designated computer room based on the size relationship between the first serial number and the second serial number. Specifically, the implementation method of determining whether the data is successfully synchronized to the designated computer room based on the first record information and the second record information can be: obtaining the size relationship between the first serial number and the second serial number; if the size relationship meets a specified condition, determining that the data is successfully synchronized to the designated computer room, wherein the size relationship meeting the specified condition indicates that the designated computer room successfully synchronizes the target data after the target data is written into the main computer room; if the size relationship does not meet the specified condition, determining that the data is not successfully synchronized to the designated computer room.
[0128] Among them, the size relationship can be whether the first sequence number is less than or equal to the second sequence number, or other size relationships that can characterize whether the first sequence number is less than or equal to the second sequence number. For example, it can also be to obtain the ratio between the first sequence number and the second sequence number. If the ratio is greater than 1, it indicates that the first sequence number is greater than the second sequence number. If the ratio is not greater than 1, it indicates that the first sequence number is less than or equal to the second sequence number.
[0129] As an implementation mode, the size relationship can be determined according to the first update rule and the second update rule. If the first update rule and the second update rule are the same, and both increase the same value on the basis of the initial value, then the size relationship can be whether the first sequence number is less than or equal to the second sequence number. If the first update rule and the second update rule are the same, and both subtract the same value on the basis of the initial value, then the size relationship can be whether the first sequence number is greater than or equal to the second sequence number. If the first update rule and the second update rule are different, and the change value corresponding to the first update rule is k times the change value corresponding to the second update rule, then the size relationship can be whether the ratio of the second sequence number to the first sequence number is a positive integer multiple of k.
[0130] 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.
[0131] The fact that the size relationship satisfies a specified condition indicates that the specified computer room successfully synchronizes the target data after the target data is written into the main computer room.
[0132] When the first updating rule and the second updating rule are the same or different, the above-mentioned size relationship is also different, and thus the corresponding designated conditions are also different.
[0133] For example, if the first update rule and the second update rule are the same, and both increase the same numerical value based on the initial value, then the size relationship can be whether the first serial number is less than or equal to the second serial number. If the first serial number is less than or equal to the second serial number, it is determined that the size relationship meets the specified condition; otherwise, it is determined that the size relationship does not meet the specified condition.
[0134] If the first update rule and the second update rule are the same, and both subtract the same value from the initial value, then the size relationship can be whether the first serial number is greater than or equal to the second serial number. If the first serial number is greater than or equal to the second serial number, then it is determined that the size relationship satisfies the specified condition; otherwise, it is determined that the size relationship does not satisfy the specified condition.
[0135] If the first update rule and the second update rule are different, and the change value corresponding to the first update rule is k times the change value corresponding to the second update rule, then the size relationship can be whether the ratio of the second serial number to the first serial number is a positive integer multiple of k. If the ratio of the second serial number to the first serial number is a positive integer multiple of k, then it is determined that the size relationship satisfies the specified condition; otherwise, it is determined that the size relationship does not satisfy the specified condition.
[0136] In an embodiment of the present application, the first update rule and the second update rule may be the same, and both increase the same value based on the initial value, and the size relationship satisfies the specified condition if the first serial number is less than or equal to the second serial number.
[0137] As an implementation mode, 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 is the first value after being updated by the first update rule, and when the slave completes the synchronization operation of the target data, the second serial number is the second value after being updated by the second update rule. The size relationship between the first value and the second value should satisfy the relationship between the first update rule and the second update rule. For example, if the first update rule and the second update rule are the same, the size relationship between the first value and the second value should be the same. If the first update rule is to increase or decrease the value a, and the second update rule is to increase the value b, the ratio of the value a to the value b is c, and the size relationship between the first value and the second value should also satisfy the ratio of the value a to the value b is n times c, where n is a positive integer.
[0138] Assuming that the first update rule and the second update rule are the same, both are 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 first serial number of the main machine room and the second serial number of the slave machine will be initialized, that is, restored to the initial value. Then, when the data to be written is one, that is, the target data is one data, after the main machine room writes the target data, the first serial number should be 1, and after the slave machine 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.
[0139] In addition, considering that there are multiple data written to the main computer room, the data synchronization operation of the main computer room and the main computer room's detection of whether the target data is successfully synchronized to the designated computer room are executed synchronously. It is possible that when the main computer room is determining whether data data1 is successfully synchronized to the slave, the slave has already 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 number. Therefore, if the second sequence number is greater than the first sequence number, it can be explained that the data corresponding to the first sequence number has been successfully synchronized to the slave.
[0140] The writing order of data written to the main machine room and the synchronization order of synchronizing the written data to the slave machine can be the same. For example, the writing order of data written to the main machine room is data1, data2, data3, data4, data5 and data6, and the synchronization order of synchronizing the written data to the slave machine is data1, data2, data3, data4, data5 and data6.
[0141] Therefore, the first serial number corresponding to the target data written in the main machine room is obtained, and the size of the current second serial number of the slave machine is obtained. If the first serial number is less than or equal to the second serial number, it means that the slave machine successfully synchronizes the target data after the target data is written into the main machine room.
[0142] For example, the data written into the main computer room include data1, data2, data3, data4, data5 and data6. At this time, data1, data2, data3, data4, data5 and data6 are successfully written into the main computer room, where data2 is the target data. Referring to Table 1 above, the first sequence number corresponding to the target data is seq1 equal to 2. The main computer room synchronizes data1, data2, data3, data4, data5 and data6 to the slave machine in sequence. At this time, seq2 of the slave machine is 1, indicating that the data successfully synchronized by the slave machine is data1. The first sequence number is greater than the second sequence number, and it can be determined that the target data has not been successfully synchronized to the designated computer room.
[0143] If the seq2 of the slave is 2 at this time, it means that the data successfully synchronized by the slave is data2, that is, the data successfully synchronized by the slave is the target data, and the first sequence number is equal to the second sequence number, then it can be determined that the target data has not been successfully synchronized to the designated computer room.
[0144] If the slave's seq2 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. If the first sequence number is less than the second sequence number, it can be determined that the target data has not been successfully synchronized to the designated computer room.
[0145] 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.
[0146] In addition, when the main computer room corresponds to multiple slave computer rooms, each slave computer room corresponds to a second serial number. The above detection method can be used to determine whether each slave computer room has successfully synchronized the target data, thereby determining whether the target data is successfully synchronized to the slave computer room corresponding to the main computer room.
[0147] In some embodiments, the above-mentioned operation of detecting whether the target data is successfully synchronized to the slave computer room corresponding to the main computer room can be named a scanning operation. If the first sequence number is greater than the second sequence number, that is, when it is determined that the target data is not successfully synchronized to the slave computer room corresponding to the main computer room, you can wait for a certain period of time before continuing to perform the scanning operation, that is, suspend the execution of the scanning operation during this period of time, so that the slave computer room can complete the synchronization operation of the target data within this time.
[0148] 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: after a specified time length, obtaining the size relationship between the first sequence number and the second sequence number again and performing subsequent operations, wherein the operation of synchronizing the target data to the specified computer room is continued within the specified time length. The specified time length may be a pre-set time length, for example, the specified time length may be the same as the predetermined time length corresponding to the above-mentioned predetermined time period, and specifically, the specified time length may be 10ms.
[0149] S550: Use a slave computer room other than the designated computer room in the slave computer rooms as a new designated computer room.
[0150] After determining that the main computer room synchronizes all written data to the designated computer room in the above manner, a slave computer room is reselected from the slave computer rooms outside the designated computer room as a new designated computer room, and the process returns to S530 until all slave computer rooms are synchronized.
[0151] Therefore, the embodiment of the present application can deploy independent Redis clusters in computer rooms in multiple locations, 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 some computer rooms fail (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 availability of services and data security.
[0152] In addition, if Figure 7 As shown, the client may include a scanning process and a subscription process. The scanning process is used to determine whether the data is successfully synchronized to the designated computer room, and the subscription process is used to monitor the write operation of the main computer room and the slave computer room, and when the write operation is detected, the target data is obtained according to the write operation.
[0153] Data synchronization is performed through external programs, which is unaware of the business layer and is easy to use. That is, data synchronization is achieved through the above-mentioned client, so there is no cross-computer room reading and writing, which will not affect business performance. It supports simultaneous reading and writing in multiple locations, and supports data synchronization between any number of clusters. Businesses can be deployed in multiple locations according to the situation, and it has strong scalability. The master-slave computer room mechanism ensures the final consistency of data when writing in multiple locations at the same time.
[0154] See also Figure 8 , which shows a structural block diagram of a data synchronization device 800 provided in an embodiment of the present application. The device may include: an acquisition unit 801, a writing unit 802 and a synchronization unit 803.
[0155] The acquisition unit 801 is used to acquire target data requested to be written into the data storage system.
[0156] The writing unit 802 is used to write the target data into the computer room.
[0157] The synchronization unit 803 is used to synchronize the target data to the slave computer room after the target data is successfully written into the master computer room.
[0158] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices and modules can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here.
[0159] See also Fig. 9 , which shows a structural block diagram of a data synchronization device 900 provided in an embodiment of the present application. The device may include: an acquisition unit 910, a writing unit 920 and a synchronization unit 930.
[0160] The acquiring unit 910 is configured to acquire target data requested to be written into the data storage system.
[0161] The acquisition unit 910 further includes a monitoring subunit 911 and a data determination subunit 912 .
[0162] The monitoring subunit 911 is used to monitor the write operations of the main computer room and the slave computer room.
[0163] The data determination subunit 912 is further configured to obtain the target data according to the write operation when the write operation is detected.
[0164] Specifically, the data determination subunit 912 is also used to obtain a timestamp corresponding to each of the write operations if there are multiple write operations, wherein each of the write operations corresponds to specified data, which is used to modify the content to be modified to the specified data; determine a target write operation from among the multiple write operations according to the timestamp; and use the specified data corresponding to the target write operation as the target data.
[0165] Furthermore, the data determination subunit 912 is also used 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; and determine the target write operation from the candidate write operations.
[0166] Furthermore, the data determination subunit 912 is further configured to, if the number of the write operations to be selected is 1, use the write operations to be selected as target write operations.
[0167] Furthermore, the data determination subunit 912 is also used to determine the operation object corresponding to each of the candidate write operations if the number of the candidate write operations is at least two, and the operation object includes the main computer room or the slave computer room; and take the candidate write operation whose operation object is the main computer room as the target write operation.
[0168] Furthermore, the data determination subunit 912 is further configured to determine, if the timestamps are all the same, an operation object corresponding to each of the to-be-selected write operations, the operation object including a main computer room or a slave computer room;
[0169] The candidate write operation whose operation object is the main computer room is taken as the target write operation.
[0170] The writing unit 920 is used to write the target data into the computer room.
[0171] The synchronization unit 930 is used to synchronize the target data to the slave computer room after the target data is successfully written into the master computer room.
[0172] The main computer room and the slave computer room both have corresponding message queues, the main computer 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 main computer room, and after the target data is successfully written into the main computer room, the target data is synchronized to the slave computer room, including: after the target data is successfully written into the main computer room, the target data is synchronized to the slave computer room through the message queue corresponding to the main computer room.
[0173] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices and modules can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here.
[0174] See also Fig.10 , which shows a structural block diagram of a data synchronization device 1000 provided in an embodiment of the present application. The device may include: an acquisition unit 1010, a writing unit 1020 and a synchronization unit 1030.
[0175] The acquisition unit 1010 is used to acquire target data requested to be written into the data storage system.
[0176] The writing unit 1020 is used to write the target data into the computer room.
[0177] The synchronization unit 1030 is used to synchronize the target data to the slave computer room after the target data is successfully written into the master computer room.
[0178] The synchronization unit 1030 includes a selection subunit 1031 , a judgment subunit 1032 and a synchronization subunit 1033 .
[0179] The selection subunit 1031 is used for synchronizing the target data to a designated computer room after the target data is successfully written into the main computer room, and the designated computer room is one of the multiple slave computer rooms.
[0180] The judging subunit 1032 is used to judge whether the data is successfully synchronized to the designated computer room.
[0181] In some embodiments, the judgment subunit 1032 is also used to detect whether the synchronization success information fed back by the designated computer room is received; if received, it is determined that the data is successfully synchronized to the designated computer room; if not received, it is determined that the data is not successfully synchronized to the designated computer room.
[0182] In other embodiments, the judgment subunit 1032 is also used to obtain first record information corresponding to the main computer room, the first record information is used to record the operation of writing the target data performed by the main computer room; obtain second record information corresponding to the designated computer room, the second record information is used to record the data synchronization operation of the target data performed by the designated computer room; and determine whether the data is successfully synchronized to the designated computer room based on the first record information and the second record information.
[0183] Furthermore, the judgment 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 determined that the data is successfully synchronized 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.
[0184] Among them, 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 target data is successfully written into the main computer room; 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 data is successfully synchronized in the designated computer room.
[0185] Furthermore, the judgment 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 the specified conditions, it is determined that the data is successfully synchronized to the designated computer room, wherein the size relationship meets the specified conditions indicating that the designated computer room successfully synchronizes the target data after the target data is written into the main computer room; if the size relationship does not meet the specified conditions, it is determined that the data is not successfully synchronized to the designated computer room.
[0186] Among them, the first update rule is to increase or decrease the first serial number by a first value when the target data is successfully written into the main computer room, and the second update rule is to increase or decrease the second serial number by a second value when the data is successfully synchronized in the designated computer room, and the first value and the second value are the same.
[0187] The size relationship satisfies a specified condition when the first serial number is smaller than or equal to the second serial number.
[0188] Furthermore, the judgment subunit 1032 is also used to obtain the size relationship between the first serial number and the second serial number again after a specified time length and perform subsequent operations, wherein the operation of synchronizing the target data to the specified computer room continues within the specified time length.
[0189] The synchronization subunit 1033 is used to synchronize the target data to the designated computer room, if the data is successfully synchronized to the designated computer room, and then use the slave computer room other than the designated computer room as the new designated computer room, and return to execute synchronization of the target data to the designated computer room until the target data synchronization operation of all the slave computer rooms is completed.
[0190] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices and modules can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here.
[0191] In several embodiments provided in the present application, the coupling between modules may be electrical, mechanical or other forms of coupling.
[0192] In addition, each functional module in each embodiment of the present application can be integrated into a processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The above integrated modules can be implemented in the form of hardware or software functional modules.
[0193] Please refer to Fig.11 , which shows a structural block diagram of an electronic device provided in an embodiment of the present application. The electronic device 100 may be an electronic device capable of running applications, such as a smart phone, a tablet computer, an e-book, etc. The electronic device 100 in the present application may include one or more of the following components: a processor 110, a memory 120, and one or more applications, wherein the one or more applications may be stored in the memory 120 and configured to be executed by one or more processors 110, and the one or more programs are configured to execute the method described in the aforementioned method embodiment.
[0194] 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 various functions and processes data of the electronic device 100 by running or executing instructions, programs, code sets or instruction sets stored in the memory 120, and calling data stored in the memory 120. Optionally, the processor 110 can be implemented in at least one hardware form of digital signal processing (Digital Signal Processing, DSP), field programmable gate array (Field-Programmable Gate Array, FPGA), and programmable logic array (Programmable Logic Array, PLA). The processor 110 can integrate one or a combination of a central processing unit (Central Processing Unit, CPU), a graphics processing unit (Graphics Processing Unit, GPU) and a modem. Among them, the CPU mainly processes the operating system, user interface and application programs; the GPU is responsible for rendering and drawing display content; and the modem is used to process wireless communications. It can be understood that the above-mentioned modem may not be integrated into the processor 110, but may be implemented separately through a communication chip.
[0195] The memory 120 may include a random access memory (RAM) or a read-only memory (ROM). 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, wherein the program storage area may store instructions for implementing an operating system, instructions for implementing at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the following various method embodiments, etc. The data storage area may also store data (such as a phone book, audio and video data, chat record data) created by the terminal 100 during use.
[0196] Please refer to Fig.12 , which shows a structural block diagram of a computer-readable storage medium provided in an embodiment of the present application. The computer-readable medium 1200 stores program codes, which can be called by a processor to execute the method described in the above method embodiment.
[0197] The computer readable storage medium 1200 may be an electronic memory such as a flash memory, an EEPROM (electrically erasable programmable read-only memory), an EPROM, a hard disk, or a ROM. Optionally, the computer readable storage medium 1200 includes a non-transitory computer-readable storage medium. The computer readable storage medium 1200 has storage space for program code 1210 that performs any method steps in the above method. These program codes can be read from or written to one or more computer program products. The program code 1210 can be compressed, for example, in an appropriate form.
[0198] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not cause 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
1. A data synchronization method, characterized in that: A main computer room applied to a data storage system, the data storage system further comprising a slave computer room corresponding to the main computer room, the slave computer room being multiple, the method comprising: Monitoring the write operations of the main computer room and the slave computer room; If there are multiple write operations, obtain a timestamp corresponding to each write operation, wherein each write operation corresponds to specified data, which is used to modify the content to be modified into the specified data; Determining a target write operation from among the plurality of write operations according to the timestamp; Using the designated data corresponding to the target write operation as target data; Writing the target data into the main computer room; After determining that the target data is successfully written into the main computer room, synchronizing the target data to a designated computer room, wherein the designated computer room is one of the plurality of slave computer rooms; Obtaining a size relationship between a first serial number corresponding to the main computer room and a second serial number corresponding to the designated computer room, wherein the first serial number is used to perform an update operation according to a first update rule when target data is successfully written into the main computer room, and the second serial number is used to perform an update operation according to a second update rule when data is successfully synchronized in the slave computer room, and each of the slave computer rooms corresponds to a second serial number; If the size relationship satisfies a specified condition, it is determined that the target data is successfully synchronized to the designated computer room, wherein the size relationship satisfies the specified condition indicating that the designated computer room successfully synchronizes the target data after the target data is written into the main computer room; If the size relationship does not satisfy the specified condition, it is determined that the data is not successfully synchronized to the specified computer room; If the data is successfully synchronized to the designated computer room, the slave computer room other than the designated computer room in the slave computer room is used as the new designated computer room, and the target data is synchronized to the designated computer room again until the target data synchronization operation of all the slave computer rooms is completed.
2. The method according to claim 1, characterized in that The determining a target write operation from among the plurality of write operations according to the timestamp comprises: If the timestamps are not all the same, determine the latest timestamp among all the timestamps as the target timestamp; Taking the write operation corresponding to the target timestamp as a candidate write operation; A target write operation is determined from among the candidate write operations.
3. The method according to claim 2, characterized in that The step of determining a target write operation from the candidate write operations includes: If the number of the write operations to be selected is 1, the write operation to be selected is used as the target write operation.
4. The method according to claim 2, characterized in that: The step of determining a target write operation from the candidate write operations includes: If the number of the write operations to be selected is at least two, determining an operation object corresponding to each of the write operations to be selected, the operation object including a main computer room or a slave computer room; The candidate write operation whose operation object is the main computer room is taken as the target write operation.
5. The method according to claim 1, characterized in that Also includes: If the timestamps are all the same, determining the operation object corresponding to each candidate write operation, the operation object including the main computer room or the slave computer room; The candidate write operation whose operation object is the main computer room is taken as the target write operation.
6. The method according to claim 1, characterized in that The first update rule is to increase or decrease the first serial number by a first value when the target data is successfully written into the main computer room, and the second update rule is to increase or decrease the second serial number by a second value when the data is successfully synchronized in the designated computer room, and the first value and the second value are the same.
7. The method according to claim 6, characterized in that The size relationship satisfies a specified condition when the first serial number is smaller than or equal to the second serial number.
8. The method according to claim 1, characterized in that If the size relationship does not satisfy the specified condition, after determining that the data is not successfully synchronized to the specified computer room, the method further includes: After a specified time length, the size relationship between the first serial number and the second serial number is obtained again and subsequent operations are performed, wherein the operation of synchronizing the target data to the specified computer room is continued within the specified time length.
9. The method according to claim 1, characterized in that: The host computer room and the slave computer room both have corresponding message queues, the host computer 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 host computer room. After determining that the target data is successfully written into the host computer room, synchronizing the target data to the slave computer room includes: After determining that the target data is successfully written into the main computer room, the target data is synchronized to the slave computer room through a message queue corresponding to the main computer room.
10. A data synchronization device, characterized in that: A main computer room applied to a data storage system, the data storage system further comprising a slave computer room corresponding to the main computer room, the slave computer rooms being multiple, the device comprising: an acquisition unit, configured to monitor the write operations of the main computer room and the slave computer room; if there are multiple write operations, acquire a timestamp corresponding to each write operation, wherein each write operation corresponds to specified data, and is used to modify the content to be modified to the specified data; determine a target write operation from the multiple write operations according to the timestamp; and use the specified data corresponding to the target write operation as the target data; A writing unit, used for writing the target data into the main computer room; A synchronization unit is used to synchronize the target data to a designated computer room after determining that the target data is successfully written into the main computer room, wherein the designated computer room is one of the multiple slave computer rooms; obtain the size relationship between the first serial number corresponding to the main computer room and the second serial number corresponding to the designated computer room, wherein the first serial number is used to perform an update operation according to a first update rule when the target data is successfully written into the main computer room, and the second serial number is used to perform an update operation according to a second update rule when the data is successfully synchronized from the slave computer room, and each of the slave computer rooms corresponds to a second serial number; if the If the size relationship satisfies the specified conditions, it is determined that the target data is successfully synchronized to the designated computer room, wherein the size relationship satisfies the specified conditions indicating that the designated computer room successfully synchronizes the target data after the target data is written into the main computer room; if the size relationship does not satisfy the specified conditions, it is determined that the data is not successfully synchronized to the designated computer room; if the data is successfully synchronized to the designated computer room, the slave computer room other than the designated computer room in the slave computer room is used as a new designated computer room, and the target data is synchronized to the designated computer room again, until the target data synchronization operation of all the slave computer rooms is completed.
11. A data storage system, characterized in that: include: A main machine room and a slave machine room corresponding to the main machine room; The main computer room is used to execute the method described in any one of claims 1 to 9.
12. A computer readable medium, characterized in that The computer-readable medium stores a program code executable by a processor, and when the program code is executed by the processor, the processor executes the method according to any one of claims 1 to 9.
Citation Information
Patent Citations
Data loading method, device and system
CN104794155A
Data synchronization method and device for machine rooms
CN108055343A