[go: up one dir, main page]

CN121501427A - Microservice transaction processing methods, devices, equipment and media - Google Patents

Microservice transaction processing methods, devices, equipment and media

Info

Publication number
CN121501427A
CN121501427A CN202511392465.0A CN202511392465A CN121501427A CN 121501427 A CN121501427 A CN 121501427A CN 202511392465 A CN202511392465 A CN 202511392465A CN 121501427 A CN121501427 A CN 121501427A
Authority
CN
China
Prior art keywords
transaction
distributed transaction
snapshot
distributed
service
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202511392465.0A
Other languages
Chinese (zh)
Inventor
许蒙蒙
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Tianyuan Innovation Technology Co ltd
Original Assignee
Beijing Tianyuan Innovation Technology Co ltd
Filing date
Publication date
Application filed by Beijing Tianyuan Innovation Technology Co ltd filed Critical Beijing Tianyuan Innovation Technology Co ltd
Publication of CN121501427A publication Critical patent/CN121501427A/en
Pending legal-status Critical Current

Links

Abstract

本发明涉及资源分配领域,提供一种微服务事务处理方法、装置、设备及介质,该方法包括:响应于分布式事务请求,在事务协调层缓存中生成全局事务快照;全局事务快照中包括分布式事务请求对应的分布式事务所需操作数据的数据变更内容;在接收到分布式事务中各参与服务反馈的准备就绪信号时,基于全局事务快照触发分布式事务中各参与服务并行将数据变更内容进行持久化处理。本发明通过预生成全局事务快照压缩资源锁定前置时间,有效提高吞吐量,通过并行触发持久化缩短提交阶段总耗时,降低了事务处理延迟。

This invention relates to the field of resource allocation, and provides a microservice transaction processing method, apparatus, device, and medium. The method includes: in response to a distributed transaction request, generating a global transaction snapshot in a transaction coordination layer cache; the global transaction snapshot includes data changes to the data required for the distributed transaction operation corresponding to the distributed transaction request; upon receiving a ready signal from each participating service in the distributed transaction, triggering each participating service in the distributed transaction to perform parallel persistence processing of the data changes based on the global transaction snapshot. This invention compresses the resource locking lead time by pre-generating a global transaction snapshot, effectively improving throughput; and shortens the total commit phase time by triggering persistence in parallel, reducing transaction processing latency.

Description

