Data synchronization method, device, equipment and medium of distributed storage system

By monitoring the instance status in the distributed system and switching the read and write access path, the data out-synchronization problem caused by changes in the cluster instance status is solved, and the normal data reading and writing and data synchronization after recovery is achieved when the instance is offline.

CN112243030BActive Publication Date: 2025-02-07WEBANK (CHINA)
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202011101540.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-10-14
Publication Date
2025-02-07
Estimated Expiration
2040-10-14

AI Technical Summary

Technical Problem

In existing distributed systems, the state changes of cluster instances lead to limited data reading and writing, resulting in data out of synchronization.

Method used

By monitoring the instance status in the main storage server, if the target instance is offline, the offline status information is generated, the proxy server switches the read and write access path to the backup storage server, and writes the data to the backup storage server and publish and subscribe message system; When the instance is restored online, the data in the message system is published and written to the target instance to achieve data synchronization.

Benefits of technology

When the instance is offline, ensure that the distributed storage system can read and write data normally, and synchronize the data in the main storage server and the backup storage server when the instance is restored, solving the problem of data out of synchronization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112243030B_ABST
    Figure CN112243030B_ABST
Patent Text Reader

Abstract

The present invention discloses a data synchronization method, device, equipment and medium for a distributed storage system. The data synchronization method for a distributed storage system switches the read and write access path to the target instance to a backup storage server when an instance of the distributed storage system is in an offline state. During this period, the distributed storage system can read and write data normally. When writing data, the proxy server writes the data into the backup storage server and a publish-subscribe message system respectively. At this time, since the data written into the backup storage server and the publish-subscribe message system are the same, after the instance is restored from an offline state to an online state, the target data in the publish-subscribe message system is consumed, and the target data in the publish-subscribe message system is written into the instance in the online state, so that the data in the primary storage server and the backup storage server can be synchronized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of distributed storage technology, and in particular to a data synchronization method, device, equipment and medium for a distributed storage system. Background Art

[0002] In order to achieve efficient data management, a distributed system is generally used. In order to store massive amounts of data, a distributed system generally uses a cluster for caching. In order to achieve high availability of a distributed system, the prior art generally uses a master-slave structure in a cluster, but due to changes in the state of the instance, data reading and writing are restricted, resulting in data asynchrony in the cluster instances.

[0003] The above contents are only used to assist in understanding the technical solution of the present invention and do not constitute an admission that the above contents are prior art. Summary of the invention

[0004] The main purpose of the present invention is to provide a data synchronization method, device, equipment and medium for a distributed storage system, aiming to solve the technical problem of data asynchrony in cluster instances of existing distributed systems.

[0005] To achieve the above object, the present invention provides a data synchronization method for a distributed storage system, wherein the distributed storage system includes a server cluster and a proxy server, the server cluster includes a primary storage server and a backup storage server, and the primary storage server includes multiple instances;

[0006] The data synchronization method of the distributed storage system comprises the following steps:

[0007] Monitoring the status of the instance in the primary storage server;

[0008] If it is monitored that the target instance in the primary storage server is offline, offline status information of the target instance is generated, so that the proxy server switches the read-write access path of the target instance to the backup storage server after reading the offline status information; wherein, during the period when the read-write access path of the target instance is switched to the backup storage server, the proxy server writes the target data into the backup storage server and the publish-subscribe message system respectively;

[0009] After monitoring that the target instance recovers from the offline state to the online state, the target data in the publish-subscribe message system is consumed, and the target data in the publish-subscribe message system is written to the target instance in the online state, so as to synchronize the data in the primary storage server and the backup storage server.

[0010] Optionally, after the step of monitoring the instance status in the primary storage server, the method further includes:

[0011] If it is monitored that the target instance in the primary storage server is in an online state, online state information of the target instance is generated, so that the proxy server sends the target data in the target instance to the publish-subscribe message system after reading the online state information;

[0012] There is a subscription relationship between the standby storage server and the publish-subscribe messaging system, so that the standby storage server consumes target data in the publish-subscribe messaging system and synchronizes data between the primary storage server and the standby storage server.

[0013] Optionally, the step of monitoring the status of the instance in the primary storage server includes:

[0014] Periodically detecting the ping connection status of the instance in the primary storage server at a preset time interval;

[0015] If the instance fails to connect to the network for at least three consecutive times, the instance is determined to be offline.

[0016] Optionally, after the step of determining that the instance is offline if the network connection of the instance fails for at least three consecutive times, the method further includes:

[0017] When the instance is in an offline state, if it is detected that the instance has successfully connected to the network at least once, it is determined that the target instance is restored from the offline state to the online state.

[0018] Optionally, the distributed storage system further includes a coordination server;

[0019] The step of generating offline status information of the target instance if it is monitored that the target instance in the primary storage server is offline, so that the proxy server switches the read-write access path of the target instance to the backup storage server after reading the offline status information, comprises:

[0020] If it is monitored that the target instance in the main storage server is in an offline state, the offline state information of the target instance is generated and stored in the coordination server, so that after the proxy server reads the offline state information from the coordination server, the read and write access path to the target instance is switched to the backup storage server.

[0021] Optionally, a plurality of logical slots are configured in the proxy server, and a mapping relationship exists between the plurality of logical slots and the plurality of instances.

[0022] Optionally, the primary storage server is a Redis storage server, and the instance is a Redis instance; the backup storage server is a LMDB storage server.

[0023] In addition, to achieve the above-mentioned purpose, the present invention also proposes a data synchronization device for a distributed storage system, wherein the distributed storage system includes a server cluster and a proxy server, the server cluster includes a primary storage server and a backup storage server, and the primary storage server includes multiple instances;

