CN110704238A - Master and standby method and device based on time sequence database and electronic equipment - Google Patents

Master and standby method and device based on time sequence database and electronic equipment Download PDF

Info

Publication number
CN110704238A
CN110704238A CN201910816659.7A CN201910816659A CN110704238A CN 110704238 A CN110704238 A CN 110704238A CN 201910816659 A CN201910816659 A CN 201910816659A CN 110704238 A CN110704238 A CN 110704238A
Authority
CN
China
Prior art keywords
data
database
node
database node
standby
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201910816659.7A
Other languages
Chinese (zh)
Inventor
董金波
田琳
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Inspur Data Technology Co Ltd
Original Assignee
Beijing Inspur Data Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Inspur Data Technology Co Ltd filed Critical Beijing Inspur Data Technology Co Ltd
Priority to CN201910816659.7A priority Critical patent/CN110704238A/en
Publication of CN110704238A publication Critical patent/CN110704238A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1446Point-in-time backing up or restoration of persistent data
    • G06F11/1448Management of the data involved in backup or backup restore

Abstract

The embodiment of the application discloses a master-slave method and a device based on a time sequence database and an electronic device, by the method provided by the embodiment of the application, the control node transmits data to the database, judges the communication state of the main database node and the standby database node, and when the two nodes are in the communication state, simultaneously, the command for saving data is called to the main data node and the standby data node, when the main database node is not in a connected state, the command for saving data is called to the standby data node, and records the record that the current data is not stored in the main data node, checks the stored record regularly, after the main database nodes are communicated, the data are automatically recovered, and when the data in the database are needed, the data are acquired at the main data node or the standby database node, so that the problems of failure and data loss of the time sequence database are avoided.

Description

