Database upgrading method and device and storage medium

By performing a full physical backup of the original master database and building a new slave database, combined with master-slave switching technology, the problem of poor stability during the database upgrade process was solved, and high availability and data consistency were achieved during the database upgrade process.

CN118916364APending Publication Date: 2024-11-08CHINA UNITED NETWORK COMM GRP CO LTD +2
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410954246.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-16
Publication Date
2024-11-08

AI Technical Summary

Technical Problem

During the database upgrade process, the existing technology has poor stability, especially when a large number of users have business needs, the database load is high and affects user access.

Method used

By performing a full physical backup of the original master database, building a new slave database, and replacing the first slave database among multiple slave databases with the new slave database, the upgrade of all slave databases is completed. At the same time, the original master database is kept in a normal access state during the upgrade process. The master-slave switching concept is used to ensure the high availability of the database.

Benefits of technology

It improves the stability of database upgrades, avoids downtime maintenance, ensures user experience and data consistency, and achieves high availability during the database upgrade process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118916364A_ABST
    Figure CN118916364A_ABST
Patent Text Reader

Abstract

The invention provides a database upgrading method and device and a storage medium. The method comprises the following steps: performing full-amount physical backup on an original main library to obtain backup data; performing data upgrading on the backup data to construct a new slave library; in the process of obtaining the new slave library, the plurality of slave libraries and the original master library are in a normal access state; using the new slave library to replace the first slave library in the plurality of slave libraries, repeating the step of using the new slave library to replace the first slave library in the plurality of slave libraries until the plurality of slave libraries are upgraded, and obtaining the plurality of upgraded slave libraries; and in the process of upgrading the plurality of slave libraries, the original master library is in a normal access state. According to the method, the stability during database version upgrading is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the computer field, and in particular to a database upgrading method, device and storage medium. Background Art

[0002] Due to security vulnerabilities in databases (such as Mysql, Redis, etc.), there is a need to upgrade the database version. For distributed databases, there is a version upgrade of a database combination in master-slave mode (including a master database and at least one slave database). The usual database upgrade method is the "unbind-upgrade-bind" method.

[0003] However, when a large number of users have business needs for the database, the database that is being upgraded will face heavy load resources, affecting user access.

[0004] Therefore, upgrading the database version has the problem of poor stability. Summary of the invention

[0005] The present application provides a database upgrade method, device and storage medium. During the database upgrade process, normal access to the database is not affected, and users are unaware of the database upgrade process, thereby solving the technical problem of poor stability of the upgraded database version.

[0006] In a first aspect, the present application provides a database upgrade method, which is applied to a distributed database, wherein the distributed database includes an original master database and multiple slave databases, and the original master database has a synchronization relationship with each slave database; the method includes:

[0007] Perform a full physical backup of the original master database to obtain backup data;

[0008] Upgrade the backup data to build a new slave database. During the process of obtaining the new slave database, multiple slave databases and the original master database are in normal access status.

[0009] Use a new slave library to replace the first slave library among the multiple slave libraries, repeat the above steps of using the new slave library to replace the first slave library among the multiple slave libraries until the upgrade of the multiple slave libraries is completed to obtain the upgraded multiple slave libraries; during the process of upgrading the multiple slave libraries, the original master library is in a normal access state.

[0010] Optionally, in the above method, replacing the first slave library of the plurality of slave libraries with the new slave library includes:

[0011] Bind the new slave to the original master, and

[0012] Unbind the first slave library from the original master library and delete the first slave library.

[0013] Optionally, the above method further comprises:

[0014] The backup data is upgraded to obtain a second slave database; the data stored in the second slave database is the same as the data stored in the upgraded multiple slave databases;

[0015] A target slave library is selected from the upgraded multiple slave libraries and the second slave library, and the target slave library is set as a new master library.

[0016] Optionally, in the above method, the synchronization relationship includes a synchronous replication relationship, a semi-synchronous replication relationship, and an asynchronous replication relationship, and selecting a target slave library from the upgraded multiple slave libraries and the second slave library includes:

[0017] Traverse the upgraded slave libraries and the second slave library in turn to obtain the synchronization relationship between the slave library and the original master library;

[0018] The slave database that is obtained for the first time and has a synchronous replication relationship with the original master database is used as the target slave database.

[0019] Optionally, in the above method, selecting a target slave library from the upgraded multiple slave libraries and the second slave library, and setting the target slave library as the new master library includes:

[0020] If the original master database is currently writing data, obtain the synchronization time of the data to the upgraded multiple slave databases and the second slave database;

[0021] If the synchronization duration is less than or equal to a preset threshold, a target slave database is selected from the upgraded multiple slave databases and the second slave database, and the target slave database is set as the new master database.

[0022] Optionally, in the above method, after selecting a target slave library from the upgraded multiple slave libraries and the second slave library and setting the target slave library as the new master library, the method further includes:

[0023] Unbind the original master database from the new master database;

