Database Upgrade Method, Device, Equipment and Medium under Physical Primary-Standby Architecture
By closing the process in the synchronization state of the main and backup database nodes and updating it to a new version of the executable file, using the metadata update instruction to obtain the latest data page from the backup node, the long time-consuming problem caused by the complexity of the main and backup switching is solved, and efficient database upgrade is achieved.
Patent Information
- Application Number
- CN202411078233.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-07
- Publication Date
- 2025-07-18
- Estimated Expiration
- 2044-08-07
AI Technical Summary
In the prior art, the physical master-support switching process is complicated, which causes the database upgrade to take a long time and may interrupt the upper-level business services. How to simplify the upgrade process of the database under the master-support architecture and shorten the total time to upgrade.
When the main database node is synchronized with the backup database node, the process of the main database node is closed, updated to a new version of the executable file, and the latest data page obtained from the backup database node through metadata update instructions to update and restore business.
Simplify the upgrade process, shorten the database upgrade time, reduce business interruption time, and improve the efficiency of database upgrade.
Smart Images

Figure CN119105776B_ABST
Abstract
Description
Technical Field
[0001] This application is applicable to the technical field of database upgrade, and particularly relates to a database upgrade method, device, equipment and medium under a physical master-slave architecture. Background Art
[0002] For database upgrade under a master-slave architecture, the rolling upgrade method is usually adopted to ensure the continuous availability of the entire database system. The core of the rolling upgrade method is to upgrade database nodes one by one or in batches without interrupting the database system. In the prior art, the implementation of the rolling upgrade is as follows: First, upgrade the standby database node, and after the upgrade is completed, switch the services of the master database node to the upgraded standby database node. Then, upgrade the master database node, and after the upgrade is completed, switch the services back to the upgraded master database node again. However, in the above rolling upgrade process, it is necessary to switch the physical master-slave to logical master-slave, and then switch back to physical master-slave after the upgrade of the master database node is completed. This conversion process between physical master-slave and logical master-slave not only increases the complexity of the upgrade, but also may cause the upgrade to take a long time. Moreover, during the switch between physical master-slave and logical master-slave, the database system will interrupt the service to the upper-layer services and generate log discrepancies. Therefore, how to simplify the database upgrade process under the master-slave architecture and shorten the total upgrade time has become an urgent problem to be solved. Summary of the Invention
[0003] In view of this, the embodiments of this application provide a database upgrade method, device, equipment and medium under a physical master-slave architecture to solve the problem of how to simplify the database upgrade process under the master-slave architecture and shorten the total upgrade time.
[0004] In a first aspect, the embodiments of this application provide a database upgrade method under a physical master-slave architecture. The database upgrade method is applied to the master database node in the master-slave architecture and includes:
[0005] Stop the services of the master database node, and when the master database node and the standby database node are in a synchronized state, shut down the process of the master database node;
[0006] Update the master database node according to the new version executable file, and after the update of the master database node is completed, start the process of the master database node;
[0007] Obtain the metadata update instruction corresponding to the new version executable file, and detect whether the data page corresponding to the metadata update instruction in the master database node is in the latest state;
[0008] If it is detected that the data page corresponding to the metadata update instruction in the primary database node is not in the latest state, obtain the data page in the latest state corresponding to the metadata update instruction from the standby database node. When the primary database node and the standby database node are in a synchronized state, the data page in the standby database node is characterized as being in the latest state;
[0009] According to the metadata update instruction, update the corresponding metadata in the data page in the latest state corresponding to the metadata update instruction. After the execution of the metadata update instruction is completed, resume the service of the primary database node.
[0010] In a second aspect, an embodiment of the present application provides a database upgrade device under a physical primary-standby architecture. The database upgrade device is applied to the primary database node in the primary-standby architecture and includes:
[0011] A synchronization module, configured to stop the service of the primary database node and close the process of the primary database node when the primary database node and the standby database node are in a synchronized state;
[0012] A file update module, configured to update the primary database node according to the new version executable file and start the process of the primary database node after the update of the primary database node is completed;
[0013] A detection module, configured to obtain a metadata update instruction corresponding to the new version executable file and detect whether the data page corresponding to the metadata update instruction in the primary database node is in the latest state;
[0014] An acquisition module, configured to, if it is detected that the data page corresponding to the metadata update instruction in the primary database node is not in the latest state, obtain the data page in the latest state corresponding to the metadata update instruction from the standby database node. When the primary database node and the standby database node are in a synchronized state, the data page in the standby database node is characterized as being in the latest state;
[0015] A metadata update module, configured to update the corresponding metadata in the data page in the latest state corresponding to the metadata update instruction according to the metadata update instruction and resume the service of the primary database node after the execution of the metadata update instruction is completed.
[0016] In a third aspect, an embodiment of the present application provides a computer device. The computer device includes a processor, a memory, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the database upgrade method under the physical primary-standby architecture described in the first aspect is implemented.
[0017] Fourthly, an embodiment of the present application provides a computer-readable storage medium storing a computer program, and when the computer program is executed by a processor, it implements the database upgrade method under the physical primary and standby architecture as described in the first aspect.
[0018] The beneficial effects of the embodiment of the present application compared with the prior art are as follows: The database upgrade method of the present application is applied to the primary database node in the primary and standby architecture. By stopping the service of the primary database node, when the primary database node and the standby database node are in a synchronized state, the process of the primary database node is shut down. After the primary database node is updated according to the new version executable file, the process of the primary database node is started, and the metadata update instruction corresponding to the new version executable file is obtained. If it is detected that the data page corresponding to the metadata update instruction in the primary database node is not in the latest state, the data page in the latest state corresponding to the metadata update instruction is obtained from the standby database node. Among them, when the primary database node and the standby database node are in a synchronized state, the data page in the standby database node is characterized as the latest state. According to the metadata update instruction, the corresponding metadata in the data page in the latest state corresponding to the metadata update instruction is updated. After the metadata update instruction is executed, the service of the primary database node is restored.
[0019] Among them, when the primary database node and the standby database node are in a synchronized state, the process of the primary database node is shut down again, so that when the process of the primary database node is shut down, the data pages between the primary database node and the standby database node are exactly the same, that is, the data page in the standby database node can be characterized as the latest state. Therefore, after the process of the primary database node is restarted, the data page corresponding to the metadata update instruction can be obtained from the standby database node, and the metadata update instruction can be directly executed. Compared with the method of replaying the log data required for restarting and restoring the data page in the primary database node to the latest state before the process is shut down and then executing the metadata update instruction after the process of the primary database node is restarted, the present application enables the primary database node to skip the log replay process and directly execute the metadata update instruction after the process is restarted. The data page in the latest state required for the metadata update instruction can be obtained from the standby database node, which simplifies the upgrade process and shortens the time required for the primary database node to restart, thereby shortening the total time required for database upgrade. At the same time, during the upgrade of the primary database, the service interruption time can include: the time from stopping the service to shutting down the process, the time for replacing the new version executable file, and the time for executing the metadata update instruction. Among them, the first two parts of the interruption time are related to the hardware performance and can usually be completed within a few seconds. The time for executing the metadata update instruction is related to the amount of metadata and can usually be completed within a few seconds. Therefore, compared with the rolling upgrade method of mutual switching between logical primary and standby and physical primary and standby, the service interruption time during the database upgrade process is shortened. Brief Description of the Drawings
[0020] To more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.
[0021] Figure 1 It is a schematic flowchart of a database upgrade method under a physical primary and standby architecture provided by Embodiment 1 of the present application;
[0022] Figure 2 It is a schematic flowchart of a database upgrade method under a physical primary and standby architecture provided by Embodiment 2 of the present application;
[0023] Figure 3 It is a schematic flowchart of a database upgrade method under a physical primary and standby architecture provided by Embodiment 3 of the present application;
[0024] Figure 4 It is a schematic flowchart of a database upgrade method under a physical primary and standby architecture provided by Embodiment 4 of the present application;
[0025] Figure 5 It is a schematic flowchart of a database upgrade method under a physical primary and standby architecture provided by Embodiment 5 of the present application;
[0026] Figure 6 It is a schematic flowchart of a database upgrade method under a physical primary and standby architecture provided by Embodiment 6 of the present application;
[0027] Figure 7 It is a schematic structural diagram of a database upgrade device under a physical primary and standby architecture provided by Embodiment 7 of the present application;
[0028] Figure 8 It is a schematic structural diagram of a computer device provided by Embodiment 8 of the present application. Detailed Description of the Invention
[0029] In the following description, for the purpose of illustration rather than limitation, specific details such as specific system structures and technologies are put forward in order to thoroughly understand the embodiments of the present application. However, those skilled in the art should clearly understand that the present application can also be implemented in other embodiments without these specific details. In other cases, the detailed descriptions of well-known systems, devices, circuits, and methods are omitted to avoid unnecessary details from interfering with the description of the present application.
[0030] It should be understood that, as used in the specification of this application and the appended claims, the term "comprising" indicates the presence of the described features, integers, steps, operations, elements and / or components, but does not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or their combinations.
[0031] It should also be understood that the term "and / or" as used in the specification of this application and the appended claims refers to any combination and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0032] As used in the specification of this application and the appended claims, the term "if" may be construed, depending on the context, as "when", "once", "in response to determining", or "in response to detecting". Similarly, the phrase "if determined" or "if detected [the described condition or event]" may be construed, depending on the context, as meaning "once determined", "in response to determining", "once detected [the described condition or event]", or "in response to detecting [the described condition or event]".
[0033] In addition, in the description of the specification of this application and the appended claims, the terms "first", "second", "third", etc. are used only for descriptive distinction and should not be construed as indicating or implying relative importance.
[0034] The reference to "one embodiment" or "some embodiments" etc. described in the specification of this application means that a specific feature, structure or characteristic described in connection with that embodiment is included in one or more embodiments of this application. Thus, statements such as "in one embodiment", "in some embodiments", "in other some embodiments", "in still other embodiments" etc. that appear in different places in this specification are not necessarily all referring to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized. The terms "comprising", "including", "having" and their variants all mean "including but not limited to", unless otherwise specifically emphasized.
[0035] The embodiments of this application may acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence is a theory, method, technology and application system that uses a digital computer or a machine controlled by a digital computer to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use the knowledge to obtain the best results.
[0036] The basic technologies of artificial intelligence generally include technologies such as sensors, special artificial intelligence chips, cloud computing, distributed storage, big data processing technologies, operation / interaction systems, and mechatronics. The software technologies of artificial intelligence mainly include several major directions such as computer vision technology, robotics, biometric technology, speech processing technology, natural language processing technology, and machine learning / deep learning.
[0037] It should be understood that the magnitudes of the sequence numbers of the steps in the following embodiments do not mean the order of execution, and the execution order of each process should be determined according to its function and internal logic, and should not constitute any limitation to the implementation process of the embodiments of the present application.
[0038] In order to illustrate the technical solution of the present application, the following will be described through specific embodiments.
[0039] See Figure 1 , which is a schematic flowchart of a database upgrade method under a physical primary / standby architecture provided by Embodiment 1 of the present application. The above database upgrade method is applied to the primary database node in the primary / standby architecture. As Figure 1 shown, the database upgrade method may include the following steps:
[0040] Step S101, stop the service of the primary database node. When the primary database node and the standby database node are in a synchronized state, shut down the process of the primary database node.
[0041] In the embodiments of the present application, in a database system adopting a primary / standby deployment architecture, the primary database node may refer to the main node in the database system, which is responsible for processing all write operations (for example, insertions and deletions, etc.), and synchronizes its own data changes to the standby database node in real time or periodically. The standby database node may refer to the backup node of the primary database node, which is responsible for replicating the data of the primary database node and keeping the data synchronized with the primary database node.
[0042] For example, it can be notified to the upstream and downstream of the system and relevant business parties to inform them to stop the business service of the primary database node at a certain time point. When upgrading the primary database node, close the server entry of the primary database node to stop the business of the primary database node, and wait for the standby database node to synchronize all the current redo logs (RedoLog) of the primary database node. When the data pages of the standby database node and the primary database node are completely consistent, it is determined that the primary database node and the standby database node are in a synchronized state, and the process of the primary database node is shut down using a database management tool.
[0043] Step S102, update the primary database node according to the new version executable file. After the update of the primary database node is completed, start the process of the primary database node.
[0044] In an embodiment of the present application, the new version executable file may refer to the executable file corresponding to the updated version of the database software. The executable file contains the machine code required for the operation of the database system. For example, the new version executable file may be a new version binary file, that is, the form of the executable file is binary.
[0045] Specifically, the new version executable file contains new functions and performance improvements. When the database software is upgraded, the path of the new version executable file can be obtained. According to the path of the new version executable file, the corresponding new version executable file can be obtained, and the old version executable file in the database system is replaced with the new version executable file to run the functions and features of the new version executable file. After the replacement of the new version executable file is completed, the process of the main database node is restarted.
[0046] Step S103: Obtain the metadata update instruction corresponding to the new version executable file, and detect whether the data page corresponding to the metadata update instruction in the main database node is in the latest state.
[0047] Step S104: If it is detected that the data page corresponding to the metadata update instruction in the main database node is not in the latest state, obtain the data page in the latest state corresponding to the metadata update instruction from the standby database node.
[0048] Step S105: Update the corresponding metadata in the data page in the latest state corresponding to the metadata update instruction according to the metadata update instruction. After the execution of the metadata update instruction is completed, resume the business of the main database node.
[0049] In an embodiment of the present application, metadata may refer to data that describes the structure, attributes, storage location, etc. of the data in the database. A metadata update instruction may refer to an instruction for updating metadata. Among them, the metadata update instruction may be Structured Query Language (SQL). For example, the metadata update instruction for adding a new column named age to the students table to store the age of students may be "ALTER TABLE students ADD age DATE;". A data page may refer to the basic unit for storing data in the database. Among them, the state of the data page when the process of the main database node is closed is the latest state. When the main database node and the standby database node are in a synchronized state, the data page in the standby database node can be characterized as the latest state.
[0050] After replacing the old version of the executable file with the new version of the executable file and updating the primary database node, new data structures, tables, fields, etc. may be introduced in the new version of the executable file configured on the primary database node. Therefore, it is necessary to update the corresponding metadata with the metadata update instructions corresponding to the new version of the executable file to maintain data consistency and integrity.
[0051] Specifically, during the execution of the metadata update instructions, first, locally detect on the primary database node whether the data pages required by the metadata update instructions are in the latest state. For example, this can be determined by detecting the flag bit recording the status of the data page to determine whether the data page is in the latest state. Then, if it is detected on the primary database node locally that the data page corresponding to the metadata update instruction is not in the latest state, obtain the data page in the latest state corresponding to the metadata update instruction from the standby database node. Finally, update the corresponding metadata in the data page in the latest state obtained according to the metadata update instructions. After all the metadata update instructions are executed, resume the business of the primary database node.
[0052] For example, in a database system adopting a physical primary-standby architecture, including a primary database node and a standby database node, the version number of the current executable file is 2.1.0, and the version number of the new version of the executable file is 2.2.0. For the upgrade of the metadata corresponding to the new version of the executable file, if a new column columnY needs to be added to the system table tableX, the overall process of upgrading this primary-standby architecture database system can be as follows:
[0053] 1) Stop the business of the primary database node. When the data pages in the primary database node and the standby database node are exactly the same, determine that the primary database node and the standby database node are in a synchronized state, and then shut down the process of the primary database node; 2) Replace the current executable file of version 2.1.0 with the new version of the executable file of version 2.2.0. After the replacement is completed, start the process of the primary database node; 3) Directly execute the metadata update instructions to add column columnY to the system table tableX, and simultaneously start the background log replay thread to continuously replay all the primary log data required for the restart of the primary database node in the background to update all the data pages in the primary database node to the latest state when the primary database node was shut down; 4) After all the metadata update instructions are executed, resume the business of the primary database node; 5) After all the primary log data of the primary database node is replayed, send the primary upgrade log data generated during the upgrade of the primary database node to the standby database node to instruct the standby database node to perform the upgrade.
[0054] Among them, the execution process of the metadata update instruction in the above 3) can be as follows: Detect whether the data page corresponding to the metadata update instruction in the primary database node is in the latest state. If it is not in the latest state, obtain the data page in the latest state corresponding to the metadata update instruction from the standby database node, and update the corresponding metadata in the data page in the latest state corresponding to the metadata update instruction according to the metadata update instruction.
[0055] The process of synchronously starting the background log replay thread in the above 3) to continuously replay all the primary log data required for the restart of the primary database node in the background can be as follows: For any primary log data, detect whether the data page corresponding to the primary log data is in the latest state. If it is not in the latest state, perform a replay operation on the primary log data so that the data page corresponding to the primary log data is replayed and updated to obtain the data page in the latest state. If it is in the latest state, skip the replay operation on the primary log data.
[0056] Optionally, after restoring the service of the primary database node in the above 4), the primary database node responds to the page request sent by the upper-layer service, detects whether the data page corresponding to the page request in the primary database node is in the latest state. If it is in the latest state, send the data page in the latest state corresponding to the page request to the upper-layer service. If it is not in the latest state, obtain the data page in the latest state corresponding to the page request from the standby database node and send the data page in the latest state corresponding to the page request to the upper-layer service.
[0057] In an embodiment of the present application, when the primary database node and the standby database node are in a synchronized state, the process of the primary database node is then shut down, so that when the process of the primary database node is shut down, the data pages between the primary database node and the standby database node are exactly the same, that is, the data pages in the standby database node can be characterized as the latest state. Therefore, after restarting the process of the primary database node, the data pages corresponding to the metadata update instruction can be obtained from the standby database node, and the metadata update instruction can be directly executed. In contrast, after restarting the process of the primary database node, the log data required for restart is played back, and after restoring the data pages in the primary database node to the latest state before the process was shut down, the metadata update instruction is then executed. The present application enables the primary database node to skip the log playback process after restarting the process and directly execute the metadata update instruction. The data pages in the latest state required by the metadata update instruction can be obtained from the standby database node, simplifying the upgrade process and shortening the time required for the primary database node to restart, thereby shortening the total time required for database upgrade. At the same time, during the upgrade process of the primary database, the service interruption time can include: the time from stopping the service to shutting down the process, the time to replace the new version executable file, and the time to execute the metadata update instruction. Among them, the first two parts of the interruption time are related to the hardware performance and can usually be completed within a few seconds. The time to execute the metadata update instruction is related to the amount of metadata and can usually be completed within a few seconds. Therefore, compared with the rolling upgrade method of logical primary-standby and physical primary-standby switching, the service interruption time during the database upgrade process is shortened.
[0058] See Figure 2 , which is a schematic flowchart of a database upgrade method under a physical primary-standby architecture provided in the second embodiment of the present application. As Figure 2 shown, after stopping the service of the primary database node in the above step S101, the database upgrade method may further include the following steps:
[0059] Step S201: Obtain the primary synchronization log data required for the standby database node to synchronize with the primary database node from all the primary log data of the primary database node locally, and send the primary synchronization log data to the standby database node.
[0060] Step S202: After the standby database node completes the playback operation on the primary synchronization log data, determine that the primary database node and the standby database node are in a synchronized state.
[0061] In the embodiments of the present application, the primary log data may refer to the log of data operations recorded by the primary database node. For example, the primary log data may be the Redo log. The primary synchronization log data may refer to the primary log data required for the standby database node to synchronize with the primary database node. For example, during the normal operation of the primary database node and the standby database node, the standby database node automatically replays the primary log data of the primary database node to maintain data synchronization with the primary database node. After stopping the service of the primary database node, the primary synchronization log data may refer to the primary log data that the standby database node has not synchronized. When the synchronization delay between the primary database node and the standby database node is relatively low, the primary synchronization log data may be the last log data of the primary log data.
[0062] For example, when the synchronization delay between the primary database node and the standby database node is relatively low, the last log data of the primary log data is sent to the standby database node as the primary synchronization log data to instruct the standby database node to perform a replay operation on the primary synchronization log data. After the standby database node completes the replay operation on the primary synchronization log data, the data pages of the standby database node and the primary database node are exactly the same, that is, it is determined that the primary database node and the standby database node are in a synchronized state.
[0063] In the embodiments of the present application, after stopping the service of the primary database node, by determining that the primary database node and the standby database node are in a synchronized state after the standby database node completely synchronizes the primary log data of the primary database node, when the process of the primary database node is closed, the data pages between the primary database node and the standby database node are exactly the same, that is, the data pages in the standby database node can be characterized as the latest state. Therefore, after restarting the process of the primary database node, the data page corresponding to the metadata update instruction can be obtained from the standby database node and the metadata update instruction can be directly executed, which simplifies the upgrade process and shortens the time required for the primary database node to restart, thereby shortening the total time-consuming for database upgrade.
[0064] See Figure 3 , which is a schematic flowchart of a database upgrade method under a physical primary-standby architecture provided in Embodiment 3 of the present application. As Figure 3 shown, after starting the process of the primary database node in the above step S102, the database upgrade method may further include the following steps:
[0065] Step S301, obtain all the primary log data of the primary database node, and for any primary log data, detect whether the data page corresponding to the primary log data is in the latest state.
[0066] Step S302: If it is detected that the data page corresponding to the main log data is not in the latest state, perform a playback operation on the main log data so that the data page corresponding to the main log data is updated by playback to obtain a data page in the latest state.
[0067] Step S303: If it is detected that the data page corresponding to the main log data is in the latest state, skip the playback operation on the main log data.
[0068] In the embodiment of the present application, after restarting the process of the primary database node, a background log playback thread can also be started to continuously playback all the main log data required for the restart of the primary database node in the background, so as to update all the data pages in the primary database node to the latest state when the primary database node is shut down.
[0069] Specifically, during the process of starting the background thread to playback the main log data, for any main log data, it is detected whether the data page corresponding to the main log data is in the latest state. If it is detected that the data page corresponding to the main log data is not in the latest state, a playback operation is performed on the main log data so that the data page corresponding to the main log data is updated by playback to obtain a data page in the latest state. If during the execution of the metadata update instruction, the data page corresponding to the main log data has been obtained from the standby database, it can be considered that the data page corresponding to the main log data is in the latest state, and the playback operation on the main log data is skipped.
[0070] In the embodiment of the present application, by continuously playing back all the main log data required for the restart of the primary database node in the background after restarting the process of the primary database node, all the data pages in the primary database node are updated to the latest state when the primary database node is shut down. Among them, performing log playback in the background enables the metadata update instruction to be directly executed after the primary database node is restarted, quickly restoring the business of the primary database node. On the basis of ensuring that the data state of the primary database node after restart is consistent with that before the process is shut down, the time of business interruption of the primary database node is reduced, and the total time consumed for database upgrade is shortened.
[0071] See Figure 4 , which is a schematic flowchart of a database upgrade method under a physical primary-standby architecture provided in Embodiment 4 of the present application. As Figure 4 shown, the database upgrade method may further include the following steps:
[0072] Step S401: After all the main log data have been played back, obtain the main upgrade log data generated during the upgrade of the primary database node.
[0073] Step S402: Send the main upgrade log data to the standby database node.
[0074] In the embodiment of the present application, the main upgrade log data may refer to the main log data generated during the upgrade of the main database node. After the main database node restarts the process, the main upgrade log data is the main log data generated by executing the metadata update instruction and providing services to the upper-layer service.
[0075] Specifically, after all the main log data has been replayed, obtain the main upgrade log data generated by the main database node after restarting the process, executing the metadata update instruction, and providing services to the upper-layer service. Send the main upgrade log data to the standby database node to instruct any standby database node to shut down the process of the standby database node. Update the standby database node according to the new version of the executable file. After the update of the standby database node is completed, start the process of the standby database node to receive the main upgrade log data and perform a replay operation on the main upgrade log data. After the replay operation of the main upgrade log data is completed, obtain the upgraded standby database node.
[0076] In the embodiment of the present application, after all the main log data of the main database node has been replayed, the main upgrade log data is sent to the standby database node to instruct the standby database node to perform an upgrade, ensuring data consistency between the main database node and the standby database node. The standby database node only needs to shut down the process, replace the new version of the executable file, start the process, and perform a replay according to the main upgrade log data to complete the upgrade process. Compared with the rolling upgrade method in the prior art, after the standby database node is upgraded, physical master-slave and logical master-slave switches are still required, which simplifies the upgrade process, reduces the complexity of the upgrade, and thus shortens the total upgrade time.
[0077] See Figure 5 , which is a schematic flowchart of a database upgrade method under a physical master-slave architecture provided in Embodiment 5 of the present application. As Figure 5 shown, the steps of obtaining the data page corresponding to the metadata update instruction from the standby database node in step S104 above may include the following steps:
[0078] Step S501, obtain the page identifier of the data page corresponding to the metadata update instruction, and send the page identifier to the standby database node.
[0079] Step S502, obtain the content of the data page corresponding to the page identifier feedback by the standby database node, and use the content of the data page corresponding to the page identifier feedback by the standby database node to overwrite the content of the data page corresponding to the metadata update instruction of the main database node locally, so as to obtain the data page in the latest state corresponding to the metadata update instruction.
[0080] In the embodiment of the present application, the page identifier may refer to the identification (ID) of the data page.
[0081] Specifically, first, obtain the page identifier of the data page corresponding to the metadata update instruction, and send the page identifier to the standby database node to instruct the standby database node to determine the data page corresponding to the page identifier locally in the standby database node, and feedback the content of the data page corresponding to the page identifier to the primary database node. Then, obtain the content of the data page corresponding to the page identifier fed back by the standby database node, and use the content of the data page corresponding to the page identifier fed back by the standby database node to overwrite the content of the data page corresponding to the metadata update instruction locally in the primary database node. After the overwriting is completed, obtain the data page in the latest state corresponding to the metadata update instruction locally in the primary database node.
[0082] In the embodiment of the present application, when it is detected that the data page corresponding to the metadata update instruction in the primary database node is not in the latest state, the corresponding data page in the latest state is obtained from the standby database node through the identifier of the data page, and the data page locally in the primary database node is overwritten to obtain the data page in the latest state locally, which improves the acquisition efficiency of the data page in the latest state corresponding to the metadata update instruction, thereby shortening the total time consumed for data upgrade.
[0083] See Figure 6 , which is a schematic flowchart of a database upgrade method under a physical primary-standby architecture provided in Embodiment 6 of the present application. As Figure 6 shown, after restoring the service of the primary database node in the above step S105, the database upgrade method further includes the following steps:
[0084] Step S601, obtain a page request sent by the upper-layer service, and detect whether the data page corresponding to the page request in the primary database node is in the latest state.
[0085] Step S602, if it is detected that the data page corresponding to the page request in the primary database node is in the latest state, send the data page in the latest state corresponding to the page request to the upper-layer service.
[0086] Step S603, if it is detected that the data page corresponding to the page request in the primary database node is not in the latest state, obtain the data page in the latest state corresponding to the page request from the standby database node, and send the data page in the latest state corresponding to the page request to the upper-layer service.
[0087] In the embodiment of the present application, the upper-layer service may refer to a user interface layer responsible for receiving user input (such as a page request, etc.), and the page request may refer to a request for obtaining a data page.
[0088] Specifically, after the primary database node resumes its services, in response to a page request from the upper-layer service, it is detected whether the data page corresponding to the page request in the page cache of the primary database node is in the latest state. If it is detected that the data page corresponding to the page request in the page cache is in the latest state, the data page in the latest state corresponding to the page request is directly sent to the upper-layer service. If it is detected that the data page corresponding to the page request in the page cache is not in the latest state, the data page in the latest state corresponding to the page request is obtained from the standby database node. Specifically, reference can be made to the content in steps S501 to S502, and the data page in the latest state corresponding to the page request is sent to the upper-layer service.
[0089] In the embodiment of the present application, after the primary database node resumes its services, it can respond to a page request from the upper-layer service. If there is no data page in the latest state corresponding to the page request locally, the data page in the latest state corresponding to the page request is obtained from the standby database node and sent to the upper-layer service. Compared with resuming services after the log replay of the primary database node is completed, the service interruption time of the upper-layer service caused by database upgrade is reduced.
[0090] Corresponding to the database upgrade method under the physical primary-standby architecture in the above embodiment, Figure 7 FIG. shows the structural block diagram of the database upgrade device under the physical primary-standby architecture provided in the seventh embodiment of the present application. The above database upgrade device is applied to the primary database node in the primary-standby architecture. For the sake of convenience of description, only the parts related to the embodiment of the present application are shown.
[0091] See Figure 7 , the database upgrade device includes:
[0092] A synchronization module 71, configured to stop the services of the primary database node and close the process of the primary database node when the primary database node and the standby database node are in a synchronized state;
[0093] A file update module 72, configured to update the primary database node according to the new version executable file and start the process of the primary database node after the update of the primary database node is completed;
[0094] A detection module 73, configured to obtain a metadata update instruction corresponding to the new version executable file and detect whether the data page corresponding to the metadata update instruction in the primary database node is in the latest state;
[0095] An acquisition module 74, configured to, if it is detected that the data page corresponding to the metadata update instruction in the primary database node is not in the latest state, obtain the data page in the latest state corresponding to the metadata update instruction from the standby database node, where when the primary database node and the standby database node are in a synchronized state, the data page in the standby database node is characterized as the latest state;
[0096] A metadata update module 75, configured to update the corresponding metadata in the data page in the latest state corresponding to the metadata update instruction according to the metadata update instruction, and resume the service of the primary database node after the execution of the metadata update instruction is completed.
[0097] Optionally, the database upgrade device further includes:
[0098] A log sending module, configured to obtain the primary synchronization log data required for the standby database node to synchronize with the primary database node from all the primary log data of the primary database node locally, and send the primary synchronization log data to the standby database node to instruct the standby database node to perform a playback operation on the primary synchronization log data;
[0099] A synchronization determination module, configured to determine that the primary database node and the standby database node are in a synchronized state after the standby database node completes the playback operation on the primary synchronization log data.
[0100] Optionally, the file update module 72 includes:
[0101] A replacement unit, configured to obtain the path of the new version executable file, obtain the new version executable file according to the path of the new version executable file, use the new version executable file to replace the old version executable file in the primary database node, and start the process of the primary database node after the replacement of the new version executable file is completed.
[0102] Optionally, the database upgrade device further includes:
[0103] A status detection module, configured to obtain all the primary log data of the primary database node, and for any primary log data, detect whether the data page corresponding to the primary log data is in the latest state;
[0104] A playback module, configured to, if it is detected that the data page corresponding to the primary log data is not in the latest state, perform a playback operation on the primary log data, so that the data page corresponding to the primary log data is updated by playback to obtain a data page in the latest state;
[0105] A skip module, configured to skip performing a playback operation on the primary log data if it is detected that the data page corresponding to the primary log data is in the latest state.
[0106] Optionally, the database upgrade device further includes:
[0107] A log determination module, configured to obtain primary upgrade log data generated during the upgrade of the primary database node after the playback operation is completed for all the primary log data;
[0108] A standby database upgrade module, configured to send the primary upgrade log data to the standby database node to instruct the standby database node to shut down the process of the standby database node, update the standby database node according to the new version executable file, start the process of the standby database node to receive the primary upgrade log data after the update of the standby database node is completed, perform a playback operation on the primary upgrade log data, and obtain the upgraded standby database node after the playback operation of the primary upgrade log data is completed.
[0109] Optionally, the obtaining module 74 includes:
[0110] An identification sending unit, configured to obtain the page identification of the data page corresponding to the metadata update instruction, send the page identification to the standby database node to instruct the standby database node to determine the data page corresponding to the page identification locally at the standby database node, and feed back the content of the data page corresponding to the page identification to the primary database node;
[0111] An overwriting unit, configured to obtain the content of the data page corresponding to the page identification fed back by the standby database node, and use the content of the data page corresponding to the page identification fed back by the standby database node to overwrite the content of the data page corresponding to the metadata update instruction locally at the primary database node, so as to obtain the data page in the latest state corresponding to the metadata update instruction.
[0112] Optionally, the database upgrade device further includes:
[0113] A request obtaining module, configured to obtain a page request sent by an upper-layer service, and detect whether the data page corresponding to the page request in the primary database node is in the latest state;
[0114] A first page sending module, configured to send the data page in the latest state corresponding to the page request to the upper-layer service if it is detected that the data page corresponding to the page request in the primary database node is in the latest state;
[0115] A second page sending module, configured to, if it is detected that the data page corresponding to the page request in the master database node is not in the latest state, obtain the data page in the latest state corresponding to the page request from the standby database node, and send the data page in the latest state corresponding to the page request to the upper-layer service.
[0116] It should be noted that, for the information interaction, execution process, etc. between the above modules, since they are based on the same concept as the method embodiments of the present application, for their specific functions and the technical effects brought, reference may be specifically made to the method embodiment part, and details are not described herein again.
[0117] Figure 8 It is a schematic structural diagram of a computer device provided in Embodiment VIII of the present application. As Figure 8 shown, the computer device of this embodiment includes: at least one processor ( Figure 8 only one is shown in the figure), a memory, and a computer program stored in the memory and executable on at least one processor. When the processor executes the computer program, it implements the steps in any of the above method embodiments for database upgrade under various physical master-slave architectures.
[0118] The computer device may include, but is not limited to, a processor and a memory. Those skilled in the art can understand that Figure 8 this is only an example of a computer device and does not constitute a limitation on the computer device. The computer device may include more or fewer components than shown in the figure, or combine some components, or different components. For example, it may also include a network interface, a display screen, and an input device, etc.
[0119] The so-called processor may be a CPU, and the processor may also be other general-purpose processors, digital signal processors (DSPs), application specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0120] The memory includes a readable storage medium, an internal memory, etc. Among them, the internal memory can be the memory of a computer device, and the internal memory provides an environment for the operation of the operating system and computer-readable instructions in the readable storage medium. The readable storage medium can be the hard disk of a computer device, and in some other embodiments, it can also be an external storage device of the computer device, for example, a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) card, a Flash Card, etc. equipped on the computer device. Further, the memory can also include both the internal storage unit of the computer device and the external storage device. The memory is used to store the operating system, application programs, a BootLoader, data, and other programs, such as the program code of a computer program. The memory can also be used to temporarily store the data that has been output or will be output.
[0121] Those skilled in the art can clearly understand that, for the convenience and conciseness of description, only the above division of each functional unit and module is used as an example. In actual applications, the above functions can be allocated to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. Each functional unit and module in the embodiments can be integrated into a processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit. The above integrated unit can be implemented in the form of hardware or in the form of a software functional unit. In addition, the specific names of each functional unit and module are only for the convenience of mutual distinction and do not limit the protection scope of this application. The specific working process of the units and modules in the above device can refer to the corresponding process in the foregoing method embodiments and will not be elaborated herein. If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, to implement all or part of the processes in the above method embodiments of this application, a computer program can be used to instruct the relevant hardware to complete. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by a processor, the steps of the above method embodiments can be implemented. Among them, the computer program includes computer program code, and the computer program code can be in the form of source code, object code, executable file or some intermediate form, etc. The computer-readable medium can at least include: any entity or device that can carry the computer program code, recording medium, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signal, telecommunication signal, and software distribution medium. For example, a USB flash drive, a mobile hard disk, a magnetic disk, or an optical disc, etc.
[0122] To implement all or part of the processes in the above method embodiments of this application, it can also be completed by a computer program product. When the computer program product runs on a computer device, it enables the computer device to execute and implement the steps in the above method embodiments.
[0123] In the above embodiments, the descriptions of each embodiment have their own emphases. For the parts not detailed or recorded in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0124] Those of ordinary skill in the art can realize that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be implemented by electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of this application.
[0125] In the embodiments provided in this application, it should be understood that the disclosed device / computer device and method can be implemented in other ways. For example, the device / computer device embodiments described above are only illustrative. For example, the division of modules or units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed coupling or direct coupling or communication connection between each other can be through some interfaces. The indirect coupling or communication connection of the device or unit can be in an electrical, mechanical or other form.
[0126] The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they can be located in one place, or can be distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0127] The above embodiments are only used to illustrate the technical solutions of this application, rather than to limit them; although this application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements for some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included in the protection scope of this application.
Claims
1. A database upgrade method under a physical primary and standby architecture, characterized in that, The database upgrade method is applied to the primary database node in a primary-standby architecture and includes: Stop the services of the primary database node. When the primary database node and the standby database node are in a synchronized state, shut down the process of the primary database node; Update the primary database node according to the new version executable file. After the update of the primary database node is completed, start the process of the primary database node; Obtain the metadata update instruction corresponding to the new version executable file, and detect whether the data page corresponding to the metadata update instruction in the primary database node is in the latest state; If it is detected that the data page corresponding to the metadata update instruction in the primary database node is not in the latest state, obtain the data page in the latest state corresponding to the metadata update instruction from the standby database node. When the primary database node and the standby database node are in a synchronized state, the data page in the standby database node is characterized as being in the latest state; Update the corresponding metadata in the data page in the latest state corresponding to the metadata update instruction according to the metadata update instruction. After the execution of the metadata update instruction is completed, resume the services of the primary database node; After stopping the services of the primary database node, the database upgrade method further includes: In all the primary log data of the primary database node locally, obtain the primary synchronization log data required for the standby database node to synchronize with the primary database node, and send the primary synchronization log data to the standby database node to instruct the standby database node to perform a replay operation on the primary synchronization log data. The primary synchronization log data refers to the primary log data that the standby database node has not synchronized after stopping the services of the primary database node; After the standby database node completes the replay operation on the primary synchronization log data, determine that the primary database node and the standby database node are in a synchronized state.
2. The database upgrade method under the physical primary and standby architecture according to claim 1, characterized in that The step of updating the primary database node according to the new version executable file and starting the process of the primary database node after the update of the primary database node is completed includes: Obtain the path of the new version executable file. According to the path of the new version executable file, obtain the new version executable file, and use the new version executable file to replace the old version executable file in the primary database node. After the replacement of the new version executable file is completed, start the process of the primary database node.
3. The database upgrade method under the physical primary and standby architecture according to claim 1, characterized in that After starting the process of the primary database node, the database upgrade method further includes: Obtain all the primary log data of the primary database node. For any primary log data, detect whether the data page corresponding to the primary log data is in the latest state; If it is detected that the data page corresponding to the primary log data is not in the latest state, perform a replay operation on the primary log data so that the data page corresponding to the primary log data is updated by replay to obtain a data page in the latest state; If it is detected that the data page corresponding to the primary log data is in the latest state, skip performing a replay operation on the primary log data.
4. The database upgrade method under the physical primary and standby architecture according to claim 3, characterized in that The database upgrade method further includes: After the replay operation is completed for all the primary log data, obtaining the primary upgrade log data generated during the upgrade of the primary database node; Sending the primary upgrade log data to the standby database node to instruct the standby database node to shut down the process of the standby database node, updating the standby database node according to the new version executable file, and after the update of the standby database node is completed, starting the process of the standby database node to receive the primary upgrade log data and performing a replay operation on the primary upgrade log data. After the replay operation of the primary upgrade log data is completed, the upgraded standby database node is obtained.
5. The database upgrade method under the physical primary and standby architecture according to claim 1, characterized in that The obtaining the data page in the latest state corresponding to the metadata update instruction from the standby database node includes: Obtaining the page identifier of the data page corresponding to the metadata update instruction, and sending the page identifier to the standby database node to instruct the standby database node to determine the data page corresponding to the page identifier locally in the standby database node and feed back the content of the data page corresponding to the page identifier to the primary database node; Obtaining the content of the data page corresponding to the page identifier fed back by the standby database node, and using the content of the data page corresponding to the page identifier fed back by the standby database node to overwrite the content of the data page corresponding to the metadata update instruction locally in the primary database node to obtain the data page in the latest state corresponding to the metadata update instruction.
6. The database upgrade method under the physical primary and standby architecture according to claim 1, characterized in that After resuming the service of the primary database node, the database upgrade method further includes: Obtaining a page request sent by the upper-layer service, and detecting whether the data page corresponding to the page request in the primary database node is in the latest state; If it is detected that the data page corresponding to the page request in the primary database node is in the latest state, sending the data page in the latest state corresponding to the page request to the upper-layer service; If it is detected that the data page corresponding to the page request in the primary database node is not in the latest state, obtaining the data page in the latest state corresponding to the page request from the standby database node and sending the data page in the latest state corresponding to the page request to the upper-layer service.
7. A database upgrade device under a physical primary / standby architecture, characterized in that, The database upgrade device is applied to the primary database node in the primary-standby architecture and includes: A synchronization module, configured to stop the service of the primary database node and shut down the process of the primary database node when the primary database node and the standby database node are in a synchronized state; A file update module, configured to update the primary database node according to the new version executable file and start the process of the primary database node after the update of the primary database node is completed; A detection module, configured to obtain a metadata update instruction corresponding to the new version executable file and detect whether the data page corresponding to the metadata update instruction in the primary database node is in the latest state; An acquisition module, configured to, if it is detected that the data page corresponding to the metadata update instruction in the primary database node is not in the latest state, acquire the data page in the latest state corresponding to the metadata update instruction from the standby database node, where when the primary database node and the standby database node are in a synchronized state, the data page in the standby database node is characterized as being in the latest state; A metadata update module, configured to update the corresponding metadata in the data page in the latest state corresponding to the metadata update instruction according to the metadata update instruction, and resume the service of the primary database node after the execution of the metadata update instruction is completed; The database upgrade device further includes: A log sending module, configured to acquire the primary synchronization log data required for the standby database node to synchronize with the primary database node from all the primary log data local to the primary database node, and send the primary synchronization log data to the standby database node to instruct the standby database node to perform a playback operation on the primary synchronization log data, where the primary synchronization log data refers to the primary log data that the standby database node has not synchronized after the service of the primary database node is stopped; A synchronization determination module, configured to determine that the primary database node and the standby database node are in a synchronized state after the standby database node completes the playback operation on the primary synchronization log data.
8. A computer device, characterized in that, The computer device includes a processor, a memory, and a computer program stored in the memory and executable on the processor, and when the processor executes the computer program, it implements the database upgrade method under the physical primary-standby architecture according to any one of claims 1 to 6.
9. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the database upgrade method under the physical primary-standby architecture according to any one of claims 1 to 6.
Citation Information
Patent Citations
Database upgrading method and device
CN107977466A
Implementation method and device of high-availability database system, equipment and storage medium
CN113220784A