State transfer method and related device

CN117170777BActive Publication Date: 2026-11-03SHANGHAI BILIBILI TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311143284.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-09-05
Publication Date
2026-11-03
Estimated Expiration
2043-09-05

AI Technical Summary

Technical Problem

In distributed systems, existing technologies cannot effectively perform state transitions across state machine nodes, resulting in high complexity of state transitions, a lack of universal methods for persisting state data, and insufficient decoupling solutions for multi-layer state machines, which affects overall performance.

Method used

Define a standardized state transition interface, adapt to different types of databases through a proxy service, realize state transitions across state machine nodes, and introduce a decoupling scheme between parent and child state machines to ensure collaborative work between state machine nodes.

Benefits of technology

It realizes state transitions across state machine nodes, improves the accuracy of state execution and transitions for complex tasks in distributed systems, reduces the complexity of state transitions, and enhances the resource utilization efficiency and overall performance of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117170777B_ABST
    Figure CN117170777B_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide a state transition method, applied to a distributed system comprising a plurality of state machine nodes; the method comprises: obtaining a state table and a state transition sequence; initializing a first state machine node according to a first state; executing action logic of the first state by calling the initialized first state machine node; in the case that the action logic of the first state is executed successfully, determining a second state machine node from the plurality of state machine nodes; determining a second state after the first state according to the state table and the state transition sequence; initializing the second state machine node according to the second state; and executing action logic of the second state by calling the initialized second state machine node. The technical solution of the embodiments of the present application can perform state transition across state machine nodes, thereby accurately controlling state execution and state transition of complex tasks in a large-scale distributed system.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a state transition method and related equipment. Background Technology

[0002] As software systems continue to evolve, their complexity increases. Task execution needs to be divided into multiple states, each with different actions (specific execution logic), such as TCP requests, database operations, video processing, and file operations. The execution of these state-action logics and the transitions between states can be handled using a state machine. A state machine is a mathematical computational model used to describe a finite number of states within a system, as well as the transitions and actions between these states.

[0003] Currently, all state transitions occur within a single state machine. However, distributed systems involve multiple state machines, making it impossible to transition between them. Summary of the Invention

[0004] This application provides a state transition method, apparatus, electronic device, and computer-readable storage medium to solve or alleviate one or more of the technical problems mentioned above.

[0005] In a first aspect, embodiments of this application provide a state transition method applied to a distributed system including multiple state machine nodes; the method includes:

[0006] Obtain the state table and state transition order, wherein the state table includes multiple states of the task;

[0007] The first state machine node is initialized according to the first state, and the first state machine node is one of the plurality of state machine nodes;

[0008] The action logic of the first state is executed by calling the initialized first state machine node;

[0009] If the action logic of the first state is successfully executed, the second state machine node is determined from the plurality of state machine nodes;

[0010] Based on the state table and the state transition order, determine the second state following the first state;

[0011] The second state machine node is initialized according to the second state;

[0012] The action logic of the second state is executed by calling the initialized second state machine node.

[0013] Secondly, embodiments of this application provide a state transition device, the device comprising:

[0014] An acquisition module is used to acquire a state table and a state transition order, wherein the state table includes multiple states of the task;

[0015] The first initialization module is used to initialize a first state machine node according to a first state, wherein the first state machine node is one of the plurality of state machine nodes;

[0016] The first execution module is used to execute the action logic of the first state by calling the initialized first state machine node;

[0017] The first determining module is used to determine the second state machine node from the plurality of state machine nodes if the action logic of the first state is successfully executed.

[0018] The second determining module is used to determine the second state after the first state based on the state table and the state transition order;

[0019] The second initialization module is used to initialize the second state machine node according to the second state;

[0020] The second execution module is used to execute the action logic of the second state by calling the initialized second state machine node.

[0021] Thirdly, embodiments of this application provide an electronic device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the aforementioned fault handling method for a distributed system.

[0022] Fourthly, embodiments of this application provide a computer-readable storage medium that stores computer instructions, wherein when the computer instructions are executed on a computer, the methods in any of the above-described embodiments are performed.

[0023] The embodiments of this application employing the above-described technical solution may have the following advantages:

[0024] The state table and state transition order are obtained to determine the multiple states corresponding to the task and the transition order between states. A first state machine node is selected from multiple state machine nodes and initialized according to the first state. The action logic of the first state is executed by calling the initialized first state machine node. If the action logic of the first state is successfully executed, a second state is determined and a second state machine node is selected from multiple state machine nodes. The second state machine node is initialized according to the second state and the action logic of the second state is executed by calling the initialized second state machine node. It can be seen that the embodiments of this application can perform state transitions across state machine nodes, thereby enabling precise control of the state execution and state transitions of complex tasks in large-scale distributed systems.

[0025] The above overview is for illustrative purposes only and is not intended to be limiting in any way. In addition to the illustrative aspects, embodiments, and features described above, further aspects, embodiments, and features of this application will become readily apparent from the accompanying drawings and the following detailed description. Attached Figure Description

[0026] The accompanying drawings exemplify embodiments and form part of the specification, serving together with the textual description to explain exemplary implementations of the embodiments. The illustrated embodiments are for illustrative purposes only and do not limit the scope of the claims. Throughout the drawings, the same reference numerals refer to similar but not necessarily identical elements.

[0027] Figure 1 This diagram schematically illustrates the operating environment of a state transition method according to an embodiment of the present application.

[0028] Figure 2 A flowchart illustrating a state transition method according to another embodiment of this application is shown schematically;