[0024] Delete the original master database and backup data;

[0025] Optionally, in the above method, before performing a full physical backup of the original master database and obtaining the backup data, the method further includes:

[0026] Receive upgrade query requests from the client and obtain the data synchronization time between the original master database and the slave database;

[0027] Send an upgrade query response to the client, where the upgrade query response includes the data synchronization time;

[0028] Receive upgrade feedback information from clients;

[0029] If the upgrade feedback information is used to indicate that the user accepts the data synchronization time, a step of performing a full physical backup of the original master database to obtain the backup data is performed.

[0030] Optionally, the method as above further includes:

[0031] If the upgrade feedback information is used to indicate that the user does not accept the data synchronization time, an upgrade indication request is sent to the client, and the upgrade indication request is used to request a time period for upgrading the distributed database;

[0032] receiving an upgrade indication response from the client;

[0033] According to the time period indicated in the upgrade instruction response, perform a step of performing a full physical backup of the original primary database to obtain backup data.

[0034] In a second aspect, the present application provides a database upgrade device, comprising:

[0035] The backup module is used to perform a full physical backup of the original master database to obtain backup data;

[0036] The upgrade module is used to upgrade the backup data to build a new slave database. In the process of obtaining the new slave database, multiple slave databases and the original master database are in normal access status.

[0037] A replacement module is used to replace the first slave library among multiple slave libraries with a new slave library, and repeat the above steps of replacing the first slave library among multiple slave libraries with the new slave library until the upgrade of the multiple slave libraries is completed to obtain the upgraded multiple slave libraries; during the process of upgrading the multiple slave libraries, the original master library is in a normal access state.

[0038] In a third aspect, the present application provides an electronic device, including:

[0039] A processor, and a memory communicatively connected to the processor;

[0040] Memory stores computer-executable instructions;

[0041] The processor executes the computer-executable instructions stored in the memory to implement any method of the first aspect of the present application.

[0042] In a fourth aspect, the present application provides a computer-readable storage medium, comprising:

[0043] The computer-readable storage medium stores computer-executable instructions, which are used to implement the method of the first aspect of the present application when executed by a processor.

[0044] In a fifth aspect, the present application provides a computer program product, including:

[0045] A computer program which, when executed by a processor, implements any one of the methods of the first aspect of the present application.

[0046] The database upgrade method, device and storage medium provided by the present application obtain backup data by performing a full physical backup of the original master library; performing a data upgrade on the backup data to build a new slave library; using the new slave library to replace the first slave library among multiple slave libraries, and repeating the step of using the new slave library to replace the first slave library among multiple slave libraries until the upgrade of the multiple slave libraries is completed to obtain multiple upgraded slave libraries; at the same time, the idea of ​​master-slave switching is used to ensure that the distributed database is in a normal access state during the database upgrade process; during the database upgrade process, normal access to the database is not affected; the method of the present application improves the stability when upgrading the database version. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0048] Figure 1 The database upgrade schematic diagram provided for this application;

[0049] Figure 2 A flowchart of a database upgrade method provided in this application;

[0050] Figure 3 A flowchart of a one-master-two-slave database upgrade method provided in this application;

[0051] Figure 4 A flowchart of another database upgrade method provided in this application;

[0052] Figure 5 A schematic diagram of the structure of the database upgrade device provided in this application;

[0053] Figure 6 A schematic diagram of the structure of the electronic device provided in this application.

[0054] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION

[0055] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.

[0056] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards, and provide corresponding operation entrances for users to choose to authorize or refuse.

[0057] First, the terms involved in this application are explained:

[0058] A distributed database (DDB), such as MySQL and Redis, is a database system that stores data in multiple physical nodes. The physical nodes can be computers or servers, etc. Data can be replicated and synchronized between multiple nodes to maintain data consistency.

[0059] The master database (Master), also known as the master node or master server, is the main data storage node in the above database system. All data write operations (such as insert, update, and delete) are usually performed on the master database first. The master database maintains data consistency and synchronizes data changes to the slave database. The master database instance (Master Instance) is a specific implementation or running instance of the logical concept of the master database, which specifically implements the functions of the master database.

[0060] A slave library (Slave) can also be called a slave node or a slave server. It is an auxiliary data storage node in the above database system. The slave library is usually used to process read operations to reduce the load of the master library. The slave library receives data changes from the master library and maintains data consistency with the master library. A slave library instance (Slave Instance) is a specific implementation or running instance of the logical concept of the slave library, which specifically implements the function of the slave library. In this application, the slave library can also be called a standby library.

[0061] Master-Slave Switch is a high availability mechanism in distributed database systems. It is used to switch roles between the master and slave databases. When the master-slave switch is completed, the original master database role is switched to the slave database role, and the original slave database role is switched to the master database role.

