Data storage method, system and storage medium
By receiving the client's write request on the master node and synchronizing it to multiple slave nodes, the problem of low availability of AMQ is solved, distributed storage and high availability are achieved, ensuring that messages are not lost, and improving the scalability and recovery performance of the cluster.
Patent Information
- Application Number
- CN202080100499.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-05-14
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2040-05-14
AI Technical Summary
The existing Active Message Queue (AMQ) has low availability in terms of clustering and horizontal expansion, data inconsistency, page break recovery failure and low availability.
By receiving the write request from the client on the master node, the data to be written is obtained and synchronized to multiple slave nodes. The number of slave nodes is monitored in real time until the submission conditions are met and a write success response is sent to the client to ensure that the message is not lost. .
It improves the availability of AMQ, ensures the distributed storage and recovery capabilities of data, realizes the separation architecture of computing and storage, and achieves stateless horizontal expansion of upper-layer applications.
Smart Images

Figure CN115486052B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of data storage, and more particularly to a data storage method, system, and storage medium. Background Art
[0002] Active Message Queue (AMQ) natively uses Kaha database (DataBase, DB) to implement message storage and indexing. KahaDB is based on single-machine storage. For clustering and horizontal expansion requirements above the storage layer, AMQ relies on network file systems such as Network File System (NFS) to achieve master-slave data synchronization, but the entire cluster has only one copy of the data, resulting in low availability of AMQ. Summary of the invention
[0003] The embodiments of the present application provide a data storage method, system and storage medium, which can improve the availability of AMQ.
[0004] The technical solution of the embodiment of the present application is implemented as follows:
[0005] The present invention provides a data storage method, the method comprising:
[0006] Receive a write request from the client through the master node, and obtain the data to be written according to the write request;
[0007] storing the data to be written into the master node;
[0008] Synchronize the data to be written to a plurality of slave nodes, and use the master node to record the number of slave nodes among the plurality of slave nodes that have synchronized the data to be written;
[0009] When it is detected that the number of slave nodes meets the submission condition, a write success response in response to the write request is sent to the client through the master node.
[0010] An embodiment of the present application provides a data storage system, the system comprising:
[0011] A receiving unit, used for receiving a write request from a client through a master node;
[0012] An acquisition unit, used for acquiring the data to be written according to the write request;
[0013] A storage unit, used for storing the data to be written to the master node;
[0014] A synchronization unit, used for synchronizing the data to be written to multiple slave nodes;
[0015] a recording unit, configured to use the master node to record the number of slave nodes among the plurality of slave nodes that have synchronized the data to be written;
[0016] A sending unit is used to send a write success response to the write request to the client through the master node when it is detected that the number of slave nodes meets the submission condition.
[0017] An embodiment of the present application provides a data storage system, the system comprising: a processor, a memory, a transmitter, a receiver and a communication bus, and the processor implements any of the above methods when executing a running program stored in the memory.
[0018] An embodiment of the present application provides a computer-readable storage medium having a program stored thereon, which is applied to a data storage system, and when the program is executed by a processor, any of the methods described above is implemented.
[0019] The embodiment of the present application provides a data storage method, system and storage medium, which may include: receiving a write request from a client through a master node, and obtaining data to be written according to the write request; storing the data to be written in the master node; synchronizing the data to be written to multiple slave nodes, and using the master node to record the number of slave nodes that have synchronized the data to be written among the multiple slave nodes; when it is detected that the number of slave nodes meets the submission condition, sending a write success response to the write request to the client through the master node. It can be seen that in the embodiment of the present application, when the master node stores the data to be written sent by the client, the data to be written is synchronized to multiple slave nodes, and the distributed storage of the client's data to be written is realized. At the same time, when multiple slave nodes synchronize the data to be written, the number of slave nodes that have completed synchronization is monitored in real time, and a write success response is sent to the client when the number of slave nodes meets the submission condition, which can ensure that the submitted message will not be lost, thereby improving the availability of AMQ. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] Figure 1 A data storage method provided in the embodiment of the present application Figure 1 ;
[0021] Figure 2 A schematic diagram of a process of writing a message to be written by a client to a RaftDB cluster provided in an embodiment of the present application;
[0022] Figure 3 A data storage method provided in the embodiment of the present application Figure 2 ;
[0023] Figure 4 A schematic diagram of a process for selecting a master node in an exemplary RaftDB cluster provided in an embodiment of the present application;
[0024] Figure 5 A data storage method provided in the embodiment of the present application Figure 3 ;
[0025] Figure 6 A schematic diagram of a data storage system provided in an embodiment of the present application Figure 1 ;
[0026] Figure 7 A schematic diagram of a data storage system provided in an embodiment of the present application Figure 2 . DETAILED DESCRIPTION
[0027] 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 is understood that the specific embodiments described herein are only used to explain the related applications, rather than to limit the applications. It should also be noted that, for the convenience of description, only the parts related to the related applications are shown in the accompanying drawings.
[0028] When using KahaDB to implement message storage and indexing, the master-slave cluster implements data sharing through NFS. The entire cluster essentially has only one copy of the data, no data replicas, cannot meet availability, and is a pseudo cluster. In addition, NFS network transmission also has performance loss, which in turn limits the throughput performance of AMQ.
[0029] The specific questions are as follows:
[0030] 1. Data inconsistency: KahaDB data is not written to disk and index / redo logs are not written to disk in the same transaction, which leads to data inconsistency between data files and index / redo files when abnormal downtime occurs.
[0031] 2. Failure of page break recovery: KahaDB lacks data verification and data recovery mechanisms. When abnormal downtime causes data tearing, the node cannot be restarted and the data needs to be cleared, resulting in large-scale data loss, which in turn leads to data recovery failure.
[0032] 3. Low availability: Node restart requires scanning all data files, and data recovery takes a long time, which is unacceptable to the business.
[0033] In order to solve the above problems, the technical solutions in the embodiments of the present application will be clearly and completely described below in combination with the drawings in the embodiments of the present application.
[0034] In one embodiment, the present application provides a data storage method. Figure 1 A schematic diagram of an implementation flow of a data storage method proposed in an embodiment of the present application, the method may include:
[0035] S101. Receive a write request from a client through a master node, and obtain data to be written according to the write request.
[0036] A data storage method provided in an embodiment of the present application is suitable for a scenario in which RaftDB is used to implement cluster expansion of an AMQ distributed multi-replica set.
[0037] In the embodiment of the present application, the data storage system is a RaftDB cluster, the RaftDB cluster includes multiple RaftDB nodes, and the master node is a leader node among the multiple RaftDB nodes.
[0038] In the embodiment of the present application, RaftDB exposes the state machine interface to the outside, allowing the state machine of the upper layer of RaftDB to implement snapshots. When the user logs in and performs other operations on the client, the master node receives the write request from the client, and the state machine records the stateful data in the login operation, such as user name, password, etc. The stateful data is the data to be written. The state machine generates a snapshot and a log corresponding to the snapshot based on the write request, and the master node determines the data to be written based on the log.
[0039] In the embodiment of the present application, snapshots are allowed to be sent and loaded. For new nodes or nodes that lag behind in synchronization in the data storage system, data synchronization can be quickly achieved through snapshot sending and loading.
[0040] S102, storing the data to be written to the master node.
[0041] When the data storage system receives a write request from the client through the master node and obtains the data to be written according to the write request, the data storage system stores the data to be written in the master node.
[0042] In an embodiment of the present application, after the master node obtains the data to be written, it assigns a unique incremental ID to the data to be written. The unique incremental ID can ensure the continuity and order of data synchronization from the slave node.
[0043] In an embodiment of the present application, the data to be written includes an index file to be written and a data file to be written. The index file to be written is used to perform addressing in the main node to obtain an addressing result, and then the data file to be written is sequentially written into the addressing result.
[0044] In the embodiment of the present application, the index file to be written uses a memory-mapped file, and the index file to be written adopts a sparse index.
[0045] S103, synchronizing the data to be written to multiple slave nodes, and using the master node to record the number of slave nodes among the multiple slave nodes that have synchronized the data to be written.
[0046] After the data storage system stores the data to be written in the master node, the data storage system synchronizes the data to be written to multiple slave nodes, and uses the master node to record the number of slave nodes that have synchronized the data to be written among the multiple slave nodes.
[0047] In the embodiment of the present application, the master node synchronizes the data to be written to multiple slave nodes, wherein the selection of multiple slave nodes can be based on load balancing, business type, etc. The specific selection method of multiple slave nodes can be selected according to the actual situation, and the embodiment of the present application does not make specific restrictions. Afterwards, when the slave node completes the synchronization operation of the data to be written, the slave node returns the latest write offset, updates the internal state, and responds to the client.
[0048] In an embodiment of the present application, during the process of synchronizing the data to be written to multiple slave nodes, the master node monitors the synchronization status of the multiple slave nodes in real time. Whenever the master node detects that a slave node has completed synchronizing the data to be written, the master node increases the number of slave nodes by one.
[0049] S104. When it is detected that the number of slave nodes meets the submission condition, a write success response in response to the write request is sent to the client through the master node.
[0050] The data storage system sets submission conditions. When the data storage system uses the master node to record the number of slave nodes among multiple slave nodes that have synchronized data to be written, it matches the slave node data with the submission conditions to detect whether the slave node data meets the submission conditions. When the master node detects that the number of slave nodes meets the submission conditions, the data storage system sends a write success response to the write request to the client through the master node.
[0051] In an embodiment of the present application, every time the number of slave nodes increases by one, the master node determines whether the slave node data meets the submission conditions in sequence. When it detects that the number of slave nodes meets the submission conditions, the master node sends a write success response to the client to respond to the client's write request.
[0052] In an embodiment of the present application, the master node obtains a first number corresponding to multiple slave nodes, and takes half of the first number as a submission condition. The master node compares the number of slave nodes that have completed synchronization with half of the first number. When the number of slave nodes is greater than half of the first number, the master node determines that the number of slave nodes meets the submission condition. At this time, the master node sends a write success response to the client in response to the write request.
[0053] For example, Figure 2As shown, the RaftDB with id 0 is the master node, and the RaftDBs with id 1 and id 2 are slave nodes. The client sends the information to be written to the master node. The data of the information to be written is "A32d322991023421", and the information to be written is stored in the RaftDB with id 0. At this time, the index of the RaftDB with id 0 increases by "7", and the corresponding term increases by "3". After that, the RaftDB with id 0 sends an additional entry request to the RaftDB with id 1. The additional entry request carries the following information to be written The RaftDB with id 1 synchronizes the information to be written. When the synchronization is completed, the index of the RaftDB with id 1 increases by "7", and the corresponding term increases by "3". After that, the RaftDB with id 1 returns an additional entry response to the RaftDB with id 0. The additional entry response carries the following information "Index: 7". After receiving the additional entry response, the RaftDB with id 0 sends a write success response to the client. At this point, the process of storing the message to be written with index 7 in the RaftDB with id 0 and the RaftDB with id 1 is completed.
[0054] It is understandable that when the master node stores the data to be written sent by the client, it synchronizes the data to be written to multiple slave nodes, realizing distributed storage of the client's data to be written. At the same time, when multiple slave nodes synchronize the data to be written, the number of slave nodes that have completed synchronization is monitored in real time. When the number of slave nodes meets the submission conditions, a write success response is sent to the client, which can ensure that the submitted messages will not be lost, thereby improving the availability of AMQ. Aggregating stateful data to the storage layer can realize the separation of computing and storage architecture, as well as the stateless horizontal expansion of upper-layer applications. Through the replica set mechanism of the underlying storage, after the single-node system is connected to the RaftDB storage, it has the ability to expand the distributed multi-replica set cluster.
[0055] Based on the above embodiment, in the embodiment of the present application, before the data storage system receives the write request of the client through the master node, that is, before step 101, the data storage system also performs master node election when implementing the data storage method, such as Figure 3 As shown, the specific steps include:
[0056] S201. When a master node election instruction is obtained, multiple terms and multiple write offsets corresponding to multiple storage databases in the data storage system are respectively obtained.
[0057] In an embodiment of the present application, when the data storage system determines that the connection between the master node and the slave node is interrupted, the data storage system obtains a master node election instruction; or, when the storage system determines that the master node has failed, the data storage system obtains a master node election instruction; or, when the data storage system is created, the data storage system obtains a master node election instruction. The specific timing at which the data storage system obtains the master node election instruction is selected based on actual conditions, and the embodiment of the present application does not make any specific limitations.
[0058] In an embodiment of the present application, when the data storage system detects that the number of slave nodes that have synchronized data to be written does not meet the submission conditions when the preset time arrives, the data storage system senses that the connection between the master node and the slave node is interrupted at the link layer. At this time, the data storage system determines that the connection between the master node and the slave node is interrupted.
[0059] In actual applications, when the master node and the slave node are not in the same network partition, there will be a connection interruption problem between the master node and the slave node. During the synchronization of the data to be written by the slave node, it can be determined whether the connection between the master node and the slave node is interrupted. Specifically, when the preset time arrives, the data storage system determines whether the number of slave nodes that have synchronized the data to be written meets the submission conditions. When the data storage system detects that the number of slave nodes does not meet the submission conditions when the preset time arrives, the data storage system determines that the connection between the master node and the slave node is interrupted; at this time, the data storage system triggers the master node reselection process and obtains the master node election instruction.
[0060] In actual applications, when the preset time arrives, the data storage system determines whether the number of slave nodes is greater than half of the first number. When the number of slave nodes is not greater than half of the first number, it indicates that the number of slave nodes does not meet the submission conditions when the preset time arrives. At this time, it is determined that the connection between the master node and the slave node is interrupted, and the data storage system initiates the master node reselection process and obtains the slave node election instruction.
[0061] In an embodiment of the present application, the data storage system can determine whether the master node fails based on the heartbeat between the master and slave nodes, and when it is determined that the master node fails, trigger the master node reselection process and obtain the master node election instruction.
[0062] The storage database in the embodiment of the present application is a RaftDB node. Each RaftDB in the data storage system includes a term and a write offset, wherein the write offset is a write offset generated by the RaftDB node when writing a new message. The data storage system can determine whether multiple RaftDB nodes have the latest logs based on multiple terms and multiple write offsets.
[0063] S202: Determine a first storage database from multiple storage databases according to multiple terms and multiple write offsets.
[0064] After the data storage system respectively obtains multiple terms and multiple write offsets corresponding to multiple storage databases in the data storage system, the data storage system determines a first storage database from the multiple storage databases according to the multiple terms and the multiple write offsets.
[0065] In an embodiment of the present application, the data storage system compares multiple terms; when the data storage system determines a term with the largest number of terms from multiple terms, the data storage system directly determines the storage database corresponding to the one term as the first storage database; when the data storage system determines at least two terms with the largest number of terms from multiple terms, the data storage system further determines the first storage database from at least two storage databases corresponding to at least two terms. Specifically, the data storage system first obtains at least two storage databases corresponding to at least two terms and at least two write offsets corresponding to at least two storage databases; the data storage system determines the first write offset with the largest write offset from the at least two write offsets, and determines the storage database corresponding to the first write offset as the first storage database.
[0066] For example, Figure 4 As shown, the data storage system includes RaftDB with id 0, RaftDB with id 1 and RaftDB with id 2. First, a voting request is initiated to select the master node from RaftDB with id 0, RaftDB with id 1 and RaftDB with id 2. Figure 2 It can be seen that the term in RaftDB with id 0 is 3, and the term in RaftDB with id 1 and RaftDB with id 2 is 2, which means that RaftDB with id 0 stores the latest log. At this time, RaftDB with id 0 is selected as the master node. RaftDB with id 0 can perform heartbeat detection on RaftDB with id 1 and RaftDB with id 2 regularly to monitor the status of RaftDB with id 1 and RaftDB with id 2.
[0067] S203: determine the first storage database as a master node, and determine the second storage database among the multiple storage databases as a slave node, where the second storage database is a storage database among the multiple storage databases except the first storage database.
[0068] After the data storage system determines the first storage database from the multiple storage databases, the data storage system determines the first storage database as a master node, and determines the second storage databases except the first storage database among the multiple storage databases as slave nodes.
[0069] In the embodiment of the present application, the master node is responsible for processing the read and write requests of the client, and regularly sending heartbeats to the slave nodes to monitor the status of each slave node.
[0070] It is understandable that RaftDB implements a master node election mechanism, which restricts the master node to have the latest log through term and write offset, thereby ensuring that the submitted messages will not be lost, thereby achieving message reliability.
[0071] Based on the above embodiment, in the embodiment of the present application, the above data storage system also performs data recovery when implementing the data storage method, such as Figure 5 As shown, the specific steps include:
[0072] S301. When the first node performs data recovery, a snapshot is searched, and the first node is a master node and a slave node for performing data recovery.
[0073] In the embodiment of the present application, when the data is recovered after the master node or the first node of the slave nodes in the data storage system crashes, for page-broken data, subsequent logs are truncated and wait for synchronization. During the startup process, the data storage system searches for a snapshot, which is the snapshot generated when writing the data to be written;
[0074] Furthermore, RaftDB will scan the data files to be written, and can rely on checkpoints to reduce the number of scanned files. Since the message storage protocol is implemented using a fixed message header + message body, it relies on the cyclic redundancy check (CRC) in the message header to verify the data and ultimately complete the verification of the data files.
[0075] S302: Mount the snapshot on the first node, and replay the log corresponding to the snapshot.
[0076] When the data storage system finds the snapshot, the data storage system loads the snapshot on the first node.
[0077] And replay the log corresponding to the snapshot.
[0078] S303. Rewrite the data to be written on the first node according to the log.
[0079] After the data storage system loads the snapshot on the first node and replays the log corresponding to the snapshot, the data storage system rewrites the to-be-written data on the first node according to the log.
[0080] It is understandable that based on snapshots, data verification and recovery mechanisms, the problem of recovery time when data is lost in native AMQ is solved, meeting the current Internet service requirements for high performance, high availability and disaster recovery of middleware.
[0081] Based on the above embodiment, in another embodiment of the present application, Figure 6 Schematic diagram of the structure of the data storage system proposed in the embodiment of the present application Figure 1 ,like Figure 6 As shown, the data storage system 1 proposed in the embodiment of the present application may include:
[0082] The receiving unit 10 is used to receive a write request from a client through a master node;
[0083] An acquisition unit 11, configured to acquire data to be written according to the write request;
[0084] A storage unit 12, used for storing the data to be written to the master node;
[0085] A synchronization unit 13, used for synchronizing the data to be written to multiple slave nodes;
[0086] A recording unit 14 is used to record, using the master node, the number of slave nodes among the multiple slave nodes that have synchronized the data to be written;
[0087] The sending unit 15 is used to send a write success response in response to the write request to the client through the master node when it is detected that the number of the slave nodes meets the submission condition.
[0088] Furthermore, the data storage system 1 further comprises: a judgment unit;
[0089] The acquisition unit 11 is further configured to acquire a first quantity corresponding to the plurality of slave nodes;
[0090] The judging unit is configured to judge that the number of slave nodes meets the submission condition when the number of slave nodes is greater than half of the first number;
[0091] The sending unit 15 is used to send a write success response in response to the write request to the client through the master node.
[0092] Furthermore, the data storage system further comprises: a determination unit;
[0093] The acquisition unit 11 is further used to respectively acquire multiple terms and multiple write offsets corresponding to multiple storage databases in the data storage system when the master node election instruction is acquired;
[0094] The determination unit is used to determine a first storage database from the multiple storage databases based on the multiple terms and the multiple write offsets; determine the first storage database as the master node, and determine a second storage database among the multiple storage databases as the slave node, the second storage database being a storage database among the multiple storage databases except the first storage database.
[0095] Furthermore, the data storage system further comprises: a comparison unit;
[0096] The comparison unit is used to compare the multiple terms;
[0097] The determining unit is further configured to, when a term with the largest number of terms is determined from the multiple terms, determine the storage database corresponding to the term as the first storage database;
[0098] The acquisition unit 11 is further configured to, when at least two terms with the largest terms are determined from the multiple terms, acquire at least two storage databases corresponding to the at least two terms and at least two write offsets corresponding to the at least two storage databases;
[0099] The determining unit is further configured to determine a first write offset having the largest write offset from the at least two write offsets, and determine a storage database corresponding to the first write offset as the first storage database.
[0100] Furthermore, the judging unit is further configured to judge that the connection between the master node and the slave node is interrupted when it is detected that the number of the slave nodes does not meet the submission condition when the preset time arrives;
[0101] The acquisition unit 11 is also used to trigger the master node re-election process and acquire the master node election instruction.
[0102] Furthermore, the data storage system further comprises: an addressing unit and a writing unit;
[0103] The addressing unit is used to use the index file to be written to perform addressing in the master node to obtain an addressing result;
[0104] The writing unit is used to write the data files to be written into the addressing result in sequence.
[0105] Furthermore, the determining unit is further configured to generate a snapshot and a log corresponding to the snapshot according to the write request; and determine the data to be written according to the log.
[0106] Furthermore, the data storage system further comprises: a search unit, a loading unit and a playback unit;
[0107] The search unit is used to search for the snapshot when the first node performs data recovery, and the first node is the node performing data recovery among the master node and the slave node;
[0108] The loading unit is used to load the snapshot on the first node;
[0109] The replay unit is used to replay the log corresponding to the snapshot;
[0110] The writing unit is further used to rewrite the to-be-written data on the first node according to the log.
[0111] Figure 7 Schematic diagram of the structure of the data storage system proposed in the embodiment of the present application Figure 2 ,like Figure 7 As shown, the data storage system 1 proposed in the embodiment of the present application may also include a processor 110 , a memory 111 , a transmitter 112 , a receiver 113 and a communication bus 114 .
[0112] In the process of a specific embodiment, the above-mentioned acquisition unit 11, synchronization unit 13, recording unit 14, judgment unit, determination unit, comparison unit, addressing unit, write unit, search unit, loading unit and replay unit can be implemented by a processor 110 located on the data storage system 1, the above-mentioned storage unit 12 can be implemented by a memory 111 located on the data storage system 1, the above-mentioned sending unit 15 can be implemented by a transmitter 112 located on the data storage system 1, and the above-mentioned receiving unit 10 can be implemented by a receiver 113 located on the data storage system 1. In the embodiment of the present application, the above-mentioned processor 110 can be at least one of an application specific integrated circuit (Application Specific Integrated Circuit, ASIC), a digital signal processor (Digital Signal Processor, DSP), a digital signal processing device (Digital Signal Processing Device, DSPD), a programmable logic device (ProgRAMmable Logic Device, PLD), a field programmable gate array (Field ProgRAMmable Gate Array, FPGA), a central processing unit (Central Processing Unit, CPU), a controller, a microcontroller, and a microprocessor. It is understandable that for different devices, the electronic device used to implement the above-mentioned processor function can also be other, and the embodiments of the present application are not specifically limited. The memory 111 is used to store executable program code, which includes computer operation instructions. The memory 111 may include a high-speed RAM memory, and may also include a non-volatile memory, for example, at least two disk memories.
[0113] In the embodiment of the present application, the communication bus 114 is used to connect the processor 110, the memory 111, the transmitter 112, the receiver 113 and the mutual communication between these devices.
[0114] In the embodiment of the present application, the memory 111 is used to store instructions and data.
[0115] Further, in an embodiment of the present application, the receiver 113 is used to receive a write request from a client through a master node.
[0116] The processor 110 is configured to obtain the data to be written according to the write request; synchronize the data to be written to multiple slave nodes, and use the master node to record the number of slave nodes among the multiple slave nodes that have synchronized the data to be written;
[0117] The memory 111 is used to store the data to be written into the master node;
[0118] The transmitter 112 is configured to send a write success response in response to the write request to the client through the master node when it is detected that the number of slave nodes meets the submission condition.
[0119] Further, the processor 110 is further configured to obtain a first number corresponding to the plurality of slave nodes; when the number of slave nodes is greater than half of the first number, determine that the number of slave nodes meets the submission condition;
[0120] The transmitter 112 is further configured to send a write success response in response to the write request to the client through the master node.
[0121] Furthermore, the processor 110 is also used to obtain multiple terms and multiple write offsets corresponding to multiple storage databases in the data storage system respectively when a master node election instruction is obtained; determine a first storage database from the multiple storage databases based on the multiple terms and the multiple write offsets; determine the first storage database as the master node, and determine the second storage database among the multiple storage databases as the slave node, the second storage database being a storage database among the multiple storage databases except the first storage database.
[0122] Furthermore, the processor 110 is also used to compare the multiple terms; when a term with the largest number of terms is determined from the multiple terms, the storage database corresponding to the term is determined as the first storage database; when at least two terms with the largest number of terms are determined from the multiple terms, at least two storage databases corresponding to the at least two terms and at least two write offsets corresponding to the at least two storage databases are obtained; the first write offset with the largest write offset is determined from the at least two write offsets, and the storage database corresponding to the first write offset is determined as the first storage database.
[0123] Furthermore, the processor 110 is also used to determine that the connection between the master node and the slave node is interrupted when it is detected that the number of slave nodes does not meet the submission condition when the preset time arrives; trigger the master node reselection process and obtain the master node election instruction.
[0124] Furthermore, the processor 110 is further configured to perform addressing in the master node using the index file to be written to obtain an addressing result; and sequentially write the data files to be written into the addressing result.
[0125] Furthermore, the processor 110 is further configured to generate a snapshot and a log corresponding to the snapshot according to the write request; and determine the data to be written according to the log.
[0126] Furthermore, the processor 110 is also used to search for the snapshot when the first node performs data recovery, where the first node is the node performing data recovery among the master node and the slave node; load the snapshot on the first node and replay the log corresponding to the snapshot; and rewrite the data to be written on the first node according to the log.
[0127] In practical applications, the memory 111 may be a volatile first memory, such as a random-access first memory (RAM); or a non-volatile first memory, such as a read-only first memory (ROM), a flash first memory, a hard disk drive (HDD) or a solid-state drive (SSD); or a combination of the above types of first memories, and provide instructions and data to the processor 110.
[0128] In addition, each functional module in this embodiment can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above integrated unit can be implemented in the form of hardware or software functional modules.
[0129] If the integrated unit is implemented in the form of a software function module and is not sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this embodiment is essentially or the part that contributes to the prior art or the whole or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, server, or network device, etc.) or a processor to perform all or part of the steps of the method of this embodiment. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc., various media that can store program codes.
[0130] A data storage system proposed in an embodiment of the present application receives a write request from a client through a master node, and obtains data to be written according to the write request; stores the data to be written in the master node; synchronizes the data to be written to multiple slave nodes, and uses the master node to record the number of slave nodes that have synchronized the data to be written among multiple slave nodes; when it is detected that the number of slave nodes meets the submission condition, a write success response in response to the write request is sent to the client through the master node. It can be seen that in an embodiment of the present application, when the master node stores the data to be written sent by the client, it synchronizes the data to be written to multiple slave nodes, realizes distributed storage of the client's data to be written, and at the same time, monitors the number of slave nodes that have completed synchronization in real time when multiple slave nodes synchronize the data to be written, and sends a write success response to the client when the number of slave nodes meets the submission condition, which can ensure that the submitted message will not be lost, thereby improving the availability of AMQ.
[0131] An embodiment of the present application provides a computer-readable storage medium having a program stored thereon, which implements the data storage method described above when the program is executed by a processor.
[0132] Specifically, the program instructions corresponding to a data storage method in this embodiment can be stored on a storage medium such as a CD, a hard disk, or a USB flash drive. When the program instructions corresponding to a data storage method in the storage medium are read or executed by an electronic device, the data storage method described in any of the above items is implemented.
[0133] 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 in combination with software and hardware. Moreover, 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 disk storage and optical storage, etc.) that contain computer-usable program code.
[0134] The present application is described with reference to implementation 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 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 generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the process in the flowchart. 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.
[0135] 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 operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which is implemented in the implementation flow diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0136] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operation steps are executed on the computer or other programmable device to produce a computer-implemented process, so that the instructions executed on the computer or other programmable device provide for implementing the process described in the flowchart. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0137] The above description is only a preferred embodiment of the present application and is not intended to limit the protection scope of the present application.
[0138] Industrial Applicability
[0139] The embodiments of the present application provide a data storage method, system and storage medium. When a master node stores the data to be written sent by a client, the data to be written is synchronized to multiple slave nodes, thereby realizing distributed storage of the client's data to be written. At the same time, when multiple slave nodes synchronize the data to be written, the number of slave nodes that have completed synchronization is monitored in real time. When the number of slave nodes meets the submission condition, a write success response is sent to the client, which can ensure that the submitted messages will not be lost, thereby improving the availability of AMQ.
Claims
1. A data storage method, the method comprising: Receive a write request from the client through the master node, and obtain the data to be written according to the write request; storing the data to be written into the master node; Synchronize the data to be written to a plurality of slave nodes, and use the master node to record the number of slave nodes among the plurality of slave nodes that have synchronized the data to be written; When it is detected that the number of slave nodes meets the submission condition, sending a write success response in response to the write request to the client through the master node; When the master node election instruction is obtained, multiple terms and multiple write offsets corresponding to multiple storage databases in the data storage system are obtained respectively; Determining a first storage database from the plurality of storage databases according to the plurality of terms and the plurality of write offsets; The first storage database is determined as the master node, and a second storage database among the multiple storage databases is determined as the slave node, wherein the second storage database is a storage database among the multiple storage databases except the first storage database.
2. The method according to claim 1, wherein: When it is detected that the number of slave nodes meets the submission condition, sending a write success response in response to the write request to the client through the master node, including: Obtaining a first quantity corresponding to the plurality of slave nodes; When the number of slave nodes is greater than half of the first number, it is determined that the number of slave nodes meets the submission condition; A write success response in response to the write request is sent to the client through the master node.
3. The method according to claim 2, wherein: The step of determining a first storage database from the plurality of storage databases according to the plurality of terms and the plurality of write offsets comprises: comparing the plurality of terms; When a term with the largest number of terms is determined from the multiple terms, the storage database corresponding to the term is determined as the first storage database; When at least two terms with the largest terms are determined from the multiple terms, obtaining at least two storage databases corresponding to the at least two terms and at least two write offsets corresponding to the at least two storage databases; A first write offset having the largest write offset is determined from the at least two write offsets, and a storage database corresponding to the first write offset is determined as the first storage database.
4. The method according to claim 1, wherein: After using the master node to record the number of slave nodes among the multiple slave nodes that have synchronized the data to be written, the method further includes: When it is detected that the number of slave nodes does not meet the submission condition when the preset time arrives, it is determined that the connection between the master node and the slave node is interrupted; The master node re-election process is triggered, and the master node election instruction is obtained.
5. The method according to claim 1, wherein: The data to be written includes an index file to be written and a data file to be written, and storing the data to be written to the master node includes: Using the index file to be written to perform addressing in the master node, obtaining an addressing result; The data files to be written are sequentially written into the addressing result.
6. The method according to claim 1, wherein: The step of obtaining the data to be written according to the write request includes: Generate a snapshot and a log corresponding to the snapshot according to the write request; The data to be written is determined according to the log.
7. The method according to claim 6, wherein: After determining the data to be written according to the log, the method further includes: When the first node performs data recovery, the snapshot is searched, and the first node is the node in which the data is recovered between the master node and the slave node; Mounting the snapshot on the first node, and replaying the log corresponding to the snapshot; The to-be-written data is rewritten on the first node according to the log.
8. A data storage system, the system comprising: A receiving unit, used for receiving a write request from a client through a master node; An acquisition unit, used for acquiring the data to be written according to the write request; A storage unit, used for storing the data to be written to the master node; A synchronization unit, used for synchronizing the data to be written to multiple slave nodes; a recording unit, configured to use the master node to record the number of slave nodes among the plurality of slave nodes that have synchronized the data to be written; A sending unit, configured to send a write success response in response to the write request to the client through the master node when it is detected that the number of slave nodes meets a submission condition; The acquisition unit is further used to respectively acquire multiple terms and multiple write offsets corresponding to multiple storage databases in the data storage system when the master node election instruction is acquired; a determining unit, configured to determine a first storage database from the plurality of storage databases according to the plurality of terms and the plurality of write offsets; The first storage database is determined as the master node, and a second storage database among the multiple storage databases is determined as the slave node, wherein the second storage database is a storage database among the multiple storage databases except the first storage database.
9. A data storage system, the system comprising: A processor, a memory, a transmitter, a receiver and a communication bus, wherein the processor implements the method according to any one of claims 1 to 7 when executing a running program stored in the memory.
10. A computer-readable storage medium having a program stored thereon, applied to a data storage system, wherein when the program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
