Transaction processing method and device, electronic equipment and storage medium

By introducing resource managers and transaction managers into the DTP model and generating snapshot dump statements, the problem of inefficiency of non-relational databases in distributed transaction processing is solved, automated proxy operations are realized, distributed transaction processing efficiency is improved, and code invasiveness of target applications is reduced.

CN120407090APending Publication Date: 2025-08-01TENCENT TECH (BEIJING) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510570059.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-30
Publication Date
2025-08-01

AI Technical Summary

Technical Problem

In the prior art, distributed transaction processing is inefficient when accessing non-relational databases such as Redis, and is invasive to the code applied to the target.

Method used

By introducing the DTP model, using the resource manager and transaction manager, snapshot dump statements are generated and non-relational database operations are automated, and distributed transaction processing is supported to avoid intrusion into the target application code.

Benefits of technology

Improve the efficiency of distributed transaction processing, reduce the complexity and maintenance costs of target application code, and ensure the automation and consistency of transaction processing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120407090A_ABST
    Figure CN120407090A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a transaction processing method and device, electronic equipment and a storage medium, and the method comprises the steps: obtaining a global identifier of a global transaction after a target application starts the global transaction, extracting a to-be-operated target key from an operation statement submitted by the target application, registering a branch transaction under the global transaction to a transaction manager based on the target key, and storing the branch transaction under the global transaction in the transaction manager. Receiving a branch identifier of the branch transaction returned by the transaction manager, generating a snapshot dump statement used for dumping a target value associated with the target key, sending the snapshot dump statement to the non-relational database, receiving an operation statement executed by the non-relational database and snapshot information returned after the snapshot dump statement, and sending the snapshot information to the transaction manager; and storing the snapshot information to the non-relational database based on the global identifier and the branch identifier, querying the snapshot information from the non-relational database in response to a processing request of the target application for the global transaction, and executing the processing request based on the snapshot information, so that the efficiency of distributed transaction processing can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular, to a transaction processing method, apparatus, electronic device, and storage medium. Background Art

[0002] A distributed transaction refers to an operation across multiple independent nodes or databases. Currently, the access to distributed transactions generally does not support non-relational databases such as Redis. In related technologies, distributed transactions can only be manually processed in related modes, which has a certain invasiveness to the code of the target application and reduces the efficiency of distributed transaction processing. Summary of the Invention

[0003] The following is an overview of the subject matter described in detail in the present disclosure. This overview is not intended to limit the scope of protection of the claims.

[0004] Embodiments of the present disclosure provide a transaction processing method, apparatus, electronic device, and storage medium, which can improve the efficiency of distributed transaction processing.

[0005] On the one hand, embodiments of the present disclosure provide a transaction processing method, which is applied to a resource manager in a DTP model. The DTP model further includes a transaction manager. The transaction processing method includes:

[0006] After a target application starts a global transaction, obtain a global identifier of the global transaction;

[0007] Obtain an operation statement submitted by the target application, extract a target key to be operated from the operation statement, register a branch transaction under the global transaction with the transaction manager based on the target key, and receive a branch identifier of the branch transaction returned by the transaction manager;

[0008] Generate a snapshot dump statement for dumping a target value associated with the target key, send the snapshot dump statement to a non-relational database, and receive snapshot information returned by the non-relational database after executing the operation statement and the snapshot dump statement;

[0009] Store the snapshot information in the non-relational database based on the global identifier and the branch identifier;

[0010] In response to a processing request of the target application for the global transaction, query the snapshot information from the non-relational database according to the global identifier and the branch identifier, and execute the processing request based on the snapshot information.

[0011] On the other hand, embodiments of the present disclosure further provide a transaction processing apparatus, including:

[0012] The first processing module is used to obtain the global identifier of the global transaction after the target application starts the global transaction;

[0013] The second processing module is used to obtain the operation statement submitted by the target application, extract the target key to be operated from the operation statement, register the branch transaction under the global transaction with the transaction manager based on the target key, and receive the branch identifier of the branch transaction returned by the transaction manager;

[0014] The third processing module is used to generate a snapshot dump statement for dumping the target value associated with the target key, send the operation statement and the snapshot dump statement to the non-relational database, and receive the snapshot information returned after the non-relational database executes the operation statement and the snapshot dump statement;

[0015] The fourth processing module is used to store the snapshot information in the non-relational database based on the global identifier and the branch identifier;

[0016] The fifth processing module is used to, in response to the processing request of the target application for the global transaction, query the snapshot information from the non-relational database according to the global identifier and the branch identifier, and execute the processing request based on the snapshot information.

[0017] Furthermore, the third processing module is further used to:

[0018] Generate a first dump statement for dumping the target value associated with the target key before executing the operation statement and a second dump statement for dumping the target value after executing the operation statement;

[0019] Concatenate the first dump statement, the operation statement, and the second dump statement in sequence to obtain a snapshot dump statement.

[0020] Furthermore, the third processing module is further used to:

[0021] Concatenate the dump instruction of the non-relational data with the target key to obtain a first dump statement for serializing the target value associated with the target key before executing the operation statement and a second dump statement for serializing the target value after executing the operation statement;

[0022] Alternatively, concatenate the copy instruction of the non-relational data with the target key to obtain a first dump statement for copying the target value associated with the target key before executing the operation statement and a second dump statement for copying the target value after executing the operation statement.

[0023] Further, the third processing module is further configured to:

[0024] Determine the space occupancy of the target value and the data consistency coefficient corresponding to the target application, and normalize both the space occupancy and the data consistency coefficient;

[0025] Perform weighted summation on the normalized space occupancy and the normalized data consistency coefficient to obtain an instruction selection coefficient;

[0026] Obtain a first preset coefficient range corresponding to the dump instruction and a second preset coefficient range corresponding to the copy instruction, compare the instruction selection coefficient with the first preset coefficient range and the second preset coefficient range respectively, and select the dump instruction or the copy instruction according to the comparison result, where the first preset coefficient range is different from the second preset coefficient range.

[0027] Further, the third processing module is further configured to:

[0028] For each of the target keys, determine the correlation coefficient with the remaining target keys, and normalize the correlation coefficient;

[0029] According to the correlation coefficient, determine the weights corresponding to the space occupancy, the data consistency coefficient, and the correlation coefficient of the same target key respectively;

[0030] Perform weighted summation on the normalized space occupancy, the normalized data consistency coefficient, and the normalized correlation coefficient according to the weights to obtain an instruction selection coefficient.

[0031] Further, the fifth processing module is further configured to:

[0032] Obtain the current value associated with the target key from the non-relational database, and the post value associated with the target key in the snapshot information after executing the second dump statement;

[0033] Verify the consistency between the current value and the post value, and when the current value is consistent with the post value, execute the processing request based on the snapshot information.

[0034] Further, the fifth processing module is further configured to:

[0035] When the current value is consistent with the post value, obtain the pre value associated with the target key in the snapshot information after executing the first dump statement;

[0036] Execute the recovery instruction to deserialize the pre - value, restore the current value to the deserialized pre - value, and delete the snapshot information to execute the rollback request.

[0037] Further, the fifth processing module is further configured to:

[0038] When the current value is consistent with the post - value, obtain the copy key corresponding to the target key in the snapshot information after executing the first dump statement;

[0039] Execute the rename instruction to rename the copy key to the target key and delete the snapshot information to execute the rollback request.

[0040] Further, the fifth processing module is further configured to:

[0041] Determine the snapshot key corresponding to the target key, and query whether the snapshot key exists in the non - relational database;

[0042] When the snapshot key does not exist in the non - relational database, generate a snapshot dump statement for dumping the target value associated with the target key using the snapshot key.

[0043] Further, the fifth processing module is further configured to:

[0044] When the snapshot key exists in the non - relational database, obtain the snapshot information corresponding to the snapshot key from the non - relational database, and update the snapshot information based on the operation statement;

[0045] In response to the processing request, query the updated snapshot information from the non - relational database according to the global identifier and the branch identifier, and execute the processing request based on the updated snapshot information.

[0046] On the other hand, an embodiment of the present disclosure further provides an electronic device, including a memory and a processor, where the memory stores a computer program, and the processor implements the above - mentioned transaction processing method when executing the computer program.

[0047] On the other hand, an embodiment of the present disclosure further provides a computer - readable storage medium, where the storage medium stores a computer program, and the computer program is implemented by the processor to implement the above - mentioned transaction processing method.

[0048] On the other hand, an embodiment of the present disclosure also provides a computer program product, which includes a computer program stored in a computer-readable storage medium. A processor of a computer device reads the computer program from the computer-readable storage medium, and the processor executes the computer program, so that the computer device executes the transaction processing method described above.

[0049] The embodiments of the present disclosure at least include the following beneficial effects: After a global transaction is started in a target application, obtain the global identifier of the global transaction, obtain the operation statement submitted by the target application, extract the target key to be operated from the operation statement, and register a branch transaction under the global transaction with the transaction manager of the DTP model based on the target key, and receive the branch identifier of the branch transaction returned by the transaction manager. Thus, by introducing the DTP model, a non-relational database can support distributed transactions. On this basis, by generating a snapshot dump statement for dumping the target value associated with the target key, sending the snapshot dump statement to the non-relational database, receiving the snapshot information returned after the non-relational database executes the operation statement and the snapshot dump statement, and storing the snapshot information in the non-relational database based on the global identifier and the branch identifier, it is possible to automatically proxy the operations of the target application through the resource manager, without the need to write relevant code additionally, avoiding intrusion into the code of the target application. Subsequently, in response to a processing request of the target application for the global transaction, query the snapshot information from the non-relational database according to the global identifier and the branch identifier, and execute the processing request based on the snapshot information. The entire process of transaction processing does not require manual operation, thereby effectively improving the efficiency of distributed transaction processing.

[0050] Other features and advantages of the present disclosure will be described in the following specification, and, in part, will be obvious from the specification, or will be understood by implementing the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0051] The drawings are used to provide a further understanding of the technical solutions of the present disclosure, and constitute a part of the specification. Together with the embodiments of the present disclosure, they are used to explain the technical solutions of the present disclosure, and do not constitute a limitation to the technical solutions of the present disclosure.