[0062] Figure 1 The database upgrade schematic diagram provided for this application is as follows: Figure 1 As shown, taking a distributed database in a one-master-two-slave (one master database and two slave databases) mode as an example, before the database upgrade, one master and two slaves are represented by an old master database and two old slave databases. After the database upgrade, one master and two slaves are represented by a new master database and two new slave databases. The specific implementation steps are as follows:

[0063] S101. Unbind an old slave library from an old master library, and upgrade the old slave library to obtain a new slave library.

[0064] The old master library can also be called the original master library, which means the master library of the unupgraded version. The old slave library means the slave library of the unupgraded version, and the new slave library means the slave library of the upgraded version.

[0065] Before unbinding, the old slave database has a synchronization relationship with the old master database, which enables the old slave database to receive and apply data changes from the old master database, ensuring data consistency between the old slave database and the old master database. When the old slave database is unbound from the old master database, the old slave database will run independently of the old master database, and there will be no synchronization relationship.

[0066] S102. Bind the new slave library to the old master library.

[0067] Among them, when the new slave library is bound to the old master library, the new slave library and the old master library are in a synchronization relationship, so that the new slave library can receive and apply data changes from the old master library, ensuring the data consistency between the new slave library and the old master library.

[0068] S103, continue to execute to unbind an old slave library from the old master library, and upgrade the old slave library to obtain a new slave library.

[0069] S104. Bind the new slave library to the old master library.

[0070] S105, performing master-slave switching.

[0071] It should be noted that before S105 , the process further includes: determining a target slave library for master-slave switching.

[0072] Specifically, if a new slave library that meets the synchronous replication mode is traversed, the new slave library will be used as the slave library before the master-slave switch, and the old master library will be used as the master library before the master-slave switch. After the master-slave switch, the new slave library will be used as the new master library after the master-slave switch, and the old master library will be used as the slave library after the master-slave switch.

[0073] S106: Unbind the old master database from the new master database, and upgrade the old master database to obtain a new slave database.

[0074] S107. Bind the new slave database to the new master database.

[0075] At this point, it indicates that an old master database and two old slave databases of the distributed database have been upgraded to a new master database and two new slave databases, and the database upgrade is complete.

[0076] However, as can be seen from the above, after unbinding the slave database and before binding the slave database, if a large number of users have business needs for the database, the distributed database that is upgrading its version will face a heavy load on resources, affecting user access. Therefore, upgrading the database version has the problem of poor stability.

[0077] In response to the above problems, the database upgrade method provided by the present application deletes an old version of the slave library after each new slave library is built, with a step size of 1, which will not cause waste of resources. If a failure occurs during the database upgrade process, the cost of recovery is also very low. The database upgrade method provided by the present application obtains backup data by performing a full physical backup of the original master library; performs a data upgrade on the backup data to build a new slave library; uses the new slave library to replace the first slave library among multiple slave libraries, repeats the above steps of replacing the first slave library among multiple slave libraries with the new slave library until the upgrade of multiple slave libraries is completed, and obtains multiple upgraded slave libraries; after the master-slave switch is performed, the upgrade of the original master library is realized. The database upgrade method provided by the present application improves the stability when upgrading the database version.

[0078] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.

[0079] Figure 2 A flowchart of a database upgrade method provided in this application is shown in FIG. Figure 2 As shown, the method includes:

[0080] S201. Perform a full physical backup of the original master database to obtain backup data.

[0081] A full physical backup refers to a complete backup of all data files, log files, configuration files, etc. of a database. A full backup contains all the contents of the database and can be used independently to restore the database to its state at the time of the backup.

[0082] In the present application, a full physical backup is performed on the original main database, and the obtained backup data can be used for backup and recovery to obtain a new database, and the new database is a copy of the data of the original main database.

[0083] Exemplarily, the statement used by the MySQL database to perform a full physical backup of the original master database may be "mysqldump" or "xtrabackup". For example, all data of the original master database is backed up to a specified path. The backup file is named backup, and the format of the backup file is ".sql". The specific expression of the statement may be: "mysqldump -u root -p --all-databases> / path / to / backup / backup.sql".

[0084] S202, performing data upgrade on the backup data to build a new slave database; in the process of obtaining the new slave database, the multiple slave databases and the original master database are in a normal access state.

[0085] It should be noted that in this application, the backup data is a static database snapshot that contains all the data of the original master database at the time of the backup. Data upgrade can also be called backup recovery, which is to restore the backup data to a new database instance. This new database instance is the so-called new slave database. The recovery process includes loading the backup data into the new instance to make it a new slave database that is consistent with the original master database data. The version of the new slave database is the upgraded version.

[0086] In an optional embodiment, the difference between the upgraded version and the pre-upgrade version is a minor version. For example, the pre-upgrade version is 8.0.23, and the upgraded version is 8.0.24. There is a security vulnerability in the 8.0.23 version of the database. After the vulnerability is resolved, the upgraded version is 8.0.24. At this time, in order to synchronize the vulnerability resolution results between multiple slave libraries and the original master library, there is a need to upgrade the database.