[0029] Figure 3 Schematic illustration Figure 2 Sub-step of step S206;

[0030] Figure 4 A schematic diagram illustrating a new flowchart of a state transition method according to another embodiment of this application is provided.

[0031] Figure 5 A schematic diagram illustrating a new flowchart of a state transition method according to another embodiment of this application is provided.

[0032] Figure 6 A schematic diagram illustrating a new flowchart of a state transition method according to another embodiment of this application is provided.

[0033] Figure 7A schematic diagram illustrating a new flowchart of a state transition method according to another embodiment of this application is provided.

[0034] Figure 8 This schematically illustrates a directed acyclic graph of the state transitions between the parent and child tasks.

[0035] Figure 9 The illustration shows an example of an application of a state transition method according to an embodiment of this application.

[0036] Figure 10 A block diagram of a state transition apparatus according to another embodiment of this application is schematically shown; and

[0037] Figure 11 A schematic diagram of the hardware architecture of an electronic device according to another embodiment of this application is shown. Detailed Implementation

[0038] In the following description, only certain exemplary embodiments are briefly described. As those skilled in the art will recognize, the described embodiments can be modified in various ways without departing from the spirit or scope of this application. Therefore, the drawings and description are considered to be exemplary in nature and not restrictive.

[0039] State machine: A mathematical computational model used to represent a finite number of states of a system and the transitions and actions between these states.

[0040] State: By discretization, a system can be decomposed into multiple finite states. For example, an access control gate can be divided into open and closed states; an electric fan can be divided into closed, first speed, second speed, third speed, etc.; a traffic light can be divided into red light, green light, and yellow light states.

[0041] State transition: The process by which a state receives input, performs certain actions, and then enters another state.

[0042] Action logic: The specific execution logic for each state.

[0043] Execution successful: An action logic is completed within the predetermined time and achieves the expected result.

[0044] Execution timeout: An action logic failed to complete within the scheduled time. Reasons for execution timeout may include network latency, service crashes, etc.

[0045] Execution failure: An action logic encountered an error, exception, or failed to achieve the expected result during execution. Reasons for execution failure may include program errors, invalid input, etc.

[0046] TCP (Transmission Control Protocol) is a connection-oriented, reliable, byte-stream-based transport layer protocol that can be used to implement reliable data transmission for application layer protocols (such as HTTP, FTP, SMTP, etc.).

[0047] A Directed Acyclic Graph (DAG) is a directed graph without loops. In a DAG, it is impossible to return to a vertex from any given vertex by following a certain number of edges.

[0048] To facilitate understanding of the technical solutions provided in the embodiments of this application by those skilled in the art, the relevant technologies are described below:

[0049] As software systems continue to evolve, their complexity increases. The execution of a task needs to be divided into multiple states, each with its own distinct action logic. Examples include TCP requests, database operations, video processing, and file operations. The execution of these states and the transitions between them can be handled using state machines.

[0050] The applicant understands that the state machine in the relevant technology still has the following shortcomings:

[0051] (1) Within a single state machine, the state transition method is direct and explicit. However, in a distributed system containing multiple state machines, state transitions may involve communication between multiple service nodes, which greatly increases the complexity of state transitions, making it difficult to find an explicit state transition method.

[0052] (2) It lacks a universal method for persisting state data and cannot be adapted to different types of databases (Database, DB).

[0053] (3) There is no multi-level state machine decoupling scheme. Due to the barrel effect, the most time-consuming state machine action will affect the overall performance.

[0054] Therefore, this application provides a technical solution for state transition. In this technical solution: (1) a standardized state transition interface is defined, which has all the interface functions that each state instance needs to implement, ensuring the universality of the interface and the difference of specific functions, and the interface can interact across processes via the network; (2) a dedicated proxy service is responsible for adapting to different types of databases and providing a general interface, which can be directly called when the state machine data is persisted; (3) a "subtask" state is added to the parent state machine, which indicates that the flow control is transferred from the parent state machine to the child state machine. The child state machine can customize the state table, transition conditions, and actions, and the child state machine will inherit the context of the parent state machine. See below for details.

[0055] Figure 1 The illustration shows an environmental application diagram of the state transition method according to an embodiment of this application. For example... Figure 1 As shown, the distributed system in this embodiment may include multiple state machine nodes, a database, and proxy nodes, wherein:

[0056] Each state machine node can be configured to perform one or more tasks, as well as to transition from the current state to the next state.

[0057] The database can be configured to store task status values ​​and state machine node data, etc.

[0058] The proxy node can be configured to: receive requests from state machine nodes, modify the state values ​​of tasks in the database based on the requests, and select a state machine node from multiple state machine nodes to execute the next state.

[0059] Figure 2 A flowchart illustrating a state transition method according to an embodiment of this application is shown schematically.

[0060] like Figure 2 As shown, this state transition method is applied to a distributed system comprising multiple state machine nodes. The state transition method may include steps S200 to S212, wherein:

[0061] S200 Obtain the state table and state transition order, wherein the state table includes multiple states of the task.

[0062] A state table can be a collection of states that a task needs to execute. A state can include multiple states. For example, in a video conferencing session, the corresponding states could include TCP requests, database operations, video processing, file operations, etc. Similarly, in a traffic light system, the corresponding states could include red light, yellow light, and green light.

[0063] The state transition order is the order in which different states are transitioned within a task. For example, transitioning from a red light state to a yellow light state, or from a yellow light state to a green light state.

[0064] In this embodiment, by obtaining the task's state table and state transition order, it is possible to quickly determine which states the task corresponds to and the execution order of these states.

