Node communication method, device and equipment based on distributed database cluster
By allocating shared memory to the data redistribution operator of the distributed database cluster and using auxiliary processes for data interaction, the problem of excessive resource consumption caused by data redistribution is solved, and the system performance and query efficiency are improved.
Patent Information
- Application Number
- CN202510937437.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-08
- Publication Date
- 2025-09-05
- Estimated Expiration
- 2045-07-08
AI Technical Summary
In a distributed database, data redistribution operations lead to the consumption of a large number of processes and network connections, resulting in excessive resource usage and affecting system performance and reliability.
Shared memory is allocated for the data redistribution operator, and data is exchanged between nodes through auxiliary processes, reducing new processes and network connections and optimizing resource usage.
It reduces system resource consumption, improves query concurrency and system service efficiency, and ensures the correctness of query results.
Smart Images

Figure CN120455517B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of distributed database technology, and in particular to a node communication method, apparatus and device based on a distributed database cluster. Background Art
[0002] As data storage needs continue to increase, traditional standalone databases often struggle to meet user performance and capacity requirements. Therefore, database systems have adopted a distributed architecture to improve scalability and reliability. Distributed databases distribute data across different data nodes based on distribution keys.
[0003] Traditionally, when two or more tables on a data node are joined, and at least one table uses a non-distribution key, data is redistributed across the data nodes based on the non-distribution key. Data redistribution involves redistributing the data from one or more tables to each node based on the distribution key in the optimal plan when performing distributed computations on multiple tables in a distributed database.
[0004] However, if there are many redistributed operators in the SQL query, when redistributing the data, each operator in the execution plan will create a new process and establish a network connection with other data nodes for data exchange, resulting in a large number of multi-layer process connections and network connection consumption. Therefore, data redistribution consumes a lot of resources. Summary of the Invention
[0005] Based on this, it is necessary to provide a node communication method, device, computer equipment, computer-readable storage medium and computer program product based on a distributed database cluster that can reduce resource consumption in order to address the above technical problems.
[0006] In one aspect, the present application provides a node communication method based on a distributed database cluster, comprising:
[0007] In a case where it is determined to generate a data redistribution operator, a shared memory is allocated to the data redistribution operator, sending data to be sent to the first other node is determined according to the data redistribution operator, and the sending data is written to a sending partition corresponding to the first other node in the shared memory;
[0008] Generate a sending record according to the node identifier of the first other node, the operator identifier of the data redistribution operator, and the partition identifier of the sending partition, and add the sending record to a routing table corresponding to the current auxiliary process in the current node;
[0009] generating a reception record according to the node identifier of the first other node and the operator identifier, and adding the reception record to a reception queue corresponding to the current auxiliary process;
[0010] During processing of the current sending record in the routing table by the current auxiliary process, determining a target sending partition corresponding to the partition identifier in the current sending record, reading data in the target sending partition to obtain a first data packet, and sending a first message to other nodes represented by the node identifier in the current sending record, where the first message carries the first data packet;
[0011] receiving a second message sent by a second other node, where the second message carries the operator identifier, the node identifier of the second other node, and a second data packet;
[0012] According to the node identifier of the second other node and the operator identifier, the corresponding target receiving record is determined from the receiving queue, and the second data packet is written into the target receiving record. When the current auxiliary process processes the current receiving record in the receiving queue, the corresponding target receiving partition is determined from the shared memory, and the received data in the current receiving record is written into the target receiving partition.
[0013] On the other hand, the present application also provides a node communication device based on a distributed database cluster, comprising:
[0014] a shared memory management module, configured to, when determining to generate a data redistribution operator, allocate shared memory to the data redistribution operator, determine, based on the data redistribution operator, send data to be sent to the first other node, and write the send data into a send partition corresponding to the first other node in the shared memory;
[0015] a sending record processing module, configured to generate a sending record according to the node identifier of the first other node, the operator identifier of the data redistribution operator, and the partition identifier of the sending partition, and add the sending record to a routing table corresponding to the current auxiliary process in the current node;
[0016] a reception record processing module, configured to generate a reception record according to the node identifier of the first other node and the operator identifier, and add the reception record to a reception queue corresponding to the current auxiliary process;
[0017] a data sending module, configured to, during the process of the current auxiliary process processing the current sending record in the routing table, determine a target sending partition corresponding to the partition identifier in the current sending record, read data in the target sending partition to obtain a first data packet, and send a first message to other nodes represented by the node identifier in the current sending record, where the first message carries the first data packet;
[0018] a data receiving module, configured to receive a second message sent by a second other node, where the second message carries the operator identifier, the node identifier of the second other node, and a second data packet;
[0019] A data processing module is used to determine the corresponding target receiving record from the receiving queue based on the node identifier of the second other node and the operator identifier, write the second data packet into the target receiving record, and when the current auxiliary process processes the current receiving record in the receiving queue, determine the corresponding target receiving partition from the shared memory and write the received data in the current receiving record into the target receiving partition.
[0020] On the other hand, the present application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps in the above-mentioned node communication method based on a distributed database cluster when executing the computer program.
[0021] On the other hand, the present application also provides a computer-readable storage medium having a computer program stored thereon, which implements the steps in the above-mentioned node communication method based on a distributed database cluster when executed by a processor.
[0022] On the other hand, the present application also provides a computer program product, including a computer program, which implements the steps in the above-mentioned node communication method based on a distributed database cluster when executed by a processor.
[0023] The above-mentioned node communication method, device, computer equipment, computer-readable storage medium and computer program product based on a distributed database cluster, when determining to generate a data redistribution operator, allocates shared memory for the data redistribution operator, determines the sending data to be sent to the first other node according to the data redistribution operator, writes the sending data to the sending partition corresponding to the first other node in the shared memory, generates a sending record according to the node identifier of the first other node, the operator identifier of the data redistribution operator and the partition identifier of the sending partition, adds the sending record to the routing table corresponding to the current auxiliary process in the current node, generates a receiving record according to the node identifier and operator identifier of the first other node, adds the receiving record to the receiving queue corresponding to the current auxiliary process, and During the process of processing the current sending record in the routing table, the process determines the target sending partition corresponding to the partition identifier in the current sending record, reads the data in the target sending partition to obtain a first data packet, sends a first message to the other node represented by the node identifier in the current sending record, the first message carries the first data packet, receives a second message sent by the second other node, the second message carries the operator identifier, the node identifier of the second other node, and the second data packet, determines the corresponding target receiving record from the receiving queue based on the node identifier and operator identifier of the second other node, writes the second data packet to the target receiving record, and when the current auxiliary process processes the current receiving record in the receiving queue, determines the corresponding target receiving partition from the shared memory, and writes the received data in the current receiving record to the target receiving partition. Thus, each time the original node encounters a data redistribution operator, a new process is created and a network connection is established with other nodes, optimizing the process so that each node has a background auxiliary process, and data is redistributed with other nodes through the auxiliary process, thereby reducing the occupation of system resources. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the following briefly introduces the drawings required for use in the embodiments of the present application or related technical descriptions. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying any creative work.
[0025] Figure 1 A diagram illustrating an application environment of a node communication method based on a distributed database cluster in some embodiments;
[0026] Figure 2 is a flowchart of a node communication method based on a distributed database cluster in some embodiments;
[0027] Figure 3 is a schematic diagram of a node communication method based on a distributed database cluster in some embodiments;
[0028] Figure 4 A schematic diagram of the working principle of sending threads in some embodiments;
[0029] Figure 5 A schematic diagram of the working principle of a receiving thread in some embodiments;
[0030] Figure 6 A schematic diagram of the working principle of the cleaning thread in some embodiments;
[0031] Figure 7 is a schematic diagram of a node communication method based on a distributed database cluster in some other embodiments;
[0032] Figure 8 is a structural block diagram of a node communication device based on a distributed database cluster in some embodiments;
[0033] Figure 9 is a diagram of the internal structure of a computer device in some embodiments;
[0034] Figure 10 1 is a diagram of the internal structure of a computer device in some other embodiments. DETAILED DESCRIPTION
[0035] In order to make the purpose, technical solutions and advantages of this application more clear, the following further describes this application in detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain this application and are not intended to limit this application.
[0036] The node communication method based on distributed database cluster provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown, the application environment includes a request node 102, a coordination node 104 and a distributed database cluster 106. The distributed database cluster 106 includes multiple data nodes. Figure 1 In the example above, data nodes 1 to 3 are included. In practice, the distributed database cluster 106 may include fewer or more data nodes. In the following, data nodes are referred to as nodes for short.
[0037] Specifically, the requesting node 102 sends a request corresponding to a table join query operation to the coordinating node 104. When at least one data table in the table join query operation uses a non-distribution key for a join operation, the coordinating node 104 generates a data redistribution operator for each data table in the at least one data table, and executes the node communication method based on the distributed database cluster provided in the embodiment of the present application for each data redistribution operator.
[0038] Requesting node 102, coordination node 104, and data nodes can be terminals or servers. Terminals can include, but are not limited to, desktop computers, laptops, smartphones, tablets, IoT devices, and portable wearable devices. IoT devices can include smart speakers, smart TVs, smart air conditioners, smart car devices, projectors, and the like. Portable wearable devices can include smart watches, smart bracelets, head-mounted devices, and the like. Head-mounted devices can include virtual reality (VR) devices, augmented reality (AR) devices, smart glasses, and the like. Servers can be standalone physical servers, server clusters or distributed systems consisting of multiple physical servers, or cloud servers providing cloud computing services. Cloud servers are used to provide basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDNs (Content Delivery Networks), and big data and artificial intelligence platforms. The requesting node 102, the coordinating node 104 and the distributed database cluster 106 may be connected directly or indirectly via wired or wireless communication, which is not limited in this application.
[0039] In some embodiments, as Figure 2 As shown, a node communication method based on a distributed database cluster is provided. The method can be executed by each node in the distributed database cluster. An auxiliary process is created in each node in the distributed database cluster, and a network connection is established between the auxiliary processes in different nodes. Taking the execution of the method by the current node in the distributed database cluster as an example, the current node is any node in the distributed database cluster, and includes the following steps 202 to 212. Among them:
[0040] Step 202, when it is determined to generate a data redistribution operator, allocate shared memory for the data redistribution operator, determine the sending data to be sent to the first other node according to the data redistribution operator, and write the sending data to the sending partition corresponding to the first other node in the shared memory.
[0041] The first other node is any other node, and the other node refers to a data node other than the current node in the distributed database cluster. For each other node, the current node executes step 202 respectively.
[0042] The data redistribution operator is triggered by a table join query operation. A table join query operation is a query operation on multiple data tables, and at least one of the multiple data tables is joined using a non-distribution key. The table join query operation is a join query operation in SQL (Structured Query Language). In a distributed database system, a distribution key is a field or a combination of multiple fields used to uniquely identify a distributed table. The distribution key is used to divide and distribute the data in the table to different nodes. The data in a table can be distributed on different nodes through the distribution key, and the table becomes a distributed table. The join operation is an operation in SQL that is used to merge multiple tables together according to specified conditions. Data can be combined by specifying related columns in multiple tables. Multiple tables refers to at least two tables.
[0043] Specifically, the coordinating node receives a request corresponding to a table join query operation sent by the requesting node. When it is determined that at least one distributed table in the table join query operation adopts a non-distribution key connection, a data redistribution operator is generated for each distributed table in the at least one distributed table, and an operator identifier is generated for the data redistribution operator. The operator identifier is used to uniquely identify an operator. For each distributed table in the at least one distributed table, different original shards of the distributed table can be stored in at least two nodes in the distributed database cluster. The original shards of the distributed table contain part of the records in the distributed table, and the records stored in different original shards are not repeated. The original shards are divided according to the original distribution key of the distributed table and distributed to at least two nodes. A record can be understood as a row of data in a distributed table. Each node in the distributed database cluster can execute the node communication method based on the distributed database cluster provided in this application for each generated data redistribution operator.
[0044] In some embodiments, the coordination node can send the data redistribution operator to each node in the distributed database cluster, such as the current node. The current node can register the data redistribution operator in the operator queue and allocate shared memory for the data redistribution operator, wherein the registration of the data redistribution operator and the allocation of shared memory can be performed by the backend process (backend process) in the current node, and the shared memory can be understood as the memory for the backend process to communicate or share with the auxiliary process. The current node can allocate shared memory for the data redistribution operator by creating a shared memory file. The shared memory file corresponds to the shared memory, and operations on the shared memory file are operations on the shared memory. The current node can divide the shared memory into a sending memory area and a receiving memory area, divide the sending memory area into multiple sending partitions, and the sending partitions correspond one-to-one to the nodes, and divide the receiving memory area into multiple receiving partitions, and the receiving partitions correspond one-to-one to the nodes.
[0045] In some embodiments, the coordination node can send the operator description information of the data redistribution operator to each node in the distributed database cluster, such as the current node, to implement the distribution of the data redistribution operator. The current node adds the operator description information to the operator queue of the auxiliary process in the current node to implement the registration of the data redistribution operator. Among them, the operator description information includes the operator identifier of the data redistribution operator, the table identifier of the target distributed table to be redistributed, and the redistribution key used for redistribution. The redistribution key is a temporary distribution key, and the redistribution key is different from the original distribution key. The current node can determine the target distributed table based on the table identifier in the operator description information, and determine the records to be sent to the first other node from the original shard of the target distributed table recorded by the current node based on the redistribution key to obtain the sent data.
[0046] Step 204: Generate a sending record based on the node identifier of the first other node, the operator identifier of the data redistribution operator, and the partition identifier of the sending partition, and add the sending record to the routing table corresponding to the current auxiliary process in the current node.
[0047] The node identifier can be a node number, which is a globally unique number established for each node in a distributed database cluster. An auxiliary process is a resident background worker process of a node, used for network data transmission between nodes. The current auxiliary process is the auxiliary process in the current node. For example, a sending record is {dest node id 1, rdaid 1, mmap 1}, where "dest node id 1" is the node identifier of the first other node, "rda id 1" is the operator identifier, and "mmap 1" is the partition identifier of the sending partition. The routing table is used to record the sending records generated by each data redistribution operator.
[0048] In some embodiments, there are multiple sending threads in the auxiliary process, and the sending threads correspond to the routing table one by one, and each sending thread can have an index. The auxiliary process can include a main thread, a sending thread, and a routing table corresponding to the sending thread, which can be created by the main thread. The current node can perform a modulo operation on the number of sending threads by the node identifier, and the result of the modulo operation is the index of a certain sending thread, for example, Node group ID = Node ID % num1, where num1 is the number of sending threads, Node ID is the node identifier, and Node group ID is the modulo operation result. Thus, the current node can perform a modulo operation on the number of sending threads by the node identifier of the first other node, determine the sending thread indexed by the modulo operation result, and add the sending record to the routing table corresponding to the determined sending thread.
[0049] Step 206: Generate a receiving record according to the node identifier and the operator identifier of the first other node, and add the receiving record to the receiving queue corresponding to the current auxiliary process.
[0050] The received record may include the node identifier and operator identifier of the first other node. For each other node, the current node may execute step 206 respectively.
[0051] In some embodiments, there are multiple receiving threads in the auxiliary process, and the receiving threads correspond to the receiving queues one by one. The current node can determine the corresponding receiving thread based on the node identifier and the number of receiving threads in the receiving record, and write the receiving record to the receiving queue corresponding to the determined receiving thread. For example, each receiving thread has an index, and the node identifier can be modulo the number of receiving threads to obtain a modulo result, which is the index of a certain receiving thread, and the receiving record is written to the receiving queue corresponding to the receiving thread indexed by the modulo result. For example, Node group ID = Node ID % num2, where "Node ID" is the node identifier, num2 is the number of receiving threads, and Node group ID is the modulo result.
[0052] Step 208, in the process of the current auxiliary process processing the current sending record in the routing table, determine the target sending partition corresponding to the partition identifier in the current sending record, read the data in the target sending partition to obtain the first data packet, and send a first message to other nodes represented by the node identifier in the current sending record, and the first message carries the first data packet.
[0053] Specifically, the current auxiliary process can traverse the sending record in the routing table, and the current sending record is the sending record traversed. In the case where the routing table corresponds to the sending thread one-to-one, the sending thread can traverse the sending record in the corresponding routing table, and the current sending record is the sending record traversed by the sending thread.
[0054] In some embodiments, a network connection is established between the auxiliary process in the other node and the current auxiliary process, and the current node can send the first message to the other node through the network connection.
[0055] In some embodiments, a helper process includes a listening thread and at least one I / O thread. An I / O thread (Input / Output Thread) is responsible for handling input / output (I / O) operations. The listening thread can receive connection establishment requests from other nodes to the current node. These connection establishment requests are used to request a network connection between the helper process on the other node and the current helper process. In response to the connection establishment requests, the listener thread establishes a network connection between the helper process on the other node and the current helper process, and registers the network connection with the I / O thread.
[0056] Step 210: Receive a second message sent by a second other node, where the second message carries the operator identifier, the node identifier of the second other node, and a second data packet.
[0057] The second other node may be any data node other than the current node, and the second other node may be the same as or different from the first other node. The second message is generated by the other node. The process for the second other node to generate the second message can refer to the process for the current node to generate the first message.
[0058] Step 212, based on the node identifier and operator identifier of the second other node, determine the corresponding target receiving record from the receiving queue, write the second data packet into the target receiving record, and when the current auxiliary process processes the current receiving record in the receiving queue, determine the corresponding target receiving partition from the shared memory, and write the received data in the current receiving record into the target receiving partition.
[0059] Specifically, the IO thread may receive a second message sent via a network connection registered in the IO thread. The IO thread may determine a corresponding reception record based on the operator identifier and the node identifier of the second other node in the second message, and write the second data packet in the second message into the corresponding reception record. For example, the corresponding reception record may be {src node id 1, rda id 1, date 1}, where "src node id 1" is the node identifier of the second other node, "rda id 1" is the operator identifier, and "date 1" is used to store the second data packet.
[0060] In some embodiments, there are multiple receiving threads in the auxiliary process, and the receiving threads correspond to the receiving queues one by one. The IO thread can determine the corresponding receiving thread based on the node identifier of the second other node in the second message and the number of receiving threads. For example, each receiving thread has an index, and the IO thread can perform a modulo operation on the node identifier of the second other node and the number of receiving threads to obtain a modulo result, which is the index of a certain receiving thread. Then, based on the node identifier and operator identifier of the second other node, the corresponding target receiving record is determined from the receiving queue of the receiving thread corresponding to the modulo result, and the second data packet is written into the target receiving record.
[0061] In some embodiments, the receiving thread includes a partition mapping table that records the mapping relationship between the partition identifier of the receiving partition and the "node identifier and operator identifier." For each receiving thread, the receiving thread can traverse the receiving records in the corresponding receiving queue. For the current receiving record traversed, based on the node identifier and operator identifier in the current receiving record, the receiving thread queries the partition mapping table for the corresponding target partition identifier, and writes the second data packet in the current receiving record to the target receiving partition corresponding to the target partition identifier. Thus, overall, the IO thread writes data to the receiving record, and the receiving thread reads data from the receiving record and writes it to the corresponding receiving partition in the shared memory.
[0062] In some embodiments, for each data redistribution operator, the backend process in the current node can read the data in the receiving partition corresponding to the operator identifier of the data redistribution operator. The read data may contain one or more records, determine the target distributed table that the data redistribution operator needs to redistribute, combine the data read from the receiving partition and the original shards in the target distributed table recorded in the current node, execute the table join query operation corresponding to the data redistribution operator, obtain the query result, and return the query result to the coordination node. The coordination node combines the query results returned by each node in the distributed database cluster to obtain the final query result of the table join query operation, and returns the final query result to the requesting node. The requesting node is the node that sends the request corresponding to the table join query operation to the coordination node.
[0063] like Figure 3 The schematic diagram shows a node communication method based on a distributed database cluster. Specifically, each node contains a backend process and an auxiliary process. The backend and auxiliary processes communicate via shared memory. The auxiliary process includes a listening thread, an I / O thread, a sending thread, a receiving thread, and a cleanup thread. It may also include a main thread. The listening thread, I / O thread, sending thread, receiving thread, or cleanup thread may be created by the main thread. The backend process in the current node writes data to be sent to other nodes to the corresponding send partition in shared memory and reads data from other nodes from the receive partition in shared memory. The sending thread reads data from the send partition in shared memory and transmits the read data to the corresponding other nodes via the network connection between the current auxiliary process and the auxiliary processes of other nodes. The I / O thread writes the received data to the receive record in the receive queue. The receiving thread reads data from the receive record in the receive queue and writes it to the corresponding receive partition in shared memory. The backend process reads data from the receive partition and combines the read data with the data in the local original shard to execute a query operation to obtain the query result. The listening thread is responsible for adding a network connection to the I / O thread when it receives a connection request, and the cleanup thread is responsible for releasing shared memory.
[0064] In the above-mentioned node communication method based on the distributed database cluster, when it is determined to generate a data redistribution operator, a shared memory is allocated to the data redistribution operator, and the sending data to be sent to the first other node is determined according to the data redistribution operator, and the sending data is written to the sending partition corresponding to the first other node in the shared memory. According to the node identifier of the first other node, the operator identifier of the data redistribution operator and the partition identifier of the sending partition, a sending record is generated, and the sending record is added to the routing table corresponding to the current auxiliary process in the current node. According to the node identifier and operator identifier of the first other node, a receiving record is generated, and the receiving record is added to the receiving queue corresponding to the current auxiliary process. The current sending record is processed in the routing table by the current auxiliary process. In the process, the target sending partition corresponding to the partition identifier in the current sending record is determined, the data in the target sending partition is read to obtain the first data packet, the first message is sent to the other node represented by the node identifier in the current sending record, the first message carries the first data packet, the second message sent by the second other node is received, the second message carries the operator identifier, the node identifier of the second other node and the second data packet, according to the node identifier and operator identifier of the second other node, the corresponding target receiving record is determined from the receiving queue, the second data packet is written to the target receiving record, when the current auxiliary process processes the current receiving record in the receiving queue, the corresponding target receiving partition is determined from the shared memory, and the received data in the current receiving record is written to the target receiving partition. Thus, each time the original node encounters a data redistribution operator, a new process is created and a network connection is established with other nodes, which is optimized so that each node has a background auxiliary process, and data is redistributed with other nodes through the auxiliary process, thereby reducing the occupation of system resources.
[0065] In traditional data redistribution methods, data redistribution will occupy a large amount of system process resources and network connections, causing a significant decline in database system performance or even downtime, affecting the database's external services. When the cluster is large, it will cause system resources to be fully occupied, resulting in database system anomalies. This application proposes a node communication method based on a distributed database cluster to solve the problem of a sharp increase in the number of processes and network connections caused by join queries on multiple tables in a distributed database. Advantages include: 1. Traditional data redistribution easily generates a large number of new processes and network connections. This application introduces a background resident auxiliary process to unify network data interaction between nodes, reduce system resource utilization, and increase the query concurrency of the distributed database system. The number of processes (network connections) of a single node is reduced from the number of nodes * the number of joins (connections) * the number of concurrent queries to the number of nodes * C (constant). C can be understood as the number of data redistribution operators in the query execution plan, which can solve the problem of excessive system resource consumption when processing complex queries. 2. When a data node executes each redistribution operator, a shared memory is allocated for the redistribution operator. The shared memory is used to communicate with the auxiliary process. The operators do not interfere with each other, which can ensure the correctness of the query results executed by the system and improve the system service efficiency.
[0066] In some embodiments, the sending record also includes the status of the sending record, the current sending record is the sending record traversed when traversing the routing table, and the first data packet is generated when the status of the current sending record is active and data is read from the target sending partition. The method also includes: when the status of the current sending record is active and no data is read from the target sending partition, generating a silent state update instruction corresponding to the current sending record; when the status of the current sending record is silent, skipping the current sending record and generating an active state update instruction corresponding to the current sending record.
[0067] Among them, the silent state update instruction is used to update the state of the current sending record to the silent state after completing the current round of traversal, and the active state update instruction is used to update the state of the current sending record to the active state after completing the current round of traversal.
[0068] Specifically, there are multiple sending threads in the auxiliary process, and the sending threads correspond to the routing tables one by one. Figure 4As shown in the figure, there are 3 sending threads in the current auxiliary process (in fact, there can be more or fewer sending threads). Sending thread i corresponds to routing table i. Each row in the routing table in the figure represents a sending record. In the sending record, mmap1~mmap9 represent the partition identifiers of 3 different sending partitions, status represents the status of the sending record, rda id 1~rda id 3 represent the operator identifiers of 3 different data redistribution operators. Different data redistribution operators have different shared memories. The sending partitions represented by the partition identifiers in the sending records with the same operator identifier belong to the same shared memory. For example, the sending partitions represented by mmap 1, mmap 4, and mmap 7 each belong to the shared memory corresponding to rda id 1.
[0069] In some embodiments, each sending thread in the current auxiliary process traverses its corresponding routing table. Taking sending thread 1 in the figure as an example, sending thread 1 traverses the sending records in routing table 1. When traversing to the first sending record in routing table 1, if the status in the first sending record is active, the sending partition corresponding to the partition identifier mmap1 in the first sending record is determined, and data is read from the sending partition corresponding to mmap1. If the sending partition corresponding to mmap1 contains data to be read, the data can be read to obtain the first data packet. If the sending partition corresponding to mmap1 does not contain data to be read, no data can be read. It can be understood that the data in the sending partition corresponding to mmap1 is written by the backend process. If the backend process is busy, it may not write data to the sending partition corresponding to mmap1 in a timely manner, resulting in no data being read. If no data is read, a corresponding silent status update instruction is generated for the first sending record. If the status in the first sending record is silent, the second sending record is traversed and a corresponding active status update instruction is generated for the first sending record.
[0070] In this embodiment, by recording the status of the current sending record, when the status of the current sending record is a silent state, the current sending record can be skipped, thereby improving the efficiency of traversing the routing table.
[0071] In some embodiments, the routing table corresponds to a sending thread in an auxiliary process, and the method further includes: in the process of traversing the routing table, writing the status update instruction generated for the sending record in the routing table into the status queue; when the current round of traversal is completed, updating the status of the corresponding sending record in the routing table according to the status update instruction in the status queue.
[0072] The state update instruction is either a silent state update instruction or an active state update instruction. The state update instruction includes a send record identifier, which uniquely identifies a send record. The send record identifier may include, for example, an operator identifier and a node identifier in the send record. Each send thread has its own corresponding state queue.
[0073] by Figure 4 Taking sending thread 1 as an example, there are 3 sending records in the routing table. After traversing routing table 1 once, a silent status update instruction "update 1 silent" is generated for the first sending record, a silent status update instruction "update 2 silent" is generated for the second sending record, and an active status update instruction "update 3active" is generated for the third sending record. As a result, these 3 status update instructions are recorded in status queue 1. The numbers in these 3 status update instructions represent the sending record identifiers.
[0074] Specifically, the sending thread can execute a status update instruction in the status queue and, after execution, remove the status update instruction from the status queue. For example, after sending thread 1 executes "update 1 silent," "update 1 silent" is removed from status queue 1. Executing a status update instruction means updating the status of the corresponding sending record according to the status update instruction. For example, executing "update 1 silent" updates the status of the first sending record to silent.
[0075] In this embodiment, when a round of traversal is completed, the status of the corresponding sending record in the routing table is updated according to the status update instruction in the status queue, which can realize batch update of status and improve the efficiency of updating status.
[0076] In some embodiments, there are multiple sending threads in the auxiliary process, and the sending threads correspond to the routing table one by one. The method also includes: when the status of all sending records in the routing table is silent, the status of the sending thread corresponding to the routing table is set to sleep.
[0077] For example, Figure 4 When the states of the three sending records in the routing table 1 are all silent, the state of the sending thread 1 corresponding to the routing table 1 is set to the dormant state.
[0078] In some embodiments, the duration of the dormant state can be set. After the preset dormant time, the state of the sending thread is set to the awake state, so that the sending thread continues to traverse the corresponding routing table.
[0079] In this embodiment, when all sending records in the routing table are in silent state, the sending thread corresponding to the routing table is set to sleep state. When there is no data to send, the sending thread can be suspended to save computer resources.
[0080] In some embodiments, the corresponding target receiving partition is determined from the shared memory, and the received data in the current receiving record is written to the target receiving partition, including: querying the corresponding target partition identifier from the partition mapping table according to the operator identifier and node identifier in the current receiving record, the target partition identifier represents a receiving partition in the shared memory; and writing the received data in the current receiving record into the target receiving partition represented by the target partition identifier.
[0081] The partition mapping table stores the mapping between "operator IDs and node IDs" and "partition IDs." For example, if shared memory 1 is generated for operator 1 and there are five data nodes in the distributed database cluster, the receiving memory area in shared memory 1 can be divided into five receiving partitions, each corresponding to a data node. Alternatively, it can be divided into four receiving partitions, each corresponding to a node other than the current node. Thus, a partition ID can be uniquely identified in the partition mapping table using the operator ID and node ID.
[0082] Specifically, the current auxiliary process may include multiple receiving threads, and the receiving threads correspond to the receiving queues one by one. Each receiving queue has its own partition mapping table. Figure 5 As shown, the current auxiliary process contains 3 receiving threads, and receiving thread 1 corresponds to receiving queue 1 and partition mapping table 1. Taking receiving thread 1 as an example, the current receiving record is the receiving record traversed by receiving thread 1 in receiving queue 1. For example, the current receiving record is the first receiving record in receiving queue 1. Then, receiving thread 1 queries the corresponding partition identifier from partition mapping table 1 based on src node id 1 and rda id 1 in the first receiving record to obtain the target partition identifier, and writes the data in date 1 in the first receiving record to the target receiving partition represented by the target partition identifier. The received data in the current receiving record is the data in date 1.
[0083] In this embodiment, by dividing the shared memory into receiving partitions, the received data in different receiving records can be written into the corresponding receiving partitions, so as to facilitate the execution of query operations based on the data in the receiving partitions.
[0084] In some embodiments, the method also includes: adding a first operator registration instruction generated based on the operator identifier and the node identifier of the first other node to the sending operator queue corresponding to the auxiliary process, wherein generating the sending record is performed when executing the first operator registration instruction in the sending operator queue; after adding the sending record to the routing table corresponding to the current auxiliary process in the current node, removing the first operator registration instruction from the sending operator queue; adding a second operator registration instruction generated based on the operator identifier and the node identifier of the first other node to the receiving operator queue corresponding to the auxiliary process, wherein generating the receiving record and adding the receiving record to the receiving queue are performed when executing the second operator registration instruction in the receiving operator queue; after adding the receiving record to the receiving queue corresponding to the current auxiliary process, removing the second operator registration instruction from the receiving operator queue.
[0085] Specifically, if Figure 4 As shown, taking the operator identifier as rda id 1 and the node identifier of the first other node as destnode id 1 as an example, the backend process in the current node generates the first operator registration instruction according to rda id 1 and dest node id 1. For example, the first operator registration instruction can be simply expressed as "create 1", and the first operator registration instruction is written into the sending operator queue 1. The sending thread 1 can determine the sending partition corresponding to dest node id 1 according to the first operator registration instruction, and generate a sending record according to the partition identifier of the sending partition corresponding to dest node id 1, rda id 1 and dest node id 1. Then, the sending record is added to the routing table 1, and the first operator registration instruction "create 1" is removed from the sending operator queue 1. It can be understood that the first sending record in the routing table 1 is inserted into the routing table 1 after executing "create 1" in the sending operator queue 1. The second operator registration instruction, for example Figure 5 In the receiving operator queue 1, "create1" is executed, and the receiving thread executes the second operator registration instruction "create 1" in the receiving operator queue 1, generates a receiving record {srcnode id 1, rda id 1, date 1}, and writes the receiving record to the receiving queue 1. It can be understood that after the receiving record {src node id 1, rda id 1, date 1} is written to the receiving queue 1, the receiving thread 1 will remove the second operator registration instruction "create 1" from the receiving operator queue 1.
[0086] In this embodiment, the sending operator queue and the receiving operator queue can allow multiple first operator registration instructions and multiple second operator registration instructions to exist, which can improve the work efficiency of the thread.
[0087] In some embodiments, the method also includes: when the step of writing the sending data to the sending partition corresponding to the first other node in the shared memory is completed, adding a first deregistration instruction corresponding to the sending record to the sending operator queue; when the first deregistration instruction in the sending operator queue is traversed, removing the sending record from the routing table, and removing the first deregistration instruction from the sending operator queue; reading data from the target receiving partition, and when the data in the target receiving partition is read, adding a second deregistration instruction corresponding to the current receiving record to the receiving operator queue; when the second deregistration instruction in the receiving operator queue is traversed, removing the current receiving record from the receiving queue, and removing the second deregistration instruction from the receiving operator queue.
[0088] Among them, the step of writing the sending data to the sending partition corresponding to the first other node in the shared memory is completed, which can be understood as the sending data has been written to the sending partition at one time or in batches. For example, if the sending data is relatively large, after filling the sending partition with a batch of data in the sending data, wait for the data in the sending partition to be sent out, and then write another batch of data in the sending data to the sending partition. Until all the sending data is written to the sending partition, it is considered that the step of writing the sending data is completed.
[0089] Specifically, the first deregistration instruction is, for example, Figure 4 In the send operator queue 1, "drop 2" corresponds to the second send record in routing table 1. Each time the sending thread traverses the corresponding routing table, it can traverse the corresponding send operator queue. For example, when sending thread 1 traverses send operator queue 1 and reaches "drop 2", it removes the second send record from routing table 1 and removes the first deregistration instruction, "drop 2", from send operator queue 1.
[0090] In some embodiments, the back-end process in the current node can read data from the target receiving partition, and "reading the data in the target receiving partition" means that all the data that need to be written to the target receiving partition have been read. For example, when "UF" is written to the target receiving partition, it means that all the data that need to be written to the target receiving queue have been written. If the back-end process reads "UF" from the target receiving partition, it can be determined that the data in the target receiving partition has been read.
[0091] For example, the second deregistration instruction is Figure 5"drop 2" in the receiving operator queue 1 in the receiving operator queue 1 corresponds to the second receiving record in the receiving queue 1. After the receiving thread 1 traverses the receiving operator queue 1 once, it traverses the receiving operator queue 1 again. When it traverses to "drop 2", it removes the second receiving record in the receiving queue 1 from the receiving queue 1 and removes "drop 2" from the receiving operator queue 1.
[0092] In this embodiment, the processed records can be cleared from the routing table and the receiving queue through the deregistration instruction, thereby avoiding traversal of the imported processed records and improving thread work efficiency.
[0093] In some embodiments, the auxiliary process further includes a cleaning thread, and the method further includes: when traversing to the first deregistration instruction in the sending operator queue, adding a sending cleanup record corresponding to the sending record to the sending cleanup queue corresponding to the cleaning thread; when traversing to the second deregistration instruction in the receiving operator queue, adding a receiving cleanup record corresponding to the current receiving record to the receiving cleanup queue corresponding to the cleaning thread; when the sending cleanup queue contains sending cleanup records corresponding to all sending records generated for the data redistribution operator, and the receiving cleanup queue contains receiving cleanup records corresponding to all receiving records generated for the data redistribution operator, releasing the shared memory allocated for the data redistribution operator.
[0094] The sending cleanup record corresponding to the sending record may include the operator identifier and node identifier in the sending record, and may also include the partition identifier in the sending record. The receiving cleanup record corresponding to the receiving record may include the operator identifier and node identifier in the receiving record, and may also include the partition identifier determined based on the operator identifier and node identifier in the receiving record. For example, the sending cleanup queue Figure 6 In the cleaning thread, the sending cleaning queue is sent. For example, the receiving cleaning queue Figure 6 The cleanup thread receives the cleanup queue. Figure 6 Each line in the send cleanup queue represents a send cleanup record. Figure 6 Each row in the receive cleanup queue represents a receive cleanup record.
[0095] Specifically, the cleanup thread can read the sending cleanup record corresponding to the same operator ID (for example, rda id 1) from the sending cleanup queue, and read the receiving cleanup record corresponding to the same operator ID from the receiving cleanup queue, that is, Figure 6 Then, the cleaning thread counts the number of each sent cleaning record read to obtain a first number, and counts the number of each received cleaning record read to obtain a second number, that is, Figure 6Determine whether the first quantity and the second quantity are both equal to the preset quantity, i.e. Figure 6 The judgment of "whether it can be deleted" is in the above. The preset number is the number of sending records generated for each operator, and also the number of receiving records generated for each operator. The preset number is, for example, the number of data nodes in a distributed database cluster. If the first number and the second number are both equal to the preset number, the judgment result of "whether it can be deleted" is yes, otherwise it is no. If the judgment result is yes, the shared memory allocated to the data redistribution operator represented by the same operator identifier is released. For example, the purpose of releasing the shared memory can be achieved by deleting the shared memory file generated for the data redistribution operator, that is, Figure 6 Delete files in the
[0096] In this embodiment, the shared memory allocated by the data redistribution operator is released by the clearing thread, so that the memory resources can be released in time.
[0097] In some embodiments, as Figure 7 The figure shows a schematic diagram of a node communication method based on a distributed database cluster. During the initialization of the distributed database system, each data node creates a helper process and establishes a network connection with the helper processes of other data nodes. When data is redistributed, each data node does not need to create a new process or establish a network connection. Instead, the data to be redistributed is transmitted through the helper process. The method mainly includes three phases: initialization, operation, and shutdown. During the initialization phase, process resources are initialized, worker threads (each thread in the helper process) are started, and network connections are established with the helper processes of other data nodes. During the operation phase, when a data redistribution operator is available, the data node registers the operator with the helper process, creates a shared memory file, and registers it in the routing table. The send thread of the helper process traverses the routing table and sends data if there is data. The receive thread of the helper process traverses the receive queue and receives data if there is data. In the shutdown phase, network connections are closed, worker threads are exited, and process resources are cleaned up. Specifically:
[0098] 1. After the data node in the distributed database cluster is started, the background resident working process, namely the auxiliary process, is started.
[0099] 2. The auxiliary process creates and initializes the working threads, including creating listening threads, sending threads, receiving threads, cleaning threads, IO threads, etc. The IO thread can be called the network information transmission thread.
[0100] 3. Obtain node metadata, establish network connections with other nodes for subsequent data redistribution, and create a connection routing table for network connection management.
[0101] 4. When the system executes a join query and a node executes the data redistribution operator, it does not need to create a new process to establish a network connection with other nodes. Instead, it transmits the data to be redistributed to the auxiliary process via shared memory, which then handles the network transmission. When the system executes the data redistribution operator, the data node creates a shared memory file for the data redistribution operator and registers it with the routing table corresponding to the auxiliary process's sending thread (i.e., the shared memory routing table). It also creates resources such as the packet queue (receive queue) and the purge queue (receive purge queue and send purge queue).
[0102] 5. The sending thread traverses the shared memory routing table. If the corresponding operator has data to send, the data is sent to the target node through the network according to the target node information of the data packet.
[0103] 6. The receiving thread reads the data packet from the data packet queue and unpacks it, and writes the data to the corresponding shared memory file for the data node to execute the query.
[0104] 7. After the redistribution operator of the query is completed, the deregistration process is performed, and the shared memory file used is deleted from the corresponding routing table of the auxiliary process. After that, the shared memory file is cleaned up asynchronously by the background cleaning thread.
[0105] 8. When the distributed database system is shut down, the auxiliary process exits each working thread in turn and disconnects the network connection before exiting normally.
[0106] In this embodiment, by introducing a background resident working process, namely an auxiliary process, as a communication method for data redistribution among data nodes in a distributed database cluster (which may be, but is not limited to, a PostgreSQL-XL distributed database), the system can significantly reduce the occupation of process resources and network connection resources when executing join queries, thereby improving the data throughput and execution concurrency of the distributed database system.
[0107] It should be understood that, although the various steps in the flowcharts involved in the various embodiments described above are displayed in sequence according to the instructions of the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the flowcharts involved in the various embodiments described above can include multiple steps or multiple stages, and these steps or stages are not necessarily executed and completed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a portion of steps or stages in other steps.
[0108] Based on the same inventive concept, embodiments of the present application also provide a distributed database cluster-based node communication device for implementing the above-mentioned distributed database cluster-based node communication method. The implementation solution provided by this device is similar to the implementation solution described in the above-mentioned method. Therefore, the specific limitations of one or more embodiments of the distributed database cluster-based node communication device provided below can be found in the above-mentioned limitations of the distributed database cluster-based node communication method, and will not be repeated here.
[0109] In some embodiments, as Figure 8 As shown, a node communication device based on a distributed database cluster is provided, comprising: a shared memory management module 802, a sending record processing module 804, a receiving record processing module 806, a data sending module 808, a data receiving module 810 and a data processing module 812, wherein:
[0110] The shared memory management module 802 is configured to allocate shared memory to the data redistribution operator when it is determined that a data redistribution operator is generated, determine the send data to be sent to the first other node based on the data redistribution operator, and write the send data to the send partition corresponding to the first other node in the shared memory;
[0111] A sending record processing module 804 is configured to generate a sending record based on the node identifier of the first other node, the operator identifier of the data redistribution operator, and the partition identifier of the sending partition, and add the sending record to a routing table corresponding to the current auxiliary process in the current node;
[0112] A reception record processing module 806 is configured to generate a reception record according to the node identifier and the operator identifier of the first other node, and add the reception record to a reception queue corresponding to the current auxiliary process;
[0113] A data sending module 808 is configured to, during the process of the current auxiliary process processing the current sending record in the routing table, determine a target sending partition corresponding to the partition identifier in the current sending record, read data in the target sending partition to obtain a first data packet, and send a first message carrying the first data packet to other nodes represented by the node identifier in the current sending record;
[0114] The data receiving module 810 is configured to receive a second message sent by a second other node, where the second message carries an operator identifier, a node identifier of the second other node, and a second data packet;
[0115] The data processing module 812 is used to determine the corresponding target receiving record from the receiving queue according to the node identifier and operator identifier of the second other node, write the second data packet into the target receiving record, and when the current auxiliary process processes the current receiving record in the receiving queue, determine the corresponding target receiving partition from the shared memory and write the received data in the current receiving record into the target receiving partition.
[0116] In some embodiments, the sending record also includes the status of the sending record. The current sending record is the sending record traversed when traversing the routing table. The first data packet is generated when the status of the current sending record is active and data is read from the target sending partition. The sending record processing module is also used to generate a silent state update instruction corresponding to the current sending record when the status of the current sending record is active and no data is read from the target sending partition; when the status of the current sending record is silent, skip the current sending record and generate an active state update instruction corresponding to the current sending record; wherein, the silent state update instruction is used to update the status of the current sending record to the silent state after completing the current round of traversal, and the active state update instruction is used to update the status of the current sending record to the active state after completing the current round of traversal.
[0117] In some embodiments, the routing table corresponds to the sending thread in the auxiliary process, and the sending record processing module is also used to write the status update instructions generated for the sending records in the routing table into the status queue during the process of traversing the routing table; when the current round of traversal is completed, the status of the corresponding sending record in the routing table is updated according to the status update instructions in the status queue.
[0118] In some embodiments, there are multiple sending threads in the auxiliary process, and the sending threads correspond one-to-one to the routing table. The device also includes a thread state management module, which is used to set the state of the sending thread corresponding to the routing table to a sleep state when the states of all sending records in the routing table are in a silent state.
[0119] In some embodiments, the data processing module 812 is also used to query the corresponding target partition identifier from the partition mapping table based on the operator identifier and node identifier in the current receiving record, where the target partition identifier represents a receiving partition in the shared memory; and write the received data in the current receiving record into the target receiving partition represented by the target partition identifier.
[0120] In some embodiments, the device also includes a first operator registration module, which is used to add a first operator registration instruction generated based on the operator identifier and the node identifier of the first other node to the sending operator queue corresponding to the auxiliary process, wherein the generation of the sending record is performed when the first operator registration instruction in the sending operator queue is executed; after the sending record is added to the routing table corresponding to the current auxiliary process in the current node, the first operator registration instruction is removed from the sending operator queue; the device also includes a second operator registration module, which is used to add a second operator registration instruction generated based on the operator identifier and the node identifier of the first other node to the receiving operator queue corresponding to the auxiliary process, wherein the generation of the receiving record and the addition of the receiving record to the receiving queue are performed when the second operator registration instruction in the receiving operator queue is executed; after the receiving record is added to the receiving queue corresponding to the current auxiliary process, the second operator registration instruction is removed from the receiving operator queue.
[0121] In some embodiments, the device also includes a first deregistration module, which is used to add a first deregistration instruction corresponding to the sending record to the sending operator queue when the step of writing the sending data to the sending partition corresponding to the first other node in the shared memory is completed; when the first deregistration instruction in the sending operator queue is traversed, the sending record is removed from the routing table, and the first deregistration instruction is removed from the sending operator queue; the device also includes a second deregistration module, which is used to read data from the target receiving partition, and when the data in the target receiving partition is read, add a second deregistration instruction corresponding to the current receiving record to the receiving operator queue; when the second deregistration instruction in the receiving operator queue is traversed, the current receiving record is removed from the receiving queue, and the second deregistration instruction is removed from the receiving operator queue.
[0122] In some embodiments, the auxiliary process further includes a cleaning thread, and the device further includes a cleaning module, which is used to add a sending cleanup record corresponding to the sending record to the sending cleanup queue corresponding to the cleaning thread when the first deregistration instruction in the sending operator queue is traversed; add a receiving cleanup record corresponding to the current receiving record to the receiving cleanup queue corresponding to the cleaning thread when the second deregistration instruction in the receiving operator queue is traversed; and release the shared memory allocated for the data redistribution operator when the sending cleanup queue contains sending cleanup records corresponding to all sending records generated for the data redistribution operator and the receiving cleanup queue contains receiving cleanup records corresponding to all receiving records generated for the data redistribution operator.
[0123] Each module in the above-mentioned node communication device based on a distributed database cluster can be implemented in whole or in part through software, hardware, or a combination thereof. Each of the above modules can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the corresponding operations of each of the above modules.
[0124] In some embodiments, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 9 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, abbreviated as I / O) and a communication interface. The processor, memory and input / output interface are connected via a system bus, and the communication interface is connected to the system bus via the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and computer program in the non-volatile storage medium. The database of the computer device is used to store data involved in a node communication method based on a distributed database cluster. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, a node communication method based on a distributed database cluster is implemented.
[0125] In some embodiments, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Figure 10As shown. The computer device includes a processor, memory, an input / output interface, a communication interface, a display unit, and an input device. The processor, memory, and input / output interface are connected via a system bus, and the communication interface, display unit, and input device are connected to the system bus via the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and external devices. The communication interface of the computer device is used to communicate with external terminals via wired or wireless means, and the wireless means can be implemented via Wi-Fi, a mobile cellular network, near-field communication (NFC), or other technologies. When executed by the processor, the computer program implements a node communication method based on a distributed database cluster. The display unit of the computer device is used to form a visually visible image and can be a display screen, a projection device, or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covering the display screen, or a button, trackball or touchpad set on the computer device casing, or an external keyboard, touchpad or mouse.
[0126] Those skilled in the art will understand that Figure 9 and Figure 10 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different component arrangement.
[0127] In some embodiments, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the steps in the above-mentioned node communication method based on a distributed database cluster are implemented.
[0128] In some embodiments, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned node communication method based on a distributed database cluster are implemented.
[0129] In some embodiments, a computer program product is provided, including a computer program, which, when executed by a processor, implements the steps in the above-mentioned node communication method based on a distributed database cluster.
[0130] Those skilled in the art will understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. In particular, any reference to memory, database, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The databases involved in the various embodiments provided herein may include at least one of a relational database and a non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the various embodiments provided herein may be, but are not limited to, general-purpose processors, central processing units (CPUs), graphics processing units (GPUs), digital signal processors (DSPs), programmable logic devices (PLDs), quantum computing-based data processing logic devices, artificial intelligence (AI) processors, and the like.
[0131] The technical features of the above embodiments can be combined arbitrarily. In order to make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0132] The above-described embodiments merely represent several implementation methods of the present application. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the present application. It should be noted that a person of ordinary skill in the art may make various modifications and improvements without departing from the spirit of the present application, and these modifications and improvements fall within the scope of protection of the present application. Therefore, the scope of protection of the present application shall be determined by the appended claims.
Claims
1. A node communication method based on a distributed database cluster, characterized in that: Executed by a current node in a distributed database cluster, the method includes: In a case where it is determined to generate a data redistribution operator, a shared memory is allocated to the data redistribution operator, sending data to be sent to the first other node is determined according to the data redistribution operator, and the sending data is written to a sending partition corresponding to the first other node in the shared memory; Generate a sending record according to the node identifier of the first other node, the operator identifier of the data redistribution operator, and the partition identifier of the sending partition, and add the sending record to a routing table corresponding to the current auxiliary process in the current node; generating a reception record according to the node identifier of the first other node and the operator identifier, and adding the reception record to a reception queue corresponding to the current auxiliary process; During processing of the current sending record in the routing table by the current auxiliary process, determining a target sending partition corresponding to the partition identifier in the current sending record, reading data in the target sending partition to obtain a first data packet, and sending a first message to other nodes represented by the node identifier in the current sending record, where the first message carries the first data packet; receiving a second message sent by a second other node, where the second message carries the operator identifier, the node identifier of the second other node, and a second data packet; According to the node identifier of the second other node and the operator identifier, the corresponding target receiving record is determined from the receiving queue, and the second data packet is written into the target receiving record. When the current auxiliary process processes the current receiving record in the receiving queue, the corresponding target receiving partition is determined from the shared memory, and the received data in the current receiving record is written into the target receiving partition.
2. The method according to claim 1, characterized in that The sending record further includes a status of the sending record, the current sending record is a sending record traversed when traversing the routing table, the first data packet is generated when the status of the current sending record is active and data is read from the target sending partition, and the method further includes: When the state of the current sending record is active and no data is read from the target sending partition, generating a silent state update instruction corresponding to the current sending record; When the state of the current sending record is a silent state, skipping the current sending record and generating an active state update instruction corresponding to the current sending record; The silent state update instruction is used to update the state of the current sending record to the silent state after completing the current round of traversal, and the active state update instruction is used to update the state of the current sending record to the active state after completing the current round of traversal.
3. The method according to claim 2, characterized in that The routing table corresponds to a sending thread in the auxiliary process, and the method further includes: In the process of traversing the routing table, writing the status update instruction generated for sending the record in the routing table into the status queue; When the current round of traversal is completed, the status of the corresponding sending record in the routing table is updated according to the status update instruction in the status queue.
4. The method according to claim 2, characterized in that There are multiple sending threads in the auxiliary process, and the sending threads correspond to the routing table one by one. The method further includes: When the states of all sending records in the routing table are in the silent state, the state of the sending thread corresponding to the routing table is set to the dormant state.
5. The method according to any one of claims 1 to 4, characterized in that The determining a corresponding target receiving partition from the shared memory and writing the received data in the current receiving record into the target receiving partition includes: According to the operator identifier and the node identifier in the current receiving record, a corresponding target partition identifier is searched from the partition mapping table, where the target partition identifier represents a receiving partition in the shared memory; The received data in the current receiving record is written into the target receiving partition represented by the target partition identifier.
6. The method according to any one of claims 1 to 4, characterized in that The method further comprises: adding a first operator registration instruction generated based on the operator identifier and the node identifier of the first other node to a sending operator queue corresponding to the auxiliary process, wherein generating the sending record is performed when the first operator registration instruction in the sending operator queue is executed; After adding the sending record to the routing table corresponding to the current auxiliary process in the current node, removing the first operator registration instruction from the sending operator queue; adding a second operator registration instruction generated based on the operator identifier and the node identifier of the first other node to a receiving operator queue corresponding to the auxiliary process, wherein generating a reception record and adding the reception record to the reception queue are performed when the second operator registration instruction in the receiving operator queue is executed; After adding the receiving record to the receiving queue corresponding to the current auxiliary process, removing the second operator registration instruction from the receiving operator queue.
7. The method according to claim 6, characterized in that The method further comprises: When the step of writing the sending data into the sending partition corresponding to the first other node in the shared memory is completed, adding a first deregistration instruction corresponding to the sending record to the sending operator queue; When the first deregistration instruction in the sending operator queue is traversed, removing the sending record from the routing table and removing the first deregistration instruction from the sending operator queue; Reading data from the target receiving partition, and when the data in the target receiving partition is finished being read, adding a second deregistration instruction corresponding to the current receiving record to the receiving operator queue; When the second deregistration instruction is found in the receiving operator queue, the current receiving record is removed from the receiving queue, and the second deregistration instruction is also removed from the receiving operator queue.
8. The method according to claim 7, characterized in that The auxiliary process further includes a cleanup thread, and the method further includes: When the first deregistration instruction in the sending operator queue is traversed, a sending cleanup record corresponding to the sending record is added to the sending cleanup queue corresponding to the cleanup thread; When the second deregistration instruction in the receiving operator queue is traversed, a receiving cleanup record corresponding to the current receiving record is added to the receiving cleanup queue corresponding to the cleanup thread; When the sending cleanup queue contains sending cleanup records corresponding to all sending records generated for the data redistribution operator, and the receiving cleanup queue contains receiving cleanup records corresponding to all receiving records generated for the data redistribution operator, the shared memory allocated for the data redistribution operator is released.
9. A node communication device based on a distributed database cluster, characterized in that: The device comprises: a shared memory management module, configured to, when determining to generate a data redistribution operator, allocate shared memory to the data redistribution operator, determine, based on the data redistribution operator, send data to be sent to the first other node, and write the send data into a send partition corresponding to the first other node in the shared memory; a sending record processing module, configured to generate a sending record according to the node identifier of the first other node, the operator identifier of the data redistribution operator, and the partition identifier of the sending partition, and add the sending record to a routing table corresponding to the current auxiliary process in the current node; a reception record processing module, configured to generate a reception record according to the node identifier of the first other node and the operator identifier, and add the reception record to a reception queue corresponding to the current auxiliary process; a data sending module, configured to, during the process of the current auxiliary process processing the current sending record in the routing table, determine a target sending partition corresponding to the partition identifier in the current sending record, read data in the target sending partition to obtain a first data packet, and send a first message to other nodes represented by the node identifier in the current sending record, where the first message carries the first data packet; a data receiving module, configured to receive a second message sent by a second other node, where the second message carries the operator identifier, the node identifier of the second other node, and a second data packet; A data processing module is used to determine the corresponding target receiving record from the receiving queue based on the node identifier of the second other node and the operator identifier, write the second data packet into the target receiving record, and when the current auxiliary process processes the current receiving record in the receiving queue, determine the corresponding target receiving partition from the shared memory and write the received data in the current receiving record into the target receiving partition.
10. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 8 are implemented.
Citation Information
Patent Citations
In-node process communication method and device, computer equipment and storage medium
CN109739670A
Data processing method and device
CN114519049A