A numerical state-based asynchronous interface quota anti-replay backfill method and system
By constructing a numerical state machine and intercepting high-concurrency requests at the microservice gateway layer, and using quota values as distributed mutex locks, the problems of network latency and resource management in high-concurrency scenarios are solved, and the consistency of resource flow and self-healing capabilities are improved.
Patent Information
- Application Number
- CN202611102645.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-23
- Publication Date
- 2026-11-03
AI Technical Summary
In high-concurrency scenarios, existing technologies suffer from increased network I/O overhead and higher network round-trip latency due to the maintenance of concurrent locks, which affects system resource allocation and billing management.
By constructing an asynchronous interface quota anti-duplication and replenishment method based on numerical states, a state machine is built using the positive, negative, and zero states of the numerical values. State reading and flipping locking are completed within the same composite atomic operation. The quota values are reused as distributed mutex locks, reducing network round-trip overhead and storage burden.
It reduces network round-trip latency, ensures the serialization of billing logic and the consistency of resource flow, and improves the system's self-healing ability and throughput under abnormal operating conditions.
Smart Images

Figure CN123035240A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of industrial gateways, and in particular to a method and system for preventing duplicate replenishment of asynchronous interface quotas based on numerical status. Background Technology
[0002] Currently, with the rapid development of cloud computing and microservice architecture, handling distributed business through a unified request access layer (such as an API gateway) has become widely used. Especially in long-running scenarios such as AI large-scale model inference and large-scale data processing, systems typically employ asynchronous task interfaces to improve overall throughput. To ensure the reasonable allocation of system resources and commercial monetization, the gateway needs to implement quota-based billing management for these asynchronous calls.
[0003] In related technologies, when a gateway receives a task result query request, it first requests the cache system to write an independent distributed lock key to preempt the processing right; after successfully preempting the lock, the gateway reads a dedicated task status key to determine the progress of the task; when it is confirmed that a refund or supplement settlement needs to be performed, the gateway reads a third independent quota amount key to extract the pre-deducted value for difference calculation; finally, after the reconciliation is completed, the gateway sends a network command to the cache to release the distributed lock key.
[0004] However, in concurrent scenarios where a large number of distributed nodes frequently poll the progress of the same task, the numerous cross-network step-by-step operations generated in order to maintain concurrent mutex locks and read associated states will amplify the network I / O overhead of the system, resulting in increased network round-trip latency caused by the gateway to the caching system in order to maintain concurrent locks. Summary of the Invention
[0005] This application provides a method and system for preventing duplicate quota redundancy based on numerical status in asynchronous interfaces, which can reduce network round-trip latency.
[0006] The first aspect of this application provides an asynchronous interface quota anti-duplicate compensation method based on task identifier value state flow, the method comprising: The system receives asynchronous task initiation requests, calculates pre-deducted quota values and performs quota deduction. It sets the value corresponding to the generated task identifier in the central cache to a positive number, where the positive number represents the pre-deducted quota value. It also receives task result retrieval requests carrying the task identifier, reads the current cache value corresponding to the task identifier through a composite atomic operation, and performs conditional update flow: if the current cache value is positive, it modifies it to the corresponding negative number within the same atomic operation to obtain the processing right for the current request and forwards the request to the backend execution node to obtain the actual execution result; if the current cache value is negative, it determines that the current task is being processed, rejects the result retrieval request, and repeatedly enters the replenishment calculation process; if the current cache value is zero, it determines that the current task has completed settlement and skips the quota processing process; after obtaining the actual execution result returned by the backend execution node, it determines whether the task is completed; if the task is not completed, it restores the cache value from negative to positive; if the task is completed, it performs quota replenishment based on the difference between the pre-deducted quota value and the actual consumed quota value, and sets the cache value to zero.
[0007] In the above embodiments, a state machine is constructed using the positive, negative, and zero states of numerical values, and state reading and toggling locking are completed within the same composite atomic operation. The microservice gateway layer intercepts repeated polling requests for the same task in high-concurrency scenarios, avoiding duplicate quota replenishment and state pollution caused by concurrent reads. The quota value itself is reused as a distributed mutex lock, reducing the network round-trip overhead and storage burden caused by introducing external independent lock components, and ensuring the serialization of billing logic and the consistency of resource flow throughout the lifecycle of long-running asynchronous tasks.
[0008] In conjunction with some embodiments of the first aspect, in some embodiments, the step of determining that the current task is being processed if the current cache value is negative, and rejecting the result retrieval request from repeatedly entering the backfilling calculation process, specifically includes: When the current cached value is read as negative, the timestamp contained in the negative value is extracted and restored to the timestamp of the last lock. The negative value is formed by combining the absolute timestamp of the original positive value when the processing right was acquired. The difference between the current system time and the extracted timestamp is calculated. If the difference is less than the preset deadlock timeout threshold, it is determined that the current task is being processed and the request is rejected. If the difference is greater than or equal to the deadlock timeout threshold, it is determined that the original processing process has abnormally caused a deadlock. The negative value is directly updated to a new negative value carrying the latest timestamp of the current system through atomic operations, the processing right is forcibly seized, and the request is forwarded to the backend execution node to obtain the result.
[0009] In the above embodiments, by compounding the timestamp in the negative cache value, the system can obtain time metadata while reading the state variable. Based on the autonomous comparison of time differences, it can proactively identify deadlock timeouts and force an update of the cache to take over processing rights when the original processing node crashes or experiences network anomalies. This mechanism eliminates secondary queries to external independent clock services, improves the self-healing capability of distributed locks under abnormal conditions, and prevents long-running tasks from falling into indefinite stagnation due to single-point failures.
[0010] In conjunction with some embodiments of the first aspect, in some embodiments, if the task has been completed, quota replenishment is performed based on the difference between the pre-deducted quota value and the actual consumed quota value, and the cached value is set to zero, specifically including: When performing quota difference calculation, the negative number with timestamp is restored to a numerical form containing only the original pre-deducted quota value by using a preset data separation rule; the difference is calculated using the original pre-deducted quota value and the actual consumed quota value, and after the replenishment is completed, the cached value is cleared and set to zero.
[0011] In the above embodiments, composite state variables are reverse-unpacked using preset data separation rules to remove redundant timestamp data introduced by concurrency control. Differential settlement is performed based on the restored basic quota, eliminating interference from time metadata on algebraic operations and ensuring the correctness of accounting logic. After reconciliation, the global cache is immediately set to zero, clearing the locking flag at the memory data level and establishing a final state to prevent duplicate settlement.
[0012] In conjunction with some embodiments of the first aspect, in some embodiments, after determining that the current task is being processed and rejecting the result retrieval request from repeatedly entering the backfilling calculation process if the current cache value is negative, the method further includes: The absolute value of the negative number is extracted as the computational resource weight of the task; a local silent duration positively correlated with the task's time is dynamically generated using a preset backoff algorithm combined with the computational resource weight; an anti-penetration interception flag is written into the local memory of the current gateway node, with the task identifier as the key and the local silent duration as the lifecycle; within the local silent duration, when a query request carrying the same task identifier is received again, it is directly intercepted in the local memory layer and a processing prompt is returned, blocking the network read operation to the central cache.
[0013] In the above embodiments, an adaptive local backoff period is generated by extracting quota weights, directly blocking high-frequency invalid polling requests generated in the early stages of long-running tasks in the gateway's local memory. The establishment of anti-penetration interception flags blocks a large number of cross-network calls that penetrate to the central cache, significantly reducing the concurrent read-only load of the underlying storage middleware, alleviating network channel congestion, and improving the gateway layer's throughput support capability for handling massive concurrent polling.
[0014] In conjunction with some embodiments of the first aspect, in some embodiments, after the step of performing quota replenishment based on the difference between the pre-deducted quota value and the actual consumed quota value if the task has been completed, and setting the cached value to zero, the method further includes: The current gateway node actively publishes a task completion notification to other gateway nodes in the same cluster; after receiving the completion notification, other gateway nodes asynchronously clear the corresponding anti-penetration interception flag in their local memory.
[0015] In the above embodiments, by establishing a cross-gateway node communication synchronization mechanism after the task's final state is established, each access instance can promptly perceive changes in the global state. Other nodes asynchronously clear their local interception barriers, preventing legitimate requests from being mistakenly intercepted by locally expired silent durations when a task completes early. This maintains the consistency of the business state machine among multiple nodes and the reachability of subsequent interface calls in a distributed environment.
[0016] In conjunction with some embodiments of the first aspect, in some embodiments, the step of restoring the cached value from a negative number to a positive number if the task is not completed specifically includes: When the actual execution result returned by the backend execution node is obtained, and it is determined that the task is in an intermediate suspended state where some stages have failed and retry is allowed; the actual consumption quota value corresponding to the currently successfully executed stage returned by the backend execution node is extracted; the stage difference between the pre-deducted quota value and the actual consumption quota value is calculated, and a stage quota replenishment operation is triggered; through an atomic operation, the cached value is updated from the current negative number to a new positive number whose absolute value is less than the original pre-deducted quota value, so as to release the locked state for subsequent retry requests to continue querying.
[0017] In the above embodiments, by calculating the difference and partially replenishing it during the task suspension phase, the idle funds that were excessively locked by the initiator are released, improving the resource turnover rate. At the same time, the atomic update instruction is used to correct the mutex negative number to a smaller positive number representing the remaining available quota. This not only unlocks the concurrency lock but also establishes a new quota benchmark for subsequent breakpoint resume retries, ensuring the continuity of billing for multi-stage asynchronous pipeline tasks.
[0018] In conjunction with some embodiments of the first aspect, in some embodiments, if the current cached value is positive, then within the same atomic operation, it is modified to the corresponding negative value to obtain the processing right of the current request, and the request is forwarded to the backend execution node to obtain the actual execution result, specifically including: When the current cached value is positive, the high-order binary routing data of the positive number is identified. This positive number is generated by combining the pre-deducted quota value and the target route identifier of the backend execution node through bitwise operations. The positive number is modified into the corresponding composite negative integer through the same atomic operation to obtain the processing right of the current request. The high-order data is extracted by performing a bitwise mask operation on the composite negative integer and decoded into the target route identifier. Dynamic routing rules are constructed using the target route identifier to forward the current task result retrieval request to the corresponding backend execution node.
[0019] In the above embodiments, bitwise operations are used to integrate the addressing information and quota status of the backend instance into a single state variable, enabling atomic operations to simultaneously read routing metadata in parallel while changing symbols to preempt processing rights. This logic directly maps the dynamic forwarding topology during the memory unpacking stage, eliminating the network waiting latency caused by the gateway node initiating a secondary addressing query to the external routing registry center, and optimizing the signaling interaction efficiency between upstream and downstream microservices.
[0020] Secondly, embodiments of this application provide an asynchronous interface quota anti-duplication compensation system based on numerical state. The asynchronous interface quota anti-duplication compensation system based on numerical state includes: one or more processors and a memory; the memory is coupled to the one or more processors, and the memory is used to store computer program code, the computer program code including computer instructions, and the one or more processors call the computer instructions to cause the asynchronous interface quota anti-duplication compensation system based on numerical state to perform the method described in the first aspect and any possible implementation thereof.
[0021] Thirdly, embodiments of this application provide a computer program product containing instructions that, when the computer program product is run on an asynchronous interface quota anti-duplication compensation system based on numerical state, causes the asynchronous interface quota anti-duplication compensation system based on numerical state to execute the method described in the first aspect and any possible implementation thereof.
[0022] Fourthly, embodiments of this application provide a computer-readable storage medium including instructions that, when executed on an asynchronous interface quota anti-duplication compensation system based on numerical state, cause the asynchronous interface quota anti-duplication compensation system based on numerical state to perform the method described in the first aspect and any possible implementation thereof.
[0023] Understandably, the asynchronous interface quota anti-duplication compensation system based on numerical state provided in the second aspect, the computer program product provided in the third aspect, and the computer storage medium provided in the fourth aspect are all used to execute the asynchronous interface quota anti-duplication compensation method based on numerical state provided in the embodiments of this application. Therefore, the beneficial effects they can achieve can be referred to the beneficial effects in the corresponding methods, and will not be repeated here.
[0024] One or more technical solutions provided in the embodiments of this application have at least the following technical effects or advantages: 1. This application constructs a state machine using positive, negative, and zero states of numerical values, and completes state reading and inversion locking within the same composite atomic operation. At the microservice gateway layer, it intercepts repeated polling requests for the same task in high-concurrency scenarios, avoiding duplicate quota replenishment and state pollution caused by concurrent reads. By reusing the quota value itself as a distributed mutex lock, it reduces the network round-trip overhead and storage burden caused by introducing external independent lock components, ensuring the serialization of billing logic and the consistency of resource flow throughout the lifecycle of long-running asynchronous tasks.
[0025] 2. This application enables the system to acquire time metadata while reading state variables by compounding a timestamp in a negative cache value. Based on autonomous comparison of time differences, it can proactively identify deadlock timeouts and force an update of the cache to take over processing rights when the original processing node crashes or experiences network anomalies. This mechanism eliminates secondary queries to external independent clock services, improves the self-healing capability of distributed locks under abnormal conditions, and prevents long-running tasks from falling into indefinite stagnation due to single-point failures.
[0026] 3. This application uses preset data separation rules to reverse-unpack composite state variables, removing redundant timestamp data introduced by concurrency control. Based on the restored basic quota, differential settlement is performed, eliminating interference from time metadata on algebraic operations and ensuring the correctness of accounting logic. After reconciliation, the global cache is directly set to zero, physically destroying the concurrency lock and solidifying the completion state of preventing duplicate refunds and compensations. Attached Figure Description
[0027] Figure 1 This is a flowchart illustrating an asynchronous interface quota anti-duplication and replenishment method based on task identifier value state transition in an embodiment of this application. Figure 2 This is another flowchart illustrating the asynchronous interface quota anti-duplication and replenishment method based on task identifier value status flow in this application embodiment; Figure 3 This is an exemplary hardware structure diagram of an asynchronous interface quota anti-duplication compensation system based on numerical status in this application embodiment. Detailed Implementation
[0028] The terminology used in the following embodiments of this application is for the purpose of describing particular embodiments only and is not intended to be limiting of this application. As used in the specification and appended claims of this application, the singular expressions “a,” “an,” “the,” “the,” “the,” and “this” are intended to include the plural expressions as well, unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used in this application refers to and includes any or all possible combinations of one or more of the listed items.
[0029] Hereinafter, the terms "first" and "second" are used for descriptive purposes only and should not be construed as implying or suggesting relative importance or implicitly indicating the number of indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature, and in the description of the embodiments of this application, unless otherwise stated, "multiple" means two or more.
[0030] Figure 1 This is a flowchart illustrating the asynchronous interface quota anti-duplicate compensation method based on task identifier value state transition in this application embodiment, including the following steps: S101. Receive the asynchronous task initiation request, calculate the pre-deducted quota value and perform quota deduction, and set the value corresponding to the generated task identifier in the central cache to a positive number, wherein the positive number represents the pre-deducted quota value.
[0031] Among them, asynchronous task initiation request refers to business processing instructions submitted by the client or external caller that require a long processing time and cannot return results immediately; pre-deducted quota value refers to the amount of computing resources or funds that the system pre-assesses and locks based on the task scale to ensure sufficient account balance; central cache is used to represent centralized storage middleware that provides cross-node shared memory data access in a distributed system architecture; task identifier refers to a globally unique string or numeric string assigned by the system for the lifecycle of a single task; positive number refers to a numerical form greater than zero, which is reused here as the initial quota state that is not locked.
[0032] Specifically, after receiving a request message containing business parameters, the system parses the message volume or pre-calculation parameters and substitutes them into the billing model to calculate the pre-deducted quota value for the task. Subsequently, the system calls the account center interface to subtract this pre-deducted quota value from the user's total quota and generates a task identifier using a hash algorithm or snowflake algorithm. Finally, the system sends a write command to the central cache, using the task identifier as the key and writing a positive integer equal to the pre-deducted quota value as the value into the cache memory, establishing the initial mount point of the state machine. When the pre-deducted quota value is zero, the system injects a preset baseline offset constant at the bottom layer during the write phase to convert it into a valid positive number, and removes this constant during the backend accounting and final settlement stages to ensure the uniqueness of the zero value as the completion identifier in the final state.
[0033] In some embodiments, the central cache state initialization can be implemented in several ways: Optionally, the system extracts the generated task identifier as the key name; constructs a network data packet containing the SET command and a positive quota value; sends the data packet to the Redis cluster via the Transmission Control Protocol and receives a write success response; Optionally, the system establishes a connection pool with the Memcached server; serializes the object containing the pre-deducted quota value; and calls the channel in the connection pool to persist the serialized data and task identifier to memory. It is understood that other methods can also be used to implement the initial quota state writing, which are not limited here.
[0034] In some embodiments, in extremely rare scenarios where massive multi-tenant concurrent task initiation leads to network congestion in billing model reading, the asynchronous interface quota anti-duplication compensation system based on task identifier value state flow can also perform local route calculation. Specifically, the system extracts the tenant identification code from the request; maps the tenant to a local memory shard of the current gateway node according to the hash consistency ring algorithm; directly calculates the pre-deducted quota value in local memory and generates a task identifier, then batches and asynchronously packages it into the central cache. This method reduces the network round-trip latency caused by the gateway maintaining concurrent locks on the caching system.
[0035] S102. Receive a task result retrieval request carrying the task identifier, read the current cache value corresponding to the task identifier through a composite atomic operation, and perform conditional update flow.
[0036] Among them, the task result retrieval request refers to the network call initiated by the client after the task is submitted, according to the polling mechanism, to query the current running progress or final output of the task; the compound atomic operation refers to the packaging of multiple data reading, logical judgment and numerical modification instructions into an indivisible execution logic unit in concurrent programming and distributed computing; the condition update flow refers to the state transition mechanism that determines the subsequent state machine direction based on the specific numerical range read.
[0037] Specifically, the gateway node receives query messages from clients or lower-level microservices and extracts the target task identifier. Since multiple nodes may simultaneously initiate queries for this task identifier in a distributed environment, the system encapsulates the read instructions and update logic into a low-level scripting language or hardware-level Compare-and-Swap (CAS) primitive. This primitive runs exclusively in the execution engine of the central cache, ensuring that the value of the cache key is not tampered with by other concurrent threads during the lifetime from the moment the current value is read to the completion of the state determination, thereby maintaining the serialization and consistency of the state machine transition.
[0038] In some embodiments, the execution of composite atomic operations can be implemented in several ways: Optionally, the system loads a Lua script containing state transition logic into memory; injects the task identifier as a parameter into the script; sends the script to the central cache engine for single-threaded execution and obtains the return value; Optionally, the system sends a read instruction to obtain the current cached value and its data version number; performs condition judgment and calculates the target update value in local memory; and sends a write request with conditional comparison to the central cache, carrying the original version number. It is understood that other methods can also be used to implement atomic reads and updates, which are not limited here.
[0039] S103. If the current cached value is positive, modify it to the corresponding negative value within the same atomic operation to obtain the processing right of the current request, and forward the request to the backend execution node to obtain the actual execution result.
[0040] In this context, "processing right" refers to the exclusive execution permission granted by the system to a specific thread or request in a scenario where concurrent requests compete for the same resource; "backend execution node" refers to a set of physical or virtual servers located downstream of the access layer that carry out the actual complex business calculation, rendering, or inference logic; and "actual execution result" refers to the stage status code or final business data generated by the backend node after processing the asynchronous task.
[0041] Specifically, when the atomic operation reads a value greater than zero, the system determines that no other concurrent threads are currently requesting the task result from the backend. The system then performs a sign-bit reversal update operation on the positive number, setting the high-order sign bit of the binary representation of the value to 1, converting it to a negative number, while retaining the underlying absolute value of the pre-deducted quota in the data bits, and writing the result back to the cache. Since this modification is completed within the same atomic operation, the negative number not only retains the original absolute value of the pre-deducted quota but also acts as a marker for the distributed mutex lock. After obtaining exclusive permission, the system ends the atomic operation, releases cache layer resources, establishes a remote procedure call (RPC) connection with the backend execution node, and sends a query command to wait for the backend response.
[0042] In some embodiments, state inversion and request forwarding can be implemented in several ways: Optionally, the system extracts the numerical variable from the script; performs a two's complement operation (bitwise inversion and addition) to convert it to a negative number and writes it; calls the load balancing component to select the target backend node and initiates the transmission message; Optionally, the system appends a negative sign to the beginning of the numerical string in memory; updates the appended result to the cached key-value pairs; parses the local routing table and establishes a Transmission Control Protocol (TCP) connection to send a query request. It is understood that other methods can also be used to implement numerical inversion and node communication, which are not limited here.
[0043] S104. If the current cache value is negative, it is determined that the current task is being processed, and the request to obtain the result is rejected so that it can be re-entered into the backfill calculation process.
[0044] The "processing" status indicates that the target asynchronous task has been taken over and followed up by other instances in the gateway cluster, or that the backend execution node is still performing a long-running calculation process; the "recovery calculation process" refers to the reconciliation procedure for calculating the difference in funds and executing the system account crediting when the task ends.
[0045] Specifically, when a subsequent query request triggers an atomic operation, the system reads a value in the negative range (less than zero). This mathematical condition causes the system to determine at the underlying logic that the mutex lock is already occupied. The system then immediately halts the data modification actions of the current request within the atomic operation, leaving the cached value negative and exiting. After exiting, the system directly constructs a response message indicating that the task is in progress at the gateway level and returns it to the caller. This effectively blocks the request from penetrating the backend billing system or execution nodes, avoiding data pollution caused by re-entrant billing logic.
[0046] In some embodiments, interception and rejection operations can be implemented in several ways: Optionally, the system suspends write operations in the central cache and returns a lock signal; the gateway node captures the lock signal and stops building the backend request; a response message containing the status code of the business processing is built and sent to the client; Optionally, the system directly outputs the absolute value of a negative number in the execution branch of the atomic script; the gateway node discards the network context of the request; and concurrent interception event information is recorded in the system log module. It is understood that other methods can also be used to block concurrent requests, and these are not limited here.
[0047] In some embodiments, when dealing with scenarios where a large number of clients frequently poll the same long-running task, causing the central cache network to become overloaded, a local anti-penetration interception and cluster state synchronization mechanism can be dynamically constructed based on numerical weights to reduce network round-trip latency.
[0048] The preset backoff algorithm refers to a time decay and extension function derived by those skilled in the art based on historical polling request frequencies and network congestion statistics. When the gateway node reads a negative cache value and determines to reject the current request from entering the backoff process, the system extracts the absolute value of this negative number. Since this absolute value essentially represents the initial pre-deducted quota for the task, and the quota size is positively correlated with the expected computation time of the task, the system uses it as the computational resource weight for the task. The system substitutes this weight value into the aforementioned backoff algorithm for logical operations, dynamically generating a local silent duration that matches the task's computation time. By adopting this weight-based dynamic calculation method, the system can adaptively allocate the shielding period for asynchronous tasks with different resource consumption scales, avoiding long-duration tasks facing dense invalid queries in the early stages of computation.
[0049] Subsequently, the system writes an anti-penetration interception flag in the local memory of the current gateway node, using the task identifier as the index key and the local silent duration as the data's lifecycle. During the period before the lifecycle expires, when the gateway node receives another result query request carrying the same task identifier, the system directly intercepts the request in the local memory layer and constructs a message carrying the processing status to return to the caller. This operation directly blocks the cross-network read operation initiated by the query request to the central cache. This is because the I / O overhead of reading local memory is far less than the overhead of accessing a remote cache node through the Transmission Control Protocol (TCP), effectively reducing the concurrent processing load of the lower-layer middleware.
[0050] Furthermore, to address the issue of isolated states between different gateway nodes in a distributed deployment, once the gateway node handling the task receives the actual result returned by the backend execution node and completes the quota replenishment and central cache zeroing operations, it proactively publishes a task completion notification to other gateway nodes within the same cluster via the internal message bus. Upon receiving this message, other gateway nodes initiate background asynchronous threads to retrieve and clear the anti-penetration interception flags for that task identifier from their local memory. This cross-node synchronous cleanup mechanism ensures that when a task completes early, the local interception barriers of each access node can be promptly removed, guaranteeing state consistency and the reachability of subsequent requests in a distributed environment.
[0051] By extracting quota weights to generate adaptive local interception flags, high-frequency invalid polling requests are directly blocked in the gateway's local memory. This reduces the frequency of cross-network read / write operations between the gateway and the central cache, alleviates the concurrent load on the storage layer, and thus reduces network round-trip latency caused by maintaining the distributed lock.
[0052] S105. If the current cache value is zero, it is determined that the current task has been settled and the quota processing process is skipped.
[0053] Among them, zero value refers to the mathematical form where the value is equal to zero. Here, it is reused as the final state marker that the task lifecycle has ended and the quota bill has been settled. Settlement status refers to the balance state that the pre-deducted funds and the actual consumed funds of the task have been reconciled and adjusted, with refunds for overpayments and additional payments for underpayments.
[0054] Specifically, when an atomic operation reads a value with an absolute value of zero, the system, based on predefined state machine rules, determines that the concurrent lock, quota refund, and backend calculations associated with that task identifier have all been completed in the entire chain. The system then exits the atomic operation and blocks the call chain of the funds accounting component in the local routing logic. The system directly retrieves the archived business calculation result file from the persistent database or object storage service based on the task identifier, constructs a response message, and sends it to the caller, thus preventing completed orders from being triggered for duplicate refunds.
[0055] In some embodiments, completion status processing can be implemented in several ways: Optionally, the system obtains the zero-value identifier returned by the atomic operation; directly requests the persistent database query result record based on the identifier; encapsulates the queried record data and returns a success status message to the client; Optionally, the system identifies the zero-value state and suspends the current thread; retrieves the historical storage path of the task from the distributed file system; constructs a file download redirection link and sends it to the requester. It is understood that other methods can also be used to implement result extraction and response, which are not limited here.
[0056] S106. After obtaining the actual execution result returned by the backend execution node, determine whether the task is completed. If the task is not completed, proceed to step S107 below; If the task has been completed, proceed to step S108 below.
[0057] Whether a task is completed refers to the status feedback from the backend node regarding the current execution progress of the asynchronous task it undertakes.
[0058] Specifically, the system unpacks and deserializes the received backend response packets to extract the message payload. The system then performs logical checks on the business status fields within the payload: when the system detects a status field indicating that the task is still in the queue, in operation, or partially failed and suspended, the system determines that the task is not completed and proceeds to branch one to execute step 107; when the system detects a status field indicating that the task is completed, has completely failed, or the operation has terminated, the system determines that the task is completed and proceeds to branch two to execute step 108.
[0059] In some embodiments, result parsing and branching can be implemented in several ways: Optionally, the system reads the protocol header status code of the response message; compares whether the status code is equal to 200 (success indicator); and switches the program's execution stack pointer based on the Boolean result of the comparison. Optionally, the system uses regular expressions to extract the progress percentage value in the message body; determines whether the percentage value is equal to 100; if it is less than 100, it routes to the incomplete processing module; otherwise, it routes to the completed processing module. It is understood that other methods can also be used to implement logical routing, which are not limited here.
[0060] S107. Restore the cached value from a negative number to the positive number.
[0061] The recovery operation refers to the process of removing the temporary mutex lock flag after confirming that the task has not yet ended, so that the task state machine can roll back to an open state that allows subsequent polling requests to continue to view the data.
[0062] Specifically, the system sends a write-back instruction to the central cache, performing a mathematical inverse operation on the currently maintained negative state and resetting the sign bit of the negative number. This updates the value from the negative range to a positive state equal to the original pre-deducted quota value. This operation releases the distributed mutex lock held by the task identifier in the central cache, allowing the client's new query request to obtain a positive number again through atomic operations when the next polling cycle interval arrives, thus driving the state machine to continue its transition.
[0063] In some embodiments, positive value recovery can be achieved in several ways: Optionally, the system reads the negative number variable cached in memory; calculates the positive number by calling the absolute value function in the mathematical standard library; and constructs an update instruction to overwrite the positive number into the corresponding key in the central cache. Optionally, the system extracts the negative number held by the current node; performs a sign bit flipping operation based on the original code to eliminate the negative sign; and sends the processed data packet to the cache server. It is understood that other methods can also be used to achieve lock release and state restoration, which are not limited here.
[0064] In some embodiments, in the extremely special scenario where the backend node returns "task not completed" but also includes a precise estimate of the remaining processing time, the asynchronous interface quota anti-duplication compensation system based on the task identifier value status flow can also perform adaptive silent interception. Specifically, the system extracts the estimated remaining processing time returned by the backend; before restoring the cached value from negative to positive, it writes a local silent flag in the gateway's local memory with this remaining time as the expiration lifecycle; if the same task query is received within the lifecycle, it is directly blocked locally on the gateway. This method effectively reduces the network round-trip latency caused by the gateway maintaining concurrency locks on the caching system.
[0065] In some embodiments, when a partial failure occurs during the execution of an asynchronous pipeline task and retry conditions are available, partial replenishment of quotas and updating of available locked quotas can be performed based on the stage consumption difference to ensure the continuity of resource billing and support the continuous flow of tasks.
[0066] The preset retry strategy refers to the judgment rules that allow the state machine to suspend and wait for a second trigger, derived by those skilled in the art based on the fault tolerance theory of distributed systems and the historical anomaly recovery rules. Specifically, after obtaining the actual execution result returned by the backend execution node, the system parses the response message. When the message status code indicates that the task is in an intermediate suspension state that meets the preset retry strategy, the system extracts the actual consumption quota value corresponding to the currently successfully executed stage carried in the response body. The system uses the initial pre-deducted quota value to subtract the actual consumption quota value to obtain the stage difference, and calls the underlying resource interface to trigger the stage quota replenishment operation. Executing this difference replenishment operation can return the remaining unconsumed computing resources or funds to the initiator in advance when the task is in a stagnant waiting period, avoiding the excessive locking of the initiator's resources due to the lengthy retry waiting period, and improving resource availability. Subsequently, the system initiates a low-level atomic update instruction to modify the current negative value in the central cache to a new positive number equal to the stage difference. Since the new positive number only includes the quota for the unexecuted phase, its absolute value is necessarily less than the original pre-deducted quota value. This state transition eliminates the negative value at the underlying storage level, releases the concurrent mutex lock for the task identifier, and simultaneously reassigns the remaining execution quota at the business logic level. This ensures that after the suspended state is lifted, subsequent retry requests can correctly read the positive value containing the remaining quota and continue the process, meeting the billing continuity requirements for resuming interrupted tasks in long-link pipelines.
[0067] By calculating the stage difference and partially replenishing it when the task is suspended, idle funds can be released in advance to avoid excessive resource locking. At the same time, atomic unlocking and updating the cached value to a smaller positive number provide a reliable remaining quota benchmark for subsequent retry requests, ensuring the continuity of state machine transitions under breakpoint resume service.
[0068] S108. Perform quota replenishment based on the difference between the pre-deducted quota value and the actual consumed quota value, and set the cached value to zero.
[0069] Among them, the actual consumed quota value refers to the final billing value calculated based on the actual computing power resources or time consumed after the backend node has completely completed the calculation; the difference refers to the mathematical difference between the pre-frozen quota and the actual cost incurred; quota replenishment refers to the secure transaction behavior in which the system returns the overcharged difference funds or resources to the initiator's account.
[0070] Specifically, the system extracts the actual consumed quota value from the backend response packet and performs an absolute value operation on the negative numbers in the cache to extract the original pre-deducted quota value. The system then performs a subtraction calculation to obtain the difference: Diff = |V negative | -ActualCost. If the difference is greater than zero, the system triggers a recharge operation in the account service via an internal remote call, returning the difference to the user. After the fund transfer is successfully confirmed, the system sends an atomic update instruction to the central cache, directly overwriting the value corresponding to the task identifier from a negative number to a mathematical zero value. This operation clears the mutex lock while closing the quota processing channel for the task, achieving final state solidification to prevent duplicate replenishment.
[0071] In some embodiments, settlement and final state setting can be implemented in multiple ways: Optionally, the system calculates the arithmetic difference between the absolute value and the consumption value; calls the transaction mechanism to update the difference in the account balance table of the relational database; constructs a network instruction with a value of zero and sends it to the central cache; Optionally, the system generates a refund statement message containing the difference; delivers the message to the message queue middleware for asynchronous consumption by the financial service; and calls the cache modification interface locally on the gateway node to clear the corresponding key-value pair. It is understood that other methods can also be used to achieve fund settlement and state reset, which are not limited here.
[0072] In the above embodiments, a state machine is constructed using the positive, negative, and zero states of numerical values, and state reading and toggling locking are completed within the same composite atomic operation. The microservice gateway layer intercepts repeated polling requests for the same task in high-concurrency scenarios, avoiding duplicate quota replenishment and state pollution caused by concurrent reads. The quota value itself is reused as a distributed mutex lock, reducing the network round-trip overhead and storage burden caused by introducing external independent lock components, and ensuring the serialization of billing logic and the consistency of resource flow throughout the lifecycle of long-running asynchronous tasks.
[0073] In some other embodiments of this application, when an anomaly occurs in the original processing node, it may cause the mutex lock to remain unreleased, leading to a task deadlock. The asynchronous interface quota anti-duplication compensation method based on task identifier numerical state transition provided in this application can extract the lock timestamp from the composite negative number for timeout evaluation, and forcibly overwrite the timestamp to take over processing rights and restore task flow when a deadlock is determined.
[0074] like Figure 2 The diagram shown is another flowchart illustrating the asynchronous interface quota anti-duplication and compensation method based on task identifier value state transition provided in this application embodiment, including the following steps: S201. Receive the asynchronous task initiation request, calculate the pre-deducted quota value and perform quota deduction, and set the value corresponding to the generated task identifier in the central cache to a positive number, wherein the positive number represents the pre-deducted quota value.
[0075] S202. Receive a task result retrieval request carrying the task identifier, read the current cache value corresponding to the task identifier through a composite atomic operation, and perform conditional update flow.
[0076] S203. If the current cached value is positive, modify it to the corresponding negative value within the same atomic operation to obtain the processing right of the current request, and forward the request to the backend execution node to obtain the actual execution result.
[0077] In some embodiments, in scenarios where asynchronous tasks need to be scheduled for specific backend instances in multi-datacenter or complex microservice clusters, the routing identifier of the flow node can be synchronized based on the bit operation mechanism of positive and negative state machines, so as to achieve dynamic addressing and forwarding while preempting the concurrent lock.
[0078] The preset bitmasking rule refers to the binary bit division convention derived by those skilled in the art based on the data bus width and cluster node scale in the computer architecture. Specifically, when the gateway node reads a positive value in the current cache, this positive number has actually incorporated the routing context during the task initialization phase. Its generation mechanism is as follows: the system places the pre-deducted quota value in the low-order space of a long integer variable and the target route identifier of the backend execution node in the high-order space, generating the positive number through a binary left shift and bitwise OR operation. After recognizing this positive number, the system applies a two's complement operation logic (bitwise inversion and addition) to it within the same underlying atomic operation execution cycle, modifying it into the corresponding composite negative integer. This operation, while changing the sign of the value to exclusively acquire the current request processing right, maintains the composite distribution state of high and low order data. Its advantage is that a single memory write completes the concurrent state inversion and persistent inheritance of routing information, avoiding the storage overhead of additionally maintaining a distributed routing table. Subsequently, the system applies the preset bitwise masking rule to the composite negative integer, performs a logical AND operation in the processor register, sets the low-order quota data to zero to extract the high-order data, and performs a right shift operation to decode and restore the target route identifier. Finally, the system uses the decoded target route identifier to match the local gateway configuration, constructs a dynamic routing rule pointing to the target instance, and forwards the current task result retrieval request along this link to the corresponding backend execution node. The advantage of this approach is that the gateway can determine the downlink physical topology the instant it acquires lock privileges, avoiding intermediate waiting states.
[0079] By integrating the routing identifier and quota status into a single variable through bitwise operations, atomic operations can simultaneously read routing information while changing the sign to preempt the lock. This eliminates the need for gateways to initiate additional network addressing requests to external routing registries, thereby reducing system signaling overhead and improving request forwarding efficiency.
[0080] Steps S201-S203 and Figure 1 Steps S101-S103 in the illustrated embodiment are similar and can be found in the descriptions of steps S101-S103, which will not be repeated here.
[0081] S204. When the current cached value is read as negative, extract the timestamp contained in the negative value and restore it to the timestamp of the last lock; the negative value is the composite system absolute timestamp formed when the original positive value is acquired for processing.
[0082] Among them, the timestamp refers to the digital sequence that records the Greenwich Mean Time offset when a specific event occurs in a computer system; the timestamp of the last lock refers to the time coordinate recorded by the original processing node at the moment when it modifies a positive number to a negative number to preempt the mutex lock; compositing refers to the operation of merging two data dimensions into the same variable through mathematical operations or data structure reorganization; the system absolute timestamp refers to the time count value that is not affected by the local time zone and has a uniform monotonically increasing characteristic in the globally distributed nodes.
[0083] Specifically, when the lock resource is first occupied, the system executes encoding logic that combines a negative quota number with an absolute timestamp. This results in the negative number representing not only the task status but also the time metadata of the locking action. The system separates and parses this value according to the inverse operation logic of the encoding rules. If the encoding uses a bit-field partitioning mechanism, the system uses bitwise AND operations to mask the high bits and retain the low bits, extracting the timestamp data fragment. The remaining high-order data is then restored to the basic negative number representing the quota. Thus, without adding additional network requests, the system extracts the key time node coordinates from the memory data of the same read operation.
[0084] In specific implementation scenarios, the current cached value is carried using a long integer data structure. Its bit field configuration is as follows: the highest binary bit serves as the sign bit indicating the status; the middle bit field is used to write or extract the system's absolute timestamp data via a mask; and the remaining low-order data area is used to carry the original pre-deducted quota value. Multi-dimensional data access in a single memory operation is achieved through a combination of bit shifting and masking operations.
[0085] In some embodiments, the extraction and restoration of timestamps can be achieved in several ways: Optionally, the system reads a 64-bit integer composite negative variable; applies a predefined 36-bit low-order mask to the variable to perform a bitwise AND operation; and forces the result to a long integer to obtain the previously locked timestamp. Optionally, the system converts the read negative floating-point data with decimal points to a string format; uses a period as a delimiter to extract the second half of the string; and performs a type conversion operation on the extracted substring to restore it to a numeric timestamp. It is understood that other methods can also be used to reverse-parse composite data, and this is not limited here.
[0086] In some embodiments, in special scenarios where a time stamp read by a distributed node differs from the local clock reference due to a malfunction in the clock synchronization component, the asynchronous interface quota anti-duplication compensation system based on task identifier value state transition can also perform adaptive correction of the local time stamp offset, achieving the technical effect of reducing network round-trip latency. Specifically, after extracting the timestamp of the last lock, the system queries and extracts the original node machine code corresponding to the lock through the Network Time Protocol (NTP) alignment table residing in local memory. The system calculates the local clock difference correction coefficient between the node corresponding to the machine code and the current gateway node. The system adds the correction coefficient to the extracted timestamp to calculate the corrected real timestamp, thereby replacing the network call action of initiating a secondary time reference query to the central cache.
[0087] S205. Calculate the difference between the current system time and the extracted timestamp.
[0088] The current system time refers to the instantaneous timestamp value obtained by the gateway node when it calls the underlying clock interface of the operating system kernel at this moment; the difference refers to the length of the interval between two time coordinate points on the time axis, representing the time elapsed since the task is currently in the processing state.
[0089] Specifically, the system initiates a system call to request kernel clock resources and obtains a millisecond-level long integer value of the current time. Then, the system uses the extracted current system time value as the minuend and the previously locked timestamp (obtained from the previous step) as the subtrahend, performing basic algebraic subtraction. The calculation formula is: ΔT = T current -T locked The arithmetic calculation is performed in the local CPU register of the gateway node, and the resulting difference variable is temporarily stored in the execution context of the current thread, providing a numerical reference for the subsequent two-branch logic to determine the lock state lifecycle.
[0090] In some embodiments, the time difference can be calculated in several ways: Optionally, the system calls the standard time library of the runtime environment to obtain the current absolute time; verifies the data type consistency between the current time variable and the extracted timestamp variable; performs subtraction using an arithmetic logic unit to calculate the difference constant; Optionally, the system calls the local time function of the cache server within the atomic script that performs the read operation in the central cache; subtracts the lock time extracted in the script from the cache server's time variable; and returns the calculated difference along with the status information to the access layer gateway. It is understood that other methods can also be used to quantize the time interval, and this is not limited here.
[0091] S206. If the difference is less than the preset deadlock timeout threshold, it is determined that the current task is being processed and the request is rejected.
[0092] The preset deadlock timeout threshold is a time limit constant that is statistically derived by those skilled in the art based on the average computation time of the system's historical asynchronous tasks and the maximum allowable network communication delay. The processing status indicates that the mutex is still within the normal lifecycle protection range and the business logic of the original processing node is still running.
[0093] Specifically, the system calls relational operators to compare the calculated difference with the deadlock timeout threshold. When the difference is less than the deadlock timeout threshold, the system logically determines that the processing time window allocated to the original locking node has not yet been exhausted, and it may be performing complex computational inference or waiting for network retries. To ensure the idempotency and serialization of task execution, the system does not perform any write-back or overwrite operations on negative values in the central cache during this atomic operation, maintaining the current negative value and the original timestamp unchanged. The system then terminates the downstream flow of the result retrieval request and encapsulates a response message with the semantics of task processing in progress at the gateway protocol layer, directly blocking the request from entering the quota replenishment flow.
[0094] In some embodiments, the blocking logic for branches that have not timed out can be implemented in several ways: Optionally, the system loads a local configuration file to read a preset deadlock timeout threshold; performs Boolean algebra operations to confirm that the logical truth value is less than the threshold; triggers an interceptor to terminate the communication session and returns a prompt indicating that the operation is occupied; Optionally, the system passes a threshold parameter to the underlying atomic script for internal flow judgment; after the script execution environment evaluation condition is met, it directly returns a specific termination status code; the gateway receives the status code and destroys the request context without initiating subsequent polling. It is understood that other methods can also be used to maintain and reject the locked state, which are not limited here.
[0095] S207. If the difference is greater than or equal to the deadlock timeout threshold, it is determined that the original processing process has abnormally caused a deadlock. The negative number is directly updated to a new negative number carrying the latest timestamp of the current system through atomic operations, the processing right is forcibly seized, and the request is forwarded to the backend execution node to obtain the result.
[0096] Among them, "abnormal" refers to the state in which the original node cannot fulfill the lock release contract normally due to physical machine crash, process crash, or network disconnection; "deadlock" refers to the phenomenon of subsequent process of the system being stalled due to the unlimited occupation of mutual exclusive resources; "forced takeover of processing rights" refers to the operation in which the current node ignores the original lock ownership status and forcibly transfers the business scheduling rights to the current thread through the overwrite action; "new negative number" refers to the value state in which the timestamp is recombined by the current gateway node and overwritten into the central cache.
[0097] Specifically, if the system's computation time difference is greater than or equal to the deadlock timeout threshold, it proves mathematically and logically that the original holder has substantially failed. To restore the state machine's operational activity, the system initiates a deadlock prevention mechanism within the current atomic operation scope. The system generates a timestamp representing the latest system time and extracts the original quota negative number, fusing it into a new numerical variable through left shift and bitwise OR operations. The system calls a memory write primitive to overwrite and update this new negative number in the cache address of the task identifier. This overwrite action resets the original latch state, and the current gateway node subsequently acquires exclusive processing rights for the task. Following this, the system establishes a transport protocol connection and sends the query request to the designated backend execution node.
[0098] In some embodiments, deadlock disruption and forced reset can be achieved in several ways: Optionally, the system extracts the current millisecond-level time parameter; uses bitmasking operations to concatenate the new time parameter with the parsed original quota negative value in memory; sends an overwrite write instruction to refresh the concatenated new negative value to the central cache; Optionally, the system suspends abnormal process information after recognizing that the timeout condition has been met; constructs a string containing the current time attribute and formats it as a negative value with decimals; pushes this new negative value as an update parameter to the in-memory database to complete the replacement. It is understood that other methods can also be used to achieve forced lock handover, which are not limited here.
[0099] In some embodiments, when a large-scale network failure in a distributed cluster leads to a large number of nodes simultaneously initiating forced resets at high concurrency, the asynchronous interface quota anti-duplication and replenishment system based on task identifier value state flow can also perform random jitter adaptive backoff interception based on local memory, achieving the technical effect of reducing network round-trip latency. Specifically, after determining that the difference is greater than or equal to the deadlock timeout threshold, the system does not immediately execute the atomic overwrite instruction. The system calls a random number generation function combined with the task identifier name to generate a short-term random jitter time constant. The system writes this constant as a lifecycle into the jitter delay flag in local memory. During this jitter time, the system intercepts all lock-grabbing operations and directly returns to the waiting retry state. By staggering peaks in the time dimension, request queue congestion caused by a large number of gateway nodes launching lock contention to the central cache is avoided, effectively reducing the overload network round-trip overhead caused by high-concurrency denial-of-service in the cache component.
[0100] S208. If the current cache value is zero, it is determined that the current task has been settled and the quota processing process is skipped.
[0101] S209. After obtaining the actual execution result returned by the backend execution node, determine whether the task is completed. If the task is not completed, proceed to step S210 below; If the task has been completed, proceed to step S211 below.
[0102] S210. Restore the cached value from a negative number to the positive number.
[0103] S211. Perform quota replenishment based on the difference between the pre-deducted quota value and the actual consumed quota value, and set the cached value to zero.
[0104] In some embodiments, when the task is completed and the composite state variable carries multidimensional metadata, the basic quota can be extracted based on the data separation rule for reconciliation and destruction, ensuring the accuracy of billing data and the complete release of resources.
[0105] The preset data separation rule refers to a decoding and extraction protocol derived by those skilled in the art based on the bit field allocation length or splicing characteristics during the data composite phase in the early lock preemption stage. When the gateway node confirms that the backend has actually completed execution and enters the billing and settlement stage, the negative numbers retained in the central cache are composited with the system's absolute timestamp during the concurrency control stage. Directly using them for algebraic operations would lead to arithmetic anomalies and financial data errors. Therefore, before performing quota difference calculation, the system first restores the read composite negative numbers using the aforementioned preset data separation rule. Specifically, if the system uses bitwise operations to composite data, the processor uses a logical shift instruction to move the low-order data containing the timestamp out of the register and applies bitwise and mask operations to strip the high-order data, thereby restoring the numerical form containing only the original pre-deducted quota value. This stripping process runs directly in the processor's hardware arithmetic logic unit, avoiding additional memory space overhead and improving the computational efficiency of data unpacking. After restoring the pure pre-deducted quota value, the system invokes arithmetic subtraction logic to subtract the actual consumed quota value returned by the backend from the original pre-deducted quota value to obtain the difference, and triggers the financial call of the account system to complete the quota replenishment. This eliminates the interference of time metadata on billing operations and ensures the correctness of the reconciliation logic. After the replenishment transaction is successfully committed, the system sends an overwrite instruction to the central cache, clearing the cached value and setting it to zero. This operation not only releases the lock state occupied by the key-value pair in the middleware, but also declares the final state of the task in the global architecture.
[0106] By reversing the unpacking of composite variables using preset separation rules, the interference of redundant timestamp data introduced during the concurrent lock maintenance period on arithmetic operations is eliminated. Based on the restored clean quota, differential settlement is performed and the global quota is reset to zero, ensuring the correctness of the arithmetic logic while solidifying the completion state of the anti-duplicate refund / refund mechanism.
[0107] Steps S208-S211 and Figure 1 Steps S105-S108 in the illustrated embodiment are similar and can be found in the descriptions of steps S105-S108, which will not be repeated here.
[0108] In the above embodiments, by avoiding the indefinite stagnation of long-running services due to single-point failures, the self-healing capability of distributed concurrent locks in abnormal scenarios and the efficiency of computing resource utilization are improved.
[0109] The following describes an exemplary asynchronous interface quota anti-duplication and replenishment system 300 based on numerical status provided in the embodiments of this application. Figure 3 This is an exemplary hardware structure diagram of the asynchronous interface quota anti-duplication compensation system 300 based on numerical status provided in this application embodiment.
[0110] In some embodiments, the asynchronous interface quota anti-duplication compensation system 300 based on numerical state is a computer device or includes a computer device. The computer device includes a processor, memory, and a network interface connected via a system bus. The processor of the computer device provides computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores an operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The database of the computer device stores data. The network interface of the computer device is used to communicate with other external terminals or servers via a network connection. In some embodiments, the network interface can be a wired network interface; in some embodiments, the network interface can also be a wireless network interface. When the computer program is executed by the processor, it implements the methods in the embodiments of this application.
[0111] Those skilled in the art will understand that Figure 3 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0112] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit it. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.
[0113] As used in the above embodiments, depending on the context, the term "when..." can be interpreted as "if...", "after...", "in response to determining...", or "in response to detecting...". Similarly, depending on the context, the phrase "when determining..." or "if (the stated condition or event) is interpreted as "if determining...", "in response to determining...", "when (the stated condition or event) is detected", or "in response to detecting (the stated condition or event)".
[0114] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state drive), etc.
[0115] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. This program can be stored in a computer-readable storage medium, and when executed, it can include the processes described in the above method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as ROM or random access memory (RAM), magnetic disks, or optical disks.
Claims
1. A method for preventing duplicate quota replenishment in asynchronous interfaces based on task identifier value state transition, characterized in that, Applied to the request access layer, including: Receive asynchronous task initiation request, calculate pre-deducted quota value and execute quota deduction, set the value corresponding to the generated task identifier in the central cache to a positive number, the positive number representing the pre-deducted quota value; Receive a task result retrieval request carrying the task identifier, read the current cached value corresponding to the task identifier through a composite atomic operation, and perform a conditional update flow: If the current cached value is positive, modify it to the corresponding negative value within the same atomic operation to obtain the processing right of the current request, and forward the request to the backend execution node to obtain the actual execution result; If the current cache value is negative, it is determined that the current task is being processed, and the request to obtain the result is rejected so that it can re-enter the backfill calculation process. If the current cache value is zero, it is determined that the current task has been settled and the quota processing process is skipped; Once the actual execution result returned by the backend execution node is obtained, determine whether the task is completed; If the task is not completed, the cached value will be restored from a negative number to the positive number. If the task has been completed, quota replenishment is performed based on the difference between the pre-deducted quota value and the actual consumed quota value, and the cached value is set to zero.
2. The method according to claim 1, characterized in that, If the current cached value is negative, it is determined that the current task is being processed, and the request to obtain the result is rejected so that it can re-enter the backfilling calculation process. Specifically, this includes: When the current cached value is read as a negative number, the timestamp contained in the negative number is extracted and restored to the timestamp of the last lock; the negative number is formed by combining the absolute timestamp of the system when the original positive number was acquired for processing. Calculate the difference between the current system time and the extracted timestamp; If the difference is less than the preset deadlock timeout threshold, it is determined that the current task is being processed and the request is rejected. If the difference is greater than or equal to the deadlock timeout threshold, it is determined that the original processing process has abnormally caused a deadlock. The negative number is directly updated to a new negative number carrying the latest timestamp of the current system through atomic operations, the processing right is forcibly seized, and the request is forwarded to the backend execution node to obtain the result.
3. The method according to claim 2, characterized in that, If the task has been completed, quota replenishment is performed based on the difference between the pre-deducted quota value and the actual consumed quota value, and the cached value is set to zero. Specifically, this includes: When performing quota difference calculation, the negative number with timestamp is restored to a numerical form containing only the original pre-deducted quota value by using a preset data separation rule; The difference between the original pre-deducted quota value and the actual consumed quota value is calculated, and after the replenishment is completed, the cached value is cleared and set to zero.
4. The method according to claim 1, characterized in that, After determining that the current task is being processed and rejecting the result retrieval request from re-entering the backfill calculation process if the current cache value is negative, the method further includes: Extract the absolute value of the negative number as the computational resource weight for this task; By using a preset backoff algorithm combined with the weight of the computing resources, a local silent duration that is positively correlated with the task's duration is dynamically generated; In the local memory of the current gateway node, write an anti-penetration interception flag with the task identifier as the key and the local silent duration as the lifecycle; During the local silent period, when a query request carrying the same task identifier is received again, it is directly intercepted in the local memory layer and a processing prompt is returned, blocking the network read operation to the central cache.
5. The method according to claim 4, characterized in that, After the step of performing quota replenishment based on the difference between the pre-deducted quota value and the actual consumed quota value, and setting the cached value to zero, if the task has been completed, the method further includes: The current gateway node proactively publishes task finality notifications to other gateway nodes within the same cluster; After receiving the final state notification, other gateway nodes asynchronously clear the corresponding anti-penetration interception flags in their local memory.
6. The method according to claim 1, characterized in that, If the task is not completed, the cached value will be restored from a negative number to a positive number, specifically including: When the actual execution result returned by the backend execution node is obtained, and it is determined that the task is in an intermediate suspended state where some stages have failed and retry is allowed; Extract the actual consumption quota value corresponding to the currently successfully executed stage returned by the backend execution node; Calculate the phased difference between the pre-deducted quota value and the actual consumed quota value, and trigger a phased quota replenishment operation; Through atomic operations, the cached value is updated from the current negative number to a new positive number whose absolute value is less than the original pre-deducted quota value, thereby releasing the locked state for subsequent retry requests to continue querying.
7. The method according to claim 1, characterized in that, If the current cached value is positive, it is modified to the corresponding negative value within the same atomic operation to obtain the processing right for the current request, and the request is forwarded to the backend execution node to obtain the actual execution result. Specifically, this includes: When the current cached value is positive, the high-order binary routing data of the positive number is identified. This positive number is generated by bitwise operations on the pre-deducted quota value and the target route identifier of the backend execution node. The positive number is modified into the corresponding composite negative integer through the same atomic operation to obtain the right to process the current request; Perform a bitwise mask operation on the composite negative integer to extract the high-order data, and decode it into the target route identifier; Dynamic routing rules are constructed using the target route identifier to forward the current task result retrieval request to the corresponding backend execution node.
8. A numerical state-based asynchronous interface quota anti-duplication compensation system, characterized in that, The asynchronous interface quota anti-duplication and replenishment system based on numerical state includes: one or more processors and a memory; the memory is coupled to the one or more processors, the memory is used to store computer program code, the computer program code includes computer instructions, and the one or more processors call the computer instructions to cause the asynchronous interface quota anti-duplication and replenishment system based on numerical state to perform the method as described in any one of claims 1-7.
9. A computer program product containing instructions, characterized in that, When the computer program product is run on the asynchronous interface quota anti-duplication and replenishment system based on numerical status, the asynchronous interface quota anti-duplication and replenishment system based on numerical status performs the method as described in any one of claims 1-7.
10. A computer-readable storage medium comprising instructions, characterized in that, When the instruction is run on the asynchronous interface quota anti-duplication and replenishment system based on numerical status, the asynchronous interface quota anti-duplication and replenishment system based on numerical status performs the method as described in any one of claims 1-7.