[0065] In one implementation, the state transition conditions and the directed acyclic graph of state transitions for the task can also be obtained. The state transition conditions serve as the basis for determining whether a state transition should occur, and the directed acyclic graph of state transitions can visually display the states of the task and the order of transitions between states.

[0066] S202The first state machine node is initialized according to the first state, and the first state machine node is one of the plurality of state machine nodes.

[0067] In distributed systems with a large number of nodes, multiple state machine nodes can be included. These state machine nodes can be connected through a network and proxy nodes to complete the execution and transition of task states through cooperation.

[0068] When a task needs to execute a state (such as the first state), the proxy node selects a first state machine node from multiple state machine nodes in response to the state to be executed (the first state). The selection method can be random selection or selection based on a load balancing algorithm, which can effectively improve the resource utilization efficiency and overall performance of the distributed system.

[0069] After determining the first state machine node, it can be initialized based on the first state. The purpose of initialization is to ensure that the first state machine node starts execution from a specific state (the first state), thereby reducing errors and uncertainties. The first state can be the state that the task currently needs to execute, which can be determined through the task's state table.

[0070] In this embodiment, the first state machine node is initialized according to the first state, and the first state machine node is correctly configured so that the first state can be executed.

[0071] S204 The action logic of the first state is executed by calling the initialized first state machine node.

[0072] Action logic is used to define the specific operations or behaviors that need to be performed for a given state. For example, in an access control gate, when the state switches to "open", the operation of opening the door needs to be performed.

[0073] In this embodiment, by calling the initialized first state machine node to execute the action logic corresponding to the first state, the specific operations that the task needs to perform in the current state are completed efficiently, reducing potential error risks.

[0074] S206 If the action logic of the first state is successfully executed, the second state machine node is determined from the plurality of state machine nodes.

[0075] In this distributed system, state transitions are not limited to a single state machine node; for example, state transitions can be implemented across multiple state machine nodes.

[0076] The success or failure of the action logic execution in the current state (first state) can serve as one of the conditions for state transition. Successful execution of the action logic in the first state can trigger a state transition. A second state machine node is determined from multiple state machine nodes, and the transitions between states are performed through this second state machine node, thereby achieving the desired state transition.

[0077] In one implementation, the state transition conditions may further include: external input, time constraints, specific conditions, specific events, etc. For example, a state transition can be triggered when external input meets a preset condition. External input may be data from user interaction, other systems, etc.

[0078] In one implementation, the second state machine node and the first state machine node can be the same state machine node, in which case the corresponding state transitions are implemented within a single state machine.

[0079] There are several ways to determine the second state machine node; an exemplary scheme is provided below.

[0080] In one implementation, step S206 may include:

[0081] According to a pre-set load balancing algorithm, the second state machine node is selected from the plurality of state machine nodes.

[0082] Load balancing algorithms can rationally distribute the load of nodes based on their load conditions, achieving a relatively balanced load for each node. This maximizes the utilization of system resources, reduces the processing burden on individual nodes, and ultimately improves the overall performance and response speed of the system.

[0083] In this embodiment, a second state machine node is selected from multiple state machine nodes according to a pre-set load balancing algorithm, so as to make reasonable use of the resources of the distributed system and improve system efficiency.

[0084] S208 Based on the state table and the state transition order, the second state following the first state is determined.

[0085] In this embodiment, by pre-acquiring a state table including multiple states of the task and the state transition order, the second state after the first state can be quickly determined, thereby achieving the expected state transition and reducing the occurrence of errors.

[0086] S210 The second state machine node is initialized according to the second state.

[0087] The second state machine node can be stateless. The second state machine node is initialized based on the second state, causing it to begin execution from that state. For the task as a whole, the transition occurs from executing the first state to executing the second state. For the distributed system, the transition occurs from the first state machine node to the second state machine node. Therefore, this embodiment achieves state transitions across state machine nodes, thereby enabling precise control over the execution and transitions of complex tasks in a distributed system.

[0088] S212 The action logic of the second state is executed by calling the initialized second state machine node.

[0089] The initialization of the second state machine node means that the task has successfully transitioned from the first state to the second state (the new state). The second state machine node can execute the action logic of the new state, thereby achieving a smooth transition between states and correct logic.

[0090] The above embodiments exemplify technical solutions for state transitions in a distributed system. The state machine node will be further described below.

[0091] In one implementation, such as Figure 1 As shown, each state machine node is configured with a scheduling module and an execution module. The execution module is configured with a general transfer interface, which is used to connect to an instance of each state. The scheduling module is used to call the execution module through the general transfer interface to execute the action logic corresponding to the state.

[0092] Correspondingly, step S204 may include:

[0093] The scheduling module in the first state machine node calls the corresponding general transfer interface so that the corresponding execution module executes the action logic of the first state.

[0094] In this embodiment, the scheduling module is responsible for controlling state transitions, and the execution module is responsible for executing the action logic of each state. The execution module can also provide a generic transition interface. This generic transition interface can be a custom, standardized state transition interface that includes all the interface functions required by each state instance, used to interface with each state instance. That is, the generic transition interface is universal while also being able to handle the specific functional requirements of each state instance. The generic transition interface can also interact across processes via network.

[0095] More specifically, the scheduling module can be used to call the execution module to execute the action logic corresponding to the current state through a general transfer interface. The internal configuration of each state machine node can be the same. The scheduling module in the first state machine node can call the corresponding general transfer interface, thereby enabling the corresponding execution module to execute the action logic of the first state, efficiently completing the specific operations that the task needs to perform in the current state, and reducing potential error risks.

