Transaction data processing method, device and electronic equipment
By using the distributed lock mechanism in the transaction business, the problem of idempotent breakdown in the existing technology is solved, ensuring the uniqueness and rapid response of transaction requests, and simplifying the design of idempotent solutions.
Patent Information
- Application Number
- CN202410930850.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-11
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2044-07-11
AI Technical Summary
The existing idempotent solution for transaction business relies on the unique index of the database primary key, which can easily lead to idempotent breakdown, causing repeated transaction requests to be processed, causing the idempotent function to fail.
A distributed lock mechanism is used to generate distributed locks through transaction interface information and unique identifiers to ensure that only one request for the same transaction request for the same transaction interface at the same time can obtain the lock, avoiding repeated processing.
It effectively prevents idempotent breakdown of transaction business, ensures that transaction requests for the same transaction interface will not be executed repeatedly, achieves rapid response to different transaction interfaces, and simplifies the design of idempotent solutions, allowing a unified idempotent solution for transaction interfaces.
Smart Images

Figure CN118469714B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of interface idempotence, and in particular to a transaction data processing method, device and electronic device. Background Art
[0002] When executing transactions, in order to ensure the stability and reliability of transactions, it is necessary to control the idempotency of transactions to prevent duplicate transactions. Currently, the idempotency solution of transaction business relies on the unique index of the database primary key, which is prone to idempotency breakdown. Summary of the invention
[0003] In view of this, embodiments of the present application provide a transaction data processing method, device, and electronic device.
[0004] According to the first aspect of the present application, an embodiment of the present application provides a transaction data processing method, including:
[0005] Multiple transaction requests are obtained, and the transaction requests include transaction interface information and a unique identifier of the transaction;
[0006] If the first response result corresponding to the multiple transaction requests does not exist in the database based on the unique identifier, a distributed lock is generated based on the transaction interface information and the unique identifier; the first response result indicates that the transaction has been completed;
[0007] Based on the transaction interface information and unique identifier, the distributed lock is allocated to multiple transaction requests;
[0008] For each transaction request, if the transaction request is assigned to a distributed lock, respond to the transaction request, perform corresponding transaction business logic processing, obtain a second response result, and save the second response result to the database.
[0009] Optionally, based on the transaction interface information and the unique identifier, a distributed lock is allocated to multiple transaction requests, including:
[0010] Based on the transaction interface information and the unique identifier, determining a first target transaction request having the same transaction interface information and the same unique identifier, and a second target transaction request having different transaction interface information and different unique identifiers among the multiple transaction requests;
[0011] Allocating a distributed lock corresponding to the first target transaction request to one of the plurality of first target transaction requests;
[0012] The distributed lock corresponding to the second target transaction request is allocated to the second target transaction request.
[0013] Optionally, after saving the second response result to the database, the transaction data processing method further includes:
[0014] Release the distributed lock.
[0015] Optionally, the transaction data processing method further includes:
[0016] If the transaction request is not assigned to a distributed lock, query the first state information of the distributed lock corresponding to the transaction request;
[0017] If the first state information indicates that the distributed lock has been released, a third response result corresponding to the transaction request is searched from the database based on the unique identifier.
[0018] Optionally, the transaction data processing method further includes:
[0019] If the first status information indicates that the distributed lock has timed out, first prompt information is returned to the client that sent the transaction request, and the first prompt information indicates that the transaction request is being executed.
[0020] Optionally, after saving the second response result to the database, the transaction data processing method further includes:
[0021] The second response result is returned to the client that sent the transaction request.
[0022] Optionally, after obtaining multiple transaction requests, the transaction data processing method further includes:
[0023] If a first target transaction request having the same transaction interface information and the same unique identifier is determined among the multiple transaction requests based on the transaction interface information and the unique identifier, then based on the unique identifier of the first target transaction request, querying a database according to a preset period whether there is a first response result corresponding to the first target transaction request;
[0024] If the first response result corresponding to the first target transaction request is not found in the database within the preset number of times, a second prompt message is returned to the client that sent the first target transaction request, and the second prompt message indicates that the first target transaction request is being executed and cannot be executed repeatedly.
[0025] Optionally, after obtaining multiple transaction requests, the transaction data processing method further includes:
[0026] Obtain second state information of the distributed lock forming module;
[0027] If the second state information indicates that the distributed lock forming module is in a normal working state, if the first response result corresponding to the multiple transaction requests is not confirmed in the database based on the unique identifier, a distributed lock is generated based on the transaction interface information and the unique identifier;
[0028] If the second status information indicates that the distributed lock forming module is in a non-working state, execute if the first response result corresponding to the multiple transaction requests does not exist in the database based on the unique identifier, respond to each transaction request, perform corresponding transaction business logic processing, obtain a fourth response result, and save the fourth response result to the database.
[0029] According to the second aspect of the present application, an embodiment of the present application provides a transaction data processing device, including:
[0030] The acquisition module is used to acquire multiple transaction requests, where the transaction requests include transaction interface information and a unique identifier of the transaction;
[0031] A generating module, configured to generate a distributed lock based on the transaction interface information and the unique identifier if the first response result corresponding to the multiple transaction requests does not exist in the database based on the unique identifier; the first response result indicates that the transaction has been completed;
[0032] An allocation module, used to allocate distributed locks to multiple transaction requests based on transaction interface information and unique identifiers;
[0033] The processing module is used to respond to each transaction request, if the transaction request is assigned to a distributed lock, perform corresponding transaction business logic processing, obtain a second response result, and save the second response result to a database.
[0034] According to a third aspect of the present application, an embodiment of the present application provides an electronic device, including:
[0035] At least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor executes the transaction data processing method as described in the first aspect or any embodiment of the first aspect.
[0036] The transaction data processing method, device and electronic device provided in the embodiments of the present application can ensure that at the same time, only one transaction request among the same transaction requests of the same transaction interface can obtain a distributed lock and execute the corresponding transaction business logic processing, thereby ensuring that the same transaction business of the same transaction interface will not be executed repeatedly and there will be no transaction business idempotence breakdown; and different transaction requests of different transaction interfaces can obtain distributed locks at the same time and perform transaction business processing at the same time, thereby achieving rapid response to different transaction businesses of different transaction interfaces; and, the present application generates a distributed lock based on the transaction interface information and the unique identifier, and allocates the distributed lock to multiple transaction requests based on the transaction interface information and the unique identifier; therefore, when designing idempotence schemes for different transaction interfaces, it is no longer necessary to consider the differences in transaction interfaces, and it is no longer necessary to design idempotence schemes separately. A unified transaction interface idempotence scheme can be adopted to achieve rapid access to idempotence schemes for different transaction interfaces.
[0037] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 A flowchart of a transaction data processing method in an embodiment of the present application;
[0039] Figure 2 A flowchart of another transaction data processing method in an embodiment of the present application;
[0040] Figure 3 A flowchart of another transaction data processing method in an embodiment of the present application;
[0041] Figure 4 This is a structural diagram of a transaction data processing device in an embodiment of the present application;
[0042] Figure 5 This is a schematic diagram of the hardware structure of an electronic device in an embodiment of the present application. DETAILED DESCRIPTION
[0043] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present application.
[0044] In the related art, the idempotent solution of the transaction business relies on the unique index of the database primary key, which easily leads to idempotent breakdown. The inventor of the present application analyzed the idempotent solution of the transaction business in the related art and found that since the response result can only be stored in the database after the transaction business logic processing of the transaction request is completed, during the period of time when the transaction request is processed by the transaction business logic, the response result cannot be queried from the database for the received repeated transaction request, so that the repeated transaction request will be sent to the transaction business logic processing system, resulting in the transaction business logic processing system receiving the repeated transaction request, executing the transaction business logic processing on the repeated transaction request, resulting in the failure of the idempotent function. Therefore, the inventor of the present application modified the idempotent solution of the transaction business in combination with the distributed lock to solve the problem of idempotent breakdown of the transaction business.
[0045] The present application embodiment provides a transaction data processing method, such as Figure 1 As shown, including:
[0046] S101, multiple transaction requests are obtained, where the transaction requests include transaction interface information and a unique identifier of the transaction.
[0047] In this embodiment, the multiple transaction requests may include the same transaction request or different transaction requests. The transaction interface information includes the interface required to be called when processing the transaction request. The unique identifier of the transaction may be the transaction serial number, the identity information of the transaction initiator, etc.
[0048] In some embodiments, after obtaining multiple transaction requests, it can be determined whether there is an identical transaction request among the multiple transaction requests. If there is an identical transaction request, a preset waiting strategy is executed.
[0049] In one implementation, if a first target transaction request with the same transaction interface information and the same unique identifier is determined among multiple transaction requests based on the transaction interface information and the unique identifier, then based on the unique identifier of the first target transaction request, a query is made in the database according to a preset period to see whether there is a first response result corresponding to the first target transaction request; if the first response result corresponding to the first target transaction request is not found from the database within the preset number of times, a second prompt message is returned to the client that sent the first target transaction request, and the second prompt message indicates that the first target transaction request is being executed and cannot be executed repeatedly. For example, the database is queried once every n milliseconds and polled m times. If the first response result is found, the loop is stopped and each repeated first target transaction request is responded to normally. If no response result is found, "the current interface has been idempotently processed and is being executed and cannot be executed repeatedly" is returned for each repeated first target transaction request. In this way, each repeated first target transaction request can receive a prompt message.
[0050] In one implementation, if a first target transaction request with the same transaction interface information and the same unique identifier is determined among multiple transaction requests based on the transaction interface information and the unique identifier, then a message "the current interface has been idempotently processed and is being executed and cannot be executed repeatedly" is returned once for the repeated first target transaction request.
[0051] S102, if it is confirmed based on the unique identifier that there is no first response result corresponding to the multiple transaction requests in the database, a distributed lock is generated based on the transaction interface information and the unique identifier; the first response result indicates that the transaction has been completed.
[0052] In this embodiment, the first response result corresponding to the transaction request is queried from the database based on the unique identifier in the transaction request.
[0053] In this embodiment, the implementation of the distributed lock may include using a distributed lock using a Redis database.
[0054] In this embodiment, if it is confirmed that there is no first response result corresponding to multiple transaction requests in the database, a distributed lock can be generated based on the transaction interface information and the unique identifier. In this way, only one distributed lock can be generated for the same transaction interface information and unique identifier.
[0055] In some implementations, generating a distributed lock based on the transaction interface information and the unique identifier includes: generating a distributed lock using the transaction interface information and the unique identifier as unique keys.
[0056] S103, allocating distributed locks to multiple transaction requests based on the transaction interface information and the unique identifier.
[0057] In this embodiment, since the basic principle of the distributed lock is to introduce mutual exclusivity in the access to shared resources to ensure that only one process or thread can hold the lock at the same time, when the distributed lock is allocated to multiple transaction requests based on the transaction interface information and the unique identifier, only one transaction request among the same transaction requests can be allocated to the distributed lock, and different transaction requests can be allocated to the distributed lock.
[0058] S104, for each transaction request, if the transaction request is assigned to a distributed lock, respond to the transaction request, perform corresponding transaction business logic processing, obtain a second response result, and save the second response result to the database.
[0059] After the distributed lock is assigned to multiple transaction requests, it can be determined whether each transaction request is assigned to the distributed lock. If it is assigned to the distributed lock, the transaction request is responded to, the corresponding transaction business logic processing is performed, and a second response result is obtained. The second response result can be saved in the database with the unique identifier as the keyword.
[0060] In some embodiments, after the second response result is saved in the database, the transaction data processing method further includes: releasing the distributed lock, so that the storage space for storing the distributed lock can be released.
[0061] In some embodiments, after the second response result is saved in the database, the transaction data processing method further includes: returning the second response result to the client that sent the transaction request. In this way, the client that sent the transaction request can receive the second response result in a timely manner, so that the user can obtain the processing result of the transaction business in a timely manner.
[0062] The transaction data processing method provided in the embodiment of the present application can ensure that at the same time, only one transaction request among the same transaction requests of the same transaction interface can obtain a distributed lock and execute the corresponding transaction business logic processing, thereby ensuring that the same transaction business of the same transaction interface will not be executed repeatedly, and there will be no transaction business idempotence breakdown; and different transaction requests of different transaction interfaces can obtain distributed locks at the same time, and perform transaction business processing at the same time, thereby achieving rapid response to different transaction businesses of different transaction interfaces; and, the present application generates a distributed lock based on the transaction interface information and the unique identifier, and allocates the distributed lock to multiple transaction requests based on the transaction interface information and the unique identifier; therefore, when designing idempotence schemes for different transaction interfaces, it is no longer necessary to consider the differences in transaction interfaces, and it is no longer necessary to design idempotence schemes separately. A unified transaction interface idempotence scheme can be adopted to achieve rapid access to idempotence schemes for different transaction interfaces.
[0063] In an optional embodiment, step S103, based on the transaction interface information and the unique identifier, the distributed lock is allocated to multiple transaction requests, such as Figure 2 As shown, including:
[0064] S1031, based on the transaction interface information and the unique identifier, determining a first target transaction request having the same transaction interface information and the same unique identifier, and a second target transaction request having different transaction interface information and different unique identifiers among the multiple transaction requests.
[0065] S1032: Allocate a distributed lock corresponding to the first target transaction request to one of the multiple first target transaction requests.
[0066] S1033: Allocate the distributed lock corresponding to the second target transaction request to the second target transaction request.
[0067] In one implementation, when a distributed lock corresponding to a first target transaction request is received, the distributed lock corresponding to the first target transaction request may be allocated to the first received first target transaction request.
[0068] In this embodiment, firstly, the first target transaction request with the same transaction interface information and the same unique identifier and the second target transaction request with different transaction interface information and different unique identifier are determined through the transaction interface information and the unique identifier, so that the distributed lock can be quickly allocated.
[0069] In an optional embodiment, the transaction data processing method further includes:
[0070] If the transaction request is not assigned to a distributed lock, query the first state information of the distributed lock corresponding to the transaction request; if the first state information indicates that the distributed lock has been released, search the database for a third response result corresponding to the transaction request based on the unique identifier.
[0071] In this embodiment, for repeated transaction requests, no distributed lock will be allocated. For transaction requests that are not allocated distributed locks, the first state information of the distributed lock corresponding to the transaction request can be queried. The distributed lock corresponding to the transaction request is the transaction interface information corresponding to the transaction request and the distributed lock corresponding to the unique identifier.
[0072] Specifically, the first state information of the distributed lock can be determined by polling the key value (key value) of the distributed lock. If the key value of the distributed lock can be found, the distributed lock has not been released. If the key value of the distributed lock cannot be found, the distributed lock has been released. If the distributed lock has been released, the third response result corresponding to the transaction request can be found from the database based on the unique identifier.
[0073] When implementing it, Figure 3 As shown, after obtaining multiple transaction requests (external requests), you can query whether there are first response results corresponding to multiple transaction requests in the database. If there is a first response result, respond to the outside, for example, return the first response information to the client that sent the transaction request. If there is no first response result, generate a distributed lock based on the transaction interface information and the unique identifier, such as redis distributed lock (redis-tryLock), and assign the distributed lock to multiple transaction requests based on the transaction interface information and the unique identifier. For each transaction request, determine whether the transaction request is successfully assigned to the distributed lock. If the transaction request is assigned to the distributed lock, respond to the transaction request, perform the corresponding transaction business logic processing, obtain the second response result, and save the second response result to the database. Then release the distributed lock, such as redis distributed lock release (redis-unLock).
[0074] If the transaction request is not assigned to a distributed lock, the key value of the distributed lock is searched in rounds. If the key value of the distributed lock cannot be found, the third response result corresponding to the transaction request can be searched from the database based on the unique identifier. The third response result can be the same as the second response result.
[0075] In this embodiment, for transaction requests that are not assigned to a distributed lock, the first status information of the distributed lock corresponding to the transaction request is queried in real time, and when the distributed lock corresponding to the transaction request has been released, the third response result corresponding to the transaction request is searched from the database based on the unique identifier. In this way, each repeated transaction request can be responded to in a timely manner, and the response result is the same.
[0076] In an optional embodiment, the transaction data processing method further includes:
[0077] If the first status information indicates that the distributed lock has timed out, first prompt information is returned to the client that sent the transaction request, and the first prompt information indicates that the transaction request is being executed.
[0078] In this embodiment, when querying whether the distributed lock has been released, a timeout period can also be set. If the distributed lock is locked for more than a certain period of time, the first prompt information is returned to the client that sent the transaction request to prevent the user from initiating a transaction request again.
[0079] When implementing it, Figure 3 As shown, when polling to find the key value of the distributed lock, if a timeout occurs, the first prompt message "in execution" is returned to the client that sends the transaction request.
[0080] In an optional embodiment, after obtaining multiple transaction requests, the transaction data processing method further includes:
[0081] Obtain second state information of the distributed lock forming module; if the second state information indicates that the distributed lock forming module is in a normal working state, execute if the first response result corresponding to the multiple transaction requests does not exist in the database based on the unique identifier, and generate a distributed lock based on the transaction interface information and the unique identifier; if the second state information indicates that the distributed lock forming module is in a non-working state, execute if the first response result corresponding to the multiple transaction requests does not exist in the database based on the unique identifier, respond to each transaction request, perform corresponding transaction business logic processing, obtain a fourth response result, and save the fourth response result to the database.
[0082] In this embodiment, the distributed lock formation module is used to generate a distributed lock. Since the idempotent transformation scheme of the transaction business involves many transaction interfaces, has a wide impact range, and is strongly dependent on the distributed lock formation module, it is necessary to consider a fallback strategy when the distributed lock formation module is unavailable to ensure idempotency. To this end, a bypass design is carried out to handle the situation where the distributed lock formation module is unavailable, ensuring that the old idempotent scheme can be used through the bypass design when the distributed lock formation module is unavailable, so as to ensure that the interface idempotent function is always available.
[0083] The present application also provides a transaction data processing device, such as Figure 4 As shown, including:
[0084] The acquisition module 41 is used to acquire multiple transaction requests, where the transaction requests include transaction interface information and a unique identifier of the transaction;
[0085] A generating module 42 is used to generate a distributed lock based on the transaction interface information and the unique identifier if the first response result corresponding to the multiple transaction requests does not exist in the database based on the unique identifier; the first response result indicates that the transaction has been completed;
[0086] An allocation module 43, configured to allocate a distributed lock to multiple transaction requests based on the transaction interface information and the unique identifier;
[0087] The processing module 44 is used for responding to each transaction request, if the transaction request is assigned to a distributed lock, performing corresponding transaction business logic processing, obtaining a second response result, and saving the second response result to a database.
[0088] The transaction data processing device provided by the embodiment of the present application can ensure that at the same time, only one transaction request among the same transaction requests of the same transaction interface can obtain a distributed lock and execute the corresponding transaction business logic processing, thereby ensuring that the same transaction business of the same transaction interface will not be executed repeatedly and there will be no transaction business idempotence breakdown; and different transaction requests of different transaction interfaces can obtain distributed locks at the same time and perform transaction business processing at the same time, thereby achieving rapid response to different transaction businesses of different transaction interfaces; and, the present application generates a distributed lock based on the transaction interface information and the unique identifier, and allocates the distributed lock to multiple transaction requests based on the transaction interface information and the unique identifier; therefore, when designing idempotence schemes for different transaction interfaces, it is no longer necessary to consider the differences in transaction interfaces, and it is no longer necessary to design idempotence schemes separately. A unified transaction interface idempotence scheme can be adopted to achieve rapid access to idempotence schemes for different transaction interfaces.
[0089] According to an embodiment of the present application, the present application also provides an electronic device and a readable storage medium.
[0090] Figure 5 A schematic block diagram of an example electronic device 800 that can be used to implement an embodiment of the present application is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workbenches, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present application described and / or required herein.
[0091] like Figure 5 As shown, the electronic device 800 includes a computing unit 801, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 802 or a computer program loaded from a storage unit 808 to a random access memory (RAM) 803. In the RAM 803, various programs and data required for the operation of the electronic device 800 can also be stored. The computing unit 801, the ROM 802, and the RAM 803 are connected to each other via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.
[0092] Multiple components in the electronic device 800 are connected to the I / O interface 805, including: an input unit 806, such as a keyboard, a mouse, etc.; an output unit 807, such as various types of displays, speakers, etc.; a storage unit 808, such as a disk, an optical disk, etc.; and a communication unit 809, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 809 allows the electronic device 800 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0093] The computing unit 801 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 801 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 801 performs the various methods and processes described above, such as the transaction data processing method. For example, in some embodiments, the transaction data processing method may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 808. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 800 via the ROM 802 and / or the communication unit 809. When the computer program is loaded into the RAM 803 and executed by the computing unit 801, one or more steps of the transaction data processing method described above may be performed. Alternatively, in other embodiments, the computing unit 801 may be configured to perform the transaction data processing method in any other appropriate manner (e.g., by means of firmware).
[0094] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0095] The program code for implementing the method of the present application can be written in any combination of one or more programming languages. These program codes can be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, implements the functions / operations specified in the flow chart and / or block diagram. The program code can be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0096] In the context of the present application, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, 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 disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0097] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0098] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0099] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship with each other. The server may be a cloud server, a server of a distributed system, or a server combined with a blockchain.
[0100] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this application can be executed in parallel, sequentially or in different orders, as long as the expected results of the technical solution disclosed in this application can be achieved, and this document is not limited here.
[0101] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include at least one of the features. In the description of this application, the meaning of "plurality" is two or more, unless otherwise clearly and specifically defined.
[0102] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A transaction data processing method, It is characterized in that include: A plurality of transaction requests are obtained, wherein the transaction requests include transaction interface information and a unique identifier of the transaction; If a first target transaction request having the same transaction interface information and the same unique identifier is determined among the multiple transaction requests based on the transaction interface information and the unique identifier, then based on the unique identifier of the first target transaction request, querying a database according to a preset period whether there is a first response result corresponding to the first target transaction request; If the first response result corresponding to the first target transaction request is not found in the database within the preset number of times, a second prompt message is returned to the client that sent the first target transaction request, wherein the second prompt message indicates that the first target transaction request is being executed and cannot be executed repeatedly; If it is confirmed based on the unique identifier that there is no first response result corresponding to the multiple transaction requests in the database, generating a distributed lock based on the transaction interface information and the unique identifier; The first response result indicates that the transaction has been completed; Based on the transaction interface information and the unique identifier, allocating the distributed lock to the plurality of transaction requests; For each of the transaction requests, if the transaction request is assigned to the distributed lock, respond to the transaction request, perform corresponding transaction business logic processing, obtain a second response result, and save the second response result to the database.
2. The transaction data processing method according to claim 1, It is characterized in that Based on the transaction interface information and the unique identifier, allocating the distributed lock to the plurality of transaction requests comprises: Based on the transaction interface information and the unique identifier, determining a first target transaction request having the same transaction interface information and the same unique identifier, and a second target transaction request having different transaction interface information and different unique identifiers among the multiple transaction requests; Allocating a distributed lock corresponding to the first target transaction request to one of the plurality of first target transaction requests; The distributed lock corresponding to the second target transaction request is allocated to the second target transaction request.
3. The transaction data processing method according to claim 1, It is characterized in that After the second response result is saved in the database, the method further includes: Release the distributed lock.
4. The transaction data processing method according to claim 1, It is characterized in that Also includes: If the transaction request is not assigned to the distributed lock, querying first state information of the distributed lock corresponding to the transaction request; If the first state information indicates that the distributed lock has been released, a third response result corresponding to the transaction request is searched from a database based on the unique identifier.
5. The transaction data processing method according to claim 4, It is characterized in that Also includes: If the first status information indicates that the distributed lock has timed out, first prompt information is returned to the client that sent the transaction request, and the first prompt information indicates that the transaction request is being executed.
6. The transaction data processing method according to claim 1, It is characterized in that After the second response result is saved in the database, the method further includes: The second response result is returned to the client that sends the transaction request.
7. The transaction data processing method according to claim 1, It is characterized in that After obtaining multiple transaction requests, it also includes: Obtain second state information of the distributed lock forming module; If the second state information indicates that the distributed lock forming module is in a normal working state, if the first response result corresponding to the plurality of transaction requests is not confirmed in the database based on the unique identifier, a distributed lock is generated based on the transaction interface information and the unique identifier; If the second status information indicates that the distributed lock forming module is in a non-working state, execute if the first response result corresponding to the multiple transaction requests does not exist in the database based on the unique identifier, respond to each transaction request, perform corresponding transaction business logic processing, obtain a fourth response result, and save the fourth response result to the database.
8. A transaction data processing device, It is characterized in that include: An acquisition module, used to acquire multiple transaction requests, wherein the transaction requests include transaction interface information and a unique identifier of the transaction; a generating module configured to, if determining, based on the transaction interface information and the unique identifier, a first target transaction request having the same transaction interface information and the same unique identifier among the plurality of transaction requests, query, based on the unique identifier of the first target transaction request, whether a first response result corresponding to the first target transaction request exists in a database according to a preset period; If the first response result corresponding to the first target transaction request is not found in the database within the preset number of times, a second prompt message is returned to the client that sent the first target transaction request, wherein the second prompt message indicates that the first target transaction request is being executed and cannot be executed repeatedly; If it is confirmed based on the unique identifier that there is no first response result corresponding to the multiple transaction requests in the database, generating a distributed lock based on the transaction interface information and the unique identifier; The first response result indicates that the transaction has been completed; An allocation module, configured to allocate the distributed lock to a plurality of the transaction requests based on the transaction interface information and the unique identifier; The processing module is used to respond to each transaction request, if the transaction request is assigned to the distributed lock, perform corresponding transaction business logic processing, obtain a second response result, and save the second response result to the database.
9. An electronic device, It is characterized in that include: at least one processor; And a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor executes the transaction data processing method as described in any one of claims 1-7.
Citation Information
Patent Citations
Idempotent implementation method, device, equipment and medium
CN113064584A