[0024] The data synchronization device of the distributed storage system comprises:

[0025] A status monitoring module, used to monitor the status of instances in the primary storage server;

[0026] an offline processing module, for generating offline status information of the target instance if it is detected that the target instance in the primary storage server is offline, so that the proxy server switches the read-write access path of the target instance to the backup storage server after reading the offline status information; wherein, during the period when the read-write access path of the target instance is switched to the backup storage server, the proxy server writes the target data into the backup storage server and the publish-subscribe message system respectively;

[0027] A data synchronization module is used to consume the target data in the publish-subscribe message system after monitoring that the target instance has recovered from an offline state to an online state, and write the target data in the publish-subscribe message system to the target instance in the online state, so as to synchronize the data in the primary storage server with the backup storage server.

[0028] In addition, to achieve the above-mentioned purpose, the present invention also provides a data synchronization device for a distributed storage system, wherein the data synchronization device for the distributed storage system includes a processor, a memory, and a data synchronization program for the distributed storage system stored in the memory. When the data synchronization program for the distributed storage system is executed by the processor, the steps of the data synchronization method for the distributed storage system as described above are implemented.

[0029] In addition, to achieve the above-mentioned purpose, the present invention also provides a computer storage medium, on which a data synchronization program of a distributed storage system is stored. When the data synchronization program of the distributed storage system is executed by a processor, the steps of the data synchronization method of the distributed storage system as described above are implemented.

[0030] The beneficial effects achieved by the present invention.

[0031] The embodiment of the present invention proposes a data synchronization method, device, equipment and medium of a distributed storage system, wherein the distributed storage system includes a server cluster and a proxy server, wherein the server cluster includes a primary storage server and a backup storage server, and the primary storage server includes multiple instances; the data synchronization method of the distributed storage system first monitors the status of the instance in the primary storage server; if it is monitored that the target instance in the primary storage server is in an offline state, the offline state information of the target instance is generated, so that the proxy server switches the read-write access path of the target instance to the backup storage server after reading the offline state information; wherein, during the period when the read-write access path of the target instance is switched to the backup storage server, the proxy server writes the target data into the backup storage server and the publish-subscribe message system respectively; then, after monitoring that the target instance is restored from the offline state to the online state, the target data in the publish-subscribe message system is consumed, and the target data in the publish-subscribe message system is written into the target instance in the online state, so that the data in the primary storage server is synchronized with that in the backup storage server. It can be seen that when an instance of the distributed storage system is offline, the read and write access path to the target instance is switched to the backup storage server. During this period, the distributed storage system can read and write data normally. When writing data, the proxy server writes the data to the backup storage server and the publish-subscribe message system respectively. At this time, since the data written to the backup storage server and the publish-subscribe message system are the same, after the instance recovers from the offline state to the online state, the target data in the publish-subscribe message system is consumed, and the target data in the publish-subscribe message system is written to the instance in the online state, so that the data in the primary storage server and the backup storage server can be synchronized. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] Figure 1 A schematic diagram of the structure of a distributed storage system according to an embodiment of the present invention;

[0033] Figure 2 Another structural schematic diagram of a distributed storage system according to an embodiment of the present invention;

[0034] Figure 3 A schematic diagram of a data synchronization method for a distributed storage system according to an embodiment of the present invention;

[0035] Figure 4 The structure diagram of the data synchronization device of the distributed storage system according to the embodiment of the present invention is shown in FIG.

[0036] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0037] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.

[0038] Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in the field without making any creative work shall fall within the scope of protection of the present invention.

[0039] It should be noted that the descriptions of "first", "second", etc. in the present invention are only used for descriptive purposes and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In addition, the technical solutions between the various embodiments can be combined with each other, but they must be based on the ability of ordinary technicians in the field to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such a combination of technical solutions does not exist and is not within the scope of protection required by the present invention.

[0040] The main solution of the embodiment of the present invention is: adopting a data synchronization method of a distributed storage system, the distributed storage system includes a server cluster and a proxy server, the server cluster includes a main storage server and a backup storage server, and the main storage server includes multiple instances; the data synchronization method of the distributed storage system first monitors the status of the instance in the main storage server; if it is monitored that the target instance in the main storage server is in an offline state, the offline state information of the target instance is generated, so that the proxy server switches the read and write access path of the target instance to the backup storage server after reading the offline state information; wherein, during the period when the read and write access path of the target instance is switched to the backup storage server, the proxy server writes the target data into the backup storage server and the publish-subscribe message system respectively; then, after monitoring that the target instance is restored from the offline state to the online state, the target data in the publish-subscribe message system is consumed, and the target data in the publish-subscribe message system is written into the target instance in the online state, so that the data in the main storage server and the backup storage server are synchronized.

[0041] Since the existing technology generally adopts a master-slave structure in the cluster, the reading and writing of data will be restricted due to the state change of the instance, resulting in data asynchrony in the cluster instances.

[0042] The present invention provides a solution. In a data synchronization method for a distributed storage system, when an instance of the distributed storage system is in an offline state, the read and write access path to the target instance is switched to a backup storage server. During this period, the distributed storage system can read and write data normally. When writing data, the proxy server writes the data into the backup storage server and the publish-subscribe message system respectively. At this time, since the data written into the backup storage server and the publish-subscribe message system are the same data, after the instance is restored from the offline state to the online state, the target data in the publish-subscribe message system is consumed, and the target data in the publish-subscribe message system is written into the instance in the online state, so that the data in the primary storage server and the backup storage server can be synchronized.

[0043] It should be noted that since the data synchronization method of the distributed storage system of the embodiment of the present application is implemented based on the distributed storage system, before explaining the data synchronization method of the distributed storage system of the present application, the distributed storage system is first explained.

