CN111475334A - TiDB database maintenance method and device, computer equipment and storage medium - Google Patents

TiDB database maintenance method and device, computer equipment and storage medium Download PDF

Info

Publication number
CN111475334A
CN111475334A CN202010150801.1A CN202010150801A CN111475334A CN 111475334 A CN111475334 A CN 111475334A CN 202010150801 A CN202010150801 A CN 202010150801A CN 111475334 A CN111475334 A CN 111475334A
Authority
CN
China
Prior art keywords
tidb
data
file
binlog
library
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
CN202010150801.1A
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.)
Ping An Technology Shenzhen Co Ltd
Original Assignee
Ping An Technology Shenzhen 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 Ping An Technology Shenzhen Co Ltd filed Critical Ping An Technology Shenzhen Co Ltd
Priority to CN202010150801.1A priority Critical patent/CN111475334A/en
Publication of CN111475334A publication Critical patent/CN111475334A/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
    • 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/1458Management of the backup or restore process
    • G06F11/1469Backup restoration techniques
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor

Abstract

The invention discloses a method and a device for maintaining a TiDB database, computer equipment and a storage medium, wherein the method comprises the following steps: the method comprises the steps of collecting data in a TiDB production library through a TiDB-Binlog cluster component to obtain a binlogo file corresponding to the data in the TiDB production library, synchronizing the binlogo file to a TiDB city-wide disaster backup library, synchronizing the binlogo file in the TiDB city-wide disaster backup library to a flash NAS device by adopting a preset timing backup script, and carrying out data reduction processing on the TiDB production library based on the binlogo file stored in the flash NAS device when the abnormality of the TiDB production library is monitored, so that the problem of low backup and reduction speed caused by the fact that the data in the production library are directly stored in a filing tape in a traditional mode is solved, and the maintenance efficiency of the TiDB database is improved.

Description

