State synchronization method and apparatus, electronic device, and storage medium
Patent Information
- Application Number
- CN202111452674.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-01
- Publication Date
- 2026-09-22
- Estimated Expiration
- 2041-12-01
AI Technical Summary
[0003]然而,采用等待方式进行模块间的状态同步时,会降低整个系统的执行速度;且在执行速度较快的模块反复操作执行速度较慢的模块的情况下,会增加用来进行状态切换的数据计算资源的消耗
[0014]本申请实施例提出的一种状态同步方法、装置、电子设备及存储介质,应用于状态机,在状态机接收到客户端发送的第一模块对应的当前状态同步指令(该当前状态同步指令指示将所述第一模块对应的状态由第一当前状态更新为执行预设事件的第一目标状态)时,基于该当前状态同步指令,将与该第一模块关联的第二模块对应的状态,由第二当前状态同步为该第二目标状态;该第二目标状态表征该第二模块执行该预设事件的关联事件的状态。由于第一模块并不直接与第二模块进行通信,而是将最新的当前状态同步指令发送至状态机,由状态机操作第二模块,并由状态机确保最终可以将第二模块的对应的状态由第二当前状态同步为第二目标状态,因此第一模块在向状态机发送完成最新的当前状态同步指令之后,无需等待第二模块,可以直接进行后续操作,从而提高整个系统的执行速度;此外,由于状态机基于最新的当前状态同步指令操作第二模块,除了最新的当前状态同步指令之外的指令不会被执行,减少了第二模块的冗余操作,从而节省了用来进行状态切换的数据计算资源。
Smart Images