[0044] Reference Figure 1 An embodiment of the present application provides a distributed storage system, which includes a server cluster and a proxy server. The server cluster includes a primary storage server and a backup storage server. The primary storage server includes multiple instances, and the multiple instances are used to store data; the proxy server is configured with multiple logical slots, and there is a mapping relationship between the multiple logical slots and the multiple instances.

[0045] Specifically, in this embodiment, the proxy server is a Redis proxy server; the primary storage server is a Redis server, and the backup storage server is a LMDB server. Therefore, the instance in this embodiment is a Redis instance, and the Redis instance is used to store target data.

[0046] The Redis proxy server is used to produce the target data in the Redis instance into the publish-subscribe message system; the LMDB instance in the LMDB server is used to consume the target data in the publish-subscribe message system, so that the Redis server and the LMDB server store the same target data;

[0047] The Redis proxy server is also used to receive a data read request, and based on an identifier in the data read request, read the target data in the Redis instance or the target data in the LMDB instance.

[0048] It should be noted that the full name of Redis is Remote Dictionary Server, which is translated as remote dictionary service. It is an open source log-type, Key-Value (identity-value) database written in ANSI C language, supports the network, can be based on memory or can be persistent, and provides APIs in multiple languages. Specifically, redis supports storing relatively more value types, including string, list, set, and zset. In this embodiment, the Redis server refers to a server for storing data that has the Redis software installed and configured.

[0049] The full name of LMDB is Lightning Memory-Mapped Database, which means: a memory-mapped database as fast as lightning. LMDB uses memory mapping to access files, which makes the addressing overhead in the file very small and can be achieved using pointer operations; a single database file can also reduce the overhead of data set replication / transmission. In this embodiment, the LMDB server refers to a server for storing data that has the LMDB software installed and configured, serving as a backup for the Redis server.

[0050] It can be seen that since both Redis and LMDB are memory-based data structure storage, they implement database functions by calling memory. Therefore, under the same conditions, in this embodiment, compared with Redis, the selection of LMDB requires relatively less memory space, and accordingly, its hardware configuration requirements are relatively low, and the hardware cost of deployment is relatively low.

[0051] In addition, a Redis proxy server refers to a server with the RedisProxy program installed and configured. RedisProxy is a proxy program in the Redis solution. RedisProxy supports multiple business statement access methods, and the command method is seamlessly compatible with Redis syntax commands. The vector mode provides binary data / natural statement input.

[0052] In the specific implementation process, in the storage distributed storage system of this embodiment, the server cluster is connected to the Redis proxy server for communication to realize data reading and writing. In order to achieve high availability while expanding the data storage capacity, the server cluster may include multiple Redis groups, each Redis group includes a Redis server and an LMDB server, the Redis server serves as the host, and the LMDB server serves as the backup.

[0053] In addition, in order to avoid the single point problem of the proxy point, multiple Redis proxy servers can also be set up to communicate with multiple Redis groups respectively.

[0054] See also Figure 1 The distributed storage system includes: 3 Redis proxy servers, 3 Redis groups, each Redis group includes a Redis server and an LMDB server. Each Redis proxy server establishes a long link with each Redis group, and the long link can reduce the time consumption caused by frequent links.

[0055] In one embodiment, a long connection pool mechanism may be established between the Redis proxy server and the Redis group. Specifically, a long connection management program may be added to the Redis proxy server to perform the following steps:

[0056] When a cache data read or write request is detected, an idle link in the link pool is obtained;

[0057] Sending a data read / write request to a Redis server through the idle link, so that the Redis server performs a target data read / write operation according to the data read / write request;

[0058] If a read / write operation failure is detected, the idle link is determined to be an invalid link;

[0059] If it is detected that the idle link is an invalid link, an invalid notification is sent to the link pool manager so that the link pool manager can start a link recovery mechanism for the idle link.

[0060] Compared with the technology of regularly recycling invalid links in the link pool in the prior art, the storage distributed storage system in this embodiment overcomes the technical defect of the prior art that invalid links cannot be recycled in time by immediately sending an invalid notification to the link pool manager when an idle link is detected as an invalid link, so that the link pool manager can promptly start the link recycling mechanism for the idle link, thereby avoiding invalid links occupying link pool resources.

[0061] In addition, the three Redis proxy servers can also connect to the user end (also called the business end in this embodiment). In one scenario, the distributed storage system is used to deliver the portrait data online. The user end can develop a set of software to facilitate the import of portrait data and output the data read from the server cluster to the advertising delivery software DSP (Demand Side Platform) to facilitate DSP delivery. It should be noted that a long link can also be established between the Redis proxy server and the user end.

[0062] Furthermore, the Redis server may include multiple Redis instances, the LMDB server may include multiple LMDB instances, and the multiple Redis instances are used to store the target data. The storage method may be cache, which is different from disk storage in that the cache can read and write quickly, making data delivery faster.

[0063] The Redis proxy server is used to produce the target data in the Redis instance to the publish-subscribe messaging system; the LMDB instance in the LMDB server is used to consume the target data in the publish-subscribe messaging system, so that the Redis server and the LMDB server store the same target data. In this case, the Redis server acts as the host, stores the target data, and allows the user to read the target data through the Redis proxy server; the LMDB server acts as a backup server, and allows the user to read the target data through the Redis proxy server when the Redis instance in the host goes offline.

