Nothing Special   »   [go: up one dir, main page]

CN109245908B - Method and device for switching master cluster and slave cluster - Google Patents

Method and device for switching master cluster and slave cluster Download PDF

Info

Publication number
CN109245908B
CN109245908B CN201710555869.6A CN201710555869A CN109245908B CN 109245908 B CN109245908 B CN 109245908B CN 201710555869 A CN201710555869 A CN 201710555869A CN 109245908 B CN109245908 B CN 109245908B
Authority
CN
China
Prior art keywords
cluster
node
configuration information
data node
client
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.)
Active
Application number
CN201710555869.6A
Other languages
Chinese (zh)
Other versions
CN109245908A (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 Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke 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 Jingdong Shangke Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN201710555869.6A priority Critical patent/CN109245908B/en
Publication of CN109245908A publication Critical patent/CN109245908A/en
Application granted granted Critical
Publication of CN109245908B publication Critical patent/CN109245908B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L41/00Arrangements for maintenance, administration or management of data switching networks, e.g. of packet switching networks
    • H04L41/06Management of faults, events, alarms or notifications
    • H04L41/0654Management of faults, events, alarms or notifications using network fault recovery
    • H04L41/0663Performing the actions predefined by failover planning, e.g. switching to standby network elements
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L41/00Arrangements for maintenance, administration or management of data switching networks, e.g. of packet switching networks
    • H04L41/08Configuration management of networks or network elements
    • H04L41/0876Aspects of the degree of configuration automation
    • H04L41/0886Fully automatic configuration
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L43/00Arrangements for monitoring or testing data switching networks
    • H04L43/10Active monitoring, e.g. heartbeat, ping or trace-route
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • H04L67/104Peer-to-peer [P2P] networks
    • H04L67/1044Group management mechanisms 

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Mathematical Physics (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Automation & Control Theory (AREA)
  • Health & Medical Sciences (AREA)
  • Cardiology (AREA)
  • General Health & Medical Sciences (AREA)
  • Hardware Redundancy (AREA)
  • Computer And Data Communications (AREA)

Abstract

The embodiment of the invention provides a method and a device for switching a master cluster and a slave cluster, and relates to the technical field of computers. The method of the embodiment of the invention comprises the following steps: creating a data node, and writing the configuration information of the main cluster into a node value of the corresponding data node; when the master cluster and the slave cluster need to be switched, the node value of the data node is modified into the configuration information of the slave cluster to be switched; and monitoring whether the node value of the data node changes or not, acquiring configuration information of a slave cluster to be switched after monitoring that the node value changes, and modifying a link of the client to the cluster according to the acquired configuration information so as to realize master-slave cluster switching. In the embodiment of the invention, the configuration information is written into the node value of the data node, the client monitors the change of the node value of the data node, and when the change of the node value is monitored, the configuration information of the slave cluster is obtained and the link from the client to the cluster is modified, so that the online switching of the master cluster and the slave cluster is realized.

Description

Method and device for switching master cluster and slave cluster
Technical Field
The invention relates to the field of computers, in particular to a master-slave cluster switching method and device.
Background
At present, more and more internet companies start to use large-scale clusters to support services, and in order to ensure high availability of the clusters, many companies use a master-slave cluster which is across a machine room and is disaster-tolerant as a solution. At present, there are two main switching schemes for master and slave clusters: the first scheme is as follows: and modifying the configuration and restarting. The client prepares two sets of configurations, one set of configuration points to the master cluster, the other set of configuration points to the slave cluster, and when the master cluster fails, the client restarts the application and modifies the configuration to point to the slave cluster. Scheme II: and (4) double activity. And simultaneously operating two sets of clients, wherein one set of clients accesses the master cluster, the other set of clients accesses the slave cluster, and when the master cluster fails, the application accessing the slave cluster can still normally access.
In the process of implementing the invention, the inventor finds that at least the following problems exist in the prior art:
(1) the service is not available. Restarting the client means that the service is not available, which is often intolerable for online traffic.
(2) It takes a long time. When the client size is thousands or even larger, it takes a very long time to restart the client.
(3) The cost is high. The double live solution means that more resources are consumed and higher maintenance costs are required.
(4) And (4) data consistency. The dual-active scheme requires that the clients themselves ensure the data consistency of the master cluster and the slave cluster, and the clients often need to complement after the failure of one set of clients is recovered.
Disclosure of Invention
In view of this, embodiments of the present invention provide a method and an apparatus for switching a master cluster and a slave cluster. In the embodiment of the invention, the configuration information is written into the node value of the data node, the client monitors the change of the node value of the data node, and when the change of the node value is monitored, the configuration information of the slave cluster is obtained and the link from the client to the cluster is modified, so that the online switching of the master cluster and the slave cluster is realized.
To achieve the above object, according to an aspect of the embodiments of the present invention, a method for master-slave cluster switching is provided.
The method for switching the master cluster and the slave cluster comprises the following steps: creating a data node, and writing the configuration information of the main cluster into a node value of the corresponding data node; when the master cluster and the slave cluster need to be switched, the node value of the data node is modified into the configuration information of the slave cluster to be switched; and monitoring whether the node value of the data node changes or not, acquiring configuration information of a slave cluster to be switched after monitoring that the node value changes, and modifying a link of the client to the cluster according to the acquired configuration information so as to realize master-slave cluster switching.
Optionally, creating a data node comprises: the data node is created in ZooKeeper.
Optionally, the monitoring whether the node value of the data node changes includes: and setting a monitor for the data node to monitor whether the node value of the data node changes in real time.
Optionally, the monitoring whether the node value of the data node changes includes: and inquiring the node value of the data node at regular time or non-regular time, and comparing whether the node values of two adjacent nodes are the same or not to monitor whether the node value of the data node is changed or not.
Optionally, the method further comprises: and when the client is started, acquiring the configuration information of the main cluster, and creating a link of the client to the cluster according to the configuration information.
To achieve the above object, according to another aspect of the embodiments of the present invention, an apparatus for master-slave cluster switching is provided.
The device for switching the master cluster and the slave cluster comprises: the creating and writing module is used for creating data nodes and writing the configuration information of the main cluster into the corresponding node values of the data nodes; the modification module is used for modifying the node value of the data node into the configuration information of the slave cluster to be switched when the master-slave cluster switching is required; and the monitoring and modifying link module is used for monitoring whether the node value of the data node changes or not, acquiring configuration information of the slave cluster to be switched after the node value is monitored to change, and modifying the link of the client pointing to the cluster according to the acquired configuration information so as to realize master-slave cluster switching.
Optionally, the creating and writing module is further configured to: the data node is created in ZooKeeper.
Optionally, the monitoring and modifying link module is further configured to: and setting a monitor for the data node to monitor whether the node value of the data node changes in real time.
Optionally, the monitoring and modifying link module is further configured to: and inquiring the node value of the data node at regular time or non-regular time, and comparing whether the node values of two adjacent nodes are the same or not to monitor whether the node value of the data node is changed or not.
Optionally, the apparatus further comprises: and the link creating module is used for acquiring the configuration information of the main cluster when a client is started, and creating a link of the client to the cluster according to the configuration information.
To achieve the above object, according to still another aspect of embodiments of the present invention, there is provided an electronic apparatus.
An electronic device of an embodiment of the present invention includes: one or more processors; 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 implement the method for switching the master cluster and the slave cluster according to the embodiment of the invention.
To achieve the above object, according to still another aspect of embodiments of the present invention, there is provided a computer-readable medium.
A computer-readable medium of an embodiment of the present invention stores thereon a computer program, which, when executed by a processor, implements a method of master-slave cluster switching of an embodiment of the present invention.
One embodiment of the above invention has the following advantages or benefits: the configuration information is maintained to the data nodes, the client monitors the change of the node values of the data nodes, when the change of the node values is monitored, the configuration information is obtained, the link from the client to the cluster is modified, and the online switching of the master cluster and the slave cluster is realized by only one set of client. The configuration information is maintained in the ZooKeeper, and the monitor monitors the node value change in real time, so that the characteristic that the ZooKeeper can monitor the node value in real time is skillfully utilized, the master-slave cluster switching is rapidly completed, and the switching can still be rapidly completed when the number of clients is huge.
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 method for master-slave cluster handover according to an embodiment of the present invention;
FIG. 2 is a flow chart of a method of master-slave cluster handover according to an embodiment of the present invention;
fig. 3 is an architecture diagram of a master-slave cluster switching system before cluster switching according to an embodiment of the present invention;
FIG. 4 is an architecture diagram of a master-slave cluster switching system after cluster switching according to an embodiment of the present invention;
FIG. 5 is a schematic diagram of a data node in a ZooKeeper before cluster switching according to an embodiment of the present invention;
FIG. 6 is a schematic diagram of a data node in a modified ZooKeeper according to an embodiment of the invention;
FIG. 7 is a schematic diagram of the main modules of an apparatus for master-slave cluster switching according to an embodiment of the present invention;
FIG. 8 is an exemplary system architecture diagram in which embodiments of the present invention may be employed;
FIG. 9 is a schematic diagram of a computer apparatus suitable for use in an electronic device to implement 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.
Fig. 1 is a schematic diagram of main steps of a method for master-slave cluster switching according to an embodiment of the present invention. As shown in fig. 1, the method for switching between master and slave clusters in the embodiment of the present invention mainly includes the following steps:
step S101: and creating a data node, and writing the configuration information of the main cluster into a node value of the corresponding data node. In this step, the configuration information is maintained in a unified manner to the data node, where the data node may be created in the ZooKeeper or in the Consul of the distributed application service. A data node generally corresponds to a specific service application of a user. The configuration information can be written into the node value of the data node, and whether the configuration information is changed or not is obtained by monitoring the change of the node value subsequently.
Step S102: and when the master-slave cluster switching is required, modifying the node value of the data node into the configuration information of the slave cluster to be switched. When the main cluster fails or needs to be upgraded and maintained, the main cluster and the slave cluster need to be switched. Two scenarios are considered here, one is that maintenance personnel manually modifies the node value into the configuration information of the slave cluster to be switched, and then the cluster switching is triggered. The other method is that the slave cluster observes a main cluster fault, automatically writes self configuration into a node value, and triggers cluster switching.
Step S103: and monitoring whether the node value of the data node changes or not, acquiring configuration information of a slave cluster to be switched after monitoring that the node value changes, and modifying a link of the client to the cluster according to the acquired configuration information so as to realize master-slave cluster switching. The client monitors the change of the node value in real time through monitoring the process. And after the server side triggers the monitoring event, a notification is sent to the client side, and the client side executes callback logic for acquiring the configuration information of the slave cluster to be switched. And modifying the link of the client to the cluster according to the acquired configuration information so that the client points to the slave cluster to be switched, thereby completing the on-line switching of the master cluster and the slave cluster. After the switching is completed, the monitoring process continues to monitor whether the modified node value changes.
In step 103, it is monitored whether the node value of the data node changes, and two implementation manners are provided in the embodiment of the present invention. The first method is as follows: and setting a monitor for the data node to monitor whether the node value of the data node changes in real time. The second method comprises the following steps: and inquiring the node value of the data node at regular time or non-regular time, and comparing whether the node values of two adjacent nodes are the same or not to monitor whether the node value of the data node is changed or not. The first mode can be monitored in real time, and the second mode cannot be monitored in real time.
When the ZooKeeper is adopted to maintain the configuration information of the cluster, the client can monitor whether the node value of the data node changes in real time through the Watcher process. The concrete implementation is as follows: the client registers the Watcher with the ZooKeeper server, and at the same time, stores the Watcher object in the client's snoop manager (WatchManager). After the ZooKeeper server triggers the watchdog event, a notification of which data node generates the watchdog event is sent to the client, and the client takes out the corresponding watchdog object from the watchdog manager to execute the callback logic. The watch is a main means for the ZooKeeper to realize applications such as distributed locks, distributed configurations, distributed queues and the like, and can monitor node value changes of any node.
In addition, between step 101 and step 102, the method for switching between master and slave clusters according to the embodiment of the present invention further includes: and when the client is started, acquiring the configuration information of the main cluster, and creating a link of the client to the cluster according to the configuration information. The following takes the ZooKeeper maintenance cluster configuration information as an example, and the step is explained in detail:
(1) acquiring configuration information of a cluster: starting a client, acquiring a locally configured data node by the client, accessing a ZooKeeper, inquiring data in the corresponding data node, and analyzing the data to acquire configuration information of a main cluster;
(2) creating a link: and the client side constructs configuration parameters according to the acquired configuration information and uses the configuration parameters to create links.
The master-slave cluster switching method of the present invention is described below by taking the example of maintaining configuration information in the ZooKeeper, the cluster a as the master cluster accessed by the client, and the cluster B as the slave cluster to be switched.
Each cluster comprises a plurality of servers, and one or more servers in the cluster form a server side. The client side initiates an access request to the server side, and finally the access request is transmitted to a specific server of the server side. Before and after the master-slave cluster is switched, it needs to ensure that the data/table requested by the client also exists in another cluster, so the data between cluster a and cluster B should be synchronized with each other. Taking the cluster a as an HBase cluster (the cluster is a distributed column storage system) as an example, a specific implementation manner of synchronization may be: the cluster A sends a Write-Ahead Logging (WAL) to the cluster B through a self-contained Replication (Replication) function, and the cluster B plays back the WAL log after receiving the WAL log and writes log data into the cluster.
Fig. 2 is a flowchart of a method of master-slave cluster handover according to an embodiment of the present invention. As shown in fig. 2, the method for switching between master and slave clusters according to the embodiment of the present invention includes the following steps:
step S201: creating a corresponding data node in the ZooKeeper, and writing the configuration information of the cluster A into the corresponding data node; the correspondence in the data node that created the correspondence is with the client. A data node is generally created in the ZooKeeper cluster, and the data node is used for storing configuration information of the cluster, and is an entity for a client to access the ZooKeeper.
Step S202: starting a client to obtain configuration information of a cluster A corresponding to a data node in the ZooKeeper; the client configures which data node it listens to in its configuration file.
Step S203: the client establishes a link pointing to the cluster according to the acquired configuration information of the cluster A, and simultaneously establishes a monitoring process (a Watcher process);
step S204: when switching is needed, manually/automatically modifying the node value of the corresponding data node in the ZooKeeper into the configuration information of the cluster B to be switched;
step S205: the client monitors the change of the node value in real time through the Watcher process, and when the change of the node value is monitored, the configuration information of the cluster B is obtained again;
step S206: and the client modifies the link of the cluster B to the cluster according to the acquired configuration information of the cluster B.
After step S206 is completed, cluster B is switched to the master cluster. And then, the client repeatedly executes the steps S205 and S206 to continuously monitor whether the modified node value changes through the watchdog process, and when the node value changes, the configuration information of the new cluster is obtained again, and the modified link points to the new cluster.
Fig. 3 is an architecture diagram of a master-slave cluster switching system before cluster switching according to an embodiment of the present invention. As shown in fig. 3, the master-slave switching system according to the embodiment of the present invention includes a client 1 to a client N, a cluster a, a cluster B, and a ZooKeeper, where before cluster switching, the cluster a is a master cluster of the client 1 to the client N, and through steps S201 to S203, the client 1 to the client N obtain configuration information of the cluster a from a corresponding data node of the ZooKeeper, and then create a link pointing to the cluster a from the client 1 to the client N, so that the client 1 to the client N access the cluster a.
Fig. 4 is an architecture diagram of a master-slave cluster switching system after cluster switching according to an embodiment of the present invention. As shown in fig. 4, after cluster switching, cluster B is switched to be the master cluster of client 1 to client N. Through the steps S205 and S206, the clients 1 to N acquire the configuration information of the cluster B from the corresponding data nodes of the ZooKeeper, and then modify the links pointing to the cluster a from the clients 1 to N to point to the cluster B, so that the clients 1 to N access the cluster B.
Fig. 5 is a schematic diagram of a data node in ZooKeeper before cluster switching according to an embodiment of the present invention. As shown in fig. 5, before cluster switching, data nodes 1 to N corresponding to clients are created in the ZooKeeper. The node names of the data nodes 1 to N are/SL 100000000001 to/SL 10000000000N; the node values of the data nodes 1 to N are all configuration information of the cluster A. Of course, whether the configuration information of the data nodes 1 to N is the cluster a or the cluster B may be customized by a user, for example, the node value of the data node 1 is set as the configuration information of the cluster a, and the node value of the data node 2 is set as the configuration information of the cluster B, which is only a schematic diagram in the figure.
Fig. 6 is a schematic diagram of a data node in a modified ZooKeeper according to an embodiment of the present invention. As shown in fig. 6, when the main cluster needs to be switched from cluster a to cluster B, the node values of data node 1 to data node N are all modified into the configuration information of cluster B. Also, here, the modified node values of the data node 1 to the data node N may also be customized by the user.
According to the method for switching the master cluster and the slave cluster, the configuration information is maintained to the data nodes, the client monitors the change of the node values of the data nodes, when the change of the node values is monitored, the configuration information is obtained, the link from the client to the cluster is modified, and the on-line switching of the master cluster and the slave cluster is realized by only one set of client. The configuration information is maintained in the ZooKeeper, and the monitor monitors the node value change in real time, so that the characteristic that the ZooKeeper can monitor the node value in real time is skillfully utilized, the master-slave cluster switching is rapidly completed, and the switching can still be rapidly completed when the number of clients is huge.
Fig. 7 is a schematic diagram of main modules of a master-slave cluster switching apparatus according to an embodiment of the present invention. As shown in fig. 7, the apparatus for switching between master and slave clusters according to the embodiment of the present invention includes:
a creating and writing module 701, configured to create a data node, and write the configuration information of the main cluster into a node value of the corresponding data node. In the embodiment, the configuration information is uniformly maintained in the data node created in the ZooKeeper.
A modifying module 702, configured to modify a node value of the data node into configuration information of a slave cluster to be switched when a master-slave cluster needs to be switched. When the main cluster fails or needs to be upgraded and maintained, the main cluster and the slave cluster need to be switched. Two scenarios are considered here, one is that maintenance personnel manually modifies the node value into the configuration information of the slave cluster to be switched, and then the cluster switching is triggered. The other method is that the slave cluster observes a main cluster fault, automatically writes self configuration into a node value, and triggers cluster switching.
The monitoring and modifying link module 703 is configured to monitor whether a node value of the data node changes, obtain configuration information of a slave cluster to be switched when the node value is monitored to change, and modify a link, pointing to the cluster, of the client according to the obtained configuration information, thereby implementing master-slave cluster switching. In the embodiment, by using the characteristic that the ZooKeeper can monitor through the Watcher in real time, the client monitors the change of the node value through the Watcher process, and when the change of the node value is monitored, the link of the client pointing to the cluster is modified, so that the master-slave cluster switching is automatically completed. After the switching is completed, the monitoring process continues to monitor whether the modified node value changes.
It can be seen from the above description that, by maintaining the configuration information to the data node, the client monitors the change of the node value of the data node, and when the change of the node value is monitored, the configuration information is obtained and the link from the client to the cluster is modified, so that the online switching between the master cluster and the slave cluster is realized by using only one set of clients. The configuration information is maintained in the ZooKeeper, and the monitor monitors the node value change in real time, so that the characteristic that the ZooKeeper can monitor the node value in real time is skillfully utilized, the master-slave cluster switching is rapidly completed, and the switching can still be rapidly completed when the number of clients is huge.
Fig. 8 shows an exemplary system architecture 800 of a master-slave cluster switching method or a master-slave cluster switching apparatus to which an embodiment of the present invention may be applied.
As shown in fig. 8, the system architecture 800 may include terminal devices 801, 802, 803, a network 804, and a server 805. The network 804 serves to provide a medium for communication links between the terminal devices 801, 802, 803 and the server 805. Network 804 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 801, 802, 803 to interact with a server 805 over a network 804 to receive or send messages or the like. The terminal devices 801, 802, 803 may have installed thereon various communication client applications, such as shopping-like applications, web browser applications, search-like applications, instant messaging tools, mailbox clients, social platform software, etc. (by way of example only).
The terminal devices 801, 802, 803 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 805 may be a server providing various services, such as a background management server (for example only) providing support for click events generated by users using the terminal devices 801, 802, 803. The background management server may analyze and perform other processing on the received click data, text content, and other data, 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 between master and slave clusters provided in the embodiment of the present application is generally executed by the server 805 and the terminal devices 801, 802, and 803, and accordingly, the device for switching between master and slave clusters is generally disposed in the server 805 and the terminal devices 801, 802, and 803.
It should be understood that the number of terminal devices, networks, and servers in fig. 8 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
The invention also provides an electronic device and a computer readable medium according to the embodiment of the invention.
The electronic device of the present invention includes: one or more processors; 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 implement the method for switching the master cluster and the slave cluster according to the embodiment of the invention.
The computer readable medium of the present invention has stored thereon a computer program, which when executed by a processor implements a method of master-slave cluster switching of an embodiment of the present invention.
Referring now to FIG. 9, shown is a block diagram of a computer system 900 suitable for use with a terminal device implementing an embodiment of the present invention. The terminal device shown in fig. 9 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. 9, the computer system 900 includes a Central Processing Unit (CPU)901 that can perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)902 or a program loaded from a storage section 908 into a Random Access Memory (RAM) 903. In the RAM 903, various programs and data necessary for the operation of the system 900 are also stored. The CPU 901, ROM 902, and RAM 903 are connected to each other via a bus 904. An input/output (I/O) interface 905 is also connected to bus 904.
The following components are connected to the I/O interface 905: an input portion 906 including a keyboard, a mouse, and the like; an output section 907 including components such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage portion 908 including a hard disk and the like; and a communication section 909 including a network interface card such as a LAN card, a modem, or the like. The communication section 909 performs communication processing via a network such as the internet. The drive 910 is also connected to the I/O interface 905 as necessary. A removable medium 911 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 910 as necessary, so that a computer program read out therefrom is mounted into the storage section 908 as necessary.
In particular, the processes described above with respect to the main step diagrams may be implemented as computer software programs, according to embodiments of the present disclosure. 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 may be downloaded and installed from a network through the communication section 909, and/or installed from the removable medium 911. The above-described functions defined in the system of the present invention are executed when the computer program is executed by a Central Processing Unit (CPU) 901.
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 principal step diagrams 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 create and write module, a modify module, and a monitor and modify link module. For example, the dependency package generation module may be further described as a module that creates a data node and writes configuration information of the main cluster into a node value of the corresponding data node.
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: creating a data node, and writing the configuration information of the main cluster into a node value of the corresponding data node; when the master cluster and the slave cluster need to be switched, the node value of the data node is modified into the configuration information of the slave cluster to be switched; and monitoring whether the node value of the data node changes or not, acquiring configuration information of a slave cluster to be switched after monitoring that the node value changes, and modifying a link of the client to the cluster according to the acquired configuration information so as to realize master-slave cluster switching.
It can be seen from the above description that, by maintaining the configuration information to the data node, the client monitors the change of the node value of the data node, and when the change of the node value is monitored, the configuration information is obtained and the link from the client to the cluster is modified, so that the online switching between the master cluster and the slave cluster is realized by using only one set of clients. The configuration information is maintained in the ZooKeeper, and the monitor monitors the node value change in real time, so that the characteristic that the ZooKeeper can monitor the node value in real time is skillfully utilized, the master-slave cluster switching is rapidly completed, and the switching can still be rapidly completed when the number of clients is huge.
The product can execute the method provided by the embodiment of the invention, and has corresponding functional modules and beneficial effects of the execution method. For technical details that are not described in detail in this embodiment, reference may be made to the method provided by the embodiment of the present invention.
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 for master-slave cluster switching, comprising:
creating a data node corresponding to the client in the ZooKeeper, and writing the configuration information of the main cluster into a node value of the corresponding data node; wherein the data node is an entity for the client to access the ZooKeeper;
when the master cluster and the slave cluster need to be switched, the node value of the data node is modified into the configuration information of the slave cluster to be switched;
the client monitors whether the node value of the data node changes or not through a monitoring program, when the node value changes, the configuration information of the slave cluster to be switched is acquired, and the link of the client pointing to the cluster is modified according to the acquired configuration information, so that master-slave cluster switching is achieved.
2. The method of claim 1, wherein monitoring whether the node value of the data node changes comprises: and setting a monitor for the data node to monitor whether the node value of the data node changes in real time.
3. The method of claim 1, wherein monitoring whether the node value of the data node changes comprises: and inquiring the node value of the data node at regular time or non-regular time, and comparing whether the node values of two adjacent nodes are the same or not to monitor whether the node value of the data node is changed or not.
4. The method of claim 1, further comprising: and when the client is started, acquiring the configuration information of the main cluster, and creating a link of the client to the cluster according to the configuration information.
5. An apparatus for master-slave cluster switching, comprising:
the creating and writing module is used for creating a data node corresponding to the client in the ZooKeeper and writing the configuration information of the main cluster into a node value of the corresponding data node; wherein the data node is an entity for the client to access the ZooKeeper;
the modification module is used for modifying the node value of the data node into the configuration information of the slave cluster to be switched when the master-slave cluster switching is required;
and the monitoring and modifying link module is used for monitoring whether the node value of the data node changes or not through a monitoring program, acquiring configuration information of a slave cluster to be switched after the node value is monitored to change, and modifying the link of the client pointing to the cluster according to the acquired configuration information so as to realize master-slave cluster switching.
6. The apparatus of claim 5, wherein the monitoring and modification linking module is further configured to: and setting a monitor for the data node to monitor whether the node value of the data node changes in real time.
7. The apparatus of claim 5, wherein the monitoring and modification linking module is further configured to: and inquiring the node value of the data node at regular time or non-regular time, and comparing whether the node values of two adjacent nodes are the same or not to monitor whether the node value of the data node is changed or not.
8. The apparatus of claim 5, further comprising: and the link creating module is used for acquiring the configuration information of the main cluster when a client is started, and creating a link of the client to the cluster according to the configuration information.
9. 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-4.
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-4.
CN201710555869.6A 2017-07-10 2017-07-10 Method and device for switching master cluster and slave cluster Active CN109245908B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710555869.6A CN109245908B (en) 2017-07-10 2017-07-10 Method and device for switching master cluster and slave cluster

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710555869.6A CN109245908B (en) 2017-07-10 2017-07-10 Method and device for switching master cluster and slave cluster

Publications (2)

Publication Number Publication Date
CN109245908A CN109245908A (en) 2019-01-18
CN109245908B true CN109245908B (en) 2022-04-26

Family

ID=65082964

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710555869.6A Active CN109245908B (en) 2017-07-10 2017-07-10 Method and device for switching master cluster and slave cluster

Country Status (1)

Country Link
CN (1) CN109245908B (en)

Families Citing this family (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112445671A (en) * 2019-08-29 2021-03-05 阿里巴巴集团控股有限公司 Link tracking method and device and computer system
CN110635953A (en) * 2019-10-17 2019-12-31 厦门网宿有限公司 Configuration information management method and device
CN111277632B (en) * 2020-01-13 2022-05-06 中国建设银行股份有限公司 Method and device for managing applications in system cluster
CN111371865B (en) * 2020-02-26 2023-02-24 上海达梦数据库有限公司 Client connection relation adjusting method, system and node
CN111901395B (en) * 2020-07-07 2024-03-22 青岛海尔科技有限公司 Multi-cluster switching method and device
CN111917846A (en) * 2020-07-19 2020-11-10 中信银行股份有限公司 Kafka cluster switching method, device and system, electronic equipment and readable storage medium
CN112181724B (en) * 2020-09-23 2024-06-18 支付宝(杭州)信息技术有限公司 Big data disaster recovery method and device and electronic equipment
CN113765690B (en) * 2021-01-07 2024-10-22 北京沃东天骏信息技术有限公司 Cluster switching method, system, device, terminal, server and storage medium

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1716227A (en) * 2004-06-30 2006-01-04 富士通株式会社 Operating means and operation apparatus control method, program and computer-readable medium
CN103546914A (en) * 2013-10-21 2014-01-29 大唐移动通信设备有限公司 HSS (home subscriber server) master-slave management method and HSS master-slave management device
CN104394142A (en) * 2014-11-24 2015-03-04 北京京东尚科信息技术有限公司 Method and device for achieving automatic Redis master-slave conversion
CN105721200A (en) * 2016-01-21 2016-06-29 北京乐动卓越科技有限公司 Master-slave server system application method and system thereof
CN106557399A (en) * 2015-09-25 2017-04-05 伊姆西公司 Method and apparatus for the state of storage cluster is presented
CN106681861A (en) * 2016-12-08 2017-05-17 杭州销冠网络科技有限公司 New environment isolation configuration data management method and system

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20160381127A1 (en) * 2012-09-10 2016-12-29 William James Gibson Systems and methods for dynamic networked peer-to-peer content distribution
US10243821B2 (en) * 2015-12-30 2019-03-26 Juniper Networks, Inc. OAM mechanisms for EVPN active-active services

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1716227A (en) * 2004-06-30 2006-01-04 富士通株式会社 Operating means and operation apparatus control method, program and computer-readable medium
CN103546914A (en) * 2013-10-21 2014-01-29 大唐移动通信设备有限公司 HSS (home subscriber server) master-slave management method and HSS master-slave management device
CN104394142A (en) * 2014-11-24 2015-03-04 北京京东尚科信息技术有限公司 Method and device for achieving automatic Redis master-slave conversion
CN106557399A (en) * 2015-09-25 2017-04-05 伊姆西公司 Method and apparatus for the state of storage cluster is presented
CN105721200A (en) * 2016-01-21 2016-06-29 北京乐动卓越科技有限公司 Master-slave server system application method and system thereof
CN106681861A (en) * 2016-12-08 2017-05-17 杭州销冠网络科技有限公司 New environment isolation configuration data management method and system

Also Published As

Publication number Publication date
CN109245908A (en) 2019-01-18

Similar Documents

Publication Publication Date Title
CN109245908B (en) Method and device for switching master cluster and slave cluster
CN113742031B (en) Node state information acquisition method and device, electronic equipment and readable storage medium
CN108984544B (en) Method and device for modifying configuration information of distributed system
CN109783151B (en) Method and device for rule change
CN112860343B (en) Configuration changing method, system, device, electronic equipment and storage medium
CN110019158A (en) A kind of method and apparatus of monitoring data quality
CN112612467A (en) Method and device for processing micro front-end architecture based on qiankun
CN111338834B (en) Data storage method and device
CN112398669B (en) Hadoop deployment method and device
CN113760638A (en) Log service method and device based on kubernets cluster
CN113079098B (en) Method, device, equipment and computer readable medium for updating route
CN107818027B (en) Method and device for switching main name node and standby name node and distributed system
CN113760469A (en) Distributed computing method and device
CN113378346A (en) Method and device for model simulation
CN113722007B (en) Configuration method, device and system of VPN branch equipment
CN115442129A (en) Method, device and system for managing cluster access authority
CN110851192B (en) Method and device for responding to degraded switch configuration
CN110609734A (en) Method and device for scheduling timed tasks
CN115190125A (en) Monitoring method and device for cache cluster
CN114756173A (en) Method, system, device and computer readable medium for file merging
CN112559001B (en) Method and device for updating application
CN112463616A (en) Chaos testing method and device for Kubernetes container platform
CN110300004B (en) Method and device for switching network services
CN112953810A (en) Network request processing method and device
CN114500485B (en) Data processing method and 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
GR01 Patent grant
GR01 Patent grant