CN115905270B - Method and device for determining active data nodes in database and storage medium - Google Patents

Method and device for determining active data nodes in database and storage medium Download PDF

Info

Publication number
CN115905270B
CN115905270B CN202310017431.8A CN202310017431A CN115905270B CN 115905270 B CN115905270 B CN 115905270B CN 202310017431 A CN202310017431 A CN 202310017431A CN 115905270 B CN115905270 B CN 115905270B
Authority
CN
China
Prior art keywords
data
data node
target
nodes
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.)
Active
Application number
CN202310017431.8A
Other languages
Chinese (zh)
Other versions
CN115905270A (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

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: under the condition that the main data node in the database fails, M quasi-new main data nodes are screened out from N data nodes, wherein the database comprises N data nodes, and the N data nodes 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 playback completed; and determining new main data nodes from the target area based on the target data nodes, wherein the data on the new main data nodes are consistent with the data on the target data nodes, and N data nodes in the database are distributed in a plurality of areas. By the method and the device, the problem that the consistency of data before and after switching cannot be ensured in the mode of switching the main data node and the standby data node after the main data node fails in the prior art is solved.

Description

Method and device for determining active data nodes in database and storage medium
Technical Field
The present invention relates to the field of data processing, and in particular, to a method and apparatus for determining a primary data node in a database, and a storage medium.
Background
For a long time, each component in the financial-level distributed database adopts a main and a standby or a main and a standby architecture to ensure the stable reliability of the service.
Here in Data nodes (Data nodes, abbreviated DN). Normally, the data service issued by the computing node is written into the main DN, and the rest one or more standby DNs bear the reading operation of the data service. The service processing mode realizes the read-write separation and load balancing of the main machine and the standby machine, 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 the data consistency is ensured. Because the switching is the basic function of the database, the switching efficiency between the primary and the secondary DNs directly affects the high availability characteristic of the database, and is an important factor for measuring whether the database can provide stable service.
At present, the master-slave switching of the data nodes in the database is based on the playback thread of the database to compare the data quantity on each DN, and the comparison method is problematic because the playback thread can only reflect the playback condition of the DN node and cannot accurately reflect the synchronization condition. In databases, playback and synchronization are two concepts. 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 the process of sending a transaction execution log on a host to a standby, and a synchronization thread determines how fast to synchronize. Like DN1 and DN2, DN1 synchronizes faster but slows down, DN2 synchronizes slower but plays back fast. After all nodes are completely replayed, the data quantity on DN1 should be larger than DN2. According to the switching logic based on the playback thread before, DN2 rises to the main last, so the switching logic before causes the 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 the mode of switching the main 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: under the condition that a main data node in the database fails, M quasi-new main data nodes are selected from N data nodes, wherein the database comprises the N data nodes, the N data nodes comprise a main data node and L standby data nodes, and the M and the L are positive integers smaller than the 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 playback completed; and determining a new main data node from a 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, N data nodes in the database are distributed in a plurality of areas, and the target area is any area in the plurality of areas.
In a second aspect, the present application provides a device 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 a main data node and L standby data nodes, and the M and the L are positive integers smaller than the N; the selecting module is used for 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 playback completed; the determining module is used for determining a new main data node from a target area based on the target data node, wherein data on the new main data node is consistent with 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 area in the plurality of areas.
In a third aspect, an electronic device is provided, including a processor, a communication interface, a memory, and a communication bus, where 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, configured to implement the method steps according to any one of the embodiments of the first aspect when executing a program stored in a 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 according to any one 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 main data nodes can be selected first, and then the quasi-new main data nodes with finished playback are used as the basis for determining the new main data nodes from the M quasi-new main data nodes, namely, the data on the new main data nodes are consistent with the data on the target data nodes, so that the data consistency of the new main data nodes and the old main data nodes with faults is ensured, and the problem that the mode of switching the main data nodes and the standby data nodes cannot ensure the data consistency before and after the main data nodes are faulty 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 invention or the technical solutions of the prior art, the drawings which are used in the description of the embodiments or the prior art will be briefly described, and it will be obvious to a person skilled in the art that other drawings can be obtained from these drawings without inventive effort.
Fig. 1 is a flow chart of a method for switching between active and standby data nodes in a database according to an embodiment of the present application;
fig. 2 is a schematic flow chart of a database data node switching optimization method based on synchronous threads according to an embodiment of the present application;
fig. 3 is a schematic structural diagram of a switching device of a master and slave data node 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
For the purposes of making the objects, technical solutions and advantages of the embodiments of the present application more clear, the technical solutions of 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 apparent that the described embodiments are some embodiments of the present application, but not all embodiments. All other embodiments, which can be made by one of ordinary skill in the art without undue burden from the present disclosure, are within the scope of the present application based on the embodiments herein.
Fig. 1 is a flow chart of a method for switching between active and standby data nodes in a database according to an embodiment of the present application, as shown in fig. 1, where the method includes the steps of:
step 101, under the condition that a main data node in a database fails, M quasi-new main data nodes are screened out from N data nodes, wherein the database comprises N data nodes, the N data nodes comprise a 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 the data node with the most transactions synchronized from the active data node with the failure, that is, if only one data node in the current standby node is the most transactions synchronized, the number of the quasi-new active data nodes is one, and if there are multiple data nodes in the current standby node simultaneously, the number of the quasi-new active data nodes may also be multiple. For example, the current value of N is 10, where the data node 1 is the active data node, and the active data node fails, and for the remaining 9 data nodes, if the data node 2, the data node 5 and the data node 8 synchronize as many transactions from the data node 1 and higher than the other data node synchronizing transactions, the value of M is 3, and the quasi-new active data node is the data node 2, the data node 5 and the data node 8. Of course, the foregoing is merely illustrative, and the corresponding arrangement may be specifically performed according to practical situations.
102, selecting a target data node from M quasi-new main data nodes, wherein the target data node is a quasi-new main data node with playback completed;
and 103, 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, N data nodes in the database are distributed in a plurality of areas, and the target area is any area in the plurality of areas.
It should be noted that, in the embodiment of the present application, the area may be divided by a machine room in an actual scene, or may be divided by an actual area, for example, the area is a province unit, and for example, the area in the south and the area in the north are a unit. Corresponding setting can be carried out according to actual conditions in specific application scenes.
As can be seen from the above steps 101 to 103, in the embodiment of the present application, M quasi-new primary data nodes may be selected first, and then, from the M quasi-new primary data nodes, the quasi-new primary data node whose playback is completed is used as a basis for determining a new primary data node, that is, the data on the new primary data node is consistent with the data on the target data node, so as to ensure the data consistency between the new primary data node and the old primary data node with a failure, thereby solving the problem that in the prior art, after the primary data node fails, the mode of switching the primary data node and the backup data node cannot ensure the data consistency before and after switching.
In this embodiment of the present application, the method for screening M quasi-new active data nodes from N data nodes in step 101 in this embodiment of the present application may further include:
step 11, sending a request for inquiring the synchronous state to N data nodes so as to inquire the synchronous sites of the N data nodes;
and step 12, determining the data node with the largest synchronization site field as the data node in M quasi-new main data nodes, wherein the M quasi-new main data nodes are distributed in one or more areas.
It should be noted that, the field corresponding to the synchronization site is the transaction number of the active data node that has been received in the standby data node, that is, indicates the active data node transaction set that the synchronization thread of the standby data node has synchronized, and based on this, the larger the synchronization site, the more transactions that the standby data node synchronizes from the active data node. It can be seen that if there are multiple maximum synchronization points in the synchronization points of the backup data node, the number of the primary new primary data nodes is also multiple. And the plurality of quasi-new primary data nodes may be distributed over one or more areas, in a specific example one or more rooms. In other words, in the application, the data node with the largest playback transaction is used as the quasi-new main data node, that is, the determined quasi-new main data node is also the first to complete the playback transaction, so that the subsequent determination of the new main data node from the target area based on the target data node is ensured, the data on the new main data node is consistent with the data on the target data node, the efficiency of switching the new main data node is improved on the premise of ensuring the consistency of the data, and the switching time is saved.
In the 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 needs, the determining, based on the target data node, the manner of determining the new active data node from the target area in step 103 in the embodiment of the present application may further include:
step 21, sending a request for waiting for playback to M quasi-new master data nodes;
step 22, determining whether the first target data node is in the target area or not under the condition that the playback-completed first target data node exists in the M quasi-new main data nodes; the target area is an area in which a new main data node is to be set;
step 23, determining the first target data node as a new main data node under the condition that the first target data node is in the target area;
step 24, under the condition that the first target data node is not in the target area and the target area does not have a quasi-new main data node, tracking data from the first target data node based on the second target data node in the target area, and determining the second target data node as a new main data node after successful tracking data;
and step 25, when the first target data node is not in the target area and the target area has the quasi-new main data node, determining the quasi-new main data node in the target area as the new main data node after waiting for the quasi-new main data node in the target area to be played back.
As can be seen from the above steps 21 to 25, if the quasi-new active data node that has completed playback is in the area where the new active data node is set, the quasi-new active data node can be directly used as the new active data node, so that the efficiency of switching the new active data node is improved and the switching time is saved on the premise of ensuring the consistency of data. If the current playback quasi-new main data node is not in the area where the new main data node is set and the target area has the quasi-new main data node, waiting for the completion of playback of the quasi-new main data node in the target area, saving the process of tracking data from the current playback quasi-new main data node on the premise of ensuring the consistency of data, and if the target area does not have the quasi-new main data node, tracking data from the playback quasi-new main data node which is selected from the target area and has normal state from the data node which is required to be played back until the data is tracked, thereby ensuring the consistency of the data. Therefore, in the embodiment of the present application, if a certain area is to be used as the area of the new active data node, the data consistency between the new active data node and the old active data node can be ensured.
In an optional implementation manner of the embodiment of the present application, for the manner of tracking data from the first target data node based on the second target data node in the target area in step 24, the method may further include:
step 31, inquiring a data node with normal state from the data nodes in the target area as a second target data node;
it should be noted that, in the embodiment of the present application, the data node with normal status refers to a situation that the data node receives and transmits data normally, and no other abnormality occurs. In the embodiment of the present application, since the new active data node is to be determined in the target area, the new active data node is not quasi-located in the target area, and therefore, a data node with 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, tracking data from the temporary master data node based on the second target data node.
In the embodiment of the application, the second target data node tracks data from the temporary main data node, and the second target data node synchronizes data from the temporary main data node until the data in the second target data node is consistent with the data in the temporary main data node.
In the embodiment of the present application, before screening M quasi-new active data nodes from N data nodes, the method in the 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 N data nodes in the database, all the services on the data node side and the original main data node can be disconnected, so that the services on the original main data node are not increased any more, and the data consistency can be ensured after the new main data node and the old main data node are switched.
In an embodiment of the present application, after determining a new active data node from within the target area based on the target data node, the method of the embodiment of the present application may further include:
step 41, executing a switching operation of the master and slave data nodes in the database;
and 42, controlling N data nodes in the database to start service, and setting the new main data node to be in a read-write state.
After the new main data node is determined, the switching operation of the main data node and the standby data node can be performed, so that 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, and the normal operation of the data nodes in the database is ensured.
The present application is explained below in connection with the specific implementation of the examples of the present application. The specific embodiment provides a database data node switching optimization method based on synchronous threads, which comprises the following steps:
step 201, the cluster manager (ClusterManager, CM) detects that the heartbeat of the host in the slice is lost and the synchronization/playback thread is abnormal, judges that the host is abnormal, and triggers a failover main-selection flow;
step 202, the CM sends a service outage request to a compute node manager (ProxyManager, PM);
it can be seen that for this step 202CM sends a service down request to the PM for setting all DN nodes to read-only state so that all traffic is disconnected.
Step 203, the cm sends a request for inquiring the synchronization status to each standby database monitoring agent (DBAgent);
step 204, each standby machine DBagent is connected with fields such as database query synchronization sites and the like and returns to the CM;
based on the request, the DBagent is connected with fields such as a database execution related command query synchronization site and the like and then returns to the CM.
Step 205, CM screens out quasi-new master list by field comparison such as synchronization site;
further to step 205 may be: the CM screens out the quasi-new master list by comparing the synchronization bit points of the standby data nodes, considers each quasi-new master to be a consistent copy of the original master, and then sends an equal playback request to the DBagent of each quasi-new master. After receiving the request, the DBagent is continuously connected with the database to execute related commands to check whether the playback of the quasi-new master is completed, and if the playback is completed, a successful reply is sent to the CM.
Step 206, the CM sends an equal playback request to each quasi-new master DBagent;
step 207, if the target machine room has a quasi-new master, then waiting for the quasi-new master in the target machine room to play back, and then cutting the quasi-new master into the master and the rest of the standby machines;
it can be seen that if there is a quasi-new master playback completed and the quasi-new master is in the target room, the CM directly sends a master-up request to it and a backup request to the remaining backup machines. Thereby reducing switching time and reducing time waste caused by waiting for all new main playbacks.
And step 208, if no quasi-new master exists in the target machine room, selecting a standby machine with normal state in the target machine room, and taking the finished quasi-new master as a temporary host machine to track data. Cutting the data into main machines and other standby machines after the data is successfully tracked;
if the playback of the quasi-new master is completed and the quasi-new master is not in the target machine room, selecting a standby machine with normal state in the target machine room, taking the quasi-new master with completed playback as a temporary host machine to trace data, and after the data trace is successful, sending a master rising request to the standby machine with the data trace by the CM, and sending a standby cutting request to the other standby machines. Therefore, the customization requirement of a user for designating a main machine room is met, and meanwhile, data is prevented from being lost to the greatest extent.
Step 209, after the active-standby switch is successful, the CM sends a service start request to the PM.
The CM is a coordinator in the whole failover process, firstly recognizes that the heartbeat of the host is lost and the synchronous/playback thread is abnormal, judges that the host is abnormal, triggers the failover main-selection process, then selects a new main according to a main-selection strategy and sends a main-lifting/standby-lifting request to the new main and the rest standby machines to complete the switching process. PM is a transparent transmitter in the fault switching process, and is used for resolving and transmitting the stopping and starting service request sent by CM to the computing node for processing, and simultaneously replying the response of the result of the stopping and starting service action executed by the computing node to CM. The DBagent is an executor in the fault switching process and is used for executing the query synchronous state, etc. playback and data following requests sent by the CM, and the essence of the DBagent is that the DBagent is connected with a database to execute corresponding SQL sentences, and then the feedback result is responded to the CM.
Therefore, through the method in the embodiment of the application, data loss can be reduced, namely, when the main data node is down, the standby data node with the fastest synchronization is screened out by inquiring and comparing the synchronization condition of each standby data node to serve as a new master, then the new master is calibrated for playback or the new master is used as a reference for data tracking, so that the finally screened new master is required to be the most data in all standby machines, and the consistency of the data before and after switching is ensured. In addition, by the embodiment of the application, switching time can be saved, namely, switching logic in the prior art is used for switching the master or the slave after playback of all the slave is completed, and time waste can be caused by the mode. In the embodiment of the application, the switching can be performed only by completing the playback of the quasi-new master, so that the time from the downtime of the original master to the start of the new master is shortened, and the influence of the switching on the service is reduced. In addition, the mode in the embodiment of the application has wide applicability, can be applied to the switching flow of various master and slave data nodes in the database, and has universality.
Further explanation follows in connection with a specific example of an embodiment of the present application, as shown in fig. 2, the method steps of the specific example include:
step 301, when the CM detects that the original main fault is down, the PM is notified to stop taking service and all DN nodes are set to be in a read-only state;
based on this, 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 synchronization status to all the standby machines;
step 303, after receiving the request, the standby DBagent connects the fields such as the synchronization site of the related playback query executed by the database and feeds back the result to the CM;
step 304, the CM compares and screens out the standby machine with the largest synchronization site field as the quasi-new master, wherein, the screened quasi-new master may have a plurality of and be distributed in different machine rooms;
step 305, the cm sends a request for playback, etc., to all quasi-new masters;
step 306, after receiving the request, the quasi-new main DBagent continuously connects the database on the quasi-new main DBagent to execute related playback to inquire whether the playback of the node is finished, and if the playback is finished, the result is fed back to the CM;
step 307, the cm determines whether the playback-completed quasi-new master is in the target machine room, and if so, directly performs a master-slave switching process;
step 308, if the target machine room has no quasi-new master, finding a standby machine with normal state in the target machine room, and taking the quasi-new master as a temporary host machine to track data;
step 309, the cm sends a master-up request to the standby machine that completes the playback of the new master or the data following successfully, and sends a standby request to the rest of the standby machines;
in step 310, after the up master/standby is completed, the CM notifies PM to start up and sets a new master DN read-write state.
Therefore, in the embodiment of the application, the switching optimization scheme based on the synchronous thread is adopted, and compared with the switching scheme based on the playback thread in the prior art, the main selection strategy is more reasonable, and the probability of inconsistent data before and after switching is lower. The core of the switching scheme in the prior art is that the DN data volume with fast playback is considered to be larger, and in the embodiment of the application, the DN data volume with fast synchronization is confirmed to be large first, and then the DN is played 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 playback is finished, so that the consistency of the data before and after switching can be ensured more through the embodiment of the application. Meanwhile, the scheme is different from the scheme in the prior art that after all standby machines are required to wait for playback to finish, the main is switched off, and after the scheme locks the quasi-new main, only one quasi-new main is required to finish, namely the main is switched off, so that switching time is saved, and the influence on the service under the fault condition is reduced. The embodiment of the application can be applied to the switching flow of various main and standby data nodes in the database, and the switching performance of the data nodes can be improved by adopting the embodiment of the application, so that the reliability and the high availability of the distributed database are improved.
Corresponding to fig. 1, the embodiment of the present application further provides a device for determining a primary data node in a database, as shown in fig. 3, where 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 the database fails, where the database includes N data nodes, the N data nodes include a primary data node and L backup data nodes, and M and L are positive integers less than N;
a selecting module 44, configured to select a target data node from M quasi-new primary data nodes; the target data node is a quasi-new main data node with playback completed;
the determining module 46 is configured to determine a new active data node from the target area based on the target data node, where data on the new active data node is consistent with 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.
Optionally, the screening module 42 in the embodiment of the present application may further include: the first sending unit is used for sending a request for inquiring the synchronous state to N data nodes so as to inquire the synchronous sites of the N data nodes; and the first determining unit is used for determining the data node with the largest synchronization site field as the data node in M quasi-new main data nodes, wherein the M quasi-new main data nodes are distributed in one or more areas.
Optionally, the determining module 46 in the embodiment of the present application may further include: a second sending unit, configured to send a request for waiting for playback to M quasi-new primary data nodes; a second determining unit, configured to determine, in a case where there is a playback-completed first target data node among the M quasi-new master data nodes, whether the first target data node is within a target area; the target area is an area in which a new main data node is to be set; a third determining unit, configured to determine, when the first target data node is in the target area, the first target data node as a new primary data node; 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 main data node, trace 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 main data after the trace data is successful; and the fifth determining unit is used for determining the quasi-new main data node in the target area as new main data after waiting for the quasi-new main data node in the target area to complete playback under the condition that the first target data node is not in the target area and the quasi-new main data node exists in the target area.
Optionally, the fourth determining unit in the embodiment of the present application may further include: the inquiring subunit is used for inquiring a data node with a normal state from the data nodes in the target area as a second target data node; a determining subunit, configured to determine the first target data node as a temporary primary data node; and the processing subunit is used for tracking data from the temporary main data node based on the second target data node.
Optionally, the apparatus in the embodiment of the present application may further include: the first processing module is used for controlling N data nodes in the database to stop service and setting the N data nodes to be in a read-only state before M quasi-new main data nodes are screened out of the N data nodes.
Optionally, the apparatus in the embodiment of the present application may further include: the execution module is used for executing the switching operation of the main data node and the standby data node 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, the embodiment of the present application provides an electronic device, which includes a processor 111, a communication interface 112, a memory 113, and a communication bus 114, wherein the processor 111, the communication interface 112, and the memory 113 perform communication with each other through the communication bus 114,
a memory 113 for storing a computer program;
in one embodiment of the present application, the processor 111 is configured to implement the method for determining the active data node in the database provided in any of the foregoing method embodiments when executing the program stored in the memory 113, and the functions of the method are consistent, which is not described herein.
The present application further provides a computer readable storage medium, on which a computer program is stored, which 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 method embodiments described above.
It should be noted that in this document, relational terms such as "first" and "second" and the like are 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. Moreover, 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 phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
The foregoing is only a specific embodiment of the invention to enable those skilled in the art to understand or practice the 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, comprising:
under the condition that a main data node in the database fails, M quasi-new main data nodes are selected from N data nodes, wherein the database comprises the N data nodes, the N data nodes comprise a main data node and L standby data nodes, and the M and the L are positive integers smaller than the 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 playback completed;
and determining a new main data node from a 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, N data nodes in the database are distributed in a plurality of areas, and the target area is any area in the plurality of areas.
2. The method of claim 1, wherein the screening M quasi-new active 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 the 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 requests for waiting for playback to the M quasi-new master data nodes;
determining whether a first target data node is in a target area or not under the condition that the playback-completed first target data node 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 main data node under the condition that the first target data node is in a target area;
under the condition that the first target data node is not in a target area and a quasi-new main data node does not exist in the target area, tracking data from the first target data node based on a second target data node in the target area, and determining the second target data node as the new main data node after successful tracking data;
and when the first target data node is not in the target area and the target area has the quasi-new main data node, after waiting for the quasi-new main data node in the target area to be played back, determining the quasi-new main data node in the target area as the new main data node.
4. A method according to claim 3, wherein the tracking data from the first target data node based on the second target data node within the target area comprises:
inquiring a data node with 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;
and tracking data from the temporary master data node based on the second target data node.
5. The method of claim 1, wherein prior to screening M quasi-new active 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 master and slave 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. A device 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 a main data node and L standby data nodes, and the M and the L are positive integers smaller than the N;
the selecting module is used for 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 playback completed;
the determining module is used for determining a new main data node from a target area based on the target data node, wherein data on the new main data node is consistent with 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 area in 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;
and the first determining unit is used for determining the data node with the largest synchronization site field as the 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.
9. The electronic equipment is characterized by comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory are communicated with each other through the communication bus;
a memory for storing a computer program;
a processor for implementing the method steps of any one of claims 1-6 when executing a program stored on a memory.
10. A computer readable storage medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, implements the method steps of any of claims 1-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 CN115905270A (en) 2023-04-04
CN115905270B true 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)

