Data definition language processing method and device, equipment and medium
By using computing nodes in a distributed database to coordinate the operations of data nodes, ensuring the atomicity and global consistency of each node when executing DDL, the problem of difficult atomicity during execution of DDL in a distributed database is solved, and efficient operation and data management of distributed databases are realized.
Patent Information
- Application Number
- CN202411990527.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-31
- Publication Date
- 2025-04-29
AI Technical Summary
In distributed databases, the Data Definition Language (DDL) is difficult to ensure atomicity when modifying the table structure, especially when the table locks between nodes are inconsistent, resulting in some nodes being successful and some nodes being failed, and the atomicity between nodes cannot be guaranteed.
After receiving the DDL instruction, the computing node sends a preparation request to each data node, and issues a lock acquisition request or submits a request when specific conditions are met, ensuring that the data node can correctly process and feedback the results at each stage, avoid forcibly applying for form locks, and ensure global consistency.
It ensures the atomicity of each data node when executing DDL, avoids the problem of metadata inconsistency between multiple nodes, and ensures efficient operation and data management of distributed databases.
Smart Images

Figure CN119903068A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of distributed technology, and in particular to a method, device, equipment and medium for processing a data definition language. Background Art
[0002] The Data Definition Language (DDL) of a distributed database is a set of languages used to define, modify, and delete the structure and properties of various objects in a distributed database. However, it is necessary to consider special factors such as the distribution of data in a distributed environment, coordination between nodes, and data consistency to ensure the correct creation, change, and maintenance of database objects on multiple nodes, thereby supporting the efficient operation and data management of distributed database systems.
[0003] On an ordinary stand-alone database, executing the data definition language can well guarantee atomicity. Atomicity means that the statements in a transaction can only succeed or fail together, and there is no intermediate state of partial failure and partial success.
[0004] However, in a distributed database, a command may be executed successfully on some nodes and failed on some nodes. In this case, in order to ensure atomicity, you can choose to retry the failed nodes to ensure that all nodes succeed, or choose to roll back the successful nodes to make all nodes fail. However, when the data definition language modifies the table structure, it is difficult to roll back the DDL statements that have been executed successfully, so as to achieve the effect of making all nodes fail.
[0005] When modifying the table structure in a distributed database, a table lock may be added to the table for a certain period of time. However, it is difficult to ensure that the table locks on each node are consistent in a distributed database. In fact, the table locks of these nodes are inconsistent most of the time. In this case, a DDL statement is likely to be successfully executed on some nodes and fail on nodes that cannot obtain table locks, resulting in the inability to ensure atomicity between nodes. Summary of the invention
[0006] The present invention provides a method, device, equipment and medium for processing a data definition language, which can ensure the atomicity of each data node when executing the data definition language and avoid the problem of inconsistent metadata between multiple nodes.
[0007] According to one aspect of the present invention, a method for processing a data definition language is provided, which is executed by a computing node and a data node in a distributed database system, and includes:
[0008] After receiving the DDL instruction sent by the application side, the computing node sends a prepare request to each data node in the distributed database system, and when it is determined that the second or third stage start conditions are met, a lock acquisition request or a commit request is sent to each data node;
[0009] When receiving the preparation request, the data node enters the first phase of operation and sends the operation result of the first phase to the computing node;
[0010] When receiving the lock acquisition request, the data node applies for a write lock of the target table, and after the write lock application is successful, sends a second-stage completion message to the computing node;
[0011] When the commit request is received, the data node executes the commit operation of the target table, and after the commit is completed, sends a third-stage completion message to the computing node.
[0012] According to another aspect of the present invention, there is provided a data definition language processing device, which is executed by a data node in a distributed database system, comprising:
[0013] The request sending module is used to send a preparation request to each data node in the distributed database system through the computing node after receiving the DDL instruction sent by the application side, and send a lock acquisition request or a submission request to each data node when it is determined that the second stage or third stage start conditions are met;
[0014] The first stage execution module is used to enter the first stage operation through the data node when receiving the preparation request, and send the operation result of the first stage to the computing node;
[0015] The second-stage execution module is used to apply for a write lock of the target table through the data node when receiving the lock acquisition request, and send a second-stage completion message to the computing node after the write lock application is successful;
[0016] The third stage execution module is used to execute the submission operation of the target table through the data node when receiving the submission request, and send a third stage completion message to the computing node after completing the submission.
[0017] According to another aspect of the present invention, there is provided an electronic device, the electronic device comprising:
[0018] at least one processor; and
[0019] a memory communicatively connected to the at least one processor; wherein,
[0020] The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the data definition language processing method described in any embodiment of the present invention.
[0021] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the data definition language processing method described in any embodiment of the present invention when executed.
[0022] The technical solution of the embodiment of the present invention uses a computing node to send a preparation request to each data node in the distributed database system after receiving the DDL instruction sent by the application side, and when it is determined that the second stage or the third stage start condition is met, a lock acquisition request or a submission request is issued to each data node, and when the data node receives the preparation request, the first stage operation is entered, and the operation result of the first stage is sent to the computing node, when the lock acquisition request is received, a write lock of the target table is applied, and after the write lock application is successful, a second stage completion message is sent to the computing node, when the submission request is received, the submission operation of the target table is performed, and after the submission is completed, a third stage completion message is sent to the computing node. In this way, during the execution of DDL, the data node application for table locks will not be interfered, and when the data node cannot apply for the table lock, the table lock will not be forcibly applied to avoid affecting the business, but the atomicity in the distributed database can still be guaranteed, and global consistency is guaranteed in each stage, avoiding the problem of inconsistent metadata between multiple nodes.
[0023] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0025] Figure 1 is a flow chart of a data definition language processing method provided according to the first embodiment of the present invention;
[0026] Figure 2 is a flowchart of another data definition language processing method provided according to the second embodiment of the present invention;
[0027] Figure 3 is a schematic diagram of the structure of a data definition language processing device provided according to Embodiment 3 of the present invention;
[0028] Figure 4 The invention is a schematic diagram of the structure of an electronic device for implementing the method for processing a data definition language according to an embodiment of the present invention. DETAILED DESCRIPTION
[0029] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0030] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0031] Embodiment 1
[0032] Figure 1 This is a flowchart of a data definition language processing method provided in the first embodiment of the present invention. This embodiment can be applied to the case where the atomicity of each data node is guaranteed when executing DDL statements in a distributed database. The method can be executed by a data definition language processing device, which can be implemented in the form of hardware and / or software and can generally be configured in a distributed system with data processing functions. Figure 1 As shown, the method includes:
[0033] S110. After receiving the DDL instruction sent by the application side, the computing node sends a prepare request to each data node in the distributed database system, and when it is determined that the start conditions of the second stage or the third stage are met, a lock acquisition request or a submission request is issued to each data node.
[0034] Optionally, computing nodes can be used to perform various computing tasks in a distributed database system, such as data processing, logical operations, request processing and other related operations. Computing nodes can interact with the application side and with data nodes. The application side can send DDL instructions to the computing nodes to process the data in the distributed database system, such as modifying the table structure. The computing nodes can parse the DDL sent by the application side and send the parsing results to the data nodes.
[0035] Optionally, a preparation request is sent to each data node in the distributed database system to notify each data node to enter the preparation phase. The preparation phase is the first phase of executing DDL instructions. The preparation phase is for basic operations such as verification and preparation, and the preparation phase time is relatively short.
[0036] Optionally, the prepare request may be sent to the main thread of each data node through the computing node, and the main thread of the data node may be used to interact with the computing node.
[0037] Optionally, after each stage of execution is completed, the data node will feedback the execution result to the computing node through the main thread of each data node. When the computing node determines that each stage is completed, it determines that the start conditions of the next stage are met and sends the execution request of the next stage to each data node.
[0038] Optionally, in the embodiment described in the present invention, the execution of DDL instructions is divided into three stages. In the first stage, each data node enters the preparation stage and the execution stage in turn. After it is determined that each data node has completed the DDL operation, it enters the second stage. In the second stage, each data node attempts to obtain the write lock of the table. After all data nodes have obtained the write lock of the table, it is determined that each current data node meets the submission conditions, and then it enters the third stage. In the third stage, each data node initiates a submission operation to complete the DDL instruction.
[0039] It should also be noted that, through the computing node, after receiving the DDL instruction, a preparation request will be sent to each data node first. After step S120 is executed, it is determined that the second stage start conditions are met, and a lock acquisition request is sent to each data node. After step S130 is completed, it is determined that the third stage start conditions are met, and a submission request is sent to each data node.
[0040] S120. When a preparation request is received through the data node, the first phase of operation is entered, and the operation result of the first phase is sent to the computing node.
[0041] Wherein, after receiving the preparation request through the data node, the following may also be included:
[0042] Through the main thread in the data node, create a child thread in the data node;
[0043] The main thread is used to exchange information with the computing node, and the child thread is used to perform write lock operations, table processing operations, and exchange information with the main thread.
[0044] It can be understood that the sub-thread in the data node is used to execute DDL operations, and the main thread is used to interact with the computing node according to the execution status information returned by the sub-thread. The main thread can also be used to forward the instructions or requests sent by the computing node to the sub-thread. The operations can be performed independently through the main thread and the sub-thread. When the DDL operation needs to be executed, it can be executed directly through the sub-thread without occupying the processing resources of the main thread.
[0045] Optionally, after the main thread in the data node receives the prepare request, it sends the prepare request to the child thread, and the child thread applies for a write lock for the table from the data node. When the child thread successfully applies for the write lock, it feeds back a successful application to the main thread, and the main thread sends it to the computing node. When the child thread fails to apply for the write lock, it feeds back a failed application to the main thread, and the main thread sends it to the computing node.
[0046] Optionally, after the child thread applies for the write lock, it is unable to add, delete, modify, or query the original table in the database.
[0047] Optionally, when the computing node receives application success messages fed back by all data nodes, it sends execution instructions to each data node, notifying each data node to execute the DDL instruction. When the settlement node receives at least one application failure message, it notifies all data nodes to perform the data node rollback operation.
[0048] Optionally, a data node rollback operation can roll back each data node to a state before receiving the prepare request.
[0049] Optionally, when the main thread of the data node receives an execution instruction sent by the computing node, the main thread forwards the execution instruction to the child thread. After receiving the execution instruction, the child thread downgrades the write lock. At this time, it still holds the table lock, but can add, delete, modify, and query the table.
[0050] Optionally, when the child thread receives an execution instruction, the child thread can enter the execution phase, which also belongs to the first phase. After the child thread enters the execution phase, it executes the DDL operation specified in the DDL instruction. The execution process takes a longer time than the preparation process. The main thread will wait for the child thread to reply. When the child thread completes the execution, it returns a return message of successful execution to the main thread. At this time, it can enter the submission state. If the child thread fails to execute, it returns a return message of failed execution to the main thread.
[0051] Optionally, when the computing node receives the return message of successful execution sent by all the data nodes, it is determined that the start condition of the second phase is met, and a lock acquisition request is sent to each data node.
[0052] It can be understood that in the first stage, whether it is the preparation stage or the execution stage, when any data node has an abnormality, the computing node can be used to notify each data node to roll back the data node. After the first stage is completed, each data node needs to commit. The third stage is the commit stage. Committing requires each data node to hold the write lock of the table. Therefore, the second stage is to obtain the write lock for the commit stage.
[0053] S130. When a lock acquisition request is received through the data node, a write lock of the target table is applied for, and after the write lock application is successful, a second-stage completion message is sent to the computing node.
[0054] Optionally, through the main thread in the data node, when a lock acquisition request sent by a computing node is received, the child threads of each data node attempt to obtain the write lock of the table. When the child thread holds the write lock, the child thread notifies the main thread, and the main thread of the data node sends a lock acquisition success message to the computing node, otherwise an error message is sent.
[0055] Optionally, when the computing node receives lock acquisition success messages sent by all data nodes, it determines that the start condition of the third stage is met.
[0056] Optionally, through the computing node, when only lock acquisition success messages sent by some data nodes are received within a specified time period, or error messages sent by at least one data node are received, a lock release request is sent to all data nodes to enable all data nodes to release the write lock, thereby avoiding long-term occupation of the write lock and causing business congestion.
[0057] Optionally, after notifying all data nodes to release the write lock, the computing node repeatedly sends lock acquisition requests to each data node until each data node obtains the write lock, or the repeated issuance reaches a specified number of rounds, then stops sending lock acquisition requests and notifies each data node to initiate a rollback operation.
[0058] S140. When a commit request is received through the data node, a commit operation of the target table is executed, and after the commit is completed, a third phase completion message is sent to the computing node.
[0059] Optionally, after each data node receives the commit request, the commit operation of the target table is executed through the child thread of the data node. When each data node completes the commit, it is determined that the third stage is completed, that is, the execution process of DDL is completed. The child thread notifies the main thread that the commit is completed, and sends the third stage completion message to the computing node through the main thread of the data node.
[0060] The technical solution of the embodiment of the present invention uses a computing node to send a preparation request to each data node in the distributed database system after receiving the DDL instruction sent by the application side, and when it is determined that the second stage or the third stage start condition is met, a lock acquisition request or a submission request is issued to each data node, and when the data node receives the preparation request, the first stage operation is entered, and the operation result of the first stage is sent to the computing node, when the lock acquisition request is received, a write lock of the target table is applied, and after the write lock application is successful, a second stage completion message is sent to the computing node, when the submission request is received, the submission operation of the target table is performed, and after the submission is completed, a third stage completion message is sent to the computing node. In this way, during the execution of DDL, the data node application for table locks will not be interfered, and when the data node cannot apply for the table lock, the table lock will not be forcibly applied to avoid affecting the business, but the atomicity in the distributed database can still be guaranteed, and global consistency is guaranteed in each stage, avoiding the problem of inconsistent metadata between multiple nodes.
[0061] Embodiment 2
[0062] Figure 2 This is a flow chart of a method for processing a data definition language provided in the second embodiment of the present invention. This embodiment specifically illustrates the method for processing a data definition language based on the above embodiments.
[0063] like Figure 2 As shown, the method includes:
[0064] S210 . After receiving the DDL instruction sent by the application side, the computing node sends a preparation request to each data node in the distributed database system.
[0065] S220. When a preparation request is received, a write lock of the target table is applied for through the data node. When it is determined that the write lock is successfully applied for, a first completion message is returned to the computing node.
[0066] When the preparation request is received through the data node, a write lock of the target table is applied for, and when it is determined that the write lock is successfully applied for, after returning a first completion message to the computing node, the following may also be included:
[0067] Determine, by computing the node, whether the first completion message returned by all the data nodes is received within the first time period;
[0068] Through the computing node, if yes, an execution instruction is sent to each data node; through the computing node, if no, each data node is notified to perform a data node rollback operation.
[0069] Optionally, the first time period is a preset time period, and the first completion message refers to the completion message of each data node in the preparation stage. If the first completion message returned by all data nodes is not received within the first time period, it means that an error occurs in a data node. At this time, each data node can be notified to perform a data node rollback operation.
[0070] S230. When receiving the execution instruction sent by the computing node, the data node downgrades the write lock and executes the DDL operation. After determining that the DDL operation is completed, a second completion message is returned to the computing node.
[0071] When receiving the execution instruction sent by the computing node through the data node, downgrading the write lock and executing the DDL operation, after determining that the DDL operation is completed, returning the second completion message to the computing node, it may also include:
[0072] Determine, by computing the node, whether a second completion message returned by all data nodes is received within a second time period;
[0073] Through the computing node, if yes, it is determined that the second stage startup conditions are met, and a lock acquisition request is sent to each data node; through the computing node, if no, each data node is notified to perform a data node rollback operation.
[0074] Optionally, the second time period is a preset time period, and the second completion message refers to the completion message of each data node during the execution phase. If the second completion message returned by all data nodes is not received within the second time period, it means that an error has occurred in a data node. At this time, each data node can be notified to perform a data node rollback operation.
[0075] S240. When a lock acquisition request is received through the data node, a write lock of the target table is applied for, and after the write lock application is successful, a second phase completion message is sent to the computing node.
[0076] When a lock acquisition request is received through the data node, a write lock of the target table is applied for, and after the write lock application is successful, a second phase completion message is sent to the computing node, and the following may also be included:
[0077] Determine, by computing the node, whether any of the following conditions is met: receiving an execution failure result returned by any data node; and, not receiving a second-stage completion message returned by all data nodes within a third time period;
[0078] Through the computing node, if yes, it notifies each data node to release the write lock, and after each data node releases the lock, it repeatedly sends lock acquisition requests to each data node until the end condition is met or each data node returns the second stage completion message;
[0079] Through the computing node, if not, it is determined that the third stage startup conditions are met and a submission request is sent to each data node.
[0080] Optionally, when the data node fails to apply for a write lock in the second phase, the main thread of the data node returns an execution failure result to the computing node.
[0081] Optionally, the third time period is a preset time period. When the computing unit does not receive the second stage completion message returned by all data nodes within the third time period, or receives an execution failure result, it is determined that the data unit has failed to successfully acquire the write lock. At this time, each data node is notified to release the write lock. After the release, the computing node repeats the lock acquisition request and repeats the above operation until it is determined that the lock acquisition success message sent by all data nodes is received within the third time period.
[0082] Optionally, the second phase completion message may refer to information that each data node successfully acquires the write lock in the second phase.
[0083] It is understandable that since the execution phase generally takes a long time, if there is no restriction on the rollback operation of the data node after the execution phase is completed, when any data node cannot obtain the write lock, the rollback operation will be performed immediately, which will cause the previous time-consuming execution phase to become meaningless. Therefore, in the second phase, when the data node cannot obtain the write lock, multiple rounds of attempts to obtain the write lock are required to retain the execution results as much as possible. When multiple rounds of attempts fail to successfully complete the second phase, the computing node is used to notify each data node to initiate a data rollback.
[0084] Optionally, the end condition for repeatedly sending the lock acquisition request to each data node may be reaching a specified number of rounds, or continuously acquiring the write lock for a specified time.
[0085] S250. When a commit request is received, the data node executes a commit operation of the target table, and after the commit is completed, sends a third-stage completion message to the computing node.
[0086] Among them, when receiving the commit request through the data node, executing the commit operation of the target table, and after completing the commit, sending the third stage completion message to the computing node, it can also include any of the following items:
[0087] When the computing node determines that the third phase completion message sent by all data nodes has been received, a DDL execution success response is generated and returned to the application side;
[0088] When it is determined through the computing node that at least one data node returns an execution failure result, an abnormal alarm is generated.
[0089] Optionally, the third stage may refer to the submission stage. In the submission stage, the possibility of data node submission failure is low and the time consumption is short. Therefore, submission can be successfully performed in most cases. However, if a data node fails to submit, an abnormal alarm needs to be generated and resolved through manual intervention.
[0090] Optionally, the method may further include:
[0091] When any operation fails to be executed, the result of the execution failure is returned to the computing node through the data node.
[0092] It can be understood that in the preparation phase or the execution phase in the first phase, the second phase or any phase in the third phase, if the operation currently executed by the child thread of the data node fails, the main thread is notified of the execution failure, and the execution failure result is returned to the computing node through the main thread of the data node.
[0093] Optionally, the method may further include:
[0094] Through the data node, when it is determined that the write lock is held for more than a preset time threshold, the write lock is automatically released.
[0095] Optionally, in order to prevent situations such as communication interruption between the data node and the computing node, which may cause the child thread to hold the write lock for a long time, thereby affecting the normal execution of other tasks in the data node, the child thread of the data node automatically releases the write lock when it is determined that the time the write lock is held exceeds a preset time threshold.
[0096] The technical solution of the embodiment of the present invention uses a computing node to send a preparation request to each data node in the distributed database system after receiving the DDL instruction sent by the application side, and when it is determined that the second stage or the third stage start condition is met, a lock acquisition request or a submission request is issued to each data node, and when the data node receives the preparation request, the first stage operation is entered, and the operation result of the first stage is sent to the computing node, when the lock acquisition request is received, a write lock of the target table is applied, and after the write lock application is successful, a second stage completion message is sent to the computing node, when the submission request is received, the submission operation of the target table is performed, and after the submission is completed, a third stage completion message is sent to the computing node. In this way, during the execution of DDL, the data node application for table locks will not be interfered, and when the data node cannot apply for the table lock, the table lock will not be forcibly applied to avoid affecting the business, but the atomicity in the distributed database can still be guaranteed, and global consistency is guaranteed in each stage, avoiding the problem of inconsistent metadata between multiple nodes.
[0097] Embodiment 3
[0098] Figure 3 This is a schematic diagram of the structure of a data definition language processing device provided in Embodiment 3 of the present invention. Figure 3 As shown, the device includes: a request sending module 310, a first-stage execution module 320, a second-stage execution module 330 and a third-stage execution module 340.
[0099] The request sending module 310 is used to send a preparation request to each data node in the distributed database system through the computing node after receiving the DDL instruction sent by the application side, and send a lock acquisition request or a submission request to each data node when it is determined that the second stage or third stage start conditions are met.
[0100] The first stage execution module 320 is used to enter the first stage operation through the data node when receiving the preparation request, and send the operation result of the first stage to the computing node.
[0101] The second phase execution module 330 is used to apply for a write lock of the target table through the data node when receiving the lock acquisition request, and send a second phase completion message to the computing node after the write lock application is successful.
[0102] The third stage execution module 340 is used to execute the commit operation of the target table through the data node when receiving the commit request, and send a third stage completion message to the computing node after completing the commit.
[0103] The technical solution of the embodiment of the present invention uses a computing node to send a preparation request to each data node in the distributed database system after receiving the DDL instruction sent by the application side, and when it is determined that the second stage or the third stage start condition is met, a lock acquisition request or a submission request is issued to each data node, and when the data node receives the preparation request, the first stage operation is entered, and the operation result of the first stage is sent to the computing node, when the lock acquisition request is received, a write lock of the target table is applied, and after the write lock application is successful, a second stage completion message is sent to the computing node, when the submission request is received, the submission operation of the target table is performed, and after the submission is completed, a third stage completion message is sent to the computing node. In this way, during the execution of DDL, the data node application for table locks will not be interfered, and when the data node cannot apply for the table lock, the table lock will not be forcibly applied to avoid affecting the business, but the atomicity in the distributed database can still be guaranteed, and global consistency is guaranteed in each stage, avoiding the problem of inconsistent metadata between multiple nodes.
[0104] Based on the above embodiments, the first stage execution module 320 can be specifically used for:
[0105] When the preparation request is received, the data node applies for a write lock of the target table, and when it is determined that the write lock is successfully applied for, a first completion message is returned to the computing node;
[0106] When receiving the execution instruction sent by the computing node, the data node downgrades the write lock and executes the DDL operation. After determining that the DDL operation is completed, a second completion message is returned to the computing node.
[0107] Based on the above embodiments, a first completion message checking module may be further included, which is used to:
[0108] Determine, by computing the node, whether the first completion message returned by all the data nodes is received within the first time period;
[0109] Through the computing node, if yes, an execution instruction is sent to each data node; through the computing node, if no, each data node is notified to perform a data node rollback operation.
[0110] Based on the above embodiments, a second completion message checking module may be further included, which is used to:
[0111] Determine, by computing the node, whether a second completion message returned by all data nodes is received within a second time period;
[0112] Through the computing node, if yes, it is determined that the second stage startup conditions are met, and a lock acquisition request is sent to each data node; through the computing node, if no, each data node is notified to perform a data node rollback operation.
[0113] Based on the above embodiments, a failure result returning module may be further included, which is used to:
[0114] When any operation fails to be executed, the result of the execution failure is returned to the computing node through the data node.
[0115] Based on the above embodiments, a write lock release module may be further included, which is used to:
[0116] Through the data node, when it is determined that the write lock is held for more than a preset time threshold, the write lock is automatically released.
[0117] Based on the above embodiments, a second stage detection module may be further included, which is used to:
[0118] Determine, by computing the node, whether any of the following conditions is met: receiving an execution failure result returned by any data node; and, not receiving a second-stage completion message returned by all data nodes within a third time period;
[0119] Through the computing node, if yes, it notifies each data node to release the write lock, and after each data node releases the lock, it repeatedly sends lock acquisition requests to each data node until the end condition is met or each data node returns the second stage completion message;
[0120] Through the computing node, if not, it is determined that the third stage startup conditions are met and a submission request is sent to each data node.
[0121] Based on the above embodiments, a third-stage detection module may be further included to perform any of the following:
[0122] When the computing node determines that the third phase completion message sent by all data nodes has been received, a DDL execution success response is generated and returned to the application side;
[0123] When it is determined through the computing node that at least one data node returns an execution failure result, an abnormal alarm is generated.
[0124] On the basis of the above embodiments, a child thread creation module may also be included, which is used to:
[0125] Through the main thread in the data node, create a child thread in the data node;
[0126] The main thread is used to perform information interaction with the computing node, and the sub-thread is used to perform write lock operations, table processing operations, and perform information interaction with the main thread.
[0127] The data definition language processing device provided in the embodiment of the present invention can execute the data definition language processing method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0128] Embodiment 4
[0129] Figure 4 A schematic diagram of the structure of an electronic device 10 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0130] like Figure 4 As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0131] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0132] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The processor 11 executes the various methods and processes described above, such as the processing method of the data definition language described in the embodiment of the present invention. That is:
[0133] After receiving the DDL instruction sent by the application side, the computing node sends a prepare request to each data node in the distributed database system, and when it is determined that the second or third stage start conditions are met, a lock acquisition request or a commit request is sent to each data node;
[0134] When receiving the preparation request, the data node enters the first phase of operation and sends the operation result of the first phase to the computing node;
[0135] When receiving the lock acquisition request, the data node applies for a write lock of the target table, and after the write lock application is successful, sends a second-stage completion message to the computing node;
[0136] When the commit request is received, the data node executes the commit operation of the target table, and after the commit is completed, sends a third-stage completion message to the computing node.
[0137] In some embodiments, the processing method of the data definition language may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the processing method of the data definition language described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to execute the processing method of the data definition language in any other appropriate manner (e.g., by means of firmware).
[0138] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0139] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0140] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0141] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0142] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0143] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.
[0144] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.
[0145] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for processing a data definition language, which is executed by a computing node and a data node in a distributed database system, characterized in that: include: After receiving the data definition language DDL instruction sent by the application side, the computing node sends a preparation request to each data node in the distributed database system, and when it is determined that the second or third stage start conditions are met, a lock acquisition request or a submission request is sent to each data node; When receiving the preparation request, the data node enters the first phase of operation and sends the operation result of the first phase to the computing node; When receiving the lock acquisition request, the data node applies for a write lock of the target table, and after the write lock application is successful, sends a second-stage completion message to the computing node; When the commit request is received, the data node executes the commit operation of the target table, and after the commit is completed, sends a third-stage completion message to the computing node.
2. The method according to claim 1, characterized in that When receiving the preparation request, the data node enters the first phase of operation and sends the operation result of the first phase to the computing node, including: When the preparation request is received, the data node applies for a write lock of the target table, and when it is determined that the write lock is successfully applied for, a first completion message is returned to the computing node; When receiving the execution instruction sent by the computing node, the data node downgrades the write lock and executes the DDL operation. After determining that the DDL operation is completed, a second completion message is returned to the computing node.
3. The method according to claim 2, characterized in that When the data node receives the preparation request, applying for a write lock of the target table, and when determining that the write lock is successfully applied, returning a first completion message to the computing node, the method further includes: Determine, by computing the node, whether the first completion message returned by all the data nodes is received within the first time period; Through the computing node, if yes, then send the execution instruction to each data node; through the computing node, if no, then notify each data node to perform the data node rollback operation; When receiving the execution instruction sent by the computing node through the data node, downgrading the write lock and executing the DDL operation, after determining that the DDL operation is completed, returning the second completion message to the computing node, further comprising: Determine, by computing the node, whether a second completion message returned by all data nodes is received within a second time period; Through the computing node, if yes, it is determined that the second stage startup conditions are met, and a lock acquisition request is sent to each data node; through the computing node, if no, each data node is notified to perform a data node rollback operation.
4. The method according to any one of claims 1 to 3, characterized in that: Also includes: When any operation fails to be executed, the data node returns the execution failure result to the computing node; The method further comprises: Through the data node, when it is determined that the write lock is held for more than a preset time threshold, the write lock is automatically released.
5. The method according to claim 4, characterized in that When the data node receives the lock acquisition request, it applies for a write lock of the target table, and after the write lock application is successful, it sends a second phase completion message to the computing node, and further includes: Determine, by computing the node, whether any of the following conditions is met: receiving an execution failure result returned by any data node; and, not receiving a second-stage completion message returned by all data nodes within a third time period; Through the computing node, if yes, it notifies each data node to release the write lock, and after each data node releases the lock, it repeatedly sends lock acquisition requests to each data node until the end condition is met or each data node returns the second stage completion message; Through the computing node, if not, it is determined that the third stage startup conditions are met and a submission request is sent to each data node.
6. The method according to claim 5, characterized in that When receiving the commit request through the data node, executing the commit operation of the target table, and after completing the commit, sending the third phase completion message to the computing node, further comprising any of the following: When the computing node determines that the third phase completion message sent by all data nodes has been received, a DDL execution success response is generated and returned to the application side; When it is determined through the computing node that at least one data node returns an execution failure result, an abnormal alarm is generated.
7. The method according to claim 1, characterized in that After receiving the preparation request through the data node, the method further includes: Through the main thread in the data node, create a child thread in the data node; The main thread is used to perform information interaction with the computing node, and the sub-thread is used to perform write lock operations, table processing operations, and perform information interaction with the main thread.
8. A data definition language processing device, executed by a data node in a distributed database system, characterized in that: include: The request sending module is used to send a preparation request to each data node in the distributed database system through the computing node after receiving the data definition language DDL instruction sent by the application side, and send a lock acquisition request or a submission request to each data node when it is determined that the second stage or third stage start conditions are met; The first stage execution module is used to enter the first stage operation through the data node when receiving the preparation request, and send the operation result of the first stage to the computing node; The second-stage execution module is used to apply for a write lock of the target table through the data node when receiving the lock acquisition request, and send a second-stage completion message to the computing node after the write lock application is successful; The third stage execution module is used to execute the submission operation of the target table through the data node when receiving the submission request, and send a third stage completion message to the computing node after completing the submission.
9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the data definition language processing method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the data definition language processing method according to any one of claims 1 to 7 when the processor executes the computer instructions.