Autonomous transaction implementation method, system and use based on concurrent mechanism

Through the autonomous transaction implementation framework based on concurrency mechanism, the database system transaction model is simplified, the problems of complexity and high cost of traditional methods are solved, and the secure and stable autonomous transaction function is realized, reducing the difficulty of development and system intrusion.

CN114003353BActive Publication Date: 2024-12-03BEIJING VASTDATA TECH +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111318864.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-09
Publication Date
2024-12-03
Estimated Expiration
2041-11-09

AI Technical Summary

Technical Problem

The traditional autonomous affairs implementation methods are complex and have a large workload, which is highly invasive to the system, has high development costs, and has high technical requirements for developers, making it difficult to simplify running programs and ensure system security.

Method used

Adopt the autonomous transaction implementation framework based on the concurrency mechanism, realize autonomous transactions through the concurrency characteristics of the program, avoid the use of traditional transaction chain data structures, reuse the original transaction framework and interface of the database system, simplify the transaction model, and reduce development difficulty and cost.

Benefits of technology

It has realized the simplification of the database system transaction model, reduce development difficulty and cost, reduce system intrusion, ensure system security, and achieve the same results as traditional methods.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114003353B_ABST
    Figure CN114003353B_ABST
Patent Text Reader

Abstract

The present invention belongs to the field of database management systems and computer software technology, and in particular, to a method, system and use for implementing autonomous transactions based on a concurrent mechanism. The method of the present invention designs a transaction framework model in which autonomous transactions and main transactions are in parallel. In this model, the various transaction operation contexts of autonomous transactions are exactly the same as those of main transactions, and the autonomous transactions and main transactions are completely consistent in the transaction operation mode. When the system executes autonomous transactions, the original transaction framework in the database system can be reused, and the original transaction interface in the system can be called to implement the autonomous transaction process, and achieve the same result as the traditional implementation method of autonomous transactions. This method simplifies the operating procedures of the database system, reduces the development difficulty and technical requirements for developers, saves human resources and development costs, and reduces the invasiveness to the system, which is conducive to ensuring system security.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of database management system and computer software, and in particular relates to a method, system and use for realizing autonomous transactions based on a concurrent mechanism. Background Art

[0002] Transaction is a typical feature in OLTP (Online Transaction Processing) database. A transaction can be regarded as an execution unit of data operation. Transactions must have four basic characteristics: atomicity, consistency, isolation, and persistence, so as to ensure the correctness of the operation data.

[0003] Autonomous transactions are a special transaction mechanism in the Oracle database system. Autonomous transactions are embedded in the main transaction, but they are executed in their own context. They can be committed or rolled back independently without affecting the status of the main transaction. In terms of data visibility, autonomous transactions cannot detect the status of data rows modified in the main transaction, while the main transaction can detect the status of data rows in the committed autonomous transaction.

[0004] The traditional method of implementing autonomous transactions is to modify the transaction model of the database and implement a transaction chain data structure. When the system detects an autonomous transaction, a new transaction context is allocated in the transaction chain, and the operation of the autonomous transaction is executed in the newly allocated transaction context. After the autonomous transaction is completed, the newly allocated transaction context is cleaned up to complete the mechanism of the autonomous transaction. However, this implementation method has obvious disadvantages, namely, the implementation mechanism is too complicated, the workload is huge, it is highly invasive to the existing system, and it requires developers to be very familiar with the database transaction mechanism. The human resources and development costs are very high. Therefore, in order to simplify the running program, ensure system security, and reduce development costs, it is urgent to develop a new, simple, easy, safe and stable autonomous transaction implementation method. Summary of the invention

[0005] Autonomous transactions are a feature of the transaction module in a database system. For database systems that do not support autonomous transactions, the transaction management model usually allocates a transaction status structure associated with the session, in which the transaction identification, status, owner and other information are recorded. This structure accompanies the entire transaction life cycle. After a transaction ends, the structure is cleared, and then the next transaction is started, and a transaction status structure is reallocated for the new transaction.

[0006] Therefore, in the application scenario of autonomous transactions, two transaction status structures need to exist at the same time, one of which stores the context of the main transaction, and the other stores the context of the autonomous transaction. The two are logically in a parallel relationship, and the two are isolated from each other. The operations within one transaction are not visible to the other transaction. However, there is a sequential relationship between the two in terms of timing. Generally speaking, some operations in the main transaction are the predecessors of the autonomous transaction. The autonomous transaction may receive the parameters passed by the predecessor main transaction operations as the basis for its own processing, and the autonomous transaction itself will also serve as the predecessor of subsequent operations in the main transaction. The operations in the main transaction may also receive the results returned by the autonomous transaction as the basis for subsequent processing. The timing relationship between the two is shown in the attached figure. Figure 1 shown.