Master and standby method and device based on time sequence database and electronic equipment
Technical Field
The present application relates to the field of database technologies, and in particular, to a master/slave method and apparatus based on a time sequence database, and an electronic device.
Background
With the rapid development of the internet, the rapid expansion of big data and the rapid rise of the internet, most data in life and work are gradually associated with time. To store these time-related data, time-series databases have gained increasing attention and research.
The time sequence data is data for recording the state changes of the system and the equipment according to the time sequence, and the time sequence database is a database for storing the time sequence data. The time sequence database can provide some general functions and operations for time sequence data analysis, such as data storage, continuous query and flexible time aggregation, and in addition, the time sequence database also provides faster large-scale query, better data compression and the like by taking time as latitude.
With the wide application of the time sequence database, when the database fails, the problem of data loss is caused, and the problem brings great trouble to people.
Disclosure of Invention
The application provides a master and standby method and device based on a time sequence database and electronic equipment, which are used for solving the problem of data loss when the time sequence database fails.
A first aspect of an embodiment of the present application provides a master/slave method based on a time sequence database, where the method is applied to a system including a control node, a master database node, and a slave database node, and the master/slave method includes: the control node transmits data to the database and judges the communication state of the main database node and the standby database node; when the two nodes are in a connected state, a command for saving data is called to the main database node and the standby database node at the same time, when the main database node is not in the connected state, the command for saving data is called to the standby database node only, and a record that the current data is not saved in the main database node is recorded; checking the stored records at regular time, and automatically recovering data after the main database nodes are recovered and connected; when data in the database is needed, the data is acquired at the primary database node or the standby database node.
In one possible design, in a first implementation form of the first aspect of the embodiment of the present application, the method includes:
the control node is connected with the connectivity detector, the data distributor, the data log saver and the database data restorer.
In a possible design, in a second implementation form of the first aspect of the embodiment of the present application, the determining the connection status of the primary database node and the standby database node includes:
the connectivity detector judges the communication state of the primary database node and the standby database node.
In a possible design, in a third implementation form of the first aspect of this embodiment of the present application, the invoking a command to save data includes:
the data distributor invokes a command to save the data.
In a possible design, in a fourth implementation form of the first aspect of the embodiment of the present application, the recording a record that the current data is not saved in the master database node includes:
and the data log holder records the record that the current data is not stored in the master database node.
In a possible design, in a fifth implementation form of the first aspect of the embodiment of the present application, the periodically checking the saved records, and automatically restoring data after the master database node restores connectivity includes:
and the database data restorer checks the stored records at regular time and automatically restores the data after the main database nodes are restored to be communicated.
In a possible design, in a sixth implementation form of the first aspect of the embodiment of the present application, the acquiring, when data in a database is needed, the data at a primary database node or a standby database node includes:
and the data distributor acquires data from the main database node or the standby database node.
In one possible design, in a seventh implementation form of the first aspect of the embodiment of the present application, the method further includes:
and connecting the main database node and the standby database node with the database, wherein the data information of the main database node and the standby database node is kept consistent.
In a possible design, in an eighth implementation form of the first aspect of the embodiment of the present application, the method further includes
And configuring node information of the primary database node and the standby database node at the control node.
A second aspect of the embodiments of the present application provides a master/slave device based on a time sequence database, where the master/slave device is applied to a system including a control node, a master database node, and a slave database node, and the master/slave device includes:
the detection unit is used for judging the communication state of the main database node and the standby database node after the control node transmits data to the database;
the distribution unit is used for calling a data storage command to the main data node and the standby data node simultaneously when the main database node and the standby database node are in a connected state, or calling a data storage command to the standby data node only when the main database node is not in a connected state;
the storage unit is used for recording that the current data is not stored in the node when the main database node is not in a connected state;
and the recovery unit is used for checking the stored records at regular time and automatically recovering the data after the nodes of the main database are recovered and connected.
And the acquisition unit is used for acquiring the data from the main data node or the standby database node when the data in the database is needed.
A third aspect of the embodiments of the present application provides an electronic device, including a memory and a processor, where the processor is configured to implement the steps of the master-slave method based on a time-series database according to any one of the above descriptions when executing a computer program stored in the memory.
According to the technical scheme, the embodiment of the application has the following advantages: the control node transmits data to the database, the communication state of a main data node and a standby database node is judged, when the main data node and the standby database node are both in the communication state, a data storage command is called to the main data node and the standby data node at the same time, when the main database node is not in the communication state, the data storage command is called to the standby data node only, no record of the current data stored in the node is recorded, the record is checked regularly, after the main database node is communicated again, the data with problem time is recovered, and the problem of data loss caused by the fault of the time sequence database is avoided.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings needed to be used in the embodiments will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for a person skilled in the art to obtain other drawings without any inventive exercise.
Fig. 1 is a flowchart of a possible active/standby method based on a time series database according to an embodiment of the present disclosure;
fig. 2 is a flowchart of another possible active/standby method based on a time series database according to an embodiment of the present application
Fig. 3 is a schematic diagram of an embodiment of a possible primary and standby device based on a time sequence database according to an embodiment of the present disclosure;
fig. 4 is a schematic view of an embodiment of an electronic device according to an embodiment of the present application.
Detailed Description
The embodiment of the application provides a master and standby method and device based on a time sequence database and an electronic device, and solves the problem of data loss caused by the failure of the time sequence database.
The terms "first," "second," "third," and the like in the description and in the claims of the present application and in the drawings are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. Furthermore, the terms "comprises," "comprising," and variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not limited to those steps or elements expressly listed. The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings of the embodiments of the present application, and the embodiments are only a part of the embodiments of the present application, but not all of the embodiments.
In the research of the time sequence database, the applicant finds that more and more people tend to use the time sequence database because the time sequence database such as the infiluxdb database has more advantages, but when the time sequence database fails, data loss is caused, and great troubles are brought to people.
The applicant provides a master and standby method based on a time sequence database, which is applied to a system comprising a control node, a master database node and a standby database node, wherein the standby database node is used as a standby option to replace the master database node to store data when the master database node fails, the standby database can store data with the master database node at the same time when the master database node does not fail, the control node transmits the data to the database, the communication state of the master database node and the standby database node is judged, the two nodes are possibly in the communication state, one communicated and one not communicated condition possibly occurs, the master database node is in the not communicated state under the condition, the standby database node is in the communicated state, after the states of the two database nodes are detected, the selection is made according to the communication state adaptability of the two nodes, and selecting to call the command of saving data to the main database node and the standby data node simultaneously when the two nodes are in a connected state, and only call the command of saving data to the standby data node when the main database node is not in the connected state and the standby database node is in the connected state. When the primary database node is not in the connected state, only the command data for storing data is called to the standby data node, and simultaneously, the record, namely the log, which is not stored in the primary database node, of the current data is recorded, and then whether the record is stored in the data log storage device is checked regularly, when the record is not stored, namely the record not stored in the database node is changed, the primary database node is meant to restore the connected state, and the data in the time when the primary database node has a problem is automatically restored.
Referring to fig. 1, a flowchart of an embodiment of a master/standby method based on a time series database provided in an embodiment of the present application is applied to a system including a control node, a master database node, and a standby database node, and may include the following steps:
101: the control node transmits data to the database and judges the communication state of the main database node and the standby database node;
the connection state of the primary and backup database nodes may be that both nodes can be normally used, and it may be that one of the nodes cannot be normally used, and the execution step is determined according to the determination result, and when the primary and backup database nodes are both in the connection state, step 112 is executed, and when the primary database node is not in the connection state, step 122 is executed.
112: simultaneously calling a command for saving data from the primary database node and the standby database node, and then executing step 103;
122: the method comprises the steps of only calling a data storage command to a standby database node, simultaneously recording a record which is not stored in a main database node by current data, wherein the main database node is not in a connected state, the main database node cannot store the data, firstly recording the record which is not stored in the main database node by the current data, and recording the record in a log mode. After recording, step 132 may be performed.
132: and checking the stored records at regular time, and automatically recovering the data after the main database nodes are recovered to be communicated.
Checking the saved record periodically, when the saved record still exists, continuing the timed check, when the saved record can not be checked, it shows that the master database node has recovered the connection state, the missing data in the period that the node can not be used normally has been automatically recovered, after the data has been recovered, the saved current data is automatically erased in the master database node without the saved record, the master database node recovers the connection state, the data is automatically recovered, and step 103 can be executed.
103: when the data in the database is needed, the main database node or the standby database node is used for acquiring the data
When a user needs to use data in a database, such as an Influxdb database, the data is directly downloaded and acquired in a main database node or a standby database node.
Referring to fig. 2, a flowchart of another embodiment of a master/standby method based on a time series database provided in this embodiment of the present application is applied to a system including a control node, a master database node, and a standby database node, and may include the following steps:
201: the control node transmits data to a database, and the data reaches a connectivity detector first;
the control node is connected with the connectivity detector, the data distributor, the data log saver and the database data restorer. The main database node is connected with the database, the standby database node is connected with the database, meanwhile, the information of the databases of the main database node and the standby database node is kept consistent, the information of the databases can be database versions, account information and the like, and the data can be stored in the database or called from the database through the main database node and the standby database node. After the control node configures the information of the primary database node and the standby database node, the control node can store the data in the database through the primary database node or the standby database node or call the data from the database.
202: the connectivity detector judges the connectivity state of the main database node and the standby database node;
the control node transmits data to the database, the data reaches the connectivity detector, and then the connectivity detector judges the connection state of the main database node and the standby database node, wherein both the nodes can be normally used, namely the main database node and the standby database node are in the connection state, and one of the nodes can not be normally used, namely the main database is in the disconnection state, and the standby database is in the connection state.
And after the connectivity detector judges the communication state of the main database node and the standby database node, the data distributor sends a command of calling and storing data to the nodes according to the communication state. When both the primary and backup database nodes are in a connected state, step 213 is performed. When the master database node is not in a connected state, step 223 is performed.
213: the data distributor invokes a command to save data on both the primary and backup data nodes, and may then execute step 204.
223: the data distributor only calls the command to save data to the standby database node while the data log saver records the records that the current data is not saved in the primary database node, and may then perform step 233.
233: and the database data restorer checks the stored records at regular time and automatically restores the data after the main database nodes are restored to be communicated.
The database data restorer can check whether the data log saver has logs regularly, when the data log saver has logs, the data log saver records that current data are not saved in the master database node, at the moment, the master database node is still in an unconnected state, and the database data restorer can continue to check whether the data log saver has logs regularly; when the database data restorer detects that the data log saver has no log, the data log restorer indicates that the main data node restores the connected state, and after the main database node restores the connection, the database data restorer automatically restores the data which is lost when the main database node is in the unconnected state.
204: when the data in the database is needed, the data distributor obtains the data from the main database node or the standby database node.
When a user needs to use the data in the time sequence database, the data distributor is called to directly go to the main database node or the standby database node to obtain the needed data.
The present application also provides a master/standby device based on a time sequence database, which is applied to a system including a control node, a master database node, and a standby database node, and may include:
the detection unit 301 is configured to determine a communication state between a primary database node and a backup database node after the control node transmits data to the database;
a distributing unit 302, configured to call a data saving command to the primary database node and the standby database node simultaneously when the primary database node and the standby database node are both in a connected state, or call a data saving command only to the standby database node when the primary database node is not in a connected state;
a saving unit 303, configured to record that the current data is not saved in the node when the master database node is not in a connected state;
and the recovery unit 304 is used for checking the saved records at regular time and automatically recovering the data after the main database nodes are recovered to be connected.
An obtaining unit 305, configured to go to the primary database node or the standby database node to obtain data when data in the database is needed.
In some embodiments, the apparatus further includes a control unit, configured to invoke the distribution unit to obtain the data from the available node when the user needs to use the data in the infiluxdb.
The detection unit provided by the embodiment of the application judges the communication state of the main database node and the standby database node, when the two nodes are in the communication state, the distribution unit simultaneously calls the data storage command to the main database node and the standby database node, and when the main database node is not in the communication state, the standby database node is in the communication state, the distribution unit only calls the data storage command to the standby database node. When the main database node is not in a connected state, only the command data for storing the data is called to the standby database node, the storage unit records the log which is the record that the current data is not stored in the main database node, and then the recovery unit periodically checks whether the data log storage device has the log, when the log does not exist, the record that the data log storage device does not store disappears, namely the main database node is in a connected state, the data in the time when the main database node has a problem is automatically recovered, and the problems that the time sequence database has a fault and the data is lost are avoided.
Based on the above embodiments of the detection method and apparatus, the present application further provides an electronic device, which will be explained with reference to the drawings.
Referring to fig. 4, an electronic device 400 according to an embodiment of the present application includes a memory 401, a processor 402, and a computer program 411 stored in the memory 401, where the processor 402 executes the computer program 411 to implement the following steps:
judging the communication state of the main database node and the standby database node; when the two nodes are in a connected state, a command for storing data is called to the main database node and the standby data node at the same time, when the main database node is not in the connected state, the command for storing data is called to the standby data node only, and the current data is recorded without a storage record at the node; checking the stored record of the node at regular time, and automatically recovering the data after the node is recovered; and when the data in the database is needed, the data is acquired from the main database node or the standby database node.
The above embodiments are only used to illustrate the technical solutions of the present invention, but not to limit the present application. Those skilled in the art can now make numerous possible variations and modifications to the disclosed embodiments, or modify equivalent embodiments, using the methods and techniques disclosed above, without departing from the scope of the claimed embodiments. Therefore, any simple modification, equivalent change and modification made to the above embodiments according to the technical essence of the present application still fall within the protection scope of the technical solution of the present application without departing from the content of the technical solution of the present application.

