Data processing methods and related products
By introducing a matching mechanism between target write nodes and storage nodes in a distributed database system, using queue management and registration nodes to optimize data routing, the problem of insufficient stability and scalability in massive data processing in traditional database systems is solved, and the problem of insufficient stability and scalability in massive data processing is realized. More efficient data storage and query.
Patent Information
- Application Number
- CN202311693042.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-08
- Publication Date
- 2024-12-24
- Estimated Expiration
- 2043-12-08
AI Technical Summary
Traditional database systems have problems of insufficient stability and scalability when processing massive data, especially in distributed environments, where data storage and access requirements are difficult to meet.
By introducing a matching mechanism between target write nodes and storage nodes in the distributed database system, it is determined that the available storage nodes can be used for data storage and query, the queue mechanism is used to manage data storage and transmission, and the data routing and query paths are optimized by registering nodes, so as to reduce the Resource utilization and improve system stability.
It improves the stability and scalability of distributed databases, reduces the resource overhead and query delay of storage clusters, and enhances the system's fault tolerance and data processing efficiency.
Smart Images

Figure CN117806546B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of distributed databases, and in particular to a data processing method and related products. Background Art
[0002] In traditional database systems, data is stored and managed in a centralized manner. However, with the advent of the Internet and the era of big data, traditional methods can no longer meet the needs of storing and accessing massive amounts of data. This is when distributed database systems came into being. Distributed database systems store data in multiple servers and share and access data through network connections. Distributed database systems can provide higher availability, higher performance, and better scalability, so they are widely used in various industries. Based on this, how to improve the stability of distributed databases is of great significance. Summary of the invention
[0003] The present application provides a data processing method and related products to improve the stability of a distributed database, wherein the related products include a data processing system, a computer-readable storage medium, and a computer program product.
[0004] In a first aspect, a data processing method is provided, the method being used to process data of a distributed database, the distributed database comprising a storage cluster, the storage cluster comprising at least one write node and at least two storage nodes, the write node being a node for writing data, the storage node being a node for storing data to be stored, the data to be stored being data that needs to be stored in the distributed database, the at least one write node comprising a target write node, the method comprising:
[0005] When receiving a request to store the data to be stored, the target write node determines a target storage node that matches the data to be stored from the at least two storage nodes, wherein the target storage node has an index that matches the data to be stored;
[0006] When the target writing node determines that the target storage node is unavailable, the target writing node stores the data to be stored in the target writing node;
[0007] When the target writing node determines that the target storage node is available, the target writing node writes the to-be-stored data in the target writing node into the target storage node.
[0008] In combination with any embodiment of the present application, the distributed database further includes a query node and a registration node, the query node is a node for querying data stored in the distributed database, the registration node includes addresses of the at least two storage nodes, and the method further includes:
[0009] The registration node determines a query address according to the addresses of the at least two storage nodes, wherein the query address is an address of a node storing query data, and the query data is data required to be queried by the query node;
[0010] The registration node sends the query address to the query node;
[0011] When receiving the query instruction, the query node filters the data stored in the node indicated by the query address according to the query address and the filtering condition in the query instruction to obtain the target data;
[0012] The query node determines a query result of the query instruction according to the target data.
[0013] In combination with any implementation manner of the present application, the query node determines the query result of the query instruction according to the target data, including:
[0014] The query node obtains an aggregation result by aggregating the target data;
[0015] The query node uses the aggregated result as the query result of the query instruction.
[0016] In combination with any implementation manner of the present application, the node other than the target storage node among the at least two storage nodes is a reference node;
[0017] Before the registration node determines the query address according to the addresses of the at least two storage nodes, the method further includes:
[0018] When the target writing node determines that the target storage node is available, the target writing node sends a message that the target storage node is available to the registration node;
[0019] The registration node determines the query address according to the addresses of the at least two storage nodes, including:
[0020] When the registration node receives the message that the target storage node is available, the registration node obtains the query address according to the address of the reference node and the address of the target storage node.
[0021] In combination with any embodiment of the present application, the distributed database further includes a replica cluster, the replica cluster is a replica of the storage cluster, the replica cluster includes a replica storage node of the target storage node, the registration node includes an address of the replica storage node, and the node other than the target storage node among the at least two storage nodes is a reference node;
[0022] Before the registration node determines the query address according to the addresses of the at least two storage nodes, the method further includes:
[0023] When the target writing node determines that the target storage node is unavailable, the target writing node sends a message that the target storage node is unavailable to the registration node;
[0024] The registration node determines the query address according to the addresses of the at least two storage nodes, including:
[0025] When the registration node receives the message that the target storage node is unavailable, the registration node obtains the query address according to the address of the reference node and the address of the replica storage node.
[0026] In combination with any embodiment of the present application, the target write node includes a target queue for storing data to be written to the target storage node, the target queue includes a memory queue, and the data in the memory queue is stored in the memory of the target write node;
[0027] The storing the data to be stored in the target write node includes:
[0028] Determining a first amount of data in the memory queue;
[0029] Before the first data amount reaches a first threshold, the data to be stored is stored in the memory queue.
[0030] In combination with any implementation manner of the present application, the target queue includes a disk queue, and the data in the disk queue is stored on the disk of the target write node;
[0031] After determining the first amount of data in the memory queue, the method further includes:
[0032] After the first data amount reaches the first threshold, the target write node stores the data to be stored in the disk queue, and transfers the data in the memory queue to the disk queue.
[0033] In combination with any implementation manner of the present application, storing the data to be stored in the disk queue includes:
[0034] When the amount of the data to be stored does not exceed a predetermined value, storing the data to be stored as a file block in the disk queue;
[0035] When the amount of data to be stored exceeds the predetermined value, the data to be stored is divided into r file blocks and stored in the disk queue, where r is an integer greater than 1, and the r file blocks include r-1 file blocks whose data amount is the predetermined value and 1 file block whose data amount does not exceed the predetermined value.
[0036] In combination with any implementation manner of the present application, when the data to be stored is stored in the disk queue, writing the data to be stored in the target write node to the target storage node includes:
[0037] Taking a file block as a reading unit, reading the n file blocks in the disk queue, and in the process of reading the n file blocks, the target writing node deletes the read file blocks from the disk queue;
[0038] By writing the n file blocks into the target storage node, the data to be stored in the target writing node is written into the target storage node.
[0039] In combination with any embodiment of the present application, the method further includes:
[0040] When all data in the disk queue has been deleted and a request to store new data is received, the target write node stores the new data in the memory queue, and the new data matches the index.
[0041] In combination with any implementation manner of the present application, the node other than the target storage node among the at least two storage nodes is a reference node;
[0042] Before the registration node determines the query address according to the addresses of the at least two storage nodes, the method further includes:
[0043] The registration node receives a second data volume of the data in the target queue sent by the target write node;
[0044] The registration node determines the query address according to the addresses of the at least two storage nodes, including:
[0045] When the second data volume does not reach a second threshold, the registration node obtains the query address according to the address of the reference node and the address of the target storage node.
[0046] In combination with any implementation manner of the present application, the distributed database further includes a replica cluster, the replica cluster is a replica of the storage cluster, the replica cluster includes a replica storage node of the target storage node, and the registration node further includes an address of the replica storage node;
[0047] After the registration node receives the second data volume of the data in the target queue sent by the target write node, the method further includes:
[0048] The registration node determines that the target storage node has a backlog when the second data amount reaches a second threshold;
[0049] The registration node determines that the target storage node is not backlogged when the second data amount does not reach the second threshold;
[0050] The registration node determines the query address according to the addresses of the at least two storage nodes, including:
[0051] When the target storage node is already backlogged, the registration node obtains the query address according to the address of the reference node and the address of the replica storage node;
[0052] When the target storage node changes from being backlogged to being unbacklogged and the time duration for which the target storage node remains unbacklogged reaches a third threshold, the registration node obtains the query address according to the address of the reference node and the address of the target storage node.
[0053] In combination with any implementation manner of the present application, the number of the write nodes is at least two, and the method further includes:
[0054] The registration node determines, when the storage cluster obtains at least three storage nodes by adding at least one of the storage nodes, an update plan for at least two of the write nodes according to the number of the write nodes, wherein the update plan is used to update addresses of the storage nodes of the storage cluster obtained by at least two of the write nodes from the registration node;
[0055] In the update plan, at least two of the write nodes are updated through at least two update phases, the update order of any two update phases is different, and the write nodes to be updated in any two update phases are different;
[0056] When the registration node determines, according to the update plan, that the update phase of the current update includes the target write node, the registration node sends the addresses of the at least three storage nodes to the target write node.
[0057] In combination with any embodiment of the present application, the method further includes:
[0058] The registration node determines the storage cluster according to the name of the storage cluster;
[0059] The registration node determines addresses of the at least two storage nodes according to the at least two storage nodes in the storage cluster.
[0060] In combination with any implementation manner of the present application, the registration node determines the addresses of the at least two storage nodes according to the at least two storage nodes in the storage cluster, including:
[0061] The registration node determines the names of the at least two storage nodes in the storage cluster;
[0062] The registration node calculates the addresses of the at least two storage nodes based on the names of the at least two storage nodes.
[0063] In combination with any embodiment of the present application, the at least two storage nodes include a reference storage node different from the target storage node, the target write node stores reference data, the reference data is data that needs to be written to the reference storage node, and the time when the target write node obtains the reference data is earlier than the time when the target write node obtains the data to be stored;
[0064] The step of writing the data to be stored in the target write node into the target storage node comprises:
[0065] The target writing node calls a writing thread to write the reference data into the reference storage node when the reference storage node is available, and the writing thread is a thread used for writing data;
[0066] After the target writing node writes the reference data into the reference storage node, the target writing node writes the data to be stored in the target writing node into the target storage node;
[0067] When the reference storage node is unavailable, the target write node calls the write thread to write the to-be-stored data in the target write node into the target storage node.
[0068] In combination with any implementation manner of the present application, determining a target storage node matching the data to be stored from the at least two storage nodes includes:
[0069] A node having an identifier matching the identifier of the data to be stored is determined from the at least two storage nodes as the target storage node.
[0070] In combination with any embodiment of the present application, after determining, from the at least two storage nodes, a target storage node having an identifier matching the identifier of the data to be stored, the method further includes:
[0071] The target write node sends a write request to the target storage node;
[0072] The target write node determines that the target storage node is unavailable if the target storage node does not respond to the write request.
[0073] In combination with any implementation manner of the present application, the data to be stored is data with a time tag.
[0074] In a second aspect, a data processing system is provided, the data processing system is used to run a distributed database, the data processing system includes a storage cluster, the storage cluster includes at least one write node and at least two storage nodes, the write node is a node for writing data, the storage node is a node for storing data to be stored, the data to be stored is data that needs to be stored in the distributed database, and the at least one write node includes a target write node;
[0075] When receiving a request to store the data to be stored, the target write node determines a target storage node that matches the data to be stored from the at least two storage nodes, wherein the target storage node has an index that matches the data to be stored;
[0076] When the target writing node determines that the target storage node is unavailable, the target writing node stores the data to be stored in the target writing node;
[0077] When the target writing node determines that the target storage node is available, the target writing node writes the to-be-stored data in the target writing node into the target storage node.
[0078] In combination with any embodiment of the present application, the data processing system further includes a query node and a registration node, the query node is a node for querying the data stored in the distributed database, and the registration node includes the addresses of the at least two storage nodes;
[0079] The registration node determines a query address according to the addresses of the at least two storage nodes, wherein the query address is an address of a node storing query data, and the query data is data required to be queried by the query node;
[0080] The registration node sends the query address to the query node;
[0081] When receiving the query instruction, the query node filters the data stored in the node indicated by the query address according to the query address and the filtering condition in the query instruction to obtain the target data;
[0082] The query node determines a query result of the query instruction according to the target data.
[0083] In combination with any implementation manner of the present application, the query node obtains an aggregation result by aggregating the target data;
[0084] The query node uses the aggregated result as the query result of the query instruction.
[0085] In combination with any implementation manner of the present application, the node other than the target storage node among the at least two storage nodes is a reference node;
[0086] When the target writing node determines that the target storage node is available, the target writing node sends a message that the target storage node is available to the registration node;
[0087] When the registration node receives the message that the target storage node is available, the registration node obtains the query address according to the address of the reference node and the address of the target storage node.
[0088] In combination with any embodiment of the present application, the data processing system further includes a replica cluster, the replica cluster is a replica of the storage cluster, the replica cluster includes a replica storage node of the target storage node, the registration node includes an address of the replica storage node, and the node other than the target storage node among the at least two storage nodes is a reference node;
[0089] When the target writing node determines that the target storage node is unavailable, the target writing node sends a message that the target storage node is unavailable to the registration node;
[0090] When the registration node receives the message that the target storage node is unavailable, the registration node obtains the query address according to the address of the reference node and the address of the replica storage node.
[0091] In combination with any embodiment of the present application, the target write node includes a target queue for storing data to be written to the target storage node, the target queue includes a memory queue, and the data in the memory queue is stored in the memory of the target write node;
[0092] The target write node determines a first data amount of the data in the memory queue;
[0093] The target writing node stores the data to be stored in the memory queue before the first data amount reaches a first threshold.
[0094] In combination with any implementation manner of the present application, the target queue includes a disk queue, and the data in the disk queue is stored on the disk of the target write node;
[0095] After the first data amount reaches the first threshold, the target write node stores the data to be stored in the disk queue, and transfers the data in the memory queue to the disk queue.
[0096] In combination with any implementation manner of the present application, the target write node stores the data to be stored as a file block in the disk queue when the amount of the data to be stored does not exceed a predetermined value;
[0097] When the amount of data to be stored exceeds the predetermined value, the target write node divides the data to be stored into r file blocks and stores them in the disk queue, where r is an integer greater than 1, and the r file blocks include r-1 file blocks with a data amount of the predetermined value and 1 file block with a data amount not exceeding the predetermined value.
[0098] In combination with any implementation manner of the present application, the target write node uses a file block as a reading unit to read the n file blocks in the disk queue. During the process of reading the n file blocks, the target write node deletes the read file blocks from the disk queue;
[0099] The target writing node writes the data to be stored in the target writing node into the target storage node by writing the n file blocks into the target storage node.
[0100] In combination with any embodiment of the present application, when all data in the disk queue has been deleted and a request to store new data is received by the target write node, the new data is stored in the memory queue, and the new data matches the index.
[0101] In combination with any implementation manner of the present application, the node other than the target storage node among the at least two storage nodes is a reference node;
[0102] The registration node receives a second data volume of the data in the target queue sent by the target write node;
[0103] When the second data volume does not reach a second threshold, the registration node obtains the query address according to the address of the reference node and the address of the target storage node.
[0104] In combination with any embodiment of the present application, the data processing system further includes a replica cluster, the replica cluster is a replica of the storage cluster, the replica cluster includes a replica storage node of the target storage node, and the registration node further includes an address of the replica storage node;
[0105] The registration node determines that the target storage node has a backlog when the second data amount reaches a second threshold;
[0106] The registration node determines that the target storage node is not backlogged when the second data amount does not reach the second threshold;
[0107] When the target storage node is already backlogged, the registration node obtains the query address according to the address of the reference node and the address of the replica storage node;
[0108] When the target storage node changes from being backlogged to being unbacklogged and the time duration for which the target storage node remains unbacklogged reaches a third threshold, the registration node obtains the query address according to the address of the reference node and the address of the target storage node.
[0109] In combination with any implementation manner of the present application, the number of the write nodes is at least two, and when the storage cluster obtains at least three storage nodes by adding at least one of the storage nodes, the registration node determines an update plan for at least two of the write nodes according to the number of the write nodes, and the update plan is used to update the addresses of the storage nodes of the storage cluster obtained by at least two of the write nodes from the registration node;
[0110] In the update plan, at least two of the write nodes are updated through at least two update phases, the update order of any two update phases is different, and the write nodes to be updated in any two update phases are different;
[0111] When the registration node determines, according to the update plan, that the update phase of the current update includes the target write node, the registration node sends the addresses of the at least three storage nodes to the target write node.
[0112] In combination with any implementation manner of the present application, the registration node determines the storage cluster according to the name of the storage cluster;
[0113] The registration node determines addresses of the at least two storage nodes according to the at least two storage nodes in the storage cluster.
[0114] In combination with any implementation manner of the present application, the registration node determines the names of the at least two storage nodes in the storage cluster;
[0115] The registration node calculates the addresses of the at least two storage nodes based on the names of the at least two storage nodes.
[0116] In combination with any embodiment of the present application, the at least two storage nodes include a reference storage node different from the target storage node, the target write node stores reference data, the reference data is data that needs to be written to the reference storage node, and the time when the target write node obtains the reference data is earlier than the time when the target write node obtains the data to be stored;
[0117] The target writing node calls a writing thread to write the reference data into the reference storage node when the reference storage node is available, and the writing thread is a thread used for writing data;
[0118] After the target writing node writes the reference data into the reference storage node, the target writing node writes the data to be stored in the target writing node into the target storage node;
[0119] When the reference storage node is unavailable, the target write node calls the write thread to write the to-be-stored data in the target write node into the target storage node.
[0120] In combination with any embodiment of the present application, the target write node determines, from the at least two storage nodes, a node having an identifier that matches the identifier of the data to be stored as the target storage node.
[0121] In combination with any implementation manner of the present application, the target write node sends a write request to the target storage node;
[0122] The target write node determines that the target storage node is unavailable if the target storage node does not respond to the write request.
[0123] In combination with any implementation manner of the present application, the data to be stored is data with a time tag.
[0124] In a third aspect, a computer-readable storage medium is provided, in which a computer program is stored. The computer program includes program instructions. When the program instructions are executed by a processor, the processor is caused to execute the first aspect and any one of its embodiments.
[0125] According to a fourth aspect, a computer program product is provided, wherein the computer program product comprises a computer program or instructions, and when the computer program or instructions are run on a computer, the computer is enabled to execute the first aspect and any embodiment thereof.
[0126] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application.
[0127] In the embodiment of the present application, when the target write node receives a request to store the data to be stored, it determines the target storage node with an index matching the data to be stored from at least two storage nodes. When the target write node determines that the target storage node is unavailable, it first stores the data to be stored locally in the target write node, and then writes the data to be stored in the target write node to the target storage node when it determines that the target storage node is available.
[0128] Since there is no index matching the data to be stored in the storage nodes other than the target storage node among the at least two storage nodes, compared with writing the data to be stored in the storage nodes other than the target storage node when the target storage node is determined to be unavailable, the embodiment of the present application does not need to establish an index matching the data to be stored in the storage nodes other than the target storage node. This can reduce the resource utilization of the storage cluster, and further reduce the probability of avalanche in the storage cluster, thereby improving the stability of the distributed database. BRIEF DESCRIPTION OF THE DRAWINGS
[0129] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the background technology, the drawings required for use in the embodiments of the present application or the background technology will be described below.
[0130] The drawings herein are incorporated into the specification and constitute a part of the specification. These drawings illustrate embodiments consistent with the present application and are used together with the specification to illustrate the technical solution of the present application.
[0131] Figure 1 An architecture diagram of a distributed database provided in an embodiment of the present application;
[0132] Figure 2 A flowchart of a data processing method provided in an embodiment of the present application;
[0133] Figure 3a A schematic diagram of storing the data to be stored in a storage node other than the target write node when the target storage node is unavailable provided in an embodiment of the present application;
[0134] Figure 3b A schematic diagram of storing data to be stored in a target queue of a target write node when a target storage node is unavailable, provided in an embodiment of the present application;
[0135] Figure 3cA schematic diagram of storing data in a target queue of a target write node to a target storage node when the target storage node is available, provided in an embodiment of the present application;
[0136] Figure 4 A schematic diagram of the architecture of a data processing system provided in an embodiment of the present application. DETAILED DESCRIPTION
[0137] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0138] The terms "first", "second", etc. in the specification and claims of this application and the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally includes steps or units that are not listed, or optionally includes other steps or units inherent to these processes, methods, products or devices.
[0139] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0140] The embodiment of the present application provides a data processing method, which is used to process data in a distributed database, specifically, including storing data in the distributed database and querying data in the distributed database. Figure 1 , Figure 1 This is a diagram of the architecture of a distributed database provided in an embodiment of the present application. Figure 1 As shown, the distributed database includes a storage cluster, a replica cluster, M query nodes and a registration node, wherein the replica cluster is a copy of the storage cluster, the query node is a node used to query the data stored in the distributed database, and the M query nodes include query node 1, ..., query node M, where M is a positive integer.
[0141] like Figure 1 As shown, the storage cluster includes P write nodes, wherein the write node is a node for writing data, and the P write nodes include write node 1, ..., write node P, and P is a positive integer. The storage cluster also includes N storage nodes, wherein the storage node is a node for storing data to be stored, and the N storage nodes include storage node 1, ..., storage node N, and N is a positive integer greater than 1. The replica cluster includes a replica of any node in the storage cluster. Specifically, the replica cluster includes N replica storage nodes of N storage nodes and P replica write nodes of P write nodes, wherein the N replica storage nodes include replica storage node 1, ..., replica storage node N, and the P replica write nodes include replica write node 1, ..., replica write node P. The registration node includes the address of the storage node in the storage cluster and the address of the replica storage node in the replica cluster, the registration information of the storage cluster, and the registration information of the replica cluster. Optionally, the above node can be one of the following: a computer, a server. Optionally, the distributed database is Victoria Metrics, the write node is the write component (vminsert) of Victoria Metrics, the storage node is the storage component (vmstorage) of Victoria Metrics, and the query node is the query component (vmselect) of Victoria Metrics.
[0142] like Figure 1 As shown, the registration node includes service discovery, and the address of the storage node is obtained through service discovery. Specifically, the registration node can determine the name of the storage cluster based on the registration information of the storage cluster. The registration node can then determine the storage cluster through service discovery and the name of the storage cluster, and then determine the address of the storage node in the storage cluster. Similarly, the registration node can obtain the address of the replica storage node in the replica cluster through service discovery. After the distributed database is started, the query node, write node, and replica write node can all obtain the address list of the storage node from the registration node.
[0143] When the address of a storage node changes and the address of a replica storage node changes, the registered node can also obtain the address changes of the storage node and the address changes of the replica storage node through service discovery, and then send the address changes of the storage node to the query node, the write node, and the replica write node, so that the query node, the write node, and the replica write node can obtain the real-time changes of the address of the storage node and the address of the replica storage node.
[0144] After obtaining the address list of the storage nodes, the query node can determine the address of each storage node according to the address list of the storage nodes. Figure 1 As shown, the query node can query the data in each storage node according to the address of each storage node.
[0145] exist Figure 1 In the example, the display terminal is a display terminal that needs to display the query results of the query node. Optionally, the display terminal displays the query results through the Grafana platform. The alarm terminal is an alarm terminal that needs to monitor and alarm according to the query results of the query node. For example, Figure 1 The distributed database shown is used to store the indicators generated by the monitored cluster, and the alarm terminal is a terminal running a monitoring system. The monitoring terminal obtains the indicators generated by the monitored cluster from the distributed database through the monitoring system, and then determines the operating status of the monitored cluster based on the indicators, and issues an alarm when an abnormality occurs in the operation. Optionally, the monitoring system is a Prometheus system.
[0146] like Figure 1 As shown, after the display terminal sends a query instruction to the query node, the load balancing is used to make each query node respond to the query instruction, and the data in the storage node is queried. Similarly, after the alarm terminal sends a query instruction to the query node, the load balancing is used to make each query node respond to the query instruction, and the data in the storage node is queried. After the M query nodes obtain the query results through the query, they return the query results to the terminal that sent the query instruction through load balancing.
[0147] After obtaining the address list of the storage nodes, the write node can determine the address of each storage node according to the address list of the storage nodes. Figure 1 As shown, the write node can write data to each storage node according to the address of each storage node. Similarly, the replica write node can also write data to each replica storage node according to the address of each replica storage node.
[0148] When writing data to a storage node, the write node can determine the status of the storage node, where the status of the storage node includes whether the storage node is available and whether the data to be written to the storage node is backlogged. Figure 1 As shown in the figure, after determining the status of the storage node, the write node reports the status of the storage node to the registration node. Similarly, after determining the status of the replica storage node, the replica write node reports the status of the replica storage node to the registration node. The status of the storage node reported by the write node and the status of the replica storage node reported by the replica write node are used by the registration node to assist in switching the flow. Specifically, Figure 1As shown, the registration node includes automatic flow switching, wherein the automatic flow switching includes switching the query object of the query node from the storage node to the replica storage node based on the status of the storage node and the status of the replica storage node, and the automatic flow switching may include switching the query object of the query node from the replica storage node to the storage node based on the status of the storage node and the status of the replica storage node.
[0149] like Figure 1 As shown, the writing node also reports the identity document (ID) of the writing node to the registering node through the client information report, so that the registering node can assist in grayscale. Figure 1 As shown, registering a node includes shard scaling and grayscale configuration, wherein shard scaling includes expanding the capacity of storage nodes in the storage cluster, and grayscale configuration includes enabling all write nodes to obtain the addresses of expanded storage nodes in stages through a phased grayscale method.
[0150] The following section will explain in detail the data processing process of the distributed database. Figure 2 , Figure 2 It is a flowchart of a data processing method provided in an embodiment of the present application.
[0151] 201. When receiving a request to store data to be stored, the target write node determines a target storage node that matches the data to be stored from at least two storage nodes.
[0152] In an embodiment of the present application, a distributed database includes a storage cluster, and the storage cluster includes at least one write node and at least two storage nodes. The target write node is any one of the at least one write node. The storage node is a node for storing data to be stored, and the data to be stored is data that needs to be stored in the distributed database, that is, the data stored in the distributed database is stored in the storage node. Optionally, the data to be stored is data with a time tag, in which case the data to be stored is time series data.
[0153] In one possible implementation, when a distributed database receives a request to store reference data, the reference data is sharded to divide the reference data into at least two data to be stored, wherein the data to be stored corresponds one-to-one to the storage node. For example, a distributed database is used to store indicators generated by a monitored cluster, in which case the indicators are reference data. When the monitored cluster generates an indicator, the distributed database receives a request to store the indicator and divides the received indicator into at least two data to be stored. The request to store each data to be stored is then sent to each write node through load balancing.
[0154] In the implementation of this application, the data in the storage nodes are stored in the form of indexes. In one possible implementation, the distributed database is a time series database, and the data stored in the distributed database is time series data (TSD). In this case, the data stored in each storage node is TSD. The index in the storage node is an index built based on TSD. For example, the index item is the memory usage of the monitored cluster, and the index built based on TSD can be the memory usage of the monitored cluster at different times.
[0155] The target storage node has an index that matches the data to be stored. In one possible implementation, the index items in the target storage node match the data to be stored. For example, the data to be stored is the memory usage of the monitored cluster. Among at least two storage nodes, storage node a includes an index related to the memory usage of the monitored cluster. Then the target write node determines that storage node a is the target storage node.
[0156] In another possible implementation, both the data to be stored and the storage node have identifiers, and the target write node determines a node having an identifier matching the identifier of the data to be stored from at least two storage nodes as the target storage node.
[0157] 202. When the target writing node determines that the target storage node is unavailable, the target writing node stores the data to be stored in the target writing node.
[0158] In an embodiment of the present application, when the target storage node is unavailable, the target write node cannot write the data to be stored to the target storage node. Therefore, when the target write node determines that the target storage node is unavailable, the target write node stores the data to be stored to the target write node.
[0159] 203. When the target writing node determines that the target storage node is available, the target writing node writes the data to be stored in the target writing node into the target storage node.
[0160] In an embodiment of the present application, when the target write node is available, the target write node can write the data to be stored to the target storage node. Therefore, when the target write node determines that the target storage node is available, the target write node writes the data to be stored in the target write node to the target storage node, thereby storing the data to be stored in the distributed database.
[0161] In the embodiment of the present application, when the target write node receives a request to store the data to be stored, it determines the target storage node with an index matching the data to be stored from at least two storage nodes. When the target write node determines that the target storage node is unavailable, it first stores the data to be stored locally in the target write node, and then writes the data to be stored in the target write node to the target storage node when it determines that the target storage node is available.
[0162] Since there is no index matching the data to be stored in the storage nodes other than the target storage node among the at least two storage nodes, compared with writing the data to be stored in the storage nodes other than the target storage node when the target storage node is determined to be unavailable, the embodiment of the present application does not need to establish an index matching the data to be stored in the storage nodes other than the target storage node. This can reduce the resource utilization of the storage cluster, and further reduce the probability of avalanche in the storage cluster, thereby improving the stability of the distributed database.
[0163] Furthermore, since there is no need to establish indexes matching the data to be stored in storage nodes other than the target storage node, the duplication rate of indexes in at least two storage nodes can be reduced, thereby improving the query hit rate when querying data in at least two storage nodes.
[0164] As an optional implementation, the distributed database further includes a query node and a registration node, wherein the query node is a node for querying data stored in the distributed database, and the registration node includes the addresses of at least two storage nodes. In this implementation, the data processing method further includes the following steps:
[0165] 301. The registration node determines a query address according to the addresses of the at least two storage nodes.
[0166] In the embodiment of the present application, the query address is the address of the node storing the query data, wherein the query data is the data required to be queried by the query node. It should be understood that the node storing the query data can be a storage node in the storage cluster or a replica storage node in the replica cluster.
[0167] In a possible implementation, at least two storage nodes other than the target storage node are reference nodes. Before the registration node executes step 301, the target write node sends a message to the registration node that the target storage node is available when determining that the target storage node is available. When the registration node receives the message that the target storage node is available, the registration node obtains a query address based on the address of the reference node and the address of the target storage node. Optionally, the registration node uses the address of the reference node and the address of the target storage node as the query address.
[0168] In this implementation, when the storage nodes in the storage cluster are available, the registration node obtains the query address according to the address of the storage node, so that the storage nodes indicated by the query address are all available, and the query node queries data according to the query address, which can also improve the query success rate and query efficiency. For example, when at least two storage nodes in the storage cluster are available, the registration node uses the addresses of the at least two storage nodes as the query address.
[0169] In another possible implementation, the distributed database further includes a replica cluster, wherein the replica cluster is a replica of the storage cluster, the replica cluster includes a replica storage node of the target storage node, and the registration node includes an address of the replica storage node. Before the registration node executes step 301, the target write node sends a message to the registration node that the target storage node is unavailable when it is determined that the target storage node is unavailable. When the registration node receives the message that the target storage node is unavailable, the registration node obtains a query address based on the address of the reference node and the address of the replica storage node. Optionally, the registration node uses the address of the reference node and the address of the replica storage node as the query address.
[0170] In this implementation, when a storage node in the storage cluster is unavailable, the registration node obtains a query address based on the address of a replica storage node of the unavailable storage node, so that all storage nodes indicated by the query address are available, and the query object of the query node is switched from the target storage node to the replica storage node of the target query node, thereby achieving automatic flow switching. Thus, the query node queries data according to the query address, which can improve the query success rate and query efficiency. For example, at least two storage nodes of the storage cluster include a target storage node and storage node a. When the target storage node is unavailable and storage node a is available, the registration node uses the address of storage node a and the address of the replica storage node of the target storage node as the query address.
[0171] 302. The registration node sends the query address to the query node.
[0172] Optionally, after the distributed database is started, the registration node sends the query address to the query node for query by the query node.
[0173] 303. When receiving the query instruction, the query node filters the data stored in the node indicated by the query address according to the query address and the filtering condition in the query instruction to obtain the target data.
[0174] In the embodiment of the present application, the screening condition is the condition carried by the query instruction, and the query node uses the screening condition to screen the data in the node indicated by the query address to obtain the target data that meets the screening condition. For example, if the screening condition is data with a memory utilization rate greater than 20%, then the query node will screen out data with a memory utilization rate greater than 20% from the data in the node indicated by the query address as the target data.
[0175] 304. The query node determines a query result of the query instruction according to the target data.
[0176] In a possible implementation, the query node aggregates the target data to obtain an aggregated result, and uses the aggregated result as the query result of the query instruction.
[0177] In another possible implementation, the query node uses the target data as the query result of the query instruction.
[0178] In this implementation, the registration node determines the query address based on the addresses of at least two storage nodes, wherein the query address is the address of the node storing the query data, and the query data is the data that the query node needs to query. The registration node then sends the query address to the query node for the query node to query. When the query node receives the query instruction, it filters the data stored in the node indicated by the query address according to the query address and the filtering conditions in the query instruction to obtain the target data. The query node then determines the query result of the query instruction based on the target data, thereby realizing the query of the data in the distributed database.
[0179] As an optional implementation, the target write node includes a target queue for storing data that needs to be written to the target storage node, that is, the data in the target queue are all data that need to be written to the target storage node. The target queue includes a memory queue and a disk queue, wherein the data in the memory queue is stored in the memory of the target write node, and the data in the disk queue is stored in the disk of the target write node, that is, the data in the memory queue and the data in the disk queue are all data that need to be written to the target storage node.
[0180] In this implementation manner, the target write node stores the data to be stored in the target write node by executing the following steps:
[0181] 401. Determine a first data volume of the data in the memory queue.
[0182] In the embodiment of the present application, the first amount is the amount of data in the memory queue. In one possible implementation, the capacity of different data to be stored in the target storage node is the same, and the target write node can determine the first amount of data by determining the amount of data in the memory queue.
[0183] 402. The target writing node stores the data to be stored in the memory queue before the first data amount reaches a first threshold.
[0184] When the first data volume reaches the first threshold, it means that the first data volume is large. At this time, storing data in the memory queue may cause the reading speed and writing speed of the memory to decrease. Before the first data volume reaches the first threshold, it means that the first data volume is small. At this time, storing data in the memory queue has a low probability of causing the reading speed and writing speed of the memory to decrease. Therefore, before the first data volume reaches the first threshold, the target write node stores the data to be stored in the memory queue.
[0185] 403. After the first data volume reaches the first threshold, the target write node stores the data to be stored in the disk queue, and transfers the data in the memory queue to the disk queue.
[0186] The target write node stores the data to be stored in the disk queue and transfers the data in the memory queue to the disk queue, so that after the first data volume reaches the first threshold, the data to be stored in the target storage node is stored in the disk.
[0187] In a possible implementation, the target write node stores the storage data in the disk queue by executing the following steps: if the data volume of the data to be stored does not exceed the predetermined value, the data to be stored is stored as a file block in the disk queue. If the data volume of the data to be stored exceeds the predetermined value, the data to be stored is divided into r file blocks and stored in the disk queue, wherein r is an integer greater than 1, and the r file blocks include r-1 file blocks with a data volume of the predetermined value and 1 file block with a data volume not exceeding the predetermined value.
[0188] In this implementation, the storage unit of the disk queue is a file block, wherein the data amount of the file block is a predetermined value. Specifically, each time data of a predetermined value is written to the disk, the write offset used to write the data increases once, wherein the write offset represents the address of writing data to the disk queue. Therefore, when the data amount of the data to be stored does not exceed the predetermined value, the target write node stores the data to be stored as a file block to the disk queue. When the data amount of the data to be stored exceeds the predetermined value, the target write node divides the data to be stored into r file blocks, and then writes r file blocks to the disk queue in sequence. Specifically, after writing one of the r file blocks, the next file block is created in the disk queue, and the write offset is increased, and then one of the r file blocks is continued to be written to the newly created file block according to the increased write offset, until all r file blocks are written to the disk queue.
[0189] In this embodiment, after determining the first data amount of the data in the memory queue, the target write node stores the data to be stored in the memory queue before the first data amount reaches the first threshold, stores the data to be stored in the disk queue after the first data amount reaches the above-mentioned first threshold, and transfers the data in the memory queue to the disk queue. In this way, when the first data amount is small, the data to be stored is stored in the memory, thereby reducing the read and write overhead of the disk when the probability of causing the read speed and write speed of the memory to be reduced is low. When the first data amount is large, the data to be stored in the target storage node is stored in the disk, thereby reducing the utilization rate of the memory and reducing the probability of reducing the read speed and write speed of the memory.
[0190] As an optional implementation, in the case where the data to be stored is stored in the disk queue, the target write node writes the data to be stored in the target write node to the target storage node by performing the following steps:
[0191] 501. Taking a file block as a reading unit, n file blocks in the disk queue are read. During the process of reading the n file blocks, the target write node deletes the read file blocks from the disk queue.
[0192] In the case of using file blocks as the reading unit, the target write node reads one file block from the disk queue each time. After reading a file block, the read offset used for reading is increased once, and the read file block is deleted from the disk queue, where the read offset represents the address of reading data from the disk queue. Then the target write node continues to read the next file block in the disk queue until the read offset is the same as the write offset, and it is determined that all the data in the disk queue has been read.
[0193] 502. The data to be stored in the target write node is written into the target storage node by writing the n file blocks into the target storage node.
[0194] After reading n file blocks from the disk queue, the target write node writes the data to be stored in the target write node to the target storage node by writing the n file blocks to the target storage node.
[0195] In this implementation manner, the target write node reads n file blocks in the disk queue in units of file blocks, and during the reading process, deletes the read file blocks from the disk queue, thereby releasing the disk space in time.
[0196] Optionally, when the target write node has deleted all the data in the disk queue and receives a request to store new data, the target write node stores the new data in the memory queue, wherein the new data matches the index. In one possible implementation, when the write offset is the same as the read offset, the target write node determines that all the data in the disk queue has been deleted, and when receiving a request to store new data, stores the new data in the memory queue. This allows the data that needs to be stored in the target storage node to be stored in the memory again.
[0197] As an optional implementation manner, before executing step 301, the registration node further executes the following steps:
[0198] 601. The registration node receives a second data volume of the data in the target queue sent by the target write node.
[0199] In the case where there is data in the memory queue that needs to be stored in the target storage node, the target queue is the memory queue, and at this time, the second data amount is the data amount of the data in the memory queue. In the case where there is data in the disk queue that needs to be stored in the target storage node, the target queue is the disk queue, and at this time, the second data amount is the data amount of the data in the disk queue.
[0200] When receiving the second data volume, the registration node performs the following steps during the process of executing step 301:
[0201] 602. When the second data volume does not reach a second threshold, the registration node obtains the query address according to the address of the reference node and the address of the target storage node.
[0202] If the second data volume does not reach the second threshold, it means that the data to be stored in the target storage node is small, that is, the data to be stored in the target storage node is not backlogged. At this time, the registration node obtains the query address according to the address of the reference node and the address of the target storage node, and the query node queries the data according to the query address, which can improve the query success rate and query efficiency.
[0203] As an optional implementation, after receiving the second data volume, the registration node further performs the following steps: when the second data volume reaches a second threshold, the registration node determines that the target storage node is backlogged. When the second data volume does not reach the second threshold, the registration node determines that the target storage node is not backlogged.
[0204] In this implementation manner, the registration node performs the following steps during the execution of step 201: when the target storage node is already backlogged, the registration node obtains the query address according to the address of the reference node and the address of the replica storage node. When the target storage node changes from backlogged to unbacklogged, and the duration for which the target storage node remains unbacklogged reaches a third threshold, the registration node obtains the query address according to the address of the reference node and the address of the target storage node.
[0205] The registered node is overloaded, which means that there is a lot of data that needs to be stored in the target storage node. At this time, querying the target storage node will reduce the query success rate and query efficiency. Therefore, the registered node obtains the query address based on the address of the reference node and the address of the replica storage node, thereby switching the query object of the query node from the target storage node to the replica storage node of the target query node, thereby achieving automatic flow switching. In this way, the query node can query data based on the query address to improve the query success rate and query efficiency. Optionally, when the target storage node is overloaded, the registered node marks the target storage node as a problem node.
[0206] When the target storage node changes from being backlogged to being unbacklogged, and the time the target storage node remains unbacklogged reaches the third threshold, it means that the target storage node has stabilized to being unbacklogged. At this time, the registration node obtains the query address based on the address of the reference node and the address of the target storage node, thereby switching the query object of the query node from the replica storage node of the target query node to the target storage node, thereby achieving automatic flow switching. In this way, the query node queries data based on the query address, which can improve the query success rate and query efficiency. Optionally, the third threshold is 10 minutes.
[0207] To further illustrate the technical effect of the data processing method of the embodiment of the present application, when the target storage node is unavailable, storing the data to be stored in the target queue of the target write node, and storing the data in the target queue to the target storage node when the target storage node is available, the embodiment of the present application provides Figure 3a , Figure 3b , Figure 3c Three schematic diagrams. Specifically, Figure 3a A schematic diagram of storing the data to be stored in a storage node other than the target write node when the target storage node is unavailable is provided in an embodiment of the present application. Figure 3b A schematic diagram of storing data to be stored in a target queue of a target write node when a target storage node is unavailable is provided in an embodiment of the present application. Figure 3c A schematic diagram of storing data in a target queue of a target write node to a target storage node when the target storage node is available is provided in an embodiment of the present application.
[0208] exist Figure 3a , Figure 3b and Figure 3c In the example, storage node 2 is the target storage node, storage node 1 and storage node 3 are storage nodes other than the target storage node, data 1 is the data that needs to be stored in storage node 1, and data 3 is the data that needs to be stored in storage node 3. Figure 3a As shown, storage node 2 is unavailable, that is, the target storage node is unavailable. At this time, the target write node cannot store the data to be stored in the target storage node, and then divides the data to be stored into two parts, and then stores them in storage node 1 and storage node 3 respectively. In this way, the data stored by the target write node to storage node 1 is: data 1+0.5*data to be stored, and the data stored by the target write node to storage node 3 is: data 3+0.5*data to be stored. As mentioned above, since neither storage node 1 nor storage node 3 has an index that matches the data to be stored, the target write node needs to create an index that matches the data to be stored in storage node 1 and storage node 3 respectively.
[0209] exist Figure 3b and Figure 3c In the example, the target write node includes queue 1, target queue and queue 3, wherein queue 1 is used to store data that needs to be stored in storage node 1, and queue 3 is used to store data that needs to be stored in storage node 3. Figure 3b and Figure 3c As shown, both storage node 1 and storage node 3 are available, so the target write node can store the data that needs to be stored in storage node 1 in storage node 1, and store the data that needs to be stored in storage node 3 in storage node 3, without having to store the data that needs to be stored in storage node 1 in queue 1, nor the data that needs to be stored in storage node 3 in queue 3. Figure 3b and Figure 3c There is no data in queue 1 and queue 3.
[0210] like Figure 3b As shown, in the embodiment of the present application, when the target storage node is unavailable, the target write node does not store the data to be stored in storage node 1, nor does it store the data to be stored in storage node 3, but stores the data to be stored in the target queue. At this time, for the target queue, data is stored but not read. Therefore, Figure 3b As shown in , there is a dashed slash in the target queue. Figure 3c As shown in , when the target storage node is restored to be available, the target write node consumes the data in the target queue and stores the data to be stored in the target queue to the target storage node. At this time, the target queue can read data, so Figure 3cAs shown, there is a solid slash in the target queue. In this way, the data to be stored can be stored in the target storage node without creating a new index matching the data to be stored in the storage nodes other than the target storage node, thereby reducing the resource overhead of the storage cluster.
[0211] As an optional implementation manner, the number of write nodes is at least two, and the data processing method further includes the following steps:
[0212] 701. When the storage cluster obtains at least three storage nodes by adding at least one storage node, the registration node determines an update plan for at least two of the write nodes according to the number of the added storage nodes and the number of the write nodes.
[0213] In an embodiment of the present application, the storage cluster is expanded by adding at least one storage node to obtain at least three storage nodes (ie, the sharding scaling described above), and the expanded storage cluster includes at least three storage nodes.
[0214] The update plan is used to update the addresses of the storage nodes of the storage cluster obtained by at least two write nodes from the registration node. Since the write node determines the storage node according to the addresses of the storage nodes of the storage cluster obtained, by updating the addresses of the storage nodes of the storage cluster obtained by the write node, the write node can be informed that the storage cluster has obtained at least three storage nodes by adding at least one storage node.
[0215] In the update plan, at least two write nodes are updated through at least two update phases, and the order of updates in any two update phases is different, that is, the execution time of different update phases is different, and the write nodes required to be updated in any two update phases are different. For example, the at least two write nodes include a target write node and a write node a, and the at least two update phases include update phase 1 and update phase 2, wherein the write nodes required to be updated in update phase 1 include the target write node, and the write nodes required to be updated in update phase 2 include write node a. Update phase 2 is executed when update phase 1 is completed, that is, after the addresses of at least three storage nodes have been sent to the target write node, the addresses of at least three storage nodes are sent to write node a.
[0216] In one possible implementation, when the registration node determines that the number of write nodes that need to be updated in each update stage is s, the registration node determines the number of update stages and then determines the update plan. For example, the storage cluster includes a total of 5 write nodes, s is 1, then the number of update stages is 5, and then it can be determined that the number of write nodes that need to be updated in one update stage is 1. Then, the order of each update stage is randomly determined to obtain the update plan.
[0217] 702. When the registration node determines, according to the update plan, that the update phase of the current update includes a target write node, the registration node sends the addresses of the at least three storage nodes to the target write node.
[0218] The registered node can determine the order of each update stage according to the update plan, and then can update each update stage in sequence according to the order of each update stage. When it is determined that the update stage of the current update includes the target write node, the target write node is updated by sending the addresses of at least three storage nodes to the target write node. In one possible implementation, each update stage in the update plan includes the identifier of the write node to be updated. After receiving the identifier reported by the target write node, the registered node determines that the update stage of the current update includes the target write node when it is determined that the update stage of the current update includes the identifier of the target write node, and then sends the addresses of at least three storage nodes to the target write node.
[0219] In this implementation, the registration node can implement grayscale configuration by executing steps 701 to 702. Specifically, when the storage cluster obtains at least three storage nodes by adding at least one of the storage nodes, the registration node determines the update plan of at least two write nodes according to the number of write nodes. Then, when it is determined that the update phase of the current update includes the target write node according to the update plan, the addresses of at least three storage nodes are sent to the target write node. In this way, the addresses of at least three storage nodes can be sent to at least two write nodes in stages.
[0220] Since the at least three storage nodes include the newly added storage node, and writing data to the newly added storage node requires creating a new index in the newly added storage node, sending the addresses of at least three storage nodes to the write node so that the write node writes data to the at least three storage nodes will increase the resources consumed by the storage cluster. Therefore, by sending the addresses of at least three storage nodes to at least two write nodes in stages, the maximum value of the resources consumed by the storage cluster can be reduced, thereby reducing the probability of avalanche in the storage cluster and improving the stability of the distributed cluster.
[0221] As an optional implementation, the data processing method further includes:
[0222] 801. The registration node determines the storage cluster according to the name of the storage cluster.
[0223] 802. The registration node determines addresses of the at least two storage nodes according to the at least two storage nodes in the storage cluster.
[0224] In one possible implementation, the registration node determines the names of at least two storage nodes in the storage cluster. The registration node calculates the addresses of at least two storage nodes based on the names of the at least two storage nodes. Since the probability of the name of the storage node changing is low, after determining the name of the storage node, the registration node calculates the address of the storage node based on the name of the storage node, which can reduce the probability of the address of the storage node changing. The write node writes data to the storage node based on the address of the storage node. Therefore, while reducing the probability of the address of the storage node changing, the success rate of the write node writing data to the storage node can be increased. Optionally, the registration node calculates the addresses of at least two storage nodes based on the names of the at least two storage nodes through a hash algorithm. At this time, the address of the storage node is the address on the hash ring.
[0225] Optionally, the registration node implements step 801 and step 802 through service discovery.
[0226] Optionally, the registration node determines addresses of replica storage nodes of at least two storage nodes through service discovery.
[0227] As an optional implementation, at least two storage nodes include a reference storage node different from the target storage node, and the target write node stores reference data, wherein the reference data is data that needs to be written to the reference storage node. The target write node acquires the reference data earlier than the target write node acquires the data to be stored.
[0228] The target write node writes the data to be stored in the target write node to the target storage node by performing the following steps:
[0229] 901. When the reference storage node is available, the target writing node calls a writing thread to write the reference data into the reference storage node, wherein the writing thread is a thread for writing data.
[0230] 902. After writing the reference data into the reference storage node, the target writing node writes the data to be stored in the target writing node into the target storage node.
[0231] 903. When the reference storage node is unavailable, the target write node calls the write thread to write the data to be stored in the target write node into the target storage node.
[0232] In this implementation, the target write node acquires the reference data earlier than the target write node acquires the data to be stored. Therefore, when the reference storage node is available, the target write node calls the write thread to write the reference data to the reference storage node, and after writing the reference data to the reference storage node, writes the data to be stored in the target write node to the target storage node. When the reference storage node is unavailable, the write thread no longer waits for the reference data to be written to the reference storage node, but calls the write thread to write the data to be stored in the target write node to the target storage node, thereby realizing asynchronous writing of data that needs to be written to different storage nodes, thereby improving the efficiency of writing data.
[0233] As an optional implementation, after the target write node determines the target storage node having an identifier matching the identifier of the data to be stored from at least two storage nodes, it further determines that the target storage node is unavailable by performing the following steps:
[0234] 1001. The target write node sends a write request to the target storage node.
[0235] In the embodiment of the present application, the write request is a request to write data to the target storage node.
[0236] 1002. When the target storage node does not respond to the write request, the target write node determines that the target storage node is unavailable.
[0237] The target storage node does not respond to the write request, which means that the target write node cannot write data to the target storage node, and thus it can be determined that the target storage node is unavailable.
[0238] Optionally, when the target storage node does not respond to the write request, the target write node sends a write request to the target storage node again, and when the number of times the target storage node does not respond reaches a fourth threshold, determines that the target storage node is unavailable.
[0239] Those skilled in the art will appreciate that, in the above method of specific implementation, the order in which the steps are written does not imply a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of the steps should be determined by their functions and possible internal logic.
[0240] See also Figure 4 , Figure 4A schematic diagram of the architecture of a data processing system provided in an embodiment of the present application, wherein the data processing system 1 is used to run a distributed database, the data processing system 1 includes a storage cluster 11, the storage cluster 11 includes at least one write node 111 and at least two storage nodes 112, the write node is a node for writing data, the storage node is a node for storing data to be stored, the data to be stored is data that needs to be stored in the distributed database, and the at least one write node 111 includes a target write node 1111;
[0241] When receiving a request to store the data to be stored, the target write node 1111 determines a target storage node 1121 that matches the data to be stored from the at least two storage nodes 112, and the target storage node 1121 has an index that matches the data to be stored;
[0242] When the target writing node 1111 determines that the target storage node 1121 is unavailable, the target writing node 1111 stores the data to be stored in the target writing node 1111;
[0243] When determining that the target storage node 1121 is available, the target write node 1111 writes the to-be-stored data in the target write node 1111 into the target storage node 1121 .
[0244] In combination with any embodiment of the present application, the data processing system 1 further includes a query node 13 and a registration node 14, the query node 13 is a node for querying the data stored in the distributed database, and the registration node 14 includes the addresses of the at least two storage nodes 112;
[0245] The registration node 14 determines a query address according to the addresses of the at least two storage nodes 112, wherein the query address is an address of a node storing query data, and the query data is data that the query node 13 needs to query;
[0246] The registration node 14 sends the query address to the query node 13;
[0247] When receiving the query instruction, the query node 13 filters the data stored in the node indicated by the query address according to the query address and the filtering condition in the query instruction to obtain the target data;
[0248] The query node 13 determines the query result of the query instruction according to the target data.
[0249] In combination with any implementation manner of the present application, the query node 13 obtains an aggregation result by aggregating the target data;
[0250] The query node 13 uses the aggregated result as the query result of the query instruction.
[0251] In combination with any embodiment of the present application, the nodes other than the target storage node 1121 among the at least two storage nodes 112 are reference nodes;
[0252] When determining that the target storage node 1121 is available, the target write node 1111 sends a message that the target storage node 1121 is available to the registration node 14;
[0253] When receiving the message that the target storage node 1121 is available, the registration node 14 obtains the query address according to the address of the reference node and the address of the target storage node 1121 .
[0254] In combination with any embodiment of the present application, the data processing system 1 further includes a replica cluster 12, the replica cluster 12 is a replica of the storage cluster 11, the replica cluster 12 includes a replica storage node 121 of the target storage node 1121, and the registration node 14 includes an address of the replica storage node 121;
[0255] When the target write node 1111 determines that the target storage node 1121 is unavailable, the target write node 1111 sends a message to the registration node 14 that the target storage node 1121 is unavailable;
[0256] When the registration node 14 receives the message that the target storage node 1121 is unavailable, the registration node 14 obtains the query address according to the address of the reference node and the address of the replica storage node 121 .
[0257] In combination with any embodiment of the present application, the target write node 1111 includes a target queue for storing data that needs to be written to the target storage node 1121, the target queue includes a memory queue, and the data in the memory queue is stored in the memory of the target write node 1111;
[0258] The target write node 1111 determines a first data amount of the data in the memory queue;
[0259] The target write node 1111 stores the data to be stored in the memory queue before the first data amount reaches a first threshold.
[0260] In combination with any implementation manner of the present application, the target queue includes a disk queue, and the data in the disk queue is stored on the disk of the target write node 1111;
[0261] After the first data volume reaches the first threshold, the target write node 1111 stores the data to be stored in the disk queue, and transfers the data in the memory queue to the disk queue.
[0262] In combination with any implementation manner of the present application, the target write node 1111 stores the data to be stored as a file block to the disk queue when the data amount of the data to be stored does not exceed a predetermined value;
[0263] When the amount of data to be stored exceeds the predetermined value, the target write node 1111 divides the data to be stored into r file blocks and stores them in the disk queue, where r is an integer greater than 1, and the r file blocks include r-1 file blocks with a data amount of the predetermined value and 1 file block with a data amount not exceeding the predetermined value.
[0264] In combination with any implementation manner of the present application, the target write node 1111 reads the n file blocks in the disk queue using the file block as a reading unit, and in the process of reading the n file blocks, the target write node 1111 deletes the read file blocks from the disk queue;
[0265] The target write node 1111 writes the data to be stored in the target write node 1111 into the target storage node 1121 by writing the n file blocks into the target storage node 1121 .
[0266] In combination with any embodiment of the present application, when all data in the disk queue has been deleted and a request to store new data is received, the target write node 1111 stores the new data in the memory queue, and the new data matches the index.
[0267] In combination with any embodiment of the present application, the nodes other than the target storage node 1121 among the at least two storage nodes 112 are reference nodes;
[0268] The registration node 14 receives a second data volume of the data in the target queue sent by the target write node 1111;
[0269] When the second data volume does not reach the second threshold, the registration node 14 obtains the query address according to the address of the reference node and the address of the target storage node 1121 .
[0270] In combination with any embodiment of the present application, the data processing system 1 further includes a replica cluster 12, the replica cluster 12 is a replica of the storage cluster 11, the replica cluster 12 includes a replica storage node 121 of the target storage node 1121, and the registration node 14 further includes an address of the replica storage node 121;
[0271] The registration node 14 determines that the target storage node 1121 is backlogged when the second data amount reaches a second threshold;
[0272] The registration node 14 determines that the target storage node 1121 is not backlogged when the second data amount does not reach the second threshold;
[0273] When the target storage node 1121 is already backlogged, the registration node 14 obtains the query address according to the address of the reference node and the address of the replica storage node 121;
[0274] When the target storage node 1121 changes from being backlogged to being unbacklogged and the time duration for which the target storage node 1121 remains unbacklogged reaches a third threshold, the registration node 14 obtains the query address according to the address of the reference node and the address of the target storage node 1121.
[0275] In combination with any embodiment of the present application, the number of the write nodes is at least two, and when the storage cluster 11 obtains at least three storage nodes by adding at least one of the storage nodes, the registration node 14 determines an update plan for at least two of the write nodes according to the number of the write nodes, and the update plan is used to update the addresses of the storage nodes of the storage cluster 11 obtained by at least two of the write nodes from the registration node 14;
[0276] In the update plan, at least two of the write nodes are updated through at least two update phases, the update order of any two update phases is different, and the write nodes to be updated in any two update phases are different;
[0277] When the registration node 14 determines, according to the update plan, that the update phase of the current update includes the target write node 1111 , the registration node 14 sends the addresses of the at least three storage nodes to the target write node 1111 .
[0278] In combination with any implementation manner of the present application, the registration node 14 determines the storage cluster 11 according to the name of the storage cluster 11;
[0279] The registration node 14 determines addresses of the at least two storage nodes 112 according to the at least two storage nodes 112 in the storage cluster 11 .
[0280] In combination with any implementation manner of the present application, the registration node 14 determines the names of the at least two storage nodes 112 in the storage cluster 11;
[0281] The registration node 14 calculates the addresses of the at least two storage nodes 112 based on the names of the at least two storage nodes 112 .
[0282] In combination with any embodiment of the present application, the at least two storage nodes 112 include a reference storage node 1122 different from the target storage node 1121, the target write node 1111 stores reference data, the reference data is data that needs to be written to the reference storage node 1122, and the time when the target write node 1111 acquires the reference data is earlier than the time when the target write node 1111 acquires the data to be stored;
[0283] The target write node 1111 calls a write thread to write the reference data into the reference storage node 1122 when the reference storage node 1122 is available, and the write thread is a thread for writing data;
[0284] After writing the reference data into the reference storage node 1122, the target writing node 1111 writes the data to be stored in the target writing node 1111 into the target storage node 1121;
[0285] When the reference storage node 1122 is unavailable, the target write node 1111 calls the write thread to write the to-be-stored data in the target write node 1111 into the target storage node 1121 .
[0286] In combination with any embodiment of the present application, the target write node 1111 determines a node having an identifier matching the identifier of the data to be stored from the at least two storage nodes 112 as the target storage node 1121 .
[0287] In combination with any implementation manner of the present application, the target write node 1111 sends a write request to the target storage node 1121;
[0288] The target write node 1111 determines that the target storage node 1121 is unavailable when the target storage node 1121 does not respond to the write request.
[0289] In combination with any implementation manner of the present application, the data to be stored is data with a time tag.
[0290] In the embodiment of the present application, when the target write node 1111 receives a request to store the data to be stored, it determines the target storage node 1121 having an index matching the data to be stored from at least two storage nodes 112. When the target write node 1111 determines that the target storage node 1121 is unavailable, the target write node 1111 first stores the data to be stored locally in the target write node 1111, and then writes the data to be stored in the target write node 1111 to the target storage node 1121 when it is determined that the target storage node 1121 is available.
[0291] Since there is no index matching the data to be stored in the storage nodes other than the target storage node 1121 in at least two storage nodes 112, compared with writing the data to be stored in the storage nodes other than the target storage node 1121 when it is determined that the target storage node 1121 is unavailable, the embodiment of the present application does not need to establish an index matching the data to be stored in the storage nodes other than the target storage node 1121. This can reduce the resource utilization of the storage cluster, and further reduce the probability of avalanche in the storage cluster, thereby improving the stability of the distributed database.
[0292] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0293] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system and unit described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here. Those skilled in the art can also clearly understand that the description of each embodiment of the present application has its own focus. For the convenience and brevity of description, the same or similar parts may not be repeated in different embodiments. Therefore, for parts not described or not described in detail in a certain embodiment, refer to the records of other embodiments.
[0294] In the several embodiments provided in this application, it should be understood that the disclosed systems and methods can be implemented in other ways. In addition, the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interface, device or unit, which can be electrical, mechanical or other forms.
[0295] The nodes described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical nodes, that is, they may be located in one place or distributed on multiple network nodes. Some or all of the nodes may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0296] In addition, each functional node in each embodiment of the present application may be integrated into one processing node, or each node may exist physically separately, or two or more nodes may be integrated into one node.
[0297] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted through the computer-readable storage medium. The computer instructions can be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (digital subscriber line, DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium may be a magnetic medium (eg, a floppy disk, a hard disk, a magnetic tape), an optical medium (eg, a digital versatile disc (DVD)), or a semiconductor medium (eg, a solid state disk (SSD)).
[0298] A person skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by a computer program to instruct the relevant hardware, and the program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the above-mentioned method embodiments. The aforementioned storage medium includes: a read-only memory (ROM) or a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.
Claims
1. A data processing method, characterized in that: The method is used to process data in a distributed database, the distributed database includes a storage cluster, the storage cluster includes at least one write node and at least two storage nodes, the write node is a node for writing data, the storage node is a node for storing data to be stored, the data to be stored is data that needs to be stored in the distributed database, the at least one write node includes a target write node, and the method includes: When receiving a request to store the data to be stored, the target write node determines a target storage node that matches the data to be stored from the at least two storage nodes, wherein the target storage node has an index that matches the data to be stored; The at least two storage nodes include a reference storage node different from the target storage node, the target write node stores reference data, the reference data is data that needs to be written to the reference storage node, and the time when the target write node obtains the reference data is earlier than the time when the target write node obtains the data to be stored; When the target writing node determines that the target storage node is unavailable, the target writing node stores the data to be stored in the target writing node; The target write node writes the data to be stored in the target write node to the target storage node when it is determined that the target storage node is available; the writing of the data to be stored in the target write node to the target storage node includes: when the reference storage node is available, the target write node calls a write thread to write the reference data to the reference storage node, the write thread being a thread for writing data; after writing the reference data to the reference storage node, the target write node writes the data to be stored in the target write node to the target storage node; when the reference storage node is unavailable, the target write node calls the write thread to write the data to be stored in the target write node to the target storage node.
2. The method according to claim 1, characterized in that The distributed database further includes a query node and a registration node, the query node is a node for querying data stored in the distributed database, the registration node includes addresses of the at least two storage nodes, and the method further includes: The registration node determines a query address according to the addresses of the at least two storage nodes, wherein the query address is an address of a node storing query data, and the query data is data required to be queried by the query node; The registration node sends the query address to the query node; When receiving the query instruction, the query node filters the data stored in the node indicated by the query address according to the query address and the filtering condition in the query instruction to obtain the target data; The query node determines a query result of the query instruction according to the target data.
3. The method according to claim 2, characterized in that The query node determines the query result of the query instruction according to the target data, including: The query node obtains an aggregation result by aggregating the target data; The query node uses the aggregated result as the query result of the query instruction.
4. The method according to claim 2 or 3, characterized in that: The nodes other than the target storage node among the at least two storage nodes are reference nodes; Before the registration node determines the query address according to the addresses of the at least two storage nodes, the method further includes: When the target writing node determines that the target storage node is available, the target writing node sends a message that the target storage node is available to the registration node; The registration node determines the query address according to the addresses of the at least two storage nodes, including: When the registration node receives the message that the target storage node is available, the registration node obtains the query address according to the address of the reference node and the address of the target storage node.
5. The method according to claim 2 or 3, characterized in that: The distributed database further includes a replica cluster, the replica cluster is a replica of the storage cluster, the replica cluster includes a replica storage node of the target storage node, the registration node includes an address of the replica storage node, and the node other than the target storage node among the at least two storage nodes is a reference node; Before the registration node determines the query address according to the addresses of the at least two storage nodes, the method further includes: When the target writing node determines that the target storage node is unavailable, the target writing node sends a message that the target storage node is unavailable to the registration node; The registration node determines the query address according to the addresses of the at least two storage nodes, including: When the registration node receives the message that the target storage node is unavailable, the registration node obtains the query address according to the address of the reference node and the address of the replica storage node.
6. The method according to claim 2 or 3, characterized in that: The target write node includes a target queue for storing data that needs to be written into the target storage node, the target queue includes a memory queue, and the data in the memory queue is stored in the memory of the target write node; The storing the data to be stored in the target write node includes: Determining a first amount of data in the memory queue; Before the first data amount reaches a first threshold, the data to be stored is stored in the memory queue.
7. The method according to claim 6, characterized in that The target queue includes a disk queue, and the data in the disk queue is stored on the disk of the target write node; After determining a first amount of data in the memory queue, the method further includes: After the first data amount reaches the first threshold, the target write node stores the data to be stored in the disk queue, and transfers the data in the memory queue to the disk queue.
8. The method according to claim 7, characterized in that The storing the data to be stored in the disk queue includes: When the amount of the data to be stored does not exceed a predetermined value, storing the data to be stored as a file block in the disk queue; When the amount of data to be stored exceeds the predetermined value, the data to be stored is divided into r file blocks and stored in the disk queue, where r is an integer greater than 1, and the r file blocks include r-1 file blocks whose data amount is the predetermined value and 1 file block whose data amount does not exceed the predetermined value.
9. The method according to claim 8, characterized in that In a case where the data to be stored is stored in the disk queue, writing the data to be stored in the target write node into the target storage node includes: Taking a file block as a reading unit, n file blocks in the disk queue are read, and in the process of reading the n file blocks, the target write node deletes the read file blocks from the disk queue; By writing the n file blocks into the target storage node, the data to be stored in the target writing node is written into the target storage node.
10. The method according to claim 9, characterized in that The method further comprises: When all data in the disk queue has been deleted and a request to store new data is received, the target write node stores the new data in the memory queue, and the new data matches the index.
11. The method according to claim 6, characterized in that The nodes other than the target storage node among the at least two storage nodes are reference nodes; Before the registration node determines the query address according to the addresses of the at least two storage nodes, the method further includes: The registration node receives a second data volume of the data in the target queue sent by the target write node; The registration node determines the query address according to the addresses of the at least two storage nodes, including: When the second data volume does not reach a second threshold, the registration node obtains the query address according to the address of the reference node and the address of the target storage node.
12. The method according to claim 11, characterized in that The distributed database further includes a replica cluster, which is a replica of the storage cluster, the replica cluster includes a replica storage node of the target storage node, and the registration node further includes an address of the replica storage node; After the registration node receives the second data volume of the data in the target queue sent by the target write node, the method further includes: The registration node determines that the target storage node has a backlog when the second data amount reaches a second threshold; The registration node determines that the target storage node is not backlogged when the second data amount does not reach the second threshold; The registration node determines the query address according to the addresses of the at least two storage nodes, including: When the target storage node is already backlogged, the registration node obtains the query address according to the address of the reference node and the address of the replica storage node; When the target storage node changes from being backlogged to being unbacklogged and the time duration for which the target storage node remains unbacklogged reaches a third threshold, the registration node obtains the query address according to the address of the reference node and the address of the target storage node.
13. The method according to claim 2 or 3, characterized in that: The number of the write nodes is at least two, and the method further comprises: The registration node determines, when the storage cluster obtains at least three storage nodes by adding at least one of the storage nodes, an update plan for at least two of the write nodes according to the number of the write nodes, wherein the update plan is used to update addresses of the storage nodes of the storage cluster obtained by at least two of the write nodes from the registration node; In the update plan, at least two of the write nodes are updated through at least two update phases, the update order of any two update phases is different, and the write nodes to be updated in any two update phases are different; When the registration node determines, according to the update plan, that the update phase of the current update includes the target write node, the registration node sends the addresses of the at least three storage nodes to the target write node.
14. The method according to claim 2 or 3, characterized in that: The method further comprises: The registration node determines the storage cluster according to the name of the storage cluster; The registration node determines addresses of the at least two storage nodes according to the at least two storage nodes in the storage cluster.
15. The method according to claim 14, characterized in that The registration node determines addresses of the at least two storage nodes according to the at least two storage nodes in the storage cluster, including: The registration node determines the names of the at least two storage nodes in the storage cluster; The registration node calculates the addresses of the at least two storage nodes based on the names of the at least two storage nodes.
16. The method according to any one of claims 1 to 3, characterized in that: The determining, from the at least two storage nodes, a target storage node matching the data to be stored comprises: A node having an identifier matching the identifier of the data to be stored is determined from the at least two storage nodes as the target storage node.
17. The method according to any one of claims 1 to 3, characterized in that: After determining, from the at least two storage nodes, a target storage node having an identifier matching the identifier of the data to be stored, the method further comprises: The target write node sends a write request to the target storage node; The target write node determines that the target storage node is unavailable if the target storage node does not respond to the write request.
18. The method according to any one of claims 1 to 3, characterized in that The data to be stored is data with a time tag.
19. A data processing system, characterized in that: The data processing system is used to run a distributed database, the data processing system includes a storage cluster, the storage cluster includes at least one write node and at least two storage nodes, the write node is a node for writing data, the storage node is a node for storing data to be stored, the data to be stored is data that needs to be stored in the distributed database, and the at least one write node includes a target write node; When receiving a request to store the data to be stored, the target write node determines a target storage node that matches the data to be stored from the at least two storage nodes, wherein the target storage node has an index that matches the data to be stored; The at least two storage nodes include a reference storage node different from the target storage node, the target write node stores reference data, the reference data is data that needs to be written to the reference storage node, and the time when the target write node obtains the reference data is earlier than the time when the target write node obtains the data to be stored; When the target writing node determines that the target storage node is unavailable, the target writing node stores the data to be stored in the target writing node; When the target writing node determines that the target storage node is available, the target writing node writes the data to be stored in the target writing node into the target storage node; The step of writing the data to be stored in the target write node into the target storage node comprises: the target write node calls a write thread to write the reference data into the reference storage node when the reference storage node is available, the write thread being a thread for writing data; after the target write node writes the reference data into the reference storage node, the target write node writes the data to be stored in the target write node into the target storage node; When the reference storage node is unavailable, the target write node calls the write thread to write the to-be-stored data in the target write node into the target storage node.
20. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program includes program instructions. When the program instructions are executed by a processor, the processor is caused to execute the method according to any one of claims 1 to 18.
21. A computer program product, characterized in that The computer program product comprises a computer program or instructions; when the computer program or instructions are run on a computer, the computer is caused to execute the method according to any one of claims 1 to 18.