[0007] like Figure 1 As shown, after the user actively opens a transaction, the user enters the context of the main transaction and executes SQL statements in this context. When the system detects the autonomous transaction, it opens the context of the autonomous transaction, and the main transaction passes the necessary parameters to the context of the autonomous transaction to execute the SQL statements in the autonomous transaction. After the execution is completed, the autonomous transaction ends. At this time, the data modifications made by the autonomous transaction are visible to the outside (including to the main transaction), and the necessary results are returned to the main transaction. The main transaction continues to proceed with subsequent steps based on the results of the autonomous transaction. When the user ends the transaction, the main transaction ends, and the data modifications made by the main transaction are visible to the outside. In addition, after the autonomous transaction ends, the data table only contains the data modifications made by the autonomous transaction. At this time, whether the main transaction is committed or rolled back will not affect the data modifications of the autonomous transaction. Until the main transaction ends, the data table will include the data modifications of both the main transaction and the autonomous transaction.

[0008] Let's take an example to illustrate the timing relationship between the autonomous transaction and the main transaction: suppose there are transactions T1 and T2, where T1 is the main transaction and T2 is the autonomous transaction; there is also a table table, transactions T1 and T2 both operate on the data in the table table, the initial data in the table is 0, operation U1 updates the data in the table to 1, U2 updates the data in the table to 2... and so on, the Un operation updates the data in the table to n. The operation sequence of transaction T1 is as follows: U1, T2, U3; the operation sequence of transaction T2 is as follows: U2.

[0009] The timing process is as follows:

[0010] Turn on T1, and the table data is 0;

[0011] Execute the U1 operation. In transaction T1, the table data is 1, and the external table data of transaction T1 is 0.

[0012] Start transaction T2. ​​The table data in transaction T2 is 0.

[0013] Execute the U2 operation. The table data in transaction T1 is 1, and the table data in transaction T2 is 2. The external table data of transaction T1 and transaction T2 is 0.

[0014] Submit transaction T2. ​​The table data in transaction T1 is 2, and the external table data of the transaction is 2.

[0015] Execute the U3 operation. The table data in transaction T1 is 3, and the data in the external table of the transaction is 2.

[0016] Commit transaction T1, and the table data is 3.

[0017] Obviously, the autonomous transaction implementation method of the transaction chain data structure has many disadvantages, the most prominent of which are complex implementation mechanism, huge workload, strong invasiveness to the system, increased system risk, high technical level requirements for developers, and high human resources and development costs.

[0018] In order to overcome the above defects, the present invention proposes an autonomous transaction implementation framework based on a concurrent mechanism. This method avoids using the data structure of the traditional transaction chain and instead uses the concurrent characteristics of the program to implement the above process. This can greatly simplify the transaction model of the database system, reduce the difficulty of development, and save development costs. In the method of the present invention, the transaction context of the autonomous transaction and the transaction context of the main transaction are exactly the same, and the same development interface can be reused. Similarly, the operation of ending the transaction can also be reused. In other words, the autonomous transaction and the main transaction are completely consistent in the operability of the transaction. There is no need to make additional modifications to the transaction model, and the existing framework can be used to implement the autonomous transaction characteristics. Therefore, this method reuses the original transaction framework in the database system to the greatest extent, and calls the original transaction interface in the system to implement the autonomous transaction process. After actual verification, the autonomous transaction implementation method under the parallel framework of the present invention can achieve the same results as the traditional implementation method of autonomous transactions.

[0019] In the first aspect, the present invention provides a method for implementing autonomous transactions based on a concurrent mechanism, wherein the method implements autonomous transactions through a concurrent mechanism of a program. Specifically, the method designs a transaction framework model in which autonomous transactions and main transactions are carried out in parallel. In this model, various transaction operation contexts of autonomous transactions are exactly the same as those of the main transactions, and the autonomous transactions and the main transactions are completely consistent in terms of transaction operation methods. When the system executes autonomous transactions, the original transaction framework in the database system can be reused, and the original transaction interface in the system can be called to implement the autonomous transaction process, thereby achieving the same result as the traditional implementation method of autonomous transactions.

[0020] Furthermore, the transaction operation context in this method includes a start transaction context, an execution transaction context, and an end transaction context.

[0021] More specifically, the autonomous transaction implementation method of the present invention includes the following steps:

[0022] (1) Create a transaction status structure and start the main transaction;

[0023] (2) Execute the SQL statements in the main transaction;

[0024] (3) An autonomous transaction statement is detected, shared memory is allocated for data exchange, a new process is started, and the autonomous transaction SQL statement is written into the shared memory;

[0025] (4) starting an autonomous transaction in the new process;

[0026] (5) reading the autonomous transaction SQL statement in the shared memory in the new process, executing it, and writing the result into the shared memory according to the actual execution situation;

[0027] (6) terminating the autonomous transaction in the new process, clearing the running state, and terminating the current process;

[0028] (7) Read the results in the shared memory in the main transaction and continue to execute subsequent main transaction SQL statements;

[0029] (8) After execution is completed, the main transaction ends.

[0030] The present invention also relates to the use of the autonomous transaction implementation method in a database management or operation system.

[0031] In the second aspect, the present invention provides an autonomous transaction implementation system based on a concurrent mechanism. The system implements autonomous transactions through a concurrent mechanism of a program. Specifically, the system designs a transaction framework model in which autonomous transactions and main transactions are parallel. In this model, the various transaction operation contexts of autonomous transactions are exactly the same as those of main transactions. Autonomous transactions and main transactions are completely consistent in terms of transaction operation methods. When the system executes autonomous transactions, the original transaction framework in the database system can be reused, and the original transaction interface in the system can be called to implement the autonomous transaction process, and the same result as the traditional implementation method of autonomous transactions can be achieved.

[0032] The autonomous transaction implementation system comprises:

[0033] Open transaction module: its function is to open the main transaction or autonomous transaction;

[0034] Transaction execution module: its function is to execute SQL statements in the main transaction or autonomous transaction;

[0035] Statement detection module: its function is to detect autonomous transaction statements;

[0036] Information storage module: its function is to allocate shared memory for data exchange and complete the writing and reading of information in the shared memory;

[0037] End transaction module: its function is to end the main transaction or autonomous transaction;

[0038] Automatic control module: Its function is to automatically organize and control the above modules.

[0039] In a third aspect, the present invention also provides an autonomous transaction implementation device based on a concurrent mechanism, the device comprising a processor and a memory, the memory being used to store programs, and the processor being used to run the programs to implement the above-mentioned autonomous transaction implementation method.

[0040] In summary, compared with the autonomous transaction implementation method of the traditional transaction chain data structure, the method of the present invention has the following characteristics:

[0041] (1) The operation procedures of the database system are simplified, and the workload is significantly reduced;

[0042] (2) It reduces the development difficulty and technical requirements for developers, effectively saving human resources and development costs;

[0043] (3) The intrusion into the system is reduced, which is conducive to ensuring system security. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the prior art and the drawings required to be used in the embodiments of the present invention are briefly introduced below. Obviously, the following drawings are only some embodiments recorded in the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0045] Figure 1 This is a schematic diagram of the timing relationship between autonomous transactions and main transactions in the traditional autonomous transaction implementation method.

[0046] Figure 2 The figure is a flow chart of the method for realizing autonomous transactions based on a concurrent mechanism of the present invention. DETAILED DESCRIPTION

[0047] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them. The present invention can also be implemented or applied through other different specific implementation methods. The details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present invention.

[0048] At the same time, it should be understood that the protection scope of the present invention is not limited to the specific embodiments described below; it should also be understood that the terms used in the embodiments of the present invention are for describing specific embodiments rather than for limiting the protection scope of the present invention.

[0049] Embodiment 1: A method for implementing autonomous transactions based on a concurrent mechanism. This method designs a transaction framework model in which autonomous transactions and main transactions are parallel. In this model, the various transaction operation contexts of autonomous transactions are exactly the same as those of main transactions. Autonomous transactions and main transactions are completely consistent in terms of transaction operation methods. When the system executes autonomous transactions, it can reuse the original transaction framework in the database system and call the original transaction interface in the system to implement the autonomous transaction process and achieve the same results as the traditional method for implementing autonomous transactions. Specifically, the following steps are included (see Attachment 1). Figure 2 ):

[0050] (1) Create a transaction status structure and start the main transaction;

[0051] (2) Execute the SQL statements in the main transaction;

[0052] (3) An autonomous transaction statement is detected, shared memory is allocated for data exchange, a new process is started, and the autonomous transaction SQL statement is written into the shared memory;

[0053] (4) starting an autonomous transaction in the new process;

[0054] (5) reading the autonomous transaction SQL statement in the shared memory in the new process, executing it, and writing the result into the shared memory according to the actual execution situation;

[0055] (6) terminating the autonomous transaction in the new process, clearing the running state, and terminating the current process;

[0056] (7) Read the results in the shared memory in the main transaction and continue to execute subsequent main transaction SQL statements;

[0057] (8) After execution is completed, the main transaction ends.

[0058] Embodiment 2: An autonomous transaction implementation system based on a concurrent mechanism, comprising:

[0059] Open transaction module: its function is to open the main transaction or autonomous transaction;

[0060] Transaction execution module: its function is to execute SQL statements in the main transaction or autonomous transaction;

[0061] Statement detection module: its function is to detect autonomous transaction statements;

[0062] Information storage module: its function is to allocate shared memory for data exchange and complete the writing and reading of information in the shared memory;

[0063] End transaction module: its function is to end the main transaction or autonomous transaction;

[0064] Automatic control module: Its function is to automatically organize and control the above modules.

[0065] For the functional details of each module, please refer to the technical solution of Example 1.

[0066] Embodiment 3: An autonomous transaction implementation device based on a concurrent mechanism comprises a processor and a memory, wherein the memory is used to store a program, and the processor is used to run the program to implement the autonomous transaction implementation method described in Embodiment 1.

[0067] The various embodiments of the present invention are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0068] The above description is only an embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, replacement, etc. made within the spirit and principle of the present invention should be included in the scope of protection of the claims of the present invention.

Claims

1. A method for implementing autonomous transactions based on a concurrent mechanism, characterized in that: The method implements autonomous transactions through the concurrent mechanism of the program, and provides a transaction framework model in which autonomous transactions and main transactions are parallel. In this model, various transaction operation contexts of autonomous transactions are completely the same as those of main transactions, and the autonomous transactions and main transactions are completely consistent in transaction operation methods. When the system executes autonomous transactions, the original transaction framework in the database system is reused, and the original transaction interface in the system is called to implement the autonomous transaction process, and the same result as the traditional implementation method of autonomous transactions is achieved; The method comprises the following steps: (1) Create a transaction status structure and start the main transaction; (2) Execute the SQL statements in the main transaction; (3) An autonomous transaction statement is detected, shared memory is allocated for data exchange, a new process is started, and the autonomous transaction SQL statement is written into the shared memory; (4) starting an autonomous transaction in the new process; (5) Reading the autonomous transaction SQL statement in the shared memory in the new process, executing it, and writing the result into the shared memory according to the actual execution situation; (6) terminating the autonomous transaction in the new process, clearing the running state, and terminating the current process; (7) Read the results in the shared memory in the main transaction and continue to execute subsequent main transaction SQL statements; (8) After execution is completed, the main transaction ends.

2. The autonomous transaction implementation method according to claim 1, characterized in that: The transaction operation context includes a start transaction context, an execution transaction context, and an end transaction context.

3. Use of the autonomous transaction implementation method described in claim 1 or 2 in a database management or operation system.

4. An autonomous transaction implementation system based on a concurrent mechanism, characterized in that: The system implements autonomous transactions through the concurrent mechanism of the program, and provides a transaction framework model in which autonomous transactions and main transactions are parallel. In this model, the various transaction operation contexts of autonomous transactions are exactly the same as those of main transactions, and the autonomous transactions and main transactions are completely consistent in terms of transaction operation methods. When the system executes autonomous transactions, it reuses the original transaction framework in the database system, calls the original transaction interface in the system to implement the autonomous transaction process, and achieves the same result as the traditional implementation method of autonomous transactions. The autonomous transaction implementation system comprises: Open transaction module: its function is to open the main transaction or autonomous transaction; Transaction execution module: its function is to execute SQL statements in the main transaction or autonomous transaction; Statement detection module: its function is to detect autonomous transaction statements; Information storage module: its function is to allocate shared memory for data exchange and complete the writing and reading of information in the shared memory; End transaction module: its function is to end the main transaction or autonomous transaction; Automatic control module: its function is to automatically organize and control the above modules; When the system is running, the steps of the method for realizing autonomous transactions based on a concurrent mechanism as described in claim 1 or 2 are implemented.

5. An autonomous transaction implementation device based on a concurrent mechanism, characterized in that: The device includes a processor and a memory, the memory is used to store a program, and the processor is used to run the program to implement the autonomous transaction implementation method described in claim 1 or 2.