CN114968498A - Distributed transaction processing method and device - Google Patents

Distributed transaction processing method and device Download PDF

Info

Publication number
CN114968498A
CN114968498A CN202210651479.XA CN202210651479A CN114968498A CN 114968498 A CN114968498 A CN 114968498A CN 202210651479 A CN202210651479 A CN 202210651479A CN 114968498 A CN114968498 A CN 114968498A
Authority
CN
China
Prior art keywords
activity
compensated
compensation
target
state
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
CN202210651479.XA
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.)
Bank of China Ltd
Original Assignee
Bank of China Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Bank of China Ltd filed Critical Bank of China Ltd
Priority to CN202210651479.XA priority Critical patent/CN114968498A/en
Publication of CN114968498A publication Critical patent/CN114968498A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements 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/46Multiprogramming arrangements
    • G06F9/466Transaction processing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements 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/46Multiprogramming arrangements
    • G06F9/465Distributed object oriented systems
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements 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/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q40/00Finance; Insurance; Tax strategies; Processing of corporate or income taxes
    • G06Q40/02Banking, e.g. interest calculation or account maintenance
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/54Indexing scheme relating to G06F9/54
    • G06F2209/547Messaging middleware
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/54Indexing scheme relating to G06F9/54
    • G06F2209/548Queue

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Business, Economics & Management (AREA)
  • Finance (AREA)
  • Accounting & Taxation (AREA)
  • Development Economics (AREA)
  • Economics (AREA)
  • Marketing (AREA)
  • Strategic Management (AREA)
  • Technology Law (AREA)
  • General Business, Economics & Management (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application provides a distributed transaction processing method and a device, wherein the method comprises the following steps: responding to an automatic compensation triggering event, acquiring activity information of at least one activity to be compensated, and writing the activity information of the at least one activity to be compensated into a remote dictionary service queue; determining target activities to be compensated meeting set conditions based on activity information in the remote dictionary service queue; generating a compensation message, wherein the compensation message comprises an activity identifier of a target activity to be compensated; sending a compensation message to the message middleware, increasing the activity compensation time interval of the target activity to be compensated, and updating the activity next compensation time of the target activity to be compensated in the remote dictionary service queue based on the increased activity compensation time interval; and acquiring the compensation message from the message middleware, and calling a compensation processing service based on the compensation message so that the compensation processing service performs compensation processing on the target activity to be compensated based on the compensation message.

Description

Distributed transaction processing method and device
Technical Field
The present application relates to the field of computer technologies, and in particular, to a distributed transaction processing method and apparatus.
Background
At present, part of functional modules in a bank system are developed by adopting a distributed transaction arrangement mode based on Saga, wherein in the functional modules developed by adopting the distributed transaction arrangement mode based on Saga, if a certain task call of a forward flow fails, a service arrangement engine calls a reverse flow opposite to the forward flow to ensure the final consistency of distributed transactions.
However, when the service orchestration engine fails to perform the reverse flow, a corresponding processing mechanism is lacking to ensure the final consistency of the distributed transaction. Therefore, how to ensure the final consistency of the distributed transaction becomes an urgent problem to be solved for the case that the service orchestration engine fails to execute the reverse flow.
Disclosure of Invention
The application provides the following technical scheme:
one aspect of the present application provides a distributed transaction processing method, including:
responding to an automatic compensation triggering event, acquiring activity information of at least one activity to be compensated, and writing the activity information of at least one activity to be compensated into a remote dictionary service queue, wherein the activity to be compensated is distributed transaction activity which is in a failure state or an unknown state or an executing state, and the duration of the executing state exceeds a set threshold, and the activity information at least comprises: the next compensation time of the activity is related to the activity identifier;
determining target activities to be compensated meeting set conditions based on activity information in the remote dictionary service queue;
generating a compensation message, wherein the compensation message comprises an activity identifier of the target activity to be compensated;
sending the compensation message to a message middleware, increasing the activity compensation time interval of the target activity to be compensated, and updating the activity next compensation time of the target activity to be compensated in the remote dictionary service queue based on the increased activity compensation time interval;
and acquiring the compensation message from the message middleware, and calling a compensation processing service based on the compensation message so that the compensation processing service performs compensation processing on the target activity to be compensated based on the compensation message.
Optionally, the determining, based on activity information in the remote dictionary service queue, a target activity to be compensated that meets a set condition includes:
acquiring an active identifier from a remote dictionary service queue, and locking the active identifier under the condition that the active identifier is in an unlocked state;
judging whether an activity identifier matched with the activity identifier exists in a database or not;
if yes, determining whether the current time is consistent with the next compensation time of the activity associated with the activity identifier;
and if so, determining that the activity to which the activity identifier belongs is the target activity to be compensated.
Optionally, the compensating processing service performs compensation processing on the target activity to be compensated based on the compensation message, including:
the compensation processing service acquires the activity identification of the target activity to be compensated from the compensation message, and acquires a record associated with the target activity to be compensated from a database based on the activity identification of the target activity to be compensated;
acquiring the state of the target activity to be compensated from the record, and determining whether the compensation times of the target activity to be compensated exceed the maximum compensation times under the condition that the state of the target activity to be compensated is an unsuccessful execution state or a non-execution state of a back flushing operation;
if not, determining whether the difference between the last updating time and the current time of the target activity to be compensated exceeds the delay time under the condition that the activity starting time of the target activity to be compensated is consistent with the last counting date;
if not, determining an abnormal task in the target activity to be compensated from the record;
if the abnormal task is a task with synchronous attributes, performing a back flushing operation on the abnormal task and a task before the abnormal task from the abnormal task;
and if the abnormal task is the task with the asynchronous attribute, executing retry operation on the abnormal task and the task behind the abnormal task from the abnormal task.
Optionally, the method further includes:
and deleting the activity information of the target activity to be compensated from the remote dictionary service queue under the condition that the state of the target activity to be compensated is a successful execution state or a state of performing a back flushing operation, or under the condition that the compensation times of the target activity to be compensated exceed the maximum compensation times.
Optionally, the activity information further includes: state information, the method further comprising:
acquiring a target record associated with the activity needing automatic compensation in a database, wherein the target record comprises a record of the current day and a historical record of the day before the current day;
determining at least one candidate activity-to-be-compensated record from the target records, wherein the at least one candidate activity-to-be-compensated record comprises: under the condition that the activity starting time is consistent with the last counted day, any one or more of activities to be compensated, the difference between the last updating time and the current time does not exceed the delay time, activities to be compensated, the execution state of which is a failure state and the compensation times of which do not reach the maximum retry times, activities to be compensated, the execution state of which is an execution state and the duration of the execution state of which exceeds a set time threshold, and activities to be compensated, the activity information of which does not exist in the remote dictionary service queue and the activity information of which exists in the database;
and updating the activity information in the remote dictionary service queue based on at least one record of the candidate activity to be compensated.
Another aspect of the present application provides a distributed transaction processing apparatus, including:
a writing module, configured to respond to an automatic compensation triggering event, obtain activity information of at least one activity to be compensated, and write the activity information of the at least one activity to be compensated into a remote dictionary service queue, where the activity to be compensated is a distributed transaction activity that is in a failure state or an unknown state or an executing state and a duration of the executing state exceeds a set threshold, and the activity information at least includes: the next compensation time of the activity is related to the activity identifier;
the determining module is used for determining target activities to be compensated meeting set conditions based on the activity information in the remote dictionary service queue;
the generating module is used for generating a compensation message, and the compensation message comprises an activity identifier of the target activity to be compensated;
a sending module, configured to send the compensation message to message middleware;
the first updating module is used for increasing the activity compensation time interval of the target activity to be compensated and updating the activity next compensation time of the target activity to be compensated in the remote dictionary service queue based on the increased activity compensation time interval;
the calling module is used for acquiring the compensation message from the message middleware and calling a compensation processing service module based on the compensation message;
and the compensation processing service module is used for performing compensation processing on the target activity to be compensated based on the compensation message.
Optionally, the determining module is specifically configured to:
acquiring an active identifier from a remote dictionary service queue, and locking the active identifier under the condition that the active identifier is in an unlocked state;
judging whether an activity identifier matched with the activity identifier exists in a database or not;
if yes, determining whether the current time is consistent with the next compensation time of the activity associated with the activity identifier;
and if so, determining that the activity to which the activity identifier belongs is the target activity to be compensated.
Optionally, the compensation processing service module is specifically configured to:
acquiring an activity identifier of the target activity to be compensated from the compensation message, and acquiring a record associated with the target activity to be compensated from a database based on the activity identifier of the target activity to be compensated;
acquiring the state of the target activity to be compensated from the record, and determining whether the compensation times of the target activity to be compensated exceed the maximum compensation times under the condition that the state of the target activity to be compensated is an unsuccessful execution state or a non-execution state of a back flushing operation;
if not, determining whether the difference between the last updating time and the current time of the target activity to be compensated exceeds the delay time under the condition that the activity starting time of the target activity to be compensated is consistent with the last counting date;
if not, determining an abnormal task in the target activity to be compensated from the record;
if the abnormal task is a task with synchronous attributes, performing a back flushing operation on the abnormal task and a task before the abnormal task from the abnormal task;
and if the abnormal task is the task with the asynchronous attribute, executing retry operation on the abnormal task and the task behind the abnormal task from the abnormal task.
Optionally, the compensation processing service module is further configured to:
and deleting the activity information of the target activity to be compensated from the remote dictionary service queue under the condition that the state of the target activity to be compensated is a successful execution state or a state of performing a back flushing operation, or under the condition that the compensation times of the target activity to be compensated exceed the maximum compensation times.
Optionally, the activity information further includes: state information, the apparatus further comprising:
a second update module to:
acquiring a target record associated with the activity needing automatic compensation in a database, wherein the target record comprises a record of the current day and a historical record of the day before the current day;
determining at least one candidate activity-to-be-compensated record from the target records, wherein the at least one candidate activity-to-be-compensated record comprises: under the condition that the activity starting time is consistent with the last counted day, any one or more of activities to be compensated, the difference between the last updating time and the current time does not exceed the delay time, activities to be compensated, the execution state of which is a failure state and the compensation times of which do not reach the maximum retry times, activities to be compensated, the execution state of which is an execution state and the duration of the execution state of which exceeds a set time threshold, and activities to be compensated, the activity information of which does not exist in the remote dictionary service queue and the activity information of which exists in the database;
and updating the activity information in the remote dictionary service queue based on at least one record of the candidate activity to be compensated.
In the method, the activity information of at least one activity to be compensated is obtained, the activity information of the at least one activity to be compensated is written into a remote dictionary service queue, the activity information of the activity to be compensated is cached, the target activity to be compensated meeting set conditions is determined based on the activity information in the remote dictionary service queue, a compensation message is generated, the compensation message is sent to a message middleware, the compensation message is obtained from the message middleware, and a compensation processing service is called based on the compensation message, so that the compensation processing service carries out compensation processing on the target activity to be compensated based on the compensation message, and therefore automatic compensation can be carried out under the condition that a service arrangement engine fails to execute a reverse flow, and consistency of distributed transactions is guaranteed.
In addition, by increasing the activity compensation time interval of the target activity to be compensated and updating the activity next compensation time of the target activity to be compensated in the remote dictionary service queue based on the increased activity compensation time interval, the times of invalid retry of the target activity to be compensated can be reduced, and system resources are saved.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without inventive labor.
Fig. 1 is a schematic flowchart of a distributed transaction processing method provided in embodiment 1 of the present application;
fig. 2 is a schematic flowchart of a distributed transaction processing method provided in embodiment 2 of the present application;
fig. 3 is a schematic flowchart of a distributed transaction processing method provided in embodiment 3 of the present application;
FIG. 4 is a schematic diagram of a logic structure of a distributed transaction processing apparatus provided in the present application;
fig. 5 is a schematic structural diagram of an electronic device provided in the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
In order to make the aforementioned objects, features and advantages of the present application more comprehensible, the present application is described in further detail with reference to the accompanying drawings and the detailed description.
Referring to fig. 1, a schematic flow chart of a distributed transaction processing method provided in embodiment 1 of the present application is shown, as shown in fig. 1, the method may include, but is not limited to, the following steps:
step S11, responding to an automatic compensation triggering event, acquiring activity information of at least one activity to be compensated, and writing the activity information of the at least one activity to be compensated into a remote dictionary service queue, where the activity to be compensated is a distributed transaction activity in a failure state, an unknown state, or an executing state, and a duration of the executing state exceeds a set threshold, and the activity information includes: and the next compensation time of the activity associated with the activity identifier.
Auto-compensation triggering events may include, but are not limited to: the service orchestration engine fails to perform the reverse flow.
The activity information of the at least one activity to be compensated is obtained, which may include but is not limited to:
and receiving the activity information of at least one activity to be compensated acquired by the SAGA transaction coordinator.
Of course, the activity information of the at least one activity to be compensated may also include, but is not limited to:
and actively scanning at least one record associated with the activity to be compensated in the activity information table in the database by utilizing the first timing task, and acquiring the activity information of at least one activity to be compensated from the record.
It will be appreciated that the activity identification is used to uniquely mark the activity to be compensated. The activity identifications of different activities to be compensated are different.
In this embodiment, the activity to be compensated may include at least one task.
And step S12, determining target activities to be compensated meeting set conditions based on the activity information in the remote dictionary service queue.
This step may include, but is not limited to:
searching activity information in a Remote Dictionary service (Redis) queue for activity next compensation time associated with an activity identifier consistent with the current time;
and if the activity to be compensated is found, determining the activity to be compensated to which the activity identifier associated with the next compensation time of the found activity belongs as the target activity to be compensated.
And step S13, generating a compensation message, wherein the compensation message comprises an activity identifier of the target activity to be compensated.
Step S14, sending the compensation message to a message middleware, increasing an activity compensation time interval of the target activity to be compensated, and updating an activity next compensation time of the target activity to be compensated in the remote dictionary service queue based on the increased activity compensation time interval.
Step S15, obtaining the compensation message from the message middleware, and invoking a compensation processing service based on the compensation message, so that the compensation processing service performs compensation processing on the target activity to be compensated based on the compensation message.
In this embodiment, the performing, by the compensation processing service, compensation processing on the target activity to be compensated based on the compensation message includes:
s151, the compensation processing service acquires the activity identifier of the target activity to be compensated from the compensation message, and acquires a record associated with the target activity to be compensated from a database based on the activity identifier of the target activity to be compensated;
s152, acquiring the state of the target activity to be compensated from the record, and determining whether the compensation times of the target activity to be compensated exceed the maximum compensation times under the condition that the state of the target activity to be compensated is an unsuccessfully executed state or a state without executing a back flushing operation;
if not, go to step S153;
s153, determining whether the difference between the last updating time and the current time of the target activity to be compensated exceeds the delay time or not under the condition that the activity starting time of the target activity to be compensated is consistent with the last counting day;
if not, go to step S154;
s154, determining abnormal tasks in the target activities to be compensated from the records;
s155, if the abnormal task is a task with synchronous attributes, performing a back flushing operation on the abnormal task and a task before the abnormal task from the abnormal task;
and S156, if the abnormal task is the task with the asynchronous attribute, executing retry operation on the abnormal task and the task after the abnormal task from the abnormal task.
In this embodiment, the activity information of the target activity to be compensated may be deleted from the remote dictionary service queue when the state of the target activity to be compensated is a successfully executed state or a state in which a rollback operation has been executed, or when the number of times of compensation of the target activity to be compensated exceeds the maximum number of times of compensation.
It is understood that, in the case that the state of the target activity to be compensated is a successfully executed state or a state in which a rollback operation has been executed, or in the case that the number of times of compensation of the target activity to be compensated exceeds the maximum number of times of compensation, deleting the activity information of the target activity to be compensated from the remote dictionary service queue may ensure the validity of the remote dictionary service queue.
In this embodiment, by obtaining activity information of at least one activity to be compensated, writing the activity information of the at least one activity to be compensated into the remote dictionary service queue, implementing caching of the activity information of the activity to be compensated, determining a target activity to be compensated that meets a set condition based on the activity information in the remote dictionary service queue, generating a compensation message, sending the compensation message to the message middleware, obtaining the compensation message from the message middleware, and invoking a compensation processing service based on the compensation message, so that the compensation processing service performs compensation processing on the target activity to be compensated based on the compensation message, thereby implementing automatic compensation and ensuring consistency of distributed transactions in the case that a service orchestration engine fails to execute a reverse flow.
In addition, by increasing the activity compensation time interval of the target activity to be compensated and updating the activity next compensation time of the target activity to be compensated in the remote dictionary service queue based on the increased activity compensation time interval, the times of invalid retry of the target activity to be compensated can be reduced, and system resources are saved.
As another alternative embodiment of the present application, in order to refine the distributed transaction processing method described in embodiment 1 above, referring to fig. 2, a schematic flow diagram of embodiment 2 of the distributed transaction processing method provided in the present application is provided, where the method may include, but is not limited to, the following steps:
step S21, responding to an automatic compensation triggering event, acquiring activity information of at least one activity to be compensated, and writing the activity information of the at least one activity to be compensated into a remote dictionary service queue, where the activity to be compensated is a distributed transaction activity in a failure state, an unknown state, or an executing state, and a duration of the executing state exceeds a set threshold, and the activity information includes: and the next compensation time of the activity associated with the activity identifier.
And step S22, obtaining the active identification from the remote dictionary service queue, and locking the active identification under the condition that the active identification is in an unlocked state.
And step S23, judging whether an activity identifier matched with the activity identifier exists in the database.
If so, go to step S24.
And step S24, determining whether the current time is consistent with the next compensation time of the activity associated with the activity identifier.
If yes, go to step S25.
And step S25, determining the activity to which the activity identification belongs as the target activity to be compensated.
Steps S22-S25 are a specific implementation of step S12 in example 1.
Step S26, generating a compensation message, wherein the compensation message comprises an activity identifier of the target activity to be compensated;
step S27, sending the compensation message to a message middleware, increasing the activity compensation time interval of the target activity to be compensated, and updating the activity next compensation time of the target activity to be compensated in the remote dictionary service queue based on the increased activity compensation time interval;
step S28, obtaining the compensation message from the message middleware, and invoking a compensation processing service based on the compensation message, so that the compensation processing service performs compensation processing on the target activity to be compensated based on the compensation message.
The detailed procedures of steps S26-S28 can be found in the related descriptions of steps S13-S15 in embodiment 1, and are not repeated herein.
In this embodiment, by obtaining activity information of at least one activity to be compensated, writing the activity information of the at least one activity to be compensated into a remote dictionary service queue, implementing caching of the activity information of the activity to be compensated, and obtaining an activity identifier from the remote dictionary service queue, locking the activity identifier when the activity identifier is in an unlocked state, determining whether an activity identifier matching the activity identifier exists in a database, if so, determining whether current time is consistent with next compensation time of the activity associated with the activity identifier, if so, determining that the activity to which the activity identifier belongs is a target activity to be compensated, generating a compensation message, sending the compensation message to a message middleware, obtaining the compensation message from the message middleware, calling a compensation processing service based on the compensation message, so that the compensation processing service is based on the compensation message, and compensating the target activity to be compensated, so that automatic compensation can be performed under the condition that the service arrangement engine fails to execute a reverse flow, and the consistency of distributed transactions is ensured.
In addition, by increasing the activity compensation time interval of the target activity to be compensated and updating the activity next compensation time of the target activity to be compensated in the remote dictionary service queue based on the increased activity compensation time interval, the times of invalid retry of the target activity to be compensated can be reduced, and system resources are saved.
And locking the movable identifier under the condition that the movable identifier is in an unlocked state, so that the disorder of the processing process of the activity to be compensated is avoided.
As another optional embodiment of the present application, in order to solve an extension of the distributed transaction processing method described in embodiment 1 above, referring to fig. 3, a schematic flow diagram of embodiment 3 of the distributed transaction processing method provided in the present application is provided, where the method may include, but is not limited to, the following steps:
step S31, responding to an automatic compensation triggering event, acquiring activity information of at least one activity to be compensated, and writing the activity information of the at least one activity to be compensated into a remote dictionary service queue, where the activity to be compensated is a distributed transaction activity in a failure state, an unknown state, or an executing state, and a duration of the executing state exceeds a set threshold, and the activity information includes: and the next compensation time and state information of the activity associated with the activity identifier.
And step S32, determining target activities to be compensated meeting set conditions based on the activity information in the remote dictionary service queue.
And step S33, generating a compensation message, wherein the compensation message comprises the activity identification of the target activity to be compensated.
Step S34, sending the compensation message to a message middleware, increasing an activity compensation time interval of the target activity to be compensated, and updating an activity next compensation time of the target activity to be compensated in the remote dictionary service queue based on the increased activity compensation time interval.
Step S35, obtaining the compensation message from the message middleware, and invoking a compensation processing service based on the compensation message, so that the compensation processing service performs compensation processing on the target activity to be compensated based on the compensation message.
The detailed procedures of steps S31-S35 can be found in the related descriptions of steps S11-S15 in embodiment 1, and are not repeated herein.
And step S36, acquiring a target record associated with the activity needing automatic compensation in the database, wherein the target record comprises a record of the current day and a historical record of the day before the current day.
And step S37, determining at least one candidate record of activities to be compensated from the target records.
At least one of the candidate activities to be compensated comprises: and under the condition that the activity starting time is consistent with the last counted day, any one or more of activities to be compensated, the difference between the last updating time and the current time does not exceed the delay time, activities to be compensated, the execution state of which is a failure state and the compensation number of times does not reach the maximum retry number, activities to be compensated, the execution state of which is an execution state and the duration of the execution state exceeds a set time threshold, and activities to be compensated, the activity information of which does not exist in the remote dictionary service queue and the activity information of which exists in the database.
The last update time may be understood as the last update time of the record of the activity to be compensated in the database.
Step S38, updating activity information in the remote dictionary service queue based on at least one record of the candidate activity to be compensated.
For example, if the candidate activity to be compensated is an activity to be compensated based on a result that a difference between the last update time and the current time does not exceed the delay time when the activity start time coincides with the last counted day, or an activity to be compensated whose execution state is a failure state and whose compensation number does not reach the maximum retry number, or an activity to be compensated whose execution state is an executing state and whose duration of the executing state exceeds a set time threshold, the state information of the candidate activity to be compensated among the activity information in the remote dictionary service queue is determined based on the state of the candidate activity to be compensated in the record of the candidate activity to be compensated.
And if the candidate activity to be compensated is the activity to be compensated, the activity information of the candidate activity to be compensated is determined based on the record of the candidate activity to be compensated, and the activity information of the candidate activity to be compensated is added into the remote dictionary service queue.
In this embodiment, by obtaining activity information of at least one activity to be compensated, writing the activity information of the at least one activity to be compensated into the remote dictionary service queue, implementing caching of the activity information of the activity to be compensated, determining a target activity to be compensated that meets a set condition based on the activity information in the remote dictionary service queue, generating a compensation message, sending the compensation message to the message middleware, obtaining the compensation message from the message middleware, and invoking a compensation processing service based on the compensation message, so that the compensation processing service performs compensation processing on the target activity to be compensated based on the compensation message, thereby implementing automatic compensation and ensuring consistency of distributed transactions in the case that a service orchestration engine fails to execute a reverse flow.
In addition, by increasing the activity compensation time interval of the target activity to be compensated and updating the activity next compensation time of the target activity to be compensated in the remote dictionary service queue based on the increased activity compensation time interval, the times of invalid retry of the target activity to be compensated can be reduced, and system resources are saved.
And determining at least one candidate activity to be compensated record from the target record by acquiring a target record associated with the activity needing automatic compensation in the database, wherein the target record comprises the record of the current day and the historical record of the day before the current day, and the at least one candidate activity to be compensated comprises: under the condition that the activity starting time is consistent with the last counted day, the difference between the last updating time and the current time does not exceed any one or more of activities to be compensated of the delay time, activities to be compensated of which the execution state is a failure state and the compensation times do not reach the maximum retry times, activities to be compensated of which the execution state is an execution state and the duration time of the execution state exceeds a set time threshold value, and activities of which the activity information does not exist in the remote dictionary service queue and the activity information exists in the database, updating the activity information in the remote dictionary service queue based on at least one record of the candidate activities to be compensated, and ensuring that the remote dictionary service queue is consistent with the database.
Next, a distributed transaction processing apparatus provided in the present application is described, and the distributed transaction processing apparatus described below and the distributed transaction processing method described above may be referred to correspondingly.
Referring to fig. 4, the distributed transaction apparatus includes: the write module 100, the determination module 200, the generation module 300, the transmission module 400, the first update module 500, the call module 600, and the compensation processing service module 700.
A writing module 100, configured to respond to an automatic compensation triggering event, obtain activity information of at least one activity to be compensated, and write the activity information of the at least one activity to be compensated into a remote dictionary service queue, where the activity to be compensated is a distributed transaction activity that is in a failure state, an unknown state, or an executing state, and a duration of the executing state exceeds a set threshold, where the activity information at least includes: the next compensation time of the activity is related to the activity identifier;
a determining module 200, configured to determine, based on activity information in a remote dictionary service queue, a target activity to be compensated that meets a set condition;
a generating module 300, configured to generate a compensation message, where the compensation message includes an activity identifier of the target activity to be compensated;
a sending module 400, configured to send the compensation message to message middleware;
a first updating module 500, configured to increase an activity compensation time interval of the target activity to be compensated, and update an activity next compensation time of the target activity to be compensated in the remote dictionary service queue based on the increased activity compensation time interval;
a calling module 600, configured to obtain the compensation message from the message middleware, and call a compensation processing service module based on the compensation message;
the compensation processing service module 700 is configured to perform compensation processing on the target activity to be compensated based on the compensation message.
In this embodiment, the determining module 200 may be specifically configured to:
acquiring an active identifier from a remote dictionary service queue, and locking the active identifier under the condition that the active identifier is in an unlocked state;
judging whether an activity identifier matched with the activity identifier exists in a database or not;
if yes, determining whether the current time is consistent with the next compensation time of the activity associated with the activity identifier;
and if so, determining that the activity to which the activity identifier belongs is the target activity to be compensated.
In this embodiment, the compensation processing service module 700 may be specifically configured to:
acquiring an activity identifier of the target activity to be compensated from the compensation message, and acquiring a record associated with the target activity to be compensated from a database based on the activity identifier of the target activity to be compensated;
acquiring the state of the target activity to be compensated from the record, and determining whether the compensation times of the target activity to be compensated exceed the maximum compensation times under the condition that the state of the target activity to be compensated is an unsuccessful execution state or a non-execution state of a back flushing operation;
if not, determining whether the difference between the last updating time and the current time of the target activity to be compensated exceeds the delay time under the condition that the activity starting time of the target activity to be compensated is consistent with the last counting date;
if not, determining an abnormal task in the target activity to be compensated from the record;
if the abnormal task is a task with synchronous attributes, performing a back flushing operation on the abnormal task and a task before the abnormal task from the abnormal task;
and if the abnormal task is the task with the asynchronous attribute, executing retry operation on the abnormal task and the task behind the abnormal task from the abnormal task.
In this embodiment, the compensation processing service module 700 may be further configured to:
and deleting the activity information of the target activity to be compensated from the remote dictionary service queue under the condition that the state of the target activity to be compensated is a successful execution state or a state of performing a back flushing operation, or under the condition that the compensation times of the target activity to be compensated exceed the maximum compensation times.
In this embodiment, the activity information further includes: state information, the distributed transaction processing apparatus further comprises:
a second update module to:
acquiring a target record associated with the activity needing automatic compensation in a database, wherein the target record comprises a record of the current day and a historical record of the day before the current day;
determining at least one candidate activity-to-be-compensated record from the target records, wherein the at least one candidate activity-to-be-compensated record comprises: under the condition that the activity starting time is consistent with the last counted day, any one or more of activities to be compensated, the difference between the last updating time and the current time does not exceed the delay time, activities to be compensated, the execution state of which is a failure state and the compensation times of which do not reach the maximum retry times, activities to be compensated, the execution state of which is an execution state and the duration of the execution state of which exceeds a set time threshold, and activities to be compensated, the activity information of which does not exist in the remote dictionary service queue and the activity information of which exists in the database;
and updating the activity information in the remote dictionary service queue based on at least one record of the candidate activity to be compensated.
Corresponding to the distributed transaction processing method provided by the application, the application also provides an embodiment of the electronic device applying the distributed transaction processing method.
Fig. 5 is a schematic structural diagram of an electronic device provided in the present application, where the electronic device may include the following structure:
a memory 10 and a processor 20.
A memory 10 for storing at least one set of instructions;
and a processor 20, configured to call and execute the instruction set in the memory 10, and execute the distributed transaction processing method described in any one of embodiments 1 to 3 by executing the instruction set.
It should be noted that each embodiment is mainly described as a difference from the other embodiments, and the same and similar parts between the embodiments may be referred to each other. For the device-like embodiment, since it is basically similar to the method embodiment, the description is simple, and for the relevant points, reference may be made to the partial description of the method embodiment.
Finally, it should also be noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
For convenience of description, the above devices are described as being divided into various modules by functions, and are described separately. Of course, the functionality of the various modules may be implemented in the same one or more software and/or hardware implementations as the present application.
From the above description of the embodiments, it is clear to those skilled in the art that the present application can be implemented by software plus necessary general hardware platform. Based on such understanding, the technical solutions of the present application may be essentially or partially implemented in the form of a software product, which may be stored in a storage medium, such as a ROM/RAM, a magnetic disk, an optical disk, etc., and includes several instructions for enabling a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the method according to the embodiments or some parts of the embodiments of the present application.
The foregoing describes in detail a distributed transaction processing method and apparatus provided by the present application, and specific examples are applied herein to explain the principles and embodiments of the present application, and the descriptions of the foregoing embodiments are only used to help understand the method and core ideas of the present application; meanwhile, for a person skilled in the art, according to the idea of the present application, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present application.

Claims (10)

1. A distributed transaction processing method, comprising:
responding to an automatic compensation triggering event, acquiring activity information of at least one activity to be compensated, and writing the activity information of at least one activity to be compensated into a remote dictionary service queue, wherein the activity to be compensated is distributed transaction activity which is in a failure state or an unknown state or an executing state, and the duration of the executing state exceeds a set threshold, and the activity information at least comprises: the next compensation time of the activity is related to the activity identifier;
determining target activities to be compensated meeting set conditions based on activity information in the remote dictionary service queue;
generating a compensation message, wherein the compensation message comprises an activity identifier of the target activity to be compensated;
sending the compensation message to a message middleware, increasing the activity compensation time interval of the target activity to be compensated, and updating the activity next compensation time of the target activity to be compensated in the remote dictionary service queue based on the increased activity compensation time interval;
and acquiring the compensation message from the message middleware, and calling a compensation processing service based on the compensation message so that the compensation processing service performs compensation processing on the target activity to be compensated based on the compensation message.
2. The method of claim 1, wherein the determining the target activity to be compensated that meets the set condition based on the activity information in the remote dictionary service queue comprises:
acquiring an active identifier from a remote dictionary service queue, and locking the active identifier under the condition that the active identifier is in an unlocked state;
judging whether an activity identifier matched with the activity identifier exists in a database or not;
if yes, determining whether the current time is consistent with the next compensation time of the activity associated with the activity identifier;
and if so, determining that the activity to which the activity identifier belongs is the target activity to be compensated.
3. The method of claim 1, wherein the compensation processing service performs compensation processing on the target activity to be compensated based on the compensation message, and comprises:
the compensation processing service acquires the activity identification of the target activity to be compensated from the compensation message, and acquires a record associated with the target activity to be compensated from a database based on the activity identification of the target activity to be compensated;
acquiring the state of the target activity to be compensated from the record, and determining whether the compensation times of the target activity to be compensated exceed the maximum compensation times under the condition that the state of the target activity to be compensated is an unsuccessful execution state or a non-execution state of a back flushing operation;
if not, determining whether the difference between the last updating time and the current time of the target activity to be compensated exceeds the delay time under the condition that the activity starting time of the target activity to be compensated is consistent with the last counting date;
if not, determining an abnormal task in the target activity to be compensated from the record;
if the abnormal task is a task with synchronous attributes, performing a back flushing operation on the abnormal task and a task before the abnormal task from the abnormal task;
and if the abnormal task is the task with the asynchronous attribute, executing retry operation on the abnormal task and the task behind the abnormal task from the abnormal task.
4. The method of claim 3, further comprising:
and deleting the activity information of the target activity to be compensated from the remote dictionary service queue under the condition that the state of the target activity to be compensated is a successful execution state or a state of performing a back flushing operation, or under the condition that the compensation times of the target activity to be compensated exceed the maximum compensation times.
5. The method of claim 1, wherein the activity information further comprises: state information, the method further comprising:
acquiring a target record associated with the activity needing automatic compensation in a database, wherein the target record comprises a record of the current day and a historical record of the day before the current day;
determining at least one candidate activity-to-be-compensated record from the target records, wherein the at least one candidate activity-to-be-compensated record comprises: under the condition that the activity starting time is consistent with the last counted day, any one or more of activities to be compensated, the difference between the last updating time and the current time does not exceed the delay time, activities to be compensated, the execution state of which is a failure state and the compensation times of which do not reach the maximum retry times, activities to be compensated, the execution state of which is an execution state and the duration of the execution state of which exceeds a set time threshold, and activities to be compensated, the activity information of which does not exist in the remote dictionary service queue and the activity information of which exists in the database;
and updating the activity information in the remote dictionary service queue based on at least one record of the candidate activity to be compensated.
6. A distributed transaction processing apparatus, comprising:
a writing module, configured to respond to an automatic compensation triggering event, obtain activity information of at least one activity to be compensated, and write the activity information of the at least one activity to be compensated into a remote dictionary service queue, where the activity to be compensated is a distributed transaction activity that is in a failure state or an unknown state or an executing state and a duration of the executing state exceeds a set threshold, and the activity information at least includes: the next compensation time of the activity is related to the activity identifier;
the determining module is used for determining target activities to be compensated meeting set conditions based on the activity information in the remote dictionary service queue;
the generating module is used for generating a compensation message, and the compensation message comprises an activity identifier of the target activity to be compensated;
a sending module, configured to send the compensation message to message middleware;
the first updating module is used for increasing the activity compensation time interval of the target activity to be compensated and updating the activity next compensation time of the target activity to be compensated in the remote dictionary service queue based on the increased activity compensation time interval;
the calling module is used for acquiring the compensation message from the message middleware and calling a compensation processing service module based on the compensation message;
and the compensation processing service module is used for performing compensation processing on the target activity to be compensated based on the compensation message.
7. The apparatus of claim 6, wherein the determining module is specifically configured to:
acquiring an active identifier from a remote dictionary service queue, and locking the active identifier under the condition that the active identifier is in an unlocked state;
judging whether an activity identifier matched with the activity identifier exists in a database or not;
if yes, determining whether the current time is consistent with the next compensation time of the activity associated with the activity identifier;
and if so, determining that the activity to which the activity identifier belongs is the target activity to be compensated.
8. The apparatus of claim 6, wherein the compensation processing service module is specifically configured to:
acquiring an activity identifier of the target activity to be compensated from the compensation message, and acquiring a record associated with the target activity to be compensated from a database based on the activity identifier of the target activity to be compensated;
acquiring the state of the target activity to be compensated from the record, and determining whether the compensation times of the target activity to be compensated exceed the maximum compensation times under the condition that the state of the target activity to be compensated is an unsuccessful execution state or a non-execution back flushing operation state;
if not, determining whether the difference between the last updating time and the current time of the target activity to be compensated exceeds the delay time under the condition that the activity starting time of the target activity to be compensated is consistent with the last counting day;
if not, determining an abnormal task in the target activity to be compensated from the record;
if the abnormal task is a task with synchronous attributes, performing a back flushing operation on the abnormal task and a task before the abnormal task from the abnormal task;
and if the abnormal task is the task with the asynchronous attribute, executing retry operation on the abnormal task and the task behind the abnormal task from the abnormal task.
9. The apparatus of claim 8, wherein the compensation processing service module is further configured to:
and deleting the activity information of the target activity to be compensated from the remote dictionary service queue under the condition that the state of the target activity to be compensated is a successful execution state or a state of performing a back flushing operation, or under the condition that the compensation times of the target activity to be compensated exceed the maximum compensation times.
10. The apparatus of claim 6, wherein the activity information further comprises: state information, the apparatus further comprising:
a second update module to:
obtaining a target record associated with the activity needing automatic compensation in a database, wherein the target record comprises a record of the current day and a historical record of the day before the current day;
determining at least one candidate activity-to-be-compensated record from the target records, wherein the at least one candidate activity-to-be-compensated record comprises: under the condition that the activity starting time is consistent with the last counted day, any one or more of activities to be compensated, the difference between the last updating time and the current time does not exceed the delay time, activities to be compensated, the execution state of which is a failure state and the compensation times of which do not reach the maximum retry times, activities to be compensated, the execution state of which is an execution state and the duration of the execution state of which exceeds a set time threshold, and activities to be compensated, the activity information of which does not exist in the remote dictionary service queue and the activity information of which exists in the database;
and updating the activity information in the remote dictionary service queue based on at least one record of the candidate activity to be compensated.
CN202210651479.XA 2022-06-10 2022-06-10 Distributed transaction processing method and device Pending CN114968498A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210651479.XA CN114968498A (en) 2022-06-10 2022-06-10 Distributed transaction processing method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210651479.XA CN114968498A (en) 2022-06-10 2022-06-10 Distributed transaction processing method and device

Publications (1)

Publication Number Publication Date
CN114968498A true CN114968498A (en) 2022-08-30

Family

ID=82962042

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210651479.XA Pending CN114968498A (en) 2022-06-10 2022-06-10 Distributed transaction processing method and device

Country Status (1)

Country Link
CN (1) CN114968498A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116909760A (en) * 2023-09-13 2023-10-20 中移(苏州)软件技术有限公司 Data processing method, device, readable storage medium and electronic equipment

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116909760A (en) * 2023-09-13 2023-10-20 中移(苏州)软件技术有限公司 Data processing method, device, readable storage medium and electronic equipment
CN116909760B (en) * 2023-09-13 2023-11-28 中移(苏州)软件技术有限公司 Data processing method, device, readable storage medium and electronic equipment

Similar Documents

Publication Publication Date Title
CN111314422A (en) Kafka-based message processing method and system, storage medium and computer equipment
CN111813791A (en) Method and equipment for distributed transaction compensation
CN102203779B (en) Method for updating data and control apparatus thereof
CN112835688A (en) Distributed transaction processing method, device and storage medium
CN106612330B (en) System and method for supporting distributed multi-file import
CN110888718A (en) Method and device for realizing distributed transaction
CN114968498A (en) Distributed transaction processing method and device
CN113094362A (en) Method and device for reliably delivering and processing asynchronous message
CN110941622A (en) Data processing method and device
CN108108126B (en) Data processing method, device and equipment
CN112632093A (en) Work order processing method, device, system, storage medium and program product
CN108959548B (en) Service request processing method and device
CN113515352B (en) Distributed transaction different-library mode anti-transaction calling method and device
CN116128491A (en) Payment information determination method, device, system and electronic equipment
CN115454933A (en) File processing method, device, equipment, storage medium and program product
CN115525449A (en) Micro-service data transmission system, method and storage medium
CN113867984A (en) Distributed transaction processing method, device and equipment
CN111708617A (en) Transaction processing method, device, equipment and computer readable storage medium
CN111708780A (en) Distributed table system and fragment master selection method, device, server and medium
CN111338574A (en) Block chain-based data self-repairing method, device, medium and electronic equipment
CN110597828A (en) Database changing method, device, equipment and storage medium
CN111049938A (en) Message notification method and device, electronic equipment and readable storage medium
CN110874713A (en) Service state management method and device
CN113051085B (en) Service calling method, device, server and storage medium
CN114090545A (en) Method, apparatus, storage medium, and program product for maintaining distributed database

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