CN116627964A - Main database selection method, device, system, equipment and medium - Google Patents

Main database selection method, device, system, equipment and medium Download PDF

Info

Publication number
CN116627964A
CN116627964A CN202310445400.2A CN202310445400A CN116627964A CN 116627964 A CN116627964 A CN 116627964A CN 202310445400 A CN202310445400 A CN 202310445400A CN 116627964 A CN116627964 A CN 116627964A
Authority
CN
China
Prior art keywords
database
slave
slave database
optimal
role switching
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310445400.2A
Other languages
Chinese (zh)
Inventor
刘欢
张成远
张广超
葛集斌
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Jingdong Technology Information Technology Co Ltd
Original Assignee
Jingdong Technology Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Jingdong Technology Information Technology Co Ltd filed Critical Jingdong Technology Information Technology Co Ltd
Priority to CN202310445400.2A priority Critical patent/CN116627964A/en
Publication of CN116627964A publication Critical patent/CN116627964A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2282Tablespace storage structures; Management thereof
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/25Integrating or interfacing systems involving database management systems
    • G06F16/258Data format conversion from or to a database
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
    • G06F9/505Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals considering the load
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The embodiment of the invention discloses a method, a device, a system, equipment and a storage medium for selecting a main database, and relates to the technical field of computers. The method comprises the following steps: receiving heartbeat information sent by a master database and at least two slave databases at fixed time, wherein the heartbeat information sent by each slave database comprises load information of the corresponding slave database; under the condition that the failure of the master database is determined based on the heartbeat information of the master database, switching the master database into slave databases, and selecting an optimal slave database from all slave databases based on the load information of each slave database; and sending a role switching task to the optimal slave database so that the optimal slave database performs role switching according to the role switching task, and changing into a new master database under the condition that the role switching is successful. By adopting the technical scheme of the embodiment of the invention, the network overhead of the shared storage system in the process of selecting the main database can be greatly reduced.

Description

