Transaction processing method and device for distributed database, equipment and medium
By sending transaction IDs in batches through peer connections between the coordinator node and the global transaction manager in a distributed database, the transaction IDs are solved, and the transaction management efficiency reduction caused by frequent interaction between the coordinator node and the GTM is improved. efficiency of transaction processing.
Patent Information
- Application Number
- CN202411453144.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-17
- Publication Date
- 2024-11-15
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
In distributed databases, frequent interaction between coordinator nodes and global transaction managers (GTMs) leads to reduced transaction management efficiency, and the prior art has failed to effectively solve this problem.
By establishing a secure peer connection between the global transaction manager and the coordinator node, creating a target thread, and sending multiple transaction IDs in batches upon receiving an ID acquisition request, the coordinator node can use these transaction IDs to allocate new transactions to new transactions ID, reduce the number of interactions.
It effectively reduces the number of interactions between the coordinator node and the GTM, improves the efficiency of transaction management, and optimizes the distributed transaction processing capabilities.
Smart Images

Figure CN118964494A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of distributed databases, and in particular to a transaction processing method, apparatus, device and medium for a distributed database. Background Art
[0002] GTM (Global Transaction Manager) is a resident process in the system. Its main function is to distribute information such as GXID (transaction ID), Snap Shot, and Sequence. In order to ensure the consistency and global uniqueness of transaction identifiers, there is only one master GTM in the distributed database cluster to provide services, and a master-slave mode is adopted. Generally, there is at least one backup machine. In order to ensure that the transaction number is not lost, the master and backup GTMs need to synchronize the current transaction number information.
[0003] In the distributed database architecture, GTM mainly interacts with each coordinator node (CN). In a high-concurrency environment, each coordinator node will frequently interact with GTM. At this time, GTM can no longer allocate so many transaction numbers and cannot process so many requests. The frequent interaction between each coordinator node and GTM greatly reduces the efficiency of transaction management.
[0004] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention
[0005] The present application provides a transaction processing method, apparatus, device and medium for a distributed database to solve the above-mentioned technical problem that "frequent interactions between coordinator nodes and GTM greatly reduce the efficiency of transaction management".
[0006] According to one aspect of an embodiment of the present application, the present application provides a transaction processing method for a distributed database, which is applied to a global transaction manager, and the method includes: upon receiving a connection request sent by any coordinator node, establishing a secure peer connection with the coordinator node; creating a target thread for the coordinator node; and upon receiving an ID acquisition request by the target thread, sending multiple transaction IDs to the coordinator node in batches, so that the coordinator node uses multiple transaction IDs to allocate transaction IDs to new transactions when receiving a new transaction creation request.
[0007] Optionally, after creating a target thread for the coordinator node, the method further includes: upon receiving a transaction management request issued by the coordinator node, parsing and recording the transaction management request through the target thread, wherein the transaction management request is a request issued by each application and received by the coordinator node; processing the transaction management request through the target thread to obtain a processing result; encapsulating the processing result, and returning the encapsulated processing result to the coordinator node.
[0008] Optionally, after creating a target thread for the coordinator node, the method further includes: receiving status information of each transaction sent by the coordinator node, wherein each status information carries the isolation level of the corresponding transaction; generating a global snapshot for each transaction according to the isolation level of each transaction; and sending the global snapshot of each transaction to the coordinator node.
[0009] According to another aspect of an embodiment of the present application, the present application provides a transaction processing method for a distributed database, which is applied to a coordinator node, and the method includes: sending a connection request to a global transaction manager to establish a secure peer-to-peer connection with the global transaction manager, wherein the global transaction manager creates a target thread after establishing the peer-to-peer connection; sending an ID acquisition request to the target thread of the global transaction manager through the peer-to-peer connection; receiving multiple transaction IDs returned by the target thread of the global transaction manager, and storing the multiple transaction IDs in a local cache queue; and allocating transaction IDs through the local cache queue when a new transaction request issued by an application is received.
[0010] Optionally, after establishing a secure peer-to-peer connection with the global transaction manager, the method further includes: when a status update of the transaction is detected, obtaining current status information of the transaction; sending the status information of the transaction to the global transaction manager so that the global transaction manager generates a global snapshot of the transaction based on the status information, wherein the status information carries the isolation level of the transaction; and receiving the global snapshot of the transaction returned by the global transaction manager.
[0011] Optionally, after allocating a transaction ID for the new transaction through the local cache queue, the method further includes: monitoring the number of transaction IDs remaining in the local cache queue; if the number of transaction IDs is less than or equal to a quantity threshold, generating an ID acquisition request; and sending the ID acquisition request to the global transaction manager.
[0012] According to another aspect of an embodiment of the present application, the present application provides a transaction processing device for a distributed database, which is applied to a global transaction manager, including: a first connection module, which is used to establish a secure peer-to-peer connection with a coordinator node when a connection request sent by any coordinator node is received; a creation module, which is used to create a target thread for the coordinator node; a first sending module, which is used to send multiple transaction IDs to the coordinator node in batches when the target thread receives an ID acquisition request, so that the coordinator node can use multiple transaction IDs to allocate transaction IDs to new transactions when receiving a new transaction request.
[0013] According to another aspect of an embodiment of the present application, the present application provides a transaction processing device for a distributed database, which is applied to a coordinator node, and includes: a second connection module, which is used to send a connection request to a global transaction manager to establish a secure peer-to-peer connection with the global transaction manager, wherein the global transaction manager creates a target thread after establishing the peer-to-peer connection; a second sending module, which is used to send an ID acquisition request to the target thread of the global transaction manager through the peer-to-peer connection; a receiving module, which is used to receive multiple transaction IDs returned by the target thread of the global transaction manager, and store the multiple transaction IDs in a local cache queue; and an allocation module, which is used to allocate transaction IDs through the local cache queue when a new transaction request issued by an application is received.
[0014] According to another aspect of an embodiment of the present application, the present application provides an electronic device, including a memory, a processor, a communication interface and a communication bus, wherein the memory stores a computer program that can be run on the processor, the memory and the processor communicate through the communication bus and the communication interface, and the steps of the above method are implemented when the processor executes the computer program.
[0015] According to another aspect of an embodiment of the present application, the present application also provides a computer-readable medium having a non-volatile program code executable by a processor, and the program code enables the processor to execute the above method.
[0016] The above technical solution provided by the embodiment of the present application has the following advantages compared with the related art: The present application adopts a transaction processing method for a distributed database applied to a global transaction manager, including: in the case of receiving a connection request sent by any coordinator node, establishing a secure peer-to-peer connection with the coordinator node; creating a target thread for the coordinator node; in the case of receiving an ID acquisition request by the target thread, sending multiple transaction IDs to the coordinator node in batches, so that the coordinator node uses multiple transaction IDs to allocate transaction IDs to new transactions when receiving a transaction creation request. By establishing a secure peer-to-peer connection with the coordinator node, and then creating a target thread specifically to receive and process transaction requests sent by the coordinator node, and sending transaction ID numbers to the coordinator node in batches, the number of interactions can be reduced, solving the problem that the frequent interactions between each coordinator node and the GTM greatly reduce the efficiency of transaction management. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0018] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related technologies, the drawings required for use in the embodiments or the related technical descriptions are briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0019] Figure 1 A flowchart of a transaction processing method for a distributed database applied to a global transaction manager according to an optional embodiment of the present application; Figure 2 An optional architecture diagram of a distributed database provided according to an embodiment of the present application; Figure 3 A flowchart of a transaction processing method for a distributed database applied to a coordinator node according to an optional embodiment of the present application; Figure 4 A block diagram of an optional transaction processing device for a distributed database applied to a global transaction manager according to an embodiment of the present application; Figure 5 A block diagram of an optional transaction processing device for a distributed database applied to a coordinator node according to an embodiment of the present application; Figure 6 A schematic diagram of an optional electronic device structure provided in an embodiment of the present application. DETAILED DESCRIPTION
[0020] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, 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 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 making creative work are within the scope of protection of this application.
[0021] In the subsequent description, the suffixes such as "module", "component" or "unit" used to represent elements are only used to facilitate the description of the present application and have no specific meaning. Therefore, "module" and "component" can be used interchangeably.
[0022] GTM (Global Transaction Manager) is a resident process in the system. Its main function is to distribute information such as GXID (transaction ID), Snap Shot, and Sequence. In order to ensure the consistency and global uniqueness of transaction identifiers, there is only one master GTM in the distributed database cluster to provide services, and a master-slave mode is adopted. Generally, there is at least one backup machine. In order to ensure that the transaction number is not lost, the master and backup GTMs need to synchronize the current transaction number information.
[0023] In the distributed database architecture, GTM mainly interacts with each coordinator node (CN). In a high-concurrency environment, each coordinator node will frequently interact with GTM. At this time, GTM can no longer allocate so many transaction numbers and cannot process so many requests. The frequent interaction between each coordinator node and GTM greatly reduces the efficiency of transaction management.
[0024] In order to solve the problems mentioned in the background technology, according to one aspect of the embodiment of the present application, a transaction processing method of a distributed database is provided, which is applied to a global transaction manager, such as Figure 1 As shown, including: Step 101, upon receiving a connection request sent by any coordinator node, establishing a secure peer-to-peer connection with the coordinator node; Step 103, creating a target thread for the coordinator node; Step 105 , when the target thread receives the ID acquisition request, multiple transaction IDs are sent to the coordinator node in batches, so that the coordinator node allocates transaction IDs to new transactions using the multiple transaction IDs when receiving the transaction creation request.
[0025] The global transaction manager opens a port to accept connection requests from each coordinator node. When the global transaction manager accepts the connection, it establishes a secure peer connection with the coordinator node that issued the connection request, and then creates a target thread to process the request issued by the coordinator backend of the coordinator node to the global transaction manager.
[0026] Whenever a new coordinator node establishes a peer connection with the global transaction manager, a dedicated thread is created to receive and process various transaction requests issued by the coordinator node. Threads are created only according to the connected coordinator node. Compared with the prior art, the number of threads created needs to correspond to the number of coordinator nodes and the number of connections between the coordinator node and the application, which can greatly reduce the number of interactions and the amount of data. For example, if the number of coordinator nodes is 10, each coordinator node has 100 connections from the application, and the global transaction manager must have thousands of GTM threads corresponding to it. If each backend issues 25 transactions per second, and each transaction contains 5 statements, the total number of interactions between GTM and 10 coordinator nodes to provide global snapshots can be estimated as: 10×100×25×5=125000. Because each coordinator node has 100 backends, if GXID is a 32-bit integer, the length of the snapshot list will be 4×100×10=4000Bytes. Therefore, the global transaction manager must send about 600MB of data in one second to support this scale.
[0027] For example, if the number of coordinator nodes is 10, the corresponding number of GTM threads is also only 10. The default length of the GXID cache queue is 5, so the length of the snapshot list will be 4×5×10=200Bytes. Through the technical solution provided by this application, the number of GTM connections and the size of data packets will be greatly reduced.
[0028] After the coordinator node sends an ID acquisition request, the global transaction manager generates multiple transaction IDs in batches and then sends them to the coordinator node at one time. In this way, the coordinator node does not need to send a request to the global transaction manager every time it receives a new transaction request from an application. Instead, it can directly allocate IDs for transactions through multiple cached transaction IDs, which can reduce the number of interactions between the coordinator node and the global transaction manager.
[0029] Through the technical solution provided in this application, the interaction mode between the coordinator node and the global transaction manager can be optimized from a transaction serial mode to an asynchronous mode, thereby reducing the number of network interactions and improving the execution efficiency of distributed transaction management.
[0030] As an optional embodiment, after creating a target thread for the coordinator node, the method further includes: upon receiving a transaction management request issued by the coordinator node, parsing and recording the transaction management request through the target thread, wherein the transaction management request is a request issued by each application and received by the coordinator node; processing the transaction management request through the target thread to obtain a processing result; encapsulating the processing result, and returning the encapsulated processing result to the coordinator node.
[0031] After creating a target thread for the coordinator node, the target thread can receive the transaction management request issued by the corresponding coordinator node, and then call the corresponding processing logic to process the transaction management request to obtain the processing result.
[0032] Transaction management requests include but are not limited to snapshot acquisition requests, transaction commit requests, transaction rollback requests, transaction status query and snapshot update requests.
[0033] The target thread is used to record and process each transaction management request issued by the coordinator node. This thread processing mechanism enables the global transaction manager to handle connections and requests from multiple coordinator nodes at the same time, improving the system's concurrent processing capability and efficiency.
[0034] As an optional embodiment, after creating a target thread for the coordinator node, the method also includes: receiving status information of each transaction sent by the coordinator node, wherein each status information carries the isolation level of the transaction to which it belongs; generating a global snapshot for each transaction according to the isolation level of each transaction; and sending the global snapshot of each transaction to the coordinator node.
[0035] Whenever the status information of a transaction is received, it is necessary to parse the status information first to determine the isolation level of the transaction. According to the isolation level of each transaction, the global transaction manager generates a global snapshot for the transaction. This global snapshot may include a record of the database status at the start of the transaction, or dynamically maintain the data version visible to the transaction according to the requirements of the isolation level.
[0036] For example, the global snapshot JSON structure is as follows: { Nodename: CN1 { SnapShot: (xmin:xmax:xip_list) } Nodename: CN2 { SnapShot: (xmin:xmax:xip_list) } } Among them, CN1 represents coordinator node 1, and CN2 represents coordinator node 2.
[0037] The transaction isolation level is an important attribute in transaction processing. It determines the visibility and concurrency control between transactions. Common isolation levels include Read Uncommitted, Read Committed, Repeatable Read, and Serializable.
[0038] The global transaction manager also needs to manage the lifecycle of the snapshot to ensure that related resources are released after the transaction is committed or rolled back.
[0039] The global snapshot of each transaction is sent back to the coordinator node, which can use these global snapshots to coordinate the submission or rollback process of distributed transactions to ensure data consistency and integrity.
[0040] The core components provided by this application include: a global transaction manager, which coordinates global transactions across multiple databases. There can be one or more global transaction managers; GTL (Global Transaction Log), which represents the transaction request queue of the global transaction manager. The order of transaction requests in GTL determines the relative serializability order between global transactions. The persistence of GTL is optional; transaction queue manager: the background process interacts with the global transaction manager and maintains the queue in the global transaction manager in real time.
[0041] The present application adopts a transaction processing method for a distributed database applied to a global transaction manager, including: in the case of receiving a connection request sent by any coordinator node, establishing a secure peer-to-peer connection with the coordinator node; creating a target thread for the coordinator node; in the case of receiving an ID acquisition request by the target thread, sending multiple transaction IDs to the coordinator node in batches, so that the coordinator node uses multiple transaction IDs to allocate transaction IDs to new transactions when receiving a transaction creation request. By establishing a secure peer-to-peer connection with the coordinator node, and then creating a target thread specifically to receive and process transaction requests sent by the coordinator node, and sending transaction ID numbers to the coordinator node in batches, the number of interactions can be reduced, solving the problem that the frequent interactions between each coordinator node and the GTM greatly reduce the efficiency of transaction management.
[0042] Figure 2The architecture diagram of the distributed database provided for this application, as shown in the figure, includes a global transaction manager and a coordinator node. The global transaction manager can be connected to multiple coordinator nodes (only one is shown in the figure), each coordinator node corresponds to a global catalog (mainly used to store metadata of the system), each coordinator node corresponds to multiple data nodes, and each data node has local data (i.e., locally stored data).
[0043] Next, the transaction processing method of the distributed database applied to the coordinator node is described.
[0044] According to another aspect of the embodiment of the present application, a transaction processing method for a distributed database is also provided, which is applied to a coordinator node, such as Figure 3 As shown, including: Step 301, sending a connection request to the global transaction manager to establish a secure peer-to-peer connection with the global transaction manager, wherein the global transaction manager creates a target thread after establishing the peer-to-peer connection; Step 303, sending an ID acquisition request to the target thread of the global transaction manager through a peer connection; Step 305, receiving multiple transaction IDs returned by the target thread of the global transaction manager, and storing the multiple transaction IDs in the local cache queue; Step 307: When a transaction creation request is received from an application, a transaction ID is allocated through a local cache queue.
[0045] After the coordinator node establishes a secure peer connection with the global transaction manager, the global transaction manager creates a target thread to process related transaction requests for the coordinator node.
[0046] After sending an ID acquisition request to the target thread of the global transaction manager, multiple transaction IDs can be obtained at one time, and then the transaction IDs are saved in the local cache queue. Whenever a new transaction request is received from an application, there is no need to send a request to the global transaction manager to obtain the ID of the new transaction. Instead, the transaction ID can be extracted from the local cache queue and assigned to the new transaction. When each application connects to the coordinator node and obtains a transaction ID, it can obtain it from the local cache queue.
[0047] After a transaction ID is assigned to a new transaction, when the relevant information of the new transaction is sent to the global transaction manager for the first time, the correspondence between the transaction and the ID and the detailed information of the new transaction need to be sent to the global transaction manager.
[0048] As an optional embodiment, when establishing a secure peer-to-peer connection with a global transaction manager, the method further includes: when detecting that a status update of a transaction occurs, obtaining current status information of the transaction; sending the status information of the transaction to the global transaction manager so that the global transaction manager generates a global snapshot of the transaction based on the status information, wherein the status information carries an isolation level of the transaction; and receiving the global snapshot of the transaction returned by the global transaction manager.
[0049] The status update of a transaction can be triggered by a variety of operations, such as data modification, transaction commit or rollback requests. During the transaction execution process, it is necessary to continuously monitor the status changes of the transaction, which is usually achieved through transaction management components or middleware. They will track the current status of each transaction (such as active, ready to commit, committed, rolled back, etc.).
[0050] Once a status update is detected, the current status information of the transaction needs to be recorded, including the transaction ID of the current transaction, the current status (such as active, ready to commit, etc.), the isolation level of the transaction, etc.
[0051] Before sending the status information, it needs to be encapsulated into a format suitable for transmission (such as JSON, XML, etc.) and attached with necessary metadata (such as transaction ID, timestamp, etc.). After receiving the status information, the global transaction manager will parse it to obtain relevant data, and then generate a global snapshot of the transaction based on the transaction status and isolation level and return it to the coordinator node.
[0052] By monitoring transaction status, capturing and sending status information, and generating and storing global snapshots, the system can effectively manage transactions in complex distributed environments.
[0053] As an optional embodiment, after allocating a transaction ID for a new transaction through a local cache queue, the method further includes: monitoring the number of transaction IDs remaining in the local cache queue; if the number of transaction IDs is less than or equal to a quantity threshold, generating an ID acquisition request; and sending the ID acquisition request to a global transaction manager.
[0054] It is necessary to monitor the number of transaction IDs in the local cache queue in real time, and send an ID acquisition request to the global transaction manager in time to obtain the transaction ID when the inventory is insufficient. It can be understood that the coordinator node continuously consumes, and the global transaction manager continuously produces and stores it in the local cache queue of the coordinator node.
[0055] Optionally, the expected number of IDs can be set according to the actual capacity of the local cache queue, and the expected number of IDs can be carried in the ID acquisition request, so that the number of IDs returned in batches can meet the storage requirements to the greatest extent.
[0056] The quantity threshold can be set according to the storable quantity in the local cache queue, and this application does not limit the specific value of the quantity threshold.
[0057] The present application adopts a transaction processing method for a distributed database applied to a coordinator node, including: sending a connection request to a global transaction manager to establish a secure peer-to-peer connection with the global transaction manager, wherein the global transaction manager creates a target thread after establishing the peer-to-peer connection; sending an ID acquisition request to the target thread of the global transaction manager through the peer-to-peer connection; receiving multiple transaction IDs returned by the target thread of the global transaction manager, and storing the multiple transaction IDs in a local cache queue; and assigning transaction IDs through the local cache queue when a new transaction request issued by an application is received. By acquiring transaction IDs in batches from the global transaction manager and storing them in the local cache queue, and then directly assigning transaction IDs through the local cache queue, it is not necessary to send a request to the global transaction manager to obtain the transaction ID every time, thereby reducing the number of interactions and solving the problem that frequent interactions between the coordinator node and the GTM greatly reduce the efficiency of transaction management.
[0058] According to another aspect of the embodiment of the present application, the present application provides a transaction processing device for a distributed database, which is applied to a global transaction manager, such as Figure 4 As shown, including: A first connection module 402 is configured to establish a secure peer-to-peer connection with the coordinator node upon receiving a connection request sent by any coordinator node; A creation module 404 is used to create a target thread for the coordinator node; The first sending module 406 is used to send multiple transaction IDs in batches to the coordinator node when the target thread receives the ID acquisition request, so that the coordinator node allocates transaction IDs to new transactions using the multiple transaction IDs when receiving the transaction creation request.
[0059] It should be noted that the first connection module 402 in this embodiment can be used to execute step 101 in the embodiment of the present application, the creation module 404 in this embodiment can be used to execute step 103 in the embodiment of the present application, and the first sending module 406 in this embodiment can be used to execute step 105 in the embodiment of the present application.
[0060] Optionally, the device also includes a first processing module, which is used to parse and record the transaction management request through the target thread after creating a target thread for the coordinator node and when receiving the transaction management request issued by the coordinator node, wherein the transaction management request is a request issued by each application and received by the coordinator node; process the transaction management request through the target thread to obtain a processing result; encapsulate the processing result, and return the encapsulated processing result to the coordinator node.
[0061] Optionally, the device also includes a second processing module, which is used to receive status information of each transaction sent by the coordinator node after creating a target thread for the coordinator node, wherein each status information carries the isolation level of the transaction to which it belongs; generate a global snapshot for each transaction according to the isolation level of each transaction; and send the global snapshot of each transaction to the coordinator node.
[0062] It should be noted here that the examples and application scenarios implemented by the above modules and corresponding steps are the same, but are not limited to the contents disclosed in the above embodiments.
[0063] According to another aspect of the embodiment of the present application, the present application provides a transaction processing device for a distributed database, which is applied to a coordinator node, such as Figure 5 As shown, including: A second connection module 502 is used to send a connection request to the global transaction manager to establish a secure peer-to-peer connection with the global transaction manager, wherein the global transaction manager creates a target thread after establishing the peer-to-peer connection; A second sending module 504 is used to send an ID acquisition request to a target thread of the global transaction manager through a peer connection; A receiving module 506 is used to receive multiple transaction IDs returned by the target thread of the global transaction manager, and store the multiple transaction IDs in a local cache queue; The allocation module 508 is used to allocate a transaction ID through a local cache queue when receiving a transaction creation request sent by an application.
[0064] It should be noted that the second connection module 502 in this embodiment can be used to execute step 301 in the embodiment of the present application, the second sending module 504 in this embodiment can be used to execute step 303 in the embodiment of the present application, the receiving module 506 in this embodiment can be used to execute step 305 in the embodiment of the present application, and the allocation module 508 in this embodiment can be used to execute step 307 in the embodiment of the present application.
[0065] Optionally, the device also includes a third processing module, which is used to, after establishing a secure peer-to-peer connection with the global transaction manager, obtain the current state information of the transaction when a state update of the transaction is detected; send the state information of the transaction to the global transaction manager so that the global transaction manager generates a global snapshot of the transaction based on the state information, wherein the state information carries the isolation level of the transaction; and receive the global snapshot of the transaction returned by the global transaction manager.
[0066] Optionally, the device also includes a fourth processing module, which is used to monitor the number of transaction IDs remaining in the local cache queue after allocating a transaction ID to a new transaction through the local cache queue; if the number of transaction IDs is less than or equal to a quantity threshold, generate an ID acquisition request; and send the ID acquisition request to the global transaction manager.
[0067] It should be noted here that the examples and application scenarios implemented by the above modules and corresponding steps are the same, but are not limited to the contents disclosed in the above embodiments.
[0068] According to another aspect of the embodiments of the present application, the present application provides an electronic device, such as Figure 6 As shown, it includes a memory 601, a processor 603, a communication interface 605 and a communication bus 607. The memory 601 stores a computer program that can be run on the processor 603. The memory 601 and the processor 603 communicate through the communication interface 605 and the communication bus 607. When the processor 603 executes the computer program, the steps of the above method are implemented.
[0069] The memory and processor in the above electronic device communicate via a communication bus and a communication interface. The communication bus may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus may be divided into an address bus, a data bus, a control bus, etc.
[0070] The memory may include a random access memory (RAM) or a non-volatile memory, such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0071] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0072] According to another aspect of the embodiments of the present application, a computer-readable medium having a non-volatile program code executable by a processor is provided.
[0073] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments, and this embodiment will not be described in detail here.
[0074] When the embodiments of the present application are specifically implemented, reference may be made to the above-mentioned embodiments, which have corresponding technical effects.
[0075] It is understood that the embodiments described herein may be implemented in hardware, software, firmware, middleware, microcode, or a combination thereof. For hardware implementation, the processing unit may be implemented in one or more application specific integrated circuits (ASIC), digital signal processors (DSP), digital signal processing devices (DSPD), programmable logic devices (PLD), field programmable gate arrays (FPGA), general purpose processors, controllers, microcontrollers, microprocessors, other electronic units for performing the functions described in the present application, or a combination thereof.
[0076] For software implementation, the technology described herein can be implemented by a unit that performs the functions described herein. The software code can be stored in a memory and executed by a processor. The memory can be implemented in the processor or outside the processor.
[0077] 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.
[0078] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0079] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the modules is only a logical function division. There may be other division methods in actual implementation, such as multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0080] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0081] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0082] If the function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium, including several instructions to make a computer device (which can be a personal computer, a server, or a network device, etc.) perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a ROM, a RAM, a magnetic disk or an optical disk. It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply that there is any such actual relationship or order between these entities or operations. Moreover, the term "include", "include" or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements includes not only those elements, but also includes other elements that are not explicitly listed, or also includes elements inherent to such a process, method, article or device. Without more constraints, an element defined by the phrase "comprising a..." does not exclude the existence of other identical elements in the process, method, article or apparatus comprising the element.
[0083] The above description is only a specific implementation of the present application, so that those skilled in the art can understand or implement the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest range consistent with the principles and novel features applied for herein.
Claims
1. A transaction processing method for a distributed database, It is characterized in that Applied to a global transaction manager, the method comprises: Upon receiving a connection request sent by any coordinator node, establishing a secure peer-to-peer connection with the coordinator node; Creating a target thread for the coordinator node; When the target thread receives an ID acquisition request, multiple transaction IDs are sent to the coordinator node in batches, so that the coordinator node allocates a transaction ID to a new transaction using the multiple transaction IDs when receiving a transaction creation request.
2. The method according to claim 1, It is characterized in that After creating a target thread for the coordinator node, the method further includes: When receiving a transaction management request sent by the coordinator node, parsing and recording the transaction management request through the target thread, wherein the transaction management request is a request sent by each application and received by the coordinator node; Processing the transaction management request through the target thread to obtain a processing result; The processing result is encapsulated, and the encapsulated processing result is returned to the coordinator node.
3. The method according to claim 1, It is characterized in that After creating a target thread for the coordinator node, the method further includes: Receiving status information of each transaction sent by the coordinator node, wherein each status information carries the isolation level of the corresponding transaction; Generating a global snapshot for each transaction according to the isolation level of each transaction; The global snapshot of each transaction is sent to the coordinator node.
4. A transaction processing method for a distributed database, It is characterized in that Applied to a coordinator node, the method comprises: Sending a connection request to a global transaction manager to establish a secure peer-to-peer connection with the global transaction manager, wherein the global transaction manager creates a target thread after establishing the peer-to-peer connection; Sending an ID acquisition request to the target thread of the global transaction manager through the peer connection; receiving a plurality of transaction IDs returned by the target thread of the global transaction manager, and storing the plurality of transaction IDs in a local cache queue; When a transaction creation request is received from an application, a transaction ID is allocated through the local cache queue.
5. The method according to claim 4, It is characterized in that After establishing a secure peer-to-peer connection with the global transaction manager, the method further comprises: When a status update of a transaction is detected, obtaining current status information of the transaction; Sending the state information of the transaction to the global transaction manager, so that the global transaction manager generates a global snapshot of the transaction according to the state information, wherein the state information carries the isolation level of the transaction; The global snapshot of the transaction is received from the global transaction manager.
6. The method according to claim 4, It is characterized in that After allocating a transaction ID for the new transaction through the local cache queue, the method further includes: Monitoring the number of transaction IDs remaining in the local cache queue; If the number of transaction IDs is less than or equal to the number threshold, generating the ID acquisition request; The ID acquisition request is sent to the global transaction manager.
7. A transaction processing device for a distributed database, It is characterized in that Applies to the global transaction manager, including: A first connection module, configured to establish a secure peer-to-peer connection with any coordinator node upon receiving a connection request sent by the coordinator node; A creation module, used to create a target thread for the coordinator node; The first sending module is used to send multiple transaction IDs in batches to the coordinator node when the target thread receives an ID acquisition request, so that the coordinator node allocates transaction IDs to new transactions using the multiple transaction IDs when receiving a transaction creation request.
8. A transaction processing device for a distributed database, It is characterized in that Applied to the coordinator node, including: A second connection module, configured to send a connection request to a global transaction manager to establish a secure peer-to-peer connection with the global transaction manager, wherein the global transaction manager creates a target thread after establishing the peer-to-peer connection; A second sending module, configured to send an ID acquisition request to the target thread of the global transaction manager through the peer connection; A receiving module, configured to receive a plurality of transaction IDs returned by the target thread of the global transaction manager, and store the plurality of transaction IDs in a local cache queue; The allocation module is used to allocate a transaction ID through the local cache queue when receiving a transaction creation request sent by an application.
9. An electronic device comprising a memory, a processor, a communication interface and a communication bus, wherein the memory stores a computer program that can be run on the processor, and the memory and the processor communicate through the communication bus and the communication interface. It is characterized in that When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer readable medium having a non-volatile program code executable by a processor, It is characterized in that The program code enables the processor to execute the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Transaction identification operation method and system, and computer readable storage medium
CN108984571A
Data processing method and system
CN114254036A
Decentralized distributed database consistency
US20180107703A1
