CN115905270A - Method and device for determining main data node in database and storage medium - Google Patents

Method and device for determining main data node in database and storage medium Download PDF

Info

Publication number
CN115905270A
CN115905270A CN202310017431.8A CN202310017431A CN115905270A CN 115905270 A CN115905270 A CN 115905270A CN 202310017431 A CN202310017431 A CN 202310017431A CN 115905270 A CN115905270 A CN 115905270A
Authority
CN
China
Prior art keywords
data
data node
nodes
target
node
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202310017431.8A
Other languages
Chinese (zh)
Other versions
CN115905270B (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.)
Jinzhuan Xinke Co Ltd
Original Assignee
Jinzhuan Xinke 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 Jinzhuan Xinke Co Ltd filed Critical Jinzhuan Xinke Co Ltd
Priority to CN202310017431.8A priority Critical patent/CN115905270B/en
Publication of CN115905270A publication Critical patent/CN115905270A/en
Application granted granted Critical
Publication of CN115905270B publication Critical patent/CN115905270B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application relates to a method, a device and a storage medium for determining a main data node in a database, wherein the method comprises the following steps: screening M quasi-new main data nodes from N data nodes under the condition that the main data nodes in the database have faults, wherein the database comprises N data nodes which comprise a main data node and L standby data nodes; selecting a target data node from M quasi-new main data nodes; the target data node is a quasi-new main data node with completed playback; and determining a new main data node from the target area based on the target data node, wherein the data on the new main data node is consistent with the data on the target data node, and N data nodes in the database are distributed in a plurality of areas. By the method and the device, the problem that in the prior art, the consistency of data before and after switching cannot be guaranteed in a mode of switching the main data node and the standby data node after the main data node fails is solved.

Description

