CN113761075A - Method, device, equipment and computer readable medium for switching databases - Google Patents

Method, device, equipment and computer readable medium for switching databases Download PDF

Info

Publication number
CN113761075A
CN113761075A CN202010904689.6A CN202010904689A CN113761075A CN 113761075 A CN113761075 A CN 113761075A CN 202010904689 A CN202010904689 A CN 202010904689A CN 113761075 A CN113761075 A CN 113761075A
Authority
CN
China
Prior art keywords
master library
instance
global transaction
database
library
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
CN202010904689.6A
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.)
Beijing Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun 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 Century Trading Co Ltd, Beijing Wodong Tianjun Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN202010904689.6A priority Critical patent/CN113761075A/en
Publication of CN113761075A publication Critical patent/CN113761075A/en
Pending legal-status Critical Current

Links

Images

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/28Databases characterised by their database models, e.g. relational or object models
    • G06F16/284Relational databases
    • 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/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor

Landscapes

  • Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a method, a device, equipment and a computer readable medium for switching databases, and relates to the technical field of computers. One embodiment of the method comprises: taking the latest instance in the database cluster as a new master database; determining the global transaction identifier of the non-master library instance in the database cluster according to the global transaction identifier of the new master library; and according to the global transaction identifier of the non-master library instance, mounting the non-master library instance to the new master library to complete database switching. The implementation mode can ensure that the database provides services normally.

Description