Main database selection method, device, system, equipment and medium
Technical Field
The embodiment of the invention relates to the technical field of computers, in particular to a method, a device, a system, equipment and a storage medium for selecting a main database.
Background
The architecture of existing shared memory systems typically includes a master database and a plurality of slave databases. The master database shares a share of data with a plurality of slave databases.
In a shared storage system, if a master database fails, the prior art generally uses a consistency protocol to perform cluster master selection, selects one slave database from a plurality of slave databases as a new master database, and then performs a role switching process to change the slave database into the new master database. In the process of realizing the invention, the inventor finds that the main database selection method of the shared storage system in the prior art at least has the problem of high network overhead.
Disclosure of Invention
The embodiment of the invention provides a method, a device, a system, equipment and a storage medium for selecting a main database, so as to reduce network overhead caused by selecting the main database in a shared storage system.
In a first aspect, an embodiment of the present invention provides a method for selecting a master database of a shared storage system, where the method includes:
receiving heartbeat information sent by a master database and at least two slave databases at fixed time, wherein the heartbeat information sent by each slave database comprises load information of the corresponding slave database;
Under the condition that the failure of the master database is determined based on the heartbeat information of the master database, switching the master database into slave databases, and selecting an optimal slave database from all slave databases based on the load information of each slave database;
and sending a role switching task to the optimal slave database so that the optimal slave database performs role switching according to the role switching task, and changing into a new master database under the condition that the role switching is successful.
In a second aspect, an embodiment of the present invention further provides a primary database selection apparatus of a shared storage system, where the apparatus includes:
the heartbeat information module is used for receiving the heartbeat information sent by the master database and at least two slave databases at fixed time, and the heartbeat information sent by each slave database comprises load information of the corresponding slave database;
the optimal slave database module is used for switching the master database into the slave databases under the condition that the master database fails based on the heartbeat information of the master database, and selecting an optimal slave database from all the slave databases based on the load information of each slave database;
and the role switching module is used for sending a role switching task to the optimal slave database so that the optimal slave database performs role switching according to the role switching task and changes into a new master database under the condition that the role switching is successful.
In a third aspect, an embodiment of the present invention provides a shared storage system, where the system includes a control device, a master database, and at least two slave databases;
the master database and the slave database are both configured to send heartbeat information to the control equipment at regular time, wherein the heartbeat information comprises load information of the corresponding slave database;
the control device is configured to switch the master database into slave databases and select an optimal slave database from all slave databases based on the load information of each slave database in the case that the master database fails based on the heartbeat information of the master database; sending a role switching task to the optimal slave database so that the optimal slave database performs role switching according to the role switching task and becomes a new master database under the condition that the role switching is successful;
the optimal slave database is configured to perform role switching according to the role switching task, and is changed into a new master database under the condition that the role switching is successful.
In a fourth aspect, an embodiment of the present invention provides an electronic device, including:
One or more processors;
a memory for storing one or more programs;
the one or more programs, when executed by the one or more processors, cause the one or more processors to implement a method for master database selection for a shared memory system as provided by any embodiment of the present invention.
In a fifth aspect, an embodiment of the present invention further provides a computer readable storage medium, where a computer program is stored, where the program when executed by a processor implements a method for selecting a master database of a shared storage system according to any embodiment of the present invention.
The embodiments of the above invention have the following advantages or benefits:
compared with the prior art, the technical scheme of the method for selecting the master database of the shared storage system provided by the embodiment of the invention has the advantages that the control equipment acquires heartbeat information for reflecting the running state of the master database and the running state of the slave database in real time and grasps the real-time states of the master database and the slave database in real time; under the condition that the main database is found to have faults, a main database selection flow is initiated; switching the master database to a slave database; accurately selecting an optimal slave database from all slave databases based on the load information of each slave database; notifying the role switching task to perform role switching through the role switching task; the optimal slave database performs role conversion according to the role switching task, and changes into a new master database under the condition that the role conversion is successful; the introduction of the control equipment integrally simplifies the selection flow of the main database, and under the condition that the main database is abnormal, only the optimal slave database has no extra network cost except the network cost caused by role conversion, so that the network cost required by the shared storage system during the selection of the main database can be greatly reduced.
Drawings
FIG. 1A is a flowchart illustrating a method for selecting a master database of a shared memory system according to an embodiment of the present invention;
FIG. 1B is a block diagram of a shared memory system according to an embodiment of the present invention;
FIG. 2 is a flowchart of a method for selecting an optimal database according to an embodiment of the present invention;
FIG. 3 is a flowchart illustrating a method for selecting a master database of another shared storage system according to an embodiment of the present invention;
FIG. 4 is a flowchart illustrating a method for selecting a master database of another shared storage system according to an embodiment of the present invention;
FIG. 5A is a schematic diagram of a primary database selection device of a shared memory system according to an embodiment of the present invention;
FIG. 5B is a schematic diagram illustrating a master database selection device of another shared memory system according to an embodiment of the present invention;
fig. 6 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
The invention is described in further detail below with reference to the drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting thereof. It should be further noted that, for convenience of description, only some, but not all of the structures related to the present invention are shown in the drawings.
Fig. 1A is a flowchart of a method for selecting a master database of a shared storage system according to an embodiment of the present invention, where the embodiment is applicable to a case of selecting a master database of a shared storage system by a control device. The method may be performed by a primary database selection device of a shared storage system, which may be implemented in software and/or hardware. As shown in fig. 1A, the method specifically includes the following steps:
s110, receiving heartbeat information sent by a master database and at least two slave databases at fixed time, wherein the heartbeat information sent by each slave database comprises load information of the corresponding slave database.
The control device is any one of electronic devices such as personal computer devices, palm computers, server devices and the like. The control device is configured to receive in real-time heartbeat information transmitted from the master database and the at least two slave databases at regular time.
As shown in fig. 1B, the shared storage system includes a control device, a master database, and at least two slave databases. Both the master database and the slave database may provide data query services. The master database can share the pre-written log and the content data with the shared storage space and acquire the memory data from the shared storage space; and the pre-written log can only be loaded from the shared storage space from the database, and the corresponding memory data is determined based on the pre-written log for the user to inquire. The slave database can provide a query service for data shared by the master database to the shared storage space; if a certain data is not shared by the master database into the shared memory space, the slave database cannot provide the query service of the data.
The master database and the slave database may be configured to send heartbeat information to the control device based on the same time interval, such as 1 second or 2 seconds each, etc.; may also be configured to send heartbeat information to the control device based on different time intervals, the former having a time interval of 1 second and the latter having a time interval of 2 seconds; or the former time interval is 2 seconds, and the latter time interval is 1 second or 3 seconds, etc.
Each slave database may be configured to send heartbeat information to the control device based on the same or different time intervals.
In one embodiment, the heartbeat information sent from the database includes load information reflecting its motion state, such as at least one of query volume per second and throughput.
The heartbeat information of the main database at least comprises the sending moment of the heartbeat information. The heartbeat information of the slave database at least comprises the sending time of the heartbeat information and load information for reflecting the running state of the corresponding slave database. Wherein the load information may be at least one of a number of queries per second and throughput.
And S120, switching the master database into the slave databases and selecting the optimal slave database from all the slave databases based on the load information of each slave database when the master database fails based on the heartbeat information of the master database.
If the time length of the latest heartbeat information of the main database from the current moment is longer than the second set time length, checking whether the main database has faults or not; if the master database fails, the master database is switched to the slave databases, and the optimal slave database is selected from all the slave databases based on the load information of each slave database. If the main database does not fail, maintaining the role of the main database in the set holding time; if the heartbeat information of the main database is not received within the set holding time, returning to the step of checking whether the main database has faults or not until the fault checking times of the main database reach the set times, and outputting prompt information for indicating that the heartbeat information of the main database is abnormal so as to enable operation and maintenance personnel to intervene in time. In this embodiment, if the master database is only abnormal in heartbeat information transmission, but can provide a normal data sharing service, a set recovery time is provided for it as long as it can normally transmit heartbeat information within the set recovery time. Wherein the set recovery time is equal to a product of the set hold time and the set failure check number.
In one embodiment, the control device checks whether the primary database is faulty. The control device may issue an instruction for requesting the setting information of the master database to any slave database with normal heartbeat information, so that the slave database sends a first setting request to the master database according to the instruction, and determines whether the master database is out of connection, that is, whether the master database fails, through a reaction result of the master database to the first setting request. Taking the first setting request as an IP address acquisition request as an example. If the master database sends the IP address of the master database to the slave database, the communication between the master database and the slave database is normal, and the data sharing service can be provided for the slave database; if the master database does not send its own IP address to the slave database within a set period of time, the communication between the master database and the slave database is abnormal, and the data sharing service cannot be provided for the slave database, so that the master database is judged to be faulty.
In one embodiment, the control device checks whether the primary database is faulty. The control device may directly send a second setting request to the master database, and determine whether the master database fails according to a reaction result of the master database to the second setting request.
And S130, sending a role switching task to the optimal slave database so that the optimal slave database performs role switching according to the role switching task, and changing the optimal slave database into a new master database under the condition that the role switching is successful.
After determining the optimal slave database, the control device generates a role switching task aiming at the optimal slave database and sends the role switching task to the optimal slave database. After the role switching task is optimally received from the database, loading a current pre-written log from the shared storage, determining corresponding memory data based on the loaded pre-written log, enabling the memory data to be the same as the memory data in the main database, loading necessary metadata at the same time, executing a switching flow, and forming a new main database after the switching flow is completed. The switching process comprises calling the sharing storage iogating interface, allowing the IP address of the optimal slave database to have the sharing storage read-write authority, and setting the IP address of the original master database to only have the sharing storage read authority.
In one embodiment, after the optimum is determined from the database, waiting for its heartbeat information; and when receiving the expired heartbeat information, determining whether the time interval between the current heartbeat information and the previous heartbeat information of the optimal slave database is smaller than or equal to a first set duration. If yes, judging that the time interval of the two latest heartbeat information of the optimal slave database is smaller than or equal to a first set duration, and sending a role switching task to the optimal slave database; otherwise, judging that the heartbeat information fails to report or the optimal slave databases fail, and returning to the step of selecting the optimal slave databases from all the slave databases based on the load information of each slave database; or selecting the optimal slave database from other slave databases based on the load information of the other slave databases, and then sending the role switching task to the optimal slave database. In this embodiment, whether the load information of the optimal slave database and the time interval between the latest two heartbeat information thereof are smaller than or equal to the first set duration is ensured to be good, simple and quick.
Compared with the prior art, the technical scheme of the method for selecting the master database of the shared storage system provided by the embodiment of the invention has the advantages that the control equipment acquires heartbeat information for reflecting the running states of the master database and the slave database in real time and grasps the running states of the master database and the slave database in real time; under the condition that the main database is found to have faults, a main database selection flow is initiated; switching the master database to a slave database; accurately selecting an optimal slave database from all slave databases based on the load information of each slave database; notifying the role switching task to perform role switching through the role switching task; the optimal slave database performs role conversion according to the role switching task, and changes into a new master database under the condition that the role conversion is successful; the introduction of the control equipment integrally simplifies the selection flow of the main database, and under the condition that the main database is abnormal, only the optimal slave database has no extra network cost except the network cost caused by role conversion, so that the network cost required by the shared storage system during the selection of the main database can be greatly reduced.
Fig. 2 is a flowchart of a method for selecting an optimal database according to an embodiment of the present invention. The embodiment further refines the selection method of the optimal slave database. As shown in fig. 2, the method includes:
s2201, determining the duration of the transmission time corresponding to the heartbeat information of each slave database from the current time.
And after receiving the heartbeat information of each slave database, determining the duration of the sending moment included in the heartbeat information of each slave database from the current moment.
S2202, deleting the slave databases with the time length greater than the set time length threshold value from all the slave databases to obtain a target slave database set.
If the duration of the slave database is greater than a set duration threshold, such as 6 minutes, the slave database is considered to be operating poorly, otherwise the slave database is considered to be operating well. For this purpose, the embodiment deletes the slave databases with the duration greater than the set duration threshold from all the slave databases to obtain the target slave database set.
If the copy delay time of the pre-written log of one slave database is longer than the set delay time, the corresponding time of the role switching operation of the slave database is longer than the corresponding time of the role switching operation of the slave database of the zero copy delay time of the pre-written log. Because the slave database takes time to acquire unread data from the shared storage due to the copy delay time of the pre-write log in the role switching operation, it is necessary to have the same shared data as the previous master database. Therefore, when the role switching is needed, compared with the slave database with longer pre-written log copying delay time, the slave database with shorter pre-written log copying delay time can complete the role switching more quickly, namely, the optimal slave database can be changed into a new master database more quickly, and the sharing system can be changed from an abnormal state without the master database into a normal state with the master database more quickly.
To this end, in one embodiment, the heartbeat information from the database further includes a pre-written log replication delay period. After the target slave database set is obtained, deleting the slave database with the pre-written log replication delay time longer than the set delay time from the target slave database set to update the target slave database set; or deleting the slave databases with the pre-written log replication delay time longer than the set delay time length from all the slave databases before determining the target slave database set to obtain a candidate slave database set, and deleting the slave databases with the time length longer than the set time length threshold from the candidate slave database combination to obtain the target slave database set.
S2203, in the case that the target slave database set comprises at least two slave databases, selecting an optimal slave database from the target slave database set based on the load information of each slave database.
If the target slave database set comprises a slave database, the slave database is directly taken as the optimal slave database. If the target slave database set comprises at least two slave databases, an optimal slave database is selected from the target slave database set based on the load information of each slave database. If the target slave database set is empty, after setting the waiting time, S2201 is returned.
In one embodiment, the load information is the amount of queries and/or throughput per second. And taking the target slave database with the largest query amount per second and/or the slave database with the largest throughput as the optimal slave database. The embodiment can simply and quickly determine the optimal slave database from the target slave database set.
In one embodiment, the load information includes load information and a pre-write log replication delay time. The control device selects an optimal slave database from the updated target slave database set based on the load information of each slave database and the copy delay time length of the pre-written log. The method comprises the following steps:
and a1, for each slave database, carrying out weighted summation on the load information of the current slave database and the copy delay time length of the pre-written log so as to obtain the performance evaluation data of the current slave database.
In one embodiment, the performance rating data is a score.
Traversing the updated target slave database set, determining the load information and the replication delay time length of the current slave database, and carrying out weighted summation on the replication information and the replication delay time length to obtain the performance evaluation data of the current slave database. The method comprises the following steps:
Wherein L is j Copying a delay time length for the j-th slave database pre-written log; q (Q) j Representing the amount of queries per second for the jth slave database; t (T) j Representing throughput of the jth slave database; alpha is a proportionality coefficient, and the value range is 0,1]The coefficient may affect the pre-write log replication delay time or the specific gravity calculated from the database load on the performance evaluation data; m is the set delay period of time, the value range is (0), ++ infinity];For the maximum of the query volume per second of all the slave databases or target slave database setsThe maximum of all queries per second from the database combined; />Is the maximum of the throughput of all the slave databases or the maximum of the throughput of all the slave databases of the target slave database set.
And a2, selecting an optimal slave database from the updated target slave database set according to the performance evaluation data of each slave database.
And determining the performance evaluation data of all the slave databases of the updated target slave database set, and taking the slave database corresponding to the maximum performance evaluation data as the optimal slave database.
In one embodiment, a descending order sequencing result of the performance evaluation data of each slave database in the target slave database set is determined, and the slave database corresponding to the first-sequenced performance evaluation data is taken as the optimal slave database.
According to the embodiment of the invention, the optimal slave databases are selected from all the slave databases according to the heartbeat information sending interval and the load information of each slave database, so that the data calculation amount is small, and the method is simple, quick and accurate.
Fig. 3 is a flowchart of a method for selecting a master database of a shared storage system according to an embodiment of the present invention. The present embodiment adds the flow of the post-conversion processing from the database role optimally on the basis of the foregoing embodiment. As shown in fig. 3, the method includes:
s310, receiving heartbeat information sent by a master database and at least two slave databases at fixed time, wherein the heartbeat information sent by each slave database comprises load information of the corresponding slave database.
And S320, switching the master database into the slave databases and selecting the optimal slave database from all the slave databases based on the load information of each slave database when the master database fails based on the heartbeat information of the master database.
And S330, sending a role switching task to the optimal slave database so that the optimal slave database performs role switching according to the role switching task, and changing the optimal slave database into a new master database under the condition that the role switching is successful.
And S340, receiving heartbeat information which is optimally sent from the database and comprises a role switching result.
And after the role switching is finished by the optimal slave database, sending heartbeat information comprising the role switching result to the control equipment immediately, so that the control equipment can acquire the role switching result of the optimal slave database in time.
In one embodiment, the role switch result is represented by a contract identification. For example, a '1' is adopted to indicate that the role is successfully switched; a "0" is used to indicate a failure of role switch.
And S350, if the role switching corresponding to the role switching result fails, sending the role switching task to the optimal slave database again until the role switching corresponding to the role switching result is successful or the sending times of the role switching task reach the set times.
And the control equipment marks the role switching task as successful role switching when the role switching corresponding to the role switching result in the heartbeat information optimally sent from the database is detected to be successful. If the role switching corresponding to the role switching result fails, the role switching task is sent to the optimal slave database again until the role switching corresponding to the role switching result is successful or the sending times of the role switching task reach the set times.
And S360, under the condition that the number of times of sending the role switching task reaches the set number of times, selecting an optimal slave database from other slave databases based on the load information of the other slave databases, and returning to the step of sending the role switching task to the optimal slave database until the role switching corresponding to the role switching result is successful.
If the number of times of sending the role switching task to the optimal slave database reaches the set number of times, determining that the optimal slave database cannot complete role switching, and accordingly reselecting the optimal slave database from other slave databases based on the load information of the other slave databases, and returning to the step of sending the role switching task to the optimal slave database until heartbeat information carrying a role switching result corresponding to successful role switching is received.
Wherein the other slave databases include: and removing all the slave databases after the target optimal slave database from all the slave databases, wherein the target optimal slave database is the optimal slave database with failed switching of all roles corresponding to the latest failure master database, or the previous optimal slave database.
According to the embodiment of the invention, whether the optimal slave database successfully completes role conversion is determined by receiving the heartbeat information which is sent by the optimal slave database and comprises the role conversion result, and when the optimal slave database does not successfully complete role conversion, a role conversion task is sent to the optimal slave database again, so that the role conversion is carried out again; and if the role transition of the optimal slave node fails repeatedly, re-selecting the optimal slave database from other slave databases. The situation that the main database is short of a long time caused by failure of role conversion of the optimal slave database can be avoided, and the robustness of selection of the main database is improved, so that the running stability of the sharing system is improved.
Fig. 4 is a flowchart of a method for selecting a master database of a shared storage system according to an embodiment of the present invention. This embodiment adds the flow image of the abnormal slave database processing method on the basis of the foregoing embodiment. As shown in fig. 4, the method includes:
s410, receiving heartbeat information sent by a master database and at least two slave databases at fixed time, wherein the heartbeat information sent by each slave database comprises load information of the corresponding slave database.
S420, switching the master database into the slave databases when the master database fails based on the heartbeat information of the master database, and selecting the optimal slave database from all the slave databases based on the load information of each slave database.
And S430, sending a role switching task to the optimal slave database so that the optimal slave database performs role switching according to the role switching task, and changing the optimal slave database into a new master database under the condition that the role switching is successful.
S440, for each slave database, when the heartbeat information of the current slave database is not received within the third set time period, the access flow of the current slave database is transferred to at least one other slave database which does not generate faults.
And the control equipment determines the interval duration of the transmission time corresponding to the latest heartbeat information of each slave database from the current time in real time according to the heartbeat information transmitted by each slave database. For each slave database, if the interval time length corresponding to the current slave database is longer than or equal to the third set time length, judging that the slave database is abnormal; and determining the access flow of the current slave database, transferring the access flow of the current slave database to at least one other slave database which does not have a fault at present, and monitoring the heartbeat information sending condition of the current slave database in real time.
In one embodiment, if the heartbeat information of the current slave database is not received within a fourth set period after the transfer of the access traffic, the access traffic of the current slave database is transferred to other slave databases which do not have faults at present on average. This embodiment may balance the access traffic of the respective slave databases.
In one embodiment, at least one slave database for receiving the diverted traffic is preset, and the access traffic of this type of slave database itself is small. And if the control device does not receive the heartbeat information of a certain slave database within the third set time period, transferring the current access traffic of the slave database to one or more slave databases for receiving the transferred traffic. The embodiment can maintain the operation state of the slave database set to be free from receiving the transfer traffic and the access speed of the transferred access traffic, thereby ensuring high-speed and stable operation of the shared storage system.
S450, if the heartbeat information of the current slave database is not received within a fourth set time period after the access flow is transferred to the at least one other slave database, transferring the access flow transferred to the at least one other slave database to an alternative database.
In one embodiment, an alternative database is provided. In the case that a certain slave database fails, the control device modifies the role of the candidate database from the candidate database to the slave database and makes it replace the failed slave database.
In one embodiment, an alternative device is provided. The setting alternative device can be understood as a standby device of the slave database and is in a non-working state at ordinary times. Under the condition that a certain slave database fails, the control device controls the alternative device to enter a working state and finishes loading corresponding data to become a slave database for replacing the failed slave database.
If the heartbeat information of the current slave database is not received within the fourth set time period after the access flow is transferred, judging that the current slave database fails, replacing the current slave database by using the alternative database, and transferring the access flow transferred to the at least one other slave database to the replaced current slave database.
In this embodiment, when detecting that the heartbeat information of the slave database is abnormal, the slave database is not immediately pulled up, but the access flow is transferred to other slave databases, so that the slave databases have state recovery time under the condition that the normal operation of the shared storage system is ensured. The task processing amount of the operation and maintenance agent of the equipment is reduced.
And S460, if the heartbeat information of the current slave database is received within the fourth set time period after the access flow is transferred to the at least one other slave database, transferring the access flow transferred to the at least one other slave database back to the current slave database.
And if the heartbeat information sent from the database currently is received in the fourth set time after the access flow is transferred, judging that the database is recovered to be normal currently. Thus transferring access traffic transferred to other slave databases back to the current slave database.
In this embodiment, under the condition that the heartbeat information of a certain slave database is abnormal, instead of directly pulling up one slave database, the access flow is transferred to other slave databases to wait for the recovery of the slave database, and if the slave database is recovered to be normal within a fourth set duration, the access flow is transferred back to the slave database, thereby being beneficial to reducing the dependence on standby machines and the operation and maintenance cost.
The following is an embodiment of a master database selection device of a shared storage system provided by the embodiment of the present invention, where the device and the master database selection method of the shared storage system of the foregoing embodiments belong to the same inventive concept, and details of the master database selection device of the shared storage system, which are not described in detail in the embodiments of the master database selection device of the shared storage system, may refer to the details of the foregoing embodiments.
Fig. 5A is a schematic structural diagram of a primary database selection device of a shared memory system according to an embodiment of the present invention. The device and the method for selecting the main database of the shared storage system in the embodiment belong to the same invention conception. As shown in fig. 5A, the apparatus includes:
the heartbeat information module 510 is configured to receive heartbeat information sent by the master database and at least two slave databases at regular time, where each heartbeat information sent by the slave databases includes load information of the corresponding slave database;
an optimal slave database module 520, configured to switch the master database to a slave database, and select an optimal slave database from all slave databases based on load information of each slave database, when it is determined that the master database fails based on heartbeat information of the master database;
and the role switching module 530 is configured to send a role switching task to the optimal slave database, so that the optimal slave database performs role switching according to the role switching task, and changes to a new master database if the role switching is successful.
In one embodiment, the optimal slave database module 520 is specifically configured to:
a time length unit, configured to determine a time length of a transmission time corresponding to the heartbeat information of each slave database from the current time;
The target slave database collection unit is used for deleting slave databases with the time length greater than a set time length threshold value from all the slave databases so as to obtain a target slave database collection;
and the optimal slave database unit is used for selecting an optimal slave database from the target slave database set based on the load information of each slave database in the case that the target slave database set comprises at least two slave databases.
In one embodiment, the target slave database collection unit is configured to delete, from the target slave database collection, a slave database with a replication delay time longer than a set delay time period to update the target slave database collection;
the optimal slave database unit is used for selecting an optimal slave database from the updated target slave database set based on the load information of each slave database and the copy delay time length of the pre-written log.
In one embodiment, the optimal slave database unit is used in particular for:
for each slave database, carrying out weighted summation on the load information of the current slave database and the replication delay time length to obtain performance evaluation data of the current slave database;
and selecting an optimal slave database from the updated target slave database set according to the performance evaluation data of each slave database.
In one embodiment, the load information includes at least one of throughput and query rate per second.
In one embodiment, role switch module 530 is further to:
receiving heartbeat information which is sent by the optimal slave database and comprises a role switching result;
if the role switching corresponding to the role switching result fails, sending a role switching task to the optimal slave database again until the role switching corresponding to the role switching result is successful or the sending times of the role switching task reach the set times;
and under the condition that the sending times of the role switching tasks reach the set times, selecting an optimal slave database from other slave databases based on the load information of the other slave databases, and returning to the step of sending the role switching tasks to the optimal slave database until the role switching results correspond to the role switching success.
In one embodiment, the optimal slave database module 520 is specifically configured to:
checking whether the main database fails or not under the condition that heartbeat information sent by the main database is not received within a second set time length;
if not, maintaining the role of the main database in the set maintaining time;
And if the heartbeat information of the main database is not received within the set holding time, returning to the step of checking whether the main database has faults or not until the fault checking times of the main database reach the set times, and outputting prompt information for indicating that the heartbeat information of the main database is abnormal.
In one embodiment, role switch module 530 is specifically configured to:
determining whether the time interval of the two latest heartbeat information of the optimal slave database is smaller than or equal to a first set duration;
if yes, sending a role switching task to the optimal slave database;
if not, returning to the step of selecting the optimal slave database from all the slave databases based on the load information of each slave database.
In one embodiment, as shown in fig. 5B, the apparatus further comprises a slave database module 540 for:
for each slave database, under the condition that the heartbeat information of the current slave database is not received within a third set time period, transferring the access flow of the current slave database to at least one other slave database which does not have faults currently;
if the heartbeat information of the current slave database is not received within a fourth set time period after the access flow is transferred to the at least one other slave database, transferring the access flow transferred to the at least one other slave database to an alternative database;
And if the heartbeat information of the current slave database is received within the fourth set time period after the access traffic is transferred to the at least one other slave database, transferring the access traffic transferred to the at least one other slave database back to the current slave database.
Compared with the prior art, the technical scheme of the main database selection device of the shared storage system provided by the embodiment of the invention has the advantages that the control equipment acquires heartbeat information reflecting the running state of the main database and the running state of the auxiliary database in real time and grasps the real-time states of the main database and the auxiliary database in real time; under the condition that the main database is found to have faults, a main database selection flow is initiated; switching the master database to a slave database; accurately selecting an optimal slave database from all slave databases based on the load information of each slave database; notifying the role switching task to perform role switching through the role switching task; the optimal slave database performs role conversion according to the role switching task, and changes into a new master database under the condition that the role conversion is successful; the introduction of the control equipment integrally simplifies the selection flow of the main database, and under the condition that the main database is abnormal, only the optimal slave database has no extra network cost except the network cost caused by role conversion, so that the network cost required by the shared storage system during the selection of the main database can be greatly reduced.
The main database selection device of the shared storage system provided by the embodiment of the invention can execute the main database selection method of the shared storage system provided by any embodiment of the invention, and has the corresponding functional modules and beneficial effects of executing the main database selection method of the shared storage system.
Fig. 1B is a schematic diagram of a shared memory system according to an embodiment of the present invention. The system and the method for selecting the main database of the shared storage system in the embodiment belong to the same invention conception.
As shown in fig. 1B, the system includes a control device, a master database, and at least two slave databases; the master database and the slave database are both configured to send heartbeat information to the control equipment at regular time, wherein the heartbeat information comprises load information of the corresponding slave database; the control device is configured to switch the master database into slave databases and select an optimal slave database from all slave databases based on the load information of each slave database in the case that the master database fails based on the heartbeat information of the master database; sending a role switching task to the optimal slave database so that the optimal slave database performs role switching according to the role switching task and becomes a new master database under the condition that the role switching is successful; the optimal slave database is configured to perform role switching according to the role switching task, and is changed into a new master database under the condition that the role switching is successful.
The control device is configured to receive in real-time heartbeat information transmitted from the master database and the at least two slave databases at regular time.
The master database is a master database, and the slave database is a slave database. As shown in fig. 1B, the shared storage system includes a control device, a master database, and at least two slave databases. Both the master database and the slave database may provide data query services. The master database can share the pre-written log and the content data with the shared storage space and acquire the memory data from the content space; and the pre-written log can only be loaded from the shared storage space from the database, and the corresponding memory data is determined based on the pre-written log for the user to inquire. The slave database can provide a query service for data shared by the master database to the shared storage space; if a certain data is not shared by the master database into the shared memory space, the slave database cannot provide the query service of the data.
The master database and the slave database may be configured to send heartbeat information to the control device based on the same time interval, such as 1 second or 2 seconds each, etc.; may also be configured to send heartbeat information to the control device based on different time intervals, the former having a time interval of 1 second and the latter having a time interval of 2 seconds; or the former time interval is 2 seconds, and the latter time interval is 1 second or 3 seconds, etc.
Each slave database may be configured to send heartbeat information to the control device based on the same or different time intervals.
In one embodiment, the heartbeat information sent from the database includes load information reflecting its motion state, such as at least one of query volume per second and throughput.
The heartbeat information of the main database at least comprises the sending moment of the heartbeat information. The heartbeat information of the slave database at least comprises the sending time of the heartbeat information and load information for reflecting the running state of the corresponding slave database. Wherein the load information may be at least one of a number of queries per second and throughput.
The control device is configured to receive in real-time heartbeat information transmitted from the master database and the at least two slave databases at regular time.
The master database is a master database, and the slave database is a slave database. As shown in fig. 1B, the shared storage system includes a control device, a master database, and at least two slave databases. Both the master database and the slave database may provide data query services. The master database can share the pre-written log and the content data with the shared storage space and acquire the memory data from the shared storage space; and the pre-written log can only be loaded from the shared storage space from the database, and the corresponding memory data is determined based on the pre-written log for the user to inquire. The slave database can provide a query service for data shared by the master database to the shared storage space; if a certain data is not shared by the master database into the shared memory space, the slave database cannot provide the query service of the data.
The master database and the slave database may be configured to send heartbeat information to the control device based on the same time interval, such as 1 second or 2 seconds each, etc.; may also be configured to send heartbeat information to the control device based on different time intervals, the former having a time interval of 1 second and the latter having a time interval of 2 seconds; or the former time interval is 2 seconds, and the latter time interval is 1 second or 3 seconds, etc.
Each slave database may be configured to send heartbeat information to the control device based on the same or different time intervals.
In one embodiment, the heartbeat information sent from the database includes load information reflecting its motion state, such as at least one of query volume per second and throughput.
The heartbeat information of the main database at least comprises the sending moment of the heartbeat information. The heartbeat information of the slave database at least comprises the sending time of the heartbeat information and load information for reflecting the running state of the corresponding slave database. Wherein the load information may be at least one of a number of queries per second and throughput.
After determining the optimal slave database, the control device generates a role switching task aiming at the optimal slave database and sends the role switching task to the optimal slave database. After the role switching task is optimally received from the database, loading a current pre-written log from the shared storage, determining corresponding memory data based on the loaded pre-written log, enabling the memory data to be the same as the memory data in the main database, loading necessary metadata at the same time, executing a switching flow, and forming a new main database after the switching flow is completed. The switching process comprises calling the sharing storage iogating interface, allowing the IP address of the optimal slave database to have the sharing storage read-write authority, and setting the IP address of the original master database to only have the sharing storage read authority.
In one embodiment, after the optimum is determined from the database, waiting for its heartbeat information; and when receiving the expired heartbeat information, determining whether the time interval between the current heartbeat information and the previous heartbeat information of the optimal slave database is smaller than or equal to a first set duration. If yes, judging that the time interval of the two latest heartbeat information of the optimal slave database is smaller than or equal to a first set duration, and sending a role switching task to the optimal slave database; otherwise, judging that the heartbeat information fails to report or the optimal slave databases fail, and returning to the step of selecting the optimal slave databases from all the slave databases based on the load information of each slave database; or selecting the optimal slave database from other slave databases based on the load information of the other slave databases, and then sending the role switching task to the optimal slave database. In this embodiment, whether the load information of the optimal slave database and the time interval between the latest two heartbeat information thereof are smaller than or equal to the first set duration is ensured to be good, simple and quick.
In one embodiment, the heartbeat information further includes a sending time of the heartbeat information, and the selecting the optimal slave database from all slave databases based on the load information of each slave database includes:
Determining the duration of the sending time corresponding to the heartbeat information of each slave database from the current time;
deleting the slave databases with the time length greater than a set time length threshold value from all the slave databases to obtain a target slave database set;
and selecting an optimal slave database from the target slave database set based on the load information of each slave database in the case that the target slave database set comprises at least two slave databases.
In one embodiment, the heartbeat information further includes a pre-write log replication delay time period, and before the optimal slave database is selected from the target slave database set based on the load information of each slave database if the slave database target set is not empty, the method further includes:
deleting a slave database with a copy delay time longer than a set delay time from the target slave database set to update the target slave database set;
the selecting an optimal slave database from the target slave database set based on the load information of each slave database comprises the following steps:
and selecting an optimal slave database from the updated target slave database set based on the load information of each slave database and the copy delay time length of the pre-written log.
In one embodiment, selecting an optimal slave database from the updated target slave database set based on the load information of each slave database and the pre-written log replication delay time length data comprises:
for each slave database, carrying out weighted summation on the load information of the current slave database and the replication delay time length to obtain performance evaluation data of the current slave database;
and selecting an optimal slave database from the updated target slave database set according to the performance evaluation data of each slave database.
In one embodiment, the load information includes at least one of throughput and query rate per second.
In one embodiment, after sending the role switch task to the optimal slave database, further comprising:
receiving heartbeat information which is sent by the optimal slave database and comprises a role switching result;
if the role switching corresponding to the role switching result fails, sending a role switching task to the optimal slave database again until the role switching corresponding to the role switching result is successful or the sending times of the role switching task reach the set times;
and under the condition that the sending times of the role switching tasks reach the set times, selecting an optimal slave database from other slave databases based on the load information of the other slave databases, and returning to the step of sending the role switching tasks to the optimal slave database until the role switching results correspond to the role switching success.
In one embodiment, it is determined whether the primary database has failed by:
checking whether the main database fails or not under the condition that heartbeat information sent by the main database is not received within a second set time length;
if not, maintaining the role of the main database in the set maintaining time;
and if the heartbeat information of the main database is not received within the set holding time, returning to the step of checking whether the main database has faults or not until the fault checking times of the main database reach the set times, and outputting prompt information for indicating that the heartbeat information of the main database is abnormal.
In one embodiment, said sending role switch tasks to said optimal slave database comprises:
determining whether the time interval of the two latest heartbeat information of the optimal slave database is smaller than or equal to a first set duration;
if yes, sending a role switching task to the optimal slave database;
if not, returning to the step of selecting the optimal slave database from all the slave databases based on the load information of each slave database.
In one embodiment, the method further comprises:
For each slave database, under the condition that the heartbeat information of the current slave database is not received within a third set time period, transferring the access flow of the current slave database to at least one other slave database which does not have faults currently;
if the heartbeat information of the current slave database is not received within a fourth set time period after the access flow is transferred to the at least one other slave database, transferring the access flow transferred to the at least one other slave database to an alternative database;
and if the heartbeat information of the current slave database is received within the fourth set time period after the access traffic is transferred to the at least one other slave database, transferring the access traffic transferred to the at least one other slave database back to the current slave database.
Note that, the present embodiment is not described in detail, and reference is made to the foregoing embodiments.
Compared with the prior art, the technical scheme of the shared storage system provided by the embodiment of the invention has the advantages that the control equipment acquires the heartbeat information for reflecting the running state of the master database and the running state of the slave database in real time and grasps the real-time states of the master database and the slave database in real time; under the condition that the main database is found to have faults, a main database selection flow is initiated; switching the master database to a slave database; accurately selecting an optimal slave database from all slave databases based on the load information of each slave database; notifying the role switching task to perform role switching through the role switching task; the optimal slave database performs role conversion according to the role switching task, and changes into a new master database under the condition that the role conversion is successful; the introduction of the control equipment integrally simplifies the selection flow of the main database, and under the condition that the main database is abnormal, only the optimal slave database has no extra network cost except the network cost caused by role conversion, so that the network cost required by the shared storage system during the selection of the main database can be greatly reduced.
Fig. 6 is a schematic structural diagram of an electronic device according to an embodiment of the present invention. Fig. 6 shows a block diagram of an exemplary server 12 suitable for use in implementing embodiments of the present invention. The server 12 shown in fig. 6 is merely an example, and should not be construed as limiting the functionality and scope of use of embodiments of the present invention.
As shown in fig. 6, the server 12 is in the form of a general purpose computing device. The components of server 12 may include, but are not limited to: one or more processors or processing units 16, a system memory 28, a bus 18 that connects the various system components, including the system memory 28 and the processing units 16.
Bus 18 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor, and a local bus using any of a variety of bus architectures. By way of example, and not limitation, such architectures include Industry Standard Architecture (ISA) bus, micro channel architecture (MAC) bus, enhanced ISA bus, video Electronics Standards Association (VESA) local bus, and Peripheral Component Interconnect (PCI) bus.
Server 12 typically includes a variety of computer system readable media. Such media can be any available media that is accessible by server 12 and includes both volatile and nonvolatile media, removable and non-removable media.
The system memory 28 may include computer system readable media in the form of volatile memory, such as Random Access Memory (RAM) 30 and/or cache memory 32. The server 12 may further include other removable/non-removable, volatile/nonvolatile computer system storage media. By way of example only, storage system 34 may be used to read from or write to non-removable, nonvolatile magnetic media (not shown in FIG. 6, commonly referred to as a "hard disk drive"). Although not shown in fig. 6, a magnetic disk drive for reading from and writing to a removable non-volatile magnetic disk (e.g., a "floppy disk"), and an optical disk drive for reading from or writing to a removable non-volatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In such cases, each drive may be coupled to bus 18 through one or more data medium interfaces. The system memory 28 may include at least one program product having a set (e.g., at least one) of program modules configured to carry out the functions of the embodiments of the invention.
A program/utility 40 having a set (at least one) of program modules 42 may be stored in, for example, system memory 28, such program modules 42 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each or some combination of which may include an implementation of a network environment. Program modules 42 generally perform the functions and/or methods of the embodiments described herein.
The server 12 may also communicate with one or more external devices 14 (e.g., keyboard, pointing device, display 24, etc.), one or more devices that enable a user to interact with the server 12, and/or any devices (e.g., network card, modem, etc.) that enable the server 12 to communicate with one or more other computing devices. Such communication may occur through an input/output (I/O) interface 22. Also, the server 12 may communicate with one or more networks such as a Local Area Network (LAN), a Wide Area Network (WAN) and/or a public network, such as the Internet, via a network adapter 20. As shown, network adapter 20 communicates with the other modules of server 12 via bus 18. It should be appreciated that although not shown, other hardware and/or software modules may be used in connection with server 12, including, but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, data backup storage systems, and the like.
The processing unit 16 executes various functional applications and data processing by running a program stored in the system memory 28, for example, implementing the steps of the method for selecting a master database of the shared memory system according to any of the embodiments of the present invention, the method includes:
Receiving heartbeat information sent by a master database and at least two slave databases at fixed time, wherein the heartbeat information sent by each slave database comprises load information of the corresponding slave database;
under the condition that the failure of the master database is determined based on the heartbeat information of the master database, switching the master database into slave databases, and selecting an optimal slave database from all slave databases based on the load information of each slave database;
and sending a role switching task to the optimal slave database so that the optimal slave database performs role switching according to the role switching task, and changing into a new master database under the condition that the role switching is successful.
Of course, it will be understood by those skilled in the art that the processor may also implement the technical scheme of the method for selecting a master database of a shared storage system according to any embodiment of the present invention.
The present embodiment provides a computer readable storage medium having stored thereon a computer program which when executed by a processor implements the steps of a master database selection method of a shared memory system as provided in the foregoing embodiment of the present invention, the method comprising:
receiving heartbeat information sent by a master database and at least two slave databases at fixed time, wherein the heartbeat information sent by each slave database comprises load information of the corresponding slave database;
Under the condition that the failure of the master database is determined based on the heartbeat information of the master database, switching the master database into slave databases, and selecting an optimal slave database from all slave databases based on the load information of each slave database;
and sending a role switching task to the optimal slave database so that the optimal slave database performs role switching according to the role switching task, and changing into a new master database under the condition that the role switching is successful.
The computer storage media of embodiments of the invention may take the form of any combination of one or more computer-readable media. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. The computer readable storage medium may be, for example, but not limited to: an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples (a non-exhaustive list) of the computer-readable storage medium would include the following: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
The computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, either in baseband or as part of a carrier wave. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
Computer program code for carrying out operations of the present invention may be written in one or more programming languages, including an object oriented programming language such as Java, smalltalk, C ++ and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computer (for example, through the Internet using an Internet service provider).
It will be appreciated by those of ordinary skill in the art that the modules or steps of the invention described above may be implemented in a general purpose computing device, they may be centralized on a single computing device, or distributed over a network of computing devices, or they may alternatively be implemented in program code executable by a computer device, such that they are stored in a memory device and executed by the computing device, or they may be separately fabricated as individual integrated circuit modules, or multiple modules or steps within them may be fabricated as a single integrated circuit module. Thus, the present invention is not limited to any specific combination of hardware and software.
Note that the above is only a preferred embodiment of the present invention and the technical principle applied. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, while the invention has been described in connection with the above embodiments, the invention is not limited to the embodiments, but may be embodied in many other equivalent forms without departing from the spirit or scope of the invention, which is set forth in the following claims.