Method and device for determining main data node in database and storage medium
Technical Field
The present application relates to the field of data processing, and in particular, to a method, an apparatus, and a storage medium for determining a primary data node in a database.
Background
For a long time, each component in the financial level distributed database adopts a master and a slave, or a master and a slave architecture to ensure the stability and reliability of the service.
Here, data nodes (DN for short) are used. Under normal conditions, data services issued by the computing nodes are written into the main DN, and the rest one or more standby DNs undertake the reading operation of the data services. The service processing mode realizes the read-write separation of the main machine and the standby machine and the load balance, and greatly improves the service processing capacity and the access performance of the database. When the primary DN fails, the service on the primary DN is required to be smoothly and quickly switched to the standby DN for execution, that is, the influence on the service is reduced as much as possible while data consistency is ensured. Because the switching is the basic function of the database, the switching efficiency between the main DN and the standby DN directly affects the high availability of the database, and is an important factor for determining whether the database can provide stable service.
At present, for the main-standby switching of data nodes in a database, the data amount on each DN is compared based on the playback thread of the database, and the comparison method has a problem because the playback thread can only reflect the playback condition of the DN nodes and cannot accurately reflect the synchronization condition. In a database, playback and synchronization are two concepts. The playback refers to the process that the standby machine sequentially executes the transaction logs synchronized from the main machine, and the playback thread of the standby machine determines the playback speed; synchronization refers to a process of sending a transaction execution log on a host computer to a standby computer, and a synchronization thread determines the speed of synchronization. Like DN1 and DN2, DN1 synchronizes faster but replays slowly, and DN2 synchronizes slower but replays quickly. After all nodes complete playback, the data amount on DN1 should be greater than DN2. And DN2 is finally raised according to the switching logic based on the playback thread, so the previous switching logic can cause data loss after switching.
Disclosure of Invention
The application provides a method, a device and a storage medium for determining a main data node in a database, which are used for solving the problem that the consistency of data before and after switching cannot be ensured in a mode of switching the main data node and the standby data node after the main data node fails in the prior art.
In a first aspect, the present application provides a method for determining a primary data node in a database, including: screening M quasi-new main data nodes from N data nodes under the condition that the main data nodes in the database have faults, wherein the database comprises the N data nodes, the N data nodes comprise one main data node and L standby data nodes, and M and L are positive integers smaller than N; selecting a target data node from the M quasi-new main data nodes; the target data node is a quasi-new main data node with completed playback; and determining a new primary data node from a target area based on the target data node, wherein the data on the new primary data node is consistent with the data on the target data node, the N data nodes in the database are distributed in a plurality of areas, and the target area is any one of the plurality of areas.
In a second aspect, the present application provides an apparatus for determining a primary data node in a database, including: the screening module is used for screening M quasi-new main data nodes from N data nodes under the condition that the main data nodes in the database have faults, wherein the database comprises the N data nodes, the N data nodes comprise one main data node and L standby data nodes, and M and L are positive integers smaller than N; a selection module, configured to select a target data node from the M quasi-new master data nodes; the target data node is a quasi-new main data node with completed playback; and the determining module is used for determining a new active data node from a target area based on the target data node, wherein the data on the new active data node is consistent with the data on the target data node, the N data nodes in the database are distributed in a plurality of areas, and the target area is any one of the plurality of areas.
In a third aspect, an electronic device is provided, which includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory complete communication with each other through the communication bus;
a memory for storing a computer program;
a processor adapted to perform the method steps of any of the embodiments of the first aspect when executing a program stored in the memory.
In a fourth aspect, a computer-readable storage medium is provided, on which a computer program is stored which, when being executed by a processor, carries out the method steps of any of the embodiments of the first aspect.
Compared with the prior art, the technical scheme provided by the embodiment of the application has the following advantages:
according to the method provided by the embodiment of the application, M quasi-new primary data nodes can be selected firstly, and then the quasi-new primary data nodes with completed playback are taken as the basis for determining the new primary data nodes from the M quasi-new primary data nodes, namely, the data on the new primary data nodes are consistent with the data on the target data nodes, so that the data consistency of the new primary data nodes and the old primary data nodes with faults is ensured, and the problem that the consistency of the data before and after switching cannot be ensured in a mode of switching the primary data nodes and the standby data nodes after the primary data nodes are in faults in the prior art is solved.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and together with the description, serve to explain the principles of the invention.
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious for those skilled in the art that other drawings can be obtained according to the drawings without inventive exercise.
Fig. 1 is a schematic flowchart of a method for switching a master/backup data node in a database according to an embodiment of the present application;
fig. 2 is a schematic flowchart of a database data node switching optimization method based on a synchronous thread according to an embodiment of the present application;
fig. 3 is a schematic structural diagram of a switching device for master and backup data nodes in a database according to an embodiment of the present application;
fig. 4 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are some embodiments of the present application, but not all embodiments. All other embodiments obtained by a person of ordinary skill in the art based on the embodiments in the present application without making creative efforts shall fall within the protection scope of the present application.
Fig. 1 is a schematic flowchart of a method for switching between a master data node and a standby data node in a database according to an embodiment of the present application, where as shown in fig. 1, the method includes:
101, screening M quasi-new main data nodes from N data nodes under the condition that the main data nodes in a database have faults, wherein the database comprises the N data nodes, the N data nodes comprise one main data node and L standby data nodes, and M and L are positive integers smaller than N;
in this embodiment of the present application, the M quasi-new active data nodes are preferentially data nodes having the most synchronized transactions from the failed active data node, that is, if only one data node in the current standby node has the most synchronized transactions, the number of the quasi-new active data nodes is one, and if a plurality of data nodes in the current standby node have the same synchronized transactions, the number of the quasi-new active data nodes may also be multiple. For example, if the value of N is 10 currently, where the data node 1 is a primary data node, and the primary data node has a fault, and for the remaining 9 data nodes, if the number of the data nodes 2, 5, and 8 synchronized from the data node 1 is the same, and is higher than the number of the other data nodes synchronized, the value of M is 3, then the primary data node is considered to be the data node 2, 5, and 8. Of course, the above is merely an example, and the corresponding setting may be specifically performed according to the actual situation.
102, selecting a target data node from the M quasi-new main data nodes, wherein the target data node is the quasi-new main data node with completed playback;
and 103, determining a new primary data node from the target area based on the target data node, wherein the data on the new primary data node is consistent with the data on the target data node, the N data nodes in the database are distributed in a plurality of areas, and the target area is any one of the plurality of areas.
It should be noted that, in the embodiment of the present application, in an actual scene, the area may be divided by a machine room, or may be divided by an actual region, for example, the unit is province, and for example, the unit is south area, and north area. And corresponding setting can be carried out according to actual conditions in specific application scenes.
As can be seen from steps 101 to 103, in the embodiment of the present application, M quasi-new primary data nodes may be selected first, and then the quasi-new primary data nodes whose playback is completed are taken as a basis for determining new primary data nodes from the M quasi-new primary data nodes, that is, data on the new primary data nodes are consistent with data on the target data node, so that data consistency between the new primary data nodes and the old primary data nodes having faults is ensured, thereby solving the problem in the prior art that the way of switching the primary and secondary data nodes cannot ensure data consistency before and after switching after the primary data nodes have faults.
In this embodiment of the present application, regarding the manner of screening M quasi-new active data nodes from the N data nodes in step 101 in this embodiment of the present application, the method further may include:
step 11, sending a request for inquiring the synchronization state to the N data nodes to inquire the synchronization sites of the N data nodes;
and step 12, determining the data node with the largest synchronization site field as a data node in the M quasi-new primary data nodes, wherein the M quasi-new primary data nodes are distributed in one or more areas.
It should be noted that, a field corresponding to the synchronization site is a transaction number of the primary data node that has been received by the standby data node, that is, a transaction set of the primary data node that indicates that the synchronization thread of the standby data node has been synchronized, and based on this, the larger the synchronization site is, the more transactions that the standby data node has been synchronized from the primary data node are. It can be seen that if there are multiple maximum synchronization points in the synchronization points of the standby data nodes, the number of the master and new master data nodes is also multiple. And the plurality of quasi-new active data nodes may be distributed in one or more areas, in a specific example, in one or more rooms. That is to say, in the application, the data node with the most replayed transactions can be used as the quasi-new primary data node, that is, the replayed transaction of the determined quasi-new primary data node is also completed first, so that it is ensured that a new primary data node is determined from a target area based on a target data node subsequently, so that data on the new primary data node is consistent with data on the target data node, the efficiency of switching the new primary data node is improved on the premise of ensuring data consistency, and the switching time is saved.
In this embodiment of the present application, if N data points in the database are distributed in multiple areas, and a data node in one of the areas may be used as a new active data node according to actual requirements, the manner, which is referred to in step 103 in this embodiment of the present application, of determining the new active data node from the target area based on the target data node may further include:
step 21, sending equal playback requests to M quasi-new main data nodes;
step 22, determining whether a first target data node is in a target area under the condition that a first target data node with finished playback exists in the M quasi-new main data nodes; the target area is an area to be provided with a new main data node;
step 23, determining the first target data node as a new primary data node when the first target data node is in the target area;
24, when the first target data node is not in the target area and the quasi-new primary data node does not exist in the target area, data is chased from the first target data node based on a second target data node in the target area, and the second target data node is determined as new primary data after the data is successfully chased;
and step 25, when the first target data node is not in the target area and the quasi-new primary data node exists in the target area, after the completion of the playback of the quasi-new primary data node in the target area, determining the quasi-new primary data node in the target area as new primary data.
As can be seen from the above steps 21 to 25, if the quasi-new primary data node that has completed playback is in the area where the new primary data node is set, the quasi-new primary data node can be directly used as the new primary data node, which also improves the efficiency of switching the new primary data node and saves the switching time on the premise of ensuring the data consistency. If the quasi-new main data node which completes the playback at present is not in the area where the new main data node is arranged and the target area has the quasi-new main data node, waiting for the completion of the playback of the quasi-new main data node in the target area, and on the premise of ensuring the data consistency, saving the process of needing to catch up the data from the quasi-new main data node which completes the playback at present. Therefore, in the embodiment of the present application, if a certain area is to be used as an area of a new active data node, data consistency between the new active data node and the old active data node can also be ensured.
In an optional implementation manner of the embodiment of the present application, regarding the manner of pursuing data from the first target data node based on the second target data node in the target area, which is referred to in the above step 24, the method further may include:
step 31, querying a data node in a normal state from data nodes in the target area as a second target data node;
it should be noted that the data node in a normal state in the embodiment of the present application means that both the data node receives and sends data normally, and no other abnormal condition occurs. In the embodiment of the present application, because a new primary data node is determined in the target area, there is no quasi-new primary data node in the target area, and therefore a data node in a normal state needs to be determined from the target area.
Step 32, determining the first target data node as a temporary main data node;
step 33, data is chased from the temporary primary data node based on the second target data node.
In the embodiment of the present application, the second target data node follows up data from the temporary active data node, and the second target data node synchronizes data from the temporary active data node until the data in the second target data node is consistent with the data in the temporary active data node.
In this embodiment of the present application, before screening M quasi-new active data nodes from N data nodes, the method in this embodiment of the present application may further include: and controlling N data nodes in the database to stop service, and setting the N data nodes to be in a read-only state.
By stopping the service of the N data nodes in the database, the service of the data node side and all the services on the original main data node can be disconnected, and the service on the original main data node is ensured not to be increased any more, so that the data consistency can be ensured after the new main data node and the old main data node are switched.
In this embodiment, after determining a new active data node from the target area based on the target data node, the method in this embodiment may further include:
step 41, executing the switching operation of the main and standby data nodes in the database;
and step 42, controlling N data nodes in the database to start service, and setting a new main data node to be in a read-write state.
After determining the new main data node, switching operation of the main data node and the standby data node can be performed, so that the N data nodes in the database are controlled to start service, the new main data node is set to be in a read-write state, and the service is restarted under the condition that the new main data node and the old main data node are consistent, so that normal operation of the data nodes in the database is ensured.
The present application will now be explained with reference to specific embodiments of examples thereof. The specific embodiment provides a database data node switching optimization method based on a synchronous thread, and the method may include the steps of:
step 201, a Cluster Manager (CM) detects that the heartbeat of a host in a fragment is lost and a synchronization/playback thread is abnormal, judges that the host is abnormal, and triggers a fault switching selection process;
step 202, the CM sends a service outage request to a compute node manager (Proxymanager, PM);
it can be seen that for this step 202 the CM sends a service down request to the PM for all DN nodes to be set to a read-only state so that all traffic is disconnected.
Step 203, the CM sends a request for inquiring the synchronous state to each standby database monitoring agent (DBagent);
step 204, each standby machine DBagent is connected with fields such as database query synchronization sites on the DBagent and returns the fields to the CM;
therefore, the CM sends a request for inquiring the synchronous state to each standby machine DBagent, and based on the request, the DBagent is connected with the database to execute relevant commands to inquire fields such as synchronous sites and then returns the fields to the CM.
Step 205, the CM screens out a quasi-new master list by comparing fields such as synchronous sites and the like;
it may further be for step 205 to: and the CM screens out a quasi-new master list by comparing the synchronous sites of the standby data nodes, considers that each quasi-new master is a consistent copy of the original host, and then sends a playback request and the like to the DBAgents of the quasi-new masters. And the DBagent continuously connects the database thereon to execute related commands after receiving the request to check whether the quasi-new master completes the playback, and if the playback is completed, a successful reply is sent to the CM.
Step 206, the CM sends playback requests to each quasi-new master DBAgents;
step 207, if the target machine room has the quasi-new master, the quasi-new master in the target machine room is switched to the master after the playback of the quasi-new master is finished, and the rest standby machines are switched to be standby;
it can be seen that, if the playback of the prospective master is completed and the prospective master is in the target computer room, the CM directly sends a master-up request to the prospective master, and sends a standby request to the remaining standby machines. Therefore, the time consumption of switching is reduced, and the time waste caused by waiting for all the quasi-new main playbacks is reduced.
And step 208, if the target machine room does not have the prospective host, selecting a standby machine with a normal state in the target machine room, and using the prospective host after playback as a temporary host to catch up data. After the data is successfully traced, the data is cut into a master and the rest of the standby machines are cut into standby;
therefore, if the playback of the prospective primary is completed and the prospective primary is not in the target machine room, the standby machine in a normal state is selected in the target machine room, the prospective primary after the playback is completed serves as a temporary host to catch up data, the CM sends a primary ascending request to the standby machine which catches up the data after the data is successfully caught up, and sends a standby request to the other standby machines. Thereby meeting the customization requirement of the user for specifying the mainframe room and simultaneously ensuring that the data is not lost to the maximum extent
Step 209, after the active/standby switch is successful, the CM sends a service enabling request to the PM.
It can be seen that the CM is a coordinator in the whole failover process, and first identifies that the heartbeat of the host is lost and the synchronization/playback thread is abnormal, determines that the host is abnormal, triggers the failover main selection process, then selects a new main according to the main selection policy, and sends a main-up/backup-down request to the new main and the remaining backup machines to complete the failover process. And the PM is a passthrough in the fault switching process and is used for analyzing and passing the service stopping and starting request sent by the CM to the computing node for processing, and simultaneously replying the result response of the computing node executing the service stopping and starting action to the CM. The DBAgents are executors in the fault switching process, are used for executing query synchronization states sent by the CM, and waiting for replaying and tracing data requests, and are essentially connected with the databases on the DBAgents to execute corresponding SQL statements, and then feedback results to the CM.
Therefore, by means of the method and the device, data loss can be reduced, namely when the main data node goes down, the standby data node with the highest synchronization speed is screened out as a quasi-new main through inquiring and comparing the synchronization condition of each standby data node, then the quasi-new main plays back or takes the quasi-new main as reference to track down data, the new main screened out finally is necessary to have the most data in all standby machines, and the consistency of the data before and after switching is guaranteed. In addition, by the embodiment of the application, the switching time can be saved, namely, in the switching logic in the prior art, the switching is performed after the playback of all the standby machines is completed, and the mode causes time waste. In the embodiment of the application, the switching can be performed as long as one quasi-new main playback is completed, so that the time from the downtime of the original main fault to the service starting of the new main is shortened, and the influence of the switching on the service is reduced. In addition, the method in the embodiment of the application has wide applicability, can be applied to the switching process of various main and standby data nodes in the database, and has universality.
As shown in fig. 2, the method steps of the specific example include:
step 301, when detecting that the original main fault is down, the CM informs the PM to stop service and sets all DN nodes to be in a read-only state;
based on the method, the data node side service and all the services on the original master are disconnected;
step 301, the CM sends a request for inquiring the synchronous state to all the standby machines;
step 303, after receiving the request, the DBAgent of the standby machine connects to the database on the DBAgent to execute fields such as relevant playback query synchronization sites and feeds back the result to the CM;
step 304, the CM compares the screened standby machine with the largest synchronization site field as a quasi-new master, wherein the screened quasi-new master may have a plurality of quasi-new masters and is distributed in different machine rooms;
step 305, the CM sends a request for equal playback to all the renewing masters;
step 306, after receiving the request, the quasi-new master DBagent continuously connects the database thereon to execute relevant playback to inquire whether the node is finished playing back, and if the node is finished playing back, the result is fed back to the CM;
step 307, the CM judges whether the quasi-new main after the playback is finished is in the target machine room, and if the quasi-new main is in the target machine room, the main switching and standby flow is directly carried out;
step 308, if the target machine room does not have a primary computer, finding a standby computer in a normal state in the target machine room, and using the primary computer as a temporary host computer to track data;
step 309, the CM sends a master-upgrading request to the standby machine which completes the playback and is ready for updating the master or successfully chases the data, and sends a standby request to the other standby machines;
and step 310, after the master/slave is upgraded, the CM informs the PM of starting up the service and sets a new master DN read-write state.
Therefore, in the embodiment of the application, a switching optimization scheme based on a synchronous thread is adopted, compared with a switching scheme based on a playback thread in the prior art, the main selection strategy is more reasonable, and the probability of data inconsistency before and after switching is lower. The core of the switching scheme in the prior art is that the DN data volume of the playback speed is considered to be larger, while the DN data volume of the synchronization speed is firstly confirmed to be large in the embodiment of the application, and then the DN is promoted to the master after the playback of the DN is finished. Because playback and synchronization are two concepts, the DN with fast synchronization has more data volume after the playback is finished, and therefore, the consistency of data before and after switching can be better ensured through the embodiment of the application. Meanwhile, compared with some schemes in the prior art, the method has the advantages that the main is switched after all the standby machines are played back, and the main is locked and then lifted as long as one standby main is played back, so that switching time is saved, and the influence on the service under the fault condition is reduced. The method and the device for switching the data nodes can be applied to switching processes of various main and standby data nodes in the database, and the switching performance of the data nodes can be improved by adopting the method and the device, so that the reliability and the high availability of the distributed database are improved.
Corresponding to fig. 1, an embodiment of the present application further provides a device for determining a primary data node in a database, where as shown in fig. 3, the device includes:
the screening module 42 is configured to screen M quasi-new primary data nodes from N data nodes when a primary data node in a database fails, where the database includes N data nodes, the N data nodes include one primary data node and L backup data nodes, and M and L are positive integers smaller than N;
a selecting module 44, configured to select a target data node from the M quasi-new primary data nodes; the target data node is a quasi-new main data node which is completed in playback;
the determining module 46 is configured to determine a new primary data node from a target area based on the target data node, where data on the new primary data node is consistent with data on the target data node, N data nodes in the database are distributed in multiple areas, and the target area is any one of the multiple areas.
Optionally, the screening module 42 in the embodiment of the present application further includes: the first sending unit is used for sending a request for inquiring the synchronous state to the N data nodes so as to inquire the synchronous sites of the N data nodes; the first determining unit is configured to determine a data node with the largest synchronization bit field as a data node of M quasi-new primary data nodes, where the M quasi-new primary data nodes are distributed in one or more areas.
Optionally, the determining module 46 in this embodiment of the present application further includes: a second sending unit, configured to send, to the M quasi-new master data nodes, requests for playback and the like; a second determining unit, configured to determine whether a first target data node that completes playback exists in the M quasi-new master data nodes; the target area is an area where a new main data node is to be set; a third determining unit, configured to determine the first target data node as a new primary data node when the first target data node is in the target area; a fourth determining unit, configured to, when the first target data node is not in the target area and the target area does not have a quasi-new primary data node, chase up data from the first target data node based on a second target data node in the target area, and determine the second target data node as new primary data after the data chase is successful; and a fifth determining unit, configured to determine, when the first target data node is not in the target area and the target area has the primary data node ready for updating, the primary data node ready for updating in the target area as new primary data after the completion of the playback of the primary data node ready for updating in the target area.
Optionally, the fourth determining unit in the embodiment of the present application further includes: the query subunit is used for querying a data node in a normal state from the data nodes in the target area as a second target data node; the determining subunit is used for determining the first target data node as a temporary main data node; and the processing subunit is used for chasing data from the temporary main data node based on the second target data node.
Optionally, the apparatus in this embodiment of the present application may further include: and the first processing module is used for controlling the N data nodes in the database to stop service before the M quasi-new main data nodes are screened out from the N data nodes, and setting the N data nodes to be in a read-only state.
Optionally, the apparatus in this embodiment of the present application may further include: the execution module is used for executing the switching operation of the main and standby data nodes in the database after determining a new main data node from the target area based on the target data node; and the second processing module is used for controlling N data nodes in the database to start service and setting the new main data node to be in a read-write state.
As shown in fig. 4, an electronic device according to an embodiment of the present application includes a processor 111, a communication interface 112, a memory 113, and a communication bus 114, where the processor 111, the communication interface 112, and the memory 113 complete mutual communication via the communication bus 114,
a memory 113 for storing a computer program;
in an embodiment of the present application, when the processor 111 is configured to execute the program stored in the memory 113, the functions of the method for determining the active data node in the database provided in any one of the foregoing method embodiments are also consistent, and are not described herein again.
An embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the steps of the method for determining a primary data node in a database provided in any one of the foregoing method embodiments.
It is noted that, in this document, relational terms such as "first" and "second," and the like, may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrases "comprising a," "8230," "8230," or "comprising" does not exclude the presence of additional like elements in a process, method, article, or apparatus that comprises the element.
The foregoing are merely exemplary embodiments of the present invention, which enable those skilled in the art to understand or practice the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims (10)