[0052] Figure 1 It is a schematic diagram of an optional implementation environment provided by an embodiment of the present disclosure;

[0053] Figure 2 It is an optional flowchart of the transaction processing method provided by an embodiment of the present disclosure;

[0054] Figure 3 It is an optional flowchart diagram of the snapshot dump operation provided by an embodiment of the present disclosure;

[0055] Figure 4An optional flowchart for executing a processing request provided by an embodiment of the present disclosure;

[0056] Figure 5 An optional flowchart for the first stage of snapshot reading provided by an embodiment of the present disclosure;

[0057] Figure 6 An optional flowchart for the second stage of snapshot reading provided by an embodiment of the present disclosure;

[0058] Figure 7 An optional overall logic diagram for the transaction processing method provided by an embodiment of the present disclosure;

[0059] Figure 8 An optional system architecture diagram for the transaction processing method provided by an embodiment of the present disclosure;

[0060] Figure 9 A structural diagram of the transaction processing device provided by an embodiment of the present disclosure;

[0061] Figure 10 A partial structural block diagram of the terminal provided by an embodiment of the present disclosure;

[0062] Figure 11 A partial structural block diagram of the server provided by an embodiment of the present disclosure. Detailed implementation manners

[0063] In order to make the objectives, technical solutions and advantages of the present disclosure clearer, the present disclosure will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present disclosure and are not used to limit the present disclosure.

[0064] It should be noted that in each specific implementation manner of the present disclosure, when it comes to performing relevant processing based on data related to the characteristics of the target object, such as target object attribute information or attribute information set, the permission or consent of the target object will be obtained first. Moreover, the collection, use and processing of these data will comply with relevant laws, regulations and standards. Among them, the target object may be a user. In addition, when an embodiment of the present disclosure needs to obtain target object attribute information, it will obtain the separate permission or separate consent of the target object through methods such as popping up a window or jumping to a confirmation page. After clearly obtaining the separate permission or separate consent of the target object, the necessary target object-related data for the normal operation of the embodiment of the present disclosure will be obtained.

[0065] In the embodiments of the present disclosure, the term "module" or "unit" refers to a computer program with a predetermined function or a part of a computer program, which works together with other related parts to achieve a predetermined goal, and can be fully or partially implemented by using software, hardware (such as a processing circuit or a memory), or a combination thereof. Similarly, a processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be a part of an overall module or unit that includes the functions of the module or unit.

[0066] To facilitate the understanding of the technical solutions provided by the embodiments of the present disclosure, some key terms used in the embodiments of the present disclosure are explained here first:

[0067] Distributed transaction: Refers to transaction operations across multiple independent nodes or databases, and it is necessary to ensure that these transaction operations succeed or fail simultaneously to maintain data consistency.

[0068] DTP (Distributed Transaction Processing) model: That is, the distributed transaction processing model, which is an architecture model for processing transactions in a distributed system, including components such as application programs, transaction managers, resource managers, and communication resource managers. The DTP model defines how to coordinate multiple participants (such as databases, application programs, etc.) to complete a complete transaction in a distributed environment to ensure data consistency and integrity.

[0069] Transaction manager: It is the core component in the DTP model for coordinating and managing distributed transactions, responsible for starting, committing, or rolling back transactions, interacting with resource managers, and ensuring that transactions can be correctly executed on all participating resources. The transaction manager can also handle issues such as concurrent control and fault recovery of transactions, and send instructions such as prepare, commit, or roll back to each resource manager.

[0070] Resource manager: It is the component in the DTP model for managing and controlling specific resources, such as database management systems, message queues, etc. The resource manager is responsible for executing specific operations in the transaction, such as reading and writing databases, sending and receiving messages, etc., and reporting the results of the operations to the transaction manager. Each resource manager can independently control the transaction processing of local resources. In a distributed transaction, multiple resource managers work together to complete a global transaction.

[0071] Non-relational database: Also known as NoSQL (Not Only SQL) database, it is a database system that does not rely on the traditional relational model and uses a more flexible data model to store and manage data. Non-relational databases usually adopt a distributed architecture, are not limited to a fixed table structure and schema, and can expand system performance by adding server nodes. These characteristics enable them to be applied to scenarios such as publish-subscribe and distributed transaction processing.

[0072] Dump: It is the process of copying a database or other data collection from one storage location to another, usually used for backup, recovery, etc. By performing regular dumps, the data in the database can be copied to other storage devices. When the database fails, data is lost or damaged, the dump file can be used for data recovery to ensure data security and availability.

[0073] A distributed transaction refers to operations across multiple independent nodes or databases. Distributed transaction processing is a crucial task in database management. Currently, most accesses to distributed transactions support the access of specific specification transactions. Most current relational databases provide specific specification transactions, while non-relational databases such as Redis itself cannot support specific specifications. Therefore, the access to distributed transactions generally does not support non-relational databases such as Redis. In related technologies, non-relational databases can only manually commit and rollback and compensate for distributed transactions in related modes, which has a certain intrusion on the code of the target application and reduces the efficiency of distributed transaction processing.

[0074] Based on this, the embodiments of the present disclosure provide a transaction processing method, apparatus, electronic device, and storage medium, which can effectively improve the efficiency of distributed transaction processing.

[0075] Refer to Figure 1 , Figure 1 FIG. is a schematic diagram of an optional implementation environment provided by the embodiments of the present disclosure. The implementation environment includes a terminal 101, a resource manager 102, a transaction manager 103, and a database 104. Among them, the terminal 101 is connected to the resource manager 102 and the transaction manager 103 through a communication network.

[0076] Exemplarily, after the target application in the terminal 101 starts a global transaction, the terminal 101 registers the global transaction with the transaction manager 103. The transaction manager 103 sends the global identifier of the global transaction to the resource manager 102. The resource manager 102 obtains the global identifier of the global transaction, obtains the operation statement submitted by the target application, extracts the target key to be operated from the operation statement, registers a branch transaction under the global transaction with the transaction manager 103 based on the target key, and receives the branch identifier of the branch transaction returned by the transaction manager 103. A snapshot dump statement for dumping the target value associated with the target key is generated in the resource manager 102, and the snapshot dump statement is sent to the non-relational database 104. The resource manager 102 receives the snapshot information returned after the non-relational database 104 executes the operation statement and the snapshot dump statement, and stores the snapshot information in the non-relational database 104 based on the global identifier and the branch identifier. The transaction manager 103 receives the processing request of the target application for the global transaction sent by the terminal 101, decides whether to execute the processing request. When it is determined to execute the processing request, the transaction manager 103 forwards the processing request to the resource manager 102. The resource manager 102 responds to the processing request of the target application of the terminal 101 for the global transaction, queries the snapshot information from the non-relational database 104 according to the global identifier and the branch identifier, and executes the processing request based on the snapshot information.

[0077] The resource manager 102 and the transaction manager 103 can be independent physical servers, or a server cluster or a distributed system composed of multiple physical servers. They can also be cloud servers that provide basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. In addition, the resource manager 102 and the transaction manager 103 can also be a node server in a blockchain network.

[0078] The terminal 101 can be a mobile phone, a computer, a smart voice interaction device, a smart wearable device, a smart home appliance, a vehicle terminal, etc., but is not limited thereto. The terminal 101, the resource manager 102, and the transaction manager 103 can be directly or indirectly connected through wired or wireless communication methods, and the embodiments of the present disclosure do not limit this here.

[0079] Refer to Figure 2 , Figure 2 FIG. is an optional flowchart of the transaction processing method provided by the embodiments of the present disclosure. The transaction processing method can be cooperatively executed by a terminal, a resource manager, a transaction manager, and a non-relational database. The transaction processing method includes, but is not limited to, the following steps S201 to step S205.

[0080] Step S201: After the target application starts a global transaction, obtain the global identifier of the global transaction.

[0081] Among them, the target application is the business program currently used by the operation object, and the start, commit, rollback, etc. of the global transaction can be controlled in the target application; the global transaction is a distributed transaction. Under the global transaction, there are multiple branch transactions, which involve data operations between multiple branch transactions. The global identifier is used to uniquely identify and distinguish different global transactions, and can be composed of one or more of numbers, letters, and symbols.

[0082] Specifically, the operation object executes the operation of starting a global transaction in the target application. The target application sends a request to start a global transaction to the transaction manager, registers the global transaction with the transaction manager, and applies for a global identifier. After the transaction manager responds to the request to start a global transaction, it registers the global transaction and generates the global identifier corresponding to the global transaction, and sends the global identifier to the target application.

[0083] Step S202: Obtain the operation statement submitted by the target application, extract the target key to be operated from the operation statement, register the branch transaction under the global transaction with the transaction manager based on the target key, and receive the branch identifier of the branch transaction returned by the transaction manager.

[0084] Among them, the operation statement is used to represent the specific data operation and control the process of the branch transaction in the branch transaction. The operation statement includes the target key to be operated and the value associated with the target key; the target key is used to locate and identify a specific data object in the branch transaction. There is at least one target key in the operation statement, and one target key can be applied to multiple branch transactions. For example, if the operation statement is SET user:111:order{′item′:′item_1′,′number′:′1′}, the target key can be user:111:order, and the value corresponding to the target key is {′item′:′item_1′,′number′:′1′}. The transaction manager is used to manage the global transaction, including global transaction registration, branch transaction registration, release of the global lock, transaction commit callback, transaction rollback callback, etc. The branch transaction is a component of the global transaction and is used to execute different business services. For example, when borrowing a book on the target platform, the entire process of borrowing a book is a global transaction, and the branch transactions involved in this process can be borrowing information verification, book information query, order creation, inventory query, etc.