[0087] In a possible implementation, in the process of obtaining a new slave library, multiple slave libraries and the original master library are in a normal access state, and the specific implementation steps are as follows:

[0088] S2021. In the process of obtaining the new slave library, the VIP address corresponding to the master library is provided to the outside; wherein, the VIP address is used as the address of the original master library before the master-slave switching operation is performed, and is used as the address of the new master library after the master-slave switching operation is performed, and the version of the new master library is the upgraded version.

[0089] Among them, the VIP address is also called a virtual IP address. Specifically, services are provided externally through a proxy node. In response to user business requests obtained based on the IP address of the proxy node, the user business requests are allocated to the main database pointed to by the VIP address for business processing, wherein the IP address of the proxy node and the VIP address are in a one-to-one correspondence.

[0090] S2022. In response to the user service request obtained based on the VIP address, the user service request is allocated to the primary library pointed to by the VIP address for service processing.

[0091] In the process of obtaining a new slave database, the new slave database is independent of the original master database, and will not affect the operation of the existing original master database and multiple slave databases bound to the original master database (including the slave databases of the old version that have not been unbound and the slave databases of the new version that have been bound). It establishes a connection with the user's business request through the VIP address, ensuring high availability and data consistency during the database upgrade process. This method effectively avoids downtime maintenance and improves the stability of database upgrades and user experience.

[0092] S203, using a new slave library to replace the first slave library among the multiple slave libraries, repeating the above step of using the new slave library to replace the first slave library among the multiple slave libraries until the upgrade of the multiple slave libraries is completed, thereby obtaining the upgraded multiple slave libraries; during the process of upgrading the multiple slave libraries, the original master library is in a normal access state.

[0093] The first slave library is any one of the multiple slave libraries in a synchronization relationship with the original master library. Completing the upgrade of multiple slave libraries may mean that the multiple slave libraries in a synchronization relationship with the original master library are upgraded after the method of S202, and the versions of the upgraded multiple slave libraries are upgraded versions.

[0094] In an optional implementation, replacing a first slave library among multiple slave libraries with a new slave library may include:

[0095] S2031. Bind the new slave library to the original master library, unbind the first slave library from the original master library, and delete the first slave library.

[0096] Binding the new slave database to the original master database may refer to establishing a synchronization relationship between the new slave database and the original master database, so that the new slave database can receive and apply data updates from the original master database, thereby ensuring data consistency and integrity.

[0097] Unbinding the first slave database from the original master database may refer to releasing the synchronization relationship between the first slave database and the original master database, so that the first slave database no longer receives data updates from the original master database.

[0098] Deleting the first slave library may refer to completely removing the first slave library and its related configuration data from the database system. By deleting the first slave library, database system resources can be released, and each time a new slave library is bound to the original master library, a non-upgraded first slave library is deleted, with a step size of 1, which is convenient for maintenance and ensures the stability and data consistency of the upgraded database version.

[0099] In an optional implementation, S203 further includes:

[0100] S2032a. Upgrade the backup data to obtain a second slave library; the data stored in the second slave library is the same as the data stored in the upgraded multiple slave libraries.

[0101] The method for obtaining the second slave library is consistent with the method for obtaining the new slave library, and the version of the second slave library is an upgraded version.

[0102] It should be pointed out that after obtaining the second slave library, the process also includes: binding the second slave library to the original master library.

[0103] At this time, the sum of the upgraded multiple slave libraries and the second slave libraries is equal to the sum of the original master library and the slave libraries in synchronization with the original master library before the database is upgraded, so that the target slave library is selected from the upgraded multiple slave libraries and the second slave libraries, and the target slave library is set as the new master library.

[0104] S2032b. Select a target slave library from the upgraded multiple slave libraries and the second slave library, and set the target slave library as the new master library.

[0105] In an optional implementation, the method for selecting a target slave library from the upgraded multiple slave libraries and the second slave library may include:

[0106] S2032ba, traverse the upgraded multiple slave libraries and the second slave library in sequence, and obtain the synchronization relationship between the slave library and the original master library.

[0107] S2032bb. The slave database that is obtained for the first time and has a synchronous replication relationship with the original master database is used as the target slave database.

[0108] Among them, the synchronization relationship includes synchronous replication relationship, semi-synchronous replication relationship and asynchronous replication relationship. In the database field, the synchronous replication relationship can mean that after the master library commits the transaction, all the slave library nodes must receive, respond and commit these transactions, and then the master library thread can continue to perform subsequent operations. The semi-synchronous replication relationship can mean that the master library only needs to wait for at least one slave library node to receive and reply, and the master library does not need to wait for all slave libraries to give feedback to the master library. The asynchronous replication relationship can mean that the master library writes the transaction event into the file, only notifies the slave library node, and then the master library will continue to process other operations, and at this time there is no guarantee that the notification will be transmitted to any slave library node.