1. A method for determining a primary data node in a database is characterized by comprising the following steps:
screening M quasi-new main data nodes from N data nodes under the condition that the main data nodes in the database have faults, wherein the database comprises the N data nodes, the N data nodes comprise one main data node and L standby data nodes, and M and L are positive integers smaller than N;
selecting a target data node from the M quasi-new main data nodes; the target data node is a quasi-new main data node with completed playback;
and determining a new primary data node from a target area based on the target data node, wherein the data on the new primary data node is consistent with the data on the target data node, N data nodes in the database are distributed in a plurality of areas, and the target area is any one of the plurality of areas.
2. The method according to claim 1, wherein the screening M quasi-new master data nodes from the N data nodes comprises:
sending a request for inquiring the synchronous state to the N data nodes so as to inquire the synchronous sites of the N data nodes;
and determining the data node with the largest synchronization site field as a data node in the M quasi-new main data nodes, wherein the M quasi-new main data nodes are distributed in one or more areas.
3. The method of claim 1, wherein determining a new active data node from within a target area based on the target data node comprises:
sending equal playback requests to the M quasi-new main data nodes;
determining whether a first target data node is in a target area or not under the condition that the first target data node with completed playback exists in the M quasi-new main data nodes; the target area is an area in which the new main data node is to be set;
determining the first target data node as the new primary data node when the first target data node is in the target area;
when the first target data node is not in a target area and the target area does not have a quasi-new primary data node, data is tracked from the first target data node based on a second target data node in the target area, and the second target data node is determined as new primary data after the data tracking is successful;
and under the condition that the first target data node is not in the target area and the quasi-new primary data node exists in the target area, after the completion of the playback of the quasi-new primary data node in the target area, determining the quasi-new primary data node in the target area as the new primary data.
4. The method of claim 3, wherein the chasing data from the first target data node based on a second target data node within the target area comprises:
querying a data node with a normal state from the data nodes in the target area as the second target data node;
determining the first target data node as a temporary main data node;
data is chased from the temporary primary data node based on the second target data node.
5. The method of claim 1, wherein prior to screening the M quasi-new primary data nodes from the N data nodes, the method further comprises:
and controlling the N data nodes in the database to stop service, and setting the N data nodes to be in a read-only state.
6. The method of claim 5, wherein after determining a new active data node from within a target area based on the target data node, the method further comprises:
executing switching operation of the main and standby data nodes in the database;
and controlling the N data nodes in the database to start service, and setting the new main data node to be in a read-write state.
7. An apparatus for determining a primary data node in a database, comprising:
the screening module is used for screening M quasi-new main data nodes from N data nodes under the condition that the main data nodes in the database have faults, wherein the database comprises the N data nodes, the N data nodes comprise one main data node and L standby data nodes, and M and L are positive integers smaller than N;
a selection module, configured to select a target data node from the M quasi-new primary data nodes; the target data node is a quasi-new main data node with completed playback;
and the determining module is used for determining a new primary data node from a target area based on the target data node, wherein the data on the new primary data node is consistent with the data on the target data node, the N data nodes in the database are distributed in a plurality of areas, and the target area is any one of the plurality of areas.
8. The apparatus of claim 7, wherein the screening module comprises:
a first sending unit, configured to send a request for querying a synchronization status to the N data nodes, so as to query synchronization sites of the N data nodes;
a first determining unit, configured to determine a data node with a largest synchronization bit field as a data node in the M quasi-new primary data nodes, where the M quasi-new primary data nodes are distributed in one or more areas.
9. An electronic device is characterized by comprising a processor, a communication interface, a memory and a communication bus, wherein the processor and the communication interface are used for realizing mutual communication by the memory through the communication bus;
a memory for storing a computer program;
a processor for implementing the method steps of any one of claims 1 to 6 when executing a program stored in the memory.
10. A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the method steps of any of claims 1 to 6.
CN202310017431.8A 2023-01-06 2023-01-06 Method and device for determining active data nodes in database and storage medium Active CN115905270B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310017431.8A CN115905270B (en) 2023-01-06 2023-01-06 Method and device for determining active data nodes in database and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310017431.8A CN115905270B (en) 2023-01-06 2023-01-06 Method and device for determining active data nodes in database and storage medium

