CN112417042A - Method and device for processing service request - Google Patents

Method and device for processing service request Download PDF

Info

Publication number
CN112417042A
CN112417042A CN202011302418.XA CN202011302418A CN112417042A CN 112417042 A CN112417042 A CN 112417042A CN 202011302418 A CN202011302418 A CN 202011302418A CN 112417042 A CN112417042 A CN 112417042A
Authority
CN
China
Prior art keywords
service
transaction completion
successful
completion state
success
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
CN202011302418.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.)
China Construction Bank Corp
Original Assignee
China Construction Bank Corp
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 China Construction Bank Corp filed Critical China Construction Bank Corp
Priority to CN202011302418.XA priority Critical patent/CN112417042A/en
Publication of CN112417042A publication Critical patent/CN112417042A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • G06F16/273Asynchronous replication or reconciliation

Landscapes

  • Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Computing Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a method and a device for processing a service request, and relates to the technical field of computers. One embodiment of the method comprises: receiving transaction completion states uploaded by each service, wherein the transaction completion states comprise success and failure; if the service with the transaction completion state as failure exists in each service, retrieving the service with the transaction completion state as success from each service; and constructing a correction task for the service with the transaction completion state being successful, and calling the service with the transaction completion state being successful so as to enable the service with the transaction completion state being successful to execute a correction method. The implementation method can solve the technical problem that the transaction consistency cannot be guaranteed.

Description

