A data storage method and device, and a storage medium
By transferring data requests to the next storage partition and storing them when a Redis storage partition fails, the problem of reduced data write speed caused by master node failure is solved, and a faster data storage process is achieved.
Patent Information
- Application Number
- CN202211368997.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-03
- Publication Date
- 2025-10-21
- Estimated Expiration
- 2042-11-03
AI Technical Summary
When a Redis node fails, existing technologies require waiting for the slave nodes to re-elect a master node, which reduces the data write speed.
Once the primary node of a storage partition is confirmed to be faulty, the data storage request is directly transferred to the next storage partition, and the target primary node is used to store the data, thus avoiding waiting for the primary node to be repaired.
It improves data storage speed and reduces data write latency caused by master node failure.
Smart Images

Figure CN115657958B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of distributed cache technology, and in particular to a data storage method and device, and a storage medium. Background Art
[0002] In internet finance, Redis is widely used due to its low latency and high throughput. Redis nodes are divided into master and slave nodes. Each master node can be configured with multiple slave nodes. Slave nodes synchronize data with the master node in real time. If the master node fails, a new master node can be elected from the slave nodes to achieve high node availability.
[0003] In related technologies, multiple slave nodes detect a master node's fault status by sending heartbeat messages to it and receiving responses from it within a specified timeframe. If the master node sends responses to the slave nodes within the specified timeframe, the master node is considered to be operating normally. If no responses are received from the master node within the specified timeframe, the master node is considered to be faulty, requiring a new master node to be re-elected from the slave nodes to perform data storage.
[0004] Since it takes time to re-elect a new master node from multiple slave nodes and it also takes time for the slave node to timeout and wait for the master node's response, the master node cannot write data normally during this period of time, thus reducing the speed of data writing. Summary of the Invention
[0005] In order to solve the above technical problems, the embodiments of the present application hope to provide a data storage method and device, and a storage medium that can improve the speed of data storage.
[0006] The technical solution of this application is achieved as follows:
[0007] An embodiment of the present application provides a data storage method, the data storage method comprising:
[0008] When it is determined that a first master node in a first storage partition fails and a first data storage request belonging to the first storage partition is received, determining a next storage partition of the first storage partition; and using the next storage partition as a target storage partition;
[0009] Obtaining first data to be stored from the first data storage request, and storing the first data to be stored using the target master node in the target storage partition;
[0010] Transmitting data storage completion response information to the client that transmitted the first data storage request.
[0011] An embodiment of the present application provides a data storage device, the device comprising:
[0012] a determining unit, configured to, upon determining that a first master node in a first storage partition has failed and receiving a first data storage request belonging to the first storage partition, determine a next storage partition of the first storage partition; and use the next storage partition as a target storage partition;
[0013] An acquiring unit, configured to acquire first data to be stored from the first data storage request;
[0014] a storage unit, configured to store the first data to be stored using a target master node in the target storage partition;
[0015] A transmission unit is used to transmit data storage completion response information to the client that transmits the first data storage request.
[0016] An embodiment of the present application provides a data storage device, the device comprising:
[0017] A memory, a processor and a communication bus, wherein the memory communicates with the processor via the communication bus, and the memory stores a data storage program executable by the processor. When the data storage program is executed, the data storage method described above is executed by the processor.
[0018] An embodiment of the present application provides a storage medium having a computer program stored thereon, which is applied to a data storage device. When the computer program is executed by a processor, the above-mentioned data storage method is implemented.
[0019] The embodiment of the present application provides a data storage method and device, and a storage medium. The data storage method includes: determining the next storage partition of the first storage partition when it is determined that the first master node in the first storage partition has failed and receiving the first data storage request belonging to the first storage partition; and using the next storage partition as the target storage partition; obtaining the first data to be stored from the first data storage request, and using the target master node in the target storage partition to store the first data to be stored; and transmitting a response message of data storage completion to the client that transmitted the first data storage request. By adopting the above method implementation scheme, the data storage device, when it is determined that the first master node in the first storage partition has failed and receiving the first data storage request belonging to the first storage partition, determines the next storage partition of the first storage partition; and uses the next storage partition as the target storage partition, thereby storing the first data to be stored in the first data storage request in the target storage partition, without having to wait for the master node failure in the first storage partition to be repaired before storing the first data to be stored, thereby improving the speed of data storage. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] Figure 1 A schematic diagram of nodes in Redis in the prior art provided in an embodiment of the present application;
[0021] Figure 2 A flow chart of a data storage method provided in an embodiment of the present application;
[0022] Figure 3 An exemplary data storage structure provided in the embodiment of the present application Figure 1 ;
[0023] Figure 4 An exemplary data storage structure provided in the embodiment of the present application Figure 2 ;
[0024] Figure 5 An exemplary data storage method process provided in the embodiment of the present application Figure 1 ;
[0025] Figure 6 An exemplary data storage method process provided in the embodiment of the present application Figure 2 ;
[0026] Figure 7 A schematic diagram of the structure of a data storage device provided in an embodiment of the present application Figure 1 ;
[0027] Figure 8 A schematic diagram of the structure of a data storage device provided in an embodiment of the present application Figure 2 . DETAILED DESCRIPTION
[0028] The following will be combined with the accompanying drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. It should be understood that the specific embodiments described here are only used to explain the present application and are not used to limit the present application.
[0029] Redis Cluster is a cluster solution officially launched by Redis. It adopts a node-free implementation method and calculates the storage node corresponding to the data based on the same hash algorithm. Figure 1 As shown in the figure: the nodes are divided into master nodes (M1, M2, M3) and slave nodes (S1, S2, S3). Each master node can be configured with multiple slave nodes. The slave nodes synchronize the master node data in real time. When the master node goes down, the slave nodes are elected to become the master node to achieve high availability of the node.
[0030] The present invention provides a data storage method, which is applied to a data storage device. Figure 2A flow chart of a data storage method provided in an embodiment of the present application is as follows: Figure 2 As shown, the data storage method may include:
[0031] S101. When it is determined that a first master node in a first storage partition fails and a first data storage request belonging to the first storage partition is received, determine a next storage partition of the first storage partition; and use the next storage partition as a target storage partition.
[0032] A data storage method provided in an embodiment of the present application is applicable to a scenario in which first data to be stored in a first data storage request is stored.
[0033] In the embodiments of the present application, the data storage device can be implemented in various forms. For example, the data storage device described in the present application can include devices such as mobile phones, cameras, tablet computers, laptop computers, PDAs, portable media players (PMPs), navigation devices, wearable devices, smart bracelets, pedometers, and devices such as digital TVs, desktop computers, and servers.
[0034] In an embodiment of the present application, the data storage device is specifically a Redis type storage device.
[0035] It should be noted that the storage format of data in Redis is key-value pair (KV) format. When the data storage device stores the data to be stored in the data storage request, it needs to establish a storage key (Key, K) according to the user information carried in the data storage request, and establish a storage value (Value, V) according to the data to be stored in the data storage request, so as to construct a key-value pair corresponding to the data storage request and execute the data storage process in accordance with the KV format.
[0036] In the embodiment of the present application, the first data storage request belonging to the first storage partition may be a request for storing the first to-be-stored data in the first data storage request in the first storage partition.
[0037] In an embodiment of the present application, the data storage device determines that the first master node in the first storage partition has failed by transmitting a heartbeat message to multiple master nodes in multiple storage partitions; when the data storage device receives heartbeat response information transmitted by multiple master nodes based on the heartbeat message, the data storage device determines that the multiple master nodes are all in a non-faulty state; if the data storage device does not receive the heartbeat response information transmitted by the first master node based on the heartbeat message, the data storage device determines that the first master node is in a faulty state.
[0038] In an embodiment of the present application, the data storage device includes a fault detection device (Proxy), and the data storage device can use the Proxy to transmit heartbeat messages to multiple master nodes in multiple storage partitions to determine whether the multiple master nodes are in a non-faulty state.
[0039] It should be noted that the data storage device may transmit heartbeat messages to multiple master nodes in the manner that the data storage device transmits heartbeat messages to each of the multiple master nodes, that is, one heartbeat message corresponds to one master node.
[0040] In an embodiment of the present application, the data storage device may transmit a heartbeat message to the multiple master nodes once every fault detection period. The fault detection period may be 1 second; the fault detection period may be 10 seconds; and the specific length of the fault detection period may be determined based on actual conditions and is not limited in the present embodiment.
[0041] It should be noted that the fault detection time period can be a time period configured in the data storage device; the fault detection time period can also be a time period transmitted from other devices to the data storage device; the specific way in which the data storage device obtains the fault detection time period can be determined according to actual conditions, and the embodiments of the present application do not limit this.
[0042] In an embodiment of the present application, after the client's data storage request is sent to the proxy, the proxy will be routed to different partitions according to the hash value of the key.
[0043] In an embodiment of the present application, the data storage device determines the next storage partition of the first storage partition by determining an available partition that is closest to the first storage partition, that is, the next storage partition, and then the data storage device uses the next storage partition as the target storage partition; the data storage device may also determine a target storage partition other than the first storage partition from multiple storage partitions in other ways; the specific way in which the data storage device determines the target storage partition based on the first storage partition can be determined according to actual conditions, and the embodiment of the present application does not limit this.
[0044] It can be understood that the data storage device uses the next storage partition of the first storage partition as the target storage partition, and the first storage partition and the next storage partition are two adjacent storage partitions, which facilitates data transfer storage and migration of transferred storage data, thereby improving the speed of data transfer.
[0045] In an embodiment of the present application, when the data storage device determines that the first master node in the first storage partition is faulty and receives a first data storage request belonging to the first storage partition, it determines the next storage partition of the first storage partition; and before taking the next storage partition as the target storage partition, the data storage device transmits an operation status detection instruction to multiple master nodes in multiple storage partitions when the fault detection time is reached; when the data storage device does not receive the operation status response information transmitted by the first master node according to the operation status detection instruction, it determines that the first master node is a faulty node.
[0046] It should be noted that the multiple master nodes include a first master node and a target master node.
[0047] In the embodiment of the present application, the time period between two adjacent fault detection time points is the fault detection time period.
[0048] In an embodiment of the present application, the running status detection instruction can be a heartbeat message, and the running status detection instruction can also be other forms of instructions for detecting whether multiple master nodes are faulty; the specific running status detection instruction can be determined according to actual conditions, and the embodiment of the present application does not limit this.
[0049] In the embodiment of the present application, the running status response information can be response information in text form; the running status response information can also be response information in other forms; the specific running status response information can be determined according to actual conditions, and the embodiment of the present application does not limit this.
[0050] In an embodiment of the present application, a proxy may be used to transmit operation status detection instructions to multiple master nodes in multiple storage partitions respectively to determine whether there are faults in the multiple master nodes.
[0051] It can be understood that the data storage device transmits operation status detection instructions to multiple master nodes in multiple storage partitions, and detects the fault status of multiple master nodes based on the operation status response information transmitted by the multiple master nodes according to the operation status detection instructions. In the event of a failure of any master node, the failure of the master node can be perceived in a timely manner, and the data to be stored in the faulty storage partition (the data storage partition to which the faulty master node belongs) can be transferred to other data storage partitions in a timely manner, thereby improving the storage speed of the data to be stored.
[0052] S102: Obtain first data to be stored from the first data storage request, and use the target master node in the target storage partition to store the first data to be stored.
[0053] In an embodiment of the present application, the data storage device determines the next storage partition of the first storage partition; and after using the next storage partition as the target storage partition, the data storage device obtains the first data to be stored from the first data storage request, and uses the target master node in the target storage partition to store the first data to be stored.
[0054] It should be noted that the first data storage request carries the first data to be stored.
[0055] In an embodiment of the present application, the process of the data storage device using the target master node in the target storage partition to store the first data to be stored includes: the data storage device establishes a first storage key according to the first data storage request; the data storage device obtains the first identifier of the first storage partition and the target identifier of the target storage partition; the data storage device adjusts the first storage key according to the first identifier and the target identifier to obtain the adjusted first storage key; the data storage device uses the target master node in the target storage partition to store the first data to be stored according to the adjusted first storage key.
[0056] In an embodiment of the present application, the process of the data storage device establishing the first storage key according to the first data storage request may be that the data storage device obtains user information from the first data storage request and establishes the first storage key according to the user information.
[0057] It should be noted that the first identifier is an identifier that uniquely identifies the first storage partition; the target identifier is an identifier that uniquely identifies the target storage partition.
[0058] In an embodiment of the present application, the data storage device adjusts the first storage key according to the first identifier and the target identifier to obtain the adjusted first storage key. The process can be: splicing the first identifier and the target identifier to obtain the spliced identifier; splicing the spliced identifier and the first storage key to obtain the adjusted first storage key. Specifically, the data storage device can add the first identifier and the target identifier in sequence in front of the first storage key to obtain the adjusted first storage key; or the data storage device can add the first identifier and the target identifier in sequence after the first storage key to obtain the adjusted first storage key; the data storage device can also adjust the first storage key according to the first identifier and the target identifier in other ways to obtain the adjusted first storage key. The specific way in which the data storage device adjusts the first storage key according to the first identifier and the target identifier to obtain the adjusted first storage key can be determined according to actual conditions, and the embodiment of the present application does not limit this.
[0059] Exemplarily, the data storage device may add “__from first identifier__to target identifier__” before the first storage key (key) to obtain __from first identifier__to target identifier__{key}, which is the adjusted first storage key.
[0060] In an embodiment of the present application, the data storage device uses the target master node to store the first data to be stored according to the adjusted first storage key in the target storage partition. A KV pair corresponding to the first data storage request can be established for the data storage device based on the adjusted first storage key and the first data to be stored, and the KV pair can be stored in the target node.
[0061] In an embodiment of the present application, after the data storage device uses the target master node in the target storage partition to store the first data to be stored, the data storage device establishes a second storage key according to the second data storage request when it determines that the second master node in the first storage partition is in a non-faulty state and receives a second data storage request belonging to the first storage partition; the data storage device determines the adjusted second storage key based on the second storage key, the first identifier and the target identifier; the data storage device obtains the first data to be stored in the target storage partition when the second storage key and the first storage key are the same; the data storage device obtains the second data to be stored from the second data storage request, and uses the first storage partition to store the first data to be stored and the second data to be stored.
[0062] It should be noted that the first master node and the second master node are the same node, or the first master node and the second master node are two different nodes.
[0063] In an embodiment of the present application, the process of the data storage device establishing the second storage key according to the second data storage request can be that the data storage device obtains user information from the second data storage request, and the data storage device establishes the first storage key according to the user information.
[0064] In an embodiment of the present application, the process of the data storage device determining the adjusted second storage key based on the second storage key, the first identifier and the target identifier can be as follows: splicing the first identifier and the target identifier to obtain a spliced identifier; splicing the spliced identifier with the second storage key to obtain the adjusted second storage key. Specifically, the data storage device can add the first identifier and the target identifier in sequence before the second storage key to obtain the adjusted second storage key; the data storage device can also add the first identifier and the target identifier in sequence after the second storage key to obtain the adjusted second storage key; the data storage device can also determine the adjusted second storage key based on the second storage key, the first identifier and the target identifier in other ways; the specific way in which the data storage device determines the adjusted second storage key based on the second storage key, the first identifier and the target identifier can be determined according to actual conditions, and the embodiment of the present application does not limit this.
[0065] It should be noted that the second data storage request carries the second data to be stored.
[0066] In an embodiment of the present application, the process of the data storage device using the first storage partition to store the first data to be stored and the second data to be stored includes: the data storage device uses the second master node in the first storage partition to store the first data to be stored and the second data to be stored according to the first storage key.
[0067] In an embodiment of the present application, after the data storage device uses the second master node to store the first data to be stored and the second data to be stored according to the first storage key, if the first data to be stored and the second data to be stored are successfully stored using the second master node according to the first storage key, the data storage device synchronizes the first data to be stored and the second data to be stored to the slave node of the first storage partition according to the first storage key.
[0068] It should be noted that the number of slave nodes in the first storage partition can be determined according to the actual storage partition, and the embodiment of the present application does not limit this.
[0069] In an embodiment of the present application, after the data storage device uses the first storage partition to store the first data to be stored and the second data to be stored, the data storage device obtains the transferred storage data from the target storage partition when the preset time arrives; the data storage device converts the adjusted transfer storage key corresponding to the transferred storage data into the original storage key according to the first identifier and the target identifier; the data storage device stores the transferred storage data in the first storage partition according to the original storage key using the first master node.
[0070] It should be noted that the transferred storage data refers to the data to be stored that is transferred to the target storage partition and is not transferred back to the first storage partition when the first storage partition fails.
[0071] In an embodiment of the present application, the number of transferred and stored data may be one; the number of transferred and stored data may also be multiple; the specific number of transferred and stored data may be determined based on actual conditions, and the embodiment of the present application does not limit this.
[0072] In an embodiment of the present application, the preset time may be the time configured in the data storage device; the preset time may also be the time for transmission from other devices to the data storage device. The specific preset time may be determined based on actual conditions, and the embodiment of the present application does not limit this.
[0073] It should be noted that the preset time can be 8 days a day, or 8 o'clock on the first day of each month; the preset time can also be the time point when the trigger instruction is received; the specific preset time can be determined according to actual conditions, and the embodiments of this application do not limit this.
[0074] It should also be noted that if the preset time can also be the time point when the trigger instruction is received, then the trigger instruction can be an instruction triggered by the operation and maintenance personnel to transfer the data to the original storage partition.
[0075] In an embodiment of the present application, the data storage device converts the adjusted transfer storage key corresponding to the transferred storage data into the original storage key according to the first identifier and the target identifier, and can delete the first identifier and the target identifier in the adjusted transfer storage key for the data storage device.
[0076] In an embodiment of the present application, after the data storage device stores the transferred storage data in the first storage partition using the first master node according to the original storage key, the data storage device deletes the transferred storage data in the target storage partition.
[0077] In an embodiment of the present application, the data storage device uses the first master node in the first storage partition to store and transfer the storage data according to the original storage key. The data storage device will also search for the storage data corresponding to the original key in the first storage partition. If the data is found, the storage data corresponding to the original key will be deleted.
[0078] It can be understood that the data storage device transfers the transferred storage data in the target storage partition back to the first storage partition when the preset time is reached. When receiving a data access instruction, the data storage device can directly find the corresponding data to be stored quickly according to the storage key determined by the data access instruction. There is no need to obtain the adjusted transfer storage key according to the storage key, target identifier and first identifier, and then find the corresponding data to be stored in the target storage partition according to the adjusted transfer storage key, thereby improving the data acquisition rate.
[0079] In an embodiment of the present application, after the data storage device obtains the first data to be stored in the target storage partition, the data storage device also deletes the first data to be stored in the target storage partition.
[0080] In an embodiment of the present application, the data storage device may also delete the first data to be stored in the target storage partition. The data storage device may delete the adjusted first storage key and the first data to be stored in the target storage partition.
[0081] It can be understood that after the data storage device obtains the first data to be stored in the target storage partition and transfers the first data to be stored back to the first storage partition, it deletes the first data to be stored in the target storage partition, that is, only stores the first data to be stored in the first storage partition, and no longer uses the target storage partition to store the first data to be stored, thereby saving storage space for the target storage partition.
[0082] S103: Transmitting data storage completion response information to the client that transmitted the first data storage request.
[0083] In an embodiment of the present application, after the data storage device uses the target master node in the target storage partition to store the first data to be stored, the data storage device transmits a response message indicating that the data storage is completed to the client that transmitted the first data storage request.
[0084] In an embodiment of the present application, the response information may be information in character form; the response information may also be information in picture form; the response information may also be information in other forms; the specific form of the response information may be determined based on actual conditions, and the embodiment of the present application does not limit this.
[0085] For example, Figure 3 As shown: the storage partitions include (Partition-1, Partition-2, Partition-3). During the failure phase, when the Proxy (Cluster) proactively detects that a partition (failure of the first storage partition) is unavailable, the Proxy will proactively cut off the data storage request accessing the partition and redirect the data storage request to another partition (the target storage partition). It also adds a specific prefix to the key by prefix tagging (adjusting the first storage key according to the first identifier and the target identifier to obtain the adjusted first storage key) to distinguish the data temporarily stored in the target master node due to the failure of the first master node in the first storage partition. The key value of the redirected request (the adjusted first storage key, Migrate Key) is rewritten into the following format: __FromPartition__ToPartition__{key}. The prefix retains two parts of information: which partition (first storage partition) the key is redirected from and to which partition (target storage partition). This information allows the key to be migrated back to the partition (first storage partition) to which it originally belonged after the partition (first storage partition) is restored. Prefix tagging can be logically considered to be equivalent to opening up a portion of memory space within the partition to store keys from other nodes.
[0086] For example, Figure 4As shown in the figure: After the Proxy (Cluster) detects that a partition (the first storage partition) has recovered, it marks the partition as being in the recovery phase. When accepting a key from a client (Client) routed to this partition (the first storage partition), it first locates the Redirect Partition (the target storage partition) to which the key was routed during the failure and checks whether the MigrateKey (the adjusted first storage key) exists. If it does, it indicates that a write request was made to the key during the failure. The data in the original Failure Partition (the first storage partition) is considered dirty and deleted. This data storage request still needs to be routed to the Redirect Partition (the target storage partition), but a background migration task (Migrate Task) is initiated to migrate the key from the Redirect Partition (the target storage partition) back to the Failure Partition (the first storage partition). This is a gradual migration process, gradually migrating the keys back to the original partition (the first storage partition) over multiple steps to avoid the excessive computational load that would be placed on the server by migrating a large number of keys at once. Progressive migration relies on client access to drive key migration. For keys that have not been accessed for a long time after the partition is restored, the Proxy automatically triggers the Scan task (Scan instruction, which can also be triggered by the administrator (Admin)), scans all redirected keys, and centrally migrates this part of the data (when the preset time arrives, the transferred storage data is obtained from the target storage partition; according to the first identifier and the target identifier, the adjusted transfer storage key corresponding to the transferred storage data is converted into the original storage key; in the first storage partition, the first master node is used to store the transferred storage data according to the original storage key). After the Scan task is completed, all keys that were redirected due to the failure should be migrated back to the partition to which they belong. At this point, the recovery phase ends, and all routes in the cluster return to normal.
[0087] For example, Figure 5 As shown:
[0088] S51. When the fault detection time is reached, the data storage device transmits an operation status detection instruction to multiple master nodes in multiple storage partitions respectively.
[0089] It should be noted that the multiple master nodes include a first master node and a target master node.
[0090] S52: When the data storage device does not receive the operation status response information transmitted by the first master node according to the operation status detection instruction, the data storage device determines that the first master node is a faulty node.
[0091] S53. When the data storage device determines that the first master node in the first storage partition fails and receives the first data storage request belonging to the first storage partition, it determines the next storage partition of the first storage partition; and uses the next storage partition as the target storage partition.
[0092] S54. The data storage device obtains the first data to be stored from the first data storage request, and establishes a first storage key according to the first data storage request.
[0093] S55. The data storage device obtains the first identifier of the first storage partition and the target identifier of the target storage partition.
[0094] S56: The data storage device adjusts the first storage key according to the first identifier and the target identifier to obtain an adjusted first storage key.
[0095] S57. The data storage device stores the first data to be stored in the target storage partition using the target master node according to the adjusted first storage key.
[0096] S58. The data storage device transmits a data storage completion response message to the client that transmitted the first data storage request.
[0097] For example, Figure 6 As shown:
[0098] S61. When the data storage device determines that the second master node in the first storage partition is in a non-faulty state and receives a second data storage request belonging to the first storage partition, the data storage device establishes a second storage key according to the second data storage request.
[0099] S62: The data storage device determines an adjusted second storage key according to the second storage key, the first identifier, and the target identifier.
[0100] S63. When the second storage key is the same as the first storage key, the data storage device obtains the first data to be stored in the target storage partition.
[0101] S64. The data storage device obtains second data to be stored from the second data storage request.
[0102] S65. The data storage device stores the first data to be stored and the second data to be stored in the first storage partition using the second master node according to the first storage key.
[0103] S66. When the preset time arrives, the data storage device obtains the transferred storage data from the target storage partition.
[0104] It should be noted that the transferred storage data refers to the data to be stored that is transferred to the target storage partition and is not transferred back to the first storage partition when the first storage partition fails.
[0105] S67: The data storage device converts the adjusted transfer storage key corresponding to the transferred storage data into the original storage key according to the first identifier and the target identifier.
[0106] S68. The data storage device stores the transferred storage data in the first storage partition using the first master node according to the original storage key.
[0107] It can be understood that when the data storage device determines that the first master node in the first storage partition has failed and receives the first data storage request belonging to the first storage partition, it determines the next storage partition of the first storage partition; and uses the next storage partition as the target storage partition, thereby storing the first data to be stored in the first data storage request into the target storage partition. There is no need to wait for the master node failure in the first storage partition to be repaired before storing the first data to be stored, thereby improving the speed of data storage.
[0108] Based on the same inventive concept as the above-mentioned data storage method, an embodiment of the present application provides a data storage device 1 corresponding to a data storage method; Figure 7 A schematic diagram of the structure of a data storage device provided in an embodiment of the present application Figure 1 , the data storage device 1 may include:
[0109] The determining unit 11 is configured to, upon determining that a first master node in a first storage partition has failed and receiving a first data storage request belonging to the first storage partition, determine a next storage partition of the first storage partition; and use the next storage partition as a target storage partition;
[0110] An acquiring unit 12 is configured to acquire first data to be stored from the first data storage request;
[0111] The storage unit 13 is configured to store the first data to be stored using the target master node in the target storage partition;
[0112] The transmission unit 14 is configured to transmit data storage completion response information to the client that transmitted the first data storage request.
[0113] In some embodiments of the present application, the apparatus further comprises an establishing unit and an adjusting unit;
[0114] The establishing unit is configured to establish a first storage key according to the first data storage request;
[0115] The acquiring unit 12 is configured to acquire a first identifier of the first storage partition and a target identifier of the target storage partition;
[0116] The adjusting unit is configured to adjust the first storage key according to the first identifier and the target identifier to obtain an adjusted first storage key;
[0117] The storage unit 13 is configured to store the first data to be stored in the target storage partition using the target master node according to the adjusted first storage key.
[0118] In some embodiments of the present application, the device further comprises a splicing unit;
[0119] The splicing unit is configured to splice the first identifier and the target identifier to obtain a spliced identifier; and splice the spliced identifier and the first storage key to obtain the adjusted first storage key.
[0120] In some embodiments of the present application, the transmission unit 14 is configured to transmit the operation status detection instruction to multiple master nodes in multiple storage partitions respectively when the fault detection time is reached; the multiple master nodes include the first master node and the target master node;
[0121] The determining unit 11 is configured to determine that the first master node is a faulty node when the running status response information transmitted by the first master node according to the running status detection instruction is not received.
[0122] In some embodiments of the present application, the establishing unit is configured to, upon determining that the second master node in the first storage partition is in a non-failed state and receiving a second data storage request belonging to the first storage partition, establish a second storage key according to the second data storage request;
[0123] The adjusting unit is configured to determine an adjusted second storage key according to the second storage key, the first identifier, and the target identifier;
[0124] The acquiring unit 12 is configured to acquire the first data to be stored in the target storage partition when the second storage key is the same as the first storage key; and acquire the second data to be stored from the second data storage request;
[0125] The storage unit 13 is configured to use the first storage partition to store the first data to be stored and the second data to be stored.
[0126] In some embodiments of the present application, the storage unit 13 is used to store the first data to be stored and the second data to be stored in the first storage partition using the second master node according to the first storage key.
[0127] In some embodiments of the present application, the apparatus further comprises a synchronization unit;
[0128] The synchronization unit is used to synchronize the first data to be stored and the second data to be stored to the slave node of the first storage partition according to the first storage key when the first data to be stored and the second data to be stored are successfully stored using the second master node according to the first storage key.
[0129] In some embodiments of the present application, the device further comprises a conversion unit;
[0130] The acquisition unit 12 is configured to acquire the transferred storage data from the target storage partition when a preset time arrives; the transferred storage data is the data to be stored that is transferred to the target storage partition and is not transferred back to the first storage partition in the event of a failure of the first storage partition;
[0131] The conversion unit is configured to convert the adjusted transfer storage key corresponding to the transfer storage data into an original storage key according to the first identifier and the target identifier;
[0132] The storage unit 13 is configured to store the transferred storage data in the first storage partition using the first master node according to the original storage key.
[0133] In some embodiments of the present application, the apparatus further includes a deletion unit;
[0134] The deleting unit is configured to delete the first data to be stored in the target storage partition.
[0135] It should be noted that, in actual applications, the above-mentioned determination unit 11, acquisition unit 12, storage unit 13 and transmission unit 14 can be implemented by a processor 15 on the data storage device 1, specifically a CPU (Central Processing Unit), MPU (Microprocessor Unit), DSP (Digital Signal Processing) or Field Programmable Gate Array (FPGA); the above-mentioned data storage can be implemented by the memory 16 on the data storage device 1.
[0136] The embodiment of the present application also provides a data storage device 1, such as Figure 8 As shown, the data storage device 1 includes: a processor 15, a memory 16 and a communication bus 17. The memory 16 communicates with the processor 15 through the communication bus 17. The memory 16 stores a program executable by the processor 15. When the program is executed, the data storage method described above is executed by the processor 15.
[0137] In practical applications, the memory 16 may be a volatile memory, such as a random-access memory (RAM); or a non-volatile memory, such as a read-only memory (ROM), a flash memory, a hard disk drive (HDD) or a solid-state drive (SSD); or a combination of the above types of memory, and provide instructions and data to the processor 15.
[0138] An embodiment of the present application provides a computer-readable storage medium having a computer program thereon, which implements the data storage method described above when the program is executed by the processor 15 .
[0139] It can be understood that when the data storage device determines that the first master node in the first storage partition has failed and receives the first data storage request belonging to the first storage partition, it determines the next storage partition of the first storage partition; and uses the next storage partition as the target storage partition, thereby storing the first data to be stored in the first data storage request into the target storage partition. There is no need to wait for the master node failure in the first storage partition to be repaired before storing the first data to be stored, thereby improving the speed of data storage.
[0140] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of hardware embodiments, software embodiments, or embodiments combining software and hardware. Furthermore, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage and optical storage, etc.) containing computer-usable program code.
[0141] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the steps in the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0142] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0143] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 The steps for the function specified in one or more boxes.
[0144] The above description is merely a preferred embodiment of the present application and is not intended to limit the scope of protection of the present application.
Claims
1. A data storage method, characterized in that: The method comprises: When it is determined that a first master node in a first storage partition fails and a first data storage request belonging to the first storage partition is received, determining a next storage partition of the first storage partition; and using the next storage partition as a target storage partition; Obtaining first data to be stored from the first data storage request; establishing a first storage key according to the first data storage request; Obtain a first identifier of the first storage partition and a target identifier of the target storage partition; the first identifier is an identifier that uniquely identifies the first storage partition; the target identifier is an identifier that uniquely identifies the target storage partition; adjusting the first storage key according to the first identifier and the target identifier to obtain an adjusted first storage key; In the target storage partition, using the target master node to store the first data to be stored according to the adjusted first storage key; Transmitting data storage completion response information to the client that transmitted the first data storage request.
2. The method according to claim 1, characterized in that The adjusting the first storage key according to the first identifier and the target identifier to obtain the adjusted first storage key includes: Concatenate the first identifier and the target identifier to obtain a concatenated identifier; The splicing identifier and the first storage key are spliced to obtain the adjusted first storage key.
3. The method according to claim 1, characterized in that determining a next storage partition of the first storage partition when it is determined that the first master node in the first storage partition is faulty and a first data storage request belonging to the first storage partition is received; Before setting the next storage partition as the target storage partition, the method further includes: When the fault detection time is reached, transmitting the operation status detection instruction to multiple master nodes in multiple storage partitions respectively; the multiple master nodes include the first master node and the target master node; In a case where the operation status response information transmitted by the first master node according to the operation status detection instruction is not received, it is determined that the first master node is a faulty node.
4. The method according to claim 1, wherein After storing the first data to be stored using the target master node in the target storage partition, the method further includes: In a case where it is determined that the second master node in the first storage partition is in a non-failure state and a second data storage request belonging to the first storage partition is received, establishing a second storage key according to the second data storage request; determining an adjusted second storage key according to the second storage key, the first identifier, and the target identifier; When the second storage key is the same as the first storage key, obtaining the first data to be stored in the target storage partition; The second data to be stored is obtained from the second data storage request, and the first data to be stored and the second data to be stored are stored in the first storage partition.
5. The method according to claim 4, characterized in that The storing the first to-be-stored data and the second to-be-stored data by using the first storage partition includes: In the first storage partition, the first data to be stored and the second data to be stored are stored using the second master node according to the first storage key.
6. The method according to claim 5, characterized in that After storing the first to-be-stored data and the second to-be-stored data according to the first storage key using the second master node, the method further includes: When the first data to be stored and the second data to be stored are successfully stored using the second master node according to the first storage key, the first data to be stored and the second data to be stored are synchronized to the slave node of the first storage partition according to the first storage key.
7. The method according to claim 4, characterized in that After storing the first data to be stored and the second data to be stored in the first storage partition, the method further includes: When a preset time arrives, the transferred storage data is obtained from the target storage partition; the transferred storage data is the data to be stored that is transferred to the target storage partition and is not transferred back to the first storage partition in the event of a failure of the first storage partition; converting the adjusted transfer storage key corresponding to the transfer storage data into an original storage key according to the first identifier and the target identifier; In the first storage partition, the transferred storage data is stored using the first master node according to the original storage key.
8. A data storage device, characterized in that The device comprises: a determining unit, configured to, upon determining that a first master node in a first storage partition has failed and receiving a first data storage request belonging to the first storage partition, determine a next storage partition of the first storage partition; and use the next storage partition as a target storage partition; an acquiring unit, configured to acquire first data to be stored from the first data storage request; and a storing unit, configured to establish a first storage key according to the first data storage request; Obtain a first identifier of the first storage partition and a target identifier of the target storage partition; the first identifier is an identifier that uniquely identifies the first storage partition; the target identifier is an identifier that uniquely identifies the target storage partition; adjusting the first storage key according to the first identifier and the target identifier to obtain an adjusted first storage key; In the target storage partition, using the target master node to store the first data to be stored according to the adjusted first storage key; A transmission unit is used to transmit data storage completion response information to the client that transmits the first data storage request.
9. A data storage device, characterized in that: The device comprises: A memory, a processor, and a communication bus, wherein the memory communicates with the processor via the communication bus, the memory stores a program of data storage executable by the processor, and when the program of data storage is executed, the method according to any one of claims 1 to 7 is performed by the processor.
10. A storage medium having a computer program stored thereon, used in a data storage device, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Data management method, device and equipment and computer storage medium
CN112311596A
Storage node fault processing method and device, equipment and storage medium
CN114281591A