Family Cites Families (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
CN113868028A (en) * 2020-06-30 2021-12-31 华为技术有限公司 Method for replaying log on data node, data node and system
CN113987078B (en) * 2021-12-24 2022-04-19 中兴通讯股份有限公司 Data synchronization method, device and computer readable storage medium

Also Published As

Publication number Publication date
CN115905270A (en) 2023-04-04

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
WO2016070375A1 (en) Distributed storage replication system and method
EP2434729A2 (en) Method for providing access to data items from a distributed storage system
WO2012071920A1 (en) Method, system, token conreoller and memory database for implementing distribute-type main memory database system
US10366106B2 (en) Quorum-based replication of data records
WO2021136422A1 (en) State management method, master and backup application server switching method, and electronic device
CN108090222B (en) Data synchronization system between database cluster nodes
CN108628717A (en) A kind of Database Systems and monitoring method
CN111049928B (en) Data synchronization method, system, electronic device and computer readable storage medium
TWI677797B (en) Management method, system and equipment of master and backup database
CN115794499B (en) Method and system for dual-activity replication data among distributed block storage clusters
US11003550B2 (en) Methods and systems of operating a database management system DBMS in a strong consistency mode
WO2024008156A1 (en) Database system, and master database election method and apparatus
CN116107828A (en) Main node selection method, distributed database and storage medium
CN110635941A (en) Database node cluster fault migration method and device
CN110196859A (en) Data base read-write based on JDBC distributor separates cluster real-time consistency method
CN110377664B (en) Data synchronization method, device, server and storage medium
CN113535665B (en) Method and device for synchronizing log files between main database and standby database
CN105323271B (en) Cloud computing system and processing method and device thereof
CN115905270B (en) Method and device for determining active data nodes in database and storage medium
CN115658245B (en) Transaction submitting system, method and device based on distributed database system
CN113905054B (en) RDMA (remote direct memory access) -based Kudu cluster data synchronization method, device and system
CN111130896A (en) NFS fault switching method and system and dual-control storage system
CN110362428A (en) The on-line automatic method and system for restoring database block

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