Claims (13)

1. A method for selecting a master database of a shared storage system, the method comprising:
receiving heartbeat information sent by a master database and at least two slave databases at fixed time, wherein the heartbeat information sent by each slave database comprises load information of the corresponding slave database;
under the condition that the failure of the master database is determined based on the heartbeat information of the master database, switching the master database into slave databases, and selecting an optimal slave database from all slave databases based on the load information of each slave database;
and sending a role switching task to the optimal slave database so that the optimal slave database performs role switching according to the role switching task, and changing into a new master database under the condition that the role switching is successful.
2. The method according to claim 1, wherein the heartbeat information further includes a sending time of the heartbeat information, and the selecting the optimal slave database from all slave databases based on the load information of each slave database includes:
determining the duration of the sending time corresponding to the heartbeat information of each slave database from the current time;
deleting the slave databases with the time length greater than a set time length threshold value from all the slave databases to obtain a target slave database set;
And selecting an optimal slave database from the target slave database set based on the load information of each slave database in the case that the target slave database set comprises at least two slave databases.
3. The method of claim 2, wherein the heartbeat information further includes a pre-write log replication delay period, the method further comprising, in the event that the target set of slave databases is not empty, before selecting an optimal slave database from the target set of slave databases based on load information of each of the slave databases:
deleting the slave database with the copy delay time of the pre-written log longer than the set delay time from the target slave database set to update the target slave database set;
the selecting an optimal slave database from the target slave database set based on the load information of each slave database comprises the following steps:
and selecting an optimal slave database from the updated target slave database set based on the load information of each slave database and the copy delay time length of the pre-written log.
4. The method of claim 3, wherein selecting an optimal slave database from the updated set of target slave databases based on the load information of each of the slave databases and the pre-written log replication delay time period, comprises:
For each slave database, carrying out weighted summation on the load information of the current slave database and the replication delay time length to obtain performance evaluation data of the current slave database;
and selecting an optimal slave database from the updated target slave database set according to the performance evaluation data of each slave database.
5. The method of any of claims 1-4, wherein the load information comprises at least one of throughput and query rate per second.
6. The method of claim 1, further comprising, after sending a role switch task to the optimal slave database:
receiving heartbeat information which is sent by the optimal slave database and comprises a role switching result;
if the role switching corresponding to the role switching result fails, sending a role switching task to the optimal slave database again until the role switching corresponding to the role switching result is successful or the sending times of the role switching task reach the set times;
and under the condition that the sending times of the role switching tasks reach the set times, selecting an optimal slave database from other slave databases based on the load information of the other slave databases, and returning to the step of sending the role switching tasks to the optimal slave database until the role switching results correspond to the role switching success.
7. The method of claim 1, wherein determining whether the primary database has failed is performed by:
checking whether the main database fails or not under the condition that heartbeat information sent by the main database is not received within a second set time length;
if not, maintaining the role of the main database in the set maintaining time;
and if the heartbeat information of the main database is not received within the set holding time, returning to the step of checking whether the main database has faults or not until the fault checking times of the main database reach the set times, and outputting prompt information for indicating that the heartbeat information of the main database is abnormal.
8. The method of claim 1, wherein the sending role switch tasks to the optimal slave database comprises:
determining whether the time interval of the two latest heartbeat information of the optimal slave database is smaller than or equal to a first set duration;
if yes, sending a role switching task to the optimal slave database;
if not, returning to the step of selecting the optimal slave database from all the slave databases based on the load information of each slave database.
9. The method as recited in claim 1, further comprising:
for each slave database, under the condition that the heartbeat information of the current slave database is not received within a third set time period, transferring the access flow of the current slave database to at least one other slave database which does not have faults currently;
if the heartbeat information of the current slave database is not received within a fourth set time period after the access flow is transferred to the at least one other slave database, transferring the access flow transferred to the at least one other slave database to an alternative database;
and if the heartbeat information of the current slave database is received within the fourth set time period after the access traffic is transferred to the at least one other slave database, transferring the access traffic transferred to the at least one other slave database back to the current slave database.
10. A master database selection apparatus for a shared memory system, the apparatus comprising:
the heartbeat information module is used for receiving the heartbeat information sent by the master database and at least two slave databases at fixed time, and the heartbeat information sent by each slave database comprises load information of the corresponding slave database;
The optimal slave database module is used for switching the master database into the slave databases under the condition that the master database fails based on the heartbeat information of the master database, and selecting an optimal slave database from all the slave databases based on the load information of each slave database;
and the role switching module is used for sending a role switching task to the optimal slave database so that the optimal slave database performs role switching according to the role switching task and changes into a new master database under the condition that the role switching is successful.
11. A shared storage system, the system comprising a control device, a master database, and at least two slave databases;
the master database and the slave database are both configured to send heartbeat information to the control equipment at regular time, wherein the heartbeat information comprises load information of the corresponding slave database;
the control device is configured to switch the master database into slave databases and select an optimal slave database from all slave databases based on the load information of each slave database in the case that the master database fails based on the heartbeat information of the master database; sending a role switching task to the optimal slave database so that the optimal slave database performs role switching according to the role switching task and becomes a new master database under the condition that the role switching is successful;
The optimal slave database is configured to perform role switching according to the role switching task, and is changed into a new master database under the condition that the role switching is successful.
12. An electronic device, the electronic device comprising:
one or more processors;
a memory for storing one or more programs;
the one or more programs, when executed by the one or more processors, cause the one or more processors to implement the master database selection method of a shared memory system as recited in any of claims 1-9.
13. A computer readable storage medium having stored thereon a computer program, which when executed by a processor implements a method of master database selection for a shared memory system as claimed in any one of claims 1-9.
CN202310445400.2A 2023-04-23 2023-04-23 Main database selection method, device, system, equipment and medium Pending CN116627964A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310445400.2A CN116627964A (en) 2023-04-23 2023-04-23 Main database selection method, device, system, equipment and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310445400.2A CN116627964A (en) 2023-04-23 2023-04-23 Main database selection method, device, system, equipment and medium