TiDB database maintenance method and device, computer equipment and storage medium
Technical Field
The invention relates to the field of data processing, in particular to a method and a device for maintaining a TiDB database, computer equipment and a storage medium.
Background
With the rapid development of economy, more and more enterprise organizations have larger and larger service ranges, user groups are wider and wider, a plurality of enterprises begin to adopt a distributed database for data storage so as to improve service processing capacity, and the TiDB is an open-source distributed relational database, has higher safety, is compatible with the MySQ L protocol and ecology, is convenient to migrate, has extremely low operation and maintenance cost, and becomes a popular distributed database.
When the database is in transaction processing, data backup is needed, so that when a fault occurs, data recovery and restoration processing is performed according to a backup file.
Disclosure of Invention
The embodiment of the invention provides a method and a device for maintaining a TiDB database, computer equipment and a storage medium, which are used for improving the maintenance efficiency of the TiDB database.
In order to solve the above technical problem, an embodiment of the present application provides a method for maintaining a TiDB database, including:
collecting data in a TiDB production library through a TiDB-Binlog cluster component to obtain a Binlog file corresponding to the data in the TiDB production library, and synchronizing the Binlog file to a TiDB city disaster recovery database;
synchronizing the binlog file in the TiDB city disaster recovery database to a flash memory NAS device by adopting a preset timing backup script;
and if the TiDB production library is monitored to be abnormal, carrying out data reduction processing on the TiDB production library based on the binlog file stored in the flash NAS equipment.
Optionally, the TiDB-Binlog cluster component includes a Drainer component and a pump component, and the collecting data in the TiDB production library by the TiDB-Binlog cluster component to obtain a Binlog file corresponding to the data in the TiDB production library, and synchronizing the Binlog file to the TiDB city disaster recovery library includes:
collecting a bin log file of a TiDB node server corresponding to the pump component as a basic file through the pump component, and sending the basic file to the Drainer component;
receiving the basic file through the Drainer component and merging the basic file to obtain a merged bin log file;
and synchronizing the merged bindlog file to the TiDB city disaster recovery database.
Optionally, the flash NAS device includes a first flash device and a second flash device.
Optionally, the synchronizing the binlog file in the TiDB city disaster recovery library to the flash NAS device by using a preset timing backup script includes:
moving and storing binlog files in the TiDB and city disaster recovery database into the first flash memory device;
carrying out incremental and full differential verification on the first flash memory device and the second flash memory device at regular time to obtain a verification result;
and if the verification result is that the difference exists, updating the data in the second flash memory device by adopting the data in the first flash memory device according to the difference in the verification result.
Optionally, the moving and saving the binlog file in the TiDB city disaster recovery library to the first flash memory device includes:
taking a binlog file in the TiDB and city disaster recovery database as data to be imported, and acquiring a storage path of the first flash memory device corresponding to the data to be imported;
determining the number of target threads based on the data to be imported and the first flash memory device;
and constructing multiple threads based on the number of the target threads, and synchronizing the data to be imported to a storage path of the first flash memory device by adopting the multiple threads.
Optionally, if the TiDB production library is monitored to be abnormal, performing data reduction processing on the TiDB production library based on the binlog file stored in the flash NAS device includes:
stopping the table writing processing of the application service on the TiDB production library, and emptying data in a data table of the TiDB production library;
acquiring a full standby file and an additional standby file from the flash memory NAS device to be used as files to be restored;
loading the full standby file into a data table in a TiDB production library, and then loading an additional standby file into the data table in the TiDB production library;
and verifying the data in the data table in the TiDB production library, confirming that the data is successfully restored after the data passes the verification, and starting application service.
In order to solve the foregoing technical problem, an embodiment of the present application further provides a device for maintaining a TiDB database, including:
the data acquisition module is used for acquiring data in the TiDB production library through the TiDB-Binlog cluster component to obtain a Binlog file corresponding to the data in the TiDB production library and synchronizing the Binlog file to the TiDB city disaster backup library;
the file synchronization module is used for synchronizing the binlog file in the TiDB city disaster recovery database to the flash memory NAS device by adopting a preset timing backup script;
and the data recovery module is used for performing data reduction processing on the TiDB production library based on the binlog file stored in the flash NAS device if the abnormality of the TiDB production library is monitored.
Optionally, the data acquisition module comprises:
the collection unit is used for collecting a bin log file of the TiDB node server corresponding to the pump component as a basic file through the pump component and sending the basic file to the Drainer component;
the merging unit is used for receiving the basic file through the Drainer component and merging the basic file to obtain a merged bindlog file;
and the synchronization unit is used for synchronizing the merged bindlog file to the TiDB city disaster recovery database.
Optionally, the flash NAS device includes a first flash device and a second flash device, and the file synchronization module includes:
the synchronization unit is used for moving and storing binlog files in the TiDB city disaster recovery database into the first flash memory device;
the verification unit is used for performing incremental and full-scale difference verification on the first flash memory device and the second flash memory device at regular time to obtain a verification result;
and the updating unit is used for updating the data in the second flash memory device by adopting the data in the first flash memory device according to the difference in the verification result if the verification result shows that the difference exists.
Optionally, the synchronization unit comprises:
a path obtaining subunit, configured to use a binlog file in the TiDB city disaster recovery library as data to be imported, and obtain a storage path of the first flash memory device corresponding to the data to be imported;
the thread number determining subunit is used for determining the number of target threads based on the data to be imported and the first flash memory device;
and the multithreading synchronization subunit is used for constructing multithreading based on the number of the target threads and synchronizing the data to be imported to a storage path of the first flash memory device by adopting the multithreading.
Optionally, the data recovery module comprises:
the data cleaning unit is used for stopping the table writing processing of the application service on the TiDB production library and cleaning data in the data table of the TiDB production library;
the file to be restored determining unit is used for acquiring a full backup file and an additional backup file from the flash memory NAS device to serve as files to be restored;
the file reduction unit is used for loading the full standby file into a data table in a TiDB production library and then loading an additional standby file into the data table in the TiDB production library;
and the data verification unit is used for verifying the data in the data table in the TiDB production library, confirming that the data is successfully restored after the data passes the verification, and starting the application service.
In order to solve the technical problem, an embodiment of the present application further provides a computer device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, and the processor implements the steps of the method for maintaining the TiDB database when executing the computer program.
In order to solve the above technical problem, an embodiment of the present application further provides a computer-readable storage medium, where a computer program is stored, and the computer program, when executed by a processor, implements the steps of the method for maintaining the TiDB database.
According to the TiDB database maintenance method, the TiDB database maintenance device, the computer equipment and the storage medium, data in the TiDB production library are collected through the TiDB-Binlog cluster assembly, the Binlog file corresponding to the data in the TiDB production library is obtained, the Binlog file is synchronized to the TiDB same-city disaster backup library, the Binlog file in the TiDB same-city disaster backup library is synchronized to the flash NAS device through the preset timing backup script, the abnormal situation of the TiDB production library is monitored, the data reduction processing is carried out on the TiDB production library based on the Binlog file stored in the NAS device, the problem that the backup and reduction speed are slow due to the fact that the data in the production library are directly stored in a filing tape in the traditional mode is solved, and the database maintenance efficiency is improved.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings needed to be used in the description of the embodiments of the present invention will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art that other drawings can be obtained according to these drawings without inventive labor.
FIG. 1 is an exemplary system architecture diagram in which the present application may be applied;
FIG. 2 is a flow diagram of one embodiment of a method of maintaining a TiDB database of the present application;
FIG. 3 is a schematic diagram of one embodiment of a TiDB database maintenance device according to the present application;
FIG. 4 is a schematic block diagram of one embodiment of a computer device according to the present application.
Detailed Description
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs; the terminology used in the description of the application herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application; the terms "including" and "having," and any variations thereof, in the description and claims of this application and the description of the above figures are intended to cover non-exclusive inclusions. The terms "first," "second," and the like in the description and claims of this application or in the above-described drawings are used for distinguishing between different objects and not for describing a particular order.
Reference herein to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the application. The appearances of the phrase in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. It is explicitly and implicitly understood by one skilled in the art that the embodiments described herein can be combined with other embodiments.
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Referring to fig. 1, as shown in fig. 1, a system architecture 100 may include terminal devices 101, 102, 103, a network 104 and a server 105. The network 104 serves as a medium for providing communication links between the terminal devices 101, 102, 103 and the server 105. Network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
The user may use the terminal devices 101, 102, 103 to interact with the server 105 via the network 104 to receive or send messages or the like.
The terminal devices 101, 102, 103 may be various electronic devices having display screens and supporting web browsing, including but not limited to smart phones, tablet computers, E-book readers, MP3 players (Moving Picture E interface displays the properties Group Audio L layer III, mpeg compression standard Audio layer 3), MP4(Moving Picture E interface displays the properties Group Audio L layer IV, mpeg compression standard Audio layer 4) players, laptop portable computers, desktop computers, and the like.
The server 105 may be a server providing various services, such as a background server providing support for pages displayed on the terminal devices 101, 102, 103.
The method for maintaining the TiDB database provided in the embodiment of the present application is executed by a server, and accordingly, a device for maintaining the TiDB database is provided in the server.
It should be understood that the number of terminal devices, networks, and servers in fig. 1 is merely illustrative. Any number of terminal devices, networks and servers may be provided according to implementation needs, and the terminal devices 101, 102 and 103 in this embodiment may specifically correspond to an application system in actual production.
Referring to fig. 2, fig. 2 shows a method for maintaining a TiDB database according to an embodiment of the present invention, which is described by taking the method applied to the server in fig. 1 as an example, and is detailed as follows:
s201: and collecting data in the TiDB production library through the TiDB-Binlog cluster component to obtain a Binlog file corresponding to the data in the TiDB production library, and synchronizing the Binlog file to the TiDB city disaster preparation library.
The TiDB is a fusion database product positioned on online transaction processing/online analysis processing (HTAP), realizes important characteristics of one-key horizontal expansion and strong consistency, such as multi-copy data safety, distributed transaction, real-time O L AP and the like, is compatible with MySQ L protocol and ecology, is convenient to migrate, and has extremely low operation and maintenance cost.
Specifically, in this embodiment, a plurality of TiDB node servers are included, and during operation, the TiDB node servers may perform data update (including but not limited to addition, deletion, modification, query, backup, and the like), acquire updated data in each TiDB node server through the TiDB-Binlog cluster component, generate corresponding Binlog files according to the updated data, and synchronize the Binlog files to the TiDB city disaster recovery database.
The TiDB city-wide disaster recovery database refers to a backup database of the same region based on TiDB.
The binlog file is a log file in a binary format and is used for recording SQ L statement information updated on a database by a user, for example, an SQ L statement for changing a database table and changing content is recorded into the binlog, but a query for the content such as the base table is not recorded.
When data is written into the database, the updated SQ L statement is written into the corresponding binlog file, and when dump backup is used, the data is completely backed up for a while.
S202: and synchronizing the binlog file in the TiDB and city disaster recovery database to the flash memory NAS device by adopting a preset timing backup script.
The existing plug-in storage is divided into the following steps according to the connection mode: Direct-Attached Storage (DAS) and networked Storage (FAS); the networked storage is further divided into: Network-Attached Storage (NAS) and Storage Area Network (SAN).
NAS usually has its own node in L AN, allowing users to access data on the network without application server intervention, in this configuration, NAS centrally manages and processes all data on the network, off-loads from application or enterprise servers, effectively reducing total cost of ownership, protecting user investment.
The NAS device is a product which is really plug-and-play, is also called as a flash NAS device and generally supports a multi-computer platform, a user can enter the same document through a network support protocol, so the NAS device can be used in a mixed Unix/Windows NT local area network without being modified, meanwhile, the application of the NAS device is very flexible, compared with other plug-in storage modes, a key problem of the flash NAS device is that the bandwidth consumption in the backup process is caused, and the NAS device still uses the network for backup and recovery, and is different from a Storage Area Network (SAN) which transfers backup data streams from L AN, so the NAS device can perform data backup and recovery in a multi-thread mode, and the data recovery and backup efficiency is improved.
The preset timed backup script is used for synchronizing the binlog file at regular time, for example, the binlog file with the creation time of the previous day in the drawer is transferred to the flash memory NAS device at 2 points per day through the timed backup script, and the types of the preset timed backup script include but are not limited to shell script, JavaScript script, L ua script, python script and the like.
According to the existing TiDB database backup method, when a production library fails, a full backup needs to be restored and an additional backup file needs to be added to a local server through an archival tape and then the backup file is imported into a database, because the full backup files of the database needing to be restored from the archival tape are generally large (the database is different in scale and generally ranges from dozens of G to several T), the tape IO capacity is weak, the time spent on acquiring the restoration files is long, the application stop time is prolonged, and serious influence is caused on the continuous operation of a service system.
It should be noted that the flash NAS device is not suitable for permanently storing data, and in this embodiment, after the binlog file is moved and stored in the flash NAS device, the data stored in the flash NAS device is further synchronized to an archive tape, so that the data can be stored and read offline.
The archive tape is also called a magnetic tape storage (magnetic tape storage), is a storage device which takes a magnetic tape as a storage medium and consists of a tape drive and a controller thereof, and is an auxiliary storage of a computer. The magnetic tape drive comprises a magnetic tape actuator and a magnetic head, and is capable of driving a magnetic tape to move relative to the magnetic head, performing electromagnetic conversion by the magnetic head, and sequentially recording or reading data on the magnetic tape. Tape storage is one of the computer peripherals. The tape controller is a control circuit device for accessing data to the tape drive by the cpu. The tape storage accesses data in a sequential manner. The magnetic tape storing the data may be stored off-line and read interchangeably.
S203: and if the TiDB production library is monitored to be abnormal, carrying out data reduction processing on the TiDB production library based on the binlog file stored in the flash memory NAS equipment.
Specifically, the server side is provided with configuration application log monitoring and database performance index monitoring, the monitoring monitors various data in the TiDB production library in real time, when partial data in the TiDB production library is monitored to exceed a normal preset range, the abnormity of the TiDB production library is confirmed, at the moment, an alarm prompt is carried out through a mail or a telephone, and data recovery processing is carried out through a binlog file stored in the flash memory NAS device.
The specific process of performing data reduction processing through the binlog file stored in the flash NAS device may refer to the description of the subsequent embodiment, and is not repeated here to avoid repetition.
In this embodiment, the data in the TiDB production library is collected by the TiDB-Binlog cluster component to obtain a Binlog file corresponding to the data in the TiDB production library, the Binlog file is synchronized to the TiDB city disaster recovery library, a preset timing backup script is used to synchronize the Binlog file in the TiDB city disaster recovery library to the flash NAS device, and when the TiDB production library is monitored to be abnormal, the data recovery processing is performed on the TiDB production library based on the Binlog file stored in the flash NAS device, so that the problem of slow backup and recovery speed caused by the fact that the data in the production library is directly stored in a filing tape in the conventional manner is solved, and the database maintenance efficiency is improved.
In some optional implementation manners of this embodiment, in step S201, the TiDB-Binlog cluster component includes a Drainer component and a pump component, the data in the TiDB production library is collected by the TiDB-Binlog cluster component, a Binlog file corresponding to the data in the TiDB production library is obtained, and synchronizing the Binlog file to the TiDB city disaster recovery library includes:
collecting a bin log file of a TiDB node server corresponding to the pump component as a basic file through the pump component, and sending the basic file to a Drainer component;
receiving the basic file through a Drainer component and merging the basic file to obtain a merged bin log file;
and synchronizing the merged bindlog file to the TiDB city disaster recovery database.
Specifically, the server comprises a plurality of TiDB node servers, each TiDB node server corresponds to a pump component, after the TiDB node servers generate a bin log file, the pump components collect the bin log file as a basic file and send the basic file to a Drainer component, the Drainer component merges all the received basic files, the merged bin log file is synchronized to the TiDB same-city disaster preparation library.
Easily understood, the data format in the bin file is binary, and the synchronous backup by using the bin file can greatly improve the backup efficiency.
The pump component generates a daemon process which runs in the background of each TiDB node server, and the main function of the daemon process is to record the Binlog files generated by the TiDB node servers when executing data processing in real time and write the Binlog files into corresponding storage spaces in sequence.
Wherein, the Drainer component interacts with the pump component and collects the Binlog file.
In this embodiment, the bin log file of the TiDB node server corresponding to the pump component is collected by the pump component and is used as the basic file, the basic file is sent to the Drainer component, the Drainer component receives and merges the basic file to obtain the merged bin log file, and the merged bin log file is synchronized to the TiDB city disaster recovery library, so that the bin log file is quickly synchronized to the TiDB city disaster recovery library, and the efficiency of quickly synchronizing the bin log file to the TiDB city disaster recovery library is improved.
In some optional implementation manners of this embodiment, in step S202, the flash NAS device includes a first flash device and a second flash device, and synchronizing the binlog file in the TiDB city disaster recovery library to the flash NAS device by using a preset timing backup script includes:
moving and storing binlog files in the TiDB and city disaster recovery database into first flash memory equipment;
carrying out incremental and full differential verification on the first flash memory device and the second flash memory device at regular time to obtain a verification result;
and if the verification result is that the difference exists, updating the data in the second flash memory device by adopting the data in the first flash memory device according to the difference in the verification result.
Specifically, the flash NAS device in this embodiment includes a first flash device and a second flash device, where the first flash device is a main storage device, the second flash device is a spare storage device, and the second flash devices are installed in the same area of the TiDB production library. And when the network is abnormally interrupted, the backup storage equipment in the same region network environment as the TiDB production library is adopted, so that the backup files of the database can be acquired from the backup storage equipment in the same city under the condition of cross-region network access failure, and the database can be quickly recovered.
And further, moving and storing binlog files in the TiDB and city disaster backup database into the first flash memory device, carrying out incremental and full difference check on the first flash memory device and the second flash memory device at regular time to obtain a check result, and updating data in the second flash memory device by adopting the data in the first flash memory device according to the difference in the check result when the check result shows that the difference exists, so as to rapidly realize synchronous updating of the first flash memory device and the second flash memory device.
The increment refers to the data that is updated last time, and the full amount refers to all the data.
The method comprises the following steps of carrying out incremental and full-amount difference verification on a first flash memory device and a second flash memory device at regular time, and obtaining a verification result, wherein the step of carrying out incremental and full-amount difference verification on the first flash memory device and the second flash memory device comprises the following steps: comparing the full and incremental file differences of the first flash memory device and the second flash memory device through the timing script, wherein the main comparison points include but are not limited to: file size, file modification time, and file creation time, etc. The specific comparison mode can adopt a character string matching mode.
In this embodiment, the binlog file in the TiDB city disaster backup library is moved and stored in the first flash memory device, incremental and full difference verification is performed on the first flash memory device and the second flash memory device at regular time, a verification result is obtained, and when the verification result indicates that there is a difference, data in the first flash memory device is used to update data in the second flash memory device according to the difference in the verification result, so that the first flash memory device and the second flash memory device are updated quickly and synchronously.
In some optional implementations of this embodiment, moving and saving the binlog file in the TiDB city disaster recovery library to the first flash memory device includes:
taking a binlog file in the TiDB city disaster recovery database as data to be imported, and acquiring a storage path of first flash memory equipment corresponding to the data to be imported;
determining the number of target threads based on the data to be imported and the first flash memory device;
and constructing multiple threads based on the number of the target threads, and synchronizing the data to be imported to a storage path of the first flash memory device by adopting the multiple threads.
Specifically, each TiDB node server corresponds to a preset storage path in a first flash memory device, a binlog file in the TiDB and city disaster backup library is used as data to be imported, the storage path of the first flash memory device corresponding to the data to be imported is determined according to the TiDB node server corresponding to the data to be imported, the number of target threads is determined according to the imported data and the first flash memory device, and multithreading of the number is constructed for data synchronization.
The method comprises the following steps of determining the number of target threads based on data to be imported and first flash memory equipment, wherein the specific process is as follows: according to the host CPU core number setting, the minimum thread number is set at first, then the minimum thread number is amplified slowly in multiple, meanwhile, the host IO and the network load are observed, and the number of the lead-in threads is dynamically determined according to the host load.
In this embodiment, the number of threads is dynamically determined, and a multithreading mode is adopted to synchronize the binlog file to the first flash memory device, which is beneficial to saving system resources and improving data backup efficiency.
In some optional implementation manners of this embodiment, in step S203, if it is monitored that the TiDB production library is abnormal, performing data reduction processing on the TiDB production library based on the binlog file stored in the flash NAS device includes:
stopping the table writing processing of the application service on the TiDB production library, and emptying data in a data table of the TiDB production library;
acquiring a full backup file and an additional backup file from the NAS device as files to be restored;
loading the full standby file into a data table in a TiDB production library, and then loading the additional standby file into the data table in the TiDB production library;
and verifying the data in the data table in the TiDB production library, confirming that the data is successfully restored after the data passes the verification, and starting application service.
Specifically, files corresponding to all data stored in the flash memory NAS device are used as full-text files, files corresponding to the last backed-up data are used as gift files, when the TiDB production library is monitored to be abnormal, the application service is stopped from writing a table of the TiDB production library, data in a data table of the TiDB production library is emptied, the full-text files and the added backup files are used as files to be restored, the data in the data table of the TiDB production library are restored by using the files to be restored, the data in the data table of the TiDB production library are verified after the data restoration is completed, after the data are verified, the data are confirmed to be successfully restored, and the application service is started.
In the embodiment, when the abnormality of the TiDB production library is monitored, the read-write processing of the data table of the TiDB production library is stopped, the file to be restored is acquired from the flash memory NAS device and restored into the data table of the TiDB production library, the data in the data table in the restored TiDB production library is verified, and the application service is started after the verification is passed, so that the automatic and rapid restoration is realized when the TiDB production library is abnormal, and the restoration efficiency of the database is improved.
It should be understood that, the sequence numbers of the steps in the foregoing embodiments do not imply an execution sequence, and the execution sequence of each process should be determined by its function and inherent logic, and should not constitute any limitation to the implementation process of the embodiments of the present invention.
Fig. 3 is a schematic block diagram of a TiDB database maintenance device in one-to-one correspondence with the TiDB database maintenance method according to the above-described embodiment. As shown in fig. 3, the apparatus for maintaining the TiDB database includes a data collection module 31, a file synchronization module 32, and a data recovery module 33. The functional modules are explained in detail as follows:
the data acquisition module 31 is used for acquiring data in the TiDB production library through the TiDB-Binlog cluster component to obtain a Binlog file corresponding to the data in the TiDB production library, and synchronizing the Binlog file to the TiDB city disaster backup library;
the file synchronization module 32 is configured to synchronize a binlog file in the TiDB city disaster recovery library to the flash NAS device by using a preset timing backup script;
and the data recovery module 33 is configured to, if the TiDB production library is monitored to be abnormal, perform data reduction processing on the TiDB production library based on the binlog file stored in the flash NAS device.
Optionally, the data acquisition module 31 includes:
the collection unit is used for collecting the bin log file of the TiDB node server corresponding to the pump component as a basic file through the pump component and sending the basic file to the Drainer component;
the merging unit is used for receiving the basic files through the Drainer component and merging the basic files to obtain merged bin log files;
and the synchronization unit is used for synchronizing the merged bindlog file to the TiDB city disaster recovery database.
Optionally, the flash NAS device includes a first flash device and a second flash device, and the file synchronization module 32 includes:
the synchronization unit is used for moving and storing binlog files in the TiDB city disaster recovery database into the first flash memory device;
the verification unit is used for performing incremental and full-amount difference verification on the first flash memory device and the second flash memory device at regular time to obtain a verification result;
and the updating unit is used for updating the data in the second flash memory device by adopting the data in the first flash memory device according to the difference in the verification result if the verification result shows that the difference exists.
Optionally, the synchronization unit comprises:
the path acquisition subunit is used for taking the binlog file in the TiDB city disaster recovery database as data to be imported and acquiring a storage path of the first flash memory device corresponding to the data to be imported;
the thread number determining subunit is used for determining the number of target threads based on the data to be imported and the first flash memory device;
and the multithreading synchronization subunit is used for constructing multithreading based on the number of the target threads and synchronizing the data to be imported to a storage path of the first flash memory device by adopting multithreading.
Optionally, the data recovery module 33 includes:
the data cleaning unit is used for stopping the table writing processing of the application service on the TiDB production library and cleaning data in the data table of the TiDB production library;
the device comprises a to-be-restored file determining unit, a restoring unit and a restoring unit, wherein the to-be-restored file determining unit is used for acquiring a full standby file and an additional standby file from the flash memory NAS device as to-be-restored files;
the file reduction unit is used for loading the full standby file into a data table in the TiDB production library and then loading the additional standby file into the data table in the TiDB production library;
and the data verification unit is used for verifying the data in the data table in the TiDB production library, confirming that the data is successfully restored after the data passes the verification, and starting the application service.
For specific limitations of the maintenance device of the TiDB database, reference may be made to the above limitations of the maintenance method of the TiDB database, which are not described herein again. The modules in the maintenance device of the TiDB database may be implemented in whole or in part by software, hardware, and a combination thereof. The modules can be embedded in a hardware form or independent from a processor in the computer device, and can also be stored in a memory in the computer device in a software form, so that the processor can call and execute operations corresponding to the modules.
In order to solve the technical problem, an embodiment of the present application further provides a computer device. Referring to fig. 4, fig. 4 is a block diagram of a basic structure of a computer device according to the present embodiment.
The computer device 4 comprises a memory 41, a processor 42, a network interface 43 communicatively connected to each other via a system bus. It is noted that only the computer device 4 having the components connection memory 41, processor 42, network interface 43 is shown, but it is understood that not all of the shown components are required to be implemented, and that more or fewer components may be implemented instead. As will be understood by those skilled in the art, the computer device is a device capable of automatically performing numerical calculation and/or information processing according to a preset or stored instruction, and the hardware includes, but is not limited to, a microprocessor, an Application Specific Integrated Circuit (ASIC), a Programmable Gate Array (FPGA), a Digital Signal Processor (DSP), an embedded device, and the like.
The computer device can be a desktop computer, a notebook, a palm computer, a cloud server and other computing devices. The computer equipment can carry out man-machine interaction with a user through a keyboard, a mouse, a remote controller, a touch panel or voice control equipment and the like.
The memory 41 includes at least one type of readable storage medium including a flash memory, a hard disk, a multimedia card, a card-type memory (e.g., SD or D interface display memory, etc.), a Random Access Memory (RAM), a Static Random Access Memory (SRAM), a Read Only Memory (ROM), an Electrically Erasable Programmable Read Only Memory (EEPROM), a Programmable Read Only Memory (PROM), a magnetic memory, a magnetic disk, an optical disk, etc. In some embodiments, the memory 41 may be an internal storage unit of the computer device 4, such as a hard disk or a memory of the computer device 4. In other embodiments, the memory 41 may also be an external storage device of the computer device 4, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like, which are provided on the computer device 4. Of course, the memory 41 may also include both internal and external storage devices of the computer device 4. In this embodiment, the memory 41 is generally used for storing an operating system installed in the computer device 4 and various types of application software, such as program codes for controlling electronic files. Further, the memory 41 may also be used to temporarily store various types of data that have been output or are to be output.
The processor 42 may be a Central Processing Unit (CPU), controller, microcontroller, microprocessor, or other data processing chip in some embodiments. The processor 42 is typically used to control the overall operation of the computer device 4. In this embodiment, the processor 42 is configured to execute the program code stored in the memory 41 or process data, such as program code for executing control of an electronic file.
The network interface 43 may comprise a wireless network interface or a wired network interface, and the network interface 43 is generally used for establishing communication connection between the computer device 4 and other electronic devices.
The present application further provides another embodiment, which is to provide a computer readable storage medium storing an interface display program, which is executable by at least one processor to cause the at least one processor to perform the steps of the method for maintaining a TiDB database as described above.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solutions of the present application may be embodied in the form of a software product, which is stored in a storage medium (such as ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a terminal device (such as a mobile phone, a computer, a server, an air conditioner, or a network device) to execute the method according to the embodiments of the present application.
It is to be understood that the above-described embodiments are merely illustrative of some, but not restrictive, of the broad invention, and that the appended drawings illustrate preferred embodiments of the invention and do not limit the scope of the invention. This application is capable of embodiments in many different forms and is provided for the purpose of enabling a thorough understanding of the disclosure of the application. Although the present application has been described in detail with reference to the foregoing embodiments, it will be apparent to one skilled in the art that the present application may be practiced without modification or with equivalents of some of the features described in the foregoing embodiments. All equivalent structures made by using the contents of the specification and the drawings of the present application are directly or indirectly applied to other related technical fields and are within the protection scope of the present application.

Claims (10)

1. A method for maintaining a TiDB database, comprising:
collecting data in a TiDB production library through a TiDB-Binlog cluster component to obtain a Binlog file corresponding to the data in the TiDB production library, and synchronizing the Binlog file to a TiDB city disaster recovery database;
synchronizing the binlog file in the TiDB city disaster recovery database to a flash memory NAS device by adopting a preset timing backup script;
and if the TiDB production library is monitored to be abnormal, carrying out data reduction processing on the TiDB production library based on the binlog file stored in the flash NAS equipment.
2. The method of maintaining the TiDB database according to claim 1, wherein the TiDB-Binlog cluster component comprises a Drainer component and a pump component, and the collecting data in the TiDB production library by the TiDB-Binlog cluster component to obtain a Binlog file corresponding to the data in the TiDB production library, and the synchronizing the Binlog file to the TiDB city disaster recovery library comprises:
collecting a bin log file of a TiDB node server corresponding to the pump component as a basic file through the pump component, and sending the basic file to the Drainer component;
receiving the basic file through the Drainer component and merging the basic file to obtain a merged bin log file;
and synchronizing the merged bindlog file to the TiDB city disaster recovery database.
3. The method of maintaining a TiDB database of claim 1, wherein the flash NAS device comprises a first flash device and a second flash device.
4. The method for maintaining the TiDB database according to claim 3, wherein the synchronizing the binlog file in the TiDB city disaster recovery library to the flash NAS device using the preset timed backup script comprises:
moving and storing binlog files in the TiDB and city disaster recovery database into the first flash memory device;
carrying out incremental and full differential verification on the first flash memory device and the second flash memory device at regular time to obtain a verification result;
and if the verification result is that the difference exists, updating the data in the second flash memory device by adopting the data in the first flash memory device according to the difference in the verification result.
5. The method of maintaining a TiDB database according to claim 4, wherein said moving and saving binlog files in the TiDB city disaster recovery library to the first flash memory device comprises:
taking a binlog file in the TiDB and city disaster recovery database as data to be imported, and acquiring a storage path of the first flash memory device corresponding to the data to be imported;
determining the number of target threads based on the data to be imported and the first flash memory device;
and constructing multiple threads based on the number of the target threads, and synchronizing the data to be imported to a storage path of the first flash memory device by adopting the multiple threads.
6. The method for maintaining the TiDB database according to any one of claims 1 to 5, wherein the data recovery processing of the TiDB production library based on the binlog file stored in the flash NAS device if the TiDB production library is monitored to be abnormal comprises:
stopping the table writing processing of the application service on the TiDB production library, and emptying data in a data table of the TiDB production library;
acquiring a full standby file and an additional standby file from the flash memory NAS device to be used as files to be restored;
loading the full standby file into a data table in a TiDB production library, and then loading an additional standby file into the data table in the TiDB production library;
and verifying the data in the data table in the TiDB production library, confirming that the data is successfully restored after the data passes the verification, and starting application service.
7. An apparatus for maintaining a TiDB database, the apparatus comprising:
the data acquisition module is used for acquiring data in the TiDB production library through the TiDB-Binlog cluster component to obtain a Binlog file corresponding to the data in the TiDB production library and synchronizing the Binlog file to the TiDB city disaster backup library;
the file synchronization module is used for synchronizing the binlog file in the TiDB city disaster recovery database to the flash memory NAS device by adopting a preset timing backup script;
and the data recovery module is used for performing data reduction processing on the TiDB production library based on the binlog file stored in the flash NAS device if the abnormality of the TiDB production library is monitored.
8. The apparatus for maintaining a TiDB database of claim 7, wherein the data collection module comprises:
the collection unit is used for collecting a bin log file of the TiDB node server corresponding to the pump component as a basic file through the pump component and sending the basic file to the Drainer component;
the merging unit is used for receiving the basic file through the Drainer component and merging the basic file to obtain a merged bindlog file;
and the synchronization unit is used for synchronizing the merged bindlog file to the TiDB city disaster recovery database.
9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method of maintaining a TiDB database according to any of claims 1 to 6 when executing the computer program.
10. A computer-readable storage medium, in which a computer program is stored, which, when being executed by a processor, carries out a method of maintaining a TiDB database according to any one of claims 1 to 6.
CN202010150801.1A 2020-03-05 2020-03-05 TiDB database maintenance method and device, computer equipment and storage medium Pending CN111475334A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010150801.1A CN111475334A (en) 2020-03-05 2020-03-05 TiDB database maintenance method and device, computer equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010150801.1A CN111475334A (en) 2020-03-05 2020-03-05 TiDB database maintenance method and device, computer equipment and storage medium

Publications (1)

Publication Number Publication Date
CN111475334A true CN111475334A (en) 2020-07-31

Family

ID=71747350

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010150801.1A Pending CN111475334A (en) 2020-03-05 2020-03-05 TiDB database maintenance method and device, computer equipment and storage medium

Country Status (1)

Country Link
CN (1) CN111475334A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112306871A (en) * 2020-10-29 2021-02-02 广州博冠信息科技有限公司 Data processing method, device, equipment and storage medium
CN115905300A (en) * 2023-03-14 2023-04-04 云账户技术(天津)有限公司 Method and device for fusion capture of stock and incremental data of TiDB (database data base)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112306871A (en) * 2020-10-29 2021-02-02 广州博冠信息科技有限公司 Data processing method, device, equipment and storage medium
CN115905300A (en) * 2023-03-14 2023-04-04 云账户技术(天津)有限公司 Method and device for fusion capture of stock and incremental data of TiDB (database data base)
CN115905300B (en) * 2023-03-14 2023-05-30 云账户技术(天津)有限公司 Method and device for fusion capturing of stock and incremental data of TiDB database

Similar Documents

Publication Publication Date Title
EP3519969B1 (en) Physical media aware spacially coupled journaling and replay
US8868858B2 (en) Method and apparatus of continuous data backup and access using virtual machines
CN103345470B (en) A kind of database disaster recovery method, system and server
CN100426247C (en) Data recovery method
CN104239166A (en) Method for realizing file backup for running virtual machine
CN110188000A (en) Application disaster recovery method and system based on virtualization and iSCSI or FC
CN102955720A (en) Method for improving stability of EXT (extended) file system
US20090327295A1 (en) Maintenance of exo-file system metadata on removable storage device
US20190317872A1 (en) Database cluster architecture based on dual port solid state disk
CN113626256B (en) Virtual machine disk data backup method, device, terminal and storage medium
CN111475515A (en) Compensation management method and device for failed task, computer equipment and storage medium
CN112380057A (en) Data recovery method, device, equipment and storage medium
CN103810060A (en) Data backup method and system thereof based on distributed database
CN112612853A (en) Data processing method and device based on database cluster and electronic equipment
CN111475334A (en) TiDB database maintenance method and device, computer equipment and storage medium
CN112380227A (en) Data synchronization method, device and equipment based on message queue and storage medium
CN109445909A (en) Backup method, system, terminal and the storage medium of virtual-machine data
CN111966644A (en) Supercomputer data storage method, device, system and storage medium
US10514988B2 (en) Method and system of migrating applications to a cloud-computing environment
CN115061858B (en) Data persistence method and device, computer equipment and storage medium
CN106445729A (en) Backup virtualization-based method
CN112860376B (en) Snapshot chain manufacturing method and device, electronic equipment and storage medium
CN114416885A (en) Data synchronization method and device based on DRBD, computer equipment and storage medium
CN101799777B (en) Store service device with dual controller and backup method thereof
CN110543385A (en) Virtual backup method and virtual backup restoration method

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