CN112328406B - Micro-service distributed transaction system based on TCC (TCC) and service processing method - Google Patents
Micro-service distributed transaction system based on TCC (TCC) and service processing method Download PDFInfo
- Publication number
- CN112328406B CN112328406B CN202011081677.4A CN202011081677A CN112328406B CN 112328406 B CN112328406 B CN 112328406B CN 202011081677 A CN202011081677 A CN 202011081677A CN 112328406 B CN112328406 B CN 112328406B
- Authority
- CN
- China
- Prior art keywords
- service
- business
- transaction
- compensation
- unified
- 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.)
- Active
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/54—Interprogram communication
- G06F9/547—Remote procedure calls [RPC]; Web services
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/54—Interprogram communication
- G06F9/544—Buffers; Shared memory; Pipes
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Hardware Redundancy (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The invention discloses a micro-service distributed transaction system based on TCC and a service processing method, wherein for each service request, a unified transaction context object is created and placed in a cache, and a plurality of subsequent service calls generated based on the service request correspondingly update the unified transaction context object, especially the transaction call chain reflects the service call sequence, when any service node is abnormal, the invention can determine the previous service call sequence based on the transaction call chain and call the compensation service of each service in turn according to the reverse sequence, thus ensuring the consistency of data.
Description
Technical Field
The invention relates to the field of distributed transactions, in particular to a micro-service distributed transaction system based on TCC and a service processing method.
Background
Distributed transaction is a technical difficulty in enterprise integration, and is a problem related to each distributed system architecture, the current solution to distributed transaction is mainly discussed in the engineering field as a solution of strong consistency and final consistency, and typical solutions mainly comprise a two-stage submission (2 PC) solution, a local message table solution, an open source TCC compensation mode and final consistency of cached data. The existing technical scheme is complex in use, most of XA technology depending on databases is realized, the coupled databases are too strong, and the flexibility is relatively single.
Disclosure of Invention
The technical problem to be solved by the invention is to provide a simple and highly flexible micro-service distributed transaction system based on TCC and a service processing method aiming at the defects in the prior art.
The technical scheme adopted for solving the technical problems is as follows:
a business processing method for constructing TCC-based micro-service distributed transactions, implemented with a TCC-based micro-service distributed transaction system, the system comprising a distributed arrangement of main business services and business services, the main business services and the business services distributing a transaction compensation framework, the method comprising:
when a business interceptor of a business compensation framework of the main business service intercepts a business request, a unified business context object corresponding to the business request is created and placed in a cache, wherein the unified business context object comprises a business call chain and marks the main business service as a root service;
when the main business service calls the local business service, a business interceptor of the local business compensation framework intercepts a request for calling the business, adds the called information of the business interceptor in a business call chain and marks the business call chain as a local call type, and if the called business has the preprocessing service, the business service is called after the preprocessing service is called;
when the main business service calls the remote business service, a request for calling the business is sent to a remote filter of a local business compensation frame, the remote filter transmits the business request and a unified business context object to a service filter of the business compensation frame of the slave business service, the service filter marks a remote call node type in the unified business context object, then transmits the business request and the unified business context object to a business interceptor of the local business compensation frame, the business interceptor adds the called information in a business call chain, and if the called business has a preprocessing service, the business service is called after the called business service is called;
when the transaction compensation framework of the main service captures an abnormality, a unified transaction context object is obtained from a cache, a service calling sequence is determined according to a transaction calling chain in the unified transaction context object, and the compensation service of each service is sequentially called according to the reverse sequence.
Further, the method further comprises:
when receiving the message of finishing the business request of the main business service, the business compensation framework of the main business service logs off the unified business context object corresponding to the business request.
Further, the preprocessing service includes: the unified transaction context object and the realization method of the business for compensation are recorded.
Further, the preprocessing service and the compensation service of each service are realized by providing interface service agreed with the transaction compensation framework, and the interface parameters comprise parameters of unified transaction upper and lower objects for providing the transaction compensation framework for caching related service information.
Further, the method further comprises:
the transaction compensation framework of the main service also records compensation logs when the compensation service of each service is invoked.
Further, the configuration file of the main business service contains an editable business compensation mark representing whether the business compensation framework is enabled or not.
In another aspect, the invention also constructs a TCC-based micro-service distributed transaction system for implementing the method, the system comprising a main service and a service, both of which arrange a transaction compensation framework comprising a service interceptor and a remote filter, the transaction compensation framework of the main service comprising a service filter and a service interceptor.
The micro-service distributed transaction system and the service processing method based on the TCC have the following beneficial effects: the invention establishes and unifies business context objects for each business request, places the business request in a cache, and then generates a plurality of columns of service calls based on the business request, correspondingly updates the unified business context objects, particularly, the business call chain reflects the service call sequence, when any service node is abnormal, the invention can determine the previous service call sequence based on the business call chain and sequentially call the compensation service of each business according to the reverse sequence, thus ensuring the consistency of data.
Drawings
For a clearer description of an embodiment of the invention or of a technical solution in the prior art, the drawings that are needed in the description of the embodiment or of the prior art will be briefly described, it being obvious that the drawings in the description below are only embodiments of the invention, and that other drawings can be obtained, without inventive effort, by a person skilled in the art from the drawings provided:
FIG. 1 is a schematic diagram of a business processing method of the TCC-based micro-service distributed transaction of the present invention;
FIG. 2 is a schematic diagram illustrating the sequence of service invocation initiated by a main service in a specific application scenario of the present invention;
fig. 3 is a schematic diagram of an implementation sequence of the compensation service in a specific application scenario of the present invention.
Detailed Description
In order that the invention may be readily understood, a more complete description of the invention will be rendered by reference to the appended drawings. Exemplary embodiments of the present invention are illustrated in the accompanying drawings. This invention may, however, be embodied in many different forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete.
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs. The terminology used herein in the description of the invention is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention.
The general idea of the invention is to introduce the concept of TCC into micro-service distributed transactions, but the invention is not directly adopted in the current TCC compensation mode, and data locking, rollback and the like are not performed. When the business interceptor of the business compensation framework of the main business service intercepts the business request, a unified business context object corresponding to the business request is created and placed in a cache, the unified business context object comprises a business call chain corresponding to the business request, each business request corresponds to one unified business context object, in the process of processing the business request, the business interceptor of the business compensation framework can add the called information in the business call chain when each business is called, when any link is abnormal, the business interceptor of the business compensation framework can be captured by the business compensation framework of the main business service, when the business compensation framework captures the abnormality, the unified business context object is obtained from the cache, the business call sequence is determined according to the business call chain, and the compensation services of all businesses are sequentially called according to the reverse sequence, so that the consistency of data can be ensured. The method has the advantages of simple scheme and flexible service expansion.
In order to better understand the above technical solutions, the following detailed description will be made with reference to the accompanying drawings and specific embodiments, and it should be understood that specific features in the embodiments and examples of the present invention are detailed descriptions of the technical solutions of the present application, and not limit the technical solutions of the present application, and the technical features in the embodiments and examples of the present invention may be combined with each other without conflict.
The service processing method of the micro-service distributed transaction based on the TCC is realized by utilizing the micro-service distributed transaction system based on the TCC. Referring to fig. 1, the system includes a distributed arrangement of a main service and a business service, both of which arrange a transaction compensation framework. The transaction compensation framework of the main service comprises a service interceptor and a remote filter, and the transaction compensation framework of the service comprises a service filter and a service interceptor.
The method of the invention comprises the following steps:
s101: when a business interceptor of a business compensation framework of the main business service intercepts a business request, a unified business context object corresponding to the business request is created and placed in a cache;
referring to fig. 1, after a client sends a service request, rather than directly starting a specific service operation of a main service, the request is firstly entered into a service interceptor to create a unified transaction context object corresponding to the service request, where the unified transaction context object includes a transaction call chain corresponding to the service request and marks the main service as a root service, and the transaction call chain is used to record a call sequence of each service. Each service invocation of the request is then recorded in the unified transaction context object for subsequent implementation of the compensation service, which may be required in reverse order. Various services of the server can be published and registered in an annotation-based mode, and the client can make service calls and can make calls in the annotation-based mode.
It should be noted that the configuration file of the main service contains an editable transaction compensation flag representing whether the transaction compensation framework is enabled or not. The user can control whether the functionality of the transaction compensation framework is enabled by editing the transaction compensation flags of the configuration file. For example, the transaction compensation flag is set to ON, which indicates that the transaction compensation framework is enabled, and the transaction compensation flag of the configuration file may be set to OFF, assuming that the business codes are integrated together, the services are no longer distributed, and there is no data consistency problem with the distributed services before.
S102: when the main business service calls the local business service, a business interceptor of the local business compensation framework intercepts a request for calling the business, adds the called information of the business interceptor in a business call chain and marks the business call chain as a local call type, and if the called business has the preprocessing service, the business service is called after the preprocessing service is called;
the preprocessing service of each service is realized by providing an interface service agreed with a transaction compensation framework, and interface parameters comprise parameters of unified transaction upper and lower objects for providing the transaction compensation framework and are used for caching related service information.
Wherein the preprocessing service includes: the unified transaction context object and the realization method of the service for compensation are recorded, namely preprocessing is to process things which can be used for realizing the compensation of the service in advance. For example, assuming that the point service is invoked and 3 points need to be deducted, the preprocessing is to deduct 3 points from the record, and then 3 points are added in the subsequent compensation.
The specific content of the preprocessing service is customized by a service developer, and the service developer only needs to provide an interface agreed with the transaction compensation framework. The service does not need to be concerned about a mechanism for triggering the preprocessing service, and only needs to be concerned about the core service logic processing of the service.
S103: when the main business service calls the remote business service, the request for calling the business is sent to the remote filter of the local business compensation framework, the remote filter transmits the business request and the unified business context object to the service filter of the business compensation framework of the slave business service, the service filter marks the remote call node type in the unified business context object, then transmits the business request and the unified business context object to the business interceptor of the local business compensation framework, the business interceptor adds the called information in the business call chain, and if the called business has the preprocessing service, the business service is called.
S104: when the transaction compensation framework of the main service captures an abnormality, a unified transaction context object is obtained from a cache, a service calling sequence is determined according to a transaction calling chain in the unified transaction context object, and the compensation service of each service is sequentially called according to the reverse sequence.
Obviously, the compensation service is actually the reverse operation of the present business operation. Like the preprocessing service, the compensation service is also realized by providing an interface service agreed with the transaction compensation framework, and the interface parameters comprise parameters of unified transaction context objects for providing the transaction compensation framework for caching related service information. The specific content of the compensation service is customized by a service developer, the service developer only needs to provide an interface appointed by the transaction compensation framework, and the service does not need to care about a mechanism triggered by the compensation service.
It will be appreciated that the compensation service, when implemented, is implemented based on information provided by the preprocessing service. The interface agreed by the preprocessing service and the supplementary service with the transaction compensation framework comprises parameters of the unified transaction upper and lower objects for providing the transaction compensation framework, so that the specific unified transaction upper and lower objects can be determined when the compensation service is called, and then the unified transaction upper and lower objects of the preprocessing service record and the corresponding compensation implementation method are found to realize compensation.
Preferably, the method further comprises: the transaction compensation framework of the main service also records compensation logs when the compensation service of each service is invoked.
S105: when receiving the message of finishing the business request of the main business service, the business compensation framework of the main business service logs off the unified business context object corresponding to the business request.
It is understood that the service request processing referred to herein includes both normal processing and compensation processing.
The method and system of the present invention are described below in a specific application scenario.
Referring to fig. 2, taking an e-commerce scenario as an example, the order service is a main service, and the service includes the following three remote services: inventory, integration and storage. The caching is realized by using a zookeeper, as shown by zk in the figure, and the sequence numbers (1) - (7) in the figure indicate the processing sequence when the order service is normally called. If the normal call ends, the compensation service is not started. If the transaction compensation framework of the main business service captures an exception, the compensation service is invoked in the order of sequence numbers (1) - (3) of fig. 3.
In summary, the TCC-based micro-service distributed transaction system and the service processing method of the present invention have the following advantages: the invention establishes and unifies business context objects for each business request, places the business request in a cache, and then generates a plurality of columns of service calls based on the business request, correspondingly updates the unified business context objects, particularly, the business call chain reflects the service call sequence, when any service node is abnormal, the invention can determine the previous service call sequence based on the business call chain and sequentially call the compensation service of each business according to the reverse sequence, thus ensuring the consistency of data.
The embodiments of the present invention have been described above with reference to the accompanying drawings, but the present invention is not limited to the above-described embodiments, which are merely illustrative and not restrictive, and many forms may be made by those having ordinary skill in the art without departing from the spirit of the present invention and the scope of the claims, which are to be protected by the present invention.
Claims (7)
1. A traffic processing method of a TCC-based micro-service distributed transaction implemented using a TCC-based micro-service distributed transaction system, the system comprising a main traffic service and a service distributed in a distributed arrangement, the main traffic service and the service distributing a transaction compensation framework, the method comprising:
when a business interceptor of a business compensation framework of the main business service intercepts a business request, a unified business context object corresponding to the business request is created and placed in a cache, wherein the unified business context object comprises a business call chain and marks the main business service as a root service;
when the main business service calls the local business service, a business interceptor of the local business compensation framework intercepts a request for calling the business, adds the called information of the business interceptor in a business call chain and marks the business call chain as a local call type, and if the called business has the preprocessing service, the business service is called after the preprocessing service is called;
when the main business service calls the remote business service, a request for calling the business is sent to a remote filter of a local business compensation frame, the remote filter transmits the business request and a unified business context object to a service filter of the business compensation frame of the slave business service, the service filter marks a remote call node type in the unified business context object, then transmits the business request and the unified business context object to a business interceptor of the local business compensation frame, the business interceptor adds the called information in a business call chain, and if the called business has a preprocessing service, the business service is called after the called business service is called;
when the transaction compensation framework of the main service captures an abnormality, a unified transaction context object is obtained from a cache, a service calling sequence is determined according to a transaction calling chain in the unified transaction context object, and the compensation service of each service is sequentially called according to the reverse sequence.
2. The method according to claim 1, wherein the method further comprises:
when receiving the message of finishing the business request of the main business service, the business compensation framework of the main business service logs off the unified business context object corresponding to the business request.
3. The method of claim 1, wherein the preprocessing service comprises: the unified transaction context object and the realization method of the business for compensation are recorded.
4. The method of claim 1, wherein the preprocessing service and the compensation service for each service are implemented by providing interface services agreed with a transaction compensation framework, and the interface parameters include parameters of unified transaction context objects providing the transaction compensation framework for caching related service information.
5. The method according to claim 1, wherein the method further comprises:
the transaction compensation framework of the main service also records compensation logs when the compensation service of each service is invoked.
6. The method of claim 1, wherein the configuration file of the main service includes an editable transaction compensation flag representing whether the transaction compensation framework is enabled.
7. A TCC-based micro-service distributed transaction system for implementing the method according to any of claims 1-6, characterized in that the system comprises a main service and a service, both of which arrange a transaction compensation framework comprising a service interceptor and a remote filter, the transaction compensation framework of the service comprising a service filter and a service interceptor.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202011081677.4A CN112328406B (en) | 2020-10-10 | 2020-10-10 | Micro-service distributed transaction system based on TCC (TCC) and service processing method |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202011081677.4A CN112328406B (en) | 2020-10-10 | 2020-10-10 | Micro-service distributed transaction system based on TCC (TCC) and service processing method |
Publications (2)
Publication Number | Publication Date |
---|---|
CN112328406A CN112328406A (en) | 2021-02-05 |
CN112328406B true CN112328406B (en) | 2023-05-09 |
Family
ID=74314717
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202011081677.4A Active CN112328406B (en) | 2020-10-10 | 2020-10-10 | Micro-service distributed transaction system based on TCC (TCC) and service processing method |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN112328406B (en) |
Families Citing this family (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113051043A (en) * | 2021-03-10 | 2021-06-29 | 北京沃东天骏信息技术有限公司 | Micro-service anomaly compensation method and device |
CN117149798B (en) * | 2023-11-01 | 2024-02-02 | 建信金融科技有限责任公司 | Service change processing method, device, equipment, medium and program product |
Family Cites Families (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6918053B1 (en) * | 2000-04-28 | 2005-07-12 | Microsoft Corporation | Compensation framework for long running transactions |
CN109992465B (en) * | 2017-12-29 | 2023-05-16 | 中国电信股份有限公司 | Service tracking method, device and computer readable storage medium |
CN108304271B (en) * | 2018-01-16 | 2021-08-06 | 深圳市康拓普信息技术有限公司 | Distributed transaction manager and management method under micro-service architecture |
-
2020
- 2020-10-10 CN CN202011081677.4A patent/CN112328406B/en active Active
Non-Patent Citations (1)
Title |
---|
Nan Cheng等.A web service process transaction framework based on compensation and proxy.《2009 Joint Conferences on Pervasive Computing (JCPC)》.2010,第369-372页. * |
Also Published As
Publication number | Publication date |
---|---|
CN112328406A (en) | 2021-02-05 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
FI106752B (en) | A system for changing software while using your computer | |
EP2130128B1 (en) | Techniques to cross-synchronize data | |
EP1620808B1 (en) | Accessing data based on user identity | |
CN103425462B (en) | A kind of method and apparatus of workflow data persistence | |
CN112328406B (en) | Micro-service distributed transaction system based on TCC (TCC) and service processing method | |
US7844912B2 (en) | System and method using transformation nodes with enhancement layers | |
KR20140047580A (en) | Method and system for synchronization mechanism on multi-server reservation system | |
CN111861482B (en) | Block chain account checking method and system | |
CN112463211A (en) | System architecture transformation method compatible with multiple development architectures and system architecture | |
KR20140063512A (en) | Method and system for centralized reservation context management on multi-server reservation system | |
CN112597249A (en) | Synchronous distribution and storage method and system for service data | |
WO2016082594A1 (en) | Data update processing method and apparatus | |
FI111195B (en) | Intelligent transaction | |
CN112015578A (en) | Wind control system and method based on pre-synchronous processing and post-asynchronous processing | |
CN110231936A (en) | A kind of application method of mobile terminal flow engine frame and mobile terminal flow engine | |
US20050131862A1 (en) | Web store events | |
CN112907336A (en) | Method and server for realizing order state synchronization based on mybatis interceptor | |
CN116911763A (en) | Flow approval method, device, terminal equipment and storage medium | |
CN110908644A (en) | Configuration method and device of state node, computer equipment and storage medium | |
JPS5856171A (en) | Resource information control method in multi-system | |
CN112910835B (en) | Block chain-based configuration management method, apparatus, system, device, and medium | |
JP2002049493A (en) | Method and system for generating program control information, and recording medium stored with processing program therefor | |
CN114064678A (en) | Event data processing method and device and terminal equipment | |
CN114116900A (en) | Efficient trading system and development method based on MDD model | |
CN106993060A (en) | A kind of master data integrated approach based on service architecture |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
CB02 | Change of applicant information | ||
CB02 | Change of applicant information |
Address after: 518000 building 501, 502, 601, 602, building D, wisdom Plaza, Qiaoxiang Road, Gaofa community, Shahe street, Nanshan District, Shenzhen City, Guangdong Province Applicant after: China Southern Power Grid Digital Platform Technology (Guangdong) Co.,Ltd. Address before: 518000 building 501, 502, 601, 602, building D, wisdom Plaza, Qiaoxiang Road, Gaofa community, Shahe street, Nanshan District, Shenzhen City, Guangdong Province Applicant before: China Southern Power Grid Shenzhen Digital Power Grid Research Institute Co.,Ltd. |
|
GR01 | Patent grant | ||
GR01 | Patent grant |