Publications (1)

Publication Number Publication Date
CN116627964A true CN116627964A (en) 2023-08-22

Family

ID=87609010

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310445400.2A Pending CN116627964A (en) 2023-04-23 2023-04-23 Main database selection method, device, system, equipment and medium

Country Status (1)

Country Link
CN (1) CN116627964A (en)

Similar Documents

Publication Publication Date Title
CN105357038B (en) Monitor the method and system of cluster virtual machine
US6078955A (en) Method for controlling a computer system including a plurality of computers and a network processed as a user resource
US10382380B1 (en) Workload management service for first-in first-out queues for network-accessible queuing and messaging services
US20170339238A1 (en) Large message support for a publish-subscribe messaging system
US20170339094A1 (en) Message delivery in messaging networks
US10970190B2 (en) Hybrid log viewer with thin memory usage
US6430616B1 (en) Scalable system method for efficiently logging management information associated with a network
CN103309731A (en) Processing system
EP2723017A1 (en) Method, apparatus and system for implementing distributed auto-incrementing counting
US8918795B2 (en) Handling and reporting of object state transitions on a multiprocess architecture
JP2007241486A (en) Memory system
JP5741254B2 (en) Transmission control method, apparatus and program
WO2020156796A1 (en) Handling an input/output store instruction
CN103108020A (en) Service collaboration device, service collaboration method, and computer-readable recording medium
JP5250955B2 (en) Data processing system backup control apparatus and system
CN106599323B (en) Method and device for realizing distributed pipeline in distributed file system
US20180018237A1 (en) Information processing apparatus and information processing system
CN114201280A (en) Multimedia data processing method, device, equipment and storage medium
US20230376470A1 (en) Moving Window Data Deduplication in Distributed Storage
CN116627964A (en) Main database selection method, device, system, equipment and medium
CN113641688B (en) Node updating method, related device and computer program product
US10996986B2 (en) Method and system for scheduling i/o operations for execution
US20210105343A1 (en) Sockets for shared link applications
US11379147B2 (en) Method, device, and computer program product for managing storage system
CN114969072B (en) Data transmission method, device and equipment based on state machine and data persistence

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination