Database system state transfer method and database system
Through a finite state machine, the system's state flow is managed, and the system's automatic switching and self-recovery is realized, which solves the problem that the database system needs manual intervention during operation and improves the system's reliability.
Patent Information
- Application Number
- CN202310274141.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-21
- Publication Date
- 2025-08-29
- Estimated Expiration
- 2043-03-21
AI Technical Summary
When problems occur during operation, the database system cannot be automatically restored, and a lot of manual intervention is required, affecting the reliability of the system.
The finite state machine is used to manage the state flow of the database system, and the finite state machine performs actions according to the current state and event to realize automatic switching and self-restoration of the system state.
Reduce the frequency of manual intervention and enhance the reliability and stability of the system.
Smart Images

Figure CN116226090B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer control technology, in particular to a database system state flow method and a database system. Background Art
[0002] When database systems encounter problems during operation, they are often unable to recover, forcing manual intervention to resolve the issue. This is unacceptable for database system users. During operation, a database system may exist in multiple states, such as initialization, running, and retrying. For systems with such a complex and frequently changing state, managing the flow of state is particularly important. Summary of the Invention
[0003] The technical task of the present invention is to address the above shortcomings and provide a database system state flow method and database system, which can complete the management of automatic switching of system states, and enable the system to have a certain self-recovery ability, reduce the frequency of manual intervention to solve problems, and enhance the reliability of the system.
[0004] The technical solution adopted by the present invention to solve its technical problem is:
[0005] A database system state transition method uses a finite state machine to manage the state transition of the database system. When a problem occurs in the database system, the finite state machine takes the current state and the event that occurred as input, executes the corresponding action according to a set system state transition table, and then uses the output state as the next state of the system.
[0006] After the database system is started, it executes the actions of serially initializing each module, and then the state changes to the initialization state. If the last module is initialized successfully, the state changes to the running state. If the initialization process fails, the cleanup function is called to clean up the initialized modules and put the system into the cleanup state. After the cleanup is completed, the system executes the shutdown process, sets the state to the idle state, and executes the startup process again.
[0007] During the operation of the database system, if a module fails to run, the system executes the recovery function. If the recovery is successful, it will switch to the running state. Otherwise, it will execute the cleanup function. After the cleanup is completed, the system will execute the shutdown process and execute the startup process again.
[0008] During the process of shutting down the database system, the system first shuts down each module in series from the running state. If the shutdown is successful, the state is set to the closed state; if the shutdown fails, the shutdown is retried. If the shutdown retry fails, the system will force shutdown. If the shutdown retry is successful, the modules will continue to be shut down in series.
[0009] A finite state machine (FSM) is a tool used to model object behavior. Its primary function is to describe the sequence of states an object goes through during its lifecycle and how it responds to various external events. In computer science, FSMs are widely used in fields such as modeling application behavior, hardware circuit system design, software design, compilers, and network protocols. A FSM can only be in one of its given states at any given time. Upon receiving an input event, the state machine generates an output, which may also be accompanied by a state transition and the execution of corresponding functional actions. FSMs typically break down complex control logic into a finite number of stable states, forming a closed-loop system. Events trigger the state machine to process transactions in a predefined sequence. Traditionally, FSMs in computer control use conditional statements (switch-case or if-else) to cause the program to jump between different states by changing the input state. Complex logic processing typically involves a large number of states, with strong coupling between state transitions and numerous processing functions. Traditional methods consume more hardware and software resources. Therefore, database systems can incorporate FSMs to better manage their operational states. Finite state machines can also be used to state business processes. Predefined state transition tables (including current state, triggering events, execution actions, and flow states) allow for control and execution throughout the lifecycle. Finite state machines can respond to an event by taking an action and simultaneously updating the state. In this way, any logic can be abstracted into a series of events and states.
[0010] Furthermore, during the database system startup process, the system status recorded in latest_shutdown.log is first used to determine the status of the last system exit or whether it is the first startup.
[0011] If the database system is started for the first time, the state is set to idle and the startup process begins;
[0012] If the database system is started after a graceful exit, that is, the status read from latest_shutdown.log is Closed, the database system is started and the startup process is executed;
[0013] If the database system is restarted after an abnormal exit, that is, the status read from latest_shutdown.log is any state other than Closed, indicating that the system exited abnormally last time, the residual cleanup action is executed and the system enters the cleanup state.
[0014] Furthermore, in the cleaning state, there will be three results when the system cleans: if the number of cleaning failures is less than 3 times, the cleaning will be retried and the state will remain in the cleaning state; if the number of cleaning failures is equal to 3 times, the system will set the state to the terminated state, and human intervention is required to solve the problems in the system; if the cleaning is completed successfully, the system will execute the shutdown process.
[0015] Furthermore, during the operation of the database system, it is normally in the running state. When a module fails to run, the system executes the recovery function and switches to the retry state. If the retry is successful, it switches to the running state; otherwise, the cleanup function is executed and the cleaning state is entered; after the cleanup is successful, the closing process is executed successfully; after the closing is successful, it enters the closed state, and then the cluster is started, and each module is initialized in series, and enters the initialization state. After the last module is successfully initialized, the database system switches to the running state again; if the closing process fails, it will be forced to close and enter the forced closing state.
[0016] Furthermore, during the shutdown process of the database system, the system will first shut down each module in series from the running state and enter the closing state. If the shutdown is successful, it will enter the closed state; if the shutdown fails, it will retry the shutdown and enter the closing retry state; if the shutdown retry fails, the system will enter the forced shutdown state; if the shutdown retry is successful, it will continue to shut down each module in series and the system will be set to the closing state.
[0017] The present invention also claims protection for a database system that utilizes a finite state machine to manage the state flow of the database system, including the startup, operation, and shutdown of the database system. When a problem occurs in the database system, the finite state machine uses the current state and the event that occurred as input, executes corresponding actions according to a preset system state transition table, and then uses the output state as the next state of the system.
[0018] After the database system is started, it executes the actions of serially initializing each module, and then the state changes to the initialization state. If the last module is initialized successfully, the state changes to the running state. If the initialization process fails, the cleanup function is called to clean up the initialized modules and put the system into the cleanup state. After the cleanup is completed, the system executes the shutdown process, sets the state to the idle state, and executes the startup process again.
[0019] During the operation of the database system, if a module fails to run, the system executes the recovery function. If the recovery is successful, it will switch to the running state. Otherwise, it will execute the cleanup function. After the cleanup is completed, the system will execute the shutdown process and execute the startup process again.
[0020] During the process of shutting down the database system, the system first shuts down each module in series from the running state. If the shutdown is successful, the state is set to the closed state; if the shutdown fails, the shutdown is retried. If the shutdown retry fails, the system will force shutdown. If the shutdown retry is successful, the modules will continue to be shut down in series.
[0021] Furthermore, during the operation of the database system, it is normally in the running state. When a module fails to run, the system executes the recovery function and switches to the retry state. If the retry is successful, it switches to the running state; otherwise, the cleanup function is executed and the cleaning state is entered; after the cleanup is successful, the closing process is executed successfully; after the closing is successful, it enters the closed state, and then the cluster is started, and each module is initialized in series, and enters the initialization state. After the last module is successfully initialized, the database system switches to the running state again; if the closing process fails, it will be forced to close and enter the forced closing state.
[0022] Furthermore, during the shutdown process of the database system, the system will first shut down each module in series from the running state and enter the closing state. If the shutdown is successful, it will enter the closed state; if the shutdown fails, it will retry the shutdown and enter the closing retry state; if the shutdown retry fails, the system will enter the forced shutdown state; if the shutdown retry is successful, it will continue to shut down each module in series and the system will be set to the closing state.
[0023] Furthermore, during the database system startup process, the system status recorded in latest_shutdown.log is first used to determine the status of the last system exit or whether it is the first startup.
[0024] If the database system is started for the first time, the state is set to idle and the startup process begins;
[0025] If the database system is started after a graceful exit, that is, the status read from latest_shutdown.log is Closed, the database system is started and the startup process is executed;
[0026] If the database system is started after an abnormal shutdown, that is, the status read from the latest_shutdown.log is any state other than the Closed state, the residual cleanup action is performed and the system enters the cleanup state.
[0027] Furthermore, in the cleaning state, there will be three results when the system cleans: if the number of cleaning failures is less than 3 times, the cleaning will be retried and the state will remain in the cleaning state; if the number of cleaning failures is equal to 3 times, the system will set the state to the terminated state, and human intervention is required to solve the problems in the system; if the cleaning is completed successfully, the system will execute the shutdown process.
[0028] Compared with the prior art, the database system state transfer method and database system of the present invention have the following beneficial effects:
[0029] The method and system realize the automatic flow of system status during the startup, operation and shutdown of the database system based on finite state machine technology, so that the system has a certain self-recovery ability, reduces the frequency of manual intervention to solve problems, and enhances the reliability of the system. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] Figure 1 This is a diagram illustrating the state transition of a database system during the startup process provided by an embodiment of the present invention;
[0031] Figure 2 This is a diagram illustrating the state transition of a database system during operation provided by an embodiment of the present invention;
[0032] Figure 3 This is a state flow diagram of a database system during a shutdown process provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0033] The present invention will be further described below with reference to specific embodiments.
[0034] An embodiment of the present invention provides a database system state flow method, which uses a finite state machine to manage the state flow of the database system. When a problem occurs in the database system, the finite state machine takes the current state and the event that occurred as input, and executes corresponding actions according to a set system state transition table, and then uses the output state as the next state of the system.
[0035] like Figure 1 As shown in the figure, during the database system startup process, the system status recorded in latest_shutdown.log is first used to determine the status of the last system exit or whether it is the first startup.
[0036] If the database system is being started for the first time, it will be set to Idle and begin the startup process. After the database cluster is started, each module will be initialized serially, and then the state will transition to Initializing. If the last module is initialized successfully, the state will transition to Running. If the initialization process fails, the cleanup function will be called to clean up the initialized modules and transition to Cleanup. There are three possible outcomes during system cleanup. If the cleanup fails less than three times, the cleanup will be retried, and the state will remain in Cleanup. If the cleanup fails three times or more, the system will transition to Abort, requiring human intervention to resolve any system issues. If the cleanup completes successfully, the system will proceed to shutdown. If the system shutdown is successful, the state will transition to Idle and the startup process will be repeated. If the system shutdown fails, the state will transition to Abort, requiring human intervention to resolve the issue.
[0037] If the database system is started after a graceful exit, that is, the status read from the latest_shutdown.log is Closed, and the database cluster is started, each module is initialized serially, and the status is set to Initializing. The subsequent process is the same as the first startup process.
[0038] If the database system reads a status other than Closed in the latest_shutdown.log file during startup, indicating an abnormal system shutdown, it will clean up any remaining data and enter the Cleanup state. The subsequent state transitions follow the same process described above, specifically the three scenarios and corresponding execution methods for system cleanup. These descriptions are omitted here.
[0039] like Figure 2 As shown in the figure, during database system operation, it is normally in the Running state. If a module fails, the system executes the recovery function and transitions to the Retry state. If the retry is successful, it transitions to the Running state; otherwise, the cleanup function is executed and the Cleanup state is entered. As described above, there are three scenarios for system cleanup. This section focuses on the successful shutdown process after a successful cleanup. After a successful shutdown, it enters the Closed state, where the cluster is then started and each module is initialized serially, entering the Initializing state. After the last module is successfully initialized, the database system transitions back to the Running state. If the shutdown process fails, a forced shutdown is performed and the system enters the Force Shutdown state.
[0040] like Figure 3As shown in the figure, during the database system shutdown process, the system will first shut down each module in the Running state and enter the Closing state. If the shutdown is successful, the system will enter the Closed state. If the shutdown fails, the system will retry the shutdown and enter the Closing Retry state. If the shutdown retry fails, the system will perform a force shutdown. If the shutdown retry succeeds, the system will continue to shut down each module in sequence and enter the Closing state.
[0041] As mentioned above, database systems use finite state machines to achieve a certain degree of self-recovery capabilities during startup, operation, and shutdown. Specifically, when a problem occurs in the system, the finite state machine will use the current state and the events that have occurred as input, and perform corresponding actions according to the set system state transition table, and then use the output state as the next state of the system.
[0042] An embodiment of the present invention also provides a database system that uses a finite state machine to manage the state flow of the database system, including the startup, operation and shutdown of the database system. When a problem occurs in the database system, the finite state machine uses the current state and the events that occur as input, and executes corresponding actions according to a set system state transition table, and then uses the output state as the next state of the system.
[0043] During database system startup, the system status recorded in latest_shutdown.log is first used to determine the status of the last system exit or whether it is the first startup.
[0044] If the database system is being started for the first time, it will be set to Idle and begin the startup process. After the database cluster is started, each module will be initialized serially, and then the state will transition to Initializing. If the last module is initialized successfully, the state will transition to Running. If the initialization process fails, the cleanup function will be called to clean up the initialized modules and transition to Cleanup. There are three possible outcomes during system cleanup. If the cleanup fails less than three times, the cleanup will be retried, and the state will remain in Cleanup. If the cleanup fails three times or more, the system will transition to Abort, requiring human intervention to resolve any system issues. If the cleanup completes successfully, the system will proceed to shutdown. If the system shutdown is successful, the state will transition to Idle and the startup process will be repeated. If the system shutdown fails, the state will transition to Abort, requiring human intervention to resolve the issue.
[0045] If the database system is started after a graceful exit, that is, the status read from the latest_shutdown.log is Closed, and the database cluster is started, each module is initialized serially, and the status is set to Initializing. The subsequent process is the same as the first startup process.
[0046] If the database system reads a status other than Closed in the latest_shutdown.log file during startup, indicating an abnormal system shutdown, it will clean up any remaining data and enter the Cleanup state. The subsequent state transitions follow the same process described above, specifically the three scenarios and corresponding execution methods for system cleanup. These descriptions are omitted here.
[0047] During database system operation, it normally remains in the Running state. If a module fails, the system executes the recovery function, transitioning to the Retry state. If the retry succeeds, the system transitions to the Running state; otherwise, the cleanup function executes, entering the Cleanup state. As described above, there are three scenarios for system cleanup. This section focuses on the successful shutdown process after a successful cleanup. After a successful shutdown, the system enters the Closed state, where the cluster is then started and each module is initialized serially, entering the Initializing state. After the last module is successfully initialized, the database system transitions back to the Running state. If the shutdown process fails, a forced shutdown is performed, entering the Force Shutdown state.
[0048] During database system shutdown, the system will first shut down each module in the Running state and enter the Closing state. If the shutdown is successful, the system will enter the Closed state. If the shutdown fails, the system will retry the shutdown and enter the Closing Retry state. If the shutdown retry fails, the system will perform a forced shutdown (ForceShutdown). If the shutdown retry succeeds, the system will continue to shut down each module in sequence and enter the Closing state.
[0049] Compared with the existing technology, which uses a lot of manual intervention methods to solve the stability problems of the database system, the present invention adopts a state transition table based on a finite state machine to complete the automatic flow of the database system state during startup, operation and shutdown, so that the system has a certain self-recovery ability, reduces the frequency of manual intervention to solve problems, and enhances the stability of the system.
[0050] The above specific embodiments will allow those skilled in the art to easily implement the present invention. However, it should be understood that the present invention is not limited to the above specific embodiments. Based on the disclosed embodiments, those skilled in the art can arbitrarily combine different technical features to implement different technical solutions.
[0051] Except for the technical features described in the specification, all other technical features are known technologies to those skilled in the art.
Claims
1. A database system state transfer method, characterized in that: Finite state machines are used to manage the state flow of the database system. When a problem occurs in the database system, the finite state machine takes the current state and the events that occurred as input, executes the corresponding actions according to the set system state transition table, and then uses the output state as the next state of the system. After the database system is started, it executes the actions of serially initializing each module, and then the state changes to the initialization state. If the last module is initialized successfully, the state changes to the running state. If the initialization process fails, the cleanup function is called to clean up the initialized modules and put the system into the cleanup state. After the cleanup is completed, the system executes the shutdown process, sets the state to the idle state, and executes the startup process again. During the operation of the database system, if a module fails to run, the system executes the recovery function. If the recovery is successful, it will switch to the running state. Otherwise, it will execute the cleanup function. After the cleanup is completed, the system will execute the shutdown process and execute the startup process again. During the process of shutting down the database system, the system first shuts down each module in series from the running state. If the shutdown is successful, the state is set to the closed state; if the shutdown fails, the shutdown is retried. If the shutdown retry fails, the system will force shutdown. If the shutdown retry is successful, the modules will continue to be shut down in series.
2. A database system state transfer method according to claim 1, characterized in that: During the database system startup process, the system status recorded in latest_shutdown.log is first used to determine the status of the last system exit or whether it is the first startup. If the database system is started for the first time, the state is set to idle and the startup process begins; If the database system is started after a graceful exit, that is, the status read from latest_shutdown.log is Closed, the database system is started and the startup process is executed; If the database system is started after an abnormal shutdown, that is, the status read from the latest_shutdown.log is any state other than the Closed state, the residual cleanup action is performed and the system enters the cleanup state.
3. A database system state transfer method according to claim 1 or 2, characterized in that: In the cleaning state, there will be three results when the system cleans: if the number of cleaning failures is less than 3 times, the cleaning will be retried and the state will remain in the cleaning state; if the number of cleaning failures is equal to 3 times, the system will set the state to the terminated state, and human intervention is required to solve the problem in the system; if the cleaning is completed successfully, the system will execute the shutdown process.
4. A database system state transfer method according to claim 3, characterized in that: During the operation of the database system, it is normally in the running state. When a module fails to run, the system executes the recovery function and switches to the retry state. If the retry succeeds, it switches to the running state; otherwise, it executes the cleanup function and enters the cleanup state. After the cleanup is successful, the shutdown process is executed successfully; after the shutdown is successful, it enters the closed state, then the cluster is started, and each module is initialized in series, entering the initialization state. After the last module is initialized successfully, the database system returns to the running state again; if the shutdown process fails, it will be forced to close and enter the forced shutdown state.
5. A database system state transfer method according to claim 4, characterized in that: During the shutdown process of the database system, the system will first shut down each module in series from the running state and enter the closing state. If the shutdown is successful, it will enter the closed state; if the shutdown fails, the shutdown will be retried and the shutdown will be entered into the closing retry state; if the shutdown retry fails, the system will enter the forced shutdown state; if the shutdown retry is successful, the modules will continue to be shut down in series and the system will be placed into the closing state.
6. A database system, characterized in that: The system uses a finite state machine to manage the state flow of the database system, including the startup, operation and shutdown of the database system. When a problem occurs in the database system, the finite state machine takes the current state and the event as input, and performs the corresponding action according to the set system state transition table, and then uses the output state as the next state of the system. After the database system is started, it executes the actions of serially initializing each module, and then the state changes to the initialization state. If the last module is initialized successfully, the state changes to the running state. If the initialization process fails, the cleanup function is called to clean up the initialized modules and put the system into the cleanup state. After the cleanup is completed, the system executes the shutdown process, sets the state to the idle state, and executes the startup process again. During the operation of the database system, if a module fails to run, the system executes the recovery function. If the recovery is successful, it will switch to the running state. Otherwise, it will execute the cleanup function. After the cleanup is completed, the system will execute the shutdown process and execute the startup process again. During the process of shutting down the database system, the system first shuts down each module in series from the running state. If the shutdown is successful, the state is set to the closed state; if the shutdown fails, the shutdown is retried. If the shutdown retry fails, the system will force shutdown. If the shutdown retry is successful, the modules will continue to be shut down in series.
7. A database system according to claim 6, characterized in that: During the operation of the database system, it is normally in the running state. When a module fails to run, the system executes the recovery function and switches to the retry state. If the retry succeeds, it switches to the running state; otherwise, it executes the cleanup function and enters the cleanup state. After the cleanup is successful, the shutdown process is executed successfully; after the shutdown is successful, it enters the closed state, then the cluster is started, and each module is initialized in series, entering the initialization state. After the last module is initialized successfully, the database system returns to the running state again; if the shutdown process fails, it will be forced to close and enter the forced shutdown state.
8. A database system according to claim 6, characterized in that: During the shutdown process of the database system, the system will first shut down each module in series from the running state and enter the closing state. If the shutdown is successful, it will enter the closed state; if the shutdown fails, the shutdown will be retried and the shutdown will be entered into the closing retry state; if the shutdown retry fails, the system will enter the forced shutdown state; if the shutdown retry is successful, the modules will continue to be shut down in series and the system will be placed into the closing state.
9. A database system according to claim 6, 7 or 8, characterized in that: During the database system startup process, the system status recorded in latest_shutdown.log is first used to determine the status of the last system exit or whether it is the first startup. If the database system is started for the first time, the state is set to idle and the startup process begins; If the database system is started after a graceful exit, that is, the status read from latest_shutdown.log is Closed, the database system is started and the startup process is executed; If the database system is started after an abnormal shutdown, that is, the status read from the latest_shutdown.log is any state other than the Closed state, the residual cleanup action is performed and the system enters the cleanup state.
10. A database system according to claim 9, characterized in that: In the cleaning state, there will be three results when the system cleans: if the number of cleaning failures is less than 3 times, the cleaning will be retried and the state will remain in the cleaning state; if the number of cleaning failures is equal to 3 times, the system will set the state to the terminated state, and human intervention is required to solve the problem in the system; if the cleaning is completed successfully, the system will execute the shutdown process.
Citation Information
Patent Citations
Modeling method based on business process management of extended finite state machine
CN104866981A
Method and system of monitoring appliance usage
CN107257984A