CN113297002A - Method and device for switching working modes of database - Google Patents

Method and device for switching working modes of database Download PDF

Info

Publication number
CN113297002A
CN113297002A CN202010107810.2A CN202010107810A CN113297002A CN 113297002 A CN113297002 A CN 113297002A CN 202010107810 A CN202010107810 A CN 202010107810A CN 113297002 A CN113297002 A CN 113297002A
Authority
CN
China
Prior art keywords
database
mode
master
switching
slave
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.)
Granted
Application number
CN202010107810.2A
Other languages
Chinese (zh)
Other versions
CN113297002B (en
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.)
Beijing Jingdong Zhenshi Information Technology Co Ltd
Original Assignee
Beijing Jingdong Zhenshi 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 Beijing Jingdong Zhenshi Information Technology Co Ltd filed Critical Beijing Jingdong Zhenshi Information Technology Co Ltd
Priority to CN202010107810.2A priority Critical patent/CN113297002B/en
Publication of CN113297002A publication Critical patent/CN113297002A/en
Application granted granted Critical
Publication of CN113297002B publication Critical patent/CN113297002B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1446Point-in-time backing up or restoration of persistent data
    • G06F11/1458Management of the backup or restore process
    • G06F11/1461Backup scheduling policy
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2201/00Indexing scheme relating to error detection, to error correction, and to monitoring
    • G06F2201/80Database-specific techniques
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2201/00Indexing scheme relating to error detection, to error correction, and to monitoring
    • G06F2201/805Real-time

Abstract

The invention discloses a method and a device for switching database working modes, and relates to the technical field of computers. One embodiment of the method comprises: when the database system is in a first mode, acquiring current master-slave delay data; if the acquired master-slave delay data meet a preset first switching condition, switching the working mode of the database system into a second mode or a third mode; or when the database system is in a second mode, acquiring current master-slave delay data; and if the acquired master-slave delay data meet a preset second switching condition, switching the working mode of the database system to a third mode. The implementation method can automatically monitor the delay condition of the current working mode and switch to a reasonable working mode according to the delay condition when the condition is met.

Description