Method and device for processing service request
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method and an apparatus for processing a service request.
Background
After the original business micro-services are split, a plurality of micro-services are often accessed to process one business request (such as a transaction), and due to various reasons such as network instability, a certain service abnormality may occur, if the control is not performed, data inconsistency is easily caused by reasons such as incomplete processing or repeated data submission, and the like, and operation and maintenance personnel are often required to correct manually, so that the operation and maintenance cost is high and the efficiency is low.
For the maintenance of data consistency among cross systems, if the data consistency is actively maintained when developers develop service interfaces, various ways of maintaining consistency easily coexist due to different habits and understanding degrees of the developers, so that the maintenance cost is greatly increased.
At present, for the problem of transaction consistency of distributed microservice, a common method is to serially connect a plurality of application transactions on a business processing chain into a long transaction, perform multi-stage commit by using transaction control of a database, and set a mode of compensating the transactions.
In the process of implementing the invention, the inventor finds that at least the following problems exist in the prior art:
all participating nodes (i.e., participants) are transaction-blocking, and the coordinator needs to additionally assign a timeout mechanism to each participant, and the entire transaction fails after timeout. If the coordinator goes down after sending the commit message and the only participant receiving the commit message goes down at the same time, even if the coordinator generates a new coordinator through the election protocol, the state of the transaction is uncertain, and it cannot know whether the transaction has been committed, so that the consistency of the transaction cannot be ensured.
Disclosure of Invention
In view of this, embodiments of the present invention provide a method and an apparatus for processing a service request, so as to solve the technical problem that transaction consistency cannot be guaranteed.
To achieve the above object, according to an aspect of the embodiments of the present invention, there is provided a method for processing a service request, including:
receiving transaction completion states uploaded by each service, wherein the transaction completion states comprise success and failure;
if the service with the transaction completion state as failure exists in each service, retrieving the service with the transaction completion state as success from each service;
and constructing a correction task for the service with the transaction completion state being successful, and calling the service with the transaction completion state being successful so as to enable the service with the transaction completion state being successful to execute a correction method.
Optionally, invoking the service whose transaction completion status is successful, so that the service whose transaction completion status is successful executes a flushing method, including:
and according to the sequence of the received transaction completion states of the services with the successful transaction completion states, calling the services with the successful transaction completion states in a reverse sequence in order to enable the services with the successful transaction completion states to sequentially execute a flushing method.
Optionally, each service intercepts request data and a transaction completion status, and stores the request data in a cache.
Optionally, the request data includes a global serial number and service data parsed by the service from the received service request.
Optionally, in each service, a base class of a control layer receiving the service request is defined, and a forward service processing method and a reverse flushing method are defined in the base class.
Optionally, constructing a correction task for the service whose transaction completion status is successful includes:
obtaining request data corresponding to the service with the transaction completion state being successful from a cache;
and constructing a correction task for the service with the transaction completion state as success according to the request data corresponding to the service with the transaction completion state as success.
Optionally, a flushing task is constructed for the service whose transaction completion status is successful, and the service whose transaction completion status is successful is called, so that the service whose transaction completion status is successful executes a flushing method, including:
and constructing a synchronous positive flushing task for the service with the transaction completion state as success, and calling the service with the transaction completion state as success so as to synchronously execute a positive flushing method for the service with the transaction completion state as success.
Optionally, after the service with the transaction completion status as successful is called, so that the service with the transaction completion status as successful synchronously executes the flushing method, the method further includes:
receiving a result of synchronous positive execution exception returned by the service with the transaction completion state being successful;
and constructing an asynchronous forward flushing task for the service with the transaction completion state being successful, and setting retry time and maximum retry times so as to obtain an asynchronous forward flushing task table.
Optionally, constructing an asynchronous forward flushing task for the service whose transaction completion status is successful, so as to obtain an asynchronous forward flushing task table, where the method includes:
periodically scanning the asynchronous forward flushing task table through a timing task according to the set retry time and the maximum retry number;
and calling a service according to the scanning result so that the service asynchronously executes the punching method.
Optionally, after invoking a service according to the scanning result, so that the service asynchronously executes the flushing method, the method further includes:
and if the number of times of calling the service reaches the maximum retry number, sending an asynchronous correction execution result to the operation and maintenance personnel.
Optionally, each service includes a service invoker and a service provider;
the service caller calls the service provider according to the received service request;
if the service provider fails to execute, triggering rollback, and returning an execution abnormal result to the service caller;
and the service caller receives the result of the abnormal execution of the service provider and triggers rollback.
In addition, according to another aspect of the embodiments of the present invention, there is provided an apparatus for processing a service request, including:
the receiving module is used for receiving transaction completion states uploaded by each service, wherein the transaction completion states comprise success and failure;
the retrieval module is used for retrieving the service with the transaction completion state as success from each service if the service with the transaction completion state as failure exists in each service;
and the calling module is used for constructing a correction task for the service with the transaction completion state as success, and calling the service with the transaction completion state as success so as to enable the service with the transaction completion state as success to execute a correction method.
Optionally, the invoking module is further configured to:
and according to the sequence of the received transaction completion states of the services with the successful transaction completion states, calling the services with the successful transaction completion states in a reverse sequence in order to enable the services with the successful transaction completion states to sequentially execute a flushing method.
Optionally, each service intercepts request data and a transaction completion status, and stores the request data in a cache.
Optionally, the request data includes a global serial number and service data parsed by the service from the received service request.
Optionally, in each service, a base class of a control layer receiving the service request is defined, and a forward service processing method and a reverse flushing method are defined in the base class.
Optionally, the invoking module is further configured to:
obtaining request data corresponding to the service with the transaction completion state being successful from a cache;
and constructing a correction task for the service with the transaction completion state as success according to the request data corresponding to the service with the transaction completion state as success.
Optionally, the invoking module is further configured to:
and constructing a synchronous positive flushing task for the service with the transaction completion state as success, and calling the service with the transaction completion state as success so as to synchronously execute a positive flushing method for the service with the transaction completion state as success.
Optionally, the invoking module is further configured to:
calling the service with the transaction completion state as success so as to receive a result of abnormal synchronous forward execution returned by the service with the transaction completion state as success after the service synchronous execution forward method with the transaction completion state as success;
and constructing an asynchronous forward flushing task for the service with the transaction completion state being successful, and setting retry time and maximum retry times so as to obtain an asynchronous forward flushing task table.
Optionally, the invoking module is further configured to:
constructing an asynchronous forward flushing task for the service with the transaction completion state being successful, and periodically scanning the asynchronous forward flushing task table through a timing task according to the set retry time and the maximum retry number after obtaining the asynchronous forward flushing task table;
and calling a service according to the scanning result so that the service asynchronously executes the punching method.
Optionally, the invoking module is further configured to:
and calling the service according to the scanning result so that after the service asynchronously executes the correction method, if the number of times of calling the service reaches the maximum retry number, the asynchronous correction execution result is sent to the operation and maintenance personnel.
Optionally, each service includes a service invoker and a service provider;
the service caller calls the service provider according to the received service request;
if the service provider fails to execute, triggering rollback, and returning an execution abnormal result to the service caller;
and the service caller receives the result of the abnormal execution of the service provider and triggers rollback.
According to another aspect of the embodiments of the present invention, there is also provided an electronic device, including:
one or more processors;
a storage device for storing one or more programs,
when the one or more programs are executed by the one or more processors, the one or more processors implement the method of any of the embodiments described above.
According to another aspect of the embodiments of the present invention, there is also provided a computer readable medium, on which a computer program is stored, which when executed by a processor implements the method of any of the above embodiments.
One embodiment of the above invention has the following advantages or benefits: the technical means that if the service with the transaction completion state failed exists, the service with the transaction completion state successful is retrieved, the correction task is constructed for the service with the transaction completion state successful, the service with the transaction completion state successful is called, and the correction method is executed for the service with the transaction completion state successful, so that the technical problem that the transaction consistency cannot be guaranteed in the prior art is solved. The embodiment of the invention collects the transaction completion state through the link tracking technology and ensures the final consistency of data after the abnormal service processing through the transaction compensation mechanism.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
fig. 1 is a schematic diagram of a main flow of a method of processing a service request according to an embodiment of the present invention;
fig. 2 is a schematic diagram of a main flow of a method of processing a service request according to a referential embodiment of the present invention;
fig. 3 is a schematic diagram of a main flow of a method of processing a service request according to another referential embodiment of the present invention;
fig. 4 is a schematic diagram of the main modules of an apparatus for processing a service request according to an embodiment of the present invention;
FIG. 5 is an exemplary system architecture diagram in which embodiments of the present invention may be employed;
fig. 6 is a schematic block diagram of a computer system suitable for use in implementing a terminal device or server of an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
Fig. 1 is a schematic diagram of a main flow of a method for processing a service request according to an embodiment of the present invention. As an embodiment of the present invention, as shown in fig. 1, the method for processing a service request is applied to a link tracing tool, and may include:
step 101, receiving transaction completion states uploaded by each service.
For each service, when the service is called, executing self business codes, and after the local transaction is finished, uploading a transaction completion state to a link tracking tool by the service, wherein the transaction completion state comprises success and failure. Alternatively, the link tracing tool may be Zipkin, which receives transaction completion status uploaded by the respective services.
Optionally, each service intercepts request data and a transaction completion status, stores the request data in a cache for use in a subsequent flushing operation, and uploads the transaction completion status to a link tracking tool. In the embodiment of the invention, by means of a mode of collecting link data, each service intercepts and records request data through an interceptor, intercepts and records the completion state of a transaction after the local transaction is finished, and the end state is when normal execution is finished, and the failed state is when abnormal execution is finished.
Since the subsequent flushing operation requires the request data carried in the service request, when the completion state of the local transaction is intercepted and recorded, the request data of each request is intercepted and recorded and is in the cache, the cached request data can be cleared after the service processing is finished or the flushing is finished, and the cache is used to avoid the pressure of a large amount of request data on the database reading and writing.
Optionally, the request data includes a global serial number and service data parsed by the service from the received service request. Because one transaction may call a plurality of different services, in order to track the transaction, a global serial number field is added, the field circulates among different services along with the transaction request and serves as an identifier of a transaction chain, when a remote service is called, the global serial number is added into request header information, and after a service provider receives the request, the global serial number is taken out and serves as the global serial number of a local transaction.
Optionally, the request data mainly records the service initiator and the service provider of each remote call, and a specific request path and parameters, and since the service request is implemented in the form of a post request body, the request parameters need to be stored after being serialized, and the type of the request parameters is stored for the subsequent deserialization request body to use.
For example, the complete request data may include:
operator, representing the operator number of the transaction (the operator number is only used for displaying information), and acquiring the data from the request head information of the request
span Id, id of current span (a specific inter-service call in a complete call chain)
traceId, transaction Link id
CLIENT, requesting CLIENT application
SERVER, requesting SERVER-side application
invokeType, the calling type of the request, is divided into Async for registering asynchronous tasks and calling Restful between conventional services
reqPath, the request path of this request
reqParam, the request body parameter of this request, is shown as a serialized result
reqParamType, the type of the request body parameter of the request, is convenient for subsequent deserialization use
taskId, records registered asynchronous task id for request to register asynchronous task
And 102, if the services with the transaction completion states as failures exist in the services, retrieving the services with the transaction completion states as successes from the services.
And after receiving the transaction completion state uploaded by each service, the link tracking tool traverses the transaction completion state uploaded by each service, and if the transaction completion state is a failed service, namely one service or a plurality of services, the link tracking tool retrieves the service with the transaction completion state as a success service from each service.
Since the service executes its own service code when the service is called, and after the local transaction is finished, the service uploads the transaction completion status to the link tracking tool, the link tracking tool can obtain the transaction completion status of each service, such as success and failure.
Optionally, each service includes a service caller and a service provider, the service caller calls the service provider according to the received service request, if the service provider fails to execute, rollback is triggered, and an execution exception result is returned to the service caller, and the service caller receives the execution exception result of the service provider, and triggers rollback. And when the execution of the service provider fails, the rollback is triggered, and the exception is returned to the service caller, so that the service caller also triggers the rollback, and the consistency of the microservice transaction is ensured.
Step 103, constructing a correction task for the service with the transaction completion state being successful, and calling the service with the transaction completion state being successful so as to enable the service with the transaction completion state being successful to execute a correction method.
After the link tracking tool retrieves the services with the transaction completion status of success, a correction task is constructed for the services with the transaction completion status of success, and then the services with the transaction completion status of success are respectively called, so that the services with the transaction completion status of success respectively execute the corresponding correction methods. The embodiment of the invention ensures the consistency of the microservice transaction through the combined action of the consistency of the transaction in the service and the transaction compensation mechanism among the cross-service.
Optionally, invoking the service whose transaction completion status is successful, so that the service whose transaction completion status is successful executes a flushing method, including: and according to the sequence of the received transaction completion states of the services with the successful transaction completion states, calling the services with the successful transaction completion states in a reverse sequence in order to enable the services with the successful transaction completion states to sequentially execute a flushing method. In the embodiment of the present invention, the link tracking tool may sequentially call the services whose transaction completion statuses are successful in a reverse order according to the sequence of the transaction completion statuses of the services whose transaction completion statuses are successful. For example, the link tracking tool receives the transaction completion status uploaded by the B service first and then receives the transaction completion status uploaded by the C service, and if the transaction completion status of both the B service and the C service is completed, the C service is invoked first and then the B service is invoked.
It should be noted that, in other embodiments of the present invention, the order of invoking the service whose transaction completion status is successful may not be limited, and the link tracking tool may also invoke the service whose transaction completion status is successful at the same time.
In each service, a base class of a control layer receiving a service request is defined, and a forward service processing method and a reverse flush method are defined in the base class. The embodiment of the invention appoints that for the method related to the data operation, the corresponding alignment method is defined by inheriting the base class, and the access path is set according to a certain rule, thereby facilitating the positioning and addressing of the alignment method. Specifically, in order to specify the format and the request path of the impulse response method, a base class of a control layer (controller layer) that receives the request is defined, a forward service processing method and a reverse impulse response method are defined in the base class, and the controller layer is agreed to be implemented by a method that inherits the base class.
Optionally, constructing a correction task for the service whose transaction completion status is successful includes: obtaining request data corresponding to the service with the transaction completion state being successful from a cache; and constructing a correction task for the service with the transaction completion state as success according to the request data corresponding to the service with the transaction completion state as success. Because each service stores the request data carried in the service request in the cache, after the link tracking tool retrieves the service with the transaction completion state as success, the link tracking tool can acquire the request data corresponding to the service with the transaction completion state as success from the cache, and construct correction tasks for the services respectively.
Optionally, step 103 may comprise: and constructing a synchronous positive flushing task for the service with the transaction completion state as success, and calling the service with the transaction completion state as success so as to synchronously execute a positive flushing method for the service with the transaction completion state as success. In the embodiment of the invention, after the link tracking tool retrieves the service with the transaction completion state as success, a synchronous reversal task is constructed for the service with the transaction completion state as success, and then the services with the transaction completion state as success are respectively called, so that the services with the transaction completion state as success respectively execute respective corresponding reversal methods to complete synchronous reversal operation, thereby ensuring the consistency of the microservice transaction.
After an exception occurs in the link, the service needs to perform a forward conflict operation on the previously submitted operation, and a forward conflict task is constructed for the completed (i.e., end submitted) transaction in the link in the reverse direction according to the acquired request data and the recorded transaction completion state. According to the rule of the local transaction interception record, if the local transaction is normally ended, the record is in an end state. It should be noted that, according to the rule of intercepting and recording the transaction completion status in the past, all the transactions recorded with the end status must be normally completed and submitted with the local transaction; and if the transaction does not have a normal end, the execution must throw an exception, so that the transaction management inside the service is triggered to control the roll-back of the submitted local transaction, and the state of the local transaction is recorded as failed in the interceptor.
Optionally, after the service with the transaction completion status as successful is called, so that the service with the transaction completion status as successful synchronously executes the flushing method, the method further includes: receiving a result of synchronous positive execution exception returned by the service with the transaction completion state being successful; and constructing an asynchronous forward flushing task for the service with the transaction completion state being successful, and setting retry time and maximum retry times so as to obtain an asynchronous forward flushing task table. If the synchronous forward flushing fails, the link tracking tool constructs an asynchronous forward flushing task for the service with the synchronous forward flushing failure, and sets retry time and maximum retry times so as to obtain an asynchronous forward flushing task table.
Optionally, constructing an asynchronous forward flushing task for the service whose transaction completion status is successful, so as to obtain an asynchronous forward flushing task table, where the method includes: periodically scanning the asynchronous forward flushing task table through a timing task according to the set retry time and the maximum retry number; and calling a service according to the scanning result so that the service asynchronously executes the punching method. Optionally, after invoking a service according to the scanning result, so that the service asynchronously executes the flushing method, the method further includes: and if the number of times of calling the service reaches the maximum retry number, sending an asynchronous correction execution result to the operation and maintenance personnel. In the embodiment of the invention, if the synchronous forward execution is abnormal, the asynchronous forward execution is automatically switched to, the asynchronous forward execution method is carried out after the asynchronous task is duralized, the time for retrying execution next time and the maximum retrying times are set, the retrying is carried out for a limited number of times, and if the retrying is still unsuccessful, developers need to be informed to intervene through logs and other modes.
The embodiment of the invention can ensure that the previously submitted data is cleared through positive operation after a certain link on a transaction chain has errors, finally the consistency of transaction data is kept, the invention has no sense to developers as much as possible, and the data consistency of business transaction can be ensured only through simple annotation and development specifications.
According to the various embodiments described above, it can be seen that the technical means of the embodiments of the present invention, by retrieving a service whose transaction completion status is successful if there is a service whose transaction completion status is failed, constructing a correction task for the service whose transaction completion status is successful, and calling the service whose transaction completion status is successful, so as to make the service whose transaction completion status is successful execute a correction method, solves the technical problem in the prior art that the transaction consistency cannot be guaranteed. The embodiment of the invention collects the transaction completion state through the link tracking technology and ensures the final consistency of data after the abnormal service processing through the transaction compensation mechanism.
Moreover, the embodiment of the invention also has the following advantages:
1) the business development is noninductive, the development is noninductive through the modes of presetting a base class, adding an interceptor to record the transaction completion state and automatically initiating the reversal in an abnormal mode, and the consistency of data can be realized only by setting a reversal method for the transaction related to data operation according to the specification;
2) based on a link data acquisition mode, intercepting and recording the completion state of the transaction after the local transaction processing is finished in an interceptor mode;
3) for the service request which needs to be flushed after the execution failure, the task can be automatically persisted after the synchronous flushing failure, and the asynchronous flushing mode is converted, so that the normal execution of the flushing task is ensured as much as possible.
4) After the execution failure of the correction task reaches the maximum retry number, the operation and maintenance personnel are informed of intervention in the forms of logs and the like, so that the operation and maintenance pressure and the labor cost are reduced.
Fig. 2 is a schematic diagram of a main flow of a method for processing a service request according to a referential embodiment of the present invention. As another embodiment of the present invention, as shown in fig. 2, the method for processing a service request may include:
the service A receives the service request, executes the service code of the service A and then calls the service B;
the service B executes a self service code, intercepts request data and a transaction completion state, stores the request data into a cache, returns a processing result to the service A and reports the transaction completion state to a link tracking tool Zipkin;
the service A continuously calls the service D, the service D executes the self service code and calls the service E;
the service E executes the service code of the service E, intercepts request data and a transaction completion state, stores the request data into a cache, returns a processing result to the service D, and reports the transaction completion state to the link tracking tool Zipkin;
d, performing exception on service, intercepting request data and a transaction completion state, storing the request data into a cache, returning exception to the A service, and reporting the transaction completion state to a link tracking tool Zipkin;
a, when the service is abnormal in calling, triggering local transaction management, and executing rollback operation on the submitted transaction;
the link tracking tool Zipkin retrieves services with transaction completion states of end, such as a B service and an E service, then acquires request data corresponding to the B service and the E service from a cache, and constructs positive flushing tasks for the B service and the E service respectively, and calls the B service and the E service so that the B service and the E service respectively execute respective positive flushing methods.
In addition, in a reference embodiment of the present invention, the detailed implementation content of the method for processing a service request is already described in detail in the above-mentioned method for processing a service request, so that the repeated content is not described again.
Fig. 3 is a schematic diagram of a main flow of a method of processing a service request according to another referential embodiment of the present invention. As another embodiment of the present invention, as shown in fig. 3, the method for processing a service request is applied to a link tracing tool, and may include:
step 301, receiving a transaction completion status uploaded by each service, wherein the transaction completion status includes success and failure.
Step 302, if there is a service whose transaction completion status is failure in each service, retrieving a service whose transaction completion status is success from each service.
Step 303, obtaining the request data corresponding to the service whose transaction completion status is successful from the cache.
And step 304, constructing a synchronous alignment task for the service with the transaction completion state as success according to the request data corresponding to the service with the transaction completion state as success.
Step 305, calling the service with the transaction completion status as successful so that the service with the transaction completion status as successful synchronously executes the flushing method.
Step 306, receiving the result of the synchronization positive execution exception returned by the service whose transaction completion status is successful.
Step 307, constructing an asynchronous forward flushing task for the service whose transaction completion state is successful, and setting retry time and maximum retry times, thereby obtaining an asynchronous forward flushing task table.
And step 308, periodically scanning the asynchronous flushing task table through the timing task according to the set retry time and the maximum retry number.
Step 309, invoking a service according to the scanning result, so that the service asynchronously executes the flushing method.
And step 310, if the number of times of calling the service reaches the maximum retry number, sending an asynchronous correction execution result to the operation and maintenance personnel.
In addition, in another embodiment of the present invention, the detailed implementation of the method for processing a service request is described in detail in the above-mentioned method for processing a service request, and therefore the repeated content is not described again.
Fig. 4 is a schematic diagram of main modules of an apparatus for processing a service request according to an embodiment of the present invention. As shown in fig. 4, the apparatus 400 for processing a service request includes a receiving module 401, a retrieving module 402, and a calling module 403; the receiving module 401 is configured to receive a transaction completion status uploaded by each service, where the transaction completion status includes success and failure; the retrieving module 402 is configured to retrieve, if there is a service in which the transaction completion status is a failure in each service, a service in which the transaction completion status is a success from each service; the invoking module 403 is configured to construct a correction task for the service whose transaction completion status is successful, and invoke the service whose transaction completion status is successful, so as to implement a correction method for the service whose transaction completion status is successful.
Optionally, the invoking module 403 is further configured to:
and according to the sequence of the received transaction completion states of the services with the successful transaction completion states, calling the services with the successful transaction completion states in a reverse sequence in order to enable the services with the successful transaction completion states to sequentially execute a flushing method.
Optionally, each service intercepts request data and a transaction completion status, and stores the request data in a cache.
Optionally, the request data includes a global serial number and service data parsed by the service from the received service request.
Optionally, in each service, a base class of a control layer receiving the service request is defined, and a forward service processing method and a reverse flushing method are defined in the base class.
Optionally, the invoking module 403 is further configured to:
obtaining request data corresponding to the service with the transaction completion state being successful from a cache;
and constructing a correction task for the service with the transaction completion state as success according to the request data corresponding to the service with the transaction completion state as success.
Optionally, the invoking module 403 is further configured to:
and constructing a synchronous positive flushing task for the service with the transaction completion state as success, and calling the service with the transaction completion state as success so as to synchronously execute a positive flushing method for the service with the transaction completion state as success.
Optionally, the invoking module 403 is further configured to:
calling the service with the transaction completion state as success so as to receive a result of abnormal synchronous forward execution returned by the service with the transaction completion state as success after the service synchronous execution forward method with the transaction completion state as success;
and constructing an asynchronous forward flushing task for the service with the transaction completion state being successful, and setting retry time and maximum retry times so as to obtain an asynchronous forward flushing task table.
Optionally, the invoking module 403 is further configured to:
constructing an asynchronous forward flushing task for the service with the transaction completion state being successful, and periodically scanning the asynchronous forward flushing task table through a timing task according to the set retry time and the maximum retry number after obtaining the asynchronous forward flushing task table;
and calling a service according to the scanning result so that the service asynchronously executes the punching method.
Optionally, the invoking module 403 is further configured to:
and calling the service according to the scanning result so that after the service asynchronously executes the correction method, if the number of times of calling the service reaches the maximum retry number, the asynchronous correction execution result is sent to the operation and maintenance personnel.
Optionally, each service includes a service invoker and a service provider;
the service caller calls the service provider according to the received service request;
if the service provider fails to execute, triggering rollback, and returning an execution abnormal result to the service caller;
and the service caller receives the result of the abnormal execution of the service provider and triggers rollback.
According to the various embodiments described above, it can be seen that the technical means of the embodiments of the present invention, by retrieving a service whose transaction completion status is successful if there is a service whose transaction completion status is failed, constructing a correction task for the service whose transaction completion status is successful, and calling the service whose transaction completion status is successful, so as to make the service whose transaction completion status is successful execute a correction method, solves the technical problem in the prior art that the transaction consistency cannot be guaranteed. The embodiment of the invention collects the transaction completion state through the link tracking technology and ensures the final consistency of data after the abnormal service processing through the transaction compensation mechanism.
It should be noted that, in the implementation of the apparatus for processing a service request according to the present invention, the details of the method for processing a service request are already described in detail, and therefore, the repeated contents are not described again here.
Fig. 5 illustrates an exemplary system architecture 500 of a method of processing a service request or an apparatus for processing a service request to which embodiments of the present invention may be applied.
As shown in fig. 5, the system architecture 500 may include terminal devices 501, 502, 503, a network 504, and a server 505. The network 504 serves to provide a medium for communication links between the terminal devices 501, 502, 503 and the server 505. Network 504 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
The user may use the terminal devices 501, 502, 503 to interact with a server 505 over a network 504 to receive or send messages or the like. The terminal devices 501, 502, 503 may have installed thereon various communication client applications, such as shopping-like applications, web browser applications, search-like applications, instant messaging tools, mailbox clients, social platform software, etc. (by way of example only).
The terminal devices 501, 502, 503 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 505 may be a server providing various services, such as a background management server (for example only) providing support for shopping websites browsed by users using the terminal devices 501, 502, 503. The background management server can analyze and process the received data such as the article information query request and feed back the processing result to the terminal equipment.
It should be noted that the method for processing the service request provided by the embodiment of the present invention is generally executed by the server 505, and accordingly, the apparatus for processing the service request is generally disposed in the server 505.
It should be understood that the number of terminal devices, networks, and servers in fig. 5 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 6, a block diagram of a computer system 600 suitable for use with a terminal device implementing an embodiment of the invention is shown. The terminal device shown in fig. 6 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present invention.
As shown in fig. 6, the computer system 600 includes a Central Processing Unit (CPU)601 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)602 or a program loaded from a storage section 608 into a Random Access Memory (RAM) 603. In the RAM603, various programs and data necessary for the operation of the system 600 are also stored. The CPU 601, ROM 602, and RAM603 are connected to each other via a bus 604. An input/output (I/O) interface 605 is also connected to bus 604.
The following components are connected to the I/O interface 605: an input portion 606 including a keyboard, a mouse, and the like; an output portion 607 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage section 608 including a hard disk and the like; and a communication section 609 including a network interface card such as a LAN card, a modem, or the like. The communication section 609 performs communication processing via a network such as the internet. The driver 610 is also connected to the I/O interface 605 as needed. A removable medium 611 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 610 as necessary, so that a computer program read out therefrom is mounted in the storage section 608 as necessary.
In particular, according to the embodiments of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 609, and/or installed from the removable medium 611. The computer program performs the above-described functions defined in the system of the present invention when executed by the Central Processing Unit (CPU) 601.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present invention, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer programs according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules described in the embodiments of the present invention may be implemented by software or hardware. The described modules may also be provided in a processor, which may be described as: a processor includes a receiving module, a retrieving module, and a calling module, where the names of the modules do not in some cases constitute a limitation on the module itself.
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, implement the method of: receiving transaction completion states uploaded by each service, wherein the transaction completion states comprise success and failure; if the service with the transaction completion state as failure exists in each service, retrieving the service with the transaction completion state as success from each service; and constructing a correction task for the service with the transaction completion state being successful, and calling the service with the transaction completion state being successful so as to enable the service with the transaction completion state being successful to execute a correction method.
According to the technical scheme of the embodiment of the invention, the technical means that if the service with the transaction completion state as failure exists, the service with the transaction completion state as success is retrieved, the correction task is constructed for the service with the transaction completion state as success, and the service with the transaction completion state as success is called to enable the service with the transaction completion state as success to execute the correction method is adopted, so that the technical problem that the transaction consistency can not be ensured in the prior art is solved. The embodiment of the invention collects the transaction completion state through the link tracking technology and ensures the final consistency of data after the abnormal service processing through the transaction compensation mechanism.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (16)