[0085] Specifically, when the operation object registers a global transaction with the transaction manager, the resource manager needs to intercept the operation information of the operation object and obtain the operation statement submitted by the target application. The resource manager parses the operation statement and extracts the target key to be operated on, reports the branch transaction to the transaction manager based on the target key, and registers the branch transaction under the global transaction with the transaction manager. The transaction manager registers the corresponding branch transaction, generates a branch identifier for the branch transaction, and sends the branch identifier to the resource manager. By introducing the transaction manager and the resource manager, and registering the global transaction and the branch transaction based on the transaction manager, the non-relational database can support distributed transactions.

[0086] It should be noted that when the resource manager intercepts the operation information, it can implement the operation of providing a database operation interface from the non-relational database to the target application.

[0087] Step S203: Generate a snapshot dump statement for dumping the target value associated with the target key, send the snapshot dump statement to the non-relational database, and receive the snapshot information returned by the non-relational database after executing the operation statement and the snapshot dump statement.

[0088] Among them, the snapshot dump statement can be regarded as a statement block for dumping the target value before and after executing the statement operation and executing the operation statement, including a first dump statement, a second dump statement, and an operation statement. A non-relational database is a database management system that does not rely on a tabular form to store data. The non-relational database can be a database such as Redis or MongoDB.

[0089] In a possible implementation manner, in the process of generating a snapshot dump statement for dumping the target value associated with the target key, specifically, a first dump statement for dumping the target value associated with the target key before executing the operation statement and a second dump statement for dumping the target value after executing the operation statement can be generated, and the first dump statement, the operation statement, and the second dump statement are concatenated in sequence to obtain the snapshot dump statement. Among them, the first dump statement is used to dump the target value associated with the target key before executing the operation statement, and the second dump statement is used to dump the target value associated with the target key after executing the operation statement.

[0090] Specifically, in the resource manager, a first dump statement for dumping the target value associated with the target key before executing the operation statement is generated, and a second dump statement for dumping the target value after executing the operation statement is generated. The first dump statement, the operation statement, and the second dump statement are concatenated in sequence to obtain a snapshot dump statement. To prevent the snapshot dump statement from being interfered with by other database statements, the transaction start statement, the transaction execution statement, the first dump statement, the operation statement, and the second dump statement can be concatenated to obtain a snapshot dump statement. Among them, both the transaction start statement and the transaction execution statement are non-relational database statements. The transaction start statement can be Multi, and the transaction execution statement can be Exec. Based on this, the snapshot dump statement can be {transaction start statement first dump statement operation statement second dump statement transaction execution statement}. After the transaction start statement is executed, the subsequent statements will not be executed immediately but will be placed in the command queue in sequence. After the transaction execution statement is executed, the first dump statement, the operation statement, and the second dump statement will be executed in sequence. By concatenating the first dump statement, the operation statement, and the second dump statement to obtain a snapshot dump statement, the structure of the snapshot dump statement becomes clearer, and the dump logic becomes more concentrated. At the same time, when the snapshot dump statement is executed in a non-relational database later, the overhead of context switching can be reduced, which is beneficial to improving the efficiency of distributed transaction processing.

[0091] In a possible implementation, during the process of generating a first dump statement for serializing the target value associated with the target key before executing the operation statement and a second dump statement for serializing the target value after executing the operation statement, specifically, the dump instruction of the non-relational data can be concatenated with the target key to obtain a first dump statement for serializing the target value associated with the target key before executing the operation statement and a second dump statement for serializing the target value after executing the operation statement. Among them, the dump instruction is used to perform serialization encoding on the target value associated with the target key, and the dump instruction can be the DUMP command.

[0092] Specifically, the dump instruction for non-relational data is concatenated with the target key to obtain a first dump statement for serializing the target value associated with the target key before executing the operation statement and a second dump statement for serializing the target value after executing the operation statement. For example, the dump instruction is the DUMP instruction and the target key is Key. Since the key name of the target key does not change before and after executing the operation statement, only the target value associated with the target key changes, so both the first dump statement and the second dump statement can be DUMP Key. When the first dump statement or the second dump statement is executed in a non-relational database, the corresponding target value can be found through the target key Key for serialization. Implementing the dump through serialization using the dump instruction can apply an appropriate locking mechanism during the dump process. The locking mechanism can effectively avoid the risk of data corruption or loss caused by factors such as concurrent access, thereby ensuring the consistency and integrity of the dump information. This locking mechanism can effectively avoid the risk of data corruption or loss caused by factors such as concurrent access, further guaranteeing the accuracy and reliability of the dump information and providing an accurate data source for subsequent rollback operations.

[0093] Alternatively, the copy instruction for non-relational data is concatenated with the target key to obtain a first dump statement for copying the target value associated with the target key before executing the operation statement and a second dump statement for copying the target value after executing the operation statement. Among them, the copy instruction is used to copy the target value associated with the target key, and the copy instruction can be the COPY command. Specifically, the copy instruction for non-relational data is concatenated with the target key to obtain a first dump statement for copying the target value associated with the target key before executing the operation statement and a second dump statement for copying the target value after executing the operation statement. For example, the copy instruction is COPY, and the key name of the target key is Key. The first dump instruction can be COPY Key[Key]_pre_replica, where [Key]_pre_replica is the key name of the copy key of the target key before executing the operation statement. When the first dump instruction is executed in a non-relational database, the first dump instruction can copy the target value associated with the target key Key to the copy key Key_pre, that is, assign the target value to the copy key Key_pre. Similarly, the second dump instruction can be COPY Key[Key]_post_replica, where [Key]_post_replica is the key name of the copy key of the target key after executing the operation statement. Since the copy instruction can directly migrate the data in binary format quickly, performing the dump through the copy instruction can improve the speed of the dump process and is beneficial to improving the efficiency of distributed transaction processing.

[0094] After obtaining the snapshot dump statement, the resource manager sends the snapshot dump statement to the non-relational database. In the non-relational database, when the snapshot dump statement uses the dump instruction, a pre-snapshot of the target value associated with the target key before the execution of the operation statement is obtained, and the pre-snapshot is dumped based on the first dump statement. When dumping, the target value associated with the target key is obtained through the target key, and the target value is serialized using the non-relational database encoding to obtain the pre-dump information. Similarly, a post-snapshot of the target value after the execution of the operation statement is obtained, and the post-snapshot is dumped based on the second dump statement to obtain the post-dump information. When the snapshot dump statement uses the copy instruction, a pre-snapshot of the target key before the execution of the operation statement is obtained, and the pre-snapshot is copied based on the first dump statement to obtain the pre-dump information. A post-snapshot of the target key after the execution of the operation statement is obtained, and the post-snapshot is copied based on the second dump statement to obtain the post-dump information. Finally, the pre-dump information, the post-dump information, the pre-snapshot, and the post-snapshot are returned to the resource manager. By sending the snapshot dump statement to the non-relational database through the resource manager and executing the snapshot dump statement in the non-relational database to obtain the snapshot information, the resource manager can automatically proxy the operations of the target application without the need to write additional relevant code, avoiding intrusion into the code of the target application.

[0095] It should be noted that when using the dump instruction, the obtained pre-dump information is the value obtained by serializing the target value before the execution of the operation statement, and the obtained post-dump information is the value obtained by serializing the target value after the execution of the operation statement. When using the copy instruction, the pre-dump information is the copy key obtained by copying the target key before the execution of the operation statement, and the post-dump information is the copy key obtained by copying the target key after the execution of the operation statement.

[0096] It should also be noted that when the snapshot dump statement uses the dump instruction for dumping, the recorded snapshot information is the value obtained by serializing the target value. When the snapshot dump statement uses the copy instruction for dumping, the recorded snapshot information is the copy key. At the same time, hashtag processing is performed on the copy key. The hashtag processing can be the Hashtag function of the non-relational database. By performing a hash calculation on the value associated with the copy key, the copy key is mapped to a specific hash slot according to the hash result. Since the value associated with the copy key is the same as the target value associated with the target key at the same time (for example, both before the execution of the operation statement), the hash results obtained by performing a hash calculation on the value associated with the copy key and the target value associated with the target key are also the same. Therefore, based on the hashtag processing, it can be ensured that both the copy key and the target key are mapped to the same hash slot.

[0097] Refer to Figure 3 , Figure 3An optional process schematic diagram of the snapshot dump operation provided by the embodiments of the present disclosure. Extract the target key from the operation statement, store the value corresponding to the target key in the operation statement into the target key, and generate corresponding snapshot dump statements according to different dump methods in the resource manager. When dumping through the dump instruction DUMP, the snapshot dump statement is {Multi / DUMP Key(pre-snapshot) / operation statement / DUMP Key(post-snapshot) / Exec}; when dumping through the copy instruction COPY, the snapshot dump statement is {Multi / COPY Key[Key]_pre_replica(pre-snapshot replica) / operation statement / COPY Key[Key]_post_replica(post-snapshot replica) / Exec}. Finally, store the dump result in a non-relational database.

[0098] In a possible implementation, before concatenating the dump instruction of the non-relational data with the target key to obtain the first dump statement for serializing the target value associated with the target key before executing the operation statement and the second dump statement for serializing the target value after executing the operation statement, specifically, it may be to determine the space occupancy of the target value and the data consistency coefficient corresponding to the target application, normalize both the space occupancy and the data consistency coefficient, and perform a weighted sum of the normalized space occupancy and the normalized data consistency coefficient to obtain an instruction selection coefficient. Obtain the first preset coefficient range corresponding to the dump instruction and the second preset coefficient range corresponding to the copy instruction, compare the instruction selection coefficient with the first preset coefficient range and the second preset coefficient range respectively, and select the dump instruction or the copy instruction according to the comparison result. Among them, the data consistency coefficient corresponding to the target application is used to measure whether multiple operation statements submitted by the target application are applied to a global transaction with the same global identifier. If multiple operation statements submitted by the target application are applied to a global transaction with the same global identifier, it can be considered that the data consistency coefficient is relatively high. If multiple operation statements submitted by the target application are applied to global transactions with different global identifiers, it can be considered that the data consistency coefficient is relatively low. The instruction selection coefficient is used to measure the selection tendency of the dump instruction under the influence of the occupied space size of the target value and the data consistency coefficient. The first preset coefficient range is the interval in which the instruction selection coefficient corresponding to the dump instruction is located, and the second preset coefficient range is the interval in which the instruction selection coefficient corresponding to the copy instruction is located. The first preset coefficient range is different from the second preset coefficient range. The first preset coefficient range and the second preset coefficient range may not overlap, or there may be an overlapping part. For example, the first preset coefficient range is [0.4, 1], and the second preset coefficient range is [0, 0.5]. If the instruction selection coefficient is 0.3, the copy instruction is selected. If the instruction selection coefficient is 0.8, the dump instruction is selected. If the instruction selection coefficient is 0.55, either the copy instruction or the dump instruction can be selected.