Claims (11)

1. A master-standby method based on a time sequence database is applied to a system comprising a control node, a master database node and a standby database node, and is characterized in that the master-standby method comprises the following steps:
the control node transmits data to the database and judges the communication state of the main database node and the standby database node;
when the two nodes are in a connected state, a command for saving data is called to the main database node and the standby database node at the same time, when the main database node is not in the connected state, the command for saving data is called to the standby database node only, and a record that the current data is not saved in the main database node is recorded;
checking the stored records at regular time, and automatically recovering data after the main database nodes are recovered and connected;
when data in the database is needed, the data is acquired at the primary database node or the standby database node.
2. The method of claim 1, wherein the control node comprises:
the system comprises a connectivity detector, a data distributor, a data log saver and a database data restorer.
3. The method of claim 2, wherein determining the connectivity status of the primary and backup database nodes comprises:
and the connectivity detector judges the communication state of the primary database node and the standby database node.
4. The method of claim 2, wherein invoking the command to save data comprises:
the data distributor invokes a command to save data.
5. The method of claim 2, wherein recording records that current data is not maintained at the master database node comprises:
and the data log holder records the record that the current data is not stored in the master database node.
6. The method of claim 2, wherein said periodically checking the saved records, and automatically restoring data after the primary database node restores connectivity comprises:
and the database data restorer checks the stored records at regular time and automatically restores the data after the main database nodes are restored to be communicated.
7. The method of claim 2, wherein obtaining data at a primary or backup database node when data in a database is needed comprises:
the data distributor obtains data at a primary database node or a backup database node.
8. The method of claim 1, further comprising:
and connecting the main database node and the standby database node with the database, wherein the data information of the main database node and the standby database node is kept consistent.
9. The method of claim 1, further comprising:
and configuring node information of the primary database node and the standby database node at the control node.
10. A master device based on a time sequence database is characterized in that the device is applied to a system comprising a control node, a master database node and a standby database node, and the master device comprises:
the detection unit is used for judging the communication state of the main database node and the standby database node after the control node transmits data to the database;
the distribution unit is used for calling a data storage command to the main database node and the standby database node simultaneously when the main database node and the standby database node are in a connected state, or calling a data storage command to the standby database node only when the main database node is not in a connected state;
the storage unit is used for recording that the current data is not stored in the node when the main database node is not in a connected state;
the recovery unit is used for checking the stored records at regular time and automatically recovering data after the main database nodes are recovered and connected;
and the acquisition unit is used for acquiring the data at the main data node or the standby database node when the data in the database is needed.
11. An electronic device comprising a memory and a processor, wherein the processor is configured to implement the steps of the sequential database based active/standby method according to any one of claims 1-9 when executing a computer program stored in the memory.
CN201910816659.7A 2019-08-30 2019-08-30 Master and standby method and device based on time sequence database and electronic equipment Pending CN110704238A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910816659.7A CN110704238A (en) 2019-08-30 2019-08-30 Master and standby method and device based on time sequence database and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910816659.7A CN110704238A (en) 2019-08-30 2019-08-30 Master and standby method and device based on time sequence database and electronic equipment