1. A method for processing a service request, comprising:
receiving transaction completion states uploaded by each service, wherein the transaction completion states comprise success and failure;
if the service with the transaction completion state as failure exists in each service, retrieving the service with the transaction completion state as success from each service;
and constructing a correction task for the service with the transaction completion state being successful, and calling the service with the transaction completion state being successful so as to enable the service with the transaction completion state being successful to execute a correction method.
2. The method of claim 1, wherein invoking the service whose transaction completion status is successful so that the service whose transaction completion status is successful performs a method of flushing, comprises:
and according to the sequence of the received transaction completion states of the services with the successful transaction completion states, calling the services with the successful transaction completion states in a reverse sequence in order to enable the services with the successful transaction completion states to sequentially execute a flushing method.
3. The method of claim 1, wherein each service is configured to store request data to a cache by intercepting the request data and a transaction completion status.
4. The method of claim 3, wherein the request data comprises a global serial number and traffic data parsed by the service from the received traffic request.
5. The method according to claim 1, wherein in each service, a base class of a control layer receiving a service request is defined, and a forward service processing method and a reverse flush method are defined in the base class.
6. The method of claim 3, wherein constructing a flushing task for the service for which the transaction completion status is successful comprises:
obtaining request data corresponding to the service with the transaction completion state being successful from a cache;
and constructing a correction task for the service with the transaction completion state as success according to the request data corresponding to the service with the transaction completion state as success.
7. The method of claim 6, wherein constructing a flushing task for the service whose transaction completion status is successful, invoking the service whose transaction completion status is successful, and making the service whose transaction completion status is successful execute a flushing method, comprises:
and constructing a synchronous positive flushing task for the service with the transaction completion state as success, and calling the service with the transaction completion state as success so as to synchronously execute a positive flushing method for the service with the transaction completion state as success.
8. The method of claim 7, wherein after invoking the service with the transaction completion status as successful so that the service with the transaction completion status as successful synchronously executes the flushing method, further comprising:
receiving a result of synchronous positive execution exception returned by the service with the transaction completion state being successful;
and constructing an asynchronous forward flushing task for the service with the transaction completion state being successful, and setting retry time and maximum retry times so as to obtain an asynchronous forward flushing task table.
9. The method of claim 8, wherein after constructing the asynchronous flushing task for the service whose transaction completion status is successful, thereby obtaining the asynchronous flushing task table, the method comprises:
periodically scanning the asynchronous forward flushing task table through a timing task according to the set retry time and the maximum retry number;
and calling a service according to the scanning result so that the service asynchronously executes the punching method.
10. The method of claim 9, wherein after invoking a service according to the scanning result to make the service asynchronously execute the flushing method, further comprising:
and if the number of times of calling the service reaches the maximum retry number, sending an asynchronous correction execution result to the operation and maintenance personnel.
11. The method of claim 1, wherein each service comprises a service invoker and a service provider;
the service caller calls the service provider according to the received service request;
if the service provider fails to execute, triggering rollback, and returning an execution abnormal result to the service caller;
and the service caller receives the result of the abnormal execution of the service provider and triggers rollback.
12. An apparatus for processing a service request, comprising:
the receiving module is used for receiving transaction completion states uploaded by each service, wherein the transaction completion states comprise success and failure;
the retrieval module is used for retrieving the service with the transaction completion state as success from each service if the service with the transaction completion state as failure exists in each service;
and the calling module is used for constructing a correction task for the service with the transaction completion state as success, and calling the service with the transaction completion state as success so as to enable the service with the transaction completion state as success to execute a correction method.
13. The apparatus of claim 12, wherein the invoking module is further configured to:
and according to the sequence of the received transaction completion states of the services with the successful transaction completion states, calling the services with the successful transaction completion states in a reverse sequence in order to enable the services with the successful transaction completion states to sequentially execute a flushing method.
14. The apparatus of claim 12, wherein each service is configured to store request data in a cache by intercepting the request data and a transaction completion status;
the calling module is further configured to:
obtaining request data corresponding to the service with the transaction completion state being successful from a cache;
and constructing a correction task for the service with the transaction completion state as success according to the request data corresponding to the service with the transaction completion state as success.
15. An electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
the one or more programs, when executed by the one or more processors, implement the method of any of claims 1-11.
16. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-11.
CN202011302418.XA 2020-11-19 2020-11-19 Method and device for processing service request Pending CN112417042A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011302418.XA CN112417042A (en) 2020-11-19 2020-11-19 Method and device for processing service request

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011302418.XA CN112417042A (en) 2020-11-19 2020-11-19 Method and device for processing service request