[0096] In one implementation, such as Figure 1 As shown, the execution module is also configured with a callback interface.

[0097] Correspondingly, such as Figure 3 As shown, step S206 may include:

[0098] S300 requests the proxy node to modify the task's state value in the database by calling the callback interface of the first state machine node.

[0099] S302, if the state value has been modified, the second state machine node is determined from the plurality of state machine nodes through the proxy node.

[0100] Callback interfaces can be used to implement asynchronous operations, event-driven mechanisms, and customized functions. When an operation is completed, the execution module can use this callback interface to call a proxy node to perform the corresponding operation. In this embodiment, when the action logic in the first state is successfully executed, the callback interface of the first state machine node can be called to send a modification request to the proxy node. The modification request can be used to modify the status value of a task in the database, for example, changing "initialization" to "read data" or "read data" to "write data". By updating the status value of the task in the database in real time through the callback interface and the proxy node, the tracking and immediate feedback of the task status can be achieved.

[0101] After the agent node successfully modifies the state value, the agent node selects a second state machine node from multiple state machine nodes to achieve the expected state transition.

[0102] The above embodiments describe the configuration of state machine nodes and the collaborative operation of state machine nodes and agent nodes.

[0103] The following example will provide an exemplary description of the initialization process of a state machine node.

[0104] In one implementation, step S202 may include:

[0105] During the initialization of the first state machine node, the state name of the first state is registered in the routing table. When the execution module of the first state machine node is invoked, the invoked execution module finds the first state based on the state name and the routing table, and executes the action logic of the first state.

[0106] When initializing the first state machine node based on the first state, the state name of the first state is registered in the routing table as a key. The state name can serve as a unique identifier for the state. When the execution module of the first state machine node is invoked, it can find the corresponding state from the routing table using the state name as an input parameter and execute the action logic for that state.

[0107] In this embodiment, by registering the state name in the routing table, the execution module can quickly and accurately obtain the state to be executed and the corresponding action logic when it is called, thereby reducing errors and improving the efficiency of task execution.

[0108] The above embodiments have described the execution module of the state machine node in detail. The calling module will be described in more detail below.

[0109] In one implementation, such as Figure 4 As shown, the state transition method may further include:

[0110] S400, in any of the multiple state machine nodes, before executing the action logic corresponding to the current state, the task information is added to the first queue of the scheduling module.

[0111] S402, if the action logic of the current state is successfully executed, the task information is removed from the first queue.

[0112] The current state machine node refers to the state machine node that is currently executing a task and is in its current state. It can be any one of multiple state machine nodes.

[0113] The scheduling module of the state machine node can maintain a first queue, which can be a running queue. The running queue stores task information corresponding to the current state, whether it is currently executing or about to execute. The queue length of the running queue can be configured in the configuration center, and the running queue can be a first-in, first-out (FIFO) queue.

[0114] The queue data of the running queue can be persistently stored in the database by calling the general interface of the proxy node. A dedicated proxy node is responsible for adapting to different types of databases and providing a general interface to facilitate the persistent storage of data for each state machine node.

[0115] Before executing the action logic for the current state, the corresponding task information is stored in the running queue, indicating that the task is being executed or is about to be executed. After the action logic is executed successfully, the task information is removed from the running queue to notify the system that the current state of the task has been successfully executed, thereby allocating resources and execution opportunities for other waiting task states. Before executing the action logic for the next state, the task information can be added back to the running queue.

[0116] In this embodiment, by maintaining the running queue through the scheduling module, the state machine node can determine the task that should be executed at the moment, effectively allocate system resources and realize state tracking.

[0117] In one implementation, such as Figure 5 As shown, the state transition method may further include:

[0118] S500, when the running time reaches a first preset delay time, the task information is removed from the first queue by the scheduling module; wherein, the running time is the storage time of the task information in the first queue.

[0119] S502, by calling the scheduling module of the current state machine node, the action logic corresponding to the current state is repeatedly executed.

[0120] If task information is stored in the running queue for too long, it indicates that the action logic of the task's current state has failed to execute successfully. To release resources and address issues promptly, when the runtime reaches the first preset delay time, the scheduling module can remove the task information from the running queue and trigger a re-transfer to the current state. The scheduling module of the current state machine node calls the corresponding execution module through the general transfer interface to repeatedly execute the action logic of the current state.

[0121] In this embodiment, removing task information that has reached a time threshold from the running queue can release resources promptly and avoid blocking. By transferring the task back to the current state and repeating the action logic of the current state, problems can be effectively identified and handled.

[0122] In one implementation, since the execution time of the action logic in different states is different, running queues with different delay time thresholds can be set for different states, thereby more flexibly controlling the execution time of different states.

[0123] In one implementation, a timer can be assigned to the running queue to periodically scan for tasks that have reached a first preset delay time and process them accordingly. Since the running queue is a first-in, first-out (FIFO) queue, the timer stops scanning when it detects the first task that has not reached the first preset delay time, and waits for the next scan. The time interval between each scan can be configured. By setting a timer, timeout tasks can be detected and abnormal situations handled promptly.

[0124] In one implementation, task information may include the task's current state, the number of times the current state has been executed, the task identifier, and the number of retries for the current state. This task information enables effective management of task states.

[0125] In one embodiment, the state transition method may further include: if the number of times the current state is executed exceeds a preset execution threshold, adding the task information to a second queue in the scheduling module and removing the task information from the first queue.