Micro service transaction processing method, device, equipment and medium
Technical Field
The present invention relates to the field of resource allocation, and in particular, to a method, an apparatus, a device, and a medium for micro-service transaction processing.
Background
In a micro-service architecture of service splitting, the atomicity (Atomicity, A), consistency (Consistency, C), isolation (I) and persistence (Durability, D) are realized by a distributed transaction protocol adopted at present by cross-service transactions so as to ensure data consistency, but on one hand, a synchronous blocking mechanism of a traditional protocol can cause overlong resource locking time and directly cause system throughput to be reduced, and on the other hand, the transaction processing average delay of the traditional scheme is high and is difficult to meet the severe requirement of low delay of a service due to the inherent characteristic of the protocol.
Disclosure of Invention
The invention provides a method, a device, equipment and a medium for processing micro-service transaction, which are used for solving the technical problems of throughput reduction and high delay in the micro-service transaction processing in the prior art.
The invention provides a micro-service transaction processing method, which comprises the following steps:
Generating a global transaction snapshot in a transaction coordination layer cache in response to a distributed transaction request, wherein the global transaction snapshot comprises data change contents of operation data required by the distributed transaction corresponding to the distributed transaction request;
and triggering each participation service in the distributed transaction based on the global transaction snapshot and performing persistence processing on the data change content when a readiness signal fed back by each participation service in the distributed transaction is received.
According to the micro-service transaction processing method provided by the invention, the global transaction snapshot is generated in the transaction coordination layer cache in response to the distributed transaction request, and the method comprises the following steps:
Responding to a distributed transaction request, and acquiring an operation log generated by each participation service in the distributed transaction when local operation is executed based on operation data required by the distributed transaction;
Encapsulating each operation log participating in service in the distributed transaction into a snapshot unit in a transaction coordination layer cache, and distributing a version number for each snapshot unit;
And generating a global transaction snapshot based on the snapshot unit and the version number corresponding to each participation service in the distributed transaction.
According to the method for processing the micro-service transaction provided by the invention, the operation log generated by each participation service in the distributed transaction when the local operation is executed based on the operation data required by the distributed transaction is obtained in response to the distributed transaction request, and the method comprises the following steps:
Responding to a distributed transaction request, and locking a cache line corresponding to operation data required by the distributed transaction;
And after the cache line is successfully locked, acquiring an operation log generated by each participation service in the distributed transaction when local operation is performed based on operation data required by the distributed transaction.
According to the micro-service transaction processing method provided by the invention, after the global transaction snapshot is generated in the transaction coordination layer cache in response to the distributed transaction request, the method further comprises the following steps:
And when detecting that the participation service in the distributed transaction fails or is abnormal in execution, executing a data rollback operation based on the global transaction snapshot.
According to the micro-service transaction processing method provided by the invention, the execution of the data rollback operation based on the global transaction snapshot comprises the following steps:
determining target difference data according to the global transaction snapshot, wherein the target difference data comprises at least one of difference data before and after a fault occurs and difference data before and after the fault is executed in the distributed transaction;
And executing a data rollback operation on the target difference data.
According to the micro-service transaction processing method provided by the invention, before the global transaction snapshot is generated in the transaction coordination layer cache, the method further comprises the following steps:
acquiring a historical access queue of the distributed transaction corresponding to the distributed transaction request;
based on the historical access queue, determining operation data required by the distributed transaction corresponding to the distributed transaction request by utilizing an LRU-K algorithm;
Loading operation data required by the distributed transaction corresponding to the distributed transaction request into a preprocessing layer cache, and generating a first version mark with a time stamp for the operation data required by the distributed transaction corresponding to the distributed transaction request;
comparing a second version mark corresponding to the operation data required by the distributed transaction in a database log with the first version mark in the preprocessing layer cache;
and when detecting that the version deviation of the second version mark and the first version mark exceeds a threshold value, updating data corresponding to the first version mark in the preprocessing layer cache based on the second version mark.
According to the micro-service transaction processing method provided by the invention, the method for triggering each participation service in the distributed transaction based on the global transaction snapshot and carrying out persistence processing on the data change content comprises the following steps:
In the persistent layer cache, adopting a merging write strategy to merge the change requests corresponding to the data change contents of the global transaction snapshot into batch I/O requests;
the batch I/O requests are written to a database to complete the persistence process.
The invention also provides a micro-service transaction processing device, which comprises:
the system comprises a response module, a transaction coordination layer cache, a response module and a transaction coordination layer cache, wherein the response module is used for responding to a distributed transaction request and generating a global transaction snapshot in the transaction coordination layer cache, wherein the global transaction snapshot comprises data change contents of operation data required by the distributed transaction corresponding to the distributed transaction request;
and the processing module is used for triggering each participation service in the distributed transaction based on the global transaction snapshot and carrying out persistence processing on the data change content in parallel when receiving a readiness signal fed back by each participation service in the distributed transaction.
The invention also provides an electronic device comprising a memory, a processor and a computer program stored on the memory and running on the processor, the processor implementing the micro-service transaction method as described in any of the above when executing the program.
The invention also provides a non-transitory computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements a micro-service transaction method as described in any of the above.
The invention also provides a computer program product comprising a computer program which when executed by a processor implements a micro-service transaction processing method as described in any one of the above.
The method, the device, the equipment and the medium for processing the micro-service transaction are used for responding to the distributed transaction request, generating a global transaction snapshot in a transaction coordination layer cache, wherein the global transaction snapshot comprises data change contents of operation data required by the distributed transaction corresponding to the distributed transaction request, and triggering each participation service in the distributed transaction to conduct persistence processing on the data change contents based on the global transaction snapshot when a readiness signal fed back by each participation service in the distributed transaction is received. Therefore, the invention effectively improves the throughput by pre-generating the global transaction snapshot compression resource locking lead time on one hand, and reduces the total time consumption of the submitting stage and the transaction processing delay by triggering persistence in parallel on the other hand.
Drawings
In order to more clearly illustrate the invention or the technical solutions of the prior art, the following description will briefly explain the drawings used in the embodiments or the description of the prior art, and it is obvious that the drawings in the following description are some embodiments of the invention, and other drawings can be obtained according to the drawings without inventive effort for a person skilled in the art.
Fig. 1 is a flowchart of a micro service transaction processing method according to an embodiment of the present invention.
Fig. 2 is a schematic structural diagram of a micro-service transaction processing device according to an embodiment of the present invention.
Fig. 3 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the present invention more apparent, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings, and it is apparent that the described embodiments are some embodiments of the present invention, not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
The micro service transaction processing method according to the embodiment of the present invention, as shown in fig. 1, includes a step 110 and a step 120.
And 110, responding to the distributed transaction request, and generating a global transaction snapshot in a transaction coordination layer cache, wherein the global transaction snapshot comprises data change contents of operation data required by the distributed transaction corresponding to the distributed transaction request.
Herein, a distributed transaction request refers to a transaction operation request that requires coordinated completion across multiple independent services. The request may be initiated by the client application or may be triggered by some service within the system, without limitation.
It should be appreciated that in a micro-service architecture, a business process often requires invocation of multiple services (e.g., order service, inventory service, payment service), which typically have separate databases or storage resources. A distributed transaction is formed when the operation of these services needs to meet the atomicity requirement of "either full success or full failure".
In this embodiment, when the system receives a distributed transaction request, the request is first routed to the transaction coordination layer, which assigns a globally unique transaction ID to the request and identifies all participating services needed to complete the transaction. The transaction coordination layer distributes corresponding tasks to each participating service. Each participating service locally executes its business logic and computes changes that would occur to the data it is responsible for if the transaction were successful. Each participating service reports the calculated data change content to the transaction coordination layer. The transaction coordination layer collects the data change contents reported by all the participating services, and aggregates the data change contents to form a complete global transaction snapshot, and then stores the global transaction snapshot into a self transaction coordination layer cache.
It should be noted that, the transaction coordination layer refers to a logical layer or a physical layer independent of each participating service, and the transaction coordination layer has its own cache space, i.e. the transaction coordination layer cache, for storing intermediate state data in the transaction processing process.
Global transaction snapshots refer to a collection of data generated for a particular distributed transaction in a transaction coordination layer cache. This data set is the final state of all data involved in the participating service, i.e., the data change content, when the transaction eventually commits to be successful. The data change content refers to the final state value of the target data after the distributed transaction is successfully executed. For example, if one transaction is to change the account balance of user a from 100 to 80 and the account balance of user B from 50 to 70, the data change includes "the account balance of user a is 80 and the account balance of user B is 70". It may be a new value of a certain field in the database, a complete data line to be inserted, or an identifier of a data line to be deleted, etc., which is not limited.
Step 120, when a ready signal of feedback of each participation service in the distributed transaction is received, triggering each participation service in the distributed transaction based on the global transaction snapshot and performing persistence processing on the data change content.
Here, the ready signal refers to one acknowledgement signal that each participating service feeds back to the transaction coordination layer in the distributed transaction. The ready signal indicates that the participating service has completed all local computing and resource preparation work and confirms that itself is conditioned to perform data persistence (e.g., local database connection is normal, disk space is sufficient, etc.).
In this embodiment, the transaction coordination layer acts as a coordinator and is responsible for listening and collecting readiness signals from all participating services. After the transaction coordination layer confirms that the ready signals of all the participation services related to the distributed transaction are received, the whole transaction is considered to be in a submittable state. At this point, the transaction orchestration layer broadcasts an instruction to all participating services to execute the commit. After receiving the instruction, each participating service changes the content according to the determined data, and concurrently executes the writing operation of the local database to complete the persistence processing.
It should be understood that performing persistence processing on the data change contents in parallel refers to that all participating services start writing the respective data change contents belonging to the global transaction snapshot into persistence storage (such as a relational database, a NoSQL database, etc.) at the rear end thereof independently at the same time after receiving an instruction submitted by execution of the transaction coordination layer, without waiting for each other. As such, the final commit time of the entire transaction is dependent only on the persistence time of the slowest participating service being executed, rather than the sum of all participating service persistence times.
According to the micro-service transaction processing method, on one hand, the throughput is effectively improved by pre-generating the global transaction snapshot compression resource locking lead time, and on the other hand, the total time consumption of the submitting stage is shortened by parallel triggering persistence, so that the transaction processing delay is reduced.
It should be noted that each embodiment of the present application may be freely combined, exchanged in order, or separately executed, and does not need to rely on or rely on a fixed execution sequence.
In some embodiments, before generating the global transaction snapshot in the transaction coordination layer cache, the method further includes:
acquiring a historical access queue of the distributed transaction corresponding to the distributed transaction request;
based on the historical access queue, determining operation data required by the distributed transaction corresponding to the distributed transaction request by utilizing an LRU-K algorithm;
Loading operation data required by the distributed transaction corresponding to the distributed transaction request into a preprocessing layer cache, and generating a first version mark with a time stamp for the operation data required by the distributed transaction corresponding to the distributed transaction request;
comparing a second version mark corresponding to the operation data required by the distributed transaction in a database log with the first version mark in the preprocessing layer cache;
and when detecting that the version deviation of the second version mark and the first version mark exceeds a threshold value, updating data corresponding to the first version mark in the preprocessing layer cache based on the second version mark.
In this embodiment, after responding to the distributed transaction request, a preprocessing read-write caching step performed in the preprocessing layer is further included before generating the global transaction snapshot.
Here, the history access queue refers to a record list maintained by the system for related data, in which time points at which the data is accessed in the past period of time, i.e., history access time stamps, are recorded in chronological order or by access frequency.
In this embodiment, the LRU-K algorithm is used to dynamically preload hot spot transaction operations. Here, the LRU-K algorithm refers to an algorithm modified compared to the conventional LRU (least recently used) algorithm, and K refers to the last K accesses. Specifically, according to the K records of the data which are accessed recently, the heat degree (such as the frequency and the timeliness of the accessed data) of the data is judged, the data with high heat degree is preferentially reserved, and the data with low heat degree is eliminated, so that the data which are most likely to need to be operated next by the distributed transaction are preloaded in a preprocessing layer. In this embodiment, K may be a preset integer.
In one example, if there are less than K historical access time stamps in the historical access queue of the data (e.g. only accessed 1 time), the data is considered to be cold data, and if the K historical access time stamps are accumulated, the interval between the last access time and the current time (i.e. the duration of the non-accessed time) is calculated, and the shorter the interval is, the higher the data heat is.
Here, the preprocessing layer refers to a first level cache layer located in the transaction coordinator, which is a cache area for read-write optimization. In this embodiment, before the global transaction snapshot is generated in the transaction coordination layer cache, it is checked whether the data determined based on the LRU-K algorithm is already in the preprocessing layer cache. If not, it is preloaded from persistent storage such as a backend database.
When data is loaded or updated into the preprocessing layer cache, the system attaches a first version stamp to it, which is used to reflect the current version stamp of the data. The second version stamp corresponding to the operational data required for the distributed transaction in the database log is then compared to the first version stamp in the current pre-processing layer cache. Here, the second version stamp refers to a version stamp obtained from a transaction log of the database for reflecting the latest state of data in the persistent storage.
In this embodiment, a threshold is preset to measure whether to trigger a local refresh operation of data in the preprocessing layer cache. Here, the partial refresh operation refers to an operation of reloading only for inconsistent data when it is detected that there may be an inconsistency between the data in the preprocessing layer cache and the database (i.e., the data is stale), without emptying the data cached in the entire preprocessing layer.
Specifically, when the version deviation between the second version mark and the first version mark exceeds a threshold (for example, the second version mark is V5, the first version mark is V2, and the threshold is 2), the data corresponding to the first version mark of the current preprocessing layer cache is updated to the data corresponding to the second version mark in the database, so as to ensure data consistency.
According to the micro-service transaction processing method, before the transaction formally starts to be executed, related data is preloaded into the cache through the LRU-K algorithm, and delay caused by accessing the database during the execution of the transaction is reduced. Meanwhile, the accuracy of data operation is ensured through version mark comparison and a local refreshing mechanism.
In some embodiments, the generating a global transaction snapshot in the transaction coordination layer cache in response to the distributed transaction request includes:
Responding to a distributed transaction request, and acquiring an operation log generated by each participation service in the distributed transaction when local operation is executed based on operation data required by the distributed transaction;
Encapsulating each operation log participating in service in the distributed transaction into a snapshot unit in a transaction coordination layer cache, and distributing a version number for each snapshot unit;
And generating a global transaction snapshot based on the snapshot unit and the version number corresponding to each participation service in the distributed transaction.
Here, the operation log refers to a detailed record describing how data is changed when each participating service performs a local operation according to operation data required for a distributed transaction, including, but not limited to, operation type (add, delete, change), data identification, structured data of a value before data change and data change.
In this embodiment, the transaction coordination layer respectively performs structured encapsulation on each received original operation log of the participating service to form an independent, identifiable and reusable snapshot unit. Further, each snapshot unit is assigned an independent version number that is unique within the current transaction. This version number may be used to track the order of operations within a transaction and provide a basis for rollback operations that may occur subsequently.
Finally, the transaction coordination layer aggregates all snapshot units belonging to the same global transaction ID to form a list or a tree structure, namely, a global transaction snapshot. The global transaction snapshot completely records all data changes that the distributed transaction needs to execute.
According to the micro-service transaction processing method, the local operation logs of each participating service are obtained and packaged into the snapshot unit with the version number, and finally the global transaction snapshot is generated, so that unified recording, versioning management and control and global traceability of distributed transaction operation data are realized.
In some embodiments, the obtaining, in response to a distributed transaction request, an operation log generated by each participating service in the distributed transaction when performing a local operation based on operation data required by the distributed transaction includes:
Responding to a distributed transaction request, and locking a cache line corresponding to operation data required by the distributed transaction;
And after the cache line is successfully locked, acquiring an operation log generated by each participation service in the distributed transaction when local operation is performed based on operation data required by the distributed transaction.
In this embodiment, when the transaction coordination layer processes a distributed transaction, firstly, based on a unique identifier of operation data required by the transaction, a specific physical storage unit (such as a storage block divided according to data slices) corresponding to the data in a cache of the transaction coordination layer is located through a preset mapping rule (such as hash calculation and index matching), where a minimum unit capable of being independently locked in the physical storage unit is defined as a cache line. And then locking the cache line.
Here, the locking operation may be performed using a distributed locking mechanism. Specifically, a unique lock identifier (such as a cache line id+transaction ID) is generated for each located cache line, and accurate locking of the target cache line is achieved by preempting the lock identifier.
Based on the above, the embodiment refines the table-level lock depending on the database in the traditional distributed transaction into the cache line-level lock cached by the transaction coordination layer, and only locks the minimum data unit actually required to be operated by the transaction, thereby avoiding the lock occupation of irrelevant data and reducing unnecessary lock competition.
After the cache line is successfully locked, local business calculation starts to be executed, and a corresponding operation log is generated. In addition, after execution is complete, the lock may continue to hold until the entire distributed transaction commits or rollbacks is completed before releasing, thereby ensuring data isolation throughout the process from preparation to commit.
According to the micro-service transaction processing method, the conflict problem in a high concurrency scene is effectively solved by locking the resources in a fine granularity mode in the early stage of transaction preparation. The method ensures that the data on which the snapshot is dependent cannot be interfered or modified by other concurrent transactions during the generation of the snapshot of the total transaction, thereby ensuring the accuracy and consistency of snapshot content.
In some embodiments, after generating the global transaction snapshot in the transaction coordination layer cache in response to the distributed transaction request, the method further comprises:
And when detecting that the participation service in the distributed transaction fails or is abnormal in execution, executing a data rollback operation based on the global transaction snapshot.
In this embodiment, the transaction coordination layer monitors the status of each participating service, and the detection mechanism includes, but is not limited to:
Timeout detection, which is to determine that a certain participating service fails if a response is not received within a preset time (e.g., timeout time of waiting for a ready signal);
abnormal feedback, namely actively feeding back a signal for executing the abnormality to a transaction coordination layer when the participating service encounters errors (such as database connection failure, business rule verification failure and the like) during executing local operation;
And (3) heartbeat or health check, wherein the transaction coordination layer judges whether the transaction coordination layer fails or performs abnormal execution through a heartbeat mechanism between the transaction coordination layer and the participated service.
Once any participation service is detected to be faulty or abnormal in execution, the transaction coordination layer can suspend the submitting flow of the whole distributed transaction, and then the global transaction snapshot is used as the unified basis for rollback to restore the operation data of all participation services to the state before the execution of the transaction, so that the atomicity of the distributed transaction is ensured, and the inconsistency of the data is avoided.
According to the micro-service transaction processing method, rollback is guided through the global transaction snapshot, so that all participating services can uniformly and coordinately cancel pre-operations which are executed, and data is restored to a state before the transaction starts, and the problem of inconsistent data caused by partial node failure is effectively prevented.
In some embodiments, the performing a data rollback operation based on the global transaction snapshot includes:
determining target difference data according to the global transaction snapshot, wherein the target difference data comprises at least one of difference data before and after a fault occurs and difference data before and after the fault is executed in the distributed transaction;
And executing a data rollback operation on the target difference data.
The target difference data refers to difference data before and after a fault or difference data before and after an abnormality is executed, which is determined according to data recorded in a global transaction snapshot as a reference in the execution process of the distributed transaction.
For example, the participating services have partially performed local operations but not completed when a failure (e.g., downtime, network disruption) occurs, resulting in differential data with data in a semi-modified state. Or the difference data formed by the modification of partial data which is caused by operation failure due to abnormality (such as insufficient stock and data format error) when the participating service executes the operation.
In this embodiment, after determining the target difference data, the target difference data is continuously restored to the initial state before the execution of the transaction according to the global transaction snapshot.
According to the micro-service transaction processing method, incremental rollback is realized through the global transaction snapshot, and the efficiency of data rollback is improved.
In some embodiments, the triggering each participating service in the distributed transaction based on the global transaction snapshot and performing persistence processing on the data change content includes:
In the persistent layer cache, adopting a merging write strategy to merge the change requests corresponding to the data change contents of the global transaction snapshot into batch I/O requests;
the batch I/O requests are written to a database to complete the persistence process.
In this embodiment, in the persistent layer cache, a merge write strategy is used to merge multiple data change contents belonging to different distributed transactions in the global transaction snapshot into a batch I/O request.
Here, the persistent layer cache refers to a third level cache in the transaction coordinator, which is located in a buffer area between the transaction coordinator layer and the database, and is used for temporarily storing the data change content of the database to be written, so that the transaction coordinator layer is prevented from directly and frequently calling the database interface.
In this embodiment, when parallel persistence is triggered, the transaction coordination layer does not enable each participating service to directly write data into the database, but gathers the data change contents of all services into the persistence layer cache, and then integrates the data change contents into batch I/O requests through a merging write strategy.
Specifically, the transaction coordination layer extracts the data change contents of all participating services from the global transaction snapshot, and uniformly writes the scattered data change contents into the persistent layer cache.
The persistent layer cache establishes a merging rule according to the database type and the operation type, and integrates the change request of scattered data change content into a batch I/O request, wherein the merging rule comprises, but is not limited to:
the same type SQL merging, namely merging a plurality of change requests into a batch SQL (structured query language) statement if the change requests are of the same table and same operation type;
and (3) transaction batch submission, namely if the change request relates to multi-table or multi-operation types, packaging the SQL into a database batch transaction, completing all operations through one transaction submission, and reducing the creation and submission times of the database transaction.
After the batch I/O requests are generated by the persistent layer cache, the batch I/O requests are sent to the database once, and final data persistence is completed.
According to the micro-service transaction processing method, the changing requests corresponding to the data changing content of the global transaction snapshot are combined into the batch I/O requests through the combination write-in strategy, and the disk access frequency is reduced.
The micro service transaction processing device provided by the invention is described below, and the micro service transaction processing device described below and the micro service transaction processing method described above can be referred to correspondingly.
The micro service transaction processing device according to the embodiment of the present invention, as shown in fig. 2, includes the following modules:
A response module 210, configured to respond to a distributed transaction request, and generate a global transaction snapshot in a transaction coordination layer cache, where the global transaction snapshot includes data change contents of operation data required by a distributed transaction corresponding to the distributed transaction request;
and the processing module 220 is configured to trigger each participating service in the distributed transaction based on the global transaction snapshot and perform persistence processing on the data change content in parallel when a readiness signal fed back by each participating service in the distributed transaction is received.
The micro-service transaction processing device responds to the distributed transaction request, generates a global transaction snapshot in a transaction coordination layer cache, wherein the global transaction snapshot comprises data change contents of operation data required by the distributed transaction corresponding to the distributed transaction request, and triggers each participation service in the distributed transaction to conduct persistence processing based on the global transaction snapshot when a readiness signal fed back by each participation service in the distributed transaction is received. Therefore, the invention effectively improves the throughput by pre-generating the global transaction snapshot compression resource locking lead time on one hand, and reduces the total time consumption of the submitting stage and the transaction processing delay by triggering persistence in parallel on the other hand.
Fig. 3 illustrates a physical schematic diagram of an electronic device, which may include a processor 310, a communication interface (Communications Interface), a memory 330, and a communication bus 340, as shown in fig. 3, where the processor 310, the communication interface 320, and the memory 330 communicate with each other via the communication bus 340. Processor 310 may invoke logic instructions in memory 330 to perform a micro-service transaction method comprising:
Generating a global transaction snapshot in a transaction coordination layer cache in response to a distributed transaction request, wherein the global transaction snapshot comprises data change contents of operation data required by the distributed transaction corresponding to the distributed transaction request;
and triggering each participation service in the distributed transaction based on the global transaction snapshot and performing persistence processing on the data change content when a readiness signal fed back by each participation service in the distributed transaction is received.
Further, the logic instructions in the memory 330 described above may be implemented in the form of software functional units and may be stored in a computer-readable storage medium when sold or used as a stand-alone product. Based on this understanding, the technical solution of the present invention may be embodied essentially or in a part contributing to the prior art or in a part of the technical solution, in the form of a software product stored in a storage medium, comprising several instructions for causing a computer device (which may be a personal computer, a server, a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The storage medium includes a U disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), a magnetic disk, or an optical disk, each of which can store a program code.
In another aspect, the present invention also provides a computer program product comprising a computer program storable on a non-transitory computer readable storage medium, the computer program, when executed by a processor, being capable of performing a method of microservice transaction provided by each of the methods described above, the method comprising:
Generating a global transaction snapshot in a transaction coordination layer cache in response to a distributed transaction request, wherein the global transaction snapshot comprises data change contents of operation data required by the distributed transaction corresponding to the distributed transaction request;
and triggering each participation service in the distributed transaction based on the global transaction snapshot and performing persistence processing on the data change content when a readiness signal fed back by each participation service in the distributed transaction is received.
In yet another aspect, the present invention also provides a non-transitory computer readable storage medium having stored thereon a computer program which, when executed by a processor, is implemented to perform a method of micro-service transaction provided by each of the methods described above, the method comprising:
Generating a global transaction snapshot in a transaction coordination layer cache in response to a distributed transaction request, wherein the global transaction snapshot comprises data change contents of operation data required by the distributed transaction corresponding to the distributed transaction request;
and triggering each participation service in the distributed transaction based on the global transaction snapshot and performing persistence processing on the data change content when a readiness signal fed back by each participation service in the distributed transaction is received.
The apparatus embodiments described above are merely illustrative, wherein the elements illustrated as separate elements may or may not be physically separate, and the elements shown as elements may or may not be physical elements, may be located in one place, or may be distributed over a plurality of network elements. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art will understand and implement the present invention without undue burden.
From the above description of embodiments, it will be apparent to those skilled in the art that each embodiment may be implemented by means of software plus necessary general purpose hardware platform, or may be implemented by hardware. Based on this understanding, the foregoing technical solution may be embodied essentially or in a part contributing to the prior art in the form of a software product, which may be stored in a computer readable storage medium, such as ROM/RAM, a magnetic disk, an optical disk, etc., including several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the method described in each embodiment or some parts of the embodiment.
It should be noted that the above-mentioned embodiments are merely for illustrating the technical solution of the present invention, and not for limiting the same, and although the present invention has been described in detail with reference to the above-mentioned embodiments, it should be understood by those skilled in the art that the technical solution described in each of the above-mentioned embodiments may be modified or some of the technical features may be equivalently replaced, and these modifications or substitutions do not make the essence of the corresponding technical solution deviate from the spirit and scope of the technical solution of each of the embodiments of the present invention.