Method and device for switching working modes of database
Technical Field
The invention relates to the technical field of computers, in particular to a method and a device for switching working modes of a database.
Background
In the current database cluster scheme, there can be one master with multiple slaves, one master with one slave, one master and other working modes. Wherein, a master-slave refers to that a master database and a plurality of slave databases provide services together, a master-slave refers to that a master database and a slave database provide services, and a master refers to that a master database provides services separately. In a specific application, since there may be a delay between the master database and the slave database and between the plurality of slave databases, and the service development may be affected when the delay is severe, it is necessary to switch to another working mode when the delay of the current working mode reaches a certain condition. In the existing switching scheme, whether delay exists needs to be monitored manually in real time, and when the delay exists, the configuration data of the UCC (unified configuration center) needs to be modified manually to realize switching of the working modes, so that the problems of judgment errors, UCC configuration errors, untimely switching and the like easily occur.
Disclosure of Invention
In view of this, embodiments of the present invention provide a method and an apparatus for switching a database operating mode, which can automatically monitor a delay condition of a current operating mode and switch to a reasonable operating mode according to the delay condition when a condition is met.
To achieve the above object, according to one aspect of the present invention, a method for switching database operation modes is provided.
The switching method of the working modes of the database is used for switching the working modes of a database system comprising a main database and a plurality of slave databases; wherein the operation modes include a first mode in which the master database and the plurality of slave databases provide services, a second mode in which the master database and one of the plurality of slave databases provide services, and a third mode in which the master database provides services alone; the method comprises the following steps: when the database system is in a first mode, acquiring current master-slave delay data; if the acquired master-slave delay data meet a preset first switching condition, switching the working mode of the database system into a second mode or a third mode; or when the database system is in a second mode, acquiring current master-slave delay data; and if the acquired master-slave delay data meet a preset second switching condition, switching the working mode of the database system to a third mode.
Optionally, the first switching condition is: the acquired master-slave delay data are larger than a preset second threshold; and switching the working mode of the database system to a second mode or a third mode comprises: when the acquired master-slave delay data are not larger than a preset fourth threshold value, switching the working mode of the database system to a second mode; wherein the fourth threshold is greater than the second threshold; and when the acquired master-slave delay data is larger than a fourth threshold value, switching the working mode of the database system to a third mode.
Optionally, the database system may turn on or off a backtracking main database function in the first mode; and, the method further comprises: when the database system is in a first mode and the function of backtracking a main database is closed, acquiring current master-slave delay data; and if the acquired master-slave delay data is greater than a preset first threshold and not greater than a second threshold, starting a backtracking master database function.
Optionally, the database system may turn on or off a backtracking main database function in the second mode; and when the acquired master-slave delay data are not greater than a preset fourth threshold, switching the working mode of the database system to a second mode, including: when the obtained master-slave delay data are larger than a second threshold and not larger than a preset third threshold, switching the working mode of the database system to a second mode and closing the function of backtracking the master database; wherein the third threshold is less than the fourth threshold; and when the acquired master-slave delay data is greater than a third threshold and not greater than a fourth threshold, switching the working mode of the database system to a second mode and starting a backtracking master database function.
Optionally, the database system may open or close the function of backtracking the main database in the second mode, and the second switching condition is: the acquired master-slave delay data are larger than a preset sixth threshold; and, the method further comprises: when the database system is in a second mode and the function of backtracking the main database is closed, acquiring current master-slave delay data; and if the acquired master-slave delay data is greater than a preset fifth threshold and not greater than a sixth threshold, starting a backtracking master database function.
Optionally, the master-slave delay data is delay duration data of a slave database relative to a master database, and the master database and the slave database are both MySQL.
In order to achieve the above object, according to another aspect of the present invention, a method for switching an operation mode of a database is provided.
The switching method of the working modes of the database is used for switching the working modes of a database collection system which comprises a first database system comprising a main database and a plurality of slave databases and a specific database; wherein a type of a particular database is different from the master database and the slave database; the operation modes include a first mode in which the master database and the plurality of slave databases provide services, a second mode in which the master database and one of the plurality of slave databases provide services, a third mode in which the master database provides services alone, and a fourth mode in which a specific database provides services alone; the method comprises the following steps: when the database collection system is in a first mode, acquiring current master-slave delay data; if the acquired master-slave delay data meet a preset third switching condition, switching the working mode of the database integration system into a second mode, a third mode or a fourth mode; or when the database collection system is in a second mode, acquiring current master-slave delay data; if the acquired master-slave delay data meet a preset fourth switching condition, switching the working mode of the database integration system into a third mode or a fourth mode; or when the database collection system is in a fourth mode, acquiring current query delay data; and if the acquired query delay data meet a preset fifth switching condition, switching the working mode of the database integration system into a first mode, a second mode or a third mode.
Optionally, the third switching condition is: the acquired master-slave delay data are larger than a preset seventh threshold; and switching the working mode of the database collection system to a second mode, a third mode or a fourth mode, including: acquiring current query delay data of a specific database; when the acquired query delay data is not longer than a preset first time, switching the working mode of the database integration system to a fourth mode; when the acquired query delay data is longer than the first time length: if the acquired master-slave delay data are not larger than a preset eighth threshold value, switching the working mode of the database integration system to a second mode; and if the acquired master-slave delay data are larger than an eighth threshold value, switching the working mode of the database integration system to a third mode.
Optionally, the fourth switching condition is: the obtained master-slave delay data are larger than a preset ninth threshold; and switching the working mode of the database collection system to a third mode or a fourth mode, including: acquiring current query delay data of a specific database; when the acquired query delay data is not longer than the first time, switching the working mode of the database integration system to a fourth mode; and when the acquired query delay data is longer than the first time, switching the working mode of the database collection system to a third mode.
Optionally, the fifth switching condition is: the obtained query delay data is longer than a first duration; and switching the working mode of the database collection system to a first mode, a second mode or a third mode, including: acquiring master-slave delay data of the database collection system in a first mode; when the acquired master-slave delay data are not larger than a seventh threshold value, switching the working mode of the database integration system to a first mode; when the acquired master-slave delay data are larger than a seventh threshold value and not larger than an eighth threshold value, switching the working mode of the database collection system to a second mode; and when the acquired master-slave delay data are larger than an eighth threshold value, switching the working mode of the database integration system to a third mode.
Optionally, the master database and the slave database are both MySQL, and the specific database is ElasticSearch; the master-slave delay data are delay duration data of the slave database relative to the master database; the numerical value of the query delay data is the ratio of the time consumption difference of two query requests to the number difference of the index documents of the two query requests.
To achieve the above object, according to still another aspect of the present invention, there is provided a database operation mode switching apparatus.
The switching device of the database working mode of the embodiment of the invention can be used for switching the working mode of a database system comprising a main database and a plurality of slave databases; wherein the operation modes include a first mode in which the master database and the plurality of slave databases provide services, a second mode in which the master database and one of the plurality of slave databases provide services, and a third mode in which the master database provides services alone; the apparatus may comprise: a first switching unit for: when the database system is in a first mode, acquiring current master-slave delay data; if the acquired master-slave delay data meet a preset first switching condition, switching the working mode of the database system into a second mode or a third mode; a second switching unit configured to: when the database system is in a second mode, acquiring current master-slave delay data; and if the acquired master-slave delay data meet a preset second switching condition, switching the working mode of the database system to a third mode.
To achieve the above object, according to another aspect of the present invention, there is provided a database operation mode switching device.
The switching device of the database working mode of the embodiment of the invention can be used for switching the working mode of a database collection system comprising a first database system comprising a main database and a plurality of slave databases and a specific database; wherein a type of a particular database is different from the master database and the slave database; the operation modes include a first mode in which the master database and the plurality of slave databases provide services, a second mode in which the master database and one of the plurality of slave databases provide services, a third mode in which the master database provides services alone, and a fourth mode in which a specific database provides services alone; the apparatus may comprise: a third switching unit configured to: when the database collection system is in a first mode, acquiring current master-slave delay data; if the acquired master-slave delay data meet a preset third switching condition, switching the working mode of the database integration system into a second mode, a third mode or a fourth mode; a fourth switching unit configured to: when the database collection system is in a second mode, acquiring current master-slave delay data; if the acquired master-slave delay data meet a preset fourth switching condition, switching the working mode of the database integration system into a third mode or a fourth mode; a fifth switching unit configured to: when the database collection system is in a fourth mode, acquiring current query delay data; and if the acquired query delay data meet a preset fifth switching condition, switching the working mode of the database integration system into a first mode, a second mode or a third mode.
To achieve the above object, according to still another aspect of the present invention, there is provided an electronic apparatus.
An electronic device of the present invention includes: one or more processors; and the storage device is used for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors realize the switching method of the database working mode provided by the invention.
To achieve the above object, according to still another aspect of the present invention, there is provided a computer-readable storage medium.
A computer-readable storage medium of the present invention stores thereon a computer program, which, when executed by a processor, implements the method for switching the database operating mode provided by the present invention.
According to the technical scheme of the invention, one embodiment of the invention has the following advantages or beneficial effects:
first, the method of the present invention can be used for switching the operation mode of a database system including a master database and a plurality of slave databases. In practical application, the method can automatically detect the master-slave delay data of the current working mode in real time, and compare the detected master-slave delay data with one or more preset thresholds, so that the reasonable working mode is selected to be switched according to the current delay condition. Generally, a master-slave mode can be switched to when the delay is not severe, and a master mode can be switched to when the delay is severe. In addition, the invention can also select whether to start the function of backtracking the main database according to the current delay condition. It will be appreciated that turning on the backtracking master database function can reduce latency, but can increase the access pressure on the master database.
Secondly, the method of the present invention can be also used for the switching of the operation mode of the database gathering system including the first database system including one master database and a plurality of slave databases and the specific database. In this scenario, in addition to one master multiple slave, one master one slave, one master, etc. modes of operation, the modes of operation are augmented with services provided solely by a particular database. In practical application, the invention can automatically detect the delay data of the current working mode in real time, and compare the detected delay data with one or more preset threshold values, thereby selecting a reasonable working mode to switch according to the current delay condition. Generally, if a first database system is currently used and the delay reaches a certain condition, switching to a specific database can be performed when the delay of the specific database is small; if a particular database is currently in use and the delay meets a certain condition, the corresponding mode of operation may be selected based on master-slave delay data of the first database system. Specifically, a master multi-slave mode may be selected when the master-slave latency data is small, a master-slave mode may be selected when the master-slave latency data is slightly large, and a master mode may be selected when the master-slave latency data is large. Through the arrangement, the flexible and accurate switching of the working modes of the database system can be realized according to automatic real-time delay monitoring, and various defects caused by manual monitoring and manual switching in the prior art are avoided.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
FIG. 1 is a schematic diagram of the main steps of a database operation mode switching method according to a first embodiment of the present invention;
FIG. 2 is a diagram illustrating the main steps of a method for switching the database operation modes according to a second embodiment of the present invention;
fig. 3 is a schematic diagram of a specific implementation of a method for switching the database operating modes according to a second embodiment of the present invention;
FIG. 4 is a schematic diagram of the components of a switching apparatus for the database operation mode corresponding to the method of the first embodiment of the present invention;
FIG. 5 is a schematic diagram of the components of a switching apparatus for the database operation mode corresponding to the method in the second embodiment of the present invention;
FIG. 6 is an exemplary system architecture diagram in which embodiments of the present invention may be employed;
fig. 7 is a schematic structural diagram of an electronic device for implementing a method for switching an operating mode of a database according to an embodiment of the present invention.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
In the embodiment of the invention, the working mode of the database system can be switched. In a database system comprising a plurality of databases, there may be one master database and a plurality of slave databases. In particular, the master database and the slave database are the same type of database, and may be cooperatively served (e.g., slave database for data reading, master database for data writing, and master database for data writing synchronized to the slave database). The master database is generally a quasi-real-time database, and the slave databases form a database environment identical to the master database through data synchronization. Taking MySQL as an example, the master database and the slave database are both MySQL, the basis of the intermediate data replication of the master database and the slave database is a binary log file, after the binary log is enabled by the master database, all operations in the database are recorded in the binary log in an event mode, the slave database is communicated with the master database through an I/O thread (input/output thread), the change of the binary log file of the master database is monitored, if the change of the binary log file of the master database is found, the change is replicated into a relay log of the slave database, and then a Structured Query Language (SQL) thread of the slave database executes related events into the slave database of the slave database, so that the consistency of the slave database and the master database is realized, and the master-slave replication is also realized.
It should be noted that, in the embodiment of the present invention, the two databases are of the same type, which means that both databases are the same relational database (e.g., MySQL), or the same column-based database in the non-relational database (e.g., Cassandra), or the same key-value pair database in the non-relational database (e.g., Redis), or the same document type database in the non-relational database (e.g., MongoDB), or the same graphic database in the non-relational database (e.g., Neo4 j). In addition, if one database is a relational database and the other database is a non-relational database, the two databases are different types of databases; if one database is a non-relational database (e.g., a graph database) and the other database is another non-relational database (e.g., a key-value pair database), then the two are different types of databases.
In a database system including a master database and slave databases, the operation modes may include a first mode (i.e., a master-multi-slave mode) in which the master database and the plurality of slave databases provide services, a second mode (i.e., a master-slave mode) in which the master database and one of the plurality of slave databases, which may be the best slave database among the plurality of slave databases, provide services, and a third mode (i.e., a master mode) in which the master database alone provides services. It is understood that the delay conditions of the first mode, the second mode and the third mode are sequentially reduced when the same access amount is faced, but the access pressure faced by the master database is sequentially increased, so in practical application, in the case that the delay conditions are acceptable, the first mode is preferably selected, the second mode is selected, and the third mode is selected. In the above database system, the delay condition may be indicated by master-slave delay data, which refers to delay duration data of the slave database relative to the master database, i.e. data synchronization duration data between the master database and the slave database. In a specific scenario, the value of the second _ while _ Master parameter outputted by the show slave status \ G (a command for displaying the status of the slave database) command can be monitored, and the value is the Master-slave delay data. This value may be zero or a positive number: a value of zero indicates that master-slave replication is good and that the delay is considered to be absent; a positive number indicates that a delay is present, and a larger number indicates a larger delay.
The database system may be further enabled to backtrack the primary database function while the database system is in the first mode and the second mode. Backtracking the master database means that when there is master-slave delay, the master database is queried again by using the queried data master key, thereby ensuring the correctness of the query result of the slave database. In practical applications, it is generally necessary to configure the maximum number of backtrails to avoid infinite backtrails. It will be appreciated that turning on the backtracking master database function can reduce latency, but can increase the access pressure on the master database.
The present invention can also perform switching of the operation mode of the database integration system including the above-described database system and a specific database. The specific database is different from the master database and the slave database in the database system. For example, where the master and slave databases are MySQL, the particular database may be an ElasticSearch (a search engine). It can be understood that the indexing delay of the ElasticSearch is small and the query fields are rich, and the combination of the ElasticSearch and MySQL can improve the overall performance of the database aggregation system. In the database aggregation system, in addition to the three modes described above, there is a fourth mode in which a specific database is individually served. Since the delay performance of a particular database tends to be better, it is preferable to switch to the fourth mode when the database collection system is in the first mode or the second mode and the delay condition satisfies the condition while the delay of the fourth mode is smaller. The delay condition of the fourth mode can be characterized by querying delay data, in practical applications, the value of the query delay data may be a ratio of a difference between time consumption of two query requests and a difference between number of index documents (i.e., queried documents) of the two query requests, and the time consumption of the query requests and the number of index documents may be obtained by invoking a specific interface.
It should be noted that the embodiments of the present invention and the technical features of the embodiments may be combined with each other without conflict.
Fig. 1 is a schematic diagram illustrating major steps of a method for switching database operating modes according to a first embodiment of the present invention.
As shown in fig. 1, the method for switching the database operating modes in this embodiment may be specifically executed according to the following steps:
step S101: when the database system is in a first mode, acquiring current master-slave delay data; and if the acquired master-slave delay data meet a preset first switching condition, switching the working mode of the database system into a second mode or a third mode.
In this embodiment, the database system includes one master database and a plurality of slave databases. Preferably, the value of the seconds _ while _ Master parameter in the database system may be monitored to obtain Master slave delay data. The first switching condition in this step and each switching condition to be described later can be flexibly set according to actual needs, and the present invention does not limit this. In practical applications, each switching condition is often switched to an operating mode according to a comparison result with a preset threshold. For example, the first switching condition may be: the obtained master-slave delay data are larger than a preset second threshold, and at this time, when the obtained master-slave delay data are not larger than a preset fourth threshold (the fourth threshold is larger than the second threshold) (the delay condition is slight), the working mode of the database system is switched to the second mode; and when the acquired master-slave delay data is larger than a fourth threshold (the delay condition is serious at the moment), switching the working mode of the database system into a third mode.
As a preferred scheme, the database system can turn on or turn off the function of backtracking the main database in the first mode or the second mode. Thus, if the database system is currently in the first mode and the function of backtracking the main database is closed, the current master-slave delay data is monitored in real time; and when the master-slave delay data is greater than a preset first threshold and not greater than the second threshold, starting the function of backtracking the master database. By the arrangement, master-slave delay can be reduced without switching the working modes. In addition, as mentioned above, when the monitored master-slave delay data is greater than the second threshold and not greater than the fourth threshold, the operation mode of the database system may be switched to the second mode, and at this time, the master-slave delay data may be further compared with a preset third threshold (the third threshold is greater than the second threshold and less than the fourth threshold): if the master-slave delay data is larger than a second threshold and not larger than a third threshold, switching the working mode of the database system to a second mode and closing the function of backtracking the master database; and if the master-slave delay data is greater than the third threshold and not greater than the fourth threshold, switching the working mode of the database system to the second mode and starting the backtracking master database function. It can be understood that the master-slave delay can be improved by turning on or off the function of backtracking the master database without switching the working modes of the database system, and the frequent switching of the working modes of the database system is avoided.
Step S102: when the database system is in a second mode, acquiring current master-slave delay data; and if the acquired master-slave delay data meet a preset second switching condition, switching the working mode of the database system to a third mode.
In an alternative implementation, the second switching condition may be: and the obtained master-slave delay data is larger than a preset sixth threshold, that is, if the monitored master-slave delay data of the second mode is larger than the sixth threshold, the working mode of the database system is switched to the third mode to improve the delay condition. In practical application, the function of backtracking the main database can be started when the delay condition is not serious. Specifically, when the database system is currently in the second mode and the function of backtracking the master database is closed, current master-slave delay data are monitored in real time; and if the monitored master-slave delay data is greater than a preset fifth threshold and not greater than a sixth threshold, starting the function of backtracking the master database.
In addition, in a specific scenario, the working mode of the database system can be switched by dynamically changing the configuration data of the UCC (unified configuration center), and the UCC can be implemented by ZooKeeper (a distributed application coordination service) cluster. For example, a UCC may be set with 1 as a first mode, 2 as a second mode, 3 as a third mode, 4 as a function of turning on a backtracking master database, and 5 as a function of turning off the backtracking master database, and the switching of the database system operation modes and the switching of the backtracking master database functions may be implemented by modifying the above data. The UCC and the ZooKeeper cluster can also be used for dynamically reading or modifying configuration data under the condition of not restarting the service, so that the free switching of the working mode is realized.
Fig. 2 is a schematic diagram of main steps of a method for switching database operating modes according to a second embodiment of the present invention.
The method of this embodiment can be applied to the database aggregation system described above, and in this embodiment, the master database and the slave database in the database aggregation system form the first database system. As shown in fig. 2, the method for switching the database operating modes in this embodiment may be specifically executed according to the following steps:
step S201: when the database collection system is in a first mode, acquiring current master-slave delay data; and if the acquired master-slave delay data meet a preset third switching condition, switching the working mode of the database integration system into a second mode, a third mode or a fourth mode.
Specifically, the third switching condition may be: and the acquired master-slave delay data is larger than a preset seventh threshold value. At this time, the operation mode can be switched as follows: firstly, acquiring current query delay data of a specific database; and when the acquired query delay data is not longer than the preset first time, switching the working mode of the database integration system to a fourth mode. It will be appreciated that query latency data not greater than the first time period indicates that the fourth database latency is relatively small, and therefore the mode of operation of the database gathering system is preferably switched to the fourth mode. If the acquired query delay data is greater than the first time length, which indicates that the specific database is relatively delayed and cannot be used, the monitored master-slave delay data can be compared with a preset eighth threshold (the eighth threshold is greater than the seventh threshold): if the master-slave delay data are not larger than the eighth threshold (the delay condition is slight at the moment), switching the working mode of the database integration system into the second mode; and if the acquired master-slave delay data is larger than an eighth threshold (the delay condition is serious at the moment), switching the working mode of the database integration system into a third mode.
It is understood that the delay performance of the system can be improved by turning on or off the function of the backtracking master database in the first mode or the second mode in this step, and the steps of executing the steps and the decision logic are similar to those of the first embodiment and will not be repeated here.
Step S202: when the database collection system is in a second mode, acquiring current master-slave delay data; and if the acquired master-slave delay data meet a preset fourth switching condition, switching the working mode of the database integration system into a third mode or a fourth mode.
In this step, the fourth switching condition may be that the acquired master-slave delay data is greater than a preset ninth threshold. At this time, the current query delay data of the specific database can be obtained first, and if the obtained query delay data is not greater than the first duration (which indicates that the fourth database can be used with smaller delay), the working mode of the database collection system can be switched to the fourth mode; if the obtained query delay data is longer than the first time (which indicates that the fourth database is delayed for a long time and cannot be used), the working mode of the database collection system can be switched to a third mode.
It is understood that the system delay performance can be improved by turning on the backtracking master database function in the second mode in this step, and the steps performed in this step are similar to the first embodiment, and will not be repeated here.
Step S203: when the database collection system is in a fourth mode, acquiring current query delay data; and if the acquired query delay data meet a preset fifth switching condition, switching the working mode of the database integration system into a first mode, a second mode or a third mode.
In this step, the fifth switching condition may be: the obtained query delay data is greater than the first duration. The query delay data meets the fifth switching condition, which indicates that the delay condition of the specific database is serious, and the specific database needs to be switched to a working mode in the first database system, namely, the first mode, the second mode or the third mode. The specific switching steps are as follows: acquiring master-slave delay data of a database collection system in a first mode; if the acquired master-slave delay data are not larger than a seventh threshold (the delay condition is slight at the moment), switching the working mode of the database integration system into the first mode; if the acquired master-slave delay data are larger than a seventh threshold and not larger than an eighth threshold (the delay situation is slightly serious at the moment), switching the working mode of the database collection system into a second mode; and if the acquired master-slave delay data is larger than an eighth threshold (the delay condition is serious at the moment), switching the working mode of the database integration system into a third mode. Through the steps, the dynamic switching of the working mode of the database integration system can be realized.
It is understood that the delay performance of the system can be improved by turning on or off the function of the backtracking master database in the first mode or the second mode in this step, and the steps of executing the steps and the decision logic are similar to those of the first embodiment and will not be repeated here. In addition, the method for switching the database operation modes described in the first embodiment and the second embodiment can be used in a database system composed of any database, and the present invention does not limit the types of the databases.
Fig. 3 is a schematic diagram of a specific implementation of the method for switching the database operating modes in the second embodiment of the present invention.
As shown in fig. 3, a first database system in this embodiment is built in a DB (i.e., database) cluster, a specific database in this embodiment is built in an ES (i.e., elastic search) cluster, and a delay detection end monitors master-slave delay data of the first database system through a DB delay detection agent end and monitors query delay data of the specific database through an ES delay detection agent end. According to the delay data collected by the delay detection end and the threshold value cached in advance, the configuration data in the UCC realized by the ZooKeeper cluster can be dynamically modified, and therefore the switching of the working mode of the database is realized. It is to be understood that the service side in fig. 3 has connections with the DB cluster and the ES cluster to develop services using the DB cluster and the ES cluster.
According to the technical scheme of the embodiment of the invention, the method can be used for switching the working modes of the database system comprising one master database and a plurality of slave databases. In practical application, the method can automatically detect the master-slave delay data of the current working mode in real time, and compare the detected master-slave delay data with one or more preset thresholds, so that the reasonable working mode is selected to be switched according to the current delay condition. Generally, a master-slave mode can be switched to when the delay is not severe, and a master mode can be switched to when the delay is severe. In addition, the invention can also select whether to start the function of backtracking the main database according to the current delay condition. It will be appreciated that turning on the backtracking master database function can reduce latency, but can increase the access pressure on the master database. In addition, the method of the present invention can be used for switching the operation mode of a database gathering system including a first database system including a master database and a plurality of slave databases and a specific database. In this scenario, in addition to one master multiple slave, one master one slave, one master, etc. modes of operation, the modes of operation are augmented with services provided solely by a particular database. In practical application, the invention can automatically detect the delay data of the current working mode in real time, and compare the detected delay data with one or more preset threshold values, thereby selecting a reasonable working mode to switch according to the current delay condition. Generally, if a first database system is currently used and the delay reaches a certain condition, switching to a specific database can be performed when the delay of the specific database is small; if a particular database is currently in use and the delay meets a certain condition, the corresponding mode of operation may be selected based on master-slave delay data of the first database system. Specifically, a master multi-slave mode may be selected when the master-slave latency data is small, a master-slave mode may be selected when the master-slave latency data is slightly large, and a master mode may be selected when the master-slave latency data is large. Through the arrangement, the flexible and accurate switching of the working modes of the database system can be realized according to automatic real-time delay monitoring, and various defects caused by manual monitoring and manual switching in the prior art are avoided.
It should be noted that, for the convenience of description, the foregoing method embodiments are described as a series of acts, but those skilled in the art will appreciate that the present invention is not limited by the order of acts described, and that some steps may in fact be performed in other orders or concurrently. Moreover, those skilled in the art will appreciate that the embodiments described in the specification are presently preferred and that no acts or modules are necessarily required to implement the invention.
To facilitate a better implementation of the above-described aspects of embodiments of the present invention, the following also provides relevant means for implementing the above-described aspects.
Referring to fig. 4, a switching apparatus 400 for operating modes of a database corresponding to the method of the first embodiment of the present invention may be used to switch operating modes of a database system including a master database and a plurality of slave databases; wherein the operation modes may include a first mode in which the master database and the plurality of slave databases provide services, a second mode in which the master database and one of the plurality of slave databases provide services, and a third mode in which the master database provides services separately. The switching device 400 for the database operation mode may include: a first switching unit 401 and a second switching unit 402.
Wherein, the first switching unit 401 may be configured to: when the database system is in a first mode, acquiring current master-slave delay data; if the acquired master-slave delay data meet a preset first switching condition, switching the working mode of the database system into a second mode or a third mode; the second switching unit 402 may be configured to: when the database system is in a second mode, acquiring current master-slave delay data; and if the acquired master-slave delay data meet a preset second switching condition, switching the working mode of the database system to a third mode.
In an alternative implementation, the first switching condition is: the acquired master-slave delay data are larger than a preset second threshold; the first switching unit 401 may further be configured to: when the acquired master-slave delay data are not larger than a preset fourth threshold value, switching the working mode of the database system to a second mode; wherein the fourth threshold is greater than the second threshold; and when the acquired master-slave delay data is larger than a fourth threshold value, switching the working mode of the database system to a third mode.
In practical application, the database system can open or close the function of backtracking the main database in a first mode; the first switching unit 401 may further be configured to: when the database system is in a first mode and the function of backtracking a main database is closed, acquiring current master-slave delay data; and if the acquired master-slave delay data is greater than a preset first threshold and not greater than a second threshold, starting a backtracking master database function.
In a specific application scenario, the database system can open or close the function of the backtracking main database in the second mode; the first switching unit 401 may further be configured to: when the obtained master-slave delay data are larger than a second threshold and not larger than a preset third threshold, switching the working mode of the database system to a second mode and closing the function of backtracking the master database; wherein the third threshold is less than the fourth threshold; and when the acquired master-slave delay data is greater than a third threshold and not greater than a fourth threshold, switching the working mode of the database system to a second mode and starting a backtracking master database function.
As a preferred scheme, the database system can open or close the function of the backtracking main database in the second mode, and the second switching condition is as follows: the acquired master-slave delay data are larger than a preset sixth threshold; and, the second switching unit 402 may be further configured to: when the database system is in a second mode and the function of backtracking the main database is closed, acquiring current master-slave delay data; and if the acquired master-slave delay data is greater than a preset fifth threshold and not greater than a sixth threshold, starting a backtracking master database function.
In addition, in the embodiment of the present invention, the master-slave delay data is delay duration data of a slave database relative to a master database, and the master database and the slave database are both MySQL.
Fig. 5 is a schematic diagram of a part of a switching device for switching the database operation mode according to a method in a second embodiment of the present invention.
As shown in fig. 5, the switching apparatus 500 of the database operation mode according to the embodiment of the present invention may be used to perform switching of the operation mode of the database gathering system including a first database system including one master database and a plurality of slave databases and a specific database; wherein a type of a particular database is different from the master database and the slave database; the operation modes include a first mode in which the master database and the plurality of slave databases provide services, a second mode in which the master database and one of the plurality of slave databases provide services, a third mode in which the master database provides services alone, and a fourth mode in which a specific database provides services alone. The switching apparatus 500 for the database operation mode may include a third switching unit 501, a fourth switching unit 502, and a fifth switching unit 503.
The third switching unit 501 may be configured to: when the database collection system is in a first mode, acquiring current master-slave delay data; if the acquired master-slave delay data meet a preset third switching condition, switching the working mode of the database integration system into a second mode, a third mode or a fourth mode; the fourth switching unit 502 may be configured to: when the database collection system is in a second mode, acquiring current master-slave delay data; if the acquired master-slave delay data meet a preset fourth switching condition, switching the working mode of the database integration system into a third mode or a fourth mode; the fifth switching unit 503 is configured to: when the database collection system is in a fourth mode, acquiring current query delay data; and if the acquired query delay data meet a preset fifth switching condition, switching the working mode of the database integration system into a first mode, a second mode or a third mode.
In the embodiment of the present invention, the third switching condition is: the acquired master-slave delay data are larger than a preset seventh threshold; the third switching unit 501 may be further configured to: acquiring current query delay data of a specific database; when the acquired query delay data is not longer than a preset first time, switching the working mode of the database integration system to a fourth mode; when the acquired query delay data is longer than the first time length: if the acquired master-slave delay data are not larger than a preset eighth threshold value, switching the working mode of the database integration system to a second mode; and if the acquired master-slave delay data are larger than an eighth threshold value, switching the working mode of the database integration system to a third mode.
In a specific application, the fourth switching condition is as follows: the obtained master-slave delay data are larger than a preset ninth threshold; the fourth switching unit 502 may be further configured to: acquiring current query delay data of a specific database; when the acquired query delay data is not longer than the first time, switching the working mode of the database integration system to a fourth mode; and when the acquired query delay data is longer than the first time, switching the working mode of the database collection system to a third mode.
In an actual application scenario, the fifth switching condition is: the obtained query delay data is longer than a first duration; the fifth switching unit 503 may be further configured to: acquiring master-slave delay data of the database collection system in a first mode; when the acquired master-slave delay data are not larger than a seventh threshold value, switching the working mode of the database integration system to a first mode; when the acquired master-slave delay data are larger than a seventh threshold value and not larger than an eighth threshold value, switching the working mode of the database collection system to a second mode; and when the acquired master-slave delay data are larger than an eighth threshold value, switching the working mode of the database integration system to a third mode.
Furthermore, in the embodiment of the present invention, both the master database and the slave database are MySQL, and the specific database is ElasticSearch; the master-slave delay data are delay duration data of the slave database relative to the master database; the numerical value of the query delay data is the ratio of the time consumption difference of two query requests to the number difference of the index documents of the two query requests.
According to the technical scheme of the embodiment of the invention, the device can be used for switching the working modes of a database system comprising a master database and a plurality of slave databases. In practical application, the method can automatically detect the master-slave delay data of the current working mode in real time, and compare the detected master-slave delay data with one or more preset thresholds, so that the reasonable working mode is selected to be switched according to the current delay condition. Generally, a master-slave mode can be switched to when the delay is not severe, and a master mode can be switched to when the delay is severe. In addition, the invention can also select whether to start the function of backtracking the main database according to the current delay condition. It will be appreciated that turning on the backtracking master database function can reduce latency, but can increase the access pressure on the master database. In addition, the apparatus of the present invention can be used for switching the operation mode of a database gathering system including a first database system including one master database and a plurality of slave databases and a specific database. In this scenario, in addition to one master multiple slave, one master one slave, one master, etc. modes of operation, the modes of operation are augmented with services provided solely by a particular database. In practical application, the invention can automatically detect the delay data of the current working mode in real time, and compare the detected delay data with one or more preset threshold values, thereby selecting a reasonable working mode to switch according to the current delay condition. Generally, if a first database system is currently used and the delay reaches a certain condition, switching to a specific database can be performed when the delay of the specific database is small; if a particular database is currently in use and the delay meets a certain condition, the corresponding mode of operation may be selected based on master-slave delay data of the first database system. Specifically, a master multi-slave mode may be selected when the master-slave latency data is small, a master-slave mode may be selected when the master-slave latency data is slightly large, and a master mode may be selected when the master-slave latency data is large. Through the arrangement, the flexible and accurate switching of the working modes of the database system can be realized according to automatic real-time delay monitoring, and various defects caused by manual monitoring and manual switching in the prior art are avoided.
Fig. 6 shows an exemplary system architecture 600 of a switching method of a database operation mode or a switching device of a database operation mode to which an embodiment of the present invention may be applied.
As shown in fig. 6, the system architecture 600 may include terminal devices 601, 602, 603, a network 604 and a server 605 (this architecture is merely an example, and the components included in a specific architecture may be adjusted according to the specific application). The network 604 serves to provide a medium for communication links between the terminal devices 601, 602, 603 and the server 605. Network 604 may include various types of connections, such as wire, wireless communication links, or fiber optic cables, to name a few.
A user may use the terminal devices 601, 602, 603 to interact with the server 605 via the network 604 to receive or send messages or the like. Various client applications, such as an application for switching database operation modes, etc. (for example only), may be installed on the terminal devices 601, 602, 603.
The terminal devices 601, 602, 603 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 605 may be a server providing various services, such as a background server (for example only) providing support for applications operated by users with the terminal devices 601, 602, 603 for switching database operation modes. The backend server may process the received operation mode switching request and feed back the processing result (e.g. the determined reasonable operation mode-just an example) to the terminal device 601, 602, 603.
It should be noted that the method for switching the database operation mode provided in the embodiment of the present invention is generally executed by the server 605, and accordingly, the means for switching the database operation mode is generally disposed in the server 605.
It should be understood that the number of terminal devices, networks, and servers in fig. 6 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
The invention also provides the electronic equipment. The electronic device of the embodiment of the invention comprises: one or more processors; and the storage device is used for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors realize the switching method of the database working mode provided by the invention.
Referring now to FIG. 7, shown is a block diagram of a computer system 700 suitable for use with the electronic device implementing an embodiment of the present invention. The electronic device shown in fig. 7 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present invention.
As shown in fig. 7, the computer system 700 includes a Central Processing Unit (CPU)701, which can perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)702 or a program loaded from a storage section 708 into a Random Access Memory (RAM) 703. In the RAM703, various programs and data necessary for the operation of the computer system 700 are also stored. The CPU701, the ROM 702, and the RAM703 are connected to each other via a bus 704. An input/output (I/O) interface 705 is also connected to bus 704.
The following components are connected to the I/O interface 705: an input portion 706 including a keyboard, a mouse, and the like; an output section 707 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage section 708 including a hard disk and the like; and a communication section 709 including a network interface card such as a LAN card, a modem, or the like. The communication section 709 performs communication processing via a network such as the internet. A drive 710 is also connected to the I/O interface 705 as needed. A removable medium 711 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 710 as necessary, so that a computer program read out therefrom is mounted into the storage section 708 as necessary.
In particular, the processes described in the main step diagrams above may be implemented as computer software programs, according to embodiments of the present disclosure. For example, embodiments of the invention include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the main step diagram. In the above-described embodiment, the computer program can be downloaded and installed from a network through the communication section 709, and/or installed from the removable medium 711. The computer program, when executed by the central processing unit 701, performs the above-described functions defined in the system of the present invention.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: 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 the present invention, 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. In the present invention, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. 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.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units described in the embodiments of the present invention may be implemented by software or hardware. The described units may also be provided in a processor, and may be described as: a processor includes a first switching unit and a second switching unit. Where the names of the units do not in some cases constitute a limitation on the units themselves, for example, the first switching unit may also be described as a "unit for performing switching of the first mode to another mode".
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by the apparatus, cause the apparatus to perform steps comprising: when the database system is in a first mode, acquiring current master-slave delay data; if the acquired master-slave delay data meet a preset first switching condition, switching the working mode of the database system into a second mode or a third mode; or when the database system is in the second mode, acquiring current master-slave delay data; and if the acquired master-slave delay data meet a preset second switching condition, switching the working mode of the database system to a third mode.
According to the technical scheme of the embodiment of the invention, the method can be used for switching the working modes of the database system comprising one master database and a plurality of slave databases. In practical application, the method can automatically detect the master-slave delay data of the current working mode in real time, and compare the detected master-slave delay data with one or more preset thresholds, so that the reasonable working mode is selected to be switched according to the current delay condition. Generally, a master-slave mode can be switched to when the delay is not severe, and a master mode can be switched to when the delay is severe. In addition, the invention can also select whether to start the function of backtracking the main database according to the current delay condition. It will be appreciated that turning on the backtracking master database function can reduce latency, but can increase the access pressure on the master database. In addition, the method of the present invention can be used for switching the operation mode of a database gathering system including a first database system including a master database and a plurality of slave databases and a specific database. In this scenario, in addition to one master multiple slave, one master one slave, one master, etc. modes of operation, the modes of operation are augmented with services provided solely by a particular database. In practical application, the invention can automatically detect the delay data of the current working mode in real time, and compare the detected delay data with one or more preset threshold values, thereby selecting a reasonable working mode to switch according to the current delay condition. Generally, if a first database system is currently used and the delay reaches a certain condition, switching to a specific database can be performed when the delay of the specific database is small; if a particular database is currently in use and the delay meets a certain condition, the corresponding mode of operation may be selected based on master-slave delay data of the first database system. Specifically, a master multi-slave mode may be selected when the master-slave latency data is small, a master-slave mode may be selected when the master-slave latency data is slightly large, and a master mode may be selected when the master-slave latency data is large. Through the arrangement, the flexible and accurate switching of the working modes of the database system can be realized according to automatic real-time delay monitoring, and various defects caused by manual monitoring and manual switching in the prior art are avoided.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (15)