[0126] If a task fails to execute successfully after exceeding a pre-configured execution threshold in its current state, to handle exceptions and prevent further problems caused by unrestricted repeated execution, the corresponding task information can be removed from the running queue and added to a second queue for manual processing. The second queue can be a Dead Letter Queue (DLQ), used to store task information for tasks that cannot be executed normally, allowing for subsequent manual analysis, processing, and intervention to improve system stability and reliability. The data in the Dead Letter Queue can also be persistently stored in a database by calling the proxy node's general interface.

[0127] It should be noted that task information will not exist in multiple queues simultaneously, ensuring consistency in task processing and simplifying task management, monitoring, and maintenance.

[0128] In one implementation, such as Figure 6 As shown, the state transition method may further include:

[0129] S600, if the action logic of the current state fails to execute, the task information is added to the third queue in the scheduling module and removed from the first queue.

[0130] S602, if the retry time reaches the second preset delay time, the task information is removed from the third queue by the scheduling module; wherein, the retry time represents the storage time of the task information in the third queue.

[0131] S604, by calling the scheduling module of the current state machine node, the action logic corresponding to the current state is repeatedly executed.

[0132] Execution failure indicates that the action logic in the current state may have encountered errors, exceptions, or failed to achieve the expected results during execution. In this case, the task information is removed from the running queue and added to a third queue. The third queue can be a retry queue, which stores task information for failed tasks so that they can be retried later, improving fault tolerance. The queue data of the retry queue can be persistently stored in the database by calling the general interface of the proxy node.

[0133] When the storage time of task information in the retry queue reaches the second preset delay time, indicating that the retry time for the corresponding task's current state has been reached, the operation of transferring the task back to the current state is triggered. The task information is removed from the retry queue to release resources and reduce data errors. By calling the scheduling module of the current state machine node, the action logic corresponding to the current state is repeatedly executed, improving the success rate of the current state's execution.

[0134] In one implementation, multiple retry queues with different second preset delay times can be configured according to delayLevel, and different failed task information can be stored in different retry queues according to delayLevel, thereby allowing for more flexible control over the retry time of different task information.

[0135] In one implementation, a timer can be allocated to the retry queue to periodically scan the queue for tasks that have reached a second preset delay time and process them accordingly. Since the retry queue is a first-in, first-out queue, the timer stops scanning when it detects the first task that has not reached the second preset delay time, and waits for the next scan. The time interval between each scan can be configured. By setting the timer, task retries can be performed promptly.

[0136] In one implementation, when the number of retries in the current state exceeds a preset retry threshold, the task information is added to the second queue in the scheduling module and removed from the third queue.

[0137] If a task fails to execute successfully after the number of retries in its current state exceeds the pre-configured retry threshold, in order to reduce system problems caused by unrestricted task retries, the corresponding task information can be removed from the retry queue and added to the dead-letter queue for manual processing, thereby improving the stability and reliability of the system.

[0138] In one implementation, if the service is interrupted (including but not limited to power failure, abnormal restart, etc.) while executing the action logic of the current state, the operation of transferring back to the current state is triggered when the task information in the running queue and the retry queue reaches the time threshold, thereby improving the fault tolerance and stability of the system.

[0139] In one implementation, such as Figure 7 As shown, the state transition method may further include:

[0140] S700, by calling the execution module of the current state machine node, executes the action logic of the current state and generates a task token.

[0141] S702, a call request is sent to the proxy node through the callback interface of the current state machine node. The call request carries the task token and is used to request the proxy node to modify the status value of the task in the database.

[0142] S704, the scheduling module of the current state machine node receives information returned by the agent node, the information including error information, the error information indicating that the task token has expired.

[0143] S706, if the information is an error message, the task information is added to the third queue through the scheduling module of the current state machine node.

[0144] When a state machine node executes the action logic for its current state, it can generate a task token. This token includes information such as the task's current state, a unique task identifier, a random number, and an expiration time. The expiration time is the same as the first preset delay time configured in the running queue.

[0145] After the action logic is executed, the execution module requests the proxy node to modify the task's status value in the database via a callback interface. This request can include the task token. The scheduling module subscribes to the information returned by the proxy node. If the returned information is an error message, it means the task token has expired and the action logic failed to execute successfully within the first preset delay time; that is, it executed successfully but timed out. In this case, the scheduling module adds the corresponding task information to the retry queue for later processing.

[0146] The above embodiments illustrate how the scheduling module tracks and provides real-time feedback on task status by maintaining first, second, and third queues. The following will provide an exemplary description of how the state machine node implements multi-level state transitions.

[0147] In an optional embodiment, the state table corresponds to a parent task, and the state table includes multiple states of the parent task; the parent task includes multiple subtasks, and each subtask corresponds to a sub-state table and a sub-state transition order; wherein, the states of the subtasks and other states in the parent task are executed separately by different state machine nodes.

[0148] like Figure 8 As shown, a parent task can be a collection of multiple states. When multiple states of a parent task need to be executed concurrently, one or more states in the parent task can be regarded as subtasks. Each subtask can define its own corresponding subtask execution state table, sub-state transition order, sub-state transition conditions, and sub-state action logic.

[0149] A parent task may need to execute multiple child tasks (e.g., 1 million). If the parent and child tasks are not decoupled and all tasks are executed under the same state machine node, the child tasks may consume a large amount of system resources (such as CPU and memory), affecting the concurrent execution capability of the parent task. Therefore, the parent and child tasks can be decoupled. After decoupling, a single parent task state machine node can be assigned to multiple distributed child task state machine nodes for execution, thereby improving the overall concurrency capability.