Publications (1)

Publication Number Publication Date
CN112417042A true CN112417042A (en) 2021-02-26

Family

ID=74774580

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011302418.XA Pending CN112417042A (en) 2020-11-19 2020-11-19 Method and device for processing service request

Country Status (1)

Country Link
CN (1) CN112417042A (en)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113051043A (en) * 2021-03-10 2021-06-29 北京沃东天骏信息技术有限公司 Micro-service anomaly compensation method and device
CN113111077A (en) * 2021-04-16 2021-07-13 中国工商银行股份有限公司 Consistency control method, consistency control device, electronic equipment, consistency control medium and program product
CN113486033A (en) * 2021-07-02 2021-10-08 中国建设银行股份有限公司 Method, apparatus, device and computer readable medium for controlling transaction consistency
CN113592655A (en) * 2021-08-13 2021-11-02 中国建设银行股份有限公司 Transaction processing method and device, electronic equipment and computer readable medium
CN113627890A (en) * 2021-08-12 2021-11-09 神州数码融信软件有限公司 Method for monitoring and processing abnormal flow in automatic approval flow

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20170097847A1 (en) * 2015-10-05 2017-04-06 International Business Machines Corporation Client controlled transaction processing involving a plurality of participants
CN108038141A (en) * 2017-11-27 2018-05-15 国云科技股份有限公司 Ensure the method for data consistency under micro services framework HTTP interactive modes
WO2018103318A1 (en) * 2016-12-06 2018-06-14 上海壹账通金融科技有限公司 Distributed transaction handling method and system
US20200021505A1 (en) * 2018-07-11 2020-01-16 Sony Interactive Entertainment LLC Tracking Application Utilization of Microservices
CN111277639A (en) * 2020-01-16 2020-06-12 中国建设银行股份有限公司 Method and device for maintaining data consistency
CN111626858A (en) * 2020-05-28 2020-09-04 北京金山云网络技术有限公司 Processing method and device for transaction, electronic equipment and computer readable medium

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20170097847A1 (en) * 2015-10-05 2017-04-06 International Business Machines Corporation Client controlled transaction processing involving a plurality of participants
WO2018103318A1 (en) * 2016-12-06 2018-06-14 上海壹账通金融科技有限公司 Distributed transaction handling method and system
CN108038141A (en) * 2017-11-27 2018-05-15 国云科技股份有限公司 Ensure the method for data consistency under micro services framework HTTP interactive modes
US20200021505A1 (en) * 2018-07-11 2020-01-16 Sony Interactive Entertainment LLC Tracking Application Utilization of Microservices
CN111277639A (en) * 2020-01-16 2020-06-12 中国建设银行股份有限公司 Method and device for maintaining data consistency
CN111626858A (en) * 2020-05-28 2020-09-04 北京金山云网络技术有限公司 Processing method and device for transaction, electronic equipment and computer readable medium

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113051043A (en) * 2021-03-10 2021-06-29 北京沃东天骏信息技术有限公司 Micro-service anomaly compensation method and device
CN113111077A (en) * 2021-04-16 2021-07-13 中国工商银行股份有限公司 Consistency control method, consistency control device, electronic equipment, consistency control medium and program product
CN113486033A (en) * 2021-07-02 2021-10-08 中国建设银行股份有限公司 Method, apparatus, device and computer readable medium for controlling transaction consistency
CN113627890A (en) * 2021-08-12 2021-11-09 神州数码融信软件有限公司 Method for monitoring and processing abnormal flow in automatic approval flow
CN113627890B (en) * 2021-08-12 2024-04-02 神州数码融信软件有限公司 Method for monitoring and processing abnormal flow in automatic approval flow
CN113592655A (en) * 2021-08-13 2021-11-02 中国建设银行股份有限公司 Transaction processing method and device, electronic equipment and computer readable medium