Method, device, equipment and computer readable medium for switching databases
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method, an apparatus, a device, and a computer-readable medium for switching databases.
Background
MySQL is a relational database management system, one of the most popular. Relational databases maintain data in different tables rather than placing all data in one large repository, which increases speed and flexibility.
In the process of implementing the invention, the inventor finds that at least the following problems exist in the prior art: when the MySQL database is switched, the database service cannot be provided frequently.
Disclosure of Invention
In view of this, embodiments of the present invention provide a method, an apparatus, a device, and a computer readable medium for switching a database, which can ensure that the database normally provides services.
To achieve the above object, according to an aspect of an embodiment of the present invention, there is provided a method for switching a database, including:
taking the latest instance in the database cluster as a new master database;
determining the global transaction identifier of the non-master library instance in the database cluster according to the global transaction identifier of the new master library;
and according to the global transaction identifier of the non-master library instance, mounting the non-master library instance to the new master library to complete database switching.
In the event of a failure of a master repository in the database cluster,
the step of using the latest instance in the database cluster as a new master library comprises the following steps:
screening primary selection examples from all the survival examples of the database cluster based on date;
and determining the latest instance according to the date from the initially selected instance and the user-selected instance, and taking the determined instance as a new master library.
In the case of online switching of databases in the database cluster,
the step of using the latest instance in the database cluster as a new master library comprises the following steps:
screening out the primary selection examples according to the date and the binlog log of the old master library;
and in the initially selected examples and the examples selected by the user, determining the latest examples according to dates, and taking the determined examples as a new master library.
Determining the global transaction identifier of the non-master library instance in the database cluster according to the global transaction identifier of the new master library, including:
and determining the global transaction identifier of the non-master library instance in the database cluster according to the global transaction identifier of the new master library and the global transaction identifier of the old master library.
Determining the global transaction identifier of the non-master library instance in the database cluster according to the global transaction identifier of the old master library and the global transaction identifier of the new master library, wherein the determining comprises the following steps:
acquiring the universal unique identification code of the old master library from the global transaction identifier of the old master library, and acquiring the universal unique identification code of the new master library from the global transaction identifier of the new master library;
constructing a first identifier according to the universal unique identification code of the old master library and the binlog locus of the old master library in the old global transaction identifier of the non-master library instance;
constructing a second identifier according to the universal unique identification code of the new master library and the binlog locus of the new master library;
and combining the first identification and the second identification to obtain a global transaction identification of the non-master database instance in the database cluster.
In the case of online switching of databases in the database cluster,
after the non-master library instance is mounted on the new master library according to the global transaction identifier of the non-master library instance, the method further includes:
and determining the global transaction identifier of the old master library according to the global transaction identifier of the new master library.
The step of using the latest instance in the database cluster as a new master library comprises the following steps:
and when the main library in the database cluster fails or the databases in the database cluster are switched online, taking the latest instance in the database cluster as a new main library.
According to a second aspect of the embodiments of the present invention, there is provided an apparatus for switching a database, including:
the screening module is used for taking the latest instance in the database cluster as a new master database;
the identification module is used for determining the global transaction identification of the non-master library instance in the database cluster according to the global transaction identification of the new master library;
and the switching module is used for mounting the non-master library instance to the new master library according to the global transaction identifier of the non-master library instance so as to complete database switching.
According to a third aspect of the embodiments of the present invention, there is provided an electronic device for switching databases, including:
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 as described above.
According to a fourth aspect of embodiments of the present invention, there is provided a computer readable medium, on which a computer program is stored, which when executed by a processor, implements the method as described above.
One embodiment of the above invention has the following advantages or benefits: taking the latest instance in the database cluster as a new master database; determining the global transaction identifier of the non-master library instance in the database cluster according to the global transaction identifier of the new master library; and according to the global transaction identifier of the non-master library instance, mounting the non-master library instance to the new master library to complete database switching. When the database is switched, the global transaction identifiers of other examples can be determined according to the global transaction identifier of the new main library, and then the other examples are mounted in the new main library to complete the switching of the database, so that the database can be ensured to normally provide services.
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 a main flow of a method of switching databases according to an embodiment of the present invention;
FIG. 2 is a schematic flow chart illustrating the determination of a new master library upon a master library failure, according to an embodiment of the present invention;
FIG. 3 is a flow diagram illustrating the determination of a new master library at online switching according to an embodiment of the present invention;
FIG. 4 is a flow diagram of determining a global transaction identification for a non-master library instance in a database cluster, according to an embodiment of the invention;
fig. 5 is a schematic diagram of a main structure of an apparatus for switching a database according to an 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 block diagram of a computer system suitable for use in implementing a terminal device or server of an embodiment of the 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.
With the upgrading improvement of MySQL technology, GTID technology is started from MySQL5.6, and GTID mode is started by default from MySQL5.7. GTID is the global transaction identifier (global transaction identifier), which actually consists of UUID + TID.
The UUID is a unique identifier of a MySQL instance. The TID represents the number of transactions that have committed on the instance and monotonically increases as the transactions commit, so the GTID can guarantee the execution of each MySQL instance transaction, i.e., the same transaction will not be executed repeatedly and the unexecuted transactions will be completed. In embodiments of the invention, the TID may also be referred to as binlog site.
When the GTID of one or more slave library instances in the cluster is inconsistent with the GTID of the master library instance, switching the databases may cause a single point of the cluster, that is, only one instance of the cluster provides services. If this single point instance also fails, then the database service cannot be provided and the user will not be able to use the application.
In order to solve the technical problem that database service cannot be provided frequently, the following technical scheme in the embodiment of the present invention may be adopted.
Referring to fig. 1, fig. 1 is a schematic diagram of a main flow of a method for switching a database according to an embodiment of the present invention, which determines a global transaction identifier of a non-master library instance in a database cluster according to a global transaction identifier of a new master library, and further mounts the non-master library instance to the new master library. As shown in fig. 1, the method specifically comprises the following steps:
and S101, taking the latest instance in the database cluster as a new master database.
The database cluster comprises a plurality of instances, one of the instances serves as a master library, and the rest of the instances serve as slave libraries, so that the purposes of data backup and load balancing are achieved.
As an example, a database cluster includes 4 instances, instance a, instance B, instance C, and instance D, respectively. Example a is the master library and the others are the slave libraries. All database operation requests go through instance A to reach instance B, instance C and instance D.
When instance a receives a request, it first determines whether the request is a query operation or an update operation. When the query request is found, load balancing operation is carried out, so that a user can quickly obtain a query result; when the discovery is an update operation, multiple message transfers between the master and slave are required to maintain data synchronization.
In the embodiment of the present invention, a database is switched, and specifically, when a master library in a database cluster fails, an old master library cannot work normally, and a slave library needs to be selected as a new master library. In addition, when the databases in the database cluster are switched online, the old master library needs to be switched to the new master library. In any case, the present invention is applicable to the technical solutions in the embodiments of the present invention.
It will be appreciated that in the event of a failure of the master library in the database cluster, or in the event of an online switch of databases in the database cluster, the most recent instance in the database cluster will be used as the new master library.
The latest instance in the database cluster refers to the latest instance in the database cluster from time to time. As an example, a database cluster includes 3 instances, instance A, instance B, and instance C, respectively. The set-up time for example a was 1 month, 1 day, 15 points; the set-up time for example B was 16 points 1 month, 1 day; the set-up time for instance C is 1 month, 1 day, 17 o' clock, then instance C is the most recent instance in time.
Considering that an instance-based GTID switch database is required, all instances in a database cluster are checked for GTIDs on before switching the database. If the GTID is not opened by any instance, the GTID can be opened by sending an instruction.
In the embodiment of the invention, under the condition of switching the database, a new master library needs to be determined again, and the latest instance in the database cluster can be used as the new master library. The step of re-determining the new master library is different for different application scenarios. The following description is made for two application scenarios of main library failure and online switching, respectively, with reference to the accompanying drawings.
Referring to fig. 2, fig. 2 is a schematic flowchart of a process for determining a new master library when a master library fails according to an embodiment of the present invention, which specifically includes:
s201, screening out primary selection examples from all the survival examples of the database cluster based on the date.
Due to the old master library failure, a new master library needs to be determined. Multiple instances are included in the database cluster, and primary instances can be screened out of all surviving instances.
In particular, a primary selection instance may be screened out of all surviving instances of a database cluster based on date. Illustratively, each instance has a corresponding GTID, with a larger binlog site in the GTID representing a newer date for that instance. Then, the survival case corresponding to the largest binlog site can be used as an initial selection case.
S202, determining the latest instance from the initially selected instance and the instance selected by the user according to the date to serve as a new master library.
It is understood that the initial selection example is a date-based selection example in the database switching process. In embodiments of the present invention, the user may also select an instance. Such as: the user selects an instance through the page.
Then, it is necessary to determine the latest instance as a new master library according to the date, in the initially selected instance and the user-selected instance.
As an example, the most recent instance may be determined as the new master library from the binlog sites, both in the initial selection instance and the user-selected instance. If the binlog site of the initially selected instance is the same as the binlog site of the user-selected instance, then a better hardware instance may be selected.
In the embodiment of FIG. 2, in the event of a master library failure, the newest instance from all surviving instances in the database cluster may be determined as the new master library.
Referring to fig. 3, fig. 3 is a schematic flowchart of determining a new master library during online switching according to an embodiment of the present invention, which specifically includes:
s301, screening out the primary selection examples according to the date and the binlog log of the old master library.
Since the master library needs to be switched online, the old master library has a corresponding binlog log. And screening out the primary selection examples according to the date and the binlog log of the old master library. Wherein, the binlog Log comprises a Relay _ Master _ Log _ File and an Exec _ Master _ Log _ Pos.
Illustratively, each instance has a corresponding GTID, with a larger binlog site in the GTID representing a newer date for that instance. Then, the example corresponding to the largest binlog site can be used as an initial selection example.
S302, determining the latest instance from the initially selected instance and the instance selected by the user according to the date to serve as a new master library.
It is understood that the initial selection example is a date-based selection example in the database switching process. In embodiments of the present invention, the user may also select an instance. Such as: the user selects an instance through the page.
Then, it is necessary to determine the latest instance as a new master library according to the date, in the initially selected instance and the user-selected instance.
As an example, the most recent instance may be determined as the new master library from the binlog sites, both in the initial selection instance and the user-selected instance. If the binlog site of the initially selected instance is the same as the binlog site of the user-selected instance, then a better hardware instance may be selected.
In the embodiment of fig. 3, in the case of online switching, the newest instance may be determined as the new master library from the date and the binlog log of the old master library, and the user-selected instance.
And S102, determining the global transaction identifier of the non-master library instance in the database cluster according to the global transaction identifier of the new master library.
The database needs to be switched due to the inconsistency of the GTID of the slave repository instance with the GTID of the master repository instance. Thus, upon determining the new master repository, the GTID of the non-master repository instance in the database cluster may be determined based on the GTID of the new master repository. Wherein the non-master library instances comprise instances in the database cluster that are not old master libraries and not new master libraries.
In one embodiment of the invention, the GTID of a non-master repository instance in a database cluster may be determined based on the GTID of the new master repository and the GTID of the old master repository. That is, the GTID of the non-master library instance is not only related to the GTID of the new master library, but also to the GTID of the old master library.
Referring to fig. 4, fig. 4 is a schematic flowchart of a process of determining a global transaction identifier of a non-master library instance in a database cluster according to an embodiment of the present invention, which specifically includes:
s401, acquiring the universal unique identification code of the old master library from the global transaction identification of the old master library, and acquiring the universal unique identification code of the new master library from the global transaction identification of the new master library.
The GTID of the new master library is taken as an example and is exemplarily described below. As an example, instance A, selected as the new master library, has a GTID value of: ac13a0aa-2070-11ea-a972-d25a8cb44014:1-19, ac63abe8-2070-11ea-a8c2-7eb9a0ee2cae: 1-24.
It can be seen that, according to the structural split of the GTID, the GTID value of instance a includes two parts, the first part: ac13a0aa-2070-11ea-a972-d25a8cb44014: 1-19. A second part: ac63abe8-2070-11ea-a8c2-7eb9a0ee2cae: 1-24.
Instance A acts as a new master, the first part being instance A's own information and the second part being instance A's old master information.
Specifically, in the first section: ac13a0aa-2070-11ea-a972-d25a8cb44014 is the UUID of example a itself; in the first section: examples 1-19 are the binlog sites written by itself.
In the second section: ac63abe8-2070-11ea-a8c2-7eb9a0ee2cae is the UUID of the old master library; in the second section: 1-24 are the binlog sites where example A replicated from the old master as the new master.
As can be seen from the above analysis, for the master library, the GTID is composed of the UUID of the master library itself and the UUID of the old master library.
In the above description of the GTID of the new master library, the following description is given of an example of the GTID of the slave library.
As an example, instance B is the slave library, the GTID value is: ac63abe8-2070-11ea-a8c2-7eb9a0ee2cae:1-20, acefb575-2070-11ea-a790-fa168856fe88: 1-2.
Instance B acts as a slave, the first part being the new master library information for instance B and the second part being the old master library information for instance B.
Specifically, in the first section: ac63abe8-2070-11ea-a8c2-7eb9a0ee2cae 1-20 is UUID of the new master library; 1-20 in the first part are the binlog sites that example B itself writes.
In the second section: acefb575-2070-11ea-a790-fa168856fe88 is the UUID of the old master library; in the second section: 1-2 are the binlog sites replicated from the old master pool for example B.
Example B as a slave library, it can only replicate the master library's GITD from 1, and does not generate its GTID. To ensure data consistency, all data from the slave library should be copied from the master library. GTID values generated as from the library itself are thus discarded, followed by the GTID _ purge value being used as the binlog that needs to be discarded.
In the embodiment of the invention, the UUID of the old master library can be obtained from the GTID of the old master library. As an example, the UUID of the old master library may be obtained from the GTID of the library. The UUID of the new master library may also be obtained from the GTID of the new master library. As an example, the UUID of the new master library may be obtained from the Executed _ Gtid _ Set of the new master library.
The purpose of obtaining the UUID of the new master library and the UUID of the old master library is to determine the GTID of the non-master library instance in the database cluster.
S402, constructing a first identifier according to the universal unique identification code of the old master library and the binlog locus of the old master library in the old global transaction identifier of the non-master library instance.
The GTID of the slave library instance is composed of two parts, which are referred to as a first identifier and a second identifier in the embodiment of the present invention.
The first identifier may be constructed from the UUID of the old master repository and the binlog position of the old master repository in the old UUID of the non-master repository instance. As an example, the UUID of the old master library can be obtained from the Executed _ Gtid _ Set of the non-master library instance, and the binlog position of the old master library in the UUID of the non-master library instance can be known.
As an example, the UUID of the old master library is ac63abe8-2070-11ea-a8c2-7eb9a0ee2 cae. Binlog sites of the old master pool in the old UUID of the non-master pool instance are: 1-24. Constructing a first identifier: ac63abe8-2070-11ea-a8c2-7eb9a0ee2cae: 1-24.
It should be noted that, if the first position of the binlog site of the old master library in the old UUID of the non-master library instance is not 1, the first position may be replaced with 1 for recording.
And S403, constructing a second identifier according to the universal unique identifier of the new master library and the binlog site of the new master library.
The second identifier can be constructed based on the UUID of the new master and the binlog site of the new master.
As an example, the UUID of the new master library is ac13a0aa-2070-11ea-a972-d25a8cb 44014. The binlog site of the new master pool was 1-19. Constructing a second identifier: ac13a0aa-2070-11ea-a972-d25a8cb44014: 1-19.
It should be noted that S402 and S403 may be executed in any order, and the present invention is not limited in this respect.
S404, combining the first identification and the second identification to obtain a global transaction identification of the non-master library instance in the database cluster.
After learning the first identifier and the second identifier, the first identifier and the second identifier may be combined to obtain the GTID of the non-master repository instance in the database cluster.
Following the above example, the first identifier is: ac63abe8-2070-11ea-a8c2-7eb9a0ee2cae: 1-24. The second identification is: ac13a0aa-2070-11ea-a972-d25a8cb44014: 1-19. The GTID of the slave library is: ac63abe8-2070-11ea-a8c2-7eb9a0ee2cae:1-24, ac13a0aa-2070-11ea-a972-d25a8cb44014: 1-19.
In the embodiment of FIG. 4, the GTID of a non-master instance, i.e., a slave instance, in a database cluster may be determined based on the GTID of the old master repository and the GTID of the new master repository.
S103, according to the global transaction identification of the non-master library instance, the non-master library instance is mounted on the new master library to complete database switching.
After the GTID of the non-master library instance is determined, the non-master library instance can be mounted on the new master library according to the GTID of the non-master library instance, and therefore switching of the database from the old master library to the new master library is completed.
As an example, a folder may be created in the local physical disk directory of the new master library, and the non-master library instance may be mounted to the created folder to mount the non-master library instance to the new master library.
When a master library in a database cluster fails, there is no concern for the old master library to be re-mounted to the new master library because the old master library failed.
When the databases in the database cluster are switched online, under the condition that the non-master library instances are all mounted on the new master library, the GTID of the old master library instance does not need to be reserved, and the GTID of the old master library instance can be determined according to the GTID of the new master library. Specifically, the GTID of the old master library instance may be determined by using the schemes of S401 to S403.
Wherein, keeping the GTID of the old master library instance is that in case the mount of the non-master library instance to the new master library fails, the GTID switch based on the old master library instance can be back to the old master library.
In the above embodiment of the present invention, the latest instance in the database cluster is used as the new master database; determining the global transaction identifier of the non-master library instance in the database cluster according to the global transaction identifier of the new master library; and according to the global transaction identifier of the non-master library instance, mounting the non-master library instance to the new master library to complete database switching. When the database is switched, the global transaction identifiers of other examples can be determined according to the global transaction identifier of the new main library, and then the other examples are mounted in the new main library to complete the switching of the database, so that the database can be ensured to normally provide services.
In the practical application of the technical scheme of the invention, aiming at the automatic switching of the MySQL database development, the user can realize the database switching by only clicking the button on the management platform, including the online switching and the fault switching of the MySQL database.
Referring to fig. 5, fig. 5 is a schematic diagram of a main structure of an apparatus for switching a database according to an embodiment of the present invention, where the apparatus for switching a database may implement a method for switching a database, and as shown in fig. 5, the apparatus for switching a database specifically includes:
a screening module 501, configured to use the latest instance in the database cluster as a new master database;
an identification module 502, configured to determine, according to the global transaction identifier of the new master library, a global transaction identifier of a non-master library instance in the database cluster;
a switching module 503, configured to mount the non-primary library instance to the new primary library according to the global transaction identifier of the non-primary library instance, so as to complete database switching.
In an embodiment of the present invention, in the case of a failure of a master database in the database cluster, the screening module 501 is specifically configured to screen out an initial selection instance from all surviving instances of the database cluster based on a date;
and determining the latest instance according to the date from the initially selected instance and the user-selected instance, and taking the determined instance as a new master library.
In an embodiment of the present invention, in a case that the databases in the database cluster are switched online, the screening module 501 is specifically configured to screen out an initial selection instance according to a date and a binlog log of an old master library;
and in the initially selected examples and the examples selected by the user, determining the latest examples according to dates, and taking the determined examples as a new master library.
In an embodiment of the present invention, the identifying module 502 is specifically configured to determine the global transaction identifier of the non-master library instance in the database cluster according to the global transaction identifier of the new master library and the global transaction identifier of the old master library.
In an embodiment of the present invention, the identifying module 502 is specifically configured to obtain the unique universal identifier of the old master library from the global transaction identifier of the old master library, and obtain the unique universal identifier of the new master library from the global transaction identifier of the new master library;
constructing a first identifier according to the universal unique identification code of the old master library and the binlog locus of the old master library in the old global transaction identifier of the non-master library instance;
constructing a second identifier according to the universal unique identification code of the new master library and the binlog locus of the new master library;
and combining the first identification and the second identification to obtain a global transaction identification of the non-master database instance in the database cluster.
In an embodiment of the present invention, in a case that the database in the database cluster is switched online, the switching module 503 is further configured to determine the global transaction identifier of the old master base according to the global transaction identifier of the new master base.
In an embodiment of the present invention, the screening module 501 is configured to, when a master library in the database cluster fails or when a database in the database cluster is switched online, use the latest instance in the database cluster as a new master library.
Fig. 6 shows an exemplary system architecture 600 of a method for switching a database or an apparatus for switching a database 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. 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. The terminal devices 601, 602, 603 may have installed thereon various communication client applications, such as shopping applications, web browser applications, search applications, instant messaging tools, mailbox clients, social platform software, etc. (by way of example only).
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 management server (for example only) providing support for shopping websites browsed by users using the terminal devices 601, 602, 603. The backend management server may analyze and perform other processing on the received data such as the product information query request, and feed back a processing result (for example, target push information, product information — just an example) to the terminal device.
It should be noted that the method for switching databases provided in the embodiment of the present invention is generally executed by the server 605, and accordingly, the apparatus for switching databases 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.
Referring now to FIG. 7, shown is a block diagram of a computer system 700 suitable for use with a terminal device implementing an embodiment of the present invention. The terminal 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 RAM 703, various programs and data necessary for the operation of the system 700 are also stored. The CPU 701, the ROM 702, and the RAM 703 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, according to the embodiments of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure 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 flow chart. In such an 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 performs the above-described functions defined in the system of the present invention when executed by the Central Processing Unit (CPU) 701.
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, however, 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 modules described in the embodiments of the present invention may be implemented by software or hardware. The described modules may also be provided in a processor, which may be described as: a processor includes a transmitting unit, an obtaining unit, a determining unit, and a first processing unit. The names of these units do not in some cases constitute a limitation to the unit itself, and for example, the sending unit may also be described as a "unit sending a picture acquisition request to a connected server".
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 a device, cause the device to comprise:
taking the latest instance in the database cluster as a new master database;
determining the global transaction identifier of the non-master library instance in the database cluster according to the global transaction identifier of the new master library;
and according to the global transaction identifier of the non-master library instance, mounting the non-master library instance to the new master library to complete database switching.
According to the technical scheme of the embodiment of the invention, the latest instance in the database cluster is used as a new master database; determining the global transaction identifier of the non-master library instance in the database cluster according to the global transaction identifier of the new master library; and according to the global transaction identifier of the non-master library instance, mounting the non-master library instance to the new master library to complete database switching. When the database is switched, the global transaction identifiers of other examples can be determined according to the global transaction identifier of the new main library, and then the other examples are mounted in the new main library to complete the switching of the database, so that the database can be ensured to normally provide services.
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 (10)