[0150] Specifically, a "Subtask" state can be added to the parent task's state table. This state indicates that control of the state transition has been transferred from the parent state machine node to the child state machine node. The child state machine node can use the general transition interface to call the execution module to concurrently create multiple subtask processes based on the number of subtasks, and then execute the subtasks. The transition condition for the "Subtask" state can be set to the successful execution of one or more corresponding subtasks.

[0151] In this embodiment, by decoupling and executing multiple states separately, the problem of subtasks affecting the concurrent execution capability of parent tasks is alleviated, thereby improving the overall concurrency capability.

[0152] To make this application easier to understand, the following is combined with... Figure 9 An example application is provided.

[0153] S11, determine the task execution state table (state table), state transition order, state transition conditions, and directed acyclic graph of state flow.

[0154] S12, Initialize state machine service A (first state machine node).

[0155] The initialization process includes registering the state name as a key in the routing table.

[0156] The state machine service is divided into a scheduling module and an execution module. The scheduling module is responsible for controlling state transitions, while the execution module is responsible for executing the action logic of the state and providing transition interfaces and callback interfaces.

[0157] S13, the scheduling module of state machine service A calls the execution module through the transfer interface to execute the action logic of the corresponding state.

[0158] When the execution module interface is called, the corresponding state is found in the routing table by the state name of the input parameter and the action logic of that state is executed.

[0159] S14. After the action logic is successfully executed, state machine service A requests the proxy service to modify the state machine database through the callback interface.

[0160] S15, After the proxy service (proxy node) successfully operates on the database, it selects the next state machine service (such as state machine service B) through a load balancing algorithm.

[0161] S16, the agent service notifies the scheduling module of state machine service B to implement state transition.

[0162] S17, execute the action logic of the next state (second state) through the transition interface of state machine service B.

[0163] In this exemplary application, (1) state transitions can be performed across state machine nodes, thereby enabling precise control of the execution and transition of complex tasks in a large-scale distributed system; (2) a standardized state transition interface is defined, which has all the interface functions that each state instance needs to implement, ensuring the universality of the interface and the differences in specific functions, and the interface can interact across processes via the network; (3) a dedicated proxy service is responsible for adapting to different types of databases and providing a general interface, which can be directly called when state machine data is persisted; (4) a "subtask" state is added to the parent state machine, which indicates that the flow control is transferred from the parent state machine to the child state machine. The child state machine can customize the state table, transition conditions, and actions, and the child state machine will inherit the context of the parent state machine.

[0164] Figure 10 A structural block diagram of a state transition device according to an embodiment of this application is shown. Figure 10 As shown, the state transition device 1000 can:

[0165] The acquisition module 1100 is used to acquire a state table and a state transition order, wherein the state table includes multiple states of the task;

[0166] The first initialization module 1200 is used to initialize a first state machine node according to a first state, wherein the first state machine node is one of the plurality of state machine nodes;

[0167] The first execution module 1300 is used to execute the action logic of the first state by calling the initialized first state machine node;

[0168] The first determining module 1400 is used to determine the second state machine node from the plurality of state machine nodes if the action logic of the first state is successfully executed.

[0169] The second determining module 1500 is used to determine the second state after the first state based on the state table and the state transition order.

[0170] The second initialization module 1600 is used to initialize the second state machine node according to the second state;

[0171] The second execution module 1700 is used to execute the action logic of the second state by calling the initialized second state machine node.

[0172] In one implementation, the state machine node is configured with a scheduling module and an execution module. The execution module is configured with a general transfer interface, which is used to interface with an instance of each state. The scheduling module is used to call the execution module through the general transfer interface to execute the action logic corresponding to the state.

[0173] Correspondingly, the first execution module 1300 is also used for:

[0174] The scheduling module in the first state machine node calls the corresponding general transfer interface so that the corresponding execution module executes the action logic of the first state.

[0175] As one implementation method, the execution module is also configured with a callback interface;

[0176] Correspondingly, the first determining module 1400 is also used for:

[0177] By calling the callback interface of the first state machine node, the proxy node is requested to modify the state value of the task in the database;

[0178] If the state value has been modified, the second state machine node is determined from the plurality of state machine nodes through the proxy node.

[0179] In one implementation, the first determining module 1400 is further configured to:

[0180] According to a pre-set load balancing algorithm, the proxy node selects the second state machine node from the plurality of state machine nodes.

[0181] In one implementation, the first initialization module 1200 is further configured to:

[0182] During the initialization of the first state machine node, the state name of the first state is registered in the routing table;

[0183] When the execution module of the first state machine node is invoked, the invoked execution module finds the first state based on the state name and the routing table, and executes the action logic of the first state.

[0184] In one embodiment, the state transition device 1000 is further configured to:

[0185] In any of the multiple state machine nodes, before executing the action logic corresponding to the current state, the task information is added to the first queue of the scheduling module.

[0186] If the action logic in the current state is executed successfully, the task information is removed from the first queue.

[0187] In one embodiment, the state transition device 1000 is further configured to:

[0188] If the running time reaches a first preset delay time, the task information is removed from the first queue by the scheduling module; wherein, the running time is the storage time of the task information in the first queue;

[0189] By calling the scheduling module of the current state machine node, the action logic corresponding to the current state is repeatedly executed.

[0190] In one implementation, the task information includes the current state of the task, the number of times the current state has been executed, the number of retries for the current task, and the task identifier.

[0191] In one embodiment, the state transition device 1000 is further configured to:

[0192] If the number of executions in the current state exceeds a preset execution threshold, the task information is added to the second queue in the scheduling module and removed from the first queue.