1. A switching method of database working mode is used for switching the working mode of a database system comprising a main database and a plurality of slave databases; wherein the operation modes include a first mode in which the master database and the plurality of slave databases provide services, a second mode in which the master database and one of the plurality of slave databases provide services, and a third mode in which the master database provides services alone;
characterized in that the method comprises:
when the database system is in the first mode, acquiring current master-slave delay data; if the acquired master-slave delay data meet a preset first switching condition, switching the working mode of the database system to the second mode or the third mode; or
When the database system is in the second mode, acquiring current master-slave delay data; and if the acquired master-slave delay data meet a preset second switching condition, switching the working mode of the database system to the third mode.
2. The method according to claim 1, characterized in that the first switching condition is: the acquired master-slave delay data are larger than a preset second threshold; and switching the operating mode of the database system to the second mode or the third mode includes:
when the acquired master-slave delay data are not larger than a preset fourth threshold value, switching the working mode of the database system to the second mode; wherein the fourth threshold is greater than the second threshold;
and when the acquired master-slave delay data is larger than a fourth threshold value, switching the working mode of the database system to the third mode.
3. The method of claim 2, wherein the database system can turn back master database functions on or off in the first mode; and, the method further comprises:
when the database system is in the first mode and the function of backtracking a main database is closed, acquiring current master-slave delay data; and if the acquired master-slave delay data is greater than a preset first threshold and not greater than a second threshold, starting a backtracking master database function.
4. The method of claim 2, wherein the database system can turn back master database functions on or off in the second mode; and when the acquired master-slave delay data are not greater than a preset fourth threshold, switching the working mode of the database system to the second mode, including:
when the obtained master-slave delay data are larger than a second threshold and not larger than a preset third threshold, switching the working mode of the database system to the second mode and closing the function of backtracking a master database; wherein the third threshold is less than the fourth threshold;
and when the acquired master-slave delay data is greater than a third threshold and not greater than a fourth threshold, switching the working mode of the database system to the second mode and starting a backtracking master database function.
5. The method of claim 1, wherein the database system can turn back master database functions on or off in the second mode, and wherein a second switching condition is: the acquired master-slave delay data are larger than a preset sixth threshold; and, the method further comprises:
when the database system is in the second mode and the function of backtracking a main database is closed, acquiring current master-slave delay data; and if the acquired master-slave delay data is greater than a preset fifth threshold and not greater than a sixth threshold, starting a backtracking master database function.
6. The method according to any of claims 1-5, wherein the master-slave delay data is delay duration data of a slave database relative to a master database, and wherein the master database and the slave database are both MySQL.
7. A switching method of an operation mode of a database for performing switching of an operation mode of a database gathering system including a first database system including a master database and a plurality of slave databases and a specific database; wherein a type of a particular database is different from the master database and the slave database; the operation modes include a first mode in which the master database and the plurality of slave databases provide services, a second mode in which the master database and one of the plurality of slave databases provide services, a third mode in which the master database provides services alone, and a fourth mode in which a specific database provides services alone;
characterized in that the method comprises:
when the database collection system is in the first mode, acquiring current master-slave delay data; if the acquired master-slave delay data meet a preset third switching condition, switching the working mode of the database integration system to the second mode, the third mode or the fourth mode;
or when the database collection system is in the second mode, acquiring current master-slave delay data; if the acquired master-slave delay data meet a preset fourth switching condition, switching the working mode of the database integration system to the third mode or the fourth mode; or
When the database collection system is in the fourth mode, acquiring current query delay data; and if the acquired query delay data meet a preset fifth switching condition, switching the working mode of the database integration system into the first mode, the second mode or the third mode.
8. The method of claim 7, wherein the third handover condition is: the acquired master-slave delay data are larger than a preset seventh threshold; and switching the operating mode of the database collection system to the second mode, the third mode, or the fourth mode includes:
acquiring current query delay data of a specific database; when the acquired query delay data is not longer than a preset first time, switching the working mode of the database collection system to the fourth mode;
when the acquired query delay data is longer than the first time length: if the acquired master-slave delay data are not larger than a preset eighth threshold value, switching the working mode of the database integration system to the second mode; and if the acquired master-slave delay data is larger than an eighth threshold value, switching the working mode of the database integration system to the third mode.
9. The method of claim 8, wherein the fourth switching condition is: the obtained master-slave delay data are larger than a preset ninth threshold; and switching the working mode of the database collection system to the third mode or the fourth mode includes:
acquiring current query delay data of a specific database;
when the acquired query delay data is not longer than the first time, switching the working mode of the database collection system to the fourth mode; and when the acquired query delay data is longer than the first time, switching the working mode of the database collection system to the third mode.
10. The method according to claim 9, characterized in that the fifth switching condition is: the obtained query delay data is longer than a first duration; and switching the operating mode of the database collection system to the first mode, the second mode, or the third mode includes:
acquiring master-slave delay data of the database collection system in the first mode;
when the acquired master-slave delay data are not larger than a seventh threshold value, switching the working mode of the database integration system to the first mode;
when the acquired master-slave delay data are larger than a seventh threshold value and not larger than an eighth threshold value, switching the working mode of the database collection system to the second mode;
and when the acquired master-slave delay data is larger than an eighth threshold value, switching the working mode of the database integration system to the third mode.
11. The method according to any one of claims 7 to 10,
the master database and the slave database are both MySQL, and the specific database is ElasticSearch;
the master-slave delay data are delay duration data of the slave database relative to the master database;
the numerical value of the query delay data is the ratio of the time consumption difference of two query requests to the number difference of the index documents of the two query requests.
12. A switching device of database working mode is used for switching the working mode of a database system comprising a main database and a plurality of slave databases; wherein the operation modes include a first mode in which the master database and the plurality of slave databases provide services, a second mode in which the master database and one of the plurality of slave databases provide services, and a third mode in which the master database provides services alone;
characterized in that the device comprises:
a first switching unit for: when the database system is in the first mode, acquiring current master-slave delay data; if the acquired master-slave delay data meet a preset first switching condition, switching the working mode of the database system to the second mode or the third mode;
a second switching unit configured to: when the database system is in the second mode, acquiring current master-slave delay data; and if the acquired master-slave delay data meet a preset second switching condition, switching the working mode of the database system to the third mode.
13. A switching apparatus of an operation mode of a database for performing switching of an operation mode of a database gathering system including a first database system including a master database and a plurality of slave databases and a specific database; wherein a type of a particular database is different from the master database and the slave database; the operation modes include a first mode in which the master database and the plurality of slave databases provide services, a second mode in which the master database and one of the plurality of slave databases provide services, a third mode in which the master database provides services alone, and a fourth mode in which a specific database provides services alone;
characterized in that the device comprises:
a third switching unit configured to: when the database collection system is in the first mode, acquiring current master-slave delay data; if the acquired master-slave delay data meet a preset third switching condition, switching the working mode of the database integration system to the second mode, the third mode or the fourth mode;
a fourth switching unit configured to: when the database collection system is in the second mode, acquiring current master-slave delay data; if the acquired master-slave delay data meet a preset fourth switching condition, switching the working mode of the database integration system to the third mode or the fourth mode;
a fifth switching unit configured to: when the database collection system is in the fourth mode, acquiring current query delay data; and if the acquired query delay data meet a preset fifth switching condition, switching the working mode of the database integration system into the first mode, the second mode or the third mode.
14. An electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-11.
15. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-11.
CN202010107810.2A 2020-02-21 2020-02-21 Database working mode switching method and device Active CN113297002B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010107810.2A CN113297002B (en) 2020-02-21 2020-02-21 Database working mode switching method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010107810.2A CN113297002B (en) 2020-02-21 2020-02-21 Database working mode switching method and device