Publications (1)

Publication Number Publication Date
CN110704238A true CN110704238A (en) 2020-01-17

Family

ID=69194106

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910816659.7A Pending CN110704238A (en) 2019-08-30 2019-08-30 Master and standby method and device based on time sequence database and electronic equipment

Country Status (1)

Country Link
CN (1) CN110704238A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113434604A (en) * 2021-08-25 2021-09-24 西安热工研究院有限公司 Time sequence database synchronization method, system, equipment and storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20090037432A1 (en) * 2007-07-31 2009-02-05 Kabushiki Kaisha Toshiba Information communication system and data sharing method
CN102158540A (en) * 2011-02-18 2011-08-17 广州从兴电子开发有限公司 System and method for realizing distributed database
GB201408071D0 (en) * 2012-05-04 2014-06-18 Box Inc Repository redundancy implementation of a system which incrementally updates clients with events that occured via a cloud-enabled platform
CN105721200A (en) * 2016-01-21 2016-06-29 北京乐动卓越科技有限公司 Master-slave server system application method and system thereof

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20090037432A1 (en) * 2007-07-31 2009-02-05 Kabushiki Kaisha Toshiba Information communication system and data sharing method
CN102158540A (en) * 2011-02-18 2011-08-17 广州从兴电子开发有限公司 System and method for realizing distributed database
GB201408071D0 (en) * 2012-05-04 2014-06-18 Box Inc Repository redundancy implementation of a system which incrementally updates clients with events that occured via a cloud-enabled platform
CN105721200A (en) * 2016-01-21 2016-06-29 北京乐动卓越科技有限公司 Master-slave server system application method and system thereof

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113434604A (en) * 2021-08-25 2021-09-24 西安热工研究院有限公司 Time sequence database synchronization method, system, equipment and storage medium
CN113434604B (en) * 2021-08-25 2021-12-03 西安热工研究院有限公司 Time sequence database synchronization method, system, equipment and storage medium