[0109] The slave database that selects the synchronization relationship as the synchronous replication relationship can provide highly consistent data with the original master database, and when switching to the new master database, it can take over quickly, reducing system downtime and avoiding data loss. This strategy helps to achieve a smooth database upgrade process and ensure the stable operation of the system.

[0110] In an optional implementation, a target slave library is selected from the upgraded multiple slave libraries and the second slave library, and the target slave library is set as the new master library. The method may include:

[0111] S2032bc. If the original master database currently has a data write operation, obtain the synchronization time of the data to the upgraded multiple slave databases and the second slave database.

[0112] S2032bd. If the synchronization duration is less than or equal to a preset threshold, a target slave library is selected from the upgraded multiple slave libraries and the second slave library, and the target slave library is set as the new master library.

[0113] For example, when the synchronization time of data to multiple upgraded slave libraries and the second slave library is close to zero, it can be considered that the delay between the original master library and the target slave library has converged. From the perspective of customer experience, the delay at this time is almost negligible.

[0114] In an optional embodiment, the target slave library is set as the new master library by performing a master-slave switch, in which the master library before the master-slave switch is the original master library, the slave library before the master-slave switch is the target slave library, the target slave library serves as the new master library after the master-slave switch, and the original master library serves as the slave library after the master-slave switch.

[0115] In the database field, master-slave switching is usually used in scenarios such as fault recovery or load balancing. In this application, for example, in a MySQL database, a high-availability module can be used to implement master-slave switching, for example, the "mysqlrpladmin" tool or MHA (Master High Availability Manager) can be used for master-slave switching.

[0116] Master-slave switching is an operation that ensures high availability and data consistency in distributed database systems. Users are unaware of the duration of the master-slave switching, which ensures user experience and improves the stability of the upgraded database.

[0117] It should be noted that after S2032b, the method further includes:

[0118] S2033a. Unbind the original master database from the new master database.

[0119] S2033b. Delete the original master database and backup data.

[0120] The method of deleting the original master database and backup data helps to release resources. The original master database and backup data are deleted only after all slave databases are upgraded and the master-slave switch is completed. At this time, there is no need to roll back the backup data to prevent temporary failures during the database upgrade process. This indicates that the database upgrade has been completed, the master database and all slave databases that are in synchronization with the master database have completed the upgrade, and the data consistency between the new master database and all new slave databases has been achieved, which improves the stability of the database upgrade.

[0121] In an optional implementation, before S201, the method further includes:

[0122] S2001. Receive an upgrade query request from the client and obtain the data synchronization time between the original master database and the slave database.

[0123] The upgrade query request of the client can usually be initiated by a database administrator. Before initiating the upgrade query request, it is ensured that the database version to be upgraded already exists.

[0124] The data synchronization time between the original master database and the slave database may refer to the time from when the original master database writes data to when the data can be synchronized to all slave databases.

[0125] S2002. Send an upgrade query response to the client, where the upgrade query response includes data synchronization time.

[0126] Specifically, the client decides whether to accept the database upgrade based on the upgrade query response and its own needs.

[0127] For example, the client's own business requirements may be: "high availability", "high data consistency", or "excellent performance", etc. If the client has high requirements for data high availability, it can choose not to accept the database upgrade at present. If the client does not have high business requirements, it can upgrade the database immediately.

[0128] S2003. Receive upgrade feedback information from the client.

[0129] The upgrade feedback information is used to indicate whether the user accepts the data synchronization time.

[0130] S2004: If the upgrade feedback information is used to indicate that the user accepts the data synchronization time, a step of performing a full physical backup of the original master database to obtain backup data is performed.

[0131] In an optional implementation, if the upgrade feedback information is used to indicate that the user does not accept the data synchronization time, the method includes:

[0132] S2005. Send an upgrade indication request to the client, where the upgrade indication request is used to request a time period for upgrading the distributed database.

[0133] S2006. Receive an upgrade indication response from the client.

[0134] Specifically, the upgrade instruction includes an upgrade period, so that when the upgrade period is reached, a step of performing a full physical backup of the original main database to obtain backup data is executed.

[0135] S2007. According to the time period indicated in the upgrade instruction response, perform a step of performing a full physical backup of the original main database to obtain backup data.

[0136] The method in which users determine whether to accept database upgrades based on data synchronization time effectively ensures high availability and data consistency of database upgrades.

[0137] In order to better understand the changes in the master and slave databases before and after the database upgrade, Figure 3 A flowchart of a one-master-two-slave database upgrade method provided in this application is shown in FIG. Figure 3 As shown, taking a distributed database with one master and two slaves (one master and two slaves) mode as an example, before the database upgrade, one master and two slaves are represented by one original master and two slaves. After the database upgrade, one master and two slaves are represented by one new master and two new slaves. It should be noted that Figure 3 The numbers of the slave libraries and the new slave libraries are only used to facilitate understanding of the steps. For example, there is no other difference between slave library 1 and slave library 2, and there is no other difference between new slave library 1 and new slave library 2 and new slave library 3.