[0099] Specifically, obtain the space occupancy of the target value and the data consistency coefficient between multiple operation statements submitted by the target application, normalize the space occupancy and the data consistency coefficient to the range of 0-1, configure a space occupancy weight and a data consistency weight for the space occupancy and the data consistency coefficient respectively, and perform weighted summation on the space occupancy and the data consistency coefficient according to the space occupancy weight and the data consistency weight to obtain an instruction selection coefficient. If it is necessary to focus on the impact of the data consistency of the operation statement on the dump, the value of the data consistency weight can be increased; if it is necessary to focus on the impact of the space occupancy of the target value on the dump, the value of the space occupancy weight can be increased. For example, the normalized value of the space occupancy is 0.6, and the normalized value of the data consistency coefficient is 0.5. If considering the impact of data consistency on the dump, the space occupancy weight can be 0.3 and the data consistency weight can be 0.7. At this time, the instruction selection coefficient is 0.3×0.6 + 0.7×0.5 = 0.53. Then, obtain the first preset coefficient range corresponding to the dump instruction and the second preset coefficient range corresponding to the copy instruction, compare the instruction selection coefficient with the first preset coefficient range and the second preset coefficient range respectively. If the instruction selection coefficient is within the first preset coefficient range, select the dump instruction; if the instruction selection coefficient is within the second preset coefficient range, select the copy instruction; if there is an overlapping range between the first preset coefficient range and the second preset coefficient range, and the instruction selection coefficient is within this overlapping range, either the dump instruction or the copy instruction can be selected. Since the dump instruction can ensure the consistency of transaction data, and the copy instruction can dump a large amount of data in a short time due to its simple operation, by calculating the instruction selection coefficient to select the corresponding instruction for dumping, it is possible to dynamically select the corresponding dumping method according to the current data state, avoid unnecessary resource waste on the premise of giving play to the advantages of the dumping method, and is conducive to improving the efficiency and quality of distributed processing.

[0100] In a possible implementation, the operation statement includes multiple target keys. The normalized space occupancy size and the normalized data consistency coefficient are weighted and summed. When obtaining the instruction selection coefficient, specifically, for each target key, the correlation coefficient with the remaining target keys is determined, the correlation coefficient is normalized, and according to the correlation coefficient, the weights corresponding to the space occupancy size, data consistency coefficient, and correlation coefficient of the same target key are determined. The normalized space occupancy size, normalized data consistency coefficient, and normalized correlation coefficient are weighted and summed according to the weights to obtain the instruction selection coefficient. Among them, the correlation coefficient between target keys is used to measure the correlation between each target key. For example, for the global transaction of book borrowing, the target keys can be user identification, order number, and book identification. The correlation coefficient between the user identification key and the order number key is relatively high, the correlation coefficient between the user identification key and the book identification key is relatively low, and the correlation coefficient between the order number and the book identification is relatively high. The data consistency coefficient of the same target key is used to measure whether the values associated with the target key are consistent in each branch transaction. For example, the same target key is applied to branch transaction A, branch transaction B, and branch transaction C. The value of the target key in branch transaction A is 5, the value of the target key in branch transaction B is 5, and the value of the target key in branch transaction C is 6. Then the data consistency coefficient of this target key can be 0.67.

[0101] Specifically, for each target key in the operation statement, the correlation coefficient between the current target key and the remaining target keys is determined, and the correlation coefficient is normalized. For the same target key, the space occupancy weight, data consistency weight, and correlation weight are respectively configured for the space occupancy size, data consistency coefficient, and correlation coefficient. The normalized space occupancy size, normalized data consistency coefficient, and normalized correlation coefficient are weighted and summed according to the space occupancy weight, data consistency weight, and correlation weight to obtain the instruction selection coefficient corresponding to one target key. For example, the target keys are user identification, book identification, and order number. The normalized correlation coefficient between the user identification key and the book identification key is 0.3, the normalized correlation coefficient between the user identification key and the order number key is 0.9, the normalized space occupancy size of the user identification key is 0.6, the normalized data consistency coefficient is 0.8, the space occupancy weight is 0.3, the data consistency weight is 0.4, and the correlation weight is 0.3. The instruction selection coefficient can be 0.6×0.3 + 0.8×0.4 + (0.9 + 0.6)×0.3 = 0.95. By calculating the instruction selection coefficient for each target key, the corresponding dump method can be accurately selected for each target key according to the instruction selection coefficient, further refining the snapshot dump process, realizing the optimal allocation of resources, and being able to reduce the storage cost and computing consumption while improving the efficiency of distributed transaction processing.

[0102] Step S204: Store the snapshot information into a non-relational database based on the global identifier and the branch identifier.

[0103] Among them, the snapshot information is a record of the non-relational database after executing the snapshot dump statement, including the pre-dump information after dumping the target value, the execution time of the snapshot dump statement, the target key of the operation statement, the global identifier of the global transaction opened by the operation statement, the branch identifier of the branch transaction in the global transaction, and other information.

[0104] Specifically, when the resource manager receives the pre-dump information, post-dump information, pre-snapshot, and post-snapshot from the non-relational database, it takes the pre-dump information and post-dump information as snapshot information, and stores the generated snapshot information into the non-relational database based on the global identifier and the branch identifier. When storing, a hash structure in the non-relational database is used for storage. The hash structure includes a hash identifier and hash fields. The global identifier can be used as the hash key, and the branch identifier can be used as the hash field. Data such as the dump information, execution time, and target key of the operation statement can be serialized and stored through a specific encoding rule. The specific encoding rule can be JSON or PROTOBUF, which is not specifically limited in this application. By storing the snapshot information into the non-relational database, the dependence of the transaction manager on other components can be reduced, and a more independent and stable distributed transaction processing architecture can be constructed. In addition, this storage method greatly facilitates the subsequent query operation of the snapshot information, which is beneficial to improving the efficiency of distributed transaction processing.

[0105] Step S205: In response to the processing request of the target application for the global transaction, query the snapshot information from the non-relational database according to the global identifier and the branch identifier, and execute the processing request based on the snapshot information.

[0106] Among them, the processing request is a request for processing the global transaction after executing the operation statement in the non-relational database, including a commit request and a rollback request.

[0107] Specifically, referring to Figure 4 , Figure 4An optional process schematic diagram for executing a processing request provided by an embodiment of the present disclosure. An operation object can submit processing requests for committing a global transaction and rolling back a global transaction in a target application. After the transaction manager responds to the processing request, it calls back the transaction manager. When the processing request is a commit request, the transaction manager verifies the current value and the post value, and determines whether to delete the snapshot information according to the verification result. When the processing request is a rollback request, if the dump instruction DUMP is used during dumping, at this time, the restore instruction is called to deserialize the serialized target value. The statement for calling the restore instruction RESTORE is RESTORE 0Key Key_RDB[REPLACE], where Key is the target key and Key_RDB is the serialized target value. The post value obtained after deserialization is verified with the current value, and the snapshot information is processed according to the verification result. If the copy instruction is used during dumping, at this time, the rename instruction is called to rename the copy key. The statement for calling the rename instruction RENAME is RENAME Key_Replica Key, where Key_Replica is the copy key. The post value of the renamed copy key is verified with the current value, and the snapshot information is processed according to the verification result. Finally, the processing result is stored in a non-relational database.

[0108] In a possible implementation manner, when executing a processing request based on snapshot information, specifically, the current value associated with the target key can be obtained from a non-relational database, and the post value associated with the target key in the snapshot information after executing the second dump statement is obtained, and the consistency between the current value and the post value is verified. When the current value is consistent with the post value, the processing request is executed based on the snapshot information. Among them, the commit request is used to submit a transaction operation request to the transaction manager. The transaction operations include verification, deleting snapshot information, etc. The current value associated with the target key is the value of the target key at a certain time point after the non-relational database executes the snapshot dump statement. The post value associated with the target key in the snapshot information can be regarded as the post-dump information after executing the second dump statement.

[0109] Specifically, when the processing request is a commit request, the transaction manager sends a commit request to the resource manager and releases the global lock. After the resource manager responds to the commit request, it obtains the current value associated with the target key from the non-relational database, and the post value associated with the target key in the snapshot information after executing the second dump statement, and verifies the consistency between the current value and the post value. If the current value is consistent with the post value, it means that after the non-relational database executes the operation statement submitted by the target application, no further operation is performed on the target key. At this time, the branch transaction can be committed and the snapshot information can be deleted.

[0110] When rolling back a request during request processing, the transaction manager initiates a rollback request to the resource manager and releases the global lock. The resource manager retrieves the current value associated with the target key from the non-relational database based on the global identifier and branch identifier, as well as the post-value associated with the target key in the snapshot information after executing the second dump statement, and verifies the consistency between the current value and the post-value. If the current value is consistent with the post-value, the global transaction can be rolled back at this time and the snapshot information can be deleted.

[0111] By verifying the current value and the post-value of the target key, it is possible to check whether other branch transactions have modified the value of the target key after the current branch transaction executes the operation statement, avoiding subsequent processing requests from affecting the operations of other branch transactions on the target key, ensuring the independence and correctness of the operations of each branch transaction, and thus ensuring the consistency and stability of the transaction manager during distributed transaction processing in a concurrent situation.