[0064] Specifically, the publish-subscribe message system can be Kafka. The Kafka server installed with the Kafka software communicates with the Redis proxy server and the LMDB server. When the Redis instance is normal, the user-side reads and writes data through the Redis proxy server to read and write the host Redis instance. At the same time, the Redis proxy server will act as a producer to produce write command data to the lmdbtopic topic of Kafka; the LMDB proxy server acts as a consumer to consume the data in Kafka in quasi-real time, ensuring the eventual consistency of data between the master and the slave, and ensuring the high availability of the distributed system at a lower deployment cost.

[0065] In addition, when a Redis instance goes offline, the Redis proxy server detects the failed instance and starts the backup solution. The read command data of the offline instance will be switched to the backup LMDB proxy server for reading. The write command data of the offline instance will be produced as production data and copied to the failtopic topic of Kafka. The failtopic will be consumed after the instance goes online to ensure that the write data is cached during the offline instance to avoid loss and inconsistency between the primary and backup.

[0066] When the Redis instance returns to normal, it senses the instance recovery by calling the component and starts consuming the failtopic data as a consumer, and writes it directly to the Redis instance. When all the data in the failtopic is consumed, the read and write requests are switched from the backup machine to the master machine to provide normal high-performance services.

[0067] In addition, in this embodiment, the Redis proxy server may be configured with multiple virtual groups and multiple logical slots, the multiple logical slots are mapped to the multiple virtual groups, and the multiple virtual groups are mapped to the Redis instance and / or LMDB instance, thereby realizing a mapping relationship between the multiple logical slots and the multiple Redis instances;

[0068] The storage distributed storage system also includes a zookeeper server, in which a mapping relationship table is stored. The mapping relationship table includes a mapping relationship between the multiple logical slots and the multiple virtual groups, and a mapping relationship between the multiple virtual groups and the Redis instance and / or LMDB instance.

[0069] In the specific implementation process, the slot is obtained by logical slicing in this embodiment, and therefore, it is called a logical slot; according to the identification key in the data, the CRC (cyclic redundancy check) algorithm is used to perform logical slicing to obtain 1024 logical slots, namely slot0, slot1, slot2...slot1023.

[0070] According to the table name rules set on the business side, AppName.TableName maps to an instance, and multiple slot logical slots (app.table->slot) are statically configured. Different slots are also mapped to the corresponding group virtual groups (slot->group). The virtual group group corresponds to one master and multiple slave instances. The relationship between the three is saved on the zookeeper server.

[0071] When reading and writing data to the Redis server, all slot relationships are obtained through AppName.TablName;

[0072] Get the slotid based on crc32(key)%1024;

[0073] Find the virtual group groupid corresponding to slotid and get the instance information corresponding to group.

[0074] As an optional implementation, the Redis proxy server is also used to receive a data write request, obtain a target logical slot based on an identifier in the data write request, obtain a target virtual group that has a mapping relationship with the target logical slot based on the mapping relationship table, and store the target data in the data write request in a Redis instance that has a mapping relationship with the target virtual group.

[0075] For example, when there is a data write request for the portrait data devicemd5:1101 (key:value format) on the business side, after receiving the data write request, the Redis proxy server will use the CRC32 algorithm on the key in the request and take the modulus of 1024 to calculate the slotid, which is the corresponding ID of the logical slot; then find the corresponding virtual group groupid according to the slotid, and get the Redis instance information (IP and Port) according to its mapping relationship table, and write the data devicemd5:1101 to the Redis instance.

[0076] As another optional implementation, the Redis proxy server is also used to receive a data read request, obtain a corresponding target logical slot based on a value corresponding to an identifier in the data read request, obtain a target virtual group that has a mapping relationship with the target logical slot based on the mapping relationship table, and read target data in a Redis instance that has a mapping relationship with the target virtual group from the Redis server or read target data in an LMDB instance that has a mapping relationship with the target virtual group from the LMDB server.

[0077] It should be understood that the above is only for illustration and does not constitute any limitation to the technical solution of the present invention. Those skilled in the art can make settings based on needs in actual applications and no limitation is made here.

[0078] From the above description, it is not difficult to find that, due to the distributed storage system in this embodiment, logical sharding is performed in the Redis proxy server, and the mapping relationship table is stored in the Zookeeper server to achieve a low coupling design with the cluster, that is, it can match various versions of Redis software in the cluster; relative to the existing codis solution, according to the current version of the codis code, codis does not use logical sharding, but sharding at the bottom of the data, and the current codis version is relatively low and is no longer compatible with a high version of the Redis database. Therefore, the distributed system of this embodiment not only achieves low cost and high availability, but its data bottom layer Redis server is compatible with any native version of Redis and supports Redis version upgrades.

[0079] Based on the distributed storage system in the above embodiment, the embodiment of the present application provides a data synchronization method for a distributed storage system. Figure 2 In this implementation, the distributed storage system further includes a monitoring server, a coordination server and a publish-subscribe message system based on the aforementioned embodiments.

[0080] Specifically, the monitoring server is connected to the primary storage server on the one hand to monitor the status of the instance in the primary storage server; on the other hand, it is connected to the publish-subscribe messaging system to consume the data therein; at the same time, it is connected to the coordination server to store the instance status information. The proxy server is connected to the coordination server to read the instance status information therein; the publish-subscribe messaging system is also connected to the proxy server and the backup storage server to receive the data written by the proxy server and for the backup storage server to consume the data therein.

[0081] based on Figure 2 For a distributed storage system, see Figure 3 , the data synchronization method of the distributed storage system of this embodiment includes:

[0082] S10, monitoring the status of the instance in the primary storage server;

[0083] S20, if it is monitored that the target instance in the primary storage server is offline, generate offline status information of the target instance, so that the proxy server switches the read-write access path of the target instance to the backup storage server after reading the offline status information; wherein, during the period when the read-write access path of the target instance is switched to the backup storage server, the proxy server writes the target data into the backup storage server and the publish-subscribe message system respectively;