[0193] In one embodiment, the state transition device 1000 is further configured to:

[0194] If the action logic in the current state fails to execute, the task information is added to the third queue in the scheduling module and removed from the first queue.

[0195] If the retry time reaches the second preset delay time, the task information is removed from the third queue by the scheduling module; wherein, the retry time represents the storage time of the task information in the third queue;

[0196] By calling the scheduling module of the current state machine node, the action logic corresponding to the current state is repeatedly executed.

[0197] In one embodiment, the state transition device 1000 is further configured to:

[0198] When the number of retries in the current state exceeds a preset retry threshold, the task information is added to the second queue in the scheduling module and removed from the third queue.

[0199] In one embodiment, the state transition device 1000 is further configured to:

[0200] By calling the execution module of the current state machine node, the action logic of the current state is executed and a task token is generated;

[0201] The current state machine node sends a call request to the proxy node through the callback interface. The call request carries the task token and is used to request the proxy node to modify the status value of the task in the database.

[0202] The scheduling module of the current state machine node receives information returned by the agent node, including error information indicating that the task token has expired.

[0203] If the information is an error, the task information is added to the third queue through the scheduling module of the current state machine node.

[0204] In one implementation, the state table corresponds to a parent task, and the state table includes multiple states of the parent task;

[0205] The parent task includes multiple sub-tasks, and each sub-task corresponds to a sub-state table and a sub-state transition order.

[0206] The state of the subtask and other states in the parent task are executed separately by different state machine nodes.

[0207] Figure 11 This diagram illustrates a structural block diagram of an electronic device according to an embodiment of the present application. The electronic device 10000 may be a rack server, blade server, tower server, or cabinet server (including standalone servers or server clusters composed of multiple servers), etc. Figure 11 As shown, the electronic device 10000 includes, but is not limited to: a memory 1110, a processor 1120, and a communication interface 1130 that can communicate and be linked to each other via a system bus. Wherein:

[0208] The memory 1110 includes at least one type of computer-readable storage medium, including flash memory, hard disk, multimedia card, card-type memory (e.g., SD or DX memory), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In one embodiment, the memory 1110 may be an internal storage module of the electronic device 10000, such as the hard disk or memory of the electronic device 10000. In another embodiment, the memory 1110 may also be an external storage device of the electronic device 10000, such as a plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc., equipped on the electronic device 10000. Of course, the memory 1110 may also include both the internal storage module and the external storage device of the electronic device 10000. In this embodiment, the memory 1110 is typically used to store the operating system and various application software installed on the electronic device 10000, such as program code for state transition methods. In addition, the memory 1110 can also be used to temporarily store various types of data that have been output or will be output.

[0209] In one embodiment, processor 1120 may be a central processing unit (CPU), controller, microcontroller, microprocessor, or other chip. Processor 1120 is typically used to control the overall operation of electronic device 10000, such as performing control and processing related to data interaction or communication with electronic device 10000. In this embodiment, processor 1120 is used to run program code stored in memory 1110 or process data.

[0210] The communication interface 1130 may include a wireless communication interface or a wired communication interface, which is typically used to establish a communication link between the electronic device 10000 and other electronic devices. For example, the communication interface 1130 is used to connect the electronic device 10000 to an external terminal via a network, establishing a data transmission channel and communication link between the electronic device 10000 and the external terminal. The network may be an intranet, the Internet, the Global System for Mobile Communications (GSM), Wideband Code Division Multiple Access (WCDMA), 4G networks, 5G networks, Bluetooth, Wi-Fi, or other wireless or wired networks.

[0211] It should be pointed out that, Figure 11 Only electronic devices with components 1110-1030 are shown; however, it should be understood that it is not required to implement all of the shown components, and more or fewer components may be implemented instead.

[0212] In this embodiment, the state transition method stored in memory 1110 can also be divided into one or more program modules and executed by one or more processors (such as processor 1120) to complete the embodiments of this application.

[0213] This application also provides a computer-readable storage medium storing a computer program thereon, wherein the computer program, when executed by a processor, implements the steps of the state transition method in the embodiments.

[0214] In this embodiment, the computer-readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (e.g., SD or DX memory), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEP ROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In one embodiment, the computer-readable storage medium can be an internal storage unit of an electronic device, such as the hard disk or memory of the electronic device. In another embodiment, the computer-readable storage medium can also be an external storage device of the electronic device, such as a plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc., equipped on the electronic device. Of course, the computer-readable storage medium can also include both internal storage units and external storage devices of the electronic device. In this embodiment, the computer-readable storage medium is typically used to store the operating system and various application software installed on the electronic device, such as the program code of the state transition method in the embodiment. In addition, the computer-readable storage medium can also be used to temporarily store various types of data that have been output or will be output.

[0215] Obviously, those skilled in the art should understand that the modules or steps of the embodiments of this application described above can be implemented using general-purpose electronic devices. They can be centralized on a single electronic device or distributed across a network of multiple electronic devices. Optionally, they can be implemented using executable program code, thereby storing them in a storage device for execution by the electronic device. In some cases, the steps shown or described can be performed in a different order than those presented here, or they can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Thus, the embodiments of this application are not limited to any particular combination of hardware and software.

[0216] It should be noted that the above are merely preferred embodiments of this application and do not limit the scope of patent protection of this application. Any equivalent structural or procedural changes made using the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the scope of patent protection of this application.

Claims