[0138] The steps include:

[0139] S301. Perform a full physical backup of the original master database to obtain backup data.

[0140] S302: Upgrade the backup data to build a new slave database.

[0141] S303, bind the new slave library to the original master library.

[0142] S304, delete a slave library.

[0143] Deleting a slave library may refer to deleting any one of two slave libraries that have not been upgraded.

[0144] S305: Upgrade the backup data to build a new slave database.

[0145] S306. Bind the new slave library to the original master library.

[0146] S307, delete a slave library.

[0147] Deleting a slave library may refer to deleting a slave library that has not been upgraded.

[0148] S308: Upgrade the backup data to build a new slave database.

[0149] S309, bind the new slave library to the original master library.

[0150] S310, performing master-slave switching.

[0151] Among them, the master database before the master-slave switch is the original master database, the slave database before the master-slave switch is a new slave database in a synchronous replication relationship among the three new slave databases, the master database after the master-slave switch is the new master database, a new slave database in a synchronous replication relationship among the three new slave databases, and the slave database after the master-slave switch is the original master database.

[0152] S311. Delete the original main database and backup data.

[0153] Through the above method, before the database is upgraded, it is configured with one original master library and two slave libraries (non-upgraded version), and after the database is upgraded, it is configured with one new master library and two new slave libraries. Each step ensures data consistency and high availability, and finally completes the master-slave switch to ensure that the master library is in a normal access state. Deleting the original master library and backup data is the final cleanup step to ensure efficient use of system resources. The database upgrade method of the present application ensures the stability of the database upgrade.

[0154] Figure 4 A flowchart of another database upgrade method provided for this application is shown in FIG. Figure 4 As shown, the method includes:

[0155] S401, query the master-slave delay time.

[0156] The master-slave delay time is equivalent to the above-mentioned data synchronization time.

[0157] S402: Determine whether the user accepts the master-slave delay time.

[0158] S403: If not, select another time to upgrade the database.

[0159] S404: If yes, the status of the master-slave instance is set from a normal status to an upgraded status.

[0160] The status of the master-slave instance may include: normal status, upgrade status, switch request status, and switch success status. The master-slave instance is an instance of a master library and multiple slave libraries.

[0161] Specifically, the normal state may refer to that the master and slave instances are in normal operation and can process read and write requests and data synchronization operations. The upgrade state may refer to that the master and slave instances are in the process of upgrading operations, and some operations may be suspended to ensure data consistency and smooth upgrading. The switch request state may refer to that the master and slave instances are ready to perform the master-slave switch operation, and only necessary preparations will be performed to ensure the success of the master-slave switch. The switch success state may refer to that the master-slave switch operation has been successfully completed, and the new master and slave roles have taken effect.

[0162] S405. Back up the original master database to generate a full physical backup.

[0163] S406. Generate a new slave library of a specified new version according to the backup.

[0164] S407, bind the new slave library to the original master library.

[0165] S408. Delete an old version of the slave library.

[0166] S409: Determine whether all old versions of the slave libraries have been deleted.

[0167] S410, if not, repeat the steps of generating a new slave library of a specified new version according to the backup and deleting a slave library of an old version until all slave libraries of the old versions are deleted.

[0168] S411. If yes, generate a new slave library of a specified new version according to the backup.

[0169] S412. Bind the new slave library to the original master library.

[0170] S413, waiting for the master-slave delay to converge.

[0171] Among them, waiting for the master-slave convergence is equivalent to the method in the above S2032bb and S2032bc if the synchronization duration is less than or equal to the preset threshold, which will not be repeated here.

[0172] S414: Set the status of the master-slave instance from the upgrade status to the switch request status.

[0173] S415, perform master-slave switching.

[0174] S416: Setting the state of the master-slave instance from the switching request state to the switching success state.

[0175] S417. Unbind the new master database from the original master database.

[0176] S418. Delete the original main database and backup.

[0177] It should be noted that Figure 2 The numbers of the old slave library and the new slave library are only used to facilitate understanding of the steps. For example, there is no other difference between the old slave library 1 and the old slave library 2, and there is no other difference between the new slave library 1 and the new slave library 2 and the new slave library 3.

[0178] Through the above method, before the database is upgraded, it is configured with one original master library and two slave libraries (non-upgraded version), and after the database is upgraded, it is configured with one new master library and two new slave libraries. Each step ensures data consistency and high availability, and finally completes the master-slave switch to ensure that the master library is in a normal access state. Deleting the original master library and backup data is the final cleanup step to ensure efficient use of system resources. The database upgrade method of the present application ensures the stability of the database upgrade.

[0179] Figure 5 The schematic diagram of the structure of the database upgrade device provided in this application is as follows: Figure 5 As shown, the database upgrade device 50 provided in the embodiment of the present application includes: a backup module 501, an upgrade module 502, and a replacement module 503;