[0112] It should also be noted that when performing the verification, it can also be to query the mirror information of the branch transaction. The mirror information includes the current mirror information and the post-mirror information. The current mirror information is the information after executing the snapshot dump statement, and the post-mirror information is the information after executing the second dump statement. Verify the consistency between the current mirror information and the post-mirror information. If the current mirror information is consistent with the post-mirror information, the branch transaction can be committed and the mirror information can be deleted or the global transaction can be rolled back and the mirror information can be deleted.

[0113] In a possible implementation manner, when the request processing is a rollback request, when using the dump instruction for dumping and the current value is consistent with the post-value, during the process of executing the processing request based on the snapshot information, specifically, it can be to obtain the pre-value associated with the target key in the snapshot information after executing the first dump statement, execute the restore instruction to deserialize the pre-value, restore the current value to the deserialized pre-value, and delete the snapshot information to execute the rollback request. Among them, the pre-value associated with the target key in the snapshot information is obtained from the pre-dump information after executing the first dump statement. The restore instruction is used to deserialize the serialized value and restore the deserialized value to the specified key. The restore instruction can be the RESTORE command. Based on the restore instruction, a restore statement is generated. The restore statement can be {restore instruction expiration time target key key name serialized value}, where the expiration time refers to the expiration time of the target key. This restore statement is used to deserialize the serialized value and then restore it to the target key with the corresponding key name.

[0114] Specifically, obtain the pre-value associated with the target key in the snapshot information after executing the first dump statement, deserialize the pre-value through a restore instruction, restore the current value associated with the target key to the deserialized pre-value, and delete the snapshot information to execute the rollback request. For example, the restore instruction is the RESTORE instruction, the target key is Key, the current value associated with the target key is 1, and the pre-value is xxx / xxx / xxx (the deserialized value is 2). Then, the restore statement obtained based on the restore instruction can be RESTORE 0 Key xxx / xxx / xxx [REPLACE]. The 0 in this restore statement indicates that the expiration time is not set, and the target key Key is a permanent key. The value obtained after deserializing the pre-value xxx / xxx / xxx (2) is restored to the target key Key. Since the target key Key already exists and the current value is 1, [REPLACE] replaces the current value (1) of the target key Key with the deserialized value (2). After executing this restore statement, the value associated with the target key Key rolls back to 2. By executing the restore instruction to deserialize the pre-value to respond to the rollback request, it is possible to restore the value of the specified target key to the state before serialization without traversing a large number of transaction log records, avoiding partial data loss or inaccuracy that may occur during the overall rollback process, and also reducing the time cost of traversing the transaction log, thereby improving the accuracy and efficiency of distributed transaction processing. In addition, using the restore instruction for rollback only requires calling the instruction in the corresponding branch transaction and does not require adding additional rollback logic in the global transaction, avoiding intrusion into the code of the target application, effectively reducing the complexity of the target application code, and reducing the maintenance cost of the target application.

[0115] In a possible implementation manner, when the request processing is a rollback request, when using the replication instruction for dumping and the current value is consistent with the post-value, during the process of executing the processing request based on the snapshot information, specifically, obtain the replication key corresponding to the target key in the snapshot information after executing the first dump statement, execute the rename instruction to rename the replication key to the target key and delete the snapshot information to execute the rollback request. Among them, the replication key corresponding to the target key in the snapshot information is obtained from the pre-dump information after executing the first dump statement. The rename instruction is used to rename the replication key. The rename instruction can be the RENAME command. Based on the rename instruction, a rename statement is generated. The rename statement can be {rename instruction current key name named key name}. The current key name can be the key name of the replication key, and the named key name can be the key name of the target key. The rename statement is used to rename the replication key name to the target key name and overwrite the current value of the target key with the value of the replication key.

[0116] Specifically, obtain the copy key corresponding to the target key in the snapshot information after executing the first dump statement, execute a rename instruction to rename the key name of the copy key to the key name of the target key. Since the key name of the target key already exists, the current value of the target key will be overwritten by the value of the copy key after renaming. Finally, delete the snapshot information to execute the rollback request. For example, the rename instruction is the RENAME command, the key name of the target key is Key, the current value associated with the target key is 1, the key name of the copy key is Key_COPY, and the value of the copy key is 2. The rename statement generated based on the rename instruction can be {RENAME Key_COPY Key}. After executing the rename statement, after renaming the key name Key_COPY of the copy key to the key name Key of the target key, the current value (1) of the target key is overwritten by the value (2) of the copy key, realizing that the value associated with the target key Key is rolled back to 2. Since the rename instruction essentially replaces one key name with another, the rollback request is responded to by executing the rename instruction to rename the key name of the copy key to the key name of the target key, without any data processing on the value associated with the target key, greatly simplifying the operation process. Therefore, the speed of executing the rollback operation is relatively fast. In addition, the rename instruction has no restrictions on the data type of the key-value pair. This feature improves the compatibility of distributed transaction processing, avoids the additional overhead and potential errors caused by data type conversion when processing different types of data, and further improves the efficiency of distributed transaction processing.

[0117] In a possible implementation, after registering a branch transaction with the transaction manager, the transaction manager locks the target key. The snapshot information includes the snapshot key associated with the target value when dumping. In the process of generating a snapshot dump statement for dumping the target value associated with the target key, specifically, it may be to determine the snapshot key corresponding to the target key, query whether the snapshot key exists in the non-relational database. When the snapshot key does not exist in the non-relational database, generate a snapshot dump statement for dumping the target value associated with the target key using the snapshot key. Among them, the snapshot key can be regarded as the copy key obtained after dumping the target key, and the snapshot key is used to replace the target key to execute the operation statement.

[0118] Specifically, to ensure the isolation of multi-branch transactions, an exclusive lock is added to the write operation of the non-relational database, so that only one transaction can hold the lock on the non-relational database at the same time, that is, only one transaction can perform a write operation on the target key. On this basis, the read operation of the non-relational database is converted into a snapshot read. Based on this, the snapshot key corresponding to the target key is determined, and it is queried whether the snapshot key exists in the non-relational database. If the snapshot key does not exist in the non-relational database, the dump instruction can be concatenated with the target key to obtain the first dump statement, and the recovery instruction can be concatenated with the target key and the snapshot key to obtain the recovery statement, and the first dump statement and the recovery statement can be concatenated to obtain the snapshot dump statement; alternatively, the copy instruction can also be concatenated with the target key and the snapshot key to obtain the first dump statement, and the first dump statement is the snapshot dump statement. After obtaining the snapshot dump statement, the snapshot dump statement is executed to dump the target value associated with the target key to construct the snapshot key, and the target value is written into the snapshot key to obtain the snapshot information associated with the snapshot key. If the snapshot key corresponding to the target key already exists in the non-relational database, the target value associated with the target key is directly written into the snapshot key to obtain the snapshot information associated with the snapshot key. By generating a snapshot dump statement for dumping the target value associated with the target key using the snapshot key in the case where the snapshot key does not exist, the target value associated with the target key in the non-relational database at a certain moment (before executing the operation statement) can be accurately obtained according to the generated snapshot dump statement, and the snapshot key can be constructed based on the target value. This method does not require real-time acquisition of the latest data state of the non-relational database, thereby reducing the overhead of the non-relational database and facilitating the improvement of the response speed of the non-relational database.

[0119] Refer to Figure 5 , Figure 5An optional process schematic diagram of the snapshot read one-phase provided by the embodiments of the present disclosure. After an operation object performs an operation in a target application, the data Value generated by the operation is written into a specified target key Key through the statement SET Key Value, so that the data Value serves as the target value associated with the target key Key. Then, the target value associated with the target key Key is obtained according to the statement GET Key. The snapshot key of the current global transaction is obtained, and it is queried whether the snapshot key corresponding to the target key exists. If the snapshot key corresponding to the target key does not exist, the target key is dumped based on a dump instruction or a copy instruction to construct a snapshot key. When constructing a snapshot key based on a dump instruction, the target value associated with the target key is serialized based on the dump statement DUMP Key, and then deserialized based on the restore statement RESTORE 0[Key]_Snapshot Key[REPLACE], and the deserialized target value is written into the snapshot key [Key]_Snapshot. The snapshot information associated with the snapshot key is obtained according to the statement GET[Key]_Snapshot. Alternatively, when constructing a snapshot key based on a copy instruction, the target value associated with the target key Key is copied and stored into a snapshot key with the key name [Key]_Snapshot based on the dump statement COPY Key[Key]_Snapshot, and the snapshot information associated with the snapshot key is obtained according to the statement GET[Key]_Snapshot. If the snapshot key corresponding to the target key exists, the target value associated with the target key is directly written into the snapshot key according to the statement SET[Key]_Snapshot Value, and the snapshot information associated with the snapshot key is obtained according to the statement GET[Key]_Snapshot.

[0120] In a possible implementation manner, after generating a snapshot dump statement for dumping the target value associated with the target key, when there is a snapshot key in the non-relational database, the snapshot information corresponding to the snapshot key is obtained from the non-relational database, the snapshot information is updated based on the operation statement, in response to a processing request, the updated snapshot information is queried from the non-relational database according to the global identifier and the branch identifier, and the processing request is executed based on the updated snapshot information.