1. A state transition method, characterized in that, Applied to a distributed system comprising multiple state machine nodes; the method includes: Obtain the state table and state transition order, wherein the state table includes multiple states of the task; The first state machine node is initialized according to the first state, and the first state machine node is one of the plurality of state machine nodes; The action logic of the first state is executed by calling the initialized first state machine node; If the action logic of the first state is successfully executed, the second state machine node is determined from the plurality of state machine nodes; Based on the state table and the state transition order, determine the second state following the first state; The second state machine node is initialized according to the second state; The action logic of the second state is executed by calling the initialized second state machine node; The state machine node is configured with an execution module; the execution module is configured with a callback interface; correspondingly, determining the second state machine node from the plurality of state machine nodes includes: By calling the callback interface of the first state machine node, the proxy node is requested to modify the state value of the task in the database; If the state value has been modified, the second state machine node is determined from the plurality of state machine nodes through the proxy node.

2. The method according to claim 1, characterized in that, The state machine node is configured with a scheduling module, and the execution module is configured with a general transfer interface. The general transfer interface is used to connect to an instance of each state, and the scheduling module is used to call the execution module through the general transfer interface to execute the action logic corresponding to the state. Correspondingly, the action logic of the first state is executed by calling the initialized first state machine node, including: The scheduling module in the first state machine node calls the corresponding general transfer interface so that the corresponding execution module executes the action logic of the first state.

3. The method according to claim 1, characterized in that, Determining the second state machine node from the plurality of state machine nodes through the proxy node includes: According to a pre-set load balancing algorithm, the proxy node selects the second state machine node from the plurality of state machine nodes.

4. The method according to claim 2, characterized in that, The initialization of the first state machine node according to the first state includes: During the initialization of the first state machine node, the state name of the first state is registered in the routing table; When the execution module of the first state machine node is invoked, the invoked execution module finds the first state based on the state name and the routing table, and executes the action logic of the first state.

5. The method according to any one of claims 2 to 4, characterized in that, The method further includes: In any of the multiple state machine nodes, before executing the action logic corresponding to the current state, the task information is added to the first queue of the scheduling module. If the action logic in the current state is executed successfully, the task information is removed from the first queue.

6. The method according to claim 5, characterized in that, The method further includes: If the running time reaches a first preset delay time, the task information is removed from the first queue by the scheduling module; wherein, the running time is the storage time of the task information in the first queue; By calling the scheduling module of the current state machine node, the action logic corresponding to the current state is repeatedly executed.

7. The method according to claim 5, characterized in that, The task information includes the current status of the task, the number of times the current status has been executed, the number of retries for the current task, and the task identifier.

8. The method according to claim 7, characterized in that, The method further includes: If the number of executions in the current state exceeds a preset execution threshold, the task information is added to the second queue in the scheduling module and removed from the first queue.

9. The method according to claim 5, characterized in that, The method further includes: If the action logic in the current state fails to execute, the task information is added to the third queue in the scheduling module and removed from the first queue. If the retry time reaches the second preset delay time, the task information is removed from the third queue by the scheduling module; wherein, the retry time represents the storage time of the task information in the third queue; By calling the scheduling module of the current state machine node, the action logic corresponding to the current state is repeatedly executed.

10. The method according to claim 9, characterized in that, The method further includes: When the number of retries in the current state exceeds a preset retry threshold, the task information is added to the second queue in the scheduling module and removed from the third queue.

11. The method according to claim 9, characterized in that, The method further includes: By calling the execution module of the current state machine node, the action logic of the current state is executed and a task token is generated; The current state machine node sends a call request to the proxy node through the callback interface. The call request carries the task token and is used to request the proxy node to modify the status value of the task in the database. The scheduling module of the current state machine node receives information returned by the agent node, including error information indicating that the task token has expired. If the information is an error, the task information is added to the third queue through the scheduling module of the current state machine node.

12. The method according to any one of claims 1 to 4, characterized in that: The state table corresponds to a parent task, and the state table includes multiple states of the parent task; The parent task includes multiple sub-tasks, and each sub-task corresponds to a sub-state table and a sub-state transition order. The state of the subtask and other states in the parent task are executed separately by different state machine nodes.

13. A state transition device, characterized in that, For use in a distributed system comprising multiple state machine nodes, the apparatus includes: An acquisition module is used to acquire a state table and a state transition order, wherein the state table includes multiple states of the task; The first initialization module is used to initialize a first state machine node according to a first state, wherein the first state machine node is one of the plurality of state machine nodes; The first execution module is used to execute the action logic of the first state by calling the initialized first state machine node; The first determining module is used to determine the second state machine node from the plurality of state machine nodes if the action logic of the first state is successfully executed. The second determining module is used to determine the second state after the first state based on the state table and the state transition order; The second initialization module is used to initialize the second state machine node according to the second state; The second execution module is used to execute the action logic of the second state by calling the initialized second state machine node; The state machine node is configured with an execution module; the execution module is configured with a callback interface; correspondingly, determining the second state machine node from the plurality of state machine nodes includes: By calling the callback interface of the first state machine node, the proxy node is requested to modify the state value of the task in the database; If the state value has been modified, the second state machine node is determined from the plurality of state machine nodes through the proxy node.

14. An electronic device, characterized in that, include: At least one processor; and A memory communicatively connected to the at least one processor; wherein: The memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method of any one of claims 1 to 12.

15. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that, when executed by a processor, implement the method as described in any one of claims 1 to 12.

Citation Information

Patent Citations

  • Data processing method and apparatus, computer device, and readable storage medium

    US20230033236A1

  • System and method for performing flexible workflow process execution in a distributed workflow management system

    US6041306A