1. A method of switching databases, comprising:
taking the latest instance in the database cluster as a new master database;
determining the global transaction identifier of the non-master library instance in the database cluster according to the global transaction identifier of the new master library;
and according to the global transaction identifier of the non-master library instance, mounting the non-master library instance to the new master library to complete database switching.
2. The method of switching databases of claim 1, wherein, in case of a failure of a master library in the database cluster,
the step of using the latest instance in the database cluster as a new master library comprises the following steps:
screening primary selection examples from all the survival examples of the database cluster based on date;
and determining the latest instance according to the date from the initially selected instance and the user-selected instance, and taking the determined instance as a new master library.
3. The method for switching databases of claim 1, wherein, in the case of online switching of databases in the database cluster,
the step of using the latest instance in the database cluster as a new master library comprises the following steps:
screening out the primary selection examples according to the date and the binlog log of the old master library;
and in the initially selected examples and the examples selected by the user, determining the latest examples according to dates, and taking the determined examples as a new master library.
4. The method of switching databases of claim 1, wherein said determining the global transaction identifier of the non-master repository instance in the database cluster according to the global transaction identifier of the new master repository comprises:
and determining the global transaction identifier of the non-master library instance in the database cluster according to the global transaction identifier of the new master library and the global transaction identifier of the old master library.
5. The method according to claim 4, wherein determining the global transaction identifier of the non-master library instance in the database cluster according to the global transaction identifier of the old master library and the global transaction identifier of the new master library comprises:
acquiring the universal unique identification code of the old master library from the global transaction identifier of the old master library, and acquiring the universal unique identification code of the new master library from the global transaction identifier of the new master library;
constructing a first identifier according to the universal unique identification code of the old master library and the binlog locus of the old master library in the old global transaction identifier of the non-master library instance;
constructing a second identifier according to the universal unique identification code of the new master library and the binlog locus of the new master library;
and combining the first identification and the second identification to obtain a global transaction identification of the non-master database instance in the database cluster.
6. The method for switching databases of claim 1, wherein, in the case of online switching of databases in the database cluster,
after the non-master library instance is mounted on the new master library according to the global transaction identifier of the non-master library instance, the method further includes:
and determining the global transaction identifier of the old master library according to the global transaction identifier of the new master library.
7. The method for switching databases according to claim 1 or 4, wherein the step of using the latest instance in the database cluster as a new master library comprises:
and when the main library in the database cluster fails or the databases in the database cluster are switched online, taking the latest instance in the database cluster as a new main library.
8. An apparatus for switching databases, comprising:
the screening module is used for taking the latest instance in the database cluster as a new master database;
the identification module is used for determining the global transaction identification of the non-master library instance in the database cluster according to the global transaction identification of the new master library;
and the switching module is used for mounting the non-master library instance to the new master library according to the global transaction identifier of the non-master library instance so as to complete database switching.
9. An electronic device for switching databases, 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-7.
10. A computer-readable 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-7.
CN202010904689.6A 2020-09-01 2020-09-01 Method, device, equipment and computer readable medium for switching databases Pending CN113761075A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010904689.6A CN113761075A (en) 2020-09-01 2020-09-01 Method, device, equipment and computer readable medium for switching databases

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010904689.6A CN113761075A (en) 2020-09-01 2020-09-01 Method, device, equipment and computer readable medium for switching databases