Similar Documents

Publication Publication Date Title
CN112417042A (en) Method and device for processing service request
CN111277639B (en) Method and device for maintaining data consistency
KR101031929B1 (en) Integration architecture for non-integrated tools
CN110633320A (en) Processing method, system, equipment and storage medium of distributed data service
US7933296B2 (en) Services for data sharing and synchronization
CN111143382B (en) Data processing method, system and computer readable storage medium
US20230014346A1 (en) Indexing data at a data intake and query system based on a node capacity threshold
KR20140047580A (en) Method and system for synchronization mechanism on multi-server reservation system
CN111190888A (en) Method and device for managing graph database cluster
CN111225012A (en) Transaction processing method, device and equipment
US7636873B2 (en) Enhancement of assured event delivery mechanism to eliminate external XA store requirement
US7007088B1 (en) Method and apparatus for providing an E-business audit trail in a distributed computing system
CN111881216A (en) Data acquisition method and device based on shared template
CN114827280A (en) Request processing method, device, equipment and medium
US11539791B1 (en) Methods, apparatuses and computer program products for synchronizing data objects between and among application service systems
CN113190517B (en) Data integration method and device, electronic equipment and computer readable medium
US20050027620A1 (en) Method, system, and computer-readable medium for updating inventory data in an inventory management system
CN111581227A (en) Event pushing method and device, computer equipment and storage medium
CN114090687A (en) Data synchronization method and device
CN114064803A (en) Data synchronization method and device
CN110288309B (en) Data interaction method, device, system, computer equipment and storage medium
CN112948430B (en) Date data query method and device
CN117478535B (en) Log storage method and device
US9336138B2 (en) Method and apparatus for implementing garbage collection within a computing environment
CN114979308B (en) Message processing method and device

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