[0084] S30. After monitoring that the target instance recovers from the offline state to the online state, consume the target data in the publish-subscribe message system, and write the target data in the publish-subscribe message system to the target instance in the online state, so as to synchronize the data in the primary storage server and the backup storage server.

[0085] It should be noted that since instances can be online and offline, when they are online, they are in a normal state and data can be read and written normally; when they are offline, data cannot be read and written, so there may be data asynchrony in the instances. The data synchronization method of this embodiment can synchronize the data in each instance in response to data asynchrony caused by instance state changes.

[0086] In addition, the method execution subject in this embodiment may be a monitoring server.

[0087] First, S10 is executed to monitor the status of the instance in the primary storage server.

[0088] In the specific implementation process, the instance status refers to whether each instance in the primary storage server is online or offline. Since data asynchrony is caused by the change of instance status, in order to synchronize data, the status of the instance in the primary storage server must be monitored first.

[0089] In one embodiment, the step of monitoring the status of the instance in the primary storage server includes:

[0090] Periodically detecting the network connection status of the instance in the primary storage server at a preset time interval;

[0091] If the instance fails to connect to the network for at least three consecutive times, the instance is determined to be offline.

[0092] In the specific implementation process, the network connection can be a ping command connection. Ping is a command in Windows, Unix and Linux systems. Ping is also a communication protocol and a part of the TCP / IP protocol. The "ping" command can be used to check whether the network is connected, which can help us analyze and determine network failures. Therefore, the ping connection can be used to detect whether the instance is online. That is, if the network connection with the instance cannot be established, it means that the instance is offline.

[0093] Specifically, a ping connection failure may be a temporary ping connection failure caused by an accidental network disconnection. Therefore, in this embodiment, if the instance fails to ping the connection for at least three consecutive times, the instance is determined to be offline.

[0094] Further, after the step of determining that the instance is offline if the ping connection of the instance fails for at least three consecutive times, the method further includes:

[0095] When the instance is in an offline state, if it is detected that the instance is successfully pinged at least once, it is determined that the target instance is restored from the offline state to the online state.

[0096] In the specific implementation process, a successful ping connection indicates that the network is connected. At this time, the instance must be online.

[0097] Next, execute S20. If it is monitored that the target instance in the primary storage server is offline, generate offline status information of the target instance so that the proxy server switches the read-write access path to the target instance to the backup storage server after reading the offline status information; wherein, during the period when the read-write access path of the target instance is switched to the backup storage server, the proxy server writes the target data into the backup storage server and the publish-subscribe message system respectively.

[0098] It should be noted that the target instance is an instance in the primary storage server. Under normal circumstances, the instances are all online, and when the monitoring server detects that the target instance in the primary storage server is offline, offline status information of the target instance is generated.

[0099] Specifically, the distributed storage system may further include a coordination server; in this case, the offline state information may be stored in the coordination server, and the proxy server may read the offline state information from the coordination server, determine that the target instance is offline, and in this case, switch the read-write access path to the target instance to the backup storage server. During the period when the read-write access path of the target instance is switched to the backup storage server, the proxy server writes the target data to the backup storage server and the publish-subscribe message system respectively.

[0100] Among them, the target data is written to the backup storage server to ensure that when the target instance is offline, the distributed storage system can use the backup storage server as a backup machine and write data normally; and the target data is written to the publish-subscribe message system to add the target data to the target instance after the target instance is online, so as to ensure that there is synchronized data in the main storage server and the backup storage server.

[0101] Therefore, next, execute S30, after monitoring that the target instance recovers from the offline state to the online state, consume the target data in the publish-subscribe message system, and write the target data in the publish-subscribe message system to the target instance in the online state, so as to synchronize the data in the primary storage server and the backup storage server.

[0102] During the specific implementation process, after monitoring that the target instance is offline, the status of the target instance is continuously monitored. After monitoring that the target instance is restored from the offline state to the online state, the monitoring server consumes the target data in the publish-subscribe message system and writes the target data in the publish-subscribe message system to the target instance in the online state, so as to synchronize the data in the primary storage server with the data in the backup storage server.

[0103] Specifically, since the target data in the publish-subscribe message system is also synchronously stored in the backup storage server, writing the target data in the publish-subscribe message system to the target instance in the online state can synchronize the data in the primary storage server with the backup storage server.

[0104] As an embodiment, after the step of monitoring the instance status in the primary storage server, the method further includes:

[0105] If it is monitored that the target instance in the primary storage server is in an online state, online state information of the target instance is generated, so that the proxy server sends the target data in the target instance to the publish-subscribe message system after reading the online state information;

[0106] There is a subscription relationship between the standby storage server and the publish-subscribe messaging system, so that the standby storage server consumes target data in the publish-subscribe messaging system and synchronizes data between the primary storage server and the standby storage server.

[0107] In the specific implementation process, the publish-subscribe message system can be Kafka; when the distributed storage system is operating normally, it is also necessary to maintain data synchronization between the primary storage server and the backup storage server. Therefore, if it is monitored that the target instance in the primary storage server is online, the online status information of the target instance is generated, so that the proxy server can send the target data in the target instance to the publish-subscribe message system after reading the online status information.

[0108] As an embodiment, the distributed storage system further includes a coordination server;

[0109] The step of generating offline status information of the target instance if it is monitored that the target instance in the primary storage server is offline, so that the proxy server switches the read-write access path of the target instance to the backup storage server after reading the offline status information, comprises:

[0110] If it is monitored that the target instance in the main storage server is in an offline state, the offline state information of the target instance is generated and stored in the coordination server, so that after the proxy server reads the offline state information from the coordination server, the read and write access path to the target instance is switched to the backup storage server.

[0111] In a specific implementation process, the coordination server may be Zookeeper, which is used to store instance status information for acquisition by the proxy server.

[0112] It should be understood that the above is only for illustration and does not constitute any limitation to the technical solution of the present invention. Those skilled in the art can make settings based on needs in actual applications and no limitation is made here.

[0113] It is not difficult to find from the above description that when an instance of the distributed storage system is in an offline state, the read and write access path to the target instance is switched to the backup storage server. During this period, the distributed storage system can read and write data normally. When writing data, the proxy server writes the data into the backup storage server and the publish-subscribe message system respectively. At this time, since the data written into the backup storage server and the publish-subscribe message system are the same data, after the instance is restored from the offline state to the online state, the target data in the publish-subscribe message system is consumed, and the target data in the publish-subscribe message system is written into the instance in the online state, so that the data in the primary storage server and the backup storage server can be synchronized.

[0114] In addition, an embodiment of the present invention further proposes a computer storage medium, on which a data synchronization program of a distributed storage system is stored. When the data synchronization program of the distributed storage system is executed by a processor, the steps of the data synchronization method of the distributed storage system as described above are implemented.

[0115] See also Figure 4 , based on the same inventive concept as the above-mentioned embodiment, the embodiment of the present application further provides a data synchronization device of a distributed storage system, wherein the distributed storage system comprises a server cluster and a proxy server, wherein the server cluster comprises a primary storage server and a backup storage server, wherein the primary storage server comprises multiple instances;

[0116] The data synchronization device of the distributed storage system comprises:

[0117] A status monitoring module 10, used to monitor the status of instances in the primary storage server;

[0118] The offline processing module 20 is used to generate offline status information of the target instance if it is detected that the target instance in the primary storage server is offline, so that the proxy server switches the read-write access path of the target instance to the backup storage server after reading the offline status information; wherein, during the period when the read-write access path of the target instance is switched to the backup storage server, the proxy server writes the target data into the backup storage server and the publish-subscribe message system respectively;

[0119] The data synchronization module 30 is used to consume the target data in the publish-subscribe message system after monitoring that the target instance has recovered from an offline state to an online state, and write the target data in the publish-subscribe message system to the target instance in the online state, so as to synchronize the data in the primary storage server and the backup storage server.

[0120] It should be noted that the data synchronization device of the distributed storage system in this implementation corresponds one-to-one to the data synchronization method of the distributed storage system in the aforementioned embodiment. Therefore, its various implementations can also refer to the implementations in the aforementioned embodiments and will not be repeated here.

[0121] In addition, in one embodiment, a data synchronization device for a distributed storage system is provided, wherein the data synchronization device for the distributed storage system includes a processor, a memory, and a data synchronization program for the distributed storage system stored in the memory. When the data synchronization program for the distributed storage system is executed by the processor, the steps of the data synchronization method for the distributed storage system as described above are implemented.

[0122] Based on the distributed storage system of the aforementioned embodiment, an embodiment of the present application further provides a storage capacity adjustment method, the storage capacity adjustment method comprising:

[0123] Based on the acquired capacity adjustment demand, a migration plan table for the target logical slot in the proxy server is generated, so that after acquiring the migration plan table, the proxy server sets the hit instance in the migration plan table to a migration state; wherein the hit instance includes the original instance mapped before the migration of the target logical slot and the target instance mapped after the migration of the target logical slot, and when the hit instance is in the migration state, the proxy server transfers the read and write access path of the data in the hit instance to the backup storage server;

[0124] When the hit instance is in a migration state, obtaining an identifier of target data corresponding to the target logical slot in the original instance;

[0125] Based on the identifier of the target data, the target data is migrated from the original instance to the target instance, and the mapping relationship between the target logical slot and the original instance is migrated to the target instance, so that a mapping relationship exists between the target logical slot and the target instance; wherein the target instance is a newly added instance when the distributed storage system is expanded or a remaining instance when the distributed storage system is reduced in size corresponding to the capacity adjustment requirement.

[0126] It should be noted that, in this embodiment, storage capacity adjustment refers to expanding or reducing the distributed storage system in the above embodiment, that is, adding or reducing instances in the server cluster, which can be reflected in hardware by adding or reducing the main storage server.

[0127] Specifically, the method of this embodiment can be completed by a program process, which can be installed on a host different from the proxy server and can establish a communication connection with the server cluster. The following describes the execution process of the method of this embodiment with the program process as the execution subject.

[0128] First, the capacity adjustment requirements are obtained.

[0129] In the specific implementation process, storage capacity adjustment refers to expanding or shrinking the distributed storage system in the above embodiment, and the capacity adjustment requirements can be obtained from the operation and maintenance system. The function of the operation and maintenance system is: when the business data increases / decreases, the Redis instance expansion / shrinkage instruction is triggered through the tool / platform.

[0130] Next, a migration plan table for a target logical slot in the proxy server is generated based on the acquired capacity adjustment demand, so that the proxy server sets a hit instance in the migration plan table to a migration state after acquiring the migration plan table;

[0131] Among them, the hit instance includes the original instance mapped before the target logical slot migration and the target instance mapped after the target logical slot migration, and when the hit instance is in the migration state, the proxy server transfers the read and write access path of the data in the hit instance to the backup storage server.