[0121] Specifically, the snapshot information corresponding to the snapshot key is obtained from the non-relational database, and the operation statement is executed in the snapshot information corresponding to the snapshot key to update the snapshot information. When the target application submits a processing request, if the processing request is a commit request, the updated snapshot information is queried from the non-relational database according to the global identifier and the branch identifier, the key name of the snapshot key is renamed as the key name of the target key, and the updated snapshot information of the snapshot key is overwritten into the target key, and finally the snapshot information is deleted. If the processing request is a rollback request, the updated snapshot information is directly deleted. Refer to Figure 6 , Figure 6An optional process schematic diagram of snapshot read two-phase provided by an embodiment of the present disclosure. The processing requests of the operation object in the target application include submitting a global transaction or rolling back a global transaction. The processing requests are sent to the resource manager, and the resource manager sends the processing requests down for callback to the resource manager, and the resource manager responds to the processing requests. When the processing request is to submit a global transaction, based on the rename instruction, the key name of the snapshot key is renamed to the key name of the target key. For example, the call statement RENAME [Key]_SnapshotKey renames the key name [Key]_Snapshot of the snapshot key to the key name Key of the target key, and the updated snapshot information of the snapshot key is overwritten into the target key. Finally, the snapshot information is deleted, and the processing result is saved to the non-relational database. When the processing request is to roll back a global transaction, the updated snapshot information is directly deleted, and the processing result is saved to the non-relational database. It should be noted that after executing the submission of the global transaction or the rollback of the global transaction, only the snapshot information is deleted, but the snapshot key corresponding to the target key can be retained for subsequent submission or rollback based on the snapshot key. By directly operating on the snapshot key to respond to the processing request, it can ensure the consistent state of the target value associated with the target key before the execution of the operation statement. Even if the snapshot information of the snapshot key is updated during the execution of the operation statement, it can ensure that the target value associated with the target key read after the execution of the operation statement is the same as that before the execution of the operation statement, achieving the isolation level of repeatable read and avoiding data inconsistency problems such as phantom reads. In addition, the method of directly overwriting the updated snapshot information to the target key to respond to the commit request and directly deleting the updated snapshot information to respond to the rollback request does not require additional queries on the snapshot key and its updated snapshot information, reducing the time cost of data acquisition and effectively improving the efficiency of distributed transaction processing.

[0122] In a possible implementation, after registering a branch transaction with the transaction manager, in order to ensure the isolation of multi-branch transactions, an exclusive lock can also be added to the write operation of the non-relational database, and no lock is added to the read operation of the non-relational database. By adding an exclusive lock to the write operation, the non-relational database can only have one transaction holding the lock at the same time, that is, only one transaction can perform a write operation on the target key, but no lock is added to the read operation, so that multiple read operations can be performed simultaneously, maintaining a high read performance of the non-relational database. In scenarios where the requirement for data consistency is not high and the focus is on read performance, it can improve the throughput and response speed of the non-relational database. At the same time, the non-relational database does not need to consume time and resources to manage the locks of read operations, reducing the lock management overhead. In addition, the strategy of adding a lock to the write operation and not adding a lock to the read operation effectively avoids deadlock problems, improves the stability and reliability of the non-relational database, and thus improves the efficiency of distributed transaction processing.

[0123] In a possible implementation, after registering a branch transaction with the transaction manager, to ensure the isolation of multi-branch transactions, an exclusive lock can also be added to write operations on a non-relational database, and a shared lock can be added to read operations. Since a shared lock is added to the read operations on the non-relational database, multiple branch transactions can simultaneously perform read operations on the target key, but cannot add an exclusive lock to perform write operations on the target key. Through the combined use of exclusive locks and shared locks, it is possible to effectively prevent multiple branch transactions from performing write operations on the same target key, ensuring data consistency. At the same time, multiple branch transactions can simultaneously perform read operations on the same target key, improving the concurrency of read operations. In scenarios with high data consistency requirements, it is beneficial to improve the efficiency of distributed transaction processing.

[0124] Refer to Figure 7 , Figure 7 FIG. is an optional overall logic diagram of the transaction processing method provided by the embodiments of the present disclosure. The principle of the transaction processing method in the embodiments of the present disclosure will be described in detail below:

[0125] The transaction processing method provided by the embodiments of the present disclosure is applied to the DTP model. The DTP model includes a resource manager, a transaction manager, and a non-relational database. The transaction manager is used to manage global transactions, including global transaction registration, branch transaction registration, release of global locks, transaction commit callbacks, transaction rollback callbacks, etc. The resource manager is used to execute transaction operations on the non-relational database and can manage the non-relational database in the form of a component. The transaction processing method provided by the embodiments of the present disclosure performs distributed transaction processing through two-phase commit (2PC). The first-phase transaction is the preparation phase, and the resource manager implements operations such as operation statement parsing, branch transaction reporting, and snapshot dumping. The second-phase transaction is the commit phase or the rollback phase, and the transaction manager calls back the operations of transaction commit and transaction rollback to the resource manager for corresponding processing.

[0126] First, the operation object registers a global transaction with the transaction manager based on the target application, applies for a global identifier of the global transaction. After registering the global transaction, the transaction manager generates a corresponding global identifier and sends the global identifier to the resource manager.

[0127] Next, a one-phase transaction is carried out. The resource manager intercepts the operation statements submitted by the target application through the database operation interface provided by the non-relational database, parses the target keys to be processed according to the operation statements, and registers branch transactions with the transaction manager according to the corresponding target keys. After registering the branch transactions, the transaction manager generates corresponding branch identifiers, adds a global lock to the target keys to ensure the isolation of the transaction, and sends the branch transactions to the resource manager. In the resource manager, the pre-snapshot dump operation is calculated to generate the corresponding first dump statement; the operation statement is recorded; the post-snapshot dump operation is calculated to generate the corresponding second dump statement. After concatenating the first dump statement, the operation statement, and the second dump statement, the snapshot dump statement is obtained and sent to the non-relational database. After executing the snapshot dump statement for the same branch transaction in the non-relational database, the pre-dump information and the post-dump information are obtained. The snapshot information is constructed based on the pre-dump information. The snapshot information includes the pre-dump information after the target value is dumped, the execution time of the snapshot dump statement, the target key of the operation statement, the global identifier of the global transaction started by the operation statement, the branch identifier of the branch transaction in the global transaction, and other information. The resource manager receives the snapshot information sent by the non-relational database and records the pre-dump information obtained after executing the first dump statement, and sends the snapshot information to the non-relational database for storage. Thus, the one-phase transaction is completed.

[0128] During the process of dumping, there are two dumping methods in the non-relational database. One is to call the dump instruction to serialize the target value associated with the target key, and the other is to call the copy instruction to copy the target key to obtain a copy key to achieve dumping. If the dump instruction is called for dumping, the snapshot information generated by the resource manager directly saves the serialized target value; if the copy instruction is called for dumping, the resource manager only needs to save the copy key corresponding to the target key. At the same time, hash tag processing is performed on the copy key to ensure that the copy key and the target key are in the same hash slot.

[0129] When sending the snapshot information to the non-relational database for storage, a hash structure in the non-relational database is used for storage. The hash structure includes a hash identifier and a hash field. The global identifier can be used as the hash key, and the branch identifier can be used as the hash field. Data such as the dump information, the execution time, and the target key of the operation statement can be serialized through a specific encoding rule and then stored.

[0130] It should be noted that the processing of the post-dump information can be an optional operation, mainly used to verify whether the current value of the target key is consistent with the post-value obtained through the post-dump information in the two-phase transaction, so as to avoid some operations that do not access the branch transaction from modifying the value of the target key in the branch transaction.

[0131] Next, perform the two-phase operation of the transaction. If the operation object sends a commit request for the global transaction to the transaction manager in the target application, the transaction manager decides whether to commit the transaction. If it is confirmed to commit the transaction, a commit request is sent to the branch transaction, a transaction commit request is initiated to the resource manager, and the global lock is released. In the resource manager, verify whether the current mirror information is consistent with the post-mirror information. If the current value is consistent with the post value, delete the snapshot information to complete the two-phase transaction commit.

[0132] If the operation object sends a rollback request for the global transaction to the transaction manager in the target application, the transaction manager decides whether to roll back. If it is confirmed to roll back the transaction, a rollback request is sent to the branch transaction, and a transaction rollback request is initiated to the resource manager. The resource manager queries the mirror information of the corresponding branch transaction in the non-relational database according to the global identifier and the branch identifier. The mirror information includes the pre-mirror information and the post-mirror information, and will verify whether the current mirror information is consistent with the post-mirror information. If the current value is consistent with the post value, take out the pre-dump information in the mirror information. If the dump instruction is used for dumping, at this time, the deserialization instruction is used to deserialize the serialized target value to obtain the snapshot information before the execution of the operation statement, and the rollback request is executed in the non-relational database according to the deserialized snapshot information to complete the two-phase transaction rollback. If the copy instruction is used for dumping, at this time, the rename instruction is used to rename the key name of the copy key to the key name of the target key, and the value of the copy key is used to overwrite the current value of the target key to obtain the snapshot information before the execution of the operation statement, and the rollback request is executed in the non-relational database according to this snapshot information to complete the two-phase transaction rollback. Thus, the complete transaction processing is completed.

[0133] The transaction processing method provided by the embodiments of the present disclosure realizes the access of distributed transactions of non-relational databases through the transaction control interface of the DTP model, executes snapshot dump statements in relational databases to proxy the operations of the operation object on non-relational databases, automatically records pre-snapshots and post-snapshots, and realizes transaction commit and transaction rollback without introducing additional code, avoiding the intrusion of the code of the target application and reducing the complexity and maintenance cost of the code of the target application. In addition, the mechanism of adding a global lock to the write operation of the non-relational database and converting the read operation into a snapshot read can achieve the isolation level of repeatable read while ensuring the performance of the non-relational database, avoiding problems such as phantom reads and data inconsistencies, thereby effectively improving the efficiency of distributed transaction processing.

[0134] In a possible implementation manner, the transaction processing method provided by the embodiments of the present disclosure can be applied to the transaction processing of Redis databases. Refer to Figure 8 , Figure 8An alternative system architecture diagram of the transaction processing method provided by the embodiments of the present disclosure includes multiple target applications, multiple resource managers, a transaction manager, and a non-relational database. Based on Figure 8 the DTP model in

[0135] proxy the Redis database operations of the operation object. First, implement the distributed transaction access of the non-relational database through the transaction control interface of the DTP model, and configure the resource manager component of the Redis database so that the resource manager component can manage the Redis database resources and interact with the Redis database. When the operation object requests to start a global transaction in the target application, intercept the operation statements submitted by the target application through the resource manager, report the branch transaction to the transaction manager based on the target key in the operation statement, calculate the snapshot dump statement based on the target key in the operation statement, and execute core operations such as committing the transaction and rolling back the transaction. At the same time, add a global lock to the target key through the transaction manager, add an exclusive lock to the write operation of the Redis database, and convert the read operation of the Redis database into a snapshot read to ensure the isolation of the branch transaction and avoid the influence between multiple branch transactions, thereby improving the efficiency of distributed transaction processing of the Redis database.