Similar Documents

Publication Publication Date Title
CN106713487B (en) Data synchronization method and device
CN108847982B (en) Distributed storage cluster and node fault switching method and device thereof
KR100743180B1 (en) Duplex data system
CN106789306B (en) Method and system for detecting, collecting and recovering software fault of communication equipment
WO2020248507A1 (en) Container cloud-based system resource monitoring method and related device
CN104036043B (en) High availability method of MYSQL and managing node
CN107357688B (en) Distributed system and fault recovery method and device thereof
CN110543386B (en) Data storage method, device, equipment and storage medium
CN111651523B (en) MySQL data synchronization method and system of Kubernetes container platform
CN106484565A (en) Method of data synchronization between multiple data centers and relevant device
CN112597202B (en) Data query method and device, computer equipment and storage medium
CN109144789A (en) A kind of method, apparatus and system for restarting OSD
CN109361777B (en) Synchronization method, synchronization system and related device for distributed cluster node states
CN117130730A (en) Metadata management method for federal Kubernetes cluster
CN110704238A (en) Master and standby method and device based on time sequence database and electronic equipment
CN109491856B (en) Bus monitoring system, method and device
CN106649000A (en) Fault recovery method for real-time processing engine, and corresponding server
CN101321319A (en) Monitoring and recovery apparatus and method for invalid connection of business database
CN104158843A (en) Storage unit invalidation detecting method and device for distributed file storage system
Danilecki et al. ReServE service: An approach to increase reliability in service oriented systems
US20130166714A1 (en) System and method for data storage
CN112579383A (en) Method and device for simulating system fault
CN112491633B (en) Fault recovery method, system and related components of multi-node cluster
CN114666201A (en) High-availability distributed micro-service architecture
CN114116318A (en) Data backup method and device, computer 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
RJ01 Rejection of invention patent application after publication

Application publication date: 20200117

RJ01 Rejection of invention patent application after publication