[0132] In the specific implementation process, the migration plan table refers to the migration plan table for the logical slot, and the target logical slot refers to the logical slot corresponding to the target data migration involved in the capacity adjustment requirement. It should be noted that in this embodiment, the proxy server is configured with multiple logical slots, and there is a mapping relationship between the multiple logical slots and the multiple instances. Therefore, to increase or decrease instances, it is necessary to re-shard and migrate the logical slots to re-establish the mapping relationship and realize data reading and writing.

[0133] In addition, the migration plan table includes hit instances, wherein the hit instances include the original instances mapped before the migration of the target logical slot and the target instances mapped after the migration of the target logical slot. In order to achieve read and write access during data migration, after obtaining the migration plan table, the proxy server can set the hit instance in the migration plan table to a migration state. When the hit instance is in the migration state, the proxy server transfers the read and write access path of the data in the hit instance to the backup storage server. Compared with the prior art, since the proxy server implements data distribution through logical slots and does not shard the underlying database, when the underlying database of the distributed storage system is expanded / reduced, the read and write access can be temporarily transferred to the backup storage server without affecting the read and write access of the data, thereby solving the problem that the prior art implements data distribution through physical slots, cannot implement the backup solution, and thus cannot implement data writing during expansion / reduction; then after completing the expansion / reduction operation, the data temporarily read and written by the backup storage server can be synchronized to the cluster to ensure the data consistency of the distributed storage system.

[0134] Therefore, before data migration, a migration plan table for the target logical slot needs to be generated.

[0135] As an optional embodiment, the step of generating a migration plan table for a target logical slot in the proxy server based on the capacity adjustment requirement includes:

[0136] Based on the capacity adjustment requirement, a balancing algorithm is used to generate a migration plan table for the target logical slot in the proxy server.

[0137] In the specific implementation process, the use of a balancing algorithm can make the allocation of the migrated logical slots more balanced, thereby making the read and write performance of the distributed storage system more stable after expansion / contraction.

[0138] As an optional embodiment, when the capacity adjustment requirement is a capacity expansion requirement, the target instance is an instance in a newly added primary storage server; the step of generating a migration plan table for a target logical slot in the proxy server using a balancing algorithm based on the capacity adjustment requirement includes:

[0139] Based on the expansion requirement, obtaining an average number of logical slots allocated to the expanded instance;

[0140] Based on the number of logical slots of each instance before the expansion, the instances before the expansion are sorted in descending order;

[0141] Traverse the instances before expansion that are arranged in descending order, allocate the logical slots in each instance before expansion that exceed the average to the target instance until the number of logical slots in the instance before expansion equals the average, and generate a migration plan table for the target logical slots in the proxy server.

[0142] In the specific implementation process, when the capacity adjustment requirement is an expansion requirement, and the target instance is an instance in a newly added primary storage server, it is necessary to allocate some existing logical slots to the newly added instance, so it is necessary to re-allocate the logical slots. Specifically, the sorted instances are allocated in turn according to the average number of logical slots to ensure the balance of the allocated logical slots.

[0143] As another optional embodiment, when the capacity adjustment requirement is a capacity reduction requirement, the target instance is an instance in the original primary storage server; the step of generating a migration plan table for the target logical slot in the proxy server using a balancing algorithm based on the capacity adjustment requirement includes:

[0144] Based on the scaling-down requirement, obtaining an average number of logical slots allocated to the scaled-down instance;

[0145] Based on the number of logical slots of each instance before scaling down, the instances retained after scaling down are sorted in ascending order;

[0146] Traverse the instances that are retained after shrinking in ascending order, allocate logical slots in the reduced instances to the target instances, until the number of logical slots in the instances that are retained after shrinking is equal to the average number, and generate a migration plan table for the target logical slots in the proxy server.

[0147] In the specific implementation process, when the capacity adjustment requirement is a capacity reduction requirement, and the target instance is an instance in the original primary storage server, the logical slots in the reduced instance need to be mapped to the target instance, so the logical slots need to be re-allocated. Specifically, the sorted instances are allocated in turn according to the average number of logical slots to ensure the balance of the allocated logical slots.

[0148] Next, when the hit instance is in a migration state, an identifier of target data corresponding to the target logical slot in the original instance is obtained.

[0149] In the specific implementation process, before migrating the target data, in order to subsequently generate a migration command and migrate the target data, the instance needs to be scanned first to obtain the identifier of the target data. In this process, the hit instance is in a migration state and is readable and writable.

[0150] Next, based on the identification of the target data, the target data is migrated from the original instance to the target instance, and the mapping relationship between the target logical slot and the original instance is migrated to the target instance, so that a mapping relationship exists between the target logical slot and the target instance; wherein the target instance is a newly added instance when the distributed storage system is expanded or a remaining instance when it is reduced in size corresponding to the capacity adjustment requirement.

[0151] In the specific implementation process, it is necessary to first generate a migration command based on the identifier of the target data. As an optional embodiment, the step of migrating the target data from the original instance to the target instance based on the identifier of the target data, and migrating the mapping relationship between the target logical slot and the original instance to the target instance includes:

[0152] generating a native migration command based on the identifier of the target data;

[0153] Based on the native migration command, the target data is migrated from the original instance to the target instance, and the mapping relationship between the target logical slot and the original instance is migrated to the target instance.

[0154] The native migration command is the native Migrate migration command. In the specific implementation process, the native Migrate migration command can realize batch migration, improve data migration efficiency, and further improve the efficiency of expansion / contraction.

[0155] In a specific implementation process, the target data is first migrated. As an optional embodiment, the migration command includes a migration plan of the target data corresponding to multiple target logical slots; the step of migrating the target data from the original instance to the target instance based on the migration command includes:

[0156] Based on the migration command, a task queue is created, wherein the task queue includes a migration plan of the target data corresponding to the multiple target logical slots;