Figure CN116204230B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of computer technology, and specifically relates to a state synchronization method, device, electronic device and storage medium. Background Technology
[0002] In related technologies, the fast-running module typically waits for the slow-running module to achieve state synchronization between two modules with different speeds. Figure 1 This is a schematic diagram illustrating the state synchronization between two modules in existing technology. For example... Figure 1 As shown, when the first module switches from state 1 to state 2, it needs to operate the second module so that the second module can also complete the corresponding state switch. Due to the unequal execution speed, after the first module reaches state 2, it needs to wait for the second module to also reach state 2 before executing subsequent operations.
[0003] However, using a waiting method to synchronize the state between modules will reduce the overall system execution speed; and when a faster module repeatedly operates on a slower module, it will increase the consumption of data computing resources used for state switching. Summary of the Invention
[0004] To address the aforementioned technical problems, this application provides a state synchronization method, apparatus, electronic device, and storage medium.
[0005] On the one hand, this application proposes a state synchronization method for use in state machines, the method comprising:
[0006] Receive a current state synchronization instruction sent by the client for the first module; the current state synchronization instruction is used to indicate that the state corresponding to the first module be updated from the first current state to the first target state for executing a preset event.
[0007] Based on the current state synchronization instruction, the state corresponding to the second module associated with the first module is synchronized from the second current state to the second target state; the second target state represents the state of the associated event of the second module executing the preset event;
[0008] The execution speed of the first module is greater than that of the second module.
[0009] On the other hand, embodiments of this application provide a state synchronization device applied to a state machine, the device comprising:
[0010] The receiving module is used to receive a current state synchronization instruction corresponding to a first module sent by the client; the current state synchronization instruction is used to indicate that the state corresponding to the first module be updated from a first current state to a first target state for executing a preset event.
[0011] The first synchronization module is used to synchronize the state of the second module associated with the first module from the second current state to the second target state based on the current state synchronization instruction; the second target state represents the state of the associated event of the second module executing the preset event; wherein the execution speed of the first module is greater than the execution speed of the second module.
[0012] On the other hand, this application proposes an electronic device including a processor and a memory, wherein the memory stores at least one instruction or at least one program, and the at least one instruction or at least one program is loaded and executed by the processor to implement the state synchronization method as described above.
[0013] On the other hand, this application proposes a computer-readable storage medium storing at least one instruction or at least one program segment, which is loaded and executed by a processor to implement the state synchronization method as described above.
[0014] This application proposes a state synchronization method, apparatus, electronic device, and storage medium applied to a state machine. When the state machine receives a current state synchronization instruction sent by a client for a first module (the current state synchronization instruction indicates that the state corresponding to the first module should be updated from a first current state to a first target state for executing a preset event), based on the current state synchronization instruction, the state corresponding to a second module associated with the first module is synchronized from a second current state to the second target state. The second target state represents the state of the associated event for the second module to execute the preset event. Since the first module does not communicate directly with the second module, but instead sends the latest current state synchronization instruction to the state machine, the state machine operates the second module and ensures that the state corresponding to the second module can eventually be synchronized from the second current state to the second target state. Therefore, after the first module sends the latest current state synchronization instruction to the state machine, it does not need to wait for the second module and can directly perform subsequent operations, thereby improving the execution speed of the entire system. In addition, since the state machine operates the second module based on the latest current state synchronization instruction, instructions other than the latest current state synchronization instruction will not be executed, reducing redundant operations of the second module and saving data computing resources used for state switching. Attached Figure Description
[0015] To more clearly illustrate the technical solutions and advantages in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0016] Figure 1 This is a schematic diagram of state synchronization between two modules in existing technology.
[0017] Figure 2 This is a schematic diagram of the implementation environment of a state synchronization method provided in an embodiment of this application.
[0018] Figure 3 This is a flowchart illustrating a state synchronization method provided in an embodiment of this application.
[0019] Figure 4 This is a flowchart illustrating, according to an exemplary embodiment, a process of synchronizing the state of a second module associated with a first module from a second current state to a second target state.
[0020] Figure 5 This is a flowchart illustrating, according to an exemplary embodiment, a process of synchronizing the state corresponding to the second module from the second current state to the second target state when it is identified that the second current state is different from the second target state.
[0021] Figure 6 This is a schematic diagram illustrating a single switch between two states according to an exemplary embodiment.
[0022] Figure 7 This is a schematic diagram illustrating repeated switching between two states according to an exemplary embodiment.
[0023] Figure 8 This is a flowchart illustrating, according to an exemplary embodiment, a process of synchronizing the state corresponding to the second module from the second current state to the second target state.
[0024] Figure 9 This is a schematic diagram illustrating repeated state switching between multiple states according to an exemplary embodiment.
[0025] Figure 10 This is a block diagram illustrating a state synchronization device according to an exemplary embodiment.
[0026] Figure 11 This is a hardware structure block diagram of a server for a state synchronization method according to an exemplary embodiment. Detailed Implementation
[0027] Cloud technology refers to a managed technology that unifies a series of resources such as hardware, software, and networks within a wide area network or local area network to achieve data computing, storage, processing, and sharing.
[0028] Cloud technology is a general term encompassing network technology, information technology, integration technology, management platform technology, and application technology based on the cloud computing business model. It can form resource pools, providing flexible and convenient on-demand access. The backend services of cloud computing systems require substantial computing and storage resources, such as those for video websites, image websites, and many portal websites. With the rapid development and application of the internet industry, every item may eventually possess its own identification mark, requiring transmission to backend systems for logical processing. Data at different levels will be processed separately, and various industry data will require robust system support, which can only be achieved through cloud computing. Specifically, cloud technology includes technical fields such as security, big data, databases, industry applications, networking, storage, management tools, and computing.
[0029] Specifically, the embodiments of this application relate to big data technology in cloud technology.
[0030] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.
[0031] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or server that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or devices.
[0032] Figure 2 This is a schematic diagram illustrating the implementation environment of a state synchronization method provided in an embodiment of this application. For example... Figure 2As shown, the implementation environment may include at least a client 01, a state machine 02, and a server 03. The client 01, the state machine 02, and the server 03 may be directly or indirectly connected via wired or wireless communication, which is not limited in this application.
[0033] Specifically, the first module in the client acts as a high-level decision-maker, which can send a current state synchronization instruction to state machine 02. This instruction instructs the state corresponding to the first module to be updated from the first current state to the first target state for executing a preset event. Optionally, the client 01 can be a smartphone, tablet, laptop, desktop computer, smart speaker, smartwatch, etc., but is not limited to these. The terminal and server can be directly or indirectly connected via wired or wireless communication, and this application does not impose any restrictions.
[0034] Specifically, a state machine acts as a mid-level decision-maker, composed of state registers and combinational logic circuits. It transitions between pre-defined states based on control signals, serving as the control center coordinating related signal actions and completing specific operations. A state machine can be understood as a directed graph consisting of a set of nodes and corresponding transition functions, which "operates" in response to a series of events. Specifically, after receiving the current state synchronization command from the client, the state machine can synchronize the state of the second module associated with the first module in the server from the second current state to the second target state. This second target state represents the state of the associated event when the second module executes the preset event. In other words, the state machine achieves state synchronization between the first module in client 01 and the second module in server 03.
[0035] Optionally, the server can be a standalone physical server, a server cluster or distributed system consisting of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms.
[0036] It should be noted that, Figure 2 This is merely an example. Other implementation environments may be included in some scenarios. For instance, such an implementation environment may include at least client 01, state machine 02, and client 03. The first module is located in client 01, and the second module is located in client 03. State machine 01 is used to achieve state synchronization between the first module in client 01 and the second module in client 02.
[0037] Figure 3This is a flowchart illustrating a state synchronization method provided in an embodiment of this application. This method can be used for... Figure 2 In the implementation environment described herein, the steps of the methods described in the embodiments or flowcharts are provided. However, based on conventional or non-inventive labor, more or fewer steps may be included. The order of steps listed in the embodiments is merely one possible execution order among many and does not represent the only possible execution order. In actual system or server product execution, the methods shown in the embodiments or drawings can be executed sequentially or in parallel (e.g., in a parallel processor or multi-threaded processing environment). Specifically, as shown in the embodiments or drawings... Figure 3 As shown, this method, applied to a state machine, can include:
[0038] S101. Receive the current state synchronization instruction corresponding to the first module sent by the client; the current state synchronization instruction is used to indicate that the state corresponding to the first module is updated from the first current state to the first target state for executing the preset event.
[0039] Optionally, in the embodiments of this application, the state machine may receive the current state synchronization instruction in various ways, and the embodiments of this application do not specifically limit it here.
[0040] In one approach, the state machine establishes a wired communication connection with the client, through which the state machine receives the client's current state synchronization command.
[0041] In another approach, the state machine establishes a wireless communication connection with the client, and receives the current state synchronization command through this wireless communication.
[0042] Optionally, in this embodiment, the client may send the current state synchronization instruction corresponding to the first module to the state machine in various ways, and this embodiment does not specifically limit the methods used.
[0043] In one approach, the first module in the client can directly send its current state synchronization command to the state machine.
[0044] In another approach, the client can directly send the current state synchronization instruction corresponding to the first module to the state machine.
[0045] Optionally, in this embodiment, there may be multiple times when the client sends the current state synchronization instruction corresponding to the first module to the state machine, and this embodiment does not specifically limit the timing.
[0046] In one approach, the first module sends the current state synchronization instruction to the state machine before performing a state update.
[0047] In another approach, while the first module is updating its state, it simultaneously sends a synchronization instruction for the current state to the state machine.
[0048] It is understandable that the type of the first module, the type of the first current state, the type of the preset event, and the type of the first target state are all related to the specific application scenario.
[0049] Optionally, in a shopping scenario, suppose the shopping application (APP) in the client includes three shopping pages, and the user can swipe between these three pages. Swiping on the page can be considered the first module, and the preset event can be a swipe event. Swiping to the first column, swiping to the second column, and swiping to the third column can be considered the states of the first module. For example, if the "first current state" is "swipe to the first column," then the "first target state" can be "swipe to the second column" or "swipe to the third column." As another example, if the "first current state" is "swipe to the second column," then the "first target state" can be "swipe to the first column" or "swipe to the third column."
[0050] It should be noted that the current state synchronization instruction for the first module sent by the client to the state machine is the latest state synchronization instruction, that is, the state synchronization instruction sent at the time closest to the current time. For example, if the client sends a current state synchronization instruction 1 for the first module at 8:00 to the state machine at 9:00, a current state synchronization instruction 2 for the first module at 9:00, and a current state synchronization instruction 3 for the first module at 10:00, then at 10:00, the latest current state synchronization instruction for the first module is current state synchronization instruction 3.
[0051] In this embodiment of the application, after the client sends the current state instruction corresponding to the first module to the state machine, the first module can be considered to have completed the synchronization. Since the state machine will ensure that the second module eventually synchronizes to the correct state, the first module can directly execute subsequent operations without waiting for the state of the second module to synchronize to the corresponding state.
[0052] S103. Based on the current state synchronization instruction, the state corresponding to the second module associated with the first module is synchronized from the second current state to the second target state; the second target state represents the state of the associated event of the second module executing the preset event; wherein, the execution speed of the first module is greater than the execution speed of the second module.
[0053] In this embodiment of the application, the state machine can record the second current state of the second module. After the state machine receives the current state synchronization instruction, it can synchronize the state of the second module associated with the first module from the second current state to the second target state according to the current state synchronization instruction.
[0054] Specifically, the execution speed of the first module is greater than that of the second module. Optionally, the second module can be a module associated with the first module in the client, a module associated with the first module in a terminal other than the client, or a module associated with the first module in the server.
[0055] It is understandable that the type of the second module is the same as or corresponds to the type of the first module, the type of the associated event is the same as or corresponds to the type of the preset event, and the type of the second target state is the same as or corresponds to the type of the first target state.
[0056] Continuing with the shopping scenario above, if the first module is the swiping action on the page, and the preset event is the swipe event, and the second module is a module on the server, then the second module could be retrieving data from the server via the network, and the associated event could be the data retrieval event associated with the swipe event. Loading data from the first column, loading data from the second column, and loading data from the third column can be considered the states of the second module. For example, if the "first target state" is "swipe to the first column," then the second target state is "load data from the first column"; if the "first target state" is "swipe to the second column," then the second target state is "load data from the second column"; if the "first target state" is "swipe to the third column," then the second target state is "load data from the third column," and so on.
[0057] It should be noted that the state machine clears all previous state synchronization instructions and executes the latest current state synchronization instruction corresponding to the first module, i.e., the state synchronization instruction sent at the time closest to the current time. For example, if the client sends a current state synchronization instruction 1 (for the first module at 8:00) to the state machine at 8:00, and then sends a current state synchronization instruction 2 (for the first module at 9:00) to the state machine at 9:00, then at 9:00, the state machine will clear current state synchronization instruction 1 and retain current state synchronization instruction 2. If, at 10:00, a current state synchronization instruction 3 (for the first module at 10:00) is sent to the state machine, then at 10:00, the state machine will clear current state synchronization instruction 2 and retain current state synchronization instruction 3.
[0058] Optionally, in the embodiments of this application, there may be various ways to set up the state machine, the first module, and the second module, and the embodiments of this application do not make specific limitations here.
[0059] In one approach, the state machine can be set up independently of both the first and second modules. This setup allows the state machine to be completely decoupled from the first and second modules, making it suitable for state synchronization between any two modules.
[0060] In another approach, the state machine can be built into the system consisting of the first module and the second module.
[0061] In another approach, the state machine can also be built into either the first or second module.
[0062] Optionally, in this embodiment, the state machine can use various methods to synchronize the state corresponding to the second module associated with the first module from the second current state to the second target state. This embodiment does not make specific limitations here.
[0063] In a feasible embodiment, the state machine can compare the first module and the second module, and based on the comparison result, synchronize the state corresponding to the second module from the second current state to the aforementioned second target state.
[0064] Figure 4 This is a flowchart illustrating, according to an exemplary embodiment, a process of synchronizing the state of a second module associated with a first module from a second current state to a second target state. For example... Figure 4 As shown, in S103 above, the synchronization of the state corresponding to the second module associated with the first module from the second current state to the second target state based on the current state synchronization instruction may include:
[0065] S1031. Identify whether the above-mentioned second current state is the same as the above-mentioned second target state.
[0066] S1033. If it is found that the second current state is the same as the second target state, control the second module to maintain the second current state.
[0067] In an optional embodiment, continue as follows Figure 4 As shown, the above method may further include:
[0068] S1035. If it is found that the second current state is different from the second target state, the state corresponding to the second module is switched from the second current state to the second target state.
[0069] In this embodiment, after the state machine receives the current state synchronization instruction, it can clear all previous state synchronization instructions, retaining only the most recent one. It can also identify the second current state and the second target state. If the second current state is identical to the second target state, it indicates that the current state of the second module recorded in the state machine has switched to the endpoint of the latest second current state (i.e., the second target state), and the state synchronization of the entire system is complete. In this case, the state machine does not perform a state switch and simply controls the second module to maintain the second current state. If the second current state is different from the second target state, the state machine can control the second module to perform a state switch to synchronize the state corresponding to the second module from the second current state to the second target state. At this point, the state synchronization of the entire system is complete.
[0070] It should be noted that after the second module completes the state transition, the state machine can re-record the latest current state of the second module.
[0071] Optionally, in this embodiment, the state machine can use various methods to identify whether the second current state is the same as the second target state, and this embodiment does not specifically limit the methods. For example, the state machine can be equipped with a state recognition module, which identifies whether the second current state is the same as the second target state.
[0072] In this embodiment, a state machine is used to identify whether the second current state is the same as the second target state. If they are the same, the second current state is maintained and no state switching is performed. Only if they are different will the second current state be switched to the second target state. This avoids redundant operations on the second module and saves data computing resources used for state switching.
[0073] Optionally, in this embodiment of the application, when the state machine recognizes that the second current state is different from the second target state, it can use various methods to switch the state corresponding to the second module from the second current state to the second target state.
[0074] In one feasible embodiment Figure 5 This is a flowchart illustrating, according to an exemplary embodiment, a process for synchronizing the state corresponding to the second module from the second current state to the second target state when it is identified that the second current state is different from the second target state. For example... Figure 5 As shown, in S1035 above, when it is identified that the second current state is different from the second target state, switching the state corresponding to the second module from the second current state to the second target state may include:
[0075] S10351. Identify whether the above-mentioned second current state is in a switching state.
[0076] S10353. When it is identified that the second current state is in the switching state and the switching state represents a switch from the second current state to the second target state, wait for the completion of the switching process corresponding to the switching state.
[0077] Optionally, in this embodiment, the state machine can identify whether the second current state is in a transition state in various ways, and this embodiment does not specifically limit the methods used. For example, the state machine can be equipped with a state recognition module to identify whether the second current state is in a transition state.
[0078] For example, "switching from the second current state to the aforementioned second target state" can mean that the second module is currently in the process of switching towards the second target state, and then it is sufficient to wait for this transition to complete.
[0079] In another feasible embodiment, continue as follows Figure 5 As shown, the above method may further include:
[0080] S10355. When it is identified that the second current state is in the switching state and the switching state represents a switch from the second current state to a non-second target state, the state after the switching process corresponding to the switching state is completed is switched to the second target state.
[0081] For example, "switching from the second current state to a non-second target state" can mean that the second module is in the process of switching to the opposite direction of the second target state. After the switching process is completed, the state after the switching process is completed will be used as the second current state again, and the second current state will be switched to the aforementioned second target state.
[0082] In another feasible embodiment, the above method may further include:
[0083] S10357. If it is identified that the second current state is in a non-switching state, the state of the second module is switched from the second current state to the second target state.
[0084] Optionally, the "non-switching state" can be a state other than the aforementioned switching state.
[0085] It is understandable that if the second current state is in a non-switching state, it indicates that the second module is in some other state besides the second target state. In this case, the state of the second module can be directly switched from the second current state to the aforementioned second target state.
[0086] In this embodiment, if the second current state is identified as different from the second target state, it can be further identified that the second current state is in a switching state. If not, the state of the second module is directly switched from the second current state to the second target state. If so, it is necessary to further determine the switching direction of the switching state and determine the final switching method based on the different switching directions. It is evident that the state machine can always synchronize the state of the second module to the latest second target state according to the current state synchronization instruction, improving the accuracy of state synchronization. Furthermore, the slower second module will not generate unnecessary redundant operations, saving data computation resources used for state switching.
[0087] The following examples illustrate S101-S103, S1031-S1035, and S10351-S10357:
[0088] In one scenario: a single switch between two states (the synchronization instruction for the current state corresponding to the first module is sent by the first module).
[0089] Figure 6 This is a schematic diagram illustrating a single switch between two states according to an exemplary embodiment.
[0090] When the first module is preparing to switch from state 1 (i.e., the first current state) to state 2 (i.e., the first target state) to execute a preset event, the first module does not communicate directly with the second module. Instead, it sends a current state synchronization instruction to the state machine. This current state synchronization instruction is used to instruct the state corresponding to the first module to be updated from state 1 (i.e., the first current state) to state 2 (i.e., the first target state). The goal of this current state synchronization instruction is to make the second module update to the second target state that executes the associated event of the aforementioned preset event.
[0091] Since the state machine will eventually ensure that the second module is synchronized to the correct second target state, the first module can assume that the synchronization is complete after the current state synchronization instruction is issued, and can perform subsequent operations without waiting.
[0092] The state machine permanently records the second current state of the second module. After the state machine receives the current state synchronization instruction, it will clear all previous state synchronization instructions, retain only the most recent current state synchronization instruction, and can identify whether the second current state is the same as the second target state.
[0093] If the second current state corresponding to the second module differs from the second target state, the state machine can control the state corresponding to the second module to switch from the second current state to the second target state. After the state corresponding to the second module switches from the second current state to the second target state, the state machine re-records the latest state of the module (i.e., the second target state), and the state synchronization of the entire system is completed. For example, if the second current state corresponding to the second module is state 1 and the second target state is state 2, then the state machine can control the state corresponding to the second module to switch from state 1 (i.e., the second current state) to state 2 (i.e., the second target state).
[0094] If the second current state is the same as the second target state, it indicates that the second module has reached the endpoint state corresponding to the current state synchronization instruction. At this point, the state synchronization of the entire system is complete. For example, if the second current state corresponding to the second module is state 2 and the second target state is state 2, it indicates that the state synchronization of the entire system is complete.
[0095] It should be noted that, Figure 6 The "State 1" in the second module is the same as or corresponds to the "State 1" in the first module. Figure 6 The "state 2" in the second module is the same as or corresponds to the "state 2" in the first module.
[0096] The following example, using the shopping scenario described above, illustrates the process of a single switch between two states:
[0097] In the shopping scenario described above, the shopping app in the client includes a three-column shopping page. Sliding on the page can be considered the first module, and the preset event can be the sliding event. Obtaining data from the server via the network can be considered the second module, and the associated event can be the data acquisition event.
[0098] Suppose the first module slides from the first column (i.e., the first current state) to the third column (i.e., the first target state). While preparing to slide from the first column to the third column, the first module does not communicate directly with the second module. Instead, it sends a current state synchronization instruction to the state machine. This current state synchronization instruction instructs the first module to slide its corresponding state from the first column to the third column. The goal of this current state synchronization instruction is to cause the second module to update to the second target state, which loads the data from the third column.
[0099] Since the state machine will eventually ensure that the second module is synchronized to the correct second target state (i.e., the state of loading the third column of data), the first module can consider the synchronization to be complete after the current state synchronization instruction is issued, and can perform subsequent operations without waiting.
[0100] The state machine permanently records the second current state of the second module. After the state machine receives the current state synchronization instruction, it clears all previous state synchronization instructions, retains only the most recent current state synchronization instruction, and can identify whether the second current state is the same as the second target state (i.e., the state that loads the third column of data).
[0101] If the second current state is the state of loading the first column of data, which is different from the second target state (i.e., the state of loading the third column of data), then the state machine can control the state corresponding to the second module to switch from the second current state to the second target state (i.e., the state of loading the third column of data). After the state corresponding to the second module switches from the second current state to the second target state, the state machine re-records the latest state of the module (i.e., the state of loading the third column of data), and the state synchronization of the entire system is completed.
[0102] If the second current state is the state of loading the third column of data, which is the same as the second target state (i.e. the state of loading the third column of data), it indicates that the second module has reached the endpoint state corresponding to the current state synchronization instruction, and the state synchronization of the entire system is completed.
[0103] In another scenario: a scenario where there is repeated switching between two states (the synchronization instruction for the current state corresponding to the first module is sent by the first module).
[0104] Figure 7 This is a schematic diagram illustrating repeated switching between two states according to an exemplary embodiment.
[0105] Since the first module can switch between state 1 and state 2 multiple times consecutively without waiting, when the first module switches from state 1 to state 2, state 1 is the first current state and state 2 is the first target state. When the first module switches from state 2 to state 1, state 2 is the first current state and state 1 is the first target state.
[0106] After receiving the latest current state synchronization instruction, the state machine uses the latest current state synchronization instruction and the second current state as the reference, and completes state synchronization according to the following rules:
[0107] The state machine clears all previous state synchronization instructions and retains only the latest current state synchronization instruction.
[0108] Identify whether the second current state is the same as the second target state mentioned above.
[0109] If the second current module is in state 2 and the second target state is also in state 2, it indicates that the second current state is already in the latest current state synchronization instruction. The second module can be controlled to maintain the second current state until the next state synchronization instruction is received.
[0110] The second current state is different from the second target state mentioned above, and can include the following three situations:
[0111] 1) When the first module switches from state 1 to state 2, if the second current state is in the process of transitioning to the second target state (for example, ... Figure 6 If the state is switched to 1), then just wait for the transition to complete.
[0112] 2) When the first module switches from state 1 to state 2, if the second current state is in the process of transitioning to a non-second target state (for example, Figure 6 If the state transition is in state 2), then wait for the transition to complete before switching the state to the second target state.
[0113] 3) If the second current state is not in a switching state, the second current state can be directly switched to the second target state.
[0114] As can be seen, when switching between states repeatedly, the state machine can always control the second module to synchronize to the latest second target state, and the slower second module will not generate unnecessary repetitive operations, thereby saving the data computing resources used for state switching.
[0115] It should be noted that, Figure 7 The "State 1" in the second module is the same as or corresponds to the "State 1" in the first module. Figure 7 The "state 2" in the second module is the same as or corresponds to the "state 2" in the first module.
[0116] Figure 8 This is a flowchart illustrating, according to an exemplary embodiment, a method for synchronizing the state corresponding to a second module from the aforementioned second current state to the aforementioned second target state. In one exemplary embodiment, the method may further include:
[0117] S201. Identify whether there is at least one intermediate state between the aforementioned second current state and the aforementioned second target state.
[0118] S203. When it is identified that there is at least one intermediate state between the second current state and the second target state, at least one state switching unit instruction corresponding to the current state synchronization instruction is generated based on the second current state, the at least one intermediate state and the second target state.
[0119] It should be noted that the current state synchronization instruction can be a general synchronization instruction, which is used to bring the second module to the final second target state. The state switching unit instruction can be a specific execution instruction, corresponding to the smallest direct switching unit in the second module.
[0120] S205. According to the above-mentioned at least one state switching unit instruction, the state corresponding to the second module is synchronized from the second current state to the second target state.
[0121] In this embodiment, there may be at least one intermediate state between the first current state and the second current state that cannot be bypassed. After receiving the current state synchronization instruction, the state machine can identify whether there is at least one intermediate state between the second current state and the second target state. If there is at least one intermediate state, it can generate at least one state switching unit instruction corresponding to the current state synchronization instruction based on the second current state, the at least one intermediate state, and the second target state. Then, based on the at least one state switching unit instruction, the state corresponding to the second module is synchronized from the second current state to the second target state.
[0122] Optionally, if there is no intermediate state, the second current state can be directly switched to the second target state. Specifically, the process of switching the second current state to the second target state can be found in steps S1031-S1035 and S103151-S10357 above, and will not be repeated here.
[0123] Optionally, in this embodiment, in step S201, the state machine can use various methods to identify whether there is at least one intermediate state between the second current state and the second target state. This embodiment does not specifically limit the methods used. For example, a state recognition module can be set in the state machine to identify whether the intermediate state exists.
[0124] Optionally, in this embodiment, in step S203 above, the state machine can generate at least one state switching unit instruction corresponding to the current state synchronization instruction in various ways, and this embodiment does not make specific limitations here.
[0125] In one approach, the state machine can determine, based on the second current state, the at least one intermediate state, and the second target state, at least one state switching unit (i.e., the smallest direct switching unit) required for the second module to synchronize from the second current state to the second target state. Then, it generates at least one state switching unit instruction corresponding to the at least one state switching unit.
[0126] For example, if at least one intermediate state includes state a, state b, and state c, then the state switching process from the second current state to the aforementioned second target state in the second module can be: second current state -> state a -> state b -> state c -> second target state. At least one state switching unit can be: second current state -> state a, state a -> state b, state b -> state c, and state c -> second target state. The instructions for at least one state switching unit can be: a switching instruction for "second current state -> state a", a switching instruction for "state a -> state b", a switching instruction for "state b -> state c", and a switching instruction for "state c -> second target state".
[0127] Optionally, in this embodiment, in step S205 above, the state machine can adopt various methods to synchronize the state corresponding to the second module from the second current state to the second target state according to the instruction of at least one state switching unit. This embodiment does not make specific limitations here.
[0128] In one approach, synchronizing the state corresponding to the second module from the second current state to the second target state according to the at least one state switching unit instruction may include:
[0129] The at least one state switching unit instruction is sorted according to the switching order to obtain a state switching unit instruction sequence; the switching order represents the order in which the at least one state switching unit corresponding to the at least one state switching unit instruction appears during the process of the second module switching from the second current state to the second target state. The state switching unit instructions in the state switching unit instruction sequence are executed sequentially to switch the state of the second module from the second current state to the second target state.
[0130] For example, if at least one state switching unit instruction is a switching instruction for "second current state -> state a", a switching instruction for "state a -> state b" corresponding to "state a -> state b", a switching instruction for "state b -> state c", and a switching instruction for "state c -> second target state", then each instruction can be sorted according to the order in which the state switching unit corresponding to each instruction switches from the second current state to the aforementioned second target state to obtain a state switching unit instruction sequence. The instructions in the state switching unit instruction sequence are then executed sequentially to synchronize the state corresponding to the second module from the aforementioned second current state to the aforementioned second target state.
[0131] In this embodiment of the disclosure, when the state machine identifies that there is at least one intermediate state between the second current state and the second target state, it can generate at least one state switching unit instruction corresponding to the current state synchronization instruction, and synchronize the state corresponding to the second module from the second current state to the second target state according to the at least one state switching unit instruction. This ensures that the state machine can always control the state of the second module to synchronize to the latest second target state according to the current state synchronization instruction, thereby improving the accuracy of state synchronization. Furthermore, the slower second module will not generate unnecessary redundant operations, saving data computing resources used for state switching.
[0132] The following example illustrates a scenario in steps S201-S205 where repeated state switching occurs between multiple states:
[0133] Figure 9 This is a schematic diagram illustrating repeated state switching between multiple states according to an exemplary embodiment.
[0134] The states 1 and 2 of the first module correspond to the response states that need to be synchronized in the second module. There are multiple state transitions in the second module, and there is an intermediate state transition between state 1 and state 2 that cannot be bypassed (i.e., state 3).
[0135] When the first module switches, a current state synchronization instruction (i.e., a general instruction) pointing to the first target state is sent to the state machine.
[0136] The state machine clears all previous state synchronization instructions and retains only the current state synchronization instruction (i.e., the general instruction).
[0137] The state machine generates at least one state switching unit instruction corresponding to the general instruction of the current state synchronization instruction based on the second current state, intermediate state and second target state of the second module.
[0138] For example, if the current state synchronization instruction corresponding to the first module is updated from state 1 (i.e., the first current state) to state 2 (i.e., the first target state), then for the second module, the generation process of at least one state switching unit instruction can be as follows:
[0139] 1) If the second current state is state 2, it indicates that the state synchronization is complete, so state 2 is maintained.
[0140] 2) If the second current state is state 1, then the following state switching unit instructions are generated: state 1 to state 3, state 3 to state 2.
[0141] 3) If the second current state is in the process of transitioning from state 1 to state 3, the following state switching unit instruction is generated: state 3 to state 2.
[0142] 4) If the second current state is in the process of transitioning from state 3 to state 2, then wait for this transition to complete.
[0143] 5) If the second current state is in the process of transitioning from state 2 to state 3, the following state switching unit instruction is generated: state 3 — state 2.
[0144] 6) If the second current state is in the process of transitioning from state 3 to state 1, the following state switching unit instructions are generated: state 1 to state 3, state 3 to state 2.
[0145] After at least one state switching unit instruction is generated, the above-mentioned at least one state switching unit instruction is executed in sequence, thereby synchronizing the second module from the first current state to the second target state.
[0146] It should be noted that if the state machine receives the next current state synchronization instruction corresponding to the first module during execution, it needs to return to the first step to start execution.
[0147] It should be noted that, Figure 9 The "State 1" in the second module is the same as or corresponds to the "State 1" in the first module. Figure 9 The "state 2" in the second module is the same as or corresponds to the "state 2" in the first module.
[0148] As can be seen, in complex multi-state, repeatedly switching scenarios, the embodiments of this application can eliminate redundant back-and-forth switching, so that the slower second module always transitions to the latest second target state, which can both speed up the execution speed of the entire system and save data computing resources.
[0149] As disclosed in the state synchronization method of the embodiments of this application, the first current state, the second current state, the first target state, and the second target state can be stored on the blockchain.
[0150] The state synchronization method provided in this application embodiment does not directly communicate with the second module. Instead, the first module sends the latest current state synchronization instruction to the state machine, which then operates the second module. This ensures that the corresponding state of the second module can eventually be synchronized from the second current state to the second target state. Therefore, after sending the latest current state synchronization instruction to the state machine, the first module does not need to wait for the second module and can directly perform subsequent operations, thereby improving the execution speed of the entire system. Furthermore, since the state machine operates the second module based on the latest current state synchronization instruction, instructions other than the latest current state synchronization instruction will not be executed, reducing redundant operations of the second module and saving data computing resources used for state switching.
[0151] Figure 10 This is a block diagram illustrating a state synchronization device according to an exemplary embodiment. For example... Figure 10 As shown, when applied to a state machine, the device may include at least:
[0152] The receiving module 301 is used to receive the current state synchronization instruction corresponding to the first module sent by the client; the current state synchronization instruction is used to indicate that the state corresponding to the first module is updated from the first current state to the first target state for executing a preset event.
[0153] The first synchronization module 303 is used to synchronize the state of the second module associated with the first module from the second current state to the second target state based on the current state synchronization instruction; the second target state represents the state of the associated event of the second module executing the preset event; wherein the execution speed of the first module is greater than the execution speed of the second module.
[0154] In one feasible embodiment, the above-described apparatus may further include:
[0155] The intermediate state identification module is used to identify whether there is at least one intermediate state between the second current state and the second target state.
[0156] The state switching unit instruction generation module is used to generate at least one state switching unit instruction corresponding to the current state synchronization instruction based on the second current state, the at least one intermediate state, and the second target state when it is identified that there is at least one intermediate state between the second current state and the second target state.
[0157] The second synchronization module is used to synchronize the state corresponding to the second module from the second current state to the second target state according to the instructions of the at least one state switching unit.
[0158] In one feasible embodiment, the first synchronization module 303 described above includes:
[0159] The first identification unit is used to identify whether the second current state is the same as the second target state.
[0160] The control unit is configured to control the second module to maintain the second current state when it is identified that the second current state is the same as the second target state.
[0161] In one feasible embodiment, the above-described apparatus may further include:
[0162] The switching unit is used to switch the state corresponding to the second module from the second current state to the second target state when it is identified that the second current state is different from the second target state.
[0163] In a feasible embodiment, the switching unit described above may include:
[0164] The switching state recognition subunit is used to identify whether the second current state is in a switching state.
[0165] The waiting subunit is used to wait for the completion of the switching process corresponding to the switching state when it is identified that the second current state is in the switching state and the switching state represents a switch to the second target state.
[0166] In one feasible embodiment, the above-described apparatus may further include:
[0167] The first switching subunit is used to switch the state after the switching process corresponding to the switching state is completed to the second target state when it is identified that the second current state is in the switching state and the switching state represents a switch to a non-second target state.
[0168] In one feasible embodiment, the above-described apparatus may further include:
[0169] The second switching subunit is used to switch the state of the second module from the second current state to the second target state when it is identified that the second current state is in a non-switching state.
[0170] It should be noted that the device embodiments provided in this application are based on the same inventive concept as the method embodiments described above.
[0171] This application also provides a state synchronization electronic device, which includes a processor and a memory. The memory stores at least one instruction or at least one program. The processor loads and executes the at least one instruction or at least one program to implement the state synchronization method provided in the above method embodiments.
[0172] Embodiments of this application also provide a computer-readable storage medium that can be disposed in a terminal to store at least one instruction or at least one program related to a state synchronization in the method embodiments, wherein the at least one instruction or at least one program is loaded and executed by a processor to implement the state synchronization method provided in the above method embodiments.
[0173] Optionally, in the embodiments of this specification, the storage medium may be located at at least one of the multiple network servers in a computer network. Optionally, in this embodiment, the storage medium may include, but is not limited to, various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.
[0174] The memory described in this specification can be used to store software programs and modules. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory. The memory may primarily include a program storage area and a data storage area. The program storage area may store the operating system, applications required for functions, etc.; the data storage area may store data created based on the use of the device, etc. Furthermore, the memory may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device. Accordingly, the memory may also include a memory controller to provide the processor with access to the memory.
[0175] This application also provides a computer program product or computer program that includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the state synchronization method provided in the above-described method embodiments.
[0176] The state synchronization method embodiments provided in this application can be executed in a terminal, computer terminal, server, or similar computing device. Taking running on a server as an example, Figure 11 This is a hardware structure block diagram of a server illustrating a state synchronization method according to an exemplary embodiment. For example... Figure 11As shown, the server 400 can vary significantly due to different configurations or performance. It may include one or more Central Processing Units (CPUs) 410 (CPUs 410 may include, but are not limited to, microprocessors such as MCUs or programmable logic devices such as FPGAs), a memory 430 for storing data, and one or more storage media 420 (e.g., one or more mass storage devices) for storing application programs 423 or data 422. The memory 430 and storage media 420 may be temporary or persistent storage. The program stored in the storage media 420 may include one or more modules, each module including a series of instruction operations on the server. Furthermore, the CPU 410 may be configured to communicate with the storage media 420 and execute a series of instruction operations stored in the storage media 420 on the server 400. The server 400 may also include one or more power supplies 460, one or more wired or wireless network interfaces 450, one or more input / output interfaces 440, and / or one or more operating systems 421, such as Windows Server. TM Mac OS X TM Unix TM Linux TM FreeBSD TM etc.
[0177] The input / output interface 440 can be used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by the communication provider of server 400. In one example, the input / output interface 440 includes a network interface controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the input / output interface 440 may be a radio frequency (RF) module for wireless communication with the Internet.
[0178] Those skilled in the art will understand that Figure 11 The structure shown is for illustrative purposes only and does not limit the structure of the aforementioned electronic device. For example, server 400 may also include... Figure 11 The more or fewer components shown, or having the same Figure 11 The different configurations shown.
[0179] It should be noted that the order of the embodiments described above is merely for descriptive purposes and does not represent the superiority or inferiority of the embodiments. Furthermore, specific embodiments have been described above. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps described in the claims can be performed in a different order than that shown in the embodiments and still achieve the desired result. Additionally, the processes depicted in the drawings do not necessarily require a specific or sequential order to achieve the desired result. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0180] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the device and server embodiments are basically similar to the method embodiments, so the descriptions are relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0181] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware, or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.
[0182] The above are merely preferred embodiments of this application and are not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A state synchronization method, characterized in that, Applied to state machines, the method includes: The system receives a current state synchronization instruction sent by the client corresponding to the first module; the current state synchronization instruction is used to indicate that the state corresponding to the first module be updated from the first current state to the first target state for executing a preset event; the current state synchronization instruction is the state synchronization instruction sent at the time closest to the current time; all instructions except the current state synchronization instruction are cleared. Based on the current state synchronization instruction, the state corresponding to the second module associated with the first module is synchronized from the second current state to the second target state; the second target state represents the state of the associated event of the second module executing the preset event; The execution speed of the first module is greater than that of the second module. After the client sends the current state synchronization instruction, the first module performs subsequent operations without waiting for the second module to complete the state synchronization. Instructions other than the current state synchronization instruction will not be executed by the state machine.
2. The state synchronization method according to claim 1, characterized in that, The method further includes: Identify whether there is at least one intermediate state between the second current state and the second target state; If at least one intermediate state is identified between the second current state and the second target state, at least one state switching unit instruction corresponding to the current state synchronization instruction is generated based on the second current state, the at least one intermediate state, and the second target state. According to the instruction of the at least one state switching unit, the state corresponding to the second module is synchronized from the second current state to the second target state.
3. The state synchronization method according to claim 1 or 2, characterized in that, The step of synchronizing the state of the second module associated with the first module from the second current state to the second target state based on the current state synchronization instruction includes: Identify whether the second current state is the same as the second target state; If it is determined that the second current state is the same as the second target state, the second module is controlled to maintain the second current state.
4. The state synchronization method according to claim 3, characterized in that, The method includes: If it is determined that the second current state is different from the second target state, the state corresponding to the second module is switched from the second current state to the second target state.
5. The state synchronization method according to claim 4, characterized in that, The step of switching the state corresponding to the second module from the second current state to the second target state when it is identified that the second current state is different from the second target state includes: Identify whether the second current state is in a transition state; If it is identified that the second current state is in the switching state, and the switching state represents a switch to the second target state, wait for the completion of the switching process corresponding to the switching state.
6. The state synchronization method according to claim 5, characterized in that, The method further includes: If it is identified that the second current state is in the switching state, and the switching state represents a switch to a non-second target state, the state after the switching process corresponding to the switching state is completed is switched to the second target state.
7. The state synchronization method according to claim 5, characterized in that, The method further includes: If it is determined that the second current state is in a non-switching state, the state of the second module is switched from the second current state to the second target state.
8. A state synchronization device, characterized in that, Applied to state machines, the device includes: A receiving module is used to receive a current state synchronization instruction corresponding to a first module sent by a client; the current state synchronization instruction is used to indicate that the state corresponding to the first module be updated from a first current state to a first target state for executing a preset event; the current state synchronization instruction is a state synchronization instruction sent at the time closest to the current time; instructions other than the current state synchronization instruction are cleared; The first synchronization module is used to synchronize the state of the second module associated with the first module from the second current state to the second target state based on the current state synchronization instruction; the second target state represents the state of the associated event of the second module executing the preset event; wherein, the execution speed of the first module is greater than the execution speed of the second module, and the first module performs subsequent operations after the client sends the current state synchronization instruction without waiting for the second module to complete the state synchronization, and the instructions other than the current state synchronization instruction will not be executed by the state machine.
9. The state synchronization device according to claim 8, characterized in that, The device further includes: Intermediate state identification module, used to identify whether there is at least one intermediate state between the second current state and the second target state; A state switching unit instruction generation module is used to generate at least one state switching unit instruction corresponding to the current state synchronization instruction based on the second current state, the at least one intermediate state, and the second target state when it is identified that at least one intermediate state exists between the second current state and the second target state. The second synchronization module is used to synchronize the state corresponding to the second module from the second current state to the second target state according to the instruction of the at least one state switching unit.
10. The state synchronization device according to claim 8 or 9, characterized in that, The first synchronization module includes: The first identification unit is used to identify whether the second current state is the same as the second target state; The control unit is configured to control the second module to maintain the second current state when it is determined that the second current state is the same as the second target state.
11. The state synchronization device according to claim 10, characterized in that, The device includes: The switching unit is used to switch the state corresponding to the second module from the second current state to the second target state when it is identified that the second current state is different from the second target state.
12. The state synchronization device according to claim 11, characterized in that, The switching unit includes: A state switching identification subunit is used to identify whether the second current state is in a switching state; The waiting subunit is used to wait for the completion of the switching process corresponding to the switching state when it is identified that the second current state is in the switching state and the switching state represents a switch to the second target state.
13. The state synchronization device according to claim 12, characterized in that, The device further includes: The first switching subunit is configured to, when it is identified that the second current state is in the switching state and the switching state represents a switch to a non-second target state, switch the state after the switching process corresponding to the switching state is completed to the second target state.
14. The state synchronization device according to claim 12, characterized in that, The device further includes: The second switching subunit is used to switch the state of the second module from the second current state to the second target state when it is identified that the second current state is in a non-switching state.
15. An electronic device for state synchronization, characterized in that, The electronic device includes a processor and a memory, the memory storing at least one instruction or at least one program, the at least one instruction or at least one program being loaded and executed by the processor to implement the state synchronization method as described in any one of claims 1 to 7.
16. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores at least one instruction or at least one program, which is loaded and executed by a processor to implement the state synchronization method as described in any one of claims 1 to 7.
17. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the state synchronization method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Interface state switching method and apparatus, storage medium and electronic device
CN108549560A
Action state synchronizing method and device, storage medium as well as electronic device
CN108650217A
Animation playing method, device and equipment and storage medium
CN111589143A