[0180] The backup module 501 is used to perform a full physical backup of the original main database to obtain backup data.

[0181] The upgrade module 502 is used to upgrade the backup data to build a new slave library. In the process of obtaining the new slave library, the multiple slave libraries and the original master library are in a normal access state.

[0182] The replacement module 503 is used to replace the first slave library among multiple slave libraries with a new slave library, and repeat the above steps of replacing the first slave library among multiple slave libraries with the new slave library until the upgrade of the multiple slave libraries is completed to obtain the upgraded multiple slave libraries; during the process of upgrading the multiple slave libraries, the original master library is in a normal access state.

[0183] In an optional embodiment, the replacement module 503 is further used to bind the new slave library to the original master library, unbind the first slave library from the original master library, and delete the first slave library.

[0184] In an optional embodiment, the replacement module 503 is further used to perform data upgrade on the backup data to obtain a second slave library; the data stored in the second slave library is the same as the data stored in the upgraded multiple slave libraries;

[0185] A target slave library is selected from the upgraded multiple slave libraries and the second slave library, and the target slave library is set as a new master library.

[0186] In an optional embodiment, the replacement module 503 is further used to sequentially traverse the upgraded multiple slave libraries and the second slave library to obtain the synchronization relationship between the slave library and the original master library;

[0187] The slave database that is obtained for the first time and has a synchronous replication relationship with the original master database is used as the target slave database.

[0188] In an optional embodiment, the replacement module 503 is further used to obtain the synchronization time of data synchronization to the upgraded multiple slave libraries and the second slave library if the original master library currently has a data writing operation;

[0189] If the synchronization duration is less than or equal to a preset threshold, a target slave database is selected from the upgraded multiple slave databases and the second slave database, and the target slave database is set as the new master database.

[0190] In an optional embodiment, the replacement module 503 is further used to unbind the original master library from the new master library;

[0191] Delete the original main database and backup data;

[0192] In an optional embodiment, before the backup module 501, it is also used to receive an upgrade query request from the client and obtain the data synchronization time between the original master database and the slave database;

[0193] Send an upgrade query response to the client, where the upgrade query response includes the data synchronization time;

[0194] Receive upgrade feedback information from clients;

[0195] If the upgrade feedback information is used to indicate that the user accepts the data synchronization time, a step of performing a full physical backup of the original master database to obtain the backup data is performed.

[0196] In an optional embodiment, before the backup module 501, it is also used to send an upgrade indication request to the client if the upgrade feedback information is used to indicate that the user does not accept the data synchronization time, and the upgrade indication request is used to request a time period for upgrading the distributed database;

[0197] receiving an upgrade indication response from the client;

[0198] According to the time period indicated in the upgrade instruction response, perform a step of performing a full physical backup of the original primary database to obtain backup data.

[0199] Figure 6 A schematic diagram of the structure of the electronic device provided in this application, such as Figure 6 As shown, the electronic device 60 provided in the embodiment of the present application includes: at least one processor 601 and a memory 602. Optionally, the device 60 also includes a communication component 603. The processor 601, the memory 602 and the communication component 603 are connected via a bus 604.

[0200] In a specific implementation process, at least one processor 601 executes the computer execution instructions stored in the memory 602, so that at least one processor 601 executes the above method.

[0201] The specific implementation process of the processor 601 can be found in the above method embodiment, and its implementation principle and technical effect are similar, so this embodiment will not be repeated here.

[0202] In the above embodiments, it should be understood that the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. A general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the invention may be directly implemented as being executed by a hardware processor, or may be executed by a combination of hardware and software modules in the processor.

[0203] The memory may include a high-speed memory (Random Access Memory, RAM), and may also include a non-volatile memory (Non-volatile Memory, NVM), such as at least one disk memory.

[0204] The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the bus in the drawings of the present application is not limited to only one bus or one type of bus.

[0205] The present application also provides a computer program product, including a computer program, which implements the above method when executed by a processor.

[0206] The present application also provides a computer-readable storage medium, in which computer-executable instructions are stored. When a processor executes the computer-executable instructions, the above method is implemented.

[0207] The above-mentioned readable storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk. The readable storage medium can be any available medium that can be accessed by a general or special-purpose computer.

[0208] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily required by the present application.

[0209] It should be further noted that, although the various steps in the flow chart are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the flow chart may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these sub-steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.

[0210] It should be understood that the above-mentioned device embodiments are only illustrative, and the device of the present application can also be implemented in other ways. For example, the division of units / modules in the above-mentioned embodiments is only a logical function division, and there may be other division methods in actual implementation. For example, multiple units, modules or components can be combined, or can be integrated into another system, or some features can be ignored or not executed.

[0211] In addition, unless otherwise specified, each functional unit / module in each embodiment of the present application may be integrated into one unit / module, each unit / module may exist physically separately, or two or more units / modules may be integrated together. The above-mentioned integrated unit / module may be implemented in the form of hardware or in the form of a software program module.

[0212] If the integrated unit / module is implemented in the form of hardware, the hardware may be a digital circuit, an analog circuit, etc. The physical implementation of the hardware structure includes but is not limited to transistors, memristors, etc. If not specifically stated, the processor may be any appropriate hardware processor, such as a CPU, a GPU, an FPGA, a DSP, an ASIC, etc. If not specifically stated, the storage unit may be any appropriate magnetic storage medium or magneto-optical storage medium, such as a resistive random access memory RRAM (Resistive Random Access Memory), a dynamic random access memory DRAM (Dynamic Random Access Memory), a static random access memory SRAM (Static Random-Access Memory), an enhanced dynamic random access memory EDRAM (Enhanced Dynamic Random Access Memory), a high-bandwidth memory HBM (High-Bandwidth Memory), a hybrid memory cube HMC (Hybrid Memory Cube), etc.

[0213] If the integrated unit / module is implemented in the form of a software program module and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art or all or part of the technical solution, can be embodied in the form of a software product, which is stored in a memory and includes several instructions for a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the various embodiments of the present application. The aforementioned memory includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or optical disk and other media that can store program codes.

[0214] In the above embodiments, the description of each embodiment has its own emphasis. For parts not described in detail in a certain embodiment, please refer to the relevant description of other embodiments. The technical features of the above embodiments can be combined arbitrarily. In order to make the description concise, all possible combinations of the technical features in the above embodiments are not described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0215] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.

[0216] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.

Claims

1. A database upgrade method, characterized in that: Applied to a distributed database, the distributed database includes an original master database and multiple slave databases, and the original master database is in a synchronization relationship with each slave database; the method includes: Performing a full physical backup of the original master database to obtain backup data; Performing data upgrade on the backup data to construct a new slave library; in the process of obtaining the new slave library, the multiple slave libraries and the original master library are all in a normal access state; The new slave library is used to replace the first slave library among the multiple slave libraries, and the step of replacing the first slave library among the multiple slave libraries with the new slave library is repeated until the upgrade of the multiple slave libraries is completed to obtain the upgraded multiple slave libraries; during the process of upgrading the multiple slave libraries, the original master library is in a normal access state.

2. The method according to claim 1, characterized in that The step of replacing the first slave library of the plurality of slave libraries with the new slave library comprises: Binding the new slave library to the original master library, and Unbind the first slave library from the original master library, and delete the first slave library.

3. The method according to claim 1, characterized in that The method further comprises: Performing data upgrade on the backup data to obtain a second slave library; the data stored in the second slave library is the same as the data stored in the upgraded multiple slave libraries; A target slave library is selected from the upgraded multiple slave libraries and the second slave library, and the target slave library is set as a new master library.

4. The method according to claim 3, characterized in that The synchronization relationship includes a synchronous replication relationship, a semi-synchronous replication relationship, and an asynchronous replication relationship. The selecting a target slave library from the upgraded multiple slave libraries and the second slave library includes: Traversing the upgraded multiple slave libraries and the second slave library in sequence to obtain the synchronization relationship between the slave library and the original master library; The slave database that is acquired for the first time and has a synchronization relationship with the original master database as a synchronous replication relationship is used as the target slave database.

5. The method according to claim 3, characterized in that: The selecting a target slave library from the upgraded multiple slave libraries and the second slave library, and setting the target slave library as a new master library, includes: If the original master database currently has a data write operation, obtain the synchronization time of the data to the upgraded multiple slave databases and the second slave database; If the synchronization duration is less than or equal to a preset threshold, a target slave library is selected from the upgraded multiple slave libraries and the second slave library, and the target slave library is set as a new master library.

6. The method according to claim 3, characterized in that After selecting a target slave library from the upgraded multiple slave libraries and the second slave library and setting the target slave library as a new master library, the method further includes: Unbinding the original master database from the new master database; Delete the original main library and the backup data.

7. The method according to any one of claims 1 to 6, characterized in that: Before performing a full physical backup of the original master database to obtain the backup data, the method further includes: Receive an upgrade query request from a client, and obtain the data synchronization time between the original master database and the slave database; Sending an upgrade query response to the client, wherein the upgrade query response includes the data synchronization time; Receiving upgrade feedback information from the client; If the upgrade feedback information is used to indicate that the user accepts the data synchronization time, the step of performing a full physical backup of the original master database to obtain backup data is performed.

8. The method according to claim 7, characterized in that The method further comprises: If the upgrade feedback information is used to indicate that the user does not accept the data synchronization time, sending an upgrade indication request to the client, the upgrade indication request is used to request a time period for upgrading the distributed database; receiving an upgrade indication response from the client; According to the time period indicated in the upgrade indication response, the step of performing a full physical backup of the original primary database to obtain backup data is performed.

9. An electronic device, characterized in that: include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 8.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 8 when executed by a processor.