Claims (10)

1. A method of micro-service transaction processing, comprising:
Generating a global transaction snapshot in a transaction coordination layer cache in response to a distributed transaction request, wherein the global transaction snapshot comprises data change contents of operation data required by the distributed transaction corresponding to the distributed transaction request;
and triggering each participation service in the distributed transaction based on the global transaction snapshot and performing persistence processing on the data change content when a readiness signal fed back by each participation service in the distributed transaction is received.
2. The method of microservice transaction processing of claim 1 wherein generating a global transaction snapshot in a transaction coordination layer cache in response to a distributed transaction request comprises:
Responding to a distributed transaction request, and acquiring an operation log generated by each participation service in the distributed transaction when local operation is executed based on operation data required by the distributed transaction;
Encapsulating each operation log participating in service in the distributed transaction into a snapshot unit in a transaction coordination layer cache, and distributing a version number for each snapshot unit;
And generating a global transaction snapshot based on the snapshot unit and the version number corresponding to each participation service in the distributed transaction.
3. The method according to claim 2, wherein the obtaining, in response to a distributed transaction request, an operation log generated by each participating service in the distributed transaction when performing a local operation based on operation data required by the distributed transaction, includes:
Responding to a distributed transaction request, and locking a cache line corresponding to operation data required by the distributed transaction;
And after the cache line is successfully locked, acquiring an operation log generated by each participation service in the distributed transaction when local operation is performed based on operation data required by the distributed transaction.
4. The method of micro-service transaction processing according to claim 1 or 2, wherein after generating a global transaction snapshot in a transaction coordination layer cache in response to a distributed transaction request, further comprising:
And when detecting that the participation service in the distributed transaction fails or is abnormal in execution, executing a data rollback operation based on the global transaction snapshot.
5. The method of microservice transaction processing of claim 4 wherein the performing a data rollback operation based on the global transaction snapshot comprises:
determining target difference data according to the global transaction snapshot, wherein the target difference data comprises at least one of difference data before and after a fault occurs and difference data before and after the fault is executed in the distributed transaction;
And executing a data rollback operation on the target difference data.
6. The method of microservice transaction processing of claim 1 wherein prior to generating the global transaction snapshot in the transaction coordination layer cache, further comprising:
acquiring a historical access queue of the distributed transaction corresponding to the distributed transaction request
Based on the historical access queue, determining operation data required by the distributed transaction corresponding to the distributed transaction request by utilizing an LRU-K algorithm;
Loading operation data required by the distributed transaction corresponding to the distributed transaction request into a preprocessing layer cache, and generating a first version mark with a time stamp for the operation data required by the distributed transaction corresponding to the distributed transaction request;
comparing a second version mark corresponding to the operation data required by the distributed transaction in a database log with the first version mark in the preprocessing layer cache;
and when detecting that the version deviation of the second version mark and the first version mark exceeds a threshold value, updating data corresponding to the first version mark in the preprocessing layer cache based on the second version mark.
7. The method of micro-service transaction processing according to claim 1, wherein triggering each participating service in the distributed transaction based on the global transaction snapshot and performing persistence processing on the data change content comprises:
In the persistent layer cache, adopting a merging write strategy to merge the change requests corresponding to the data change contents of the global transaction snapshot into batch I/O requests;
the batch I/O requests are written to a database to complete the persistence process.
8. A micro-service transaction processing apparatus, comprising:
the system comprises a response module, a transaction coordination layer cache, a response module and a transaction coordination layer cache, wherein the response module is used for responding to a distributed transaction request and generating a global transaction snapshot in the transaction coordination layer cache, wherein the global transaction snapshot comprises data change contents of operation data required by the distributed transaction corresponding to the distributed transaction request;
and the processing module is used for triggering each participation service in the distributed transaction based on the global transaction snapshot and carrying out persistence processing on the data change content in parallel when receiving a readiness signal fed back by each participation service in the distributed transaction.
9. An electronic device comprising a memory, a processor and a computer program stored on the memory and running on the processor, characterized in that the processor implements the micro-service transaction method according to any of claims 1 to 7 when executing the computer program.
10. A non-transitory computer readable storage medium, having stored thereon a computer program, which when executed by a processor implements the micro-service transaction method of any of claims 1 to 7.
CN202511392465.0A 2025-09-26 Microservice transaction processing methods, devices, equipment and media Pending CN121501427A (en)

