Database upgrading method, device and equipment under physical main-standby architecture and medium
By updating and synchronizing metadata in the synchronous state of the primary and secondary database nodes and directly executing metadata update instructions, the complexity and time-consuming database upgrade problems under the physical primary and secondary architecture are solved, and a more efficient database upgrade is achieved.
Patent Information
- Application Number
- CN202411078233.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-07
- Publication Date
- 2024-12-10
- Estimated Expiration
- 2044-08-07
AI Technical Summary
In the prior art, the database upgrade process under the physical primary and backup architecture is complex and time-consuming, and may lead to business interruptions and log disagreements, making it difficult to simplify the upgrade process and shorten the total time-consuming upgrade.
When the main database node is in a synchronous state with the backup database node, the main database node service is stopped, the executable file of the main database node is updated, and the latest data page is detected and synchronized through metadata update instructions to obtain the latest data from the backup database node. The page is updated to avoid the log playback process and directly execute metadata update instructions.
It simplifies the database upgrade process, shortens the total time to upgrade, reduces business interruption time, and improves the upgrade efficiency of the database system.
Smart Images

Figure CN119105776A_ABST
Abstract
Description
Technical Field
[0001] The present application is applicable to the field of database upgrade technology, and in particular, relates to a database upgrade method, device, equipment and medium under a physical master-slave architecture. Background Art
[0002] For database upgrades under the master-slave architecture, a rolling upgrade method is usually used 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 method of rolling upgrade is to first upgrade the standby database node, and after the upgrade is completed, switch the business of the master database node to the upgraded standby database node, and then upgrade the master database node, and after the upgrade is completed, switch the business back to the upgraded master database node again. However, in the above-mentioned rolling upgrade process, it is necessary to switch the physical master-slave to the logical master-slave, and after the upgrade of the master database node is completed, it is converted to the physical master-slave. This conversion process between the physical master-slave and the logical master-slave not only increases the complexity of the upgrade, but also may cause the upgrade to take a long time. During the switching between the physical master-slave and the logical master-slave, the database system will interrupt the service to the upper-level business and generate log differences. Therefore, how to simplify the upgrade process of the database 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 the present application provide a database upgrade method, device, equipment and medium under a physical active-standby architecture to solve the problem of how to simplify the database upgrade process under the active-standby architecture and shorten the total upgrade time.
[0004] In a first aspect, an embodiment of the present application provides a database upgrade method in a physical active-standby architecture, wherein the database upgrade method is applied to a primary database node in the active-standby architecture, and includes:
[0005] Stop the service of the primary database node, and when the primary database node is in a synchronized state with the standby database node, close the process of the primary database node;
[0006] According to the new version executable file, the master database node is updated, and after the master database node is updated, the process of the master database node is started;
[0007] Obtaining a metadata update instruction corresponding to the new version of the executable file, and detecting whether a 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, the data page in the latest state corresponding to the metadata update instruction is obtained from the standby database node, wherein 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, the metadata corresponding to the data page in the latest state corresponding to the metadata update instruction is updated, and after the metadata update instruction is executed, the business of the main database node is restored.
[0010] In a second aspect, an embodiment of the present application provides a database upgrade device in a physical master-slave architecture, wherein the database upgrade device is applied to a master database node in the master-slave architecture, comprising:
[0011] A synchronization module, used to stop the service of the primary database node and close the process of the primary database node when the primary database node is in a synchronized state with the standby database node;
[0012] A file update module, used to update the master database node according to the new version executable file, and start the process of the master database node after the master database node is updated;
[0013] A detection module, used to obtain a metadata update instruction corresponding to the new version of the executable file, and detect whether the data page corresponding to the metadata update instruction in the master database node is in the latest state;
[0014] an acquisition module, configured to acquire the data page in the latest state corresponding to the metadata update instruction from the standby database node if it is detected that the data page in the primary database node corresponding to the metadata update instruction is not in the latest state, wherein 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] The metadata update module is used to update the metadata corresponding to the latest state of the data page corresponding to the metadata update instruction according to the metadata update instruction, and restore the business of the main database node after the metadata update instruction is executed.
[0016] In a third aspect, an embodiment of the present application provides a computer device, comprising a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the database upgrade method under the physical master-slave architecture as described in the first aspect is implemented.
[0017] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the database upgrade method under the physical master-slave architecture as described in the first aspect is implemented.
[0018] Compared with the prior art, the embodiments of the present application have the following beneficial effects: the database upgrade method of the present application is applied to the master database node in the master-standby architecture, and by stopping the business of the master database node, when the master database node and the standby database node are in a synchronized state, the process of the master database node is closed, and after the update of the master database node is completed according to the new version of the executable file, the process of the master database node is started to obtain the metadata update instruction corresponding to the new version of the executable file, and if it is detected that the data page corresponding to the metadata update instruction in the master 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, wherein when the master 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, and according to the metadata update instruction, the metadata corresponding to the data page in the latest state corresponding to the metadata update instruction is updated, and after the metadata update instruction is executed, the business of the master 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 closed, so that when the process of the primary database node is closed, the data pages between the primary database node and the standby database node are completely consistent, that is, the data pages in the standby database node can be represented 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. Compared with, after restarting the process of the primary database node, replaying the log data required for restarting, restoring the data page in the primary database node to the latest state before the process is closed, and then executing the metadata update instruction, the present application allows the primary database node to skip the log playback process after restarting the process, and directly Then execute the metadata update instruction. The data page with the latest status required by the metadata update instruction can be obtained from the standby database node, which simplifies the upgrade process and shortens the time required for restarting the primary database node, thereby shortening the total time consumed for database upgrade. At the same time, during the upgrade of the primary database, the business interruption time may include: the time from stopping the business to closing the process, the time from replacing the new version of the 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 data and can usually be completed within a few seconds. Therefore, compared with the rolling upgrade method of switching between logical master and standby and physical master and standby, the business interruption time during the database upgrade process is shortened. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0021] Figure 1 It is a flowchart of a database upgrade method under a physical master-slave architecture provided in Example 1 of the present application;
[0022] Figure 2 It is a flowchart of a database upgrade method under a physical master-slave architecture provided in Embodiment 2 of the present application;
[0023] Figure 3 It is a flowchart of a database upgrade method under a physical master-slave architecture provided in Embodiment 3 of the present application;
[0024] Figure 4 It is a flowchart of a database upgrade method under a physical master-slave architecture provided in Embodiment 4 of the present application;
[0025] Figure 5 It is a flowchart of a database upgrade method under a physical master-slave architecture provided in Embodiment 5 of the present application;
[0026] Figure 6 It is a flowchart of a database upgrade method under a physical master-slave architecture provided in Example 6 of the present application;
[0027] Figure 7 This is a structural diagram of a database upgrade device under a physical master-slave architecture provided in Embodiment 7 of the present application;
[0028] Figure 8 It is a structural diagram of a computer device provided in Example 8 of the present application. DETAILED DESCRIPTION
[0029] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.
[0030] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or combinations thereof.
[0031] It should also be understood that the term “and / or” used in the specification and appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0032] As used in the specification and appended claims of this application, the term "if" can be interpreted as "when" or "uponce" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" can be interpreted as meaning "uponce it is determined" or "in response to determining" or "uponce [described condition or event] is detected" or "in response to detecting [described condition or event]", depending on the context.
[0033] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.
[0034] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.
[0035] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Artificial intelligence is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
[0036] AI basic technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. AI software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.
[0037] It should be understood that the size of the serial numbers of the steps in the following embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0038] In order to illustrate the technical solution of the present application, a specific embodiment is provided below for illustration.
[0039] See also Figure 1 , is a flow chart of a database upgrade method under a physical master-slave architecture provided in the first embodiment of the present application. The above database upgrade method is applied to the master database node in the master-slave architecture. Figure 1 As shown, the database upgrade method may include the following steps:
[0040] Step S101, stopping the service of the primary database node, and closing the process of the primary database node when the primary database node is in a synchronized state with the standby database node.
[0041] In an embodiment of the present application, in a database system that adopts a master-slave deployment architecture, the master database node may refer to the main node in the database system, which is responsible for processing all write operations (for example, insertion and deletion, etc.) and synchronizing 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 master database node, which is responsible for copying the data of the master database node and maintaining data synchronization with the master database node.
[0042] For example, the upstream and downstream of the system and related business parties can be notified to stop the business services of the primary database node at a certain point in time. When the primary database node is upgraded, the server entrance of the primary database node is closed to stop the business of the primary database node, and the standby database node is waited for to synchronize all the current redo logs (RedoLog) of the primary database node. When the data page of the standby database node is completely consistent with the data page of the primary database node, 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 closed using the database management tool.
[0043] Step S102: updating the master database node according to the new version executable file, and starting the process of the master database node after the update of the master database node is completed.
[0044] In an embodiment of the present application, the new version executable file may refer to an executable file corresponding to an updated version of the database software, which 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 executable file is in binary form.
[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 is 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, obtaining a metadata update instruction corresponding to the new version of the executable file, and detecting 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 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.
[0048] Step S105 , according to the metadata update instruction, the metadata corresponding to the data page in the latest state corresponding to the metadata update instruction is updated, and after the metadata update instruction is executed, the service of the primary database node is restored.
[0049] In an embodiment of the present application, metadata may refer to data that describes information such as the structure, attributes, and storage location of data in a database, and a metadata update instruction may refer to an instruction for updating metadata, wherein the metadata update instruction may be a structured query language (SQL). For example, a 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 ageDATE;", and a data page may refer to a basic unit for storing data in a database, wherein the state of the data page when the primary database node process is shut down is the latest state, and when the primary database node and the standby database node are in a synchronized state, the data page in the standby database node may be characterized as the latest state.
[0050] After the new version of the executable file replaces the old version of the executable file and the master database node is updated, the new version of the executable file configured by the master database node may introduce new data structures, tables, fields, etc. Therefore, the corresponding metadata needs to be updated by the metadata update instructions corresponding to the new version of the executable file to maintain data consistency and integrity.
[0051] Specifically, in the process of executing the metadata update instruction, first, it is detected locally on the primary database node whether the data page required by the metadata update instruction is in the latest state. For example, this can be determined by detecting the flag bit that records the data page state. Then, if it is detected locally on the primary database node that the data page corresponding to the metadata update instruction is not in the latest state, the data page with the latest state corresponding to the metadata update instruction is obtained from the standby database node. Finally, according to the metadata update instruction, the corresponding metadata in the acquired data page with the latest state is updated. After all metadata update instructions are executed, the business of the primary database node is restored.
[0052] For example, in a database system that adopts a physical master-slave architecture, including a master database node and a slave database node, the version number of the current executable file is 2.1.0, and the version number of the new version executable file is 2.2.0. To upgrade the metadata of the new version executable file, it is necessary to add a column columnY to the system table tableX. The overall process of upgrading the database system with the master-slave architecture can be:
[0053] 1) Stop the business of the master database node. When the data pages in the master database node and the standby database node are completely consistent, determine that the master database node and the standby database node are in a synchronized state, and shut down the process of the master database node; 2) Replace the current executable file of version 2.1.0 with the new version executable file of version 2.2.0. After the replacement is completed, start the process of the master database node; 3) Directly execute the metadata update instruction, add columnY to the tableX system table, and synchronously start the background log playback thread, and continuously play back all the master log data required for the restart of the master database node in the background to update all the data pages in the master database node to the latest state when the master database node is shut down; 4) After all the metadata update instructions are executed, resume the business of the master database node; 5) After all the master log data of the master database node are played back, send the master upgrade log data generated during the upgrade of the master database node to the standby database node to instruct the standby database node to upgrade.
[0054] Among them, the execution process of the metadata update instruction in the above 3) can be: detect whether the data page corresponding to the metadata update instruction in the primary database node is in the latest state; if not, obtain the data page with the latest state corresponding to the metadata update instruction from the standby database node; and according to the metadata update instruction, update the corresponding metadata in the data page with the latest state corresponding to the metadata update instruction.
[0055] In the above 3), the background log playback thread is synchronously started, and the process of continuously playing back all the master log data required for restarting the master database node in the background can be: for any master log data, check whether the data page corresponding to the master log data is in the latest state. If it is not the latest state, perform the playback operation on the master log data, so that the data page corresponding to the master log data is played back and updated to obtain the data page in the latest state. If it is the latest state, skip the playback operation on the master log data.
[0056] Optionally, after the business of the primary database node is restored in the above 4), the primary database node responds to the page request sent by the upper-level business, and detects whether the data page corresponding to the page request in the primary database node is in the latest state. If it is the latest state, the data page with the latest state corresponding to the page request is sent to the upper-level business. If it is not the latest state, the data page with the latest state corresponding to the page request is obtained from the standby database node, and the data page with the latest state corresponding to the page request is sent to the upper-level business.
[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 closed, so that when the process of the primary database node is closed, the data pages between the primary database node and the standby database node are completely consistent, that is, the data pages in the standby database node can be represented 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. Compared with, after restarting the process of the primary database node, replaying the log data required for restarting, restoring the data page in the primary database node to the latest state before the process is closed, and then executing the metadata update instruction, the present application allows the primary database node to skip the log playback process after restarting the process. The metadata update instruction is directly executed during the upgrade process. The data page with the latest status required by the metadata update instruction can be obtained from the standby database node, which simplifies the upgrade process and shortens the time required for restarting the primary database node, thereby shortening the total time consumed for database upgrade. At the same time, during the upgrade of the primary database, the business interruption time may include: the time from stopping the business to closing the process, the time from replacing the new version of the 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 data and can usually be completed within a few seconds. Therefore, compared with the rolling upgrade method of switching between logical master and standby and physical master and standby, the business interruption time during the database upgrade process is shortened.
[0058] See also Figure 2 , is a flow chart of a database upgrade method under a physical master-slave architecture provided in Embodiment 2 of the present application. Figure 2 As 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 , obtaining the master synchronization log data required for the standby database node to synchronize with the master database node from all the master log data locally at the master database node, and sending the master 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, it is determined that the primary database node and the standby database node are in a synchronized state.
[0061] In an embodiment of the present application, the master log data may refer to a log of data operations recorded by the master database node. For example, the master log data may be a Redo log. The master synchronization log data may refer to the master log data required for the standby database node to synchronize with the master database node. For example, during the normal operation of the master database node and the standby database node, the standby database node automatically replays the master log data of the master database node to maintain data synchronization with the master database node. After stopping the business of the master database node, the master synchronization log data may refer to the master log data that is not synchronized with the standby database node. In the case where the synchronization delay between the master database node and the standby database node is low, the master synchronization log data may be the last log data of the master log data.
[0062] For example, when the synchronization delay between the primary database node and the standby database node is 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 playback operation on the primary synchronization log data. After the standby database node completes the playback operation on the primary synchronization log data, the data page of the standby database node is completely consistent with the data page of the primary database node, that is, it is determined that the primary database node and the standby database node are in a synchronized state.
[0063] In an embodiment of the present application, after stopping the business of the primary database node, after completely synchronizing the master log data of the primary database node in the standby database node, it is determined that the primary database node and the standby database node are in a synchronized state, so that 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 represented 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 restarting the primary database node, thereby shortening the total time required for database upgrade.
[0064] See also Figure 3 , is a flow chart of a database upgrade method under a physical master-slave architecture provided in Embodiment 3 of the present application. Figure 3 As shown, after starting the process of the master database node in the above step S102, the database upgrade method may further include the following steps:
[0065] Step S301, obtaining all the master log data of the master database node, and for any master log data, detecting whether the data page corresponding to the master 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, a playback operation is performed on the main log data, so that the data page corresponding to the main log data is played back and updated to obtain the 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, the playback operation on the main log data is skipped.
[0068] In an embodiment of the present application, after restarting the process of the main database node, a background log playback thread can also be started to continuously play back all the main log data required for restarting the main database node in the background to update all data pages in the main database node to the latest state when the main database node was shut down.
[0069] Specifically, in the process of starting the background thread to play back the master log data, for any master log data, it is detected whether the data page corresponding to the master log data is in the latest state. If it is detected that the data page corresponding to the master log data is not in the latest state, a playback operation is performed on the master log data, so that the data page corresponding to the master log data is played back and updated to obtain the data page in the latest state. If, during the execution of the metadata update instruction, the data page corresponding to the master log data has been obtained from the backup database, it can be considered that the data page corresponding to the master log data is in the latest state, and the playback operation on the master log data is skipped.
[0070] In an embodiment of the present application, after restarting the process of the master database node, all master log data required for restarting the master database node are continuously replayed in the background to update all data pages in the master database node to the latest state when the master database node was shut down. Log playback is performed in the background so that after the master database node is restarted, metadata update instructions can be directly executed to quickly restore the business of the master database node. On the basis of ensuring that the data state of the master database node after restart is consistent with that before the process is shut down, the time of business interruption of the master database node is reduced, and the total time consumed for database upgrade is shortened.
[0071] See also Figure 4 , is a flowchart of a database upgrade method under a physical master-slave architecture provided in Embodiment 4 of the present application, such as Figure 4 As shown, the database upgrade method may further include the following steps:
[0072] Step S401, after all the master log data have been replayed, the master upgrade log data generated during the upgrade of the master database node is obtained.
[0073] Step S402: Send the master upgrade log data to the standby database node.
[0074] In an embodiment of the present application, the master upgrade log data may refer to the master log data generated during the upgrade of the master database node, that is, the master log data generated after the master database node restarts the process, executes metadata update instructions and provides services to upper-level businesses.
[0075] Specifically, after all the master log data have been replayed, the master database node restart process is obtained, the metadata update instruction is executed and the master upgrade log data generated by providing services to the upper-layer business is sent to the standby database node to instruct any standby database node to shut down the standby database node process, and the standby database node is updated according to the new version executable file. After the standby database node is updated, the standby database node process is started to receive the master upgrade log data, and the master upgrade log data is replayed. After the master upgrade log data is replayed, the upgraded standby database node is obtained.
[0076] In an embodiment of the present application, after all the master log data of the master database node are replayed, the master upgrade log data is sent to the standby database node to instruct the standby database node to upgrade, thereby ensuring data consistency between the master database node and the standby database node. The standby database node only needs to close the process, replace the new version executable file, start the process, and replay according to the master upgrade log data to complete the upgrade process. Compared with the rolling upgrade method of the prior art, after the standby database node is upgraded, it is necessary to switch between physical master and logical master and standby. This simplifies the upgrade process, reduces the complexity of the upgrade, and thus shortens the total time required for the upgrade.
[0077] See also Figure 5 , is a flow chart of a database upgrade method under a physical master-slave architecture provided in Embodiment 5 of the present application. Figure 5 As shown, the acquisition of the latest state data page corresponding to the metadata update instruction from the standby database node in the above step S104 may include the following steps:
[0078] Step S501: Obtain a page identifier of a data page corresponding to a metadata update instruction, and send the page identifier to a standby database node.
[0079] Step S502, 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 local metadata update instruction of the primary database node, and obtain the data page in the latest state corresponding to the metadata update instruction.
[0080] In the embodiment of the present application, the page identification may refer to the identification (ID) of the data page.
[0081] Specifically, first, the page identifier of the data page corresponding to the metadata update instruction is obtained, and the page identifier is sent 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. Then, the content of the data page corresponding to the page identifier fed back by the standby database node is obtained, and the content of the data page corresponding to the page identifier fed back by the standby database node is used to overwrite the content of the data page corresponding to the local metadata update instruction of the primary database node. After the overwriting is completed, the data page with the latest status corresponding to the local metadata update instruction of the primary database node is obtained.
[0082] In an 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 local data page of the primary database node is overwritten to obtain the local data page in the latest state, thereby improving the efficiency of obtaining the data page in the latest state corresponding to the metadata update instruction, thereby shortening the total time consumed for data upgrade.
[0083] See also Figure 6 , is a flow chart of a database upgrade method under a physical master-slave architecture provided in Example 6 of the present application. Figure 6 As shown, after the service of the primary database node is restored in the above step S105, the database upgrade method further includes the following steps:
[0084] Step S601: Obtain a page request sent by an upper-layer business, 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, the data page in the latest state corresponding to the page request is sent to the upper layer business.
[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, the data page in the latest state corresponding to the page request is obtained from the standby database node, and the data page in the latest state corresponding to the page request is sent to the upper layer business.
[0087] In the embodiment of the present application, the upper-layer business may refer to a user interface layer responsible for receiving user input (eg, page request, etc.), and the page request may refer to a request for obtaining a data page.
[0088] Specifically, after the main database node resumes its business, it responds to the page request of the upper-level business, and detects whether the data page corresponding to the page request in the page cache of the main 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 with the latest state corresponding to the page request is directly sent to the upper-level business. 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 with the latest state corresponding to the page request is obtained from the standby database node. Specifically, please refer to the contents of steps S501 to S502, and the data page with the latest state corresponding to the page request is sent to the upper-level business.
[0089] In an embodiment of the present application, after the main database node resumes business, it can respond to the page request of the upper-level business. If the data page with the latest status corresponding to the page request does not exist locally, the data page with the latest status corresponding to the page request is obtained from the standby database node and sent to the upper-level business. Compared with resuming the business after the log is replayed on the main database node, the service interruption time of the upper-level business due to the database upgrade is reduced.
[0090] Corresponding to the database upgrade method under the physical master-slave architecture of the above embodiment, Figure 7 The structure block diagram of the database upgrade device under the physical master-slave architecture provided by the seventh embodiment of the present application is shown, and the above database upgrade device is applied to the master database node in the master-slave architecture. For the convenience of explanation, only the part related to the embodiment of the present application is shown.
[0091] See also Figure 7 , the database upgrading device comprises:
[0092] A synchronization module 71, used to stop the service of the primary database node and close the process of the primary database node when the primary database node is in a synchronized state with the standby database node;
[0093] A file update module 72, used to update the master database node according to the new version executable file, and start the process of the master database node after the master database node is updated;
[0094] The detection module 73 is used to 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;
[0095] The acquisition module 74 is configured to acquire the data page in the latest state corresponding to the metadata update instruction from the standby database node if it is detected that the data page in the primary database node corresponding to the metadata update instruction is not in the latest state, wherein 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;
[0096] The metadata update module 75 is used to update the metadata corresponding to the latest state of the data page corresponding to the metadata update instruction according to the metadata update instruction, and restore the business of the main database node after the metadata update instruction is executed.
[0097] Optionally, the database upgrading device further includes:
[0098] A log sending module, configured to obtain, from all the local master log data of the master database node, the master synchronization log data required for the standby database node to synchronize with the master database node, and send the master synchronization log data to the standby database node to instruct the standby database node to perform a playback operation on the master synchronization log data;
[0099] The synchronization determination module is used to determine that the primary database node and the standby database node are in a synchronization state after the standby database node completes the playback operation on the primary synchronization log data.
[0100] Optionally, the file updating module 72 includes:
[0101] A replacement unit is used 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 main database node, and after the replacement of the new version executable file is completed, start the process of the main database node.
[0102] Optionally, the database upgrading device further includes:
[0103] A status detection module is used to obtain all the master log data of the master database node, and for any master log data, detect whether the data page corresponding to the master log data is in the latest state;
[0104] A playback module, for performing a playback operation on the master log data if it is detected that the data page corresponding to the master log data is not in the latest state, so that the data page corresponding to the master log data is played back and updated to obtain the data page in the latest state;
[0105] The skipping module is used to skip the playback operation on the main log data if it is detected that the data page corresponding to the main log data is in the latest state.
[0106] Optionally, the database upgrading device further includes:
[0107] A log determination module, configured to obtain the master upgrade log data generated during the upgrade of the master database node after all master log data have been replayed;
[0108] The standby database upgrade module is used to send the master 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, and after the standby database node is updated, start the process of the standby database node to receive the master upgrade log data, perform a playback operation on the master upgrade log data, and after the playback operation on the master upgrade log data is completed, obtain the upgraded standby database node.
[0109] Optionally, the acquisition module 74 includes:
[0110] an identification sending unit, configured to obtain a page identification of a data page corresponding to the metadata update instruction, and 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 is used to 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, so as to obtain the data page in the latest state corresponding to the metadata update instruction.
[0112] Optionally, the database upgrading device further includes:
[0113] A request acquisition module, used to acquire a page request sent by an upper-layer business, and detect whether a data page corresponding to the page request in the master 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 business if it is detected that the data page in the master database node corresponding to the page request is in the latest state;
[0115] The second page sending module is used to obtain the data page with the latest status corresponding to the page request from the standby database node if it is detected that the data page corresponding to the page request in the primary database node is not in the latest status, and send the data page with the latest status corresponding to the page request to the upper-layer business.
[0116] It should be noted that the information interaction, execution process and other contents between the above-mentioned modules are based on the same concept as the method embodiment of the present application. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.
[0117] Figure 8 This is a schematic diagram of the structure of a computer device provided in Example 8 of the present application. Figure 8 As shown, the computer device of this embodiment includes: at least one processor ( Figure 8 Only one is shown), a memory, and a computer program stored in the memory and executable on at least one processor, and when the processor executes the computer program, the steps in the above-mentioned database upgrade method embodiment under any of the physical master-slave architectures are implemented.
[0118] The computer device may include, but is not limited to, a processor and a memory. Those skilled in the art will appreciate that Figure 8 This is merely 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 those shown in the figure, or a combination of certain components, or different components. For example, it may also include a network interface, a display screen, and an input device.
[0119] The processor may be a CPU, or other general-purpose processors, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0120] The memory includes a readable storage medium, an internal memory, etc., wherein the internal memory may be the memory of a computer device, and the internal memory provides an environment for the operation of an operating system and computer-readable instructions in the readable storage medium. The readable storage medium may be a hard disk of a computer device, and in other embodiments may also be an external storage device of a computer device, for example, a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on a computer device. Further, the memory may also include both an internal storage unit of a computer device and an external storage device. The memory is used to store an operating system, an application program, a boot loader (BootLoader), data, and other programs, such as program codes of computer programs, etc. The memory may also be used to temporarily store data that has been output or is to be output.
[0121] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device is divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated into a processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned device can refer to the corresponding process in the above-mentioned method embodiment, which will not be repeated here. 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 understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, which can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned method embodiment when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may at least include: any entity or device capable of carrying computer program code, recording medium, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium. For example, a USB flash drive, a mobile hard disk, a magnetic disk or an optical disk. In some jurisdictions, according to legislation and patent practice, computer-readable media cannot be electric carrier signals and telecommunication signals.
[0122] The present application implements all or part of the processes in the above-mentioned embodiment method, and may also be completed through a computer program product. When the computer program product runs on a computer device, the computer device can implement the steps in the above-mentioned method embodiment when executing the computer program product.
[0123] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0124] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0125] In the embodiments provided in the present application, it should be understood that the disclosed devices / computer equipment and methods can be implemented in other ways. For example, the device / computer equipment embodiments described above are only schematic, for example, the division of modules or units is only a logical function division, and there may be other division methods in actual implementation, such as 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 mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0126] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may 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 the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A database upgrade method under a physical master-slave architecture, characterized in that: The database upgrade method is applied to the master database node in the master-slave architecture, and includes: Stop the service of the primary database node, and when the primary database node is in a synchronized state with the standby database node, close the process of the primary database node; According to the new version executable file, the master database node is updated, and after the master database node is updated, the process of the master database node is started; Obtaining a metadata update instruction corresponding to the new version of the executable file, and detecting whether a data page corresponding to the metadata update instruction in the master 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, the data page in the latest state corresponding to the metadata update instruction is obtained from the standby database node, wherein 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; According to the metadata update instruction, the metadata corresponding to the data page in the latest state corresponding to the metadata update instruction is updated, and after the metadata update instruction is executed, the business of the main database node is restored.
2. The database upgrade method under the physical master-slave architecture according to claim 1, characterized in that: After stopping the service of the primary database node, the database upgrade method further includes: Obtaining master synchronization log data required for synchronization between the standby database node and the master database node from all master log data locally on the master database node, and sending the master synchronization log data to the standby database node to instruct the standby database node to perform a playback operation on the master synchronization log data; After the standby database node completes the playback operation on the primary synchronization log data, it is determined that the primary database node and the standby database node are in a synchronized state.
3. The database upgrade method under the physical master-slave architecture according to claim 1, characterized in that: The updating of the master database node according to the new version executable file and starting the process of the master database node after the updating of the master database node is completed include: 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 main database node, and after the replacement of the new version executable file is completed, start the process of the main database node.
4. The database upgrade method under the physical active-standby architecture according to claim 1, characterized in that: After starting the process of the master database node, the database upgrade method further includes: Obtain all the master log data of the master database node, and for any master log data, detect whether the data page corresponding to the master log data is in the latest state; If it is detected that the data page corresponding to the master log data is not in the latest state, a playback operation is performed on the master log data so that the data page corresponding to the master log data is played back and updated to obtain the data page in the latest state; If it is detected that the data page corresponding to the main log data is in the latest state, the playback operation on the main log data is skipped.
5. The database upgrade method under the physical active-standby architecture according to claim 4 is characterized in that: The database upgrade method also includes: After all the master log data have been replayed, the master upgrade log data generated during the upgrade of the master database node is obtained; The master upgrade log data is sent to the standby database node to instruct the standby database node to shut down the process of the standby database node, and the standby database node is updated according to the new version executable file. After the standby database node is updated, the process of the standby database node is started to receive the master upgrade log data, and a playback operation is performed on the master upgrade log data. After the playback operation on the master upgrade log data is completed, the upgraded standby database node is obtained.
6. The database upgrade method under the physical active-standby architecture according to claim 1, characterized in that: The acquiring, from the standby database node, a data page with the latest status corresponding to the metadata update instruction comprises: Obtaining a page identifier of a 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 at the standby database node, and feed back the content of the data page corresponding to the page identifier to the primary database node; 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 local metadata update instruction of the primary database node, so as to obtain the data page with the latest status corresponding to the metadata update instruction.
7. The database upgrade method under the physical active-standby architecture according to claim 1, characterized in that: After the service of the primary database node is restored, the database upgrade method further includes: Obtaining a page request sent by an upper-layer business, and detecting whether a data page corresponding to the page request in the master database node is in the latest state; If it is detected that the data page corresponding to the page request in the master database node is in the latest state, the data page in the latest state corresponding to the page request is sent to the upper layer business; If it is detected that the data page corresponding to the page request in the primary database node 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, and the data page in the latest state corresponding to the page request is sent to the upper-layer business.
8. A database upgrade device under a physical master-slave architecture, characterized in that: The database upgrade device is applied to the master database node in the master-slave architecture, and includes: A synchronization module, used to stop the service of the primary database node and close the process of the primary database node when the primary database node is in a synchronized state with the standby database node; A file update module, used to update the master database node according to the new version executable file, and start the process of the master database node after the master database node is updated; A detection module, used to obtain a metadata update instruction corresponding to the new version of the executable file, and detect whether the data page corresponding to the metadata update instruction in the master database node is in the latest state; an acquisition module, configured to acquire the data page in the latest state corresponding to the metadata update instruction from the standby database node if it is detected that the data page in the primary database node corresponding to the metadata update instruction is not in the latest state, wherein 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; The metadata update module is used to update the metadata corresponding to the latest state of the data page corresponding to the metadata update instruction according to the metadata update instruction, and restore the business of the main database node after the metadata update instruction is executed.
9. 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. When the processor executes the computer program, the database upgrade method under the physical master-slave architecture as described in any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the database upgrade method under the physical master-slave architecture as described in any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Database upgrading method and device
CN107977466A
Heterogeneous database synchronization method and device
CN109101627A
Implementation method and device of high-availability database system, equipment and storage medium
CN113220784A
Method and device for sending redo log to standby database
CN114328021A
Method, device and equipment for repairing split brain of database cluster and medium
CN118445120A