[0157] Based on the task queue, create a plurality of threads having the same number as the target logical slots;

[0158] The multiple threads respectively obtain the migration plan in the task queue to migrate the target data corresponding to the multiple target logical slots from the original instance to the target instance.

[0159] It can be understood that, in the specific implementation process, when the migration command includes migration plans for target data corresponding to multiple target logical slots, a shared memory task queue can be created, and the migration plan for the target data corresponding to each target logical slot can be put into the queue as a task, so as to make full use of the number of CPU cores and create multiple threads. Each thread obtains the tasks in the queue and migrates the target data corresponding to the multiple target logical slots from the original instance to the target instance, thereby realizing concurrent migration and improving the migration speed.

[0160] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.

[0161] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.

[0162] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned implementation methods can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product is stored in a storage medium (such as a read-only memory / random access memory, a disk, or an optical disk), including a number of instructions for enabling a multimedia terminal device (which can be a mobile phone, a computer, a television receiver, or a network device, etc.) to execute the methods described in each embodiment of the present invention.

[0163] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.

Claims

1. A data synchronization method for a distributed storage system, characterized in that: The distributed storage system includes a server cluster and a proxy server, the server cluster includes a primary storage server and a backup storage server, and the primary storage server includes multiple instances; The data synchronization method of the distributed storage system comprises the following steps: Monitoring the status of the instance in the primary storage server; If it is monitored that the target instance in the primary storage server is offline, offline status information of the target instance is generated, so that the proxy server switches the read-write access path of the target instance to the backup storage server after reading the offline status information; wherein, during the period when the read-write access path of the target instance is switched to the backup storage server, the proxy server writes the target data into the backup storage server and the publish-subscribe message system respectively; After monitoring that the target instance recovers from the offline state to the online state, the target data in the publish-subscribe message system is consumed, and the target data in the publish-subscribe message system is written to the target instance in the online state, so as to synchronize the data in the primary storage server and the backup storage server.

2. The data synchronization method of a distributed storage system according to claim 1, characterized in that: After the step of monitoring the instance status in the primary storage server, the method further includes: If it is monitored that the target instance in the primary storage server is in an online state, online state information of the target instance is generated, so that the proxy server sends the target data in the target instance to the publish-subscribe message system after reading the online state information; There is a subscription relationship between the standby storage server and the publish-subscribe messaging system, so that the standby storage server consumes target data in the publish-subscribe messaging system and synchronizes data between the primary storage server and the standby storage server.

3. The data synchronization method of a distributed storage system according to claim 1, characterized in that: The step of monitoring the status of the instance in the primary storage server includes: Periodically detecting the network connection status of the instance in the primary storage server at a preset time interval; If the instance fails to connect to the network for at least three consecutive times, the instance is determined to be offline.

4. The data synchronization method of a distributed storage system according to claim 3, characterized in that: After the step of determining that the instance is offline if the instance fails to connect to the network for at least three consecutive times, the method further includes: When the instance is in an offline state, if it is detected that the instance has successfully connected to the network at least once, it is determined that the target instance is restored from the offline state to the online state.

5. The data synchronization method of a distributed storage system according to claim 1, characterized in that: The distributed storage system also includes a coordination server; The step of generating offline status information of the target instance if it is monitored that the target instance in the primary storage server is offline, so that the proxy server switches the read-write access path of the target instance to the backup storage server after reading the offline status information, comprises: If it is monitored that the target instance in the main storage server is in an offline state, the offline state information of the target instance is generated and stored in the coordination server, so that after the proxy server reads the offline state information from the coordination server, the read and write access path to the target instance is switched to the backup storage server.

6. The data synchronization method of a distributed storage system according to any one of claims 1 to 5, characterized in that: The proxy server is configured with a plurality of logical slots, and a mapping relationship exists between the plurality of logical slots and the plurality of instances.

7. The data synchronization method of a distributed storage system according to claim 6, characterized in that: The primary storage server is a Redis storage server, and the instance is a Redis instance; the backup storage server is a LMDB storage server.

8. A data synchronization device for a distributed storage system, characterized in that: The distributed storage system includes a server cluster and a proxy server, the server cluster includes a primary storage server and a backup storage server, and the primary storage server includes multiple instances; The data synchronization device of the distributed storage system comprises: A status monitoring module, used to monitor the status of instances in the primary storage server; an offline processing module, for generating offline status information of the target instance if it is detected that the target instance in the primary storage server is offline, so that the proxy server switches the read-write access path of the target instance to the backup storage server after reading the offline status information; wherein, during the period when the read-write access path of the target instance is switched to the backup storage server, the proxy server writes the target data into the backup storage server and the publish-subscribe message system respectively; A data synchronization module is used to consume the target data in the publish-subscribe message system after monitoring that the target instance has recovered from an offline state to an online state, and write the target data in the publish-subscribe message system to the target instance in the online state, so as to synchronize the data in the primary storage server with the backup storage server.

9. A data synchronization device for a distributed storage system, characterized in that: The data synchronization device of the distributed storage system includes a processor, a memory, and a data synchronization program of the distributed storage system stored in the memory. When the data synchronization program of the distributed storage system is executed by the processor, the steps of the data synchronization method of the distributed storage system as described in any one of claims 1 to 7 are implemented.

10. A computer storage medium, characterized in that: The computer storage medium stores a data synchronization program for a distributed storage system, and when the data synchronization program for a distributed storage system is executed by a processor, the steps of the data synchronization method for a distributed storage system as claimed in any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Distributed data synchronization system and method for embedded equipment

    CN103747091A

  • distributed architecture data sharing method based on Redis

    CN109800239A