Publications (1)

Publication Number Publication Date
CN121501427A true CN121501427A (en) 2026-02-10

Family

ID=

Similar Documents

Publication Publication Date Title
US8209699B2 (en) System and method for subunit operations in a database
JP7549137B2 (en) Transaction processing method, system, device, equipment, and program
US10942823B2 (en) Transaction processing system, recovery subsystem and method for operating a recovery subsystem
US8209696B2 (en) Method and system for load balancing a distributed database
US8645319B2 (en) Information processing system, data update method and data update program
EP2997490B1 (en) Transaction ordering
EP2378420A1 (en) Ownership reassignment in a shared-nothing database system
CN111259083A (en) Distributed transaction processing method and device
CN113961315B (en) Transaction processing method, device, equipment and storage medium
CN113010549B (en) Data processing method based on remote multi-activity system, related equipment and storage medium
US9922086B1 (en) Consistent query of local indexes
CN112765126A (en) Database transaction management method and device, computer equipment and storage medium
US11914571B1 (en) Optimistic concurrency for a multi-writer database
CN110659303A (en) Read-write control method and device for database nodes
US7146385B1 (en) System and method for application-transparent synchronization with a persistent data store
CN113872781B (en) Transaction processing method, device, equipment and storage medium
CN121501427A (en) Microservice transaction processing methods, devices, equipment and media
US12265839B2 (en) Management method and apparatus for transaction processing system, device, and medium
CN119013659A (en) Transaction processing method, device, node and computer readable storage medium
CN116910064B (en) Method and system for on-line creation of table index in distributed system
US12455884B2 (en) Execution tracing for node cluster
US11579785B2 (en) Systems and methods of providing fault-tolerant file access
HK40065219B (en) Transaction processing method and device, equipment and storage medium
HK40065219A (en) Transaction processing method and device, equipment and storage medium
HK40037752A (en) Transaction processing method, device and computer readable storage medium

Legal Events

Date Code Title Description
PB01 Publication