Publications (2)

Publication Number Publication Date
CN113297002A true CN113297002A (en) 2021-08-24
CN113297002B CN113297002B (en) 2023-12-05

Family

ID=77317490

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010107810.2A Active CN113297002B (en) 2020-02-21 2020-02-21 Database working mode switching method and device

Country Status (1)

Country Link
CN (1) CN113297002B (en)

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2016173179A1 (en) * 2015-04-29 2016-11-03 中兴通讯股份有限公司 Method and device for switching primary database and secondary database
CN109388630A (en) * 2018-09-29 2019-02-26 北京京东金融科技控股有限公司 Database switching method, system, electronic equipment and computer-readable medium
CN110413685A (en) * 2019-04-12 2019-11-05 财付通支付科技有限公司 Database service switching method, device, readable storage medium storing program for executing and computer equipment

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2016173179A1 (en) * 2015-04-29 2016-11-03 中兴通讯股份有限公司 Method and device for switching primary database and secondary database
CN109388630A (en) * 2018-09-29 2019-02-26 北京京东金融科技控股有限公司 Database switching method, system, electronic equipment and computer-readable medium
CN110413685A (en) * 2019-04-12 2019-11-05 财付通支付科技有限公司 Database service switching method, device, readable storage medium storing program for executing and computer equipment

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
张旭刚;李东辉;俞俊;朱广新;郑磊;: "基于Zookeeper框架实现MySQL分布式数据库集群", 计算机与数字工程, no. 09 *