[0136] Refer to Figure 9 , Figure 9 which is a schematic structural diagram of the transaction processing device provided by the embodiments of the present disclosure. The transaction processing device 900 includes:

[0137] A first processing module 901, configured to obtain the global identifier of the global transaction after the target application starts the global transaction;

[0138] A second processing module 902, configured to obtain the operation statement submitted by the target application, extract the target key to be operated from the operation statement, register the branch transaction under the global transaction with the transaction manager based on the target key, and receive the branch identifier of the branch transaction returned by the transaction manager;

[0139] The third processing module 903 is configured to generate a snapshot dump statement for dumping the target value associated with the target key, send the snapshot dump statement to the non-relational database, and receive the snapshot information returned after the non-relational database executes the operation statement and the snapshot dump statement;

[0140] The fourth processing module 904 is configured to store the snapshot information in the non-relational database based on the global identifier and the branch identifier;

[0141] The fifth processing module 905 is configured to, in response to a processing request of the target application for the global transaction, query the snapshot information from the non-relational database according to the global identifier and the branch identifier, and execute the processing request based on the snapshot information.

[0142] Furthermore, the third processing module 903 is further configured to:

[0143] Generate a first dump statement for dumping the target value associated with the target key before executing the operation statement and a second dump statement for dumping the target value after executing the operation statement;

[0144] Concatenate the first dump statement, the operation statement, and the second dump statement in sequence to obtain the snapshot dump statement.

[0145] Furthermore, the third processing module 903 is further configured to:

[0146] Concatenate the dump instruction of the non-relational data with the target key to obtain a first dump statement for serializing the target value associated with the target key before executing the operation statement and a second dump statement for serializing the target value after executing the operation statement;

[0147] Alternatively, concatenate the copy instruction of the non-relational data with the target key to obtain a first dump statement for copying the target value associated with the target key before executing the operation statement and a second dump statement for copying the target value after executing the operation statement.

[0148] Furthermore, the third processing module 903 is further configured to:

[0149] Determine the space occupancy size of the target value and the data consistency coefficient corresponding to the target application, and normalize both the space occupancy size and the data consistency coefficient;

[0150] Perform a weighted sum of the normalized space occupancy size and the normalized data consistency coefficient to obtain an instruction selection coefficient;

[0151] Obtain the first preset coefficient range corresponding to the dump instruction and the second preset coefficient range corresponding to the copy instruction, compare the instruction selection coefficient with the first preset coefficient range and the second preset coefficient range respectively, and select the dump instruction or the copy instruction according to the comparison result, where the first preset coefficient range is different from the second preset coefficient range.

[0152] Further, the third processing module 903 is further configured to:

[0153] For each target key, determine the correlation coefficient with the remaining target keys, and normalize the correlation coefficient;

[0154] According to the correlation coefficient, determine the weights corresponding to the space occupancy size, data consistency coefficient, and correlation coefficient of the same target key respectively;

[0155] Perform weighted summation on the normalized space occupancy size, the normalized data consistency coefficient, and the normalized correlation coefficient according to the weights to obtain the instruction selection coefficient.

[0156] Further, the fifth processing module 905 is further configured to:

[0157] Obtain the current value associated with the target key from the non-relational database, and the post value associated with the target key in the snapshot information after executing the second dump statement;

[0158] Verify the consistency between the current value and the post value, and when the current value is consistent with the post value, execute the processing request based on the snapshot information.

[0159] Further, the fifth processing module 905 is further configured to:

[0160] When the current value is consistent with the post value, obtain the pre value associated with the target key in the snapshot information after executing the first dump statement;

[0161] Execute the restore instruction to deserialize the pre value, restore the current value to the deserialized pre value, and delete the snapshot information to execute the rollback request.

[0162] Further, the fifth processing module 905 is further configured to: <9000360>When the current value is consistent with the post value, obtain the copy key corresponding to the target key in the snapshot information after executing the first dump statement;

[0164] Execute the rename instruction to rename the copy key to the target key and delete the snapshot information to execute the rollback request.

[0165] Further, the fifth processing module 905 is further configured to:

[0166] Determine the snapshot key corresponding to the target key, and query whether the snapshot key exists in the non-relational database;

[0167] When the snapshot key does not exist in the non-relational database, generate a snapshot dump statement for dumping the target value associated with the target key by using the snapshot key.

[0168] Further, the fifth processing module 905 is further configured to:

[0169] When the snapshot key exists in the non-relational database, obtain the snapshot information corresponding to the snapshot key from the non-relational database, and update the snapshot information based on the operation statement;

[0170] In response to the processing request, query the updated snapshot information from the non-relational database according to the global identifier and the branch identifier, and execute the processing request based on the updated snapshot information.

[0171] In summary, the transaction processing device provided by the embodiments of the present disclosure obtains the global identifier of the global transaction after the target application starts the global transaction, obtains the operation statement submitted by the target application, extracts the target key to be operated from the operation statement, registers the branch transaction under the global transaction with the transaction manager of the DTP model based on the target key, and receives the branch identifier of the branch transaction returned by the transaction manager. Thus, by introducing the DTP model, the non-relational database can support distributed transactions. On this basis, by generating a snapshot dump statement for dumping the target value associated with the target key, sending the operation statement and the snapshot dump statement to the non-relational database, receiving the snapshot information returned after the non-relational database executes the operation statement and the snapshot dump statement, and storing the snapshot information in the non-relational database based on the global identifier and the branch identifier, it can automatically proxy the operations of the target application through the resource manager, without the need to write relevant code additionally, avoiding intrusion into the code of the target application, and then by responding to the processing request of the target application for the global transaction, querying the snapshot information from the non-relational database according to the global identifier and the branch identifier, and executing the processing request based on the snapshot information, the entire process of transaction processing does not require manual operation, thereby effectively improving the efficiency of distributed transaction processing.

[0172] The electronic device provided by the embodiments of the present disclosure for executing the above transaction processing method may be a terminal. Refer to Figure 10 , Figure 10 which is a partial structural block diagram of the terminal provided by the embodiments of the present disclosure. The terminal includes components such as a camera component 1010, a first memory 1020, an input unit 1030, a display unit 1040, a sensor 1050, an audio circuit 1060, a wireless fidelity (WiFi) module 1070, a first processor 1080, and a first power supply 1090. Those skilled in the art can understand,Figure 10 The terminal structure shown does not constitute a limitation on the terminal, and it may include more or fewer components than shown, or combine certain components, or have different component arrangements.

[0173] The camera assembly 1010 can be used to collect images or videos. Optionally, the camera assembly 1010 includes a front camera and a rear camera. Generally, the front camera is disposed on the front panel of the terminal, and the rear camera is disposed on the back of the terminal. In some embodiments, there are at least two rear cameras, which are any one of a main camera, a depth camera, a wide-angle camera, and a telephoto camera, so as to implement the function of background blurring by fusing the main camera and the depth camera, panoramic shooting by fusing the main camera and the wide-angle camera, and VR (Virtual Reality) shooting function or other fusion shooting functions.

[0174] The first memory 1020 can be used to store software programs and modules. The first processor 1080 executes various functional applications and data processing of the terminal by running the software programs and modules stored in the first memory 1020.

[0175] The input unit 1030 can be used to receive input digital or character information, and generate key signal inputs related to the settings and function controls of the terminal. Specifically, the input unit 1030 may include a touch panel 1031 and other input devices 1032.

[0176] The display unit 1040 can be used to display input information or provided information and various menus of the terminal. The display unit 1040 may include a display panel 1041.

[0177] The audio circuit 1060, the speaker 1061, and the microphone 1062 can provide an audio interface.

[0178] The first power supply 1090 can be alternating current, direct current, a primary battery, or a rechargeable battery.

[0179] The number of sensors 1050 can be one or more. The one or more sensors 1050 include, but are not limited to: an acceleration sensor, a gyroscope sensor, a pressure sensor, an optical sensor, etc. Among them:

[0180] The acceleration sensor can detect the magnitudes of accelerations on the three coordinate axes of the coordinate system established by the terminal. For example, the acceleration sensor can be used to detect the components of the gravitational acceleration on the three coordinate axes. The first processor 1080 can control the display unit 1040 to display the user interface in a landscape view or a portrait view according to the gravitational acceleration signal collected by the acceleration sensor. The acceleration sensor can also be used for game or collection of user's motion data.

