Timeout fuse method for collaborative interruption and resource recycling of multi-class downstream resources
Patent Information
- Application Number
- CN202610710593.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-05-22
- Publication Date
- 2026-08-18
AI Technical Summary
传统数据服务普遍采用同步阻塞式请求处理模式,或即使采用异步处理方式,当特定服务请求因网络延迟、数据库负载异常或外部依赖响应迟缓等因素导致执行时间过长时,将长时间占用调用线程资源,引发线程池耗尽、系统吞吐量下降,并可能进一步产生级联故障,导致数据服务平台及下游业务系统的服务雪崩
Smart Images

Figure CN122601742A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the fields of data service platforms, distributed systems and microservice architectures, and in particular to a timeout circuit breaker method, apparatus, computer-readable storage medium and electronic device for coordinated interruption and resource reclamation of multiple types of downstream resources. Background Technology
[0002] With the widespread adoption of big data and microservice architectures, data service platforms, as crucial hubs connecting data sources and business systems, directly impact overall business continuity through their performance and operational stability. Traditional data services typically employ synchronous blocking request processing models. Even when asynchronous processing is used, if a specific service request takes too long to execute due to network latency, abnormal database load, or slow response from external dependencies, it will consume call thread resources for an extended period, leading to thread pool exhaustion, decreased system throughput, and potentially cascading failures, causing a service avalanche for the data service platform and downstream business systems.
[0003] While existing data service platforms' timeout circuit breakers can interrupt upper-layer calling threads and return timeout responses to upstream, their scope is usually limited to asynchronous tasks or thread execution termination at the programming language level (e.g., via future.cancel(true)). They cannot effectively reach and terminate resources actually occupied in downstream dependent services, database connections, external API calls, script processes, or streaming computing tasks.
[0004] Specifically, when a data service interface call involves operations such as database queries, external HTTP requests, or custom script execution, and is triggered by a circuit breaker due to timeout, even if the thread handling the request is interrupted, slow SQL queries executed on downstream database connections, remote responses still awaited by HTTP clients, background Spark / Flink jobs, or long-running external script processes may continue to consume system resources. This can lead to persistent problems such as downstream resource exhaustion (e.g., database connection pool exhaustion, HTTP connection saturation, thread pool deadlock), memory leaks, or temporary file accumulation even after the upstream circuit breaker has occurred. These resources, which are not terminated and reclaimed in a timely manner, will continue to drag down system performance, reduce overall throughput, and further increase the risk of cascading failures or even system avalanche.
[0005] Therefore, there is an urgent need for a timeout circuit breaker solution that can not only detect and isolate potential slow requests during the lifecycle of a data service request, but also coordinate the interruption and efficient recovery of various downstream resources occupied by the request, so as to effectively ensure the overall stability and reliability of the data service platform. Summary of the Invention
[0006] To overcome the aforementioned deficiencies in the existing technology, this application proposes a novel timeout circuit breaker method and apparatus for coordinated interruption and resource recovery of multiple types of downstream resources. More specifically, this application proposes a timeout circuit breaker method and apparatus for achieving efficient recovery of multiple types of downstream resources through a coordinated interruption mechanism in data service interfaces or business logic processing.
[0007] This invention aims to address the pain point of downstream resources not being effectively terminated and recovered after timeout circuit breakers in existing technologies, and provides a timeout circuit breaker scheme that can proactively identify, isolate and efficiently process slow requests, while ensuring the complete release of related downstream resources.
[0008] The core of this invention lies in establishing a unified cancellation context and a multi-resource collaborative termination protocol. When a request times out, instead of simply interrupting the Java thread, it executes corresponding interruptible actions based on the types of downstream resources used during the request's execution (such as JDBC connections, HTTP client calls, external script processes, streaming computing tasks, etc.), thereby achieving true resource reclamation.
[0009] To achieve the above objectives, the present invention employs the following innovative technical strategies:
[0010] 1. Unified Cancellation Semantics and Cooperative Termination Protocol: A unified cancellation semantic is established across various downstream resources, including threads, databases, network calls, external scripts, and streaming tasks. Each data service request, upon execution, is associated with a unique cancellation context, registering all cancelable resource handles used within that context. Once a timeout is triggered, the circuit breaker controller, based on the predefined cooperative termination protocol, iterates through and invokes the corresponding cancellation adapters for each resource type, executing precise resource interruption operations.
[0011] 2. Resource Handle Registration Mechanism: This solves the problem in existing technologies where downstream resources cannot be truly released after timeout. During the lifecycle of a request, regardless of whether the data source is a database, an external API, or an executed script, the key operation handles generated (such as JDBC Statement, HTTP Client Call, Process PID, Flink Job ID, etc.) are dynamically registered in the request's cancellation context, forming a traceable and manageable list of resources.
[0012] 3. Multi-Resource Type Adapter Design: A series of dedicated cancellation adapters are provided for different types of downstream resources. For example, for database operations, `Statement.cancel()` is called; for HTTP requests, `Call.cancel()` is called; for external processes, a termination signal is sent or `process.destroy()` is called; for streaming tasks, their `job.cancel()` interface is called. This design ensures the effectiveness of interruption operations and the thoroughness of resource reclamation.
[0013] 4. Secondary Compensation and Recovery Mechanism: A verification step for resource recovery results has been added. After the initial collaborative interruption attempt, the system checks the actual recovery status of each resource. For resources that fail to be recovered, a secondary compensation and recovery mechanism will be triggered, employing stronger measures (such as forcibly terminating the process or evictring specific connections from the connection pool) to ensure that the resources are eventually released, thereby improving the determinism of resource recovery.
[0014] 5. Enhanced monitoring metrics: The circuit breaker trigger status, resource reclamation details, and "cancellation success rate" are collected and recorded as core monitoring metrics. This greatly enhances the system's observability, supports rapid problem diagnosis and root cause analysis, and can intuitively reflect the effectiveness of the collaborative interruption mechanism.
[0015] Specifically, this application provides the following technical solutions:
[0016] The first aspect of this application provides a timeout circuit breaker method for coordinated interruption and resource recovery of multiple types of downstream resources. This method is implemented by establishing a unified cancellation context and a multi-resource coordinated termination protocol, such as... Figure 1 As shown, the method includes the following steps:
[0017] S1. Strategy Configuration and Context Creation: Configure a timeout circuit breaker strategy for the data service interface, wherein the timeout circuit breaker strategy includes at least a timeout threshold; upon receiving a call request for the data service interface, create a unique cancellation context object for the request;
[0018] S2. Asynchronous Execution and Resource Registration: Create and execute an asynchronous task that encapsulates the request logic; during the execution of the asynchronous task, dynamically register the handles of various downstream resources used by the request to the cancellation context object;
[0019] S3. Timeout Control and Circuit Breaker Trigger: Monitor the execution status of the asynchronous task, and obtain the execution result of the asynchronous task based on the timeout threshold using a timeout waiting mechanism; if the asynchronous task is not completed within the timeout threshold, a timeout exception is captured and a circuit breaker event is triggered.
[0020] S4. Cooperative Interruption and Resource Recovery: In response to the circuit breaker event, traverse all resource handles registered in the cancellation context object, and perform a cooperative interruption operation through the corresponding resource cancellation adapter according to the type of each resource handle to terminate the operation of the relevant downstream resources;
[0021] S5. Result Verification and Compensation Recovery: Verify the recovery results of downstream resources after the collaborative interruption operation; if any resources fail to be recovered, a secondary compensation recovery mechanism is triggered to perform a more powerful termination and recovery operation on the unrecovered resources.
[0022] S6. Monitoring Records and Effect Evaluation: Record the call monitoring information, resource reclamation details, and circuit breaker effect indicators of the data service interface.
[0023] Furthermore, in the method of this application, the cancellation context object in step S1 is configured to maintain a traceable set of resource handles during the request lifecycle and provide a unified resource registration interface and resource traversal interface to achieve centralized management and collaborative control of multiple types of downstream resources.
[0024] Each resource handle in the resource handle set implements a unified cancellation interface, which is implemented by the resource cancellation adapter on a specific resource type, so that downstream resources of different technology stacks can be interrupted and reclaimed in a consistent manner.
[0025] The cancellation context object is created at the start of the request and bound to the current request execution path. It is destroyed after the request ends normally or a circuit breaker is triggered, to ensure that the resource handle is always in a controllable state throughout the request's lifecycle.
[0026] Furthermore, in the method of this application, the cooperative interruption operation in step S4 follows a predefined cooperative termination protocol. The cooperative termination protocol specifies the interruption order, interruption method, and compensation strategy after interruption failure for different types of resources, so as to achieve the determinism and consistency of resource recovery.
[0027] The collaborative termination protocol prioritizes graceful interruption when performing collaborative interruption operations. If graceful interruption fails, a forced interruption is used in the secondary compensation and recovery mechanism to improve the success rate of resource recovery.
[0028] The execution process of the collaborative termination protocol is uniformly scheduled by the collaborative termination protocol execution engine, and the corresponding resource cancellation adapter is selected based on the resource type to complete the specific interruption operation.
[0029] Furthermore, in the method of this application, the timeout circuit breaker strategy in step S1 also includes configuring differentiated timeout thresholds for different data source types, as well as a function switch to enable or disable the timeout circuit breaker strategy.
[0030] Furthermore, in the method of this application, the asynchronous task in step S2 is created based on an asynchronous programming tool and submitted to a thread pool for execution, and the execution of the asynchronous task does not block the calling thread;
[0031] The types of downstream resources include at least: database connections, external HTTP calls, external RPC calls, scripts or processes, and distributed locks or temporary file handles.
[0032] Furthermore, in the method of this application, in step S3, if the asynchronous task is completed normally within the timeout threshold, the execution result is directly passed to the caller; if a timeout circuit breaker is triggered, circuit breaker response information is returned to the caller, the circuit breaker response information including predefined error codes, error descriptions or degradation response data.
[0033] Furthermore, in the method of this application, the interface of the resource cancellation adapter described in step S4 defines a cancellation method and provides specific implementations for different types of downstream resources, including:
[0034] For database connections, call the statement to cancel the connection method;
[0035] For external HTTP calls, invoke the request cancellation method;
[0036] For external processes, send a termination signal or call the process destruction method;
[0037] For external RPC calls, invoke their cancellation method or close the corresponding communication channel.
[0038] Furthermore, in the method of this application, the strong termination means adopted by the secondary compensation and recycling mechanism in step S5 include: sending a forced termination signal, expelling from the connection pool and forcibly closing the connection.
[0039] Furthermore, in the method of this application, the call monitoring information mentioned in step S6 includes at least: interface call volume, interface response time, number of circuit breaker triggers, number of successful resource reclamation, number of failed resource reclamation, and interface return status; the circuit breaker effect indicators include at least the cancellation success rate.
[0040] The second aspect of this application provides a timeout circuit breaker device for coordinated interruption and resource recovery of multiple types of downstream resources. When the device operates, it implements the steps of the aforementioned timeout circuit breaker method for coordinated interruption and resource recovery of multiple types of downstream resources, such as... Figure 2 As shown, the device includes:
[0041] The strategy configuration and context creation module is used to configure a timeout circuit breaker strategy for the data service interface, wherein the timeout circuit breaker strategy includes at least a timeout threshold; and when a call request to the data service interface is received, a unique cancellation context object is created for the request.
[0042] The asynchronous execution and resource registration module is used to create and execute asynchronous tasks that encapsulate request logic; during the execution of the asynchronous task, the handles of various downstream resources used by the request are dynamically registered to the cancellation context object;
[0043] The timeout control and circuit breaker triggering module is used to monitor the execution status of the asynchronous task, and obtain the execution result of the asynchronous task based on the timeout time threshold using a timeout waiting mechanism; if the asynchronous task is not completed within the timeout time threshold, a timeout exception is captured and a circuit breaker event is triggered.
[0044] The coordinated interruption and resource reclamation module is used to respond to the circuit breaker event, traverse all resource handles registered in the cancellation context object, and perform coordinated interruption operations through the corresponding resource cancellation adapter according to the type of each resource handle to terminate the operation of related downstream resources;
[0045] The result verification and compensation recovery module is used to verify the recovery results of downstream resources after the collaborative interruption operation. If any resources fail to be recovered, a secondary compensation recovery mechanism is triggered to perform a more powerful termination and recovery operation on the unrecovered resources.
[0046] The monitoring and effect evaluation module is used to record the call monitoring information, resource reclamation details, and circuit breaker effect indicators of the data service interface.
[0047] A third aspect of this application provides an electronic device, including: a memory and a processor;
[0048] Memory: Used to store computer programs;
[0049] Processor: Used to execute the computer program to implement the steps of the aforementioned timeout circuit breaker method for coordinated interruption and resource reclamation of multiple types of downstream resources.
[0050] A fourth aspect of this application provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, it implements the steps of the aforementioned timeout circuit breaker method for coordinated interruption and resource reclamation for multiple types of downstream resources.
[0051] In summary, compared with the prior art, the solution of this application has the following technical advantages:
[0052] (1) This solution systematically solves the problems of stability, efficiency and thoroughness of resource recycling of traditional data service interfaces in complex distributed scenarios through the innovative design of the whole link of “unified cancellation semantics → resource handle registration → collaborative interruption → result verification → compensation recycling → detailed monitoring”, and provides more reliable and efficient technical support for data service platforms in high-concurrency and high-availability scenarios.
[0053] (2) Enhancing the thoroughness and certainty of resource recovery: By establishing a unified cancellation context and a multi-resource collaborative termination protocol, this solution can perform interruption operations at the downstream resource level, such as canceling database queries and terminating HTTP requests, ensuring the thoroughness of resource recovery and avoiding the "false circuit breaker" problem caused by upper-level circuit breakers but lower-level resources still being occupied. The secondary compensation recovery mechanism further improves the certainty of resource recovery.
[0054] (3) Eliminate resource leakage and invalid occupation: Effectively solves the problems of connection pool exhaustion, thread pool deadlock, memory leakage or temporary file accumulation caused by the failure of downstream resources to terminate in time in the existing technology, fundamentally eliminates resource leakage and invalid occupation, and significantly optimizes system resource utilization.
[0055] (4) Significantly improve system stability and throughput: By efficiently recovering and releasing various occupied resources, the system resources can be quickly turned over, thereby avoiding resource bottlenecks and significantly improving the overall stability of the data service platform and the throughput in high-concurrency scenarios.
[0056] (5) Reduce the risk of avalanche in complex distributed systems: By bringing the circuit breaker point down to the multi-dimensional resource level, the cascading failure propagation path caused by slow requests is cut off from the source, effectively isolating the scope of the failure impact, thereby significantly reducing the risk of avalanche in the data service platform and downstream calling systems.
[0057] (6) Enhance system observability and self-healing capabilities: The newly added resource recycling details and monitoring indicators such as “cancellation success rate” enable system maintenance personnel to clearly understand the actual effects of circuit breaking and resource recycling, providing accurate data support for rapid problem diagnosis and optimization strategies, and improving the system’s self-healing and automated processing capabilities.
[0058] (7) Supports unified circuit breaker management across multiple dimensions and technology stacks: Through a unified cancellation context and an extensible resource cancellation adapter design, this solution can seamlessly support downstream resources of various technology stacks such as JDBC, HTTP, RPC, and process management, realizing unified management of circuit breaker policies across technology stacks and simplifying system architecture and operation and maintenance complexity. Attached Figure Description
[0059] To more clearly illustrate the technical solution of this application, the accompanying drawings involved in the description of this invention will be briefly introduced below. It should be noted that the drawings only show some embodiments of the invention. For those skilled in the art, other related drawings can be derived from these drawings without creative effort.
[0060] Figure 1 This is a flowchart illustrating the operational steps of the timeout circuit breaker method for coordinated interruption and resource recovery of multiple types of downstream resources in this application.
[0061] Figure 2 This is a structural diagram of the timeout circuit breaker device for coordinated interruption and resource recovery of multiple downstream resources, as described in this application.
[0062] Figure 3 This is a schematic diagram illustrating the overall implementation process of the embodiments of this application.
[0063] Figure 4 This is a schematic diagram of the execution process of multiple types of downstream resource collaborative interruption and resource recovery in the embodiment of this application.
[0064] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0065] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. It should be understood that the described embodiments are only some embodiments of this application, and not all embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the protection scope of this application.
[0066] In this document, the term "comprising" and any variations thereof (such as "including," "including," etc.) are open-ended expressions and should be understood as "including but not limited to," meaning that the listed content is not exhaustive and may include other content not explicitly mentioned. The term "based on" should be understood as "at least partially based on," meaning that the basis or condition referred to may not be the only factor and may involve other relevant factors. The term "one embodiment" should be understood as "at least one embodiment," meaning that the described embodiment is not the only possible implementation, and other similar embodiments may exist.
[0067] In this application, the terms "a" and "a plurality of" are used to modify related elements or features, and their expression is illustrative rather than restrictive. Unless otherwise expressly stated in the context, "a" should be understood as "at least one," and "a plurality of" should be understood as "at least two." Those skilled in the art should reasonably interpret these terms based on the semantic and logical relationships of the context to ensure that they cover the possibility of "one or more."
[0068] This invention provides the following technical solution:
[0069] In a first aspect, the present invention provides a timeout circuit breaker method for coordinated interruption and resource recovery of multiple types of downstream resources, the method comprising:
[0070] S1. Strategy Configuration and Context Creation: On the data service platform, a timeout circuit breaker strategy is configured for the data service interface, the strategy including at least a timeout threshold; and when a call request to the data service interface is received, a unique cancellation context object is created for the request.
[0071] S2. Asynchronous Execution and Resource Registration: Use asynchronous programming tools to create and execute asynchronous tasks that encapsulate request logic; during the execution of the asynchronous task, dynamically register the handles of various downstream resources used by the request to the cancellation context object;
[0072] S3. Timeout Control and Circuit Breaker Trigger: Monitor the execution status of the asynchronous task, and obtain the execution result of the asynchronous task based on the timeout threshold using a timeout waiting mechanism; if the asynchronous task is not completed within the timeout threshold, a timeout exception is captured, and a unified circuit breaker event is triggered.
[0073] S4. Cooperative Interruption and Resource Recovery: In response to the circuit breaker event, traverse all resource handles registered in the cancellation context object, and perform a cooperative interruption operation through the corresponding resource cancellation adapter according to the type of each resource handle to terminate the operation of the relevant downstream resources;
[0074] S5. Result Verification and Compensation Recovery: Verify the recovery result of downstream resources after the collaborative interruption operation; if any resources fail to be recovered, a secondary compensation recovery mechanism is triggered to perform a more powerful termination and recovery operation on the unrecovered resources.
[0075] S6. Monitoring Records and Effect Evaluation: Record the call monitoring information, resource reclamation details, and circuit breaker effect indicators of the data service interface. The circuit breaker effect indicators include at least the cancellation success rate.
[0076] Furthermore, the downstream resource types include at least: database connections (such as JDBC Statements), external HTTP calls (such as HTTP Client Calls), external RPC calls (such as RPC Futures), scripts or processes (such as process PIDs, Job IDs), and distributed locks or temporary file handles.
[0077] Furthermore, the resource cancellation adapter interface defines a cancellation method `cancel()` and provides specific implementations for different types of downstream resources, such as:
[0078] For a JDBC Statement, call statement.cancel();
[0079] For HTTP Client Calls, call.cancel();
[0080] For the PID of an external process, send a termination signal or call process.destroy();
[0081] For an RPC Future, call its cancel() method or close the corresponding communication channel.
[0082] Furthermore, the specific method for creating the asynchronous task in step S2 includes: creating the asynchronous task based on an asynchronous programming tool, and submitting the asynchronous task to a thread pool for execution. The execution of the asynchronous task does not block the calling thread. The asynchronous programming tool can be CompletableFuture.supplyAsync, and the asynchronous task can encapsulate the request logic using Callable or Runnable.
[0083] Furthermore, in step S5, if the asynchronous task completes normally, the execution result is directly passed to the caller.
[0084] Furthermore, in step S5, after executing the timeout circuit breaker step, circuit breaker response information is returned to the caller. The circuit breaker response information includes predefined error codes, error descriptions, or degradation response data.
[0085] Furthermore, the monitoring information mentioned in step S6 includes at least: interface call volume, interface response time, number of circuit breaker triggers, number of successful resource reclamation, number of failed resource reclamation, and interface return status, wherein the interface return status includes at least success, failure, and timeout circuit breaker.
[0086] Secondly, the present invention provides a timeout circuit breaker device for coordinated interruption and resource recovery of multiple types of downstream resources. The device, when operating, implements the aforementioned data service interface timeout circuit breaker method. The device includes:
[0087] The strategy configuration and context creation module is used to configure timeout circuit breaker strategies for data service interfaces on the data service platform, wherein the strategy includes at least a timeout threshold; and to create a unique cancellation context object for the request when a call request to the data service interface is received.
[0088] The asynchronous execution and resource registration module is used to create and execute asynchronous tasks that encapsulate request logic using asynchronous programming tools; during the execution of the asynchronous task, the handles of various downstream resources used by the request are dynamically registered to the cancellation context object;
[0089] The timeout control and circuit breaker triggering module is used to monitor the execution status of the asynchronous task, and obtain the execution result of the asynchronous task based on the timeout time threshold using a timeout waiting mechanism; if the asynchronous task is not completed within the timeout time threshold, a timeout exception is captured and a unified circuit breaker event is triggered.
[0090] The coordinated interruption and resource reclamation module is used to respond to the circuit breaker event, traverse all resource handles registered in the cancellation context object, and perform coordinated interruption operations through the corresponding resource cancellation adapter according to the type of each resource handle to terminate the operation of related downstream resources;
[0091] The result verification and compensation recovery module is used to verify the recovery results of downstream resources after the collaborative interruption operation; if any resources fail to be recovered, a secondary compensation recovery mechanism is triggered to perform a stronger termination and recovery operation on the unrecovered resources.
[0092] The monitoring and effect evaluation module is used to record the call monitoring information, resource reclamation details, and circuit breaker effect indicators of the data service interface.
[0093] To more clearly illustrate the technical solution of this application, the following will provide further explanation through specific scenario embodiments.
[0094] Example 1: A timeout circuit breaker method for coordinated interruption and resource reclamation of data service interfaces for multiple types of downstream resources.
[0095] Figure 3 This is a flowchart illustrating the overall implementation of the timeout circuit breaker method for the data service interface in this application. Figure 4 This is a schematic diagram illustrating the execution flow of multiple downstream resource collaborative interruptions and resource reclamation in the embodiments of this application, such as... Figure 3 and Figure 4As shown, the detailed implementation process of this method is as follows:
[0096] S1. Strategy Configuration and Context Creation:
[0097] Policy Configuration: The data service platform provides an interface definition module and a policy configuration module, allowing users to configure timeout circuit breaker policies for data service interfaces. This policy must include at least one timeout threshold to limit the maximum allowed execution time of the data service interface. Users can configure differentiated thresholds for different data source types (such as data table access, custom SQL execution, and external interface calls), and a function switch is provided to enable or disable this policy.
[0098] Context Creation: When a data service platform receives a request to call a specific data service interface, the interface execution engine immediately creates a unique cancellation context object for that request. This context object serves as a lifecycle companion to the request, used to track and manage all downstream cancelable resources that the request may occupy during execution. For example, mechanisms such as ThreadLocal, RequestContext, or the Reactor Context of a reactive programming framework can be used to associate this cancellation context with the execution thread or logic flow of the current request.
[0099] S2. Asynchronous Execution and Resource Registration:
[0100] Asynchronous execution: The interface execution engine uses asynchronous programming tools (such as Java's CompletableFuture.supplyAsync) to create and execute an asynchronous task. This asynchronous task encapsulates the specific data service interface request logic (such as database queries, calling external RESTful APIs, executing shell scripts, etc.) and is submitted to a dedicated thread pool for execution, which does not block the upper-level calling thread.
[0101] Resource registration: During the execution of an asynchronous task, whenever the request acquires or creates a downstream resource that may run for a long time and can be interrupted externally, the handle or ID of the resource is dynamically registered to the cancellation context object of the current request.
[0102] For example, when a database query is executed, a java.sql.Statement object (which provides a cancel() method) is registered.
[0103] When an external HTTP request is made, objects such as okhttp3.Call or java.net.http.HttpRequest associated with CompletableFuture will be registered.
[0104] When an external shell script or process is started, its process ID (PID) or Process object is registered.
[0105] When a distributed streaming computing task is submitted, its job ID is registered.
[0106] When a distributed lock is acquired or a temporary file is created, the corresponding lock handle or file path will also be registered.
[0107] To achieve versatility, a CancelableResource interface can be defined, and all cancelable resources can implement this interface and be registered using the adapter pattern.
[0108] S3, Timeout Control and Circuit Breaker Trigger:
[0109] After the asynchronous task starts, the caller will not wait directly for future.get(), but will use the future.get(timeout, TimeUnit.SECONDS) method to block and attempt to obtain the execution result of the data service interface within a time limit, where timeout is the timeout threshold configured in the S1 phase.
[0110] Normal completion: If the asynchronous task completes successfully and returns a result within the timeout period, the result is passed to the caller.
[0111] Circuit breaking triggered by timeout: If an asynchronous task fails to complete within the timeout period, the get() method will throw a java.util.concurrent.TimeoutException. Upon catching this exception, the system will trigger a unified circuit breaker event, indicating that the request has timed out and a coordinated interruption and resource reclamation process needs to be initiated.
[0112] S4. Coordinated Interruption and Resource Recovery:
[0113] In response to a circuit breaker event triggered in S3, the circuit breaker controller obtains the cancellation context object for the current request.
[0114] The circuit breaker controller iterates through all CancelableResource handles registered in the cancellation context.
[0115] For each registered resource handle, the circuit breaker controller will find and call the corresponding resource cancellation adapter based on its type (such as JDBC Statement, HTTPCall, process PID, etc.).
[0116] Resource cancellation adapters are predefined logical components used to perform interruption operations for specific resource types, including but not limited to the following types:
[0117] JDBC adapter: Calls the registered statement.cancel() method to attempt to interrupt the execution of SQL on the database side.
[0118] HTTP adapter: Calls the registered call.cancel() method to interrupt a network request that is in progress by the HTTP client.
[0119] RPC adapter: Interrupt the RPC call by calling the registered future.cancel() method or through the communication channel closing mechanism.
[0120] Process adapter: For a registered process PID or Process object, send a termination signal (such as SIGTERM in Linux) or call the process.destroy() method to attempt to gracefully terminate the external process.
[0121] Streaming task adapter: Cancels a distributed streaming computing task by calling the registered job.cancel(jobId) through the management API.
[0122] This step ensures that not only are the upper-level Java threads interrupted, but the computing, network, or I / O resources actually used by their downstream dependencies are also actively and precisely terminated.
[0123] S5. Result Verification and Compensation Recovery:
[0124] After the coordinated interrupt operation of S4 is executed, the system does not immediately assume that the resources have been fully reclaimed. The circuit breaker controller will further verify the reclamation results of each downstream resource.
[0125] For example, for a terminated process, check if it has truly exited; for a canceled database query, check if the database connection has been restored; for a canceled HTTP request, confirm if the relevant connection has been released.
[0126] Secondary compensation and reclamation: If the verification finds that some resources have not been successfully reclaimed (for example, the process has not exited after receiving the termination signal, or the database connection is still busy), the system will trigger the secondary compensation and reclamation mechanism.
[0127] The secondary compensation and recycling mechanism will employ more forceful measures: for example, for stubborn external processes, a SIGKILL signal (process.destroyForcibly()) can be sent; for database connections that are suspected of being dead, they can be evicted from the connection pool and forcibly closed.
[0128] This step increases the certainty of resource recovery and minimizes the risk of resource leakage.
[0129] S6. Monitoring Records and Effectiveness Evaluation:
[0130] The platform will record the call monitoring information of each data service API in real time, including: API call volume, API response time, number of circuit breaker triggers, and API return status (success, failure, timeout circuit breaker, etc.).
[0131] Effectiveness Evaluation: This plan will also record detailed resource recovery information and circuit breaker performance indicators.
[0132] (1) Resource recovery details: Record which resources were attempted to be recovered each time the circuit breaker was triggered, their type, and the result of the recovery attempt (success, failure, successful compensation, etc.).
[0133] (2) Cancellation success rate: Calculate and record the cancellation success rate of specific types of resources (such as JDBC Statement and HTTP Call) as a key indicator for evaluating the effectiveness of the collaborative interruption mechanism.
[0134] (3) Resource recovery time: Record the time required from the circuit breaker being triggered to the confirmation of the recovery of all resources.
[0135] This wealth of monitoring data provides users with data support to understand the operational status of the interface, the effectiveness of the collaborative interruption mechanism, and to further optimize strategies.
[0136] Through the above steps, a timeout circuit breaker mechanism for collaborative interruption and resource recovery of data service interfaces for multiple types of downstream resources is constructed and implemented.
[0137] Example 2: A timeout circuit breaker device for coordinated interruption and resource recovery of data service interfaces for multiple types of downstream resources.
[0138] When this device is running, it implements the steps of the aforementioned data service interface timeout circuit breaker method.
[0139] This device includes the following modules:
[0140] The strategy configuration and context creation module is used to create data service interfaces within the data service platform using data tables, custom SQL, or external interfaces. It allows users to configure timeout circuit breaker policies for these interfaces, including setting timeout thresholds and enabling / disabling the timeout circuit breaker switch. Additionally, upon receiving a request to call a data service interface, this module is responsible for creating a unique cancellation context object for that request.
[0141] The asynchronous execution and resource registration module receives requests from data service interfaces and uses asynchronous programming tools (such as CompletableFuture.supplyAsync) to create asynchronous tasks to execute the request logic of the data service interfaces. This module is also responsible for dynamically registering handles of various downstream resources used in the request to the cancellation context object during the execution of the asynchronous task.
[0142] Timeout Control and Circuit Breaker Trigger Module: Used to monitor the execution status of asynchronous tasks. When the data service interface is configured with a timeout circuit breaker policy and is enabled, this module waits for the result of the asynchronous task in a blocking manner through the Future.get(timeout, TimeUnit.SECONDS) method, and catches the TimeoutException exception in real time when a timeout occurs, and then triggers a unified circuit breaker event.
[0143] The coordinated interruption and resource reclamation module is used to respond to the circuit breaker event, obtain and traverse all resource handles registered in the cancellation context object, and perform coordinated interruption operations through the corresponding resource cancellation adapter according to the type of each resource handle to terminate the operation of the relevant downstream resources.
[0144] The result verification and compensation recovery module is used to verify the recovery results of downstream resources after a collaborative interruption operation. If the verification finds that some resources have failed to be recovered, this module is responsible for triggering a secondary compensation recovery mechanism to perform a more forceful termination and recovery operation on the unrecovered resources.
[0145] Monitoring and Performance Evaluation Module: Responsible for collecting and recording monitoring data such as call volume, response time, return status, resource reclamation details, and circuit breaker performance indicators (including cancellation success rate) of data service interfaces.
[0146] The flowcharts and block diagrams in the accompanying drawings illustrate possible implementations of apparatus, methods, and computer program products according to various embodiments of this application, including architecture, functionality, and operation. In these figures, each block may represent a module, program segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should be noted that each block in the block diagrams and / or flowcharts, and combinations thereof, can be implemented using either a dedicated hardware-based system or a combination of dedicated hardware and computer instructions to achieve the specified function or operation.
[0147] like Figure 5 As shown, embodiments of this application also disclose an electronic device, including: a processor 310, a communication interface 320, a memory 330 for storing a processor-executable computer program, and a communication bus 340. The processor 310, communication interface 320, and memory 330 communicate with each other via the communication bus 340. The processor 310 executes the executable computer program to implement the steps of the aforementioned timeout circuit breaker method for coordinated interruption and resource reclamation for multiple types of downstream resources.
[0148] It is understood that, in addition to memory and a processor, this electronic device may also include input devices (such as a keyboard), output devices (such as a display), and other communication modules. These input devices, output devices, and other communication modules all communicate with the processor through I / O interfaces (i.e., input / output interfaces).
[0149] The operations described in this application can be implemented by writing computer program code using one or more programming languages or a combination thereof. The programming languages include, but are not limited to, the following types:
[0150] Object-oriented programming languages, such as Java, Smalltalk, C++, etc.
[0151] Conventional procedural programming languages, such as "C" or similar programming languages.
[0152] The execution methods of program code include, but are not limited to:
[0153] It runs entirely on the user's computer;
[0154] Part of it executes on the user's computer, and part of it executes on a remote computer;
[0155] Execute as a standalone software package;
[0156] It is executed entirely on a remote computer or server.
[0157] In scenarios involving remote computers, the remote computer can connect to the user's computer via any type of network, including but not limited to local area networks (LANs) or wide area networks (WANs). Furthermore, the remote computer can also connect to external computers through an internet service provider, for example, by utilizing the internet for connection.
[0158] Furthermore, this application also discloses a computer-readable storage medium, wherein when the instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is able to perform the various steps of the timeout circuit breaker method for coordinated interruption and resource reclamation for multiple types of downstream resources disclosed in this application.
[0159] In the context of this application, a computer-readable storage medium refers to a tangible medium capable of storing computer program code and related data. Specific examples include, but are not limited to, the following:
[0160] (1) Portable computer disk: such as floppy disks and other removable magnetic storage media.
[0161] (2) Hard disk: including mechanical hard disks and solid-state hard disks and other fixed storage devices.
[0162] (3) Random Access Memory (RAM): A volatile storage medium used for temporary storage of data and program code.
[0163] (4) Read-only memory (ROM): a non-volatile storage medium used to store fixed programs and data.
[0164] (5) Erasable programmable read-only memory (EPROM) or flash memory: non-volatile storage media that supports multiple erasures and reprogrammings.
[0165] (6) Fiber optic storage devices: storage media based on fiber optic technology.
[0166] (7) Portable compact disc read-only memory (CD-ROM): a read-only medium that stores data in the form of an optical disc.
[0167] (8) Optical storage devices: such as DVDs, Blu-ray discs and other storage media based on optical principles.
[0168] (9) Magnetic storage devices: such as magnetic tapes, disks and other storage media based on magnetic principles.
[0169] (10) Any suitable combination of the above: for example, combining multiple storage media to meet different storage needs.
[0170] These computer-readable storage media can be used to store the program code and related data described in this application to support program execution and persistent data storage.
[0171] Specifically, according to embodiments of this application, the processes described in the flowcharts can be implemented as computer software programs. For example, embodiments of this application relate to a computer program product comprising a computer program carried on a non-transitory computer-readable medium. This computer program includes program code for executing the timeout circuit breaker method for coordinated interruption and resource reclamation of multiple types of downstream resources disclosed in this application. When the computer program is executed by a processing device, it can achieve the functions defined in the embodiments of this application.
[0172] While the foregoing discussion contains several specific implementation details, these details should not be construed as limiting the scope of this application. The above description is merely a preferred embodiment of this application and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of this application is not limited to technical solutions formed by specific combinations of the above-described technical features. Furthermore, this application should also cover other technical solutions formed by any combination of the above-described technical features or their equivalents without departing from the foregoing disclosed concept.
[0173] Those skilled in the art should also understand that modifications can be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features, without departing from the spirit and scope of the technical solutions of the embodiments of this application. These modifications or substitutions will not cause the essence of the corresponding technical solutions to deviate from the core spirit and scope of the technical solutions of the embodiments of this application.
Claims
1. A timeout circuit breaker method for coordinated interruption and resource recovery of multiple downstream resources, characterized in that, The method is achieved by establishing a unified cancellation context and a multi-resource collaborative termination protocol, specifically including the following steps: S1. Strategy Configuration and Context Creation: Configure a timeout circuit breaker strategy for the data service interface, wherein the timeout circuit breaker strategy includes at least a timeout threshold; upon receiving a call request for the data service interface, create a unique cancellation context object for the request; S2. Asynchronous Execution and Resource Registration: Create and execute an asynchronous task that encapsulates the request logic; during the execution of the asynchronous task, dynamically register the handles of various downstream resources used by the request to the cancellation context object; S3. Timeout Control and Circuit Breaker Trigger: Monitor the execution status of the asynchronous task, and obtain the execution result of the asynchronous task based on the timeout threshold using a timeout waiting mechanism; if the asynchronous task is not completed within the timeout threshold, a timeout exception is captured and a circuit breaker event is triggered. S4. Cooperative Interruption and Resource Recovery: In response to the circuit breaker event, traverse all resource handles registered in the cancellation context object, and perform a cooperative interruption operation through the corresponding resource cancellation adapter according to the type of each resource handle to terminate the operation of the relevant downstream resources; S5. Result Verification and Compensation Recovery: Verify the recovery results of downstream resources after the collaborative interruption operation; if any resources fail to be recovered, a secondary compensation recovery mechanism is triggered to perform a more powerful termination and recovery operation on the unrecovered resources. S6. Monitoring Records and Effect Evaluation: Record the call monitoring information, resource reclamation details, and circuit breaker effect indicators of the data service interface.
2. The method according to claim 1, characterized in that, The cancellation context object described in step S1 is configured to maintain a traceable set of resource handles during the request lifecycle and provide a unified resource registration interface and resource traversal interface to achieve centralized management and collaborative control of multiple types of downstream resources. Each resource handle in the resource handle set implements a unified cancellation interface, which is implemented by the resource cancellation adapter on a specific resource type, so that downstream resources of different technology stacks can be interrupted and reclaimed in a consistent manner. The cancellation context object is created at the start of the request and bound to the current request execution path. It is destroyed after the request ends normally or a circuit breaker is triggered, to ensure that the resource handle is always in a controllable state throughout the request's lifecycle.
3. The method according to claim 1, characterized in that, The collaborative interruption operation in step S4 follows a predefined collaborative termination protocol. The collaborative termination protocol specifies the interruption order, interruption method, and compensation strategy after interruption failure for different types of resources, so as to achieve determinism and consistency in resource recovery. The collaborative termination protocol prioritizes graceful interruption when performing collaborative interruption operations. If graceful interruption fails, a forced interruption is used in the secondary compensation and recovery mechanism to improve the success rate of resource recovery. The execution process of the collaborative termination protocol is uniformly scheduled by the collaborative termination protocol execution engine, and the corresponding resource cancellation adapter is selected based on the resource type to complete the specific interruption operation.
4. The method according to claim 1, characterized in that, The timeout circuit breaker strategy described in step S1 also includes configuring differentiated timeout thresholds for different data source types, as well as a function switch to enable or disable the timeout circuit breaker strategy.
5. The method according to claim 1, characterized in that, The asynchronous task described in step S2 is created based on an asynchronous programming tool and submitted to a thread pool for execution. The execution of the asynchronous task does not block the calling thread. The types of downstream resources include at least: database connections, external HTTP calls, external RPC calls, scripts or processes, and distributed locks or temporary file handles.
6. The method according to claim 1, characterized in that, In step S3, if the asynchronous task is completed normally within the timeout threshold, the execution result is directly passed to the caller; if a timeout circuit breaker is triggered, circuit breaker response information is returned to the caller, which includes predefined error codes, error descriptions, or degradation response data.
7. The method according to claim 1, characterized in that, The resource cancellation adapter interface described in step S4 defines cancellation methods and provides specific implementations for different types of downstream resources, including: For database connections, call the statement to cancel the connection method; For external HTTP calls, invoke the request cancellation method; For external processes, send a termination signal or call the process destruction method; For external RPC calls, invoke their cancellation method or close the corresponding communication channel.
8. The method according to claim 1, characterized in that, The strong termination methods used in the secondary compensation and recovery mechanism in step S5 include: sending a forced termination signal, expelling from the connection pool and forcibly closing the connection.
9. The method according to claim 1, characterized in that, The monitoring information mentioned in step S6 includes at least: interface call volume, interface response time, number of circuit breaker triggers, number of successful resource reclamation, number of failed resource reclamation, and interface return status; the circuit breaker effectiveness indicators include at least the cancellation success rate.
10. A timeout circuit breaker device for coordinated interruption and resource recovery of multiple downstream resources, characterized in that, The steps of implementing the timeout circuit breaker method for coordinated interruption and resource recovery for multiple types of downstream resources as described in any one of claims 1-9 when the device is in operation include: The strategy configuration and context creation module is used to configure a timeout circuit breaker strategy for the data service interface, wherein the timeout circuit breaker strategy includes at least a timeout threshold; and when a call request to the data service interface is received, a unique cancellation context object is created for the request. The asynchronous execution and resource registration module is used to create and execute asynchronous tasks that encapsulate request logic; during the execution of the asynchronous task, the handles of various downstream resources used by the request are dynamically registered to the cancellation context object; The timeout control and circuit breaker triggering module is used to monitor the execution status of the asynchronous task, and obtain the execution result of the asynchronous task based on the timeout time threshold using a timeout waiting mechanism; if the asynchronous task is not completed within the timeout time threshold, a timeout exception is captured and a circuit breaker event is triggered. The coordinated interruption and resource reclamation module is used to respond to the circuit breaker event, traverse all resource handles registered in the cancellation context object, and perform coordinated interruption operations through the corresponding resource cancellation adapter according to the type of each resource handle to terminate the operation of related downstream resources; The result verification and compensation recovery module is used to verify the recovery results of downstream resources after the collaborative interruption operation. If any resources fail to be recovered, a secondary compensation recovery mechanism is triggered to perform a more powerful termination and recovery operation on the unrecovered resources. The monitoring and effect evaluation module is used to record the call monitoring information, resource reclamation details, and circuit breaker effect indicators of the data service interface.