Data service and database switching method and device, equipment, medium and product

By obtaining and comparing the environmental information of the database cluster data nodes, and selecting a backup master node that is consistent with the master node environment, the risk of switchover failure caused by inconsistent environments in the existing technology is solved, the switchover efficiency and success rate are improved, and the operation cost is reduced. dimension cost.

CN118656255APending Publication Date: 2024-09-17MASHANG CONSUMER FINANCE CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202410418620.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-04-08
Publication Date
2024-09-17

AI Technical Summary

Technical Problem

Existing database clusters lack an environment checking algorithm before master-slave switching, resulting in a higher risk of switching failure due to inconsistency in the running environment, and dependence on manual comparison, which causes delays and individual differences.

Method used

By obtaining the environment information of the database cluster data node, the environment difference information between the master node and the slave node is determined, and the backup master node is selected from multiple slave nodes based on the difference information to reduce the difference in operating environment and the risk of switching.

Benefits of technology

It effectively reduces operational risks caused by differences in the operating environments of master and slave nodes, improves the speed and success rate of data node switching, and reduces operation and maintenance costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118656255A
    Figure CN118656255A
Patent Text Reader

Abstract

The invention provides a data service and database switching method and device, equipment, a medium and a product. The method comprises the following steps: acquiring environment information of a data node of a database cluster; the data nodes comprise a master node and a first slave node, and the master node is used for providing data service; determining environment difference information between the first slave node and the master node according to the environment information of the data node; according to the environment difference information, a standby master node is determined from the first slave nodes, and the standby master node is used as a new master node after data nodes in the database cluster are switched. According to the embodiment of the invention, the operation risk in the data service can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of database technology, and in particular to a data service and database switching method, device, electronic device, storage medium and computer program product. Background Art

[0002] A database cluster is an overall system consisting of a series of databases. It achieves high availability by replicating data into multiple databases through data redundancy. Therefore, at any time, at least one database can accept user requests and provide database services. Generally speaking, there is a primary database in a database cluster to process data requests, and several backup databases for disaster recovery switching. When the primary database cannot provide services, the backup database will continue to provide services as the new primary database through master-slave switching to ensure the availability and stability of the entire system. Summary of the invention

[0003] The present disclosure provides a data service method and device, an electronic device, and a storage medium.

[0004] In a first aspect, the present disclosure provides a data service method, comprising: obtaining environmental information of data nodes of a database cluster; the data nodes include a master node and a first slave node, the master node is used to provide data services; based on the environmental information of the data nodes, determining environmental difference information between the first slave node and the master node; based on the environmental difference information, determining a backup master node from the first slave node, the backup master node is used to serve as a new master node after a data node in the database cluster is switched.

[0005] In a second aspect, the present disclosure provides a database switching method, comprising: sending a data node switching request when a database cluster meets a data node switching condition; the database cluster comprises a data node, and the data node comprises a master node and a first slave node; when data node switching information is received, sending a data node switching instruction to the standby master node according to the architecture information and the information of the standby master node in the data node switching information, so as to set the standby master node as a new master node; wherein the standby master node is determined from the first slave node according to the above-mentioned data service method.

[0006] In a third aspect, the present disclosure provides a data service device, including:

[0007] An environment information acquisition module, used to acquire environment information of a data node of a database cluster; the data node includes a master node and a first slave node, and the master node is used to provide data services;

[0008] A difference information acquisition module, used to determine the environment difference information between the first slave node and the master node according to the environment information of the data node;

[0009] The standby master determination module is used to determine a standby master node from the first slave nodes according to the environmental difference information, and the standby master node is used to serve as a new master node after the data node in the database cluster is switched.

[0010] In a fourth aspect, the present disclosure provides a database switching device, comprising:

[0011] A request sending module, used to send a data node switching request when the database cluster meets the data node switching condition; the database cluster includes data nodes, and the data nodes include a master node and a first slave node;

[0012] A node switching module is used to send a data node switching instruction to the backup master node when receiving data node switching information, based on the architecture information and information of the backup master node in the data node switching information, so as to set the backup master node as the new master node; wherein the backup master node is determined from the first slave node based on the above-mentioned data service device.

[0013] In a fifth aspect, the present disclosure provides an electronic device comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores one or more computer programs executable by the at least one processor, and one or more of the computer programs are executed by the at least one processor so that the at least one processor can execute the above-mentioned data service method or database switching method.

[0014] In a sixth aspect, the present disclosure provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program implements the above-mentioned data service method or database switching method when executed by a processor.

[0015] In the seventh aspect, the present disclosure provides a computer program product, including a computer-readable code, or a non-volatile computer-readable storage medium carrying a computer-readable code. When the computer-readable code runs in a processor of an electronic device, the processor in the electronic device executes the data service method or database switching method as described above.

[0016] According to the embodiments of the present disclosure, it is possible to obtain environmental information of data nodes of a database cluster, determine environmental difference information between a first slave node and a master node, and then determine a standby master node from a plurality of first slave nodes based on the environmental difference information, thereby reducing the operating environment difference between the standby master node and the master node, and reducing the operating risks caused by the operating environment difference between the master and slave nodes.

[0017] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] The accompanying drawings are used to provide a further understanding of the present disclosure and constitute a part of the specification. Together with the embodiments of the present disclosure, they are used to explain the present disclosure and do not constitute a limitation of the present disclosure. The above and other features and advantages will become more apparent to those skilled in the art by describing detailed example embodiments with reference to the accompanying drawings, in which:

[0019] Figure 1 It is a flowchart of a master-slave switching method of a database in the related art;

[0020] Figure 2 An application scenario diagram of a data service method provided by an embodiment of the present disclosure;

[0021] Figure 3 A flowchart of a data service method provided by an embodiment of the present disclosure;

[0022] Figure 4 A schematic diagram of the architecture of a data service method provided by an embodiment of the present disclosure;

[0023] Figure 5 A flowchart of a database switching method provided by an embodiment of the present disclosure;

[0024] Figure 6a and Figure 6b A schematic diagram of an application scenario of a data service method provided by an embodiment of the present disclosure;

[0025] Figure 7 A block diagram of a data service device provided in an embodiment of the present disclosure;

[0026] Figure 8 A block diagram of a database switching device provided in an embodiment of the present disclosure;

[0027] Fig. 9 A block diagram of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION

[0028] In order to enable those skilled in the art to better understand the technical solutions of the present disclosure, the exemplary embodiments of the present disclosure are described below in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, those of ordinary skill in the art should recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, the description of well-known functions and structures is omitted in the following description.

[0029] In the absence of conflict, the various embodiments of the present disclosure and the various features therein may be combined with each other.

[0030] As used herein, the term "and / or" includes any and all combinations of one or more of the associated listed items.

[0031] The terms used herein are only used to describe specific embodiments and are not intended to limit the present disclosure. As used herein, the singular forms "a" and "the" are also intended to include plural forms, unless the context clearly indicates otherwise. It will also be understood that when the terms "including" and / or "made of" are used in this specification, the presence of the features, wholes, steps, operations, elements and / or components is specified, but the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or groups thereof is not excluded. "Connected" or "connected" and similar words are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect.

[0032] Unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as commonly understood by those of ordinary skill in the art. It will also be understood that terms such as those defined in commonly used dictionaries should be interpreted as having a meaning consistent with their meaning in the context of the relevant art and the present disclosure, and will not be interpreted as having an idealized or overly formal meaning unless explicitly defined as such herein.

[0033] In the related technology, the master-slave switching scheme of the database (switching between the master node and the slave node) mainly considers the consistency of the data after the switch. However, the risk of inconsistent operating environment of the database before and after the switch may not be as direct as the impact of inconsistent data, but the hidden dangers are no less than data inconsistency. In some cases, it may even cause serious performance problems, compatibility problems, program errors, etc.

[0034] There are many high-availability architectures for database clusters in the related technology. Taking the commonly used relational database MySQL as an example, there are MGR (MySQL Group Replication, MySQL group replication, is an architectural model of MySQL database cluster), MHA (MySQL High-Available, MySQL high availability, is an open source third-party software that can automatically initiate database fault switching to ensure high availability), Orchestrator (Orchestrator, a visual management tool that provides high availability and topology for MySQL replication) and other technical solutions. However, in the above-mentioned various technical solutions, there is no complete environment check algorithm to check the database operating environment before the master-slave switch. Even considering the environmental changes before and after the database switch, it is generally achieved through manual comparison. Therefore, there is an urgent need for a technical solution to reduce the risk of master-slave switching failure caused by the inconsistency of the database operating environment.

[0035] Figure 1 FIG. 1 is a flowchart of a master-slave switching method of a database in the related art. Figure 1 As shown in the figure, when the database master-slave switch is required, the database operation and maintenance personnel collect and check the environment information of the operating environment of the master node and the operating environment of the slave node in the database cluster, manually compare the environment information of each slave node with the master node, and select a relatively better slave node as the standby master (standby master node), and set it as the new master node when the master-slave switch is required, so as to complete the master-slave switch process of the database. However, the database operating environment is generally more complex. Take MySQL as an example. There are hundreds of database-level parameters, as well as operating system-level parameters, DNS domain names of database instance servers, etc. This leads to a very large delay in manual judgment. When the master node is unavailable and the master-slave switch is required, either wait for the manual inspection and correction to be completed, or take the risk of inconsistent master-slave environment information and switch directly, which may directly lead to the failure of the master-slave switch. In addition, there are large individual differences among operation and maintenance personnel, and many factors such as knowledge mastering degree, operation and maintenance experience, operation speed, professional quality, and external environment all affect the final result.

[0036] Figure 2 An application scenario diagram of a data service method provided in an embodiment of the present disclosure.

[0037] like Figure 2As shown, the application scenarios of the embodiments of the present disclosure may include a database cluster and a detection server. Among them, the database cluster may include multiple data nodes, which can provide external data services through database instances set in the data nodes. The data nodes include a master node, and slave nodes such as slave node a and slave node b. After the data is written to the master node, the data is synchronized to each slave node through the data change log. In scenarios such as the master node crashing, the slave node can be switched to the master node to continue to provide data services.

[0038] The detection server can obtain the environment information of the database cluster to perform environment detection on the data nodes in the database cluster. For example, a client (Agent) is set on the server where each data node is located, and the detection server can be set as a server (Server) corresponding to the client (Agent).

[0039] It should be noted that the data service method provided in the embodiment of the present disclosure can be executed by the detection server. Accordingly, the data service device provided in the embodiment of the present disclosure can be set in the detection server. In some cases, the detection server can be a server in a database cluster, for example, the detection server can also be used as a slave node or management node in the database cluster, and the present disclosure does not limit this.

[0040] It should be understood that Figure 2 The number and relationship of the master node and slave node in the database cluster are only illustrative. According to the implementation requirements, the database cluster can have any number of master nodes and slave nodes, and the present disclosure does not limit this.

[0041] Figure 3 The flowchart of a data service method provided by the embodiment of the present disclosure is as follows. The method can be applied to a detection server, such as Figure 3 As shown, the method comprises the following steps:

[0042] Step 31, obtaining environmental information of a data node of a database cluster; the data node includes a master node and a first slave node, and the master node is used to provide data services;

[0043] Step 32, determining environmental difference information between the first slave node and the master node according to the environmental information of the data node;

[0044] Step 33: Determine a backup master node from the first slave nodes according to the environmental difference information, and the backup master node is used to serve as a new master node after the data node in the database cluster is switched.

[0045] For example, a database cluster may include multiple data nodes for storing databases, and may provide external data services through database instances set in the data nodes. Data nodes may be divided into master nodes and slave nodes (hereinafter referred to as first slave nodes), where the master node is the data node currently providing data services, and the first slave node is a standby data node used to perform data backup or data synchronization for the master node, and where the slave node may become the new master node to continue providing data services when data node switching is required.

[0046] In some embodiments, the detection server may obtain the environmental information of the data nodes of the database cluster in step 31. Among them, a scheduled task may be set to collect the environmental information of each data node in a certain time period (e.g., 1 hour, 1 day). For example, a scheduled task may be set in the detection server, and when the time period is reached, the detection server sends an information collection instruction to each data node respectively, and the data node responds to the information collection instruction and sends its own environmental information to the detection server; a scheduled task may also be set in each data node, and when the time period is reached, each data node actively reports its own environmental information to the detection server, and the present disclosure does not limit this.

[0047] In some embodiments, the environment information of the data node may include at least one of instance parameter information corresponding to the data node, server configuration information of the data node, and configuration information of a database cluster.

[0048] Among them, the instance parameter information corresponding to the data node includes parameter information of the database instance of the data node, such as the version of the database instance, the database version, Gtid_purged (this parameter is a function in MySQL for viewing or operating GTID (global transaction identifier)), Sql_mode (this parameter is a set of syntax verification rules in MySQL), Innodb_buffer_pool_size (this parameter is a variable for buffer pool configuration in MySQL), and other parameters.

[0049] The server configuration information of the data node includes the server's operating system type (such as Unix or Linux) and version, the server's hardware configuration information (such as CPU model, memory type and size, etc.), and other information.

[0050] The configuration information of the database cluster includes the architecture information of the database cluster (for example, MGR, MHA or Orchestrator), backup task information, and the like.

[0051] In this way, the environment information may include multiple environment items, each of which corresponds to a parameter information or configuration information. It should be understood that those skilled in the art may set the specific content of the environment information according to actual conditions, and the present disclosure does not limit the number and type of environment items included in the environment information.

[0052] In some embodiments, according to the environment information of the data nodes of the database cluster, the environment difference information between each first slave node and the master node may be determined in step 32 .

[0053] For any first slave node, the environment information of the first slave node can be compared item by item with the corresponding environment items in the environment information of the master node. For example, the versions of the database instances, database versions, and server operating system types can be compared. For a certain environment item (such as the syntax check rule Sql_mode), if the environment item is the same, no processing is performed and the next environment item is compared; if the environment item is different, the environment item is recorded as the difference item of the first slave node relative to the master node.

[0054] In some embodiments, after comparing all environmental items, environmental difference information between the first slave node and the master node can be obtained. The environmental difference information is used to characterize the difference items of the first slave node relative to the master node. If there are no difference items between the first slave node and the master node, the environmental difference information can be represented as no difference between the first slave node and the master node; if there are difference items between the first slave node and the master node, the environmental difference information can be represented as a set of difference items between the first slave node and the master node.

[0055] In this way, the above processing is performed on each first slave node respectively, and the environmental difference information between all the first slave nodes and the master node can be determined.

[0056] In some embodiments, according to the environmental difference information of the plurality of first slave nodes, a standby master node may be determined from the plurality of first slave nodes in step 33 to serve as a new master node after the data node in the database cluster is switched. If there is a first slave node that is indistinguishable from the master node among the plurality of first slave nodes, the first slave node may be directly used as the standby master node; if there is no first slave node that is indistinguishable from the master node, a judgment may be made according to the difference items in the environmental difference information.

[0057] In some embodiments, among the difference items of the environmental difference information, some difference items have a high risk level, which may cause the data node switching failure and must be corrected and aligned. The first slave node with such difference items cannot be used as a backup master node; some difference items have a low risk level and will not cause the data node switching failure. The first slave node with only such difference items can be selected as the backup master node. If there are multiple first slave nodes to be selected, the environmental difference index of the first slave node can be determined according to the weight value of each difference item of the first slave node, and then the optimal backup master node can be selected.

[0058] According to the embodiments of the present disclosure, it is possible to obtain the environmental information of the data nodes of the database cluster, determine the environmental difference information between the first slave node and the master node, and then determine the backup master node from the first slave node according to the environmental difference information. Compared with the processing method of manually comparing environmental differences when switching data nodes, the embodiments of the present disclosure can effectively reduce the operating risks caused by the operating environment differences between the master and slave nodes, and significantly improve the processing efficiency, while helping to increase the speed of data node switching and reduce the time required for data node switching.

[0059] The data service method of the embodiment of the present disclosure is described below.

[0060] Before step 31, a detection server, which may also be called a database environment information automatic inspection system, may be set up to perform environment detection; and a database cluster corresponding to the detection server may be set up.

[0061] Figure 4 The following is a schematic diagram of the architecture of a data service method provided by an embodiment of the present disclosure. Figure 4 As shown, the detection server may correspond to multiple database clusters, including cluster A, cluster B, ... cluster N, each database cluster includes multiple data nodes, the data nodes of cluster A include master node A, slave node A1, ... slave node Am1; the data nodes of cluster B include master node B, slave node B1, ... slave node Bm2; ...; the data nodes of cluster N include master node N, slave node N1, ... slave node NmN. Wherein, N is the number of clusters; m1, ..., mN are the numbers of slave nodes of each cluster, and the present disclosure does not limit their specific values.

[0062] In some embodiments, an alignment rule between a master node and a slave node may be set in the detection server. The alignment rule may be an alignment rule for all database clusters corresponding to the detection server, an alignment rule for a certain database cluster, an alignment rule for certain nodes in a certain database cluster, etc. The present disclosure does not impose any restrictions on this.

[0063] In some embodiments, the alignment rules may include the environment items that need to be forcibly aligned, the environment items that do not need to be forcibly aligned, and the weight values ​​of each environment item in the environment information of the data node. Each environment item corresponds to a parameter information or configuration information, including the instance parameter information corresponding to the data node, the server configuration information of the data node, and the configuration information of the database cluster. The instance parameter information includes, for example, the database version, important database parameters (such as the above-mentioned Gtid_purged, Sql_mode, Innodb_buffer_pool_size, etc.); the server configuration information includes, for example, the operating system type and hardware configuration information; the configuration information of the database cluster includes the high-availability architecture information of the database cluster (for example, MGR, MHA or Orchestrator), backup task information, etc.

[0064] In some embodiments, the environment items that need to be forced to align are those that reach the target risk level and the differences between the master node and the slave node may cause the data node switching failure; the environment items that do not need to be forced to align are those that do not reach the target risk level and the differences between the master node and the slave node will not cause the data node switching failure. Among them, the environment items that do not need to be forced to align can also be divided into ignorable environment items (the weight value can be set to 0) and non-ignorable environment items (the weight value is not 0).

[0065] It should be understood that those skilled in the art may set the content and specific type of the environment items according to actual conditions, for example, setting the weight value of the environment items that require forced alignment to be higher and the weight value of the environment items that do not require forced alignment to be lower, etc. The present disclosure does not impose any restrictions on this.

[0066] After determining the alignment rule, the detection server may obtain the environment information of the data nodes of each database cluster in a certain time period in step S31.

[0067] For any database cluster, according to the environmental information of the data nodes of the database cluster acquired in the current time period, the environmental difference information between each first slave node and the master node can be determined in step S32.

[0068] For any first slave node, the environment information of the first slave node can be compared item by item with the corresponding environment items in the environment information of the master node. For example, the versions of the database instances, database versions, and server operating system types can be compared. For a certain environment item (such as the syntax check rule Sql_mode), if the environment item is the same, no processing is performed and the next environment item is compared; if the environment item is different, the environment item is recorded as the difference item of the first slave node relative to the master node.

[0069] In some embodiments, after comparing all environmental items, environmental difference information between the first slave node and the master node can be obtained. The environmental difference information is used to characterize the difference items of the first slave node relative to the master node. If there are no difference items between the first slave node and the master node, the environmental difference information can be represented as no difference between the first slave node and the master node; if there are difference items between the first slave node and the master node, the environmental difference information can be represented as a set of difference items between the first slave node and the master node.

[0070] In this way, by performing the above processing on each first slave node respectively, the environmental difference information between all the first slave nodes and the master node can be determined, so as to subsequently select a backup master node from the first slave nodes.

[0071] In some embodiments, the environmental information of the data node also includes delay information of the data node. The delay information can be used to indicate the delay of the slave node relative to the master node. The delay information can be the master-slave delay time (Seconds_Behind_Master), which can be obtained by the current timestamp at the slave node and the timestamp carried by the data change log. The present disclosure does not limit the specific method of obtaining the delay information.

[0072] In some embodiments, if the delay information of the first slave node is greater than the preset delay threshold, data loss may occur, resulting in poor performance of the database cluster. Therefore, in a high-availability architecture, the first slave node whose delay information is less than or equal to the preset delay threshold can be preferentially selected as the backup master node to improve the performance of the database cluster. The present disclosure does not limit the specific value of the preset delay threshold.

[0073] In some embodiments, in step S33, the step of determining a backup master node from the first slave node according to the environment difference information may include:

[0074] If the delay information of the first slave node is less than or equal to a preset delay threshold, determining the first slave node as a second slave node;

[0075] According to the environmental difference information, a backup master node is determined from the second slave nodes.

[0076] That is, the delay information can be used to screen the slave nodes whose delay information is less than or equal to the preset delay threshold in the first slave nodes as candidate backup master nodes (hereinafter referred to as second slave nodes) to form a backup candidate list. Then, according to the environment difference information of the second slave nodes in the candidate list, the backup master node is determined from the second slave nodes.

[0077] In this way, preliminary screening can be performed based on delay information to ensure the stability of data services and reduce or avoid data loss. Then, based on environmental difference information, the backup master node with the best environmental consistency with the master node can be screened out, thereby reducing the operational risks caused by differences in the operating environments of the master and slave nodes.

[0078] In some embodiments, determining a standby master node from the second slave nodes according to the environment difference information includes:

[0079] If the risk levels of the difference items in the environment difference information of the second slave node are all lower than the target risk level, determining the second slave node as the third slave node;

[0080] Determining an environment difference index of the third slave node according to a weight value of a difference item in the environment difference information of the third slave node;

[0081] A backup master node is determined from the third slave nodes according to the environment difference index of the third slave nodes.

[0082] For example, for each second slave node in the candidate list, its environmental difference information may include one or more difference items; according to the alignment rule between the master node and the slave node, the risk level of the difference items in the environmental difference information of the second slave node can be determined. Among them, a target risk level can be set, and the difference items that reach the target risk level are the environmental items that need to be forcibly aligned. Such difference items have a greater risk of causing data node switching failure, and the corresponding second slave node can be directly eliminated.

[0083] In some embodiments, if the risk levels of the difference items in the environmental difference information of the second slave node are all lower than the target risk level, that is, the difference items between the second slave node and the master node do not include the difference items that reach the target risk level, then the second slave node can be determined as the third slave node for further screening. Conversely, if there are difference items with a risk level greater than or equal to the target risk level in the difference items in the environmental difference information of the second slave node, then the second slave node can be removed from the candidate list. In this way, the above processing is performed on each second slave node respectively, and a third slave node that meets the conditions can be determined.

[0084] In some embodiments, the weight values ​​of environmental items that have reached the target risk level and require forced alignment can be set to a higher value, and the weight values ​​of environmental items that have not reached the target risk level and do not require forced alignment can be set to a lower value. Subsequently, judgment is made only by using the environmental difference index obtained by weighted summation of the weight values. The present disclosure does not limit the specific implementation method.

[0085] In some embodiments, for each third slave node, the weight value of the difference item in the environmental difference information of the third slave node can be determined; then, the difference items in the environmental difference information are weighted and summed according to the weight value to obtain the environmental difference index of the third slave node. The environmental difference index is used to characterize the difference between the environmental information of the third slave node and the environmental information of the master node. In this way, the above processing is performed on each third slave node respectively, and the environmental difference index of all third slave nodes can be determined.

[0086] In some embodiments, based on the environmental difference index of the third slave node, a backup master node may be determined from the third slave node. This step may include:

[0087] Among the third slave nodes whose environmental difference index meets the preset threshold condition, the third slave node whose operating environment difference with the master node is the smallest is used as the backup master node.

[0088] For example, a preset threshold condition of the environmental difference index can be set. If a third slave node does not meet the preset threshold condition, it is considered that the operating environment of the third slave node is greatly different from that of the master node, and the data node switching success rate is low, and it can be removed from the candidate list; if a third slave node meets the preset threshold condition, it is considered that the operating environment of the third slave node is less different from that of the master node, and the data node switching success rate is high, and it can be retained in the candidate list. The preset threshold condition can be a value or a range interval, and the present disclosure does not limit the specific setting method of the preset threshold condition.

[0089] In some embodiments, if there is a third slave node whose environmental difference index meets the preset threshold condition, the third slave node with the smallest difference in operating environment with the master node can be selected from the third slave nodes as the backup master node. Conversely, if there is no third slave node whose environmental difference index meets the preset threshold condition, it can be determined that there is no backup master node that meets the requirements among the first slave nodes of the database cluster, and a corresponding alarm message is sent to remind relevant personnel (such as operation and maintenance personnel) to handle it.

[0090] In this way, it is possible to screen based on the environmental difference index and determine a backup master node with better environmental consistency with the master node, thereby reducing the operational risks caused by differences in the operating environments of the master and slave nodes and improving processing efficiency.

[0091] In some embodiments, if the delay information of all first slave nodes is large, the slave node with the smallest delay may be selected as the backup master node. The data service method according to the embodiment of the present disclosure also includes:

[0092] If the delay information of the first slave nodes is greater than the preset delay threshold, the first slave node with the smallest delay information and whose difference items in the environmental difference information are all less than the target risk level will be determined as the backup master node.

[0093] For example, if the delay information of the first slave nodes is greater than the preset delay threshold, it means that the delays of all the first slave nodes are relatively large. In this case, screening can be performed according to the types of delay information and difference items.

[0094] For any first slave node, if there are difference items that reach the target risk level in the difference items of the first slave node's environmental difference information, the risk of data node switching failure is high and it can be directly eliminated; if the difference items of the first slave node's environmental difference information are all less than the target risk level, it can be used as a candidate backup master node. If there are multiple first slave nodes selected, the first slave node with the smallest delay information can be determined as the backup master node, thereby reducing the risk of data loss.

[0095] In some embodiments, if there are difference items in the difference items of the environmental difference information of all first slave nodes that reach the target risk level, it can be determined that there is no backup master node that meets the requirements among the first slave nodes, and a corresponding alarm message is sent to remind relevant personnel (such as operation and maintenance personnel) to handle it.

[0096] In this way, environmental differences and data delays can be taken into account when selecting a backup master node, while reducing the risk of data node switching and data loss, and improving the success rate of data node switching.

[0097] In some embodiments, after determining the environmental difference information between the first slave node and the master node in step S32, relevant information for adjusting the environmental difference information may also be generated and sent. The data service method according to the embodiment of the present disclosure further includes:

[0098] According to the environment difference information and the preset alignment rule, when the environment difference information of the first slave node includes a difference item to be repaired, generating an environment adjustment instruction for the first slave node and sending the instruction to the first slave node;

[0099] Among them, the difference items to be repaired include difference items in the environment information of the first slave node to be adjusted to be consistent with the environment information of the master node, and the environment adjustment instruction is used to instruct the difference items to be repaired in the environment information of the first slave node to be adjusted to be consistent with the environment information of the master node.

[0100] For example, in actual applications, the environment information of a data node includes instance parameter information corresponding to the data node, server configuration information of the data node, and configuration information of the database cluster, etc. Among them, some difference items can be directly aligned with the environment of the master node, such as Gtid_purged (this parameter is a function in MySQL for viewing or operating GTID (global transaction identifier)), etc.; other difference items cannot be aligned with the environment of the master node, such as the database version number, the server's operating system type, etc.

[0101] In some embodiments, the alignment rule set in the detection server may further include: whether the difference item between the master node and the slave node includes a repairable environmental item. If the difference item between the master node and the slave node includes a repairable environmental item, it may be referred to as a difference item to be repaired, and the difference item to be repaired includes a difference item in the environmental information of the first slave node to be adjusted to be consistent with the environmental information of the master node.

[0102] In some embodiments, for any first slave node, based on the environment difference information of the first slave node and a preset alignment rule, it can be determined whether the environment difference information includes a difference item to be repaired; if the environment difference information includes a difference item to be repaired, the detection server can generate an environment adjustment instruction for the first slave node, wherein the environment adjustment instruction is used to instruct the difference item to be repaired in the environment information of the first slave node to be adjusted to be consistent with the environment information of the master node. The present disclosure does not limit the specific method of generating the environment adjustment instruction.

[0103] In some embodiments, the detection server may send the environment adjustment instruction to the first slave node, directly instructing the first slave node to adjust the difference item to be repaired to be consistent with the environment information of the master node; it may also be sent to the master node or management node of the database cluster, etc., so that the master node or management node of the database cluster adjusts the difference item to be repaired of the first slave node to be consistent with the environment information of the master node. The present disclosure does not limit the specific sending method of the environment adjustment instruction and the specific adjustment method of the first slave node.

[0104] In some embodiments, if the environmental difference information of the first slave node includes an irreparable difference item, that is, a difference item that cannot be adjusted to be consistent with the environmental information of the master node, the detection server may also generate environmental adjustment prompt information for the first slave node and send it to the operation and maintenance personnel. The environmental adjustment prompt information is used to prompt the operation and maintenance personnel to manually align the irreparable difference items in the first slave node.

[0105] In this way, after determining the environmental difference information, the environmental information of the first slave node can be adjusted to align the environmental information of the first slave node with the environmental information of the master node, thereby improving the environmental consistency between each first slave node and the master node, and effectively reducing the operating risks caused by the differences in the operating environments of the master and slave nodes.

[0106] In some embodiments, after determining the standby master node for the current time period and sending the environment adjustment instruction and environment adjustment prompt information, the detection server can obtain the environment information of the data node of the database cluster again in the next time period, repeat the processing of steps S31-S33, and determine the standby master node for the next time period again. In this way, the environment consistency between the standby master node and the master node can be better, which helps to further reduce the operation risk caused by the difference in the operation environment of the master and slave nodes after the data node is switched.

[0107] In some embodiments, when the database cluster meets the data node switching condition (for example, the master node is down) and needs to switch the data node, the database cluster will send a data node switching request to the detection server to obtain the information required for the data node switching. The data node switching request can be generated by the management node in the database cluster or a data node used for management, and the present disclosure does not limit this.

[0108] In this case, the data service method according to the embodiment of the present disclosure further includes:

[0109] In response to a data node switching request of the database cluster, generating data node switching information for the database cluster; the data node switching information is used to indicate setting the standby master node as a new master node in the database cluster;

[0110] The data node switching information is sent to the database cluster.

[0111] For example, if the detection server receives a data node switching request of a database cluster, data node switching information for the database cluster may be generated. The data node switching information may include architecture information of the database cluster (such as MGR or MHA), information of the standby master node, etc., for indicating that the standby master node is set as the new master node in the database cluster. The data node switching information may also include a data node switching instruction, and the present disclosure does not limit the specific content included in the data node switching information.

[0112] In some embodiments, the detection server may send the data node switching information to the management node of the database cluster, a certain data node for management, or directly to the standby master node, so that the database cluster can perform data node switching. After receiving the data node switching information sent by the detection server, the database cluster sends a data node switching instruction to the standby master node according to the architecture information in the data node switching information and the information of the standby master node, so as to set the standby master node as the new master node.

[0113] In this way, the speed of data node switching can be improved and the time required for data node switching can be further reduced.

[0114] Figure 5 A flowchart of a database switching method provided in an embodiment of the present disclosure. The method can be applied to a database cluster, such as a management node of a database cluster or a data node for management. The database cluster includes multiple data nodes, the data nodes include a master node, and multiple first slave nodes for backing up data of the master node. Figure 5 As shown, the method comprises the following steps:

[0115] Step 51, when the database cluster meets the data node switching condition, send a data node switching request;

[0116] Step 52, when receiving the data node switching information, send a data node switching instruction to the backup master node according to the architecture information and the information of the backup master node in the data node switching information to set the backup master node as the new master node; wherein the backup master node is determined from the multiple first slave nodes according to the above-mentioned data service method.

[0117] For example, if the database cluster meets the data node switching condition and needs to switch the data node, a data node switching request will be sent to the detection server in step S51 to obtain the information required for the data node switching. Among them, the data node switching condition may include, for example, the main node is down, the delay of the main node is greater than the delay threshold, the performance of the database cluster is lower than the performance threshold, the data loss rate / error rate of the main node reaches the loss threshold / error threshold, the instruction of the operation and maintenance personnel to switch the data node is received, and the preset data node switching time is reached, etc. The present disclosure does not limit the specific setting of the data node switching condition.

[0118] In some embodiments, the detection server may generate data node switching information in response to the data node switching request and send it to the database cluster for the database cluster to perform data node switching. The data node switching information may include architecture information of the database cluster (such as MGR or MHA), information of the standby master node, etc.

[0119] In some embodiments, after receiving the data node switching information sent by the detection server, the database cluster generates a data node switching instruction based on the architecture information and the information of the standby master node in the data node switching information, and sends the data node switching instruction to the standby master node to set the standby master node as the new master node. If the data node switching information sent by the detection server includes the data node switching instruction, the data node switching instruction can be directly forwarded to the standby master node.

[0120] exist Figure 4 In the example, the data node switching process can be implemented by an independent management node. When a certain database cluster (such as cluster A) meets the data node switching conditions, the management node sends a data node switching request (not shown) for the database cluster to the detection server to obtain the architecture information (such as MGR or MHA) and the information of the backup master node required for the data node switching; a data node switching instruction is generated according to the architecture information and the information of the backup master node, and the data node switching instruction is sent to set the backup master node as the new master node.

[0121] In some embodiments, after setting the standby master node as the new master node, the database cluster can broadcast the information of the new master node to all nodes or servers using the database cluster so that the new master node can provide data services; and the database cluster can deactivate the original master node, or change the master node to a slave node, thereby completing the entire process of data node switching.

[0122] In this way, when the data node is switched, the architecture information and the information of the backup master node can be obtained from the detection server, and the data node switching instruction can be generated and sent to set the backup master node as the new master node, thereby effectively reducing the operating risks caused by the differences in the operating environment of the master and slave nodes, and at the same time helping to increase the speed of data node switching and reduce the time required for data node switching.

[0123] In some possible implementations, the database switching method provided according to the embodiment of the present disclosure further includes:

[0124] receiving an environment adjustment instruction for the first slave node sent by the detection server;

[0125] In response to the environment adjustment instruction, the difference items to be repaired in the environment information of the first slave node are adjusted to be consistent with the environment information of the master node; the difference items to be repaired include the difference items in the environment information of the first slave node to be adjusted to be consistent with the environment information of the master node.

[0126] In some embodiments, the environment adjustment instruction may be determined by the detection server according to the environment difference information of the first slave node and a preset alignment rule. The present disclosure does not limit the specific content of the environment adjustment instruction and the specific adjustment method of the environment information of the first slave node.

[0127] In the disclosed embodiment, after obtaining the environment adjustment instruction for the first slave node, the difference item to be repaired in the environment information of the first slave node is adjusted to be consistent with the environment information of the master node. Thus, the environment information of the first slave node is aligned with the environment information of the master node, thereby improving the environment consistency of each first slave node and the master node, and effectively reducing the operation risk caused by the difference in the operation environment of the master and slave nodes.

[0128] Figure 6a and Figure 6b A schematic diagram of an application scenario of a data service method provided by an embodiment of the present disclosure. Figure 6a As shown, alignment rules can be pre-defined in the detection server, and the alignment rules may include alignment rules for all global data nodes of all database clusters corresponding to the detection server, alignment rules for data nodes within a certain database cluster, alignment rules for specific data nodes in a certain database cluster, etc., and the present disclosure does not impose any restrictions on this.

[0129] In the example, the alignment rules may include the environment items that need to be forcibly aligned, the environment items that do not need to be forcibly aligned, and the weight values ​​of each environment item in the environment information of the data node. Each environment item corresponds to a parameter information or configuration information, including the instance parameter information corresponding to the data node, the server configuration information of the data node, and the configuration information of the database cluster. The instance parameter information includes, for example, the database version, important database parameters (such as the above-mentioned Gtid_purged, Sql_mode, Innodb_buffer_pool_size, etc.); the server configuration information includes, for example, the operating system type and hardware configuration information; the configuration information of the database cluster includes the high-availability architecture information of the database cluster (for example, MGR, MHA or Orchestrator), backup task information, etc.

[0130] In the example, after determining the alignment rules, the detection server can schedule in a certain time period. When starting the first scheduling or a new scheduling, the environment information of multiple data nodes (agents) of each database cluster is collected; after receiving the environment information reported by each data node, the information can be summarized and the environment difference information between the environment information of the slave node and the environment information of the master node can be compared; the best backup master node is selected based on the environment difference information. If the selection is successful, the backup master node is recorded; if the selection fails, that is, all slave nodes do not meet the requirements, the corresponding alarm information can be sent to remind relevant personnel (such as operation and maintenance personnel) to handle it.

[0131] In the example, no matter whether the standby master node is selected successfully or failed, it can be determined whether each slave node has a difference item to be adjusted to be consistent with the environment information of the master node; if so, an environment adjustment instruction is sent to the corresponding slave node so that the slave node adjusts the difference item to be consistent with the environment information of the master node. In this way, the current scheduling process can be completed, and the scheduling can be ended or the next scheduling can be performed after the time period is reached.

[0132] In the example, Figure 6b As shown in the figure, when the database cluster meets the data node switching conditions and needs to switch the data node, the architecture information of the database cluster and the information of the standby master node can be obtained from the detection server; the data node switching instruction is generated according to the architecture information and sent to the standby master node, thereby completing the data node switching process. If the standby master node information is not obtained from the detection server, an alarm message indicating that the standby master node failed to be obtained can be sent to remind relevant personnel to handle it.

[0133] According to the embodiments of the present disclosure, a detection server is provided, which can regularly collect the environmental information of the data nodes corresponding to each database instance in all database clusters; compare the environmental difference information between the master node and the slave node according to the environmental information and the preset alignment rules, and select the best node as the standby master node according to the environmental difference information, thereby reducing the difference in the operating environment between the standby master node and the master node, and reducing the risk caused by the difference in the operating environment between the master and slave nodes when the data node is switched. In addition, different adjustment strategies can be automatically generated according to the environmental difference information, and adjustment instructions can be sent to the corresponding slave nodes for adjustment and alignment; each scheduling will collect information on the environment in which all MySQL database instances are running and repair the environment that needs to be corrected and aligned, which can ensure that the operating environment before and after the MySQL database instance is switched is the same as much as possible, and provide the quality of database services.

[0134] According to the embodiments of the present disclosure, it is possible to implement detection and automatic alignment of environmental information of each data node in a MySQL database cluster; it can be applied to MHA high-availability architecture, Orchestrator, MGR and other high-availability management tools, to detect the server configuration of the new data node before the data node is switched, and to directly eliminate slave nodes with large environmental differences from the candidate list of backup master nodes based on the weight values ​​of each environmental item in the alignment rule, thereby reducing risks and improving efficiency; it is possible to directly eliminate delayed slave nodes, or when all slave nodes are delayed, automatically compare and select the slave node with the smallest delay as the backup master node, thereby reducing the risk of data node switching and the risk of data loss.

[0135] According to the embodiments of the present disclosure, it is possible to solve the errors or omissions that may occur in the process of manual information collection, comparison and repair, all environmental inspection items can be standardized, and all data nodes can be automatically aligned according to the specified alignment rules; it can greatly liberate manpower and reduce operation and maintenance costs. All operations can be automatically completed by the system, including information collection, comparison, repair and alignment, thereby improving processing efficiency.

[0136] According to the embodiments of the present disclosure, when the data node switching conditions are met, a new data node with the same environmental information as the master node can be pulled up through an environment configuration template based on the environment information of the master node, and it can be used as a backup master node, and a node switching operation can be performed. However, this operation is not suitable for emergency switching of data nodes, especially when the amount of data stored in the database is relatively large. This processing method can be used in scenarios where the database RTO (Recovery Time Object) requirements are not high, such as database test environments.

[0137] According to the embodiments of the present disclosure, the environment of the backup master node of the database cluster can also be strictly controlled, and any channel is prohibited from modifying the environmental information, so as to achieve the effect of keeping the environmental information consistent before and after the data node switch of the MySQL database.

[0138] It can be understood that the above-mentioned various method embodiments mentioned in the present disclosure can be combined with each other to form a combined embodiment without violating the principle logic. Due to space limitations, the present disclosure will not repeat them. It can be understood by those skilled in the art that in the above-mentioned method of the specific implementation method, the specific execution order of each step should be determined according to its function and possible internal logic.

[0139] Based on the same technical concept, the present disclosure also provides a data service device, a database switching device, an electronic device, a computer-readable storage medium, and a computer program product, all of which can be used to implement any data service method and database switching method provided by the present disclosure.

[0140] Figure 7 A block diagram of a data service device provided by an embodiment of the present disclosure. Figure 7 , the data service device comprises:

[0141] An environment information acquisition module 71 is used to acquire environment information of a data node of a database cluster; the data node includes a master node and a first slave node, and the master node is used to provide data services;

[0142] A difference information acquisition module 72, configured to determine environment difference information between the first slave node and the master node according to the environment information of the data node;

[0143] The standby master determining module 73 is used to determine a standby master node from the first slave nodes according to the environmental difference information, and the standby master node is used to serve as a new master node after the data node in the database cluster is switched.

[0144] In some embodiments, the standby master determination module 73 is used to:

[0145] If the delay information of the first slave node is less than or equal to a preset delay threshold, the first slave node is determined as the second slave node; and a backup master node is determined from the second slave nodes according to the environmental difference information.

[0146] In some embodiments, the standby master determination module 73 is used to:

[0147] If the risk levels of the difference items in the environmental difference information of the second slave node are all lower than the target risk level, the second slave node is determined as the third slave node; based on the weight values ​​of the difference items in the environmental difference information of the third slave node, the environmental difference index of the third slave node is determined; based on the environmental difference index of the third slave node, a backup master node is determined from the third slave node.

[0148] In some embodiments, the standby master determination module 73 is used to:

[0149] Among the third slave nodes whose environmental difference index meets the preset threshold condition, the third slave node whose operating environment difference with the master node is the smallest is used as the backup master node.

[0150] In some embodiments, the device also includes: a first determination module, used to: if the delay information of the first slave nodes is greater than a preset delay threshold, then the first slave node with the smallest delay information and the difference items in the environmental difference information are all less than the target risk level is determined as a backup master node.

[0151] In some embodiments, the apparatus further comprises: a difference repair module, configured to:

[0152] According to the environmental difference information and the preset alignment rules, when the environmental difference information of the first slave node includes difference items to be repaired, an environmental adjustment instruction for the first slave node is generated and sent to the first slave node; wherein the difference items to be repaired include difference items in the environmental information of the first slave node to be adjusted to be consistent with the environmental information of the master node, and the environmental adjustment instruction is used to instruct the difference items to be repaired in the environmental information of the first slave node to be adjusted to be consistent with the environmental information of the master node.

[0153] In some embodiments, the apparatus further comprises:

[0154] A switching information generating module, configured to generate data node switching information for the database cluster in response to a data node switching request of the database cluster; the data node switching information is used to indicate setting the standby master node as a new master node in the database cluster;

[0155] The switching information sending module is used to send the data node switching information to the database cluster.

[0156] Figure 8 A block diagram of a database switching device provided by an embodiment of the present disclosure. Figure 8 , the database switching device comprises:

[0157] A switching request sending module 81 is used to send a data node switching request when the database cluster meets the data node switching condition; the database cluster includes data nodes, and the data nodes include a master node and a first slave node;

[0158] A switching instruction sending module 82 is used to send a data node switching instruction to the standby master node according to the architecture information and the information of the standby master node in the data node switching information when receiving the data node switching information, so as to set the standby master node as a new master node;

[0159] The standby master node is determined from the first slave nodes according to the above data service method.

[0160] Each module in the above-mentioned data service device and database switching device can be implemented in whole or in part by software, hardware and a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute the operations corresponding to each module above.

[0161] Fig. 9 A block diagram of an electronic device provided in an embodiment of the present disclosure.

[0162] Reference Fig. 9 An embodiment of the present disclosure provides an electronic device, which includes: at least one processor 501; at least one memory 502, and one or more I / O interfaces 503, connected between the processor 501 and the memory 502; wherein the memory 502 stores one or more computer programs that can be executed by the at least one processor 501, and the one or more computer programs are executed by the at least one processor 501 so that the at least one processor 501 can execute the above-mentioned data service method or database switching method.

[0163] Each module in the above electronic device can be implemented in whole or in part by software, hardware, or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.

[0164] The present disclosure also provides a computer-readable storage medium on which a computer program is stored, wherein the computer program implements the above-mentioned data service method or database switching method when executed by a processor. The computer-readable storage medium may be a volatile or non-volatile computer-readable storage medium.

[0165] The embodiments of the present disclosure also provide a computer program product, including a computer-readable code, or a non-volatile computer-readable storage medium carrying the computer-readable code. When the computer-readable code runs in a processor of an electronic device, the processor in the electronic device executes the above-mentioned data service method or database switching method.

[0166] It will be appreciated by those skilled in the art that all or some of the steps, systems, and functional modules / units in the methods disclosed above may be implemented as software, firmware, hardware, and appropriate combinations thereof. In a hardware implementation, the division between the functional modules / units mentioned in the above description does not necessarily correspond to the division of physical components; for example, a physical component may have multiple functions, or a function or step may be performed by several physical components in cooperation. Some or all physical components may be implemented as software executed by a processor, such as a central processing unit, a digital signal processor, or a microprocessor, or may be implemented as hardware, or may be implemented as an integrated circuit, such as an application-specific integrated circuit. Such software may be distributed on a computer-readable storage medium, which may include a computer storage medium (or a non-transitory medium) and a communication medium (or a temporary medium).

[0167] As is known to those of ordinary skill in the art, the term computer storage media includes volatile and nonvolatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable program instructions, data structures, program modules or other data). Computer storage media include, but are not limited to, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), static random access memory (SRAM), flash memory or other memory technology, portable compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, magnetic disk storage or other magnetic storage devices, or any other medium that can be used to store desired information and can be accessed by a computer. In addition, it is known to those of ordinary skill in the art that communication media typically contain computer-readable program instructions, data structures, program modules or other data in a modulated data signal such as a carrier wave or other transmission mechanism, and may include any information delivery medium.

[0168] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmissions, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.

[0169] The computer program instructions for performing the operation of the present disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages, such as Smalltalk, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. Computer-readable program instructions may be executed completely on a user's computer, partially on a user's computer, as an independent software package, partially on a user's computer, partially on a remote computer, or completely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider to connect via the Internet). In some embodiments, an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA), may be customized by utilizing the state information of the computer-readable program instructions, and the electronic circuit may execute the computer-readable program instructions, thereby realizing various aspects of the present disclosure.

[0170] The computer program product described herein may be implemented in hardware, software, or a combination thereof. In one optional embodiment, the computer program product is embodied as a computer storage medium, and in another optional embodiment, the computer program product is embodied as a software product, such as a software development kit (SDK), etc.

[0171] Various aspects of the present disclosure are described herein with reference to the flowcharts and / or block diagrams of the methods, devices (systems) and computer program products according to the embodiments of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer-readable program instructions.

[0172] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processor of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.

[0173] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operating steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.

[0174] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to multiple embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a part of a module, program segment or instruction, and a part of the module, program segment or instruction includes one or more executable instructions for realizing the specified logical function. In some alternative implementations, the function marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous square boxes can actually be executed substantially in parallel, and they can sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs the specified function or action, or can be implemented with a combination of special hardware and computer instructions.

[0175] Example embodiments have been disclosed herein, and although specific terms are employed, they are used and should be interpreted only in a general illustrative sense and not for limiting purposes. In some instances, it will be apparent to those skilled in the art that, unless otherwise expressly noted, features, characteristics, and / or elements described in conjunction with a particular embodiment may be used alone or in combination with features, characteristics, and / or elements described in conjunction with other embodiments. Therefore, those skilled in the art will appreciate that various changes in form and detail may be made without departing from the scope of the present disclosure as set forth in the appended claims.

Claims

1. A data service method, It is characterized in that The method comprises: Obtaining environmental information of a data node of a database cluster; the data node includes a master node and a first slave node, and the master node is used to provide data services; Determine, according to the environmental information of the data node, environmental difference information between the first slave node and the master node; A standby master node is determined from the first slave nodes according to the environmental difference information, and the standby master node is used to serve as a new master node after a data node in the database cluster is switched.

2. The method according to claim 1, It is characterized in that The step of determining a standby master node from the first slave node according to the environmental difference information includes: If the delay information of the first slave node is less than or equal to a preset delay threshold, determining the first slave node as a second slave node; According to the environmental difference information, a backup master node is determined from the second slave nodes.

3. The method according to claim 2, It is characterized in that The step of determining a standby master node from the second slave nodes according to the environmental difference information includes: If the risk levels of the difference items in the environment difference information of the second slave node are all lower than the target risk level, determining the second slave node as the third slave node; Determining an environment difference index of the third slave node according to a weight value of a difference item in the environment difference information of the third slave node; A backup master node is determined from the third slave nodes according to the environment difference index of the third slave nodes.

4. The method according to claim 3, It is characterized in that Determining a standby master node from the third slave node according to the environment difference indicator of the third slave node includes: Among the third slave nodes whose environmental difference index meets the preset threshold condition, the third slave node whose operating environment difference with the master node is the smallest is used as the backup master node.

5. The method according to claim 2, It is characterized in that The method further comprises: If the delay information of the first slave nodes is greater than the preset delay threshold, the first slave node with the smallest delay information and whose difference items in the environmental difference information are all less than the target risk level will be determined as the backup master node.

6. The method according to claim 1, It is characterized in that The method further comprises: According to the environment difference information and the preset alignment rule, when the environment difference information of the first slave node includes a difference item to be repaired, generating an environment adjustment instruction for the first slave node and sending the instruction to the first slave node; Among them, the difference items to be repaired include difference items in the environment information of the first slave node to be adjusted to be consistent with the environment information of the master node, and the environment adjustment instruction is used to instruct the difference items to be repaired in the environment information of the first slave node to be adjusted to be consistent with the environment information of the master node.

7. The method according to claim 1, It is characterized in that The method further comprises: In response to a data node switching request of the database cluster, generating data node switching information for the database cluster; the data node switching information is used to indicate setting the standby master node as a new master node in the database cluster; The data node switching information is sent to the database cluster.

8. A database switching method, It is characterized in that The method comprises: When the database cluster meets the data node switching condition, sending a data node switching request; the database cluster includes data nodes, and the data nodes include a master node and a first slave node; When receiving the data node switching information, according to the architecture information and the information of the standby master node in the data node switching information, sending a data node switching instruction to the standby master node to set the standby master node as a new master node; The standby master node is determined from the first slave node according to the data service method according to any one of claims 1-7.

9. A data service device, It is characterized in that include: An environment information acquisition module is used to obtain environment information of data nodes in a database cluster; The data node includes a master node and a first slave node, and the master node is used to provide data services; A difference information acquisition module, used to determine the environment difference information between the first slave node and the master node according to the environment information of the data node; The standby master determination module is used to determine a standby master node from the first slave nodes according to the environmental difference information, and the standby master node is used to serve as a new master node after the data node in the database cluster is switched.

10. An electronic device, It is characterized in that include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores one or more computer programs that can be executed by the at least one processor, and the one or more computer programs are executed by the at least one processor to enable the at least one processor to execute the data service method as described in any one of claims 1 to 7 or the database switching method as described in claim 8.

11. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the computer program implements the data service method according to any one of claims 1 to 7 or the database switching method according to claim 8.

12. A computer program product, It is characterized in that The invention comprises a computer-readable code, or a non-volatile computer-readable storage medium carrying the computer-readable code. When the computer-readable code runs in a processor of an electronic device, the processor in the electronic device executes the data service method as described in any one of claims 1 to 7 or the database switching method as described in claim 8.

Citation Information

Cited By

  • Data transmission method of PLC cluster, medium and equipment

    CN120711013A

  • A data transmission method, medium and device of a PLC cluster

    CN120711013B