Also Published As

Publication number Publication date
CN113297002B (en) 2023-12-05

Similar Documents

Publication Publication Date Title
US11663242B2 (en) Mass insertion into single-threaded databases
EP2948875B1 (en) Method and system for using a recursive event listener on a node in hierarchical data structure
CN109245908B (en) Method and device for switching master cluster and slave cluster
CN111190888A (en) Method and device for managing graph database cluster
US10878006B2 (en) Systems to interleave search results and related methods therefor
CN110543512B (en) Information synchronization method, device and system
CN113193947B (en) Method, apparatus, medium, and program product for implementing distributed global ordering
CN108363741B (en) Big data unified interface method, device, equipment and storage medium
US10331484B2 (en) Distributed data platform resource allocator
CN115495473A (en) Database query method and device, electronic equipment and storage medium
CN112860343A (en) Configuration changing method, system, device, electronic equipment and storage medium
CN112181942A (en) Time sequence database system and data processing method and device
CN113297002B (en) Database working mode switching method and device
CN109271266A (en) Document transmission method, device and terminal device
CN115629909A (en) Service data processing method and device, electronic equipment and storage medium
CN114756301A (en) Log processing method, device and system
CN113297516A (en) Customer interaction interface generation method and device and electronic equipment
CN110879818B (en) Method, device, medium and electronic equipment for acquiring data
CN114945026A (en) Data processing method, device and system
CN114374703A (en) Method, device and equipment for acquiring cloud mobile phone information and storage medium
CN108984431B (en) Method and apparatus for flushing stale caches
CN110807058B (en) Method and system for exporting data
CN110727694A (en) Data processing method and device, electronic equipment and storage medium
CN110851192A (en) Method and device for responding to configuration of degraded switch
CN111459981A (en) Query task processing method, device, server and system

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
GR01 Patent grant
GR01 Patent grant