Publications (2)

Publication Number Publication Date
CN115905270A true CN115905270A (en) 2023-04-04
CN115905270B CN115905270B (en) 2023-06-09

Family

ID=86472815

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310017431.8A Active CN115905270B (en) 2023-01-06 2023-01-06 Method and device for determining active data nodes in database and storage medium

Country Status (1)

Country Link
CN (1) CN115905270B (en)

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111028902A (en) * 2019-12-09 2020-04-17 天津开心生活科技有限公司 Request processing method, device, equipment and medium based on node switching
WO2022002103A1 (en) * 2020-06-30 2022-01-06 华为技术有限公司 Method for playing back log on data node, data node, and system
CN113987078A (en) * 2021-12-24 2022-01-28 中兴通讯股份有限公司 Data synchronization method, device and computer readable storage medium

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111028902A (en) * 2019-12-09 2020-04-17 天津开心生活科技有限公司 Request processing method, device, equipment and medium based on node switching
WO2022002103A1 (en) * 2020-06-30 2022-01-06 华为技术有限公司 Method for playing back log on data node, data node, and system
CN113987078A (en) * 2021-12-24 2022-01-28 中兴通讯股份有限公司 Data synchronization method, device and computer readable storage medium

Also Published As

Publication number Publication date
CN115905270B (en) 2023-06-09