[0181] The gyroscope sensor can detect the body direction and rotation angle of the terminal, and the gyroscope sensor can cooperate with the acceleration sensor to collect the 3D actions of the user on the terminal. According to the data collected by the gyroscope sensor, the first processor 1080 can implement the following functions: motion sensing (such as changing the UI according to the user's tilting operation), image stabilization during shooting, game control, and inertial navigation.

[0182] The pressure sensor can be disposed on the side frame of the terminal and / or the lower layer of the display unit 1040. When the pressure sensor is disposed on the side frame of the terminal, it can detect the holding signal of the user on the terminal, and the first processor 1080 can perform left / right hand recognition or quick operation according to the holding signal collected by the pressure sensor. When the pressure sensor is disposed on the lower layer of the display unit 1040, the first processor 1080 can control the operable controls on the UI interface according to the pressure operation of the user on the display unit 1040. The operable controls include at least one of button controls, scroll bar controls, icon controls, and menu controls.

[0183] The optical sensor is used to collect the ambient light intensity. In one embodiment, the first processor 1080 can control the display brightness of the display unit 1040 according to the ambient light intensity collected by the optical sensor. Specifically, when the ambient light intensity is high, the display brightness of the display unit 1040 is increased; when the ambient light intensity is low, the display brightness of the display unit 1040 is decreased. In another embodiment, the first processor 1080 can also dynamically adjust the shooting parameters of the camera module 1010 according to the ambient light intensity collected by the optical sensor.

[0184] In this embodiment, the first processor 1080 included in the terminal can execute the transaction processing method of the previous embodiment.

[0185] The electronic device provided by the embodiments of the present disclosure for executing the above transaction processing method can also be a server. Refer to Figure 11 , Figure 11This is a partial structural block diagram of the server provided by the embodiments of the present disclosure. The server may vary greatly due to configuration or performance differences, and may include one or more second processors 1110 and a second memory 1130, and one or more storage media 1140 (such as one or more mass storage devices) for storing application programs 1143 or data 1142. Among them, the second memory 1130 and the storage media 1140 may be transient storage or persistent storage. The program stored in the storage media 1140 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations on the server. Further, the second processor 1110 may be configured to communicate with the storage media 1140 and execute a series of instruction operations in the storage media 1140 on the server.

[0186] The server may further include one or more second power supplies 1120, one or more wired or wireless network interfaces 1150, one or more input / output interfaces 1160, and / or one or more operating systems 1141, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, and so on.

[0187] The second processor 1110 in the server may be used to execute the transaction processing method.

[0188] The embodiments of the present disclosure further provide a computer-readable storage medium for storing a computer program for executing the transaction processing method of the foregoing various embodiments.

[0189] The embodiments of the present disclosure further provide a computer program product including a computer program stored in a computer-readable storage medium. The processor of the computer device reads the computer program from the computer-readable storage medium, and the processor executes the computer program, so that the computer device executes the transaction processing method described above.

[0190] The terms "first", "second", "third", "fourth", etc. (if any) in the description of the present disclosure and the above-mentioned drawings are used to distinguish similar objects and do not necessarily describe a specific order or sequence. It should be understood that the data used in this way can be interchanged under appropriate circumstances so as to describe the embodiments of the present disclosure. For example, it can be implemented in an order other than those illustrated or described herein. In addition, the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device comprising a series of steps or units does not necessarily limit to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products or devices.

[0191] It should be understood that in the present disclosure, "at least one (item)" means one or more, and "a plurality" means two or more. "And / or" is used to describe the association relationship of associated objects and indicates that three relationships can exist. For example, "A and / or B" can mean: only A exists, only B exists, and both A and B exist at the same time. Among them, A and B can be singular or plural. The character " / " generally means that the associated objects before and after are in an "or" relationship. "At least one (one) of the following" or its similar expression means any combination of these items, including any combination of single item (one) or plural items (ones). For example, at least one (one) of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.

[0192] It should be understood that in the description of the embodiments of the present disclosure, the meaning of "a plurality (or a number of)" is more than two. Understandings such as "greater than", "less than", "exceeding", etc. do not include the present number, and understandings such as "above", "below", "within", etc. include the present number.

[0193] In several embodiments provided by the present disclosure, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed coupling or direct coupling or communication connection to each other can be through some interfaces, and the indirect coupling or communication connection of devices or units can be in electrical, mechanical or other forms.

[0194] The unit described as a separate component may or may not be physically separated. The component displayed as a unit may or may not be a physical unit, that is, it may be located in one place or distributed across multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0195] In addition, each functional unit in various embodiments of the present disclosure may be integrated in a processing unit, may exist separately as individual physical units, or two or more units may be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of a software functional unit.

[0196] If the integrated unit 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 present disclosure, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods in various embodiments of the present disclosure. The aforementioned storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memories (ROM), random access memories (RAM), magnetic disks, or optical discs that can store program codes.

[0197] It should also be understood that the various embodiments provided in the present disclosure can be combined arbitrarily to achieve different technical effects.

[0198] The above is a specific description of the preferred embodiments of the present disclosure, but the present disclosure is not limited to the above-mentioned embodiments. Those skilled in the art can also make various equivalent deformations or substitutions without departing from the spirit of the present disclosure, and these equivalent deformations or substitutions are all included within the scope defined by the claims of the present disclosure.

Claims

1. A transaction processing method, characterized in that, A resource manager applied to a DTP model, the DTP model further including a transaction manager, and the transaction processing method includes: After a target application starts a global transaction, obtain the global identifier of the global transaction; Obtain the operation statement submitted by the target application, extract the target key to be operated from the operation statement, register a branch transaction under the global transaction with the transaction manager based on the target key, and receive the branch identifier of the branch transaction returned by the transaction manager; Generate a snapshot dump statement for dumping the target value associated with the target key, send the snapshot dump statement to a non-relational database, and receive the snapshot information returned by the non-relational database after executing the operation statement and the snapshot dump statement; Store the snapshot information in the non-relational database based on the global identifier and the branch identifier; In response to a processing request of the target application for the global transaction, query the snapshot information from the non-relational database according to the global identifier and the branch identifier, and execute the processing request based on the snapshot information.

2. The transaction processing method according to claim 1, characterized in that, The generating a snapshot dump statement for dumping the target value associated with the target key includes: Generate a first dump statement for dumping the target value associated with the target key before executing the operation statement and a second dump statement for dumping the target value after executing the operation statement; Concatenate the first dump statement, the operation statement, and the second dump statement in sequence to obtain a snapshot dump statement.

3. The transaction processing method according to claim 2, wherein The generating a first dump statement for serializing the target value associated with the target key before executing the operation statement and a second dump statement for serializing the target value after executing the operation statement includes: Concatenate the dump instruction of the non-relational data with the target key to obtain a first dump statement for serializing the target value associated with the target key before executing the operation statement and a second dump statement for serializing the target value after executing the operation statement; Alternatively, concatenate the copy instruction of the non-relational data with the target key to obtain a first dump statement for copying the target value associated with the target key before executing the operation statement and a second dump statement for copying the target value after executing the operation statement.

4. The transaction processing method according to claim 3, wherein Before the concatenating the dump instruction of the non-relational data with the target key to obtain a first dump statement for serializing the target value associated with the target key before executing the operation statement and a second dump statement for serializing the target value after executing the operation statement, the transaction processing method further includes: Determine the space occupancy size of the target value and the data consistency coefficient corresponding to the target application, and normalize both the space occupancy size and the data consistency coefficient; Perform a weighted sum of the normalized space occupancy size and the normalized data consistency coefficient to obtain an instruction selection coefficient; Obtain a first preset coefficient range corresponding to the dump instruction and a second preset coefficient range corresponding to the copy instruction, compare the instruction selection coefficient with the first preset coefficient range and the second preset coefficient range respectively, and select the dump instruction or the copy instruction according to the comparison result, where the first preset coefficient range is different from the second preset coefficient range.

5. The transaction processing method according to claim 4, wherein The operation statement includes a plurality of the target keys, and the weighted sum of the normalized space occupancy size and the normalized data consistency coefficient to obtain an instruction selection coefficient includes: For each of the target keys, determine the correlation coefficient with the remaining target keys and normalize the correlation coefficient; According to the correlation coefficient, determine the weights corresponding to the space occupancy size, the data consistency coefficient, and the correlation coefficient of the same target key; Perform a weighted sum of the normalized space occupancy size, the normalized data consistency coefficient, and the normalized correlation coefficient according to the weights to obtain an instruction selection coefficient.

6. The transaction processing method according to claim 1, wherein The processing request includes a submission request, and the execution of the processing request based on the snapshot information includes: Obtain the current value associated with the target key from the non-relational database, and the post value associated with the target key in the snapshot information after executing the second dump statement; Verify the consistency between the current value and the post value, and when the current value is consistent with the post value, execute the processing request based on the snapshot information.

7. The transaction processing method according to claim 6, wherein The processing request includes a rollback request, and the execution of the processing request based on the snapshot information when the current value is consistent with the post value includes: When the current value is consistent with the post value, obtain the pre value associated with the target key in the snapshot information after executing the first dump statement; Execute a recovery instruction to deserialize the pre value, restore the current value to the deserialized pre value, and delete the snapshot information to execute the rollback request.

8. The transaction processing method according to claim 6, wherein The processing request includes a rollback request, and the execution of the processing request based on the snapshot information when the current value is consistent with the post value includes: When the current value is consistent with the post value, obtain the copy key corresponding to the target key in the snapshot information after executing the first dump statement; Execute a rename instruction to rename the copy key to the target key and delete the snapshot information to execute the rollback request.

9. The transaction processing method according to claim 1, characterized in that After registering the branch transaction with the transaction manager, the transaction manager locks the target key. The snapshot information includes the snapshot key associated with the target value when dumping. The generation of a snapshot dump statement for dumping the target value associated with the target key includes: Determine the snapshot key corresponding to the target key and query whether the snapshot key exists in the non-relational database; When the snapshot key does not exist in the non-relational database, generate a snapshot dump statement for dumping the target value associated with the target key using the snapshot key.

10. The transaction processing method according to claim 9, characterized in that, The transaction processing method further includes: When the snapshot key exists in the non-relational database, obtaining the snapshot information corresponding to the snapshot key from the non-relational database, and updating the snapshot information based on the operation statement; In response to the processing request, querying the updated snapshot information from the non-relational database according to the global identifier and the branch identifier, and executing the processing request based on the updated snapshot information.

11. A transaction processing device, characterized in that, It includes: A first processing module, configured to obtain the global identifier of the global transaction after the target application starts the global transaction; A second processing module, configured to obtain the operation statement submitted by the target application, extract the target key to be operated from the operation statement, register the branch transaction under the global transaction with the transaction manager based on the target key, and receive the branch identifier of the branch transaction returned by the transaction manager; A third processing module, configured to generate a snapshot dump statement for dumping the target value associated with the target key, send the operation statement and the snapshot dump statement to the non-relational database, and receive the snapshot information returned after the non-relational database executes the operation statement and the snapshot dump statement; A fourth processing module, configured to store the snapshot information in the non-relational database based on the global identifier and the branch identifier; A fifth processing module, configured to, in response to the processing request of the target application for the global transaction, query the snapshot information from the non-relational database according to the global identifier and the branch identifier, and execute the processing request based on the snapshot information.

12. An electronic device, comprising a memory and a processor, the memory storing a computer program, characterized in that, When the processor executes the computer program, it implements the transaction processing method according to any one of claims 1 to 10.

13. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the transaction processing method according to any one of claims 1 to 10.

14. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the transaction processing method according to any one of claims 1 to 10.