Publications (1)

Publication Number Publication Date
CN113761075A true CN113761075A (en) 2021-12-07

Family

ID=78785641

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010904689.6A Pending CN113761075A (en) 2020-09-01 2020-09-01 Method, device, equipment and computer readable medium for switching databases

Country Status (1)

Country Link
CN (1) CN113761075A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116595085A (en) * 2023-07-17 2023-08-15 上海爱可生信息技术股份有限公司 Database master-slave switching method and distributed database

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104516966A (en) * 2014-12-24 2015-04-15 北京奇虎科技有限公司 High-availability solving method and device of database cluster
CN106383755A (en) * 2016-09-23 2017-02-08 北京奇虎科技有限公司 Method, apparatus and system for recovering slave database from master-slave database system
CN106909568A (en) * 2015-12-23 2017-06-30 北京奇虎科技有限公司 A kind of changing method and device of data-base cluster MDL
CN107291787A (en) * 2016-04-13 2017-10-24 中兴通讯股份有限公司 Master/slave data storehouse switching method and apparatus
CN107623703A (en) * 2016-07-13 2018-01-23 中兴通讯股份有限公司 Global transaction identifies GTID synchronous method, apparatus and system
US20190095293A1 (en) * 2016-07-27 2019-03-28 Tencent Technology (Shenzhen) Company Limited Data disaster recovery method, device and system

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104516966A (en) * 2014-12-24 2015-04-15 北京奇虎科技有限公司 High-availability solving method and device of database cluster
CN106909568A (en) * 2015-12-23 2017-06-30 北京奇虎科技有限公司 A kind of changing method and device of data-base cluster MDL
CN107291787A (en) * 2016-04-13 2017-10-24 中兴通讯股份有限公司 Master/slave data storehouse switching method and apparatus
CN107623703A (en) * 2016-07-13 2018-01-23 中兴通讯股份有限公司 Global transaction identifies GTID synchronous method, apparatus and system
US20190095293A1 (en) * 2016-07-27 2019-03-28 Tencent Technology (Shenzhen) Company Limited Data disaster recovery method, device and system
CN106383755A (en) * 2016-09-23 2017-02-08 北京奇虎科技有限公司 Method, apparatus and system for recovering slave database from master-slave database system