Similar Documents

Publication Publication Date Title
US11360854B2 (en) Storage cluster configuration change method, storage cluster, and computer system
WO2017177941A1 (en) Active/standby database switching method and apparatus
US7802128B2 (en) Method to avoid continuous application failovers in a cluster
US7062676B2 (en) Method and system for installing program in multiple system
US11892922B2 (en) State management methods, methods for switching between master application server and backup application server, and electronic devices
US20120036394A1 (en) Data recovery method, data node, and distributed file system
WO2020248507A1 (en) Container cloud-based system resource monitoring method and related device
US20080281959A1 (en) Managing addition and removal of nodes in a network
CN106062717A (en) Distributed storage replication system and method
US9348841B2 (en) Transaction processing method and system
US20080288812A1 (en) Cluster system and an error recovery method thereof
CN111049928B (en) Data synchronization method, system, electronic device and computer readable storage medium
CN106331081B (en) Information synchronization method and device
CN116107828A (en) Main node selection method, distributed database and storage medium
CN110377664B (en) Data synchronization method, device, server and storage medium
CN116400855A (en) Data processing method and data storage system
CN110196859A (en) Data base read-write based on JDBC distributor separates cluster real-time consistency method
CN112650629A (en) Block chain index data recovery method, device, equipment and computer storage medium
CN115905270A (en) Method and device for determining main data node in database and storage medium
CN117271227A (en) Database cluster master node switching method, system and management and control platform
CN112231150B (en) Method and device for recovering fault database in database cluster
CN114036164A (en) High-concurrency transaction locking method and system combining optimistic lock and pessimistic lock
CN111130896A (en) NFS fault switching method and system and dual-control storage system
CN118093251A (en) Fault processing method and device, electronic equipment and storage medium
CN118093250A (en) Fault processing method and device, electronic equipment and storage medium

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