Database management method and device, electronic equipment and storage medium
By responding to connection requests from the database and determining the transmission strategy in the database takeover system, the problems of database backup efficiency and failover automation are solved, database synchronization efficiency and data security are improved, and configuration complexity is reduced.
Patent Information
- Application Number
- CN202411122308.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-15
- Publication Date
- 2024-12-06
AI Technical Summary
The existing database backup solutions are not efficient and reliable, failover requires manual intervention, and configuring database clusters requires professional skills, which affects system reliability and stability.
By responding to the connection request from the slave database in the database takeover system, establishing a communication connection, receiving a log sequence number, determining the target write-up log information, and determining the transmission strategy based on the communication and database status information, the synchronization of the master and slave database is realized and the indicator information is monitored. to perform failover automatically.
Improve database synchronization efficiency, ensure data security and integrity, realize automated failure recovery, and reduce configuration complexity.
Smart Images

Figure CN119088878A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to a database management method, device, electronic equipment and storage medium. Background Art
[0002] With the continuous increase in data volume and demand for data security, a single database can no longer meet the requirements of high concurrency and load balancing. Therefore, it is necessary to build a reliable database cluster. In order to improve read and write efficiency, read-write separation technology is often required. At the same time, in order to ensure the security and integrity of data, regular data backup is also indispensable. At this time, database management systems came into being, and database management systems can provide reliable technical solutions for these needs. Among them, stream replication technology can achieve synchronization between the primary and standby databases to ensure data consistency. In addition, stream replication can also be used to build hot backup, off-site backup or multi-data center deployment to improve the fault tolerance and availability of the system.
[0003] However, in the process of using streaming replication technology to achieve master-slave database synchronization, there are the following technical problems:
[0004] 1) Low efficiency and reliability of data backup: Existing data backup solutions usually need to be manually executed regularly, and the backup process may affect the normal operation of the database. At the same time, the recovery test of the backup data is not sufficient, resulting in low efficiency and reliability of data backup;
[0005] 2) Failure switching requires manual intervention: When a primary server fails, the existing technology requires manual intervention to complete the failover, and cannot achieve automatic fault recovery, which affects the reliability and stability of the system;
[0006] 3) Professional skills are required: To correctly configure a database cluster, you need to have a high level of technical skills and rich experience. Lack of relevant professional knowledge and skills may cause problems in the configuration process or fail to complete it smoothly.
[0007] Therefore, there is an urgent need for a database management method to solve the above technical problems. Summary of the invention
[0008] The purpose of the embodiments of the present invention is to provide a database management method, device, electronic device and storage medium to solve at least one technical problem existing in the above-mentioned background technology.
[0009] In a first aspect, an embodiment of the present invention provides a database management method, which is applied to a master database in a database takeover system, wherein the database takeover system further includes at least one slave database, and the database management method includes:
[0010] In response to a connection request sent from a slave database, establishing a communication connection with the slave database;
[0011] receiving a first log sequence number sent by the slave database, and determining target write-ahead log information to be sent to the slave database according to a second log sequence number in the master database and the first log sequence number;
[0012] Acquire communication status information with the slave database and database status information of the slave database, and determine a target transmission strategy of the target write-ahead log information according to the communication status information and the database status information;
[0013] Based on the target transmission strategy, the target write-ahead log information is transmitted to the slave database, so that the slave database applies the target write-ahead log information to the slave database.
[0014] In some embodiments, the step of determining the target write-ahead log information to be sent to the slave database according to the second log sequence number and the first log sequence number in the master database includes:
[0015] Determine whether the second log sequence number in the primary database is the same as the first log sequence number;
[0016] In a case where the second log sequence number is different from the first log sequence number, all write-ahead log information between the second log sequence number and the first log sequence number is determined as target write-ahead log information to be sent to the slave database.
[0017] In some embodiments, the step of determining a target transmission strategy of the target write-ahead log information according to the communication status information and the database status information includes:
[0018] Determining a target communication channel according to the plurality of communication channel information in the communication state information;
[0019] Determining the transmission priority of the target write-ahead log information according to the configuration information in the database status information;
[0020] The target channel information and the transmission priority are determined as a target transmission strategy for the target write-ahead log information.
[0021] In some embodiments, the step of determining the target communication channel according to the multiple communication channels in the communication state information includes:
[0022] detecting a transmission rate of each communication channel in the communication status information;
[0023] The communication channel with the highest transmission rate is selected as a candidate channel;
[0024] Detecting a packet loss rate of each candidate channel;
[0025] The candidate channel with the lowest packet loss rate is determined as the target communication channel.
[0026] In some embodiments, the step of determining the transmission priority of the target write-ahead log information according to the configuration information in the database state information includes:
[0027] When the configuration information in the database status information represents the configuration information of the slave database and is not lower than the configuration information of the master database, determining the transmission priority of the target write-ahead log information to be the first priority;
[0028] When the configuration information in the database status information represents the configuration information of the slave database, which is lower than the configuration information of the master database, the transmission priority of the target write-ahead log information is determined to be the second priority, and the first priority is higher than the second priority.
[0029] In some embodiments, the slave database includes a first slave database and a second slave database, and the method further includes:
[0030] Obtaining a first application rate at which the first slave database applies the target write-ahead log information to the first slave database;
[0031] When the application rate is lower than a preset rate value, the target write-ahead log information is transmitted to the second slave database, the second application rate of the second slave database is higher than the preset rate value, and the transmission priority of the second slave database is not higher than the transmission priority of the first slave database.
[0032] In some embodiments, the method further comprises:
[0033] When the slave database completes the application of the target write-ahead log information, monitoring the current first indicator information of the master database and the current second indicator information of the slave database;
[0034] When the first indicator information indicates that the primary database needs to perform a failover, determining the workload information of the secondary database according to the second indicator information;
[0035] A slave database whose workload information is lower than a preset load rate is used as an object for a master-slave switching operation with the master database, and a master-standby switching operation is performed.
[0036] In a second aspect, an embodiment of the present invention provides a database management device, which is applied to a master database in a database takeover system, wherein the database takeover system further includes at least one slave database, and the database management device includes:
[0037] A connection module, configured to establish a communication connection with a slave database in response to a connection request sent from the slave database;
[0038] A receiving module, configured to receive a first log sequence number sent by the slave database, and determine target write-ahead log information to be sent to the slave database according to a second log sequence number in the master database and the first log sequence number;
[0039] A first acquisition module, configured to acquire communication status information with the slave database and database status information of the slave database, and determine a target transmission strategy for the target write-ahead log information according to the communication status information and the database status information;
[0040] The first transmission module is used to transmit the target write-ahead log information to the slave database based on the target transmission strategy, so that the slave database applies the target write-ahead log information to the slave database.
[0041] In a third aspect, an embodiment of the present invention provides an electronic device, comprising a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of any of the above-mentioned database management methods when executing the computer program.
[0042] In a fourth aspect, an embodiment of the present invention 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 steps in any of the above-mentioned database management methods are implemented.
[0043] The embodiment of the present invention provides a database management method, device, electronic device and storage medium. The method receives a first log sequence number sent from a slave database, determines target write-ahead log information to be sent to a slave database according to a second log sequence number in a master database, and then obtains communication status information with the slave database and database status information of the slave database to determine a target transmission strategy for the target write-ahead log information, thereby being able to transmit the target write-ahead log information to the slave database based on the target transmission strategy, so that the slave database can apply the target write-ahead log information to the slave database, thereby realizing synchronization operations between master and slave databases, which can not only effectively improve the synchronization efficiency of the database, but also ensure the security and integrity of the data during the synchronization process, and effectively prevent data loss or tampering. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] Figure 1 It is a flow chart of a database management method provided by an embodiment of the present invention;
[0045] Figure 2 It is a flow chart of a target transmission strategy for determining target write-ahead log information provided by an embodiment of the present invention;
[0046] Figure 3 It is a second flow chart of the database management method provided by the embodiment of the present invention;
[0047] Figure 4 1 is a third flow chart of the database management method provided in the embodiment of the present invention;
[0048] Figure 5 It is a structural schematic diagram of a database management device provided by an embodiment of the present invention;
[0049] Figure 6 is a structural schematic diagram of an electronic device provided by an embodiment of the present invention;
[0050] Figure 7 This is another structural schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0051] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0052] It should be understood that the various steps described in the method embodiments of the present disclosure may be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present disclosure is not limited in this respect.
[0053] The term "including" and its variations used herein are open inclusions, i.e., "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". The relevant definitions of other terms will be given in the following description.
[0054] In related technologies, with the continuous increase in data volume and demand for data security, a single database can no longer meet the requirements of high concurrency and load balancing. Therefore, it is necessary to build a reliable database cluster. In order to improve read and write efficiency, read-write separation technology is often required. At the same time, in order to ensure the security and integrity of data, regular data backup is also indispensable. At this time, database management systems came into being, and database management systems can provide reliable technical solutions for these needs. Among them, stream replication technology can achieve synchronization between the primary and standby databases to ensure data consistency. In addition, stream replication can also be used to build hot backup, off-site backup or multi-data center deployment to improve the fault tolerance and availability of the system.
[0055] However, in the process of using streaming replication technology to achieve master-slave database synchronization, there are the following technical problems:
[0056] 1) Low efficiency and reliability of data backup: Existing data backup solutions usually need to be manually executed regularly, and the backup process may affect the normal operation of the database. At the same time, the recovery test of the backup data is not sufficient, resulting in low efficiency and reliability of data backup;
[0057] 2) Failure switching requires manual intervention: When a primary server fails, the existing technology requires manual intervention to complete the failover, and cannot achieve automatic fault recovery, which affects the reliability and stability of the system;
[0058] 3) Professional skills are required: To correctly configure a database cluster, you need to have a high level of technical skills and rich experience. Lack of relevant professional knowledge and skills may cause problems in the configuration process or fail to complete it smoothly.
[0059] Therefore, there is an urgent need for a database management method to solve the above technical problems.
[0060] In order to solve the technical problems existing in the related art, an embodiment of the present invention provides a database management method, which can be applied to a master database in a database takeover system, wherein the database takeover system also includes at least one slave database. Figure 1 , Figure 1 1 is a flow chart of a database management method provided by an embodiment of the present invention, the method comprising steps 101 to 104;
[0061] Step 101: In response to a connection request sent by a slave database, establish a communication connection with the slave database.
[0062] In this embodiment, this embodiment mainly realizes data synchronization between the master and slave databases through write-ahead log information (WAL). Therefore, this embodiment can establish a communication connection through the walsender process set in the master database and the walreceiver process set in the slave database.
[0063] The walsender process is applied in the master database and mainly sends the write-ahead log information in the master database to the slave database. The walreceiver process is applied in the slave database and mainly receives the write-ahead log information sent by the master database.
[0064] Specifically, the specific connection process between the walsender process and the walreceiver process is as follows: the walreceiver process sends a connection request to the primary database. If the primary database has not yet started, the walreceiver will resend the request periodically. When the primary database receives the connection request, it will start the walsender process and establish a TCP connection between the walsender process and the walreceiver process.
[0065] Step 102: Receive the first log sequence number sent by the slave database, and determine the target write-ahead log information to be sent to the slave database according to the second log sequence number in the master database and the first log sequence number.
[0066] In this embodiment, the log sequence number (LSN) provided in this embodiment is mainly used to identify the location of a specific log file record in the log information, so as to determine the consistency of the data in the database. If the latest first log sequence number sent by the slave database is less than the latest second log sequence number of the master database, the walsender process of the master database will use the pre-write log information between the second log sequence number and the first log sequence number as the target pre-write log information sent to the walreceiver process of the slave database, so that the slave database can catch up with the master database and achieve the purpose of master-slave database synchronization.
[0067] Specifically, the step provided in this embodiment of determining the target write-ahead log information to be sent to the slave database based on the second log sequence number and the first log sequence number in the master database may be: determining whether the sequence numbers of the second log sequence number and the first log sequence number in the master database are the same; and in the case where the sequence numbers of the second log sequence number and the first log sequence number are different, determining all the write-ahead log information between the second log sequence number and the first log sequence number as the target write-ahead log information to be sent to the slave database.
[0068] Specifically, by using a write-ahead log in the database, the data modification in the database is not directly written to the database file, but is first written to the write-ahead log; if the transaction fails, the record in the write-ahead log will be ignored and the modification will be undone; if the transaction succeeds, it will be written back to the database file at a later time and the modification will be committed. In this way, using a write-ahead log to synchronize data between the master and slave databases can effectively ensure the atomicity and consistency of the data and effectively prevent data loss or tampering.
[0069] Step 103: Acquire communication status information with the slave database and database status information of the slave database, and determine a target transmission strategy of the target write-ahead log information according to the communication status information and the database status information.
[0070] In this embodiment, in order to improve the data synchronization efficiency between the master and slave databases, this embodiment can dynamically set the target transmission strategy of pre-write log information of different slave database transmission targets to select the optimal method and the fastest speed to synchronize the data of the master and slave databases, so as to avoid the problem of data loss and property loss caused by the lack of corresponding slave database to switch when the master database needs to switch the master-slave database.
[0071] For details, see Figure 2 , Figure 2 is a flow chart of a target transmission strategy for determining target write-ahead log information provided by an embodiment of the present invention, such as Figure 2 As shown, it includes steps 201 to 203;
[0072] Step 201: determine a target communication channel according to a plurality of communication channel information in the communication state information.
[0073] In this embodiment, after the slave database establishes a communication connection with the master database, there may be multiple communication channels for data transmission. In order to increase the transmission rate of transmitting the target pre-write log information to the slave database, this embodiment may select the communication channel with the highest transmission rate from multiple communication channels as the target communication channel, thereby improving the synchronization efficiency of data synchronization of the entire master-slave database.
[0074] Specifically, the step of determining the target communication channel based on multiple communication channels in the communication status information provided in this embodiment may be: detecting the transmission rate of each communication channel in the communication status information; taking the communication channel with the highest transmission rate as a candidate channel; detecting the packet loss rate of each candidate channel; and determining the candidate channel with the lowest packet loss rate as the target communication channel.
[0075] The transmission rate of each communication channel may be detected by using the same data at the transmitting end of each communication channel to perform a data transmission test on the receiving end, and then recording the time taken to transmit the data after the receiving end of each communication channel receives the data sent by the transmitting end. The communication channel with the least time taken is determined as the communication channel with the highest transmission rate.
[0076] While ensuring the data transmission rate, in order to ensure the integrity of the data transmission at the same time, this embodiment can also use the communication channel with the highest transmission rate as a candidate channel, and then detect the packet loss rate of each candidate signal, so that the candidate channel with the lowest packet loss rate is used only as the target communication channel to transmit the target pre-write log information.
[0077] Specifically, the packet loss rate of each candidate channel can be detected by using the same data at the transmitting end of each candidate channel to perform a data transmission test on the receiving end, and then after the receiving end of each candidate channel receives the data sent by the transmitting end, the integrity of the received data is detected to determine the packet loss rate of each candidate channel. The candidate channel with the lowest packet loss rate is determined as the target communication channel for transmitting the target pre-write log information. In this way, not only the efficiency of data transmission can be effectively guaranteed, but also the integrity of the data during the data transmission process can be guaranteed.
[0078] Step 202: Determine the transmission priority of the target write-ahead log information according to the configuration information in the database status information.
[0079] Among them, the configuration information provided by this embodiment may include CPU configuration information, storage capacity information, network bandwidth information and other configuration information that can characterize database performance. Specifically, the step of determining the transmission priority of the target write-ahead log information according to the configuration information in the database status information provided by this embodiment may be: when the configuration information in the database status information represents the configuration information of the slave database, which is not lower than the configuration information of the master database, determining the transmission priority of the target write-ahead log information to be the first priority; when the configuration information in the database status information represents the configuration information of the slave database, which is lower than the configuration information of the master database, determining the transmission priority of the target write-ahead log information to be the second priority, and the first priority is higher than the second priority.
[0080] In this way, the performance status of each slave database can be determined through the configuration information in the database status information, so that the slave database with the best performance status can be preferentially selected for the synchronization operation of the master-slave database, so as to complete the synchronization of the master-slave database as soon as possible, thereby improving the efficiency of the master-slave database synchronization and avoiding the problem of data loss and property loss when the master database needs to switch to the master-slave database and there is no corresponding slave database to switch.
[0081] Step 203: Determine the target channel information and the transmission priority as the target transmission strategy of the target write-ahead log information.
[0082] In this embodiment, after determining the target channel information and transmission priority corresponding to each slave database, the target channel information and transmission priority corresponding to each slave database can be used as the target transmission strategy for transmission to the corresponding slave database. In this way, not only can the data synchronization of each slave database with the master database be completed in sequence, but the synchronization efficiency of the data synchronization of each slave database can also be effectively improved.
[0083] As an optional embodiment, in order to enable the slave database to update data in time and maintain data synchronization with the master database, this embodiment can monitor the data synchronization status of each slave database, and when it is found that the slave database has a large synchronization delay, it is necessary to switch the slave database with a large synchronization delay to a database with a small synchronization delay, so as to ensure that the slave database connected to the master database can update data in time, so as to improve the reliability of the database management system, and facilitate the slave database that can provide data synchronization for the master database as a switching object when the master database fails. For details, please refer to Figure 3 , Figure 3 is a second flow chart of the database management method provided by the embodiment of the present invention, such as Figure 3 As shown, the slave database provided in this embodiment may include a first slave database and a second slave database. The database management method provided in this embodiment may also include: step 301 to step 302;
[0084] Step 301 : Obtain a first application rate at which the first slave database applies the target write-ahead log information to the first slave database.
[0085] In this embodiment, in order to determine the synchronization delay of each slave database, this embodiment can determine it by obtaining the application rate of the target write-ahead log information applied by the slave database. Specifically, the application time of the target write-ahead log information applied by the slave database can be recorded, and then the log file of the target write-ahead log can be checked to determine the operation content actually performed in the slave database, so as to determine the progress of applying the target write-ahead log information during the application time, and then the application rate of the current slave database can be calculated based on the application time and the progress.
[0086] The first slave database provided in this embodiment may be any slave database, and the first slave database is a slave database that is currently applying the target write-ahead log information.
[0087] Step 302, when the application rate is less than a preset rate value, the target write-ahead log information is transmitted to the second slave database, the second application rate of the second slave database is greater than the preset rate value, and the transmission priority of the second slave database is not higher than the transmission priority of the first slave database.
[0088] When adopting the method provided in an embodiment of the present invention, the first application rate of the current first slave database is calculated. The first application rate of the first slave database can be compared with a preset application rate value, and when the first application rate is lower than the preset application rate value, it is determined that the synchronization delay of the first slave database is large and it is necessary to switch to a second slave database with a smaller synchronization delay, that is, an application rate greater than the preset application rate value, to ensure that the slave database completes the data synchronization operation as soon as possible.
[0089] The preset application rate value provided in this embodiment may be a rate value set according to actual application requirements, or a rate value set according to the amount of data required for the application, and is not specifically limited here.
[0090] As another optional embodiment, in order to ensure the availability and stability of the database management system provided by this embodiment, this embodiment also needs to ensure that when the main database fails, the slave database can immediately and automatically take over the service. For details, please refer to Figure 4 , Figure 4 FIG. 1 is a third flow chart of the database management method provided in an embodiment of the present invention. Figure 4 As shown, the database management method provided in this embodiment may also include: step 401 to step 403;
[0091] Step 401 , when the slave database completes the application of the target write-ahead log information, monitor the current first indicator information of the master database and the current second indicator information of the slave database.
[0092] In order to select a matching slave database to immediately take over the service when the master database fails, this embodiment can continuously monitor the indicator information of the master database and the slave database. The indicator information provided by this embodiment may include the current occupancy rate of the running memory, the current working frequency of the CPU, the current network status information of the network, and the current remaining storage capacity of the storage space, etc., which can represent the current working status of the database.
[0093] Optionally, this embodiment can determine whether the current database needs to perform a primary-standby database switch operation based on the indicator information of the database. For example, when it is monitored that the operating memory usage of the primary database is 100%, or the CPU operating frequency is unstable and fluctuates, or the network status information is disconnected, or the remaining storage capacity of the storage space is 0, etc., it can be determined that the current primary database needs to perform a failover operation.
[0094] Step 402: When the first indicator information indicates that the primary database needs to perform a failover, determine the workload information of the secondary database according to the second indicator information.
[0095] In this embodiment, in order to ensure that the new master database can normally take over the service after the master-slave database switching operation is performed, this embodiment can first determine the current workload information of the slave database based on the second indicator information, avoid using a slave database with high load information as the object of master-slave switching, and prevent failure problems from occurring after the slave database switches to the master database to take over the service.
[0096] Step 403: The slave database whose workload information is lower than the preset load rate is used as the object of the master-slave switching operation with the master database, and the master-slave switching operation is performed.
[0097] Specifically, the preset load rate provided in this embodiment can be a value such as 50%, 40% or 30%, and can also be set according to the workload that the primary database needs to take over. As long as it can be guaranteed that the slave database has sufficient performance to take over the service after switching to the new primary database, no specific limitation is made here.
[0098] Step 104 : Based on the target transmission strategy, transmit the target write-ahead log information to the slave database, so that the slave database applies the target write-ahead log information to the slave database.
[0099] In order to enable the slave database to apply the target write-ahead log information to the slave database, the present embodiment may set a startup process in the slave database, wherein the startup process is used to apply the write-ahead log information to the slave database and ensure the atomicity and consistency of the transaction to avoid data corruption or inconsistency. At the same time, the startup process can also handle concurrent transactions to ensure the correct application order of data, avoid data conflicts or losses, and when the slave database fails or restarts, the slave database can be restored to the latest available data state according to the state of the write-ahead log information and the replication progress.
[0100] In this embodiment, the main purpose of this embodiment is to achieve synchronization between the master and slave databases through stream replication technology and based on the way of pre-write log transmission. Specifically, the process of achieving synchronization between the master and slave databases in this embodiment can be:
[0101] (1) When the background process of the primary database issues an insert statement in the primary database, the background process executes the XLogInsert() and XLogFlush() functions to write the pre-write log information to the cache area, and then refreshes the cache area to write the data in the cache area to the pre-write log segment file;
[0102] (2) The walsender process of the master database sends the write-ahead log information written into the write-ahead log segment file to the walreceiver process of the slave database;
[0103] (3) After the master database sends the WAL data, the backend process continues to wait for the ACK response from the slave database. More precisely, the background process executes the internal function SyncRepWaitForLSN() to obtain the latch and wait for it to be released;
[0104] (4) The walreceiver process of the slave database writes the received write-ahead log information into the write-ahead log buffer of the slave database through the write() function, and returns an ACK response to the walsender process of the master database;
[0105] (5) The walreceiver process of the slave database uses the fsync() function to cache all the write-ahead log information and write it to the write-ahead log segment file, and then returns an ACK response to the walsengder process of the master database, and at the same time notifies the startup process in the slave database that the write-ahead log related data has been updated;
[0106] (6) After receiving notification from the startup process in the database, the application has written the write-ahead log information to the write-ahead log segment file;
[0107] (7) The walsender process of the primary database releases the latch after receiving the ACK response, and then the backend process completes the commit or abort action. The time when the latch is released depends on the parameter synchronous_commit: if the parameter is on, the latch is released after receiving the ACK response in step (5); if it is remote_write, the latch is released after receiving the ACK response in step (4).
[0108] The above is a detailed description of the database management method provided by this embodiment.
[0109] In summary, an embodiment of the present invention provides a database management method, which is applied to a master database in a database takeover system, wherein the database takeover system further includes at least one slave database, wherein the method includes responding to a connection request sent by the slave database, establishing a communication connection with the slave database, receiving a first log sequence number sent by the slave database, determining target pre-write log information to be sent to the slave database according to a second log sequence number in the master database, obtaining communication status information with the slave database and database status information of the slave database to determine a target transmission strategy for the target pre-write log information, transmitting the target pre-write log information to the slave database based on the target transmission strategy, and allowing the slave database to apply the target pre-write log information to the slave database. The present invention can not only improve the synchronization efficiency of the database, but also ensure the security and integrity of the data during the synchronization process, and effectively prevent data loss or tampering.
[0110] According to the method described in the above embodiment, this embodiment will be further described from the perspective of a database management device. The database management device can be implemented as an independent entity or integrated into an electronic device, such as a terminal. The terminal can include a mobile phone, a tablet computer, etc.
[0111] In order to solve the same technical problem, this embodiment also provides a database management device, which is applied to a master database in a database takeover system, and the database takeover system also includes at least one slave database. Figure 5 , Figure 5 is a schematic diagram of a structure of a database management device provided by an embodiment of the present invention, such as Figure 5 As shown, the database management device 500 provided in the embodiment of the present invention includes: a connection module 501, a receiving module 502, a first acquisition module 503 and a first transmission module 504;
[0112] The connection module 501 is used to establish a communication connection with a slave database in response to a connection request sent from the slave database.
[0113] The receiving module 502 is used to receive the first log sequence number sent by the slave database, and determine the target write-ahead log information to be sent to the slave database according to the second log sequence number in the master database and the first log sequence number.
[0114] In this embodiment, the receiving module 502 provided in this embodiment is specifically used to: determine whether the sequence numbers between the second log sequence number and the first log sequence number in the master database are the same; in the case where the sequence numbers between the second log sequence number and the first log sequence number are different, determine all pre-write log information between the second log sequence number and the first log sequence number as target pre-write log information to be sent to the slave database.
[0115] The first acquisition module 503 is used to acquire the communication status information between the slave database and the database status information of the slave database, and determine the target transmission strategy of the target write-ahead log information according to the communication status information and the database status information.
[0116] In this embodiment, the first acquisition module 503 provided in this embodiment is specifically used to: determine the target communication channel according to the multiple communication channel information in the communication status information; determine the transmission priority of the target pre-write log information according to the configuration information in the database status information; determine the target channel information and the transmission priority as the target transmission strategy of the target pre-write log information.
[0117] In one implementation, the first acquisition module 503 provided in this embodiment is further specifically used to: detect the transmission rate of each communication channel in the communication status information; use the communication channel with the highest transmission rate as a candidate channel; detect the packet loss rate of each candidate channel; and determine the candidate channel with the lowest packet loss rate as the target communication channel.
[0118] In another implementation, the first acquisition module 503 provided in this embodiment is further specifically used for: when the configuration information in the database status information represents the configuration information of the slave database and is not lower than the configuration information of the master database, determining that the transmission priority of the target write-ahead log information is the first priority; when the configuration information in the database status information represents the configuration information of the slave database and is lower than the configuration information of the master database, determining that the transmission priority of the target write-ahead log information is the second priority, and the first priority is higher than the second priority.
[0119] The first transmission module 504 is configured to transmit the target write-ahead log information to the slave database based on the target transmission strategy, so that the slave database applies the target write-ahead log information to the slave database.
[0120] As an optional embodiment, the slave database provided in this embodiment includes a first slave database and a second slave database. The data management device 500 provided in this embodiment may also include a second acquisition module, a second transmission module, a monitoring module, a determination module, and a switching module.
[0121] The second acquisition module is used to acquire a first application rate at which the first slave database applies the target write-ahead log information to the first slave database.
[0122] A second transmission module is used to transmit the target write-ahead log information to the second slave database when the application rate is lower than a preset rate value, the second application rate of the second slave database is higher than the preset rate value, and the transmission priority of the second slave database is not higher than the transmission priority of the first slave database.
[0123] A monitoring module is used to monitor the current first indicator information of the master database and the current second indicator information of the slave database when the slave database completes the application of the target pre-write log information.
[0124] A determination module is used to determine the workload information of the slave database according to the second indicator information when the first indicator information indicates that the master database needs to perform a failover.
[0125] The switching module is used to use the slave database whose workload information is lower than the preset load rate as the object of the master-slave switching operation with the master database, and perform the master-standby switching operation.
[0126] During specific implementation, the above modules and / or units can be implemented as independent entities, or can be arbitrarily combined to be implemented as the same or several entities. The specific implementation of the above modules and / or units can refer to the previous method embodiments. The specific beneficial effects that can be achieved can also refer to the beneficial effects in the previous method embodiments, which will not be repeated here.
[0127] Also, see Figure 6 , Figure 6 1 is a schematic diagram of a structure of an electronic device provided by an embodiment of the present invention, and the electronic device may be a mobile terminal such as a smart phone, a tablet computer, or the like. Figure 6 As shown, the electronic device 600 includes a processor 601 and a memory 602. The processor 601 is electrically connected to the memory 602.
[0128] The processor 601 is the control center of the electronic device 600. It uses various interfaces and lines to connect various parts of the entire electronic device. It executes various functions of the electronic device 600 and processes data by running or loading applications stored in the memory 602 and calling data stored in the memory 602, thereby monitoring the electronic device 600 as a whole.
[0129] In this embodiment, the processor 601 in the electronic device 600 will load the instructions corresponding to the processes of one or more applications into the memory 602 according to the following steps, and the processor 601 will run the application stored in the memory 602, thereby implementing any step in the database management method provided in the above embodiment.
[0130] The electronic device 600 can implement the steps in any embodiment of the database management method provided in the embodiments of the present invention, and therefore can achieve the beneficial effects that can be achieved by any database management method provided in the embodiments of the present invention. Please refer to the previous embodiments for details and will not be repeated here.
[0131] See also Figure 7 , Figure 7 is another structural diagram of an electronic device provided by an embodiment of the present invention, such as Figure 7 As shown, Figure 7 The electronic device 700 is a block diagram of a specific structure of an electronic device provided in an embodiment of the present invention, and the electronic device can be used to implement the database management method provided in the above embodiment. The electronic device 700 can be a mobile terminal such as a smart phone or a laptop computer.
[0132] The RF circuit 710 is used to receive and send electromagnetic waves, realize the mutual conversion between electromagnetic waves and electrical signals, and thus communicate with a communication network or other devices. The RF circuit 710 may include various existing circuit elements for performing these functions, such as antennas, radio frequency transceivers, digital signal processors, encryption / decryption chips, user identity module (SIM) cards, memories, etc. The RF circuit 710 can communicate with various networks such as the Internet, corporate intranets, wireless networks, or communicate with other devices through wireless networks. The above-mentioned wireless networks may include cellular telephone networks, wireless local area networks, or metropolitan area networks. The above-mentioned wireless networks can use various communication standards, protocols and technologies, including but not limited to Global System for Mobile Communication (GSM), Enhanced Data GSM Environment (EDGE), Wideband Code Division Multiple Access (WCDMA), Code Division Multiple Access (CDMA), Time Division Multiple Access (TDMA), Wireless Fidelity (Wi-Fi) (such as Institute of Electrical and Electronics Engineers standards IEEE 802.11a, IEEE 802.11b, IEEE802.11g and / or IEEE802.11n), Voice over Internet Protocol (VoIP), Worldwide Interoperability for Microwave Access (Wi-Max), other protocols for email, instant messaging and short messages, and any other suitable communication protocols, even those that have not yet been developed.
[0133] The memory 720 can be used to store software programs and modules, such as the program instructions / modules corresponding to the database management method in the above-mentioned embodiment. The processor 780 executes various functional applications and manages the database by running the software programs and modules stored in the memory 720.
[0134] The memory 720 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 720 may further include a memory remotely arranged relative to the processor 780, and these remote memories may be connected to the electronic device 700 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0135] The input unit 730 can be used to receive input digital or character information, and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control. Specifically, the input unit 730 may include a touch-sensitive surface 731 and other input devices 732. The touch-sensitive surface 731, also known as a touch display screen or touch pad, can collect user touch operations on or near it (such as operations performed by users using fingers, styluses, or any other suitable objects or accessories on or near the touch-sensitive surface 731), and drive corresponding connection devices according to a pre-set program. Optionally, the touch-sensitive surface 731 may include a touch detection device and a touch controller. Among them, the touch detection device detects the user's touch orientation, detects the signal brought by the touch operation, and transmits the signal to the touch controller; the touch controller receives the touch information from the touch detection device, converts it into touch point coordinates, and then sends it to the processor 780, and can receive and execute commands sent by the processor 780. In addition, the touch-sensitive surface 731 can be implemented in various types such as resistive, capacitive, infrared, and surface acoustic wave. In addition to the touch-sensitive surface 731, the input unit 730 may further include other input devices 732. Specifically, the other input devices 732 may include, but are not limited to, one or more of a physical keyboard, function keys (such as volume control keys, switch keys, etc.), a trackball, a mouse, a joystick, and the like.
[0136] The display unit 740 can be used to display information input by the user or information provided to the user and various graphical user interfaces of the electronic device 700, which can be composed of graphics, text, icons, videos and any combination thereof. The display unit 740 may include a display panel 741, and optionally, the display panel 741 may be configured in the form of LCD (Liquid Crystal Display), OLED (Organic Light-Emitting Diode), etc. Further, the touch-sensitive surface 731 may cover the display panel 741, and when the touch-sensitive surface 731 detects a touch operation on or near it, it is transmitted to the processor 780 to determine the type of the touch event, and then the processor 780 provides corresponding visual output on the display panel 741 according to the type of the touch event. Although in the figure, the touch-sensitive surface 731 and the display panel 741 are implemented as two independent components to implement input and output functions, in some embodiments, the touch-sensitive surface 731 and the display panel 741 can be integrated to implement input and output functions.
[0137] The electronic device 700 may also include at least one sensor 750, such as a light sensor, a motion sensor, and other sensors. Specifically, the light sensor may include an ambient light sensor and a proximity sensor, wherein the ambient light sensor may adjust the brightness of the display panel 741 according to the brightness of the ambient light, and the proximity sensor may generate an interrupt when the flip cover is closed or closed. As a type of motion sensor, the gravity acceleration sensor can detect the magnitude of acceleration in each direction (generally three axes), and can detect the magnitude and direction of gravity when stationary, which can be used for applications that identify the posture of the mobile phone (such as horizontal and vertical screen switching, related games, magnetometer posture calibration), vibration recognition related functions (such as pedometer, tapping), etc.; as for other sensors such as gyroscopes, barometers, hygrometers, thermometers, infrared sensors, etc. that can also be configured in the electronic device 700, they will not be repeated here.
[0138] The audio circuit 760, the speaker 761, and the microphone 762 can provide an audio interface between the user and the electronic device 700. The audio circuit 760 can transmit the electrical signal converted from the received audio data to the speaker 761, which is converted into a sound signal for output; on the other hand, the microphone 762 converts the collected sound signal into an electrical signal, which is received by the audio circuit 760 and converted into audio data, and then the audio data is output to the processor 780 for processing, and then sent to another terminal through the RF circuit 710, or the audio data is output to the memory 720 for further processing. The audio circuit 760 may also include an earplug jack to provide communication between an external headset and the electronic device 700.
[0139] The electronic device 700 can help the user receive requests, send information, etc. through the first transmission module 770 (such as a Wi-Fi module), which provides the user with wireless broadband Internet access. Although the first transmission module 770 is shown in the figure, it is understandable that it is not a necessary component of the electronic device 700 and can be omitted as needed without changing the essence of the invention.
[0140] The processor 780 is the control center of the electronic device 700. It uses various interfaces and lines to connect various parts of the entire mobile phone. By running or executing software programs and / or modules stored in the memory 720, and calling data stored in the memory 720, it executes various functions of the electronic device 700 and processes data, thereby monitoring the electronic device as a whole. Optionally, the processor 780 may include one or more processing cores; in some embodiments, the processor 780 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, etc., and the modem processor mainly processes wireless communications. It can be understood that the above-mentioned modem processor may not be integrated into the processor 780.
[0141] The electronic device 700 also includes a power supply 790 (such as a battery) for supplying power to various components. In some embodiments, the power supply can be logically connected to the processor 780 through a power management system, so that the power management system can manage charging, discharging, and power consumption management. The power supply 790 can also include any components such as one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, and power status indicators.
[0142] Although not shown, the electronic device 700 also includes a camera (such as a front camera, a rear camera), a Bluetooth module, etc., which will not be described in detail here. Specifically in this embodiment, the display unit of the electronic device is a touch screen display, and the mobile terminal also includes a memory, and one or more programs, wherein one or more programs are stored in the memory, and are configured to be executed by one or more processors to implement any step in the database management method provided in the above embodiment.
[0143] In specific implementation, the above modules can be implemented as independent entities, or can be arbitrarily combined and implemented as the same or several entities. The specific implementation of the above modules can be found in the previous method embodiments, which will not be repeated here.
[0144] Those skilled in the art will appreciate that all or part of the steps in the various methods of the above embodiments can be completed by instructions, or by controlling related hardware through instructions, and the instructions can be stored in a computer-readable storage medium and loaded and executed by a processor. To this end, an embodiment of the present invention provides a storage medium, which stores a plurality of instructions, and when the instructions are executed by the processor, any step in the database management method provided in the above embodiments can be implemented.
[0145] The storage medium may include: a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0146] Since the instructions stored in the storage medium can execute the steps in any embodiment of the database management method provided in the embodiments of the present invention, the beneficial effects that can be achieved by any database management method provided in the embodiments of the present invention can be achieved. Please refer to the previous embodiments for details and will not be repeated here.
[0147] The above is a detailed introduction to a database management method, device, electronic device and storage medium provided in the embodiments of the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method and its core idea of the present application. At the same time, for those skilled in the art, according to the idea of the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application. Moreover, for those of ordinary skill in the art, without departing from the principles of the present invention, several improvements and modifications can be made, and these improvements and modifications are also regarded as the protection scope of the present invention.
Claims
1. A method for managing a database, characterized in that: A master database is applied to a database takeover system, wherein the database takeover system further comprises at least one slave database, and the database management method comprises: In response to a connection request sent from a slave database, establishing a communication connection with the slave database; receiving a first log sequence number sent by the slave database, and determining target write-ahead log information to be sent to the slave database according to a second log sequence number in the master database and the first log sequence number; Acquire communication status information with the slave database and database status information of the slave database, and determine a target transmission strategy of the target write-ahead log information according to the communication status information and the database status information; Based on the target transmission strategy, the target write-ahead log information is transmitted to the slave database, so that the slave database applies the target write-ahead log information to the slave database.
2. The database management method according to claim 1, characterized in that: The step of determining the target write-ahead log information to be sent to the slave database according to the second log sequence number and the first log sequence number in the master database comprises: Determine whether the second log sequence number in the primary database is the same as the first log sequence number; In a case where the second log sequence number is different from the first log sequence number, all write-ahead log information between the second log sequence number and the first log sequence number is determined as target write-ahead log information to be sent to the slave database.
3. The database management method according to claim 1, characterized in that: The step of determining a target transmission strategy of the target write-ahead log information according to the communication status information and the database status information comprises: Determining a target communication channel according to the plurality of communication channel information in the communication state information; Determining the transmission priority of the target write-ahead log information according to the configuration information in the database status information; The target channel information and the transmission priority are determined as a target transmission strategy for the target write-ahead log information.
4. The database management method according to claim 3, characterized in that: The step of determining a target communication channel according to the plurality of communication channels in the communication state information comprises: detecting a transmission rate of each communication channel in the communication status information; The communication channel with the highest transmission rate is selected as a candidate channel; Detecting a packet loss rate of each candidate channel; The candidate channel with the lowest packet loss rate is determined as the target communication channel.
5. The database management method according to claim 3, characterized in that: The step of determining the transmission priority of the target write-ahead log information according to the configuration information in the database status information comprises: When the configuration information in the database status information represents the configuration information of the slave database and is not lower than the configuration information of the master database, determining the transmission priority of the target write-ahead log information to be the first priority; When the configuration information in the database status information represents the configuration information of the slave database, which is lower than the configuration information of the master database, the transmission priority of the target write-ahead log information is determined to be the second priority, and the first priority is higher than the second priority.
6. The database management method according to claim 5, characterized in that: The slave database includes a first slave database and a second slave database, and the method further includes: Obtaining a first application rate at which the first slave database applies the target write-ahead log information to the first slave database; When the application rate is lower than a preset rate value, the target write-ahead log information is transmitted to the second slave database, the second application rate of the second slave database is higher than the preset rate value, and the transmission priority of the second slave database is not higher than the transmission priority of the first slave database.
7. The database management method according to claim 1, characterized in that: Also includes: When the slave database completes the application of the target write-ahead log information, monitoring the current first indicator information of the master database and the current second indicator information of the slave database; When the first indicator information indicates that the primary database needs to perform a failover, determining the workload information of the secondary database according to the second indicator information; A slave database whose workload information is lower than a preset load rate is used as an object for a master-slave switching operation with the master database, and a master-standby switching operation is performed.
8. A database management device, characterized in that: A master database applied to a database takeover system, wherein the database takeover system further comprises at least one slave database, and the database management device comprises: A connection module, configured to establish a communication connection with a slave database in response to a connection request sent from the slave database; A receiving module, configured to receive a first log sequence number sent by the slave database, and determine target write-ahead log information to be sent to the slave database according to a second log sequence number in the master database and the first log sequence number; A first acquisition module, configured to acquire communication status information with the slave database and database status information of the slave database, and determine a target transmission strategy for the target write-ahead log information according to the communication status information and the database status information; The first transmission module is used to transmit the target write-ahead log information to the slave database based on the target transmission strategy, so that the slave database applies the target write-ahead log information to the slave database.
9. An electronic device, characterized in that: The electronic device comprises a processor, a memory, and a computer program stored in the memory and executable on the processor, and the processor implements the steps in the method according to any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in the method according to any one of claims 1 to 7 are implemented.