Non-Patent Citations (1)

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

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116595085A (en) * 2023-07-17 2023-08-15 上海爱可生信息技术股份有限公司 Database master-slave switching method and distributed database
CN116595085B (en) * 2023-07-17 2023-09-29 上海爱可生信息技术股份有限公司 Database master-slave switching method and distributed database

Similar Documents

Publication Publication Date Title
CN110597595B (en) Method for providing multi-language information, method for configuring multi-language information, device, equipment and medium
EP4033374A1 (en) Method and device for synchronizing node data
US10725976B2 (en) Fast recovery using self-describing replica files in a distributed storage system
US10936423B2 (en) Enhanced application write performance
CN111782235A (en) Data upgrading and querying method and device
CN111666134A (en) Method and system for scheduling distributed tasks
CN107526838B (en) Method and device for database cluster capacity expansion
CN111338834A (en) Data storage method and device
CN113761075A (en) Method, device, equipment and computer readable medium for switching databases
CN113760924A (en) Distributed transaction processing method and device
CN108833147B (en) Configuration information updating method and device
CN111177260A (en) Database remote copying method and device and electronic equipment
CN116049142A (en) Data processing method, device, electronic equipment and storage medium
CN110019059B (en) Timing synchronization method and device
US11416468B2 (en) Active-active system index management
CN113821249A (en) Project development configuration method and device, electronic equipment and readable storage medium
CN113011858A (en) Audit project configuration and execution method and device
CN111984686A (en) Data processing method and device
CN113806327A (en) Database design method and device and related equipment
CN113157354A (en) Method, device, equipment and computer readable medium for processing data
CN111277632B (en) Method and device for managing applications in system cluster
CN113760860B (en) Data reading method and device
WO2023221002A1 (en) Ota-based system updating method and apparatus, electronic device, and storage medium
CN116226274A (en) Metadata synchronization method, distributed database system, and storage medium
CN115033600A (en) Data processing method and data processing device

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