CN113326325A - Detection method and device for database master-slave service disconnection - Google Patents

Detection method and device for database master-slave service disconnection Download PDF

Info

Publication number
CN113326325A
CN113326325A CN202110651637.7A CN202110651637A CN113326325A CN 113326325 A CN113326325 A CN 113326325A CN 202110651637 A CN202110651637 A CN 202110651637A CN 113326325 A CN113326325 A CN 113326325A
Authority
CN
China
Prior art keywords
database
log
record
log file
synchronized
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
CN202110651637.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.)
WeBank Co Ltd
Original Assignee
WeBank 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 WeBank Co Ltd filed Critical WeBank Co Ltd
Priority to CN202110651637.7A priority Critical patent/CN113326325A/en
Publication of CN113326325A publication Critical patent/CN113326325A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • 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
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/17Details of further file system functions
    • G06F16/178Techniques for file synchronisation in file systems
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/18File system types
    • G06F16/1805Append-only file systems, e.g. using logs or journals to store data
    • G06F16/1815Journaling file systems

Abstract

The embodiment of the invention provides a method and a device for detecting disconnection of a master service and a slave service of a database. The method comprises the following steps: at the disconnection detection time, acquiring a first log file of a master database and a second log file of a slave database; comparing the first log file with the second log file, and determining a record to be synchronized, wherein the record to be synchronized is a log record which exists in the first log file and is not synchronized into the second log file; and determining whether the master database and the slave database are in a disconnected state or not by judging the relationship between the operation time of the log record in the record to be synchronized and the disconnection detection time. The method and the device can accurately determine the records to be synchronized in the first log file, determine whether the master database and the slave database are in a disconnected state, automatically determine the service state between the master database and the slave database, and simultaneously acquire the missing data from the databases without manual participation, thereby saving the labor cost and improving the data transmission efficiency.

Description

Detection method and device for database master-slave service disconnection
Technical Field
The embodiment of the invention relates to the technical field of computer software, in particular to a method and a device for detecting disconnection of master and slave services of a database, computing equipment and a computer-readable storage medium.
Background
With the development of computer technology, more and more technologies are applied in the financial field, and the traditional financial industry is gradually changing to financial technology (Fintech), but due to the requirements of the financial industry on safety and real-time performance, higher requirements are also put forward on the technologies.
MySQL master-slave synchronization is a database architecture which is commonly used at present, and data can be copied from one database to other databases by referring to master-slave synchronization, so that the pressure of the databases is effectively relieved. When data is replicated, one database acts as a master database (master) and the remaining databases act as slave databases (slave). Master-slave synchronization between Mysql databases is based on the binlog (binary log) mechanism, which is used by the master database to record changes to the database, and the slave database is kept consistent with the master database's data by reading and executing the binlog file. However, when the master database and the slave database are disconnected, it is not timely discovered whether the master database and the slave database are disconnected, so that effective data transmission cannot be realized.
Therefore, a method for detecting disconnection of a master-slave service of a database is needed to determine whether a master-slave database is in a disconnected state and determine data to be synchronized in a master database in time.
Disclosure of Invention
The embodiment of the invention provides a method for detecting disconnection of master and slave services of a database, which is used for determining whether a master database and a slave database are in a disconnected state in time and determining data to be synchronized in a master database.
In a first aspect, an embodiment of the present invention provides a method for detecting disconnection of a master service and a slave service of a database, including:
at the disconnection detection time, acquiring a first log file of a master database and a second log file of a slave database;
comparing the first log file with the second log file, and determining a record to be synchronized, wherein the record to be synchronized is a log record which exists in the first log file and is not synchronized into the second log file;
and determining whether the master database and the slave database are in a disconnected state or not by judging the relationship between the operation time of the log record in the record to be synchronized and the disconnection detection time.
By comparing the first log file and the second log file acquired at the disconnection detection time, the record to be synchronized in the first log file can be accurately determined, and whether the master database and the slave database are in a disconnected state or not is determined according to the relationship between the operation time of the log record in the record to be synchronized and the disconnection detection time. Therefore, the service state between the master database and the slave database can be automatically determined, the data missing from the databases are obtained, manual participation is not needed, the labor cost is saved, and the data transmission efficiency is improved.
Optionally, determining whether the master database and the slave database are in a disconnected state by determining a relationship between an operation time of a log record in the to-be-synchronized record and the disconnection detection time includes:
acquiring first operation time of a first log record in the records to be synchronized, wherein the first log record is ordered according to a time sequence;
and if the difference value between the first operation time and the disconnection detection time is greater than a preset threshold value, determining that the master database and the slave database are in a disconnected state.
If the difference value between the first operation time and the disconnection detection time is larger than a preset threshold value, it indicates that the first log record in the records to be synchronized is not synchronized to the slave database within the preset threshold value time, and it indicates that the master database and the slave database are in a disconnected state.
Optionally, after determining that the master database and the slave database are in a disconnected state, the method further includes:
determining a second operation time of a last log record in the second log file plus a preset synchronization period as a time when the master database and the slave database are disconnected; the preset threshold is greater than the preset synchronization time.
Since the preset synchronization time is an empirical value of time required for synchronizing the log records of the master database to the slave database, the empirical value is less than a preset threshold. In this way, the disconnection time of the master database and the slave database can be limited to a more accurate time point.
Optionally, after determining that the master database and the slave database are disconnected, the method further includes:
generating alarm information for disconnecting the master database and the slave database and reporting the alarm information; the alarm information includes the time when the master database and the slave database are disconnected and the record to be synchronized.
Therefore, operation and maintenance personnel can find out that the connection between the master database and the slave database is disconnected in time and acquire the records to be synchronized in time.
Optionally, at the disconnection detection time, acquiring a first log file of the master database and a second log file of the slave database, including:
acquiring a to-be-synchronized record of the master database at the last disconnection detection time and a log record generated by the master database in a disconnection detection period;
taking the record to be synchronized at the last disconnection detection time and the log record generated by the main database in the disconnection detection period as the first log file;
and acquiring the log record generated from the database in the disconnection detection period as the second log file.
The master database is added to the first log file in the next disconnection detection period for the record to be synchronized at the last disconnection detection time, so that the problem that the first log file and the second log file have the log records which are not corresponding to each other and the comparison burden is increased due to the fact that the record to be synchronized at the last disconnection detection time is synchronized to the second log file in the next disconnection detection period is solved.
Optionally, the method further comprises:
opening log configurations for the master database and the slave database; the log is configured to instruct the master database and the slave database to record database operations in real time;
and collecting the log records of the master database and the slave database in real time and reporting the log records to a storage server.
Therefore, by uploading the latest generated log records in real time, the subsequent comparison process can be compared based on the latest database operation, and the comparison accuracy is improved.
Optionally, comparing the first log file with the second log file to determine a record to be synchronized, including:
analyzing the first log file into a first text file, and analyzing the second log file into a second text file;
and comparing the first text file with the second text file to determine the record to be synchronized.
The binary log file is analyzed into the text file, so that comparison between the binary log file and the text file is facilitated, and the record to be synchronized is accurately determined.
In a second aspect, an embodiment of the present invention further provides a device for detecting disconnection of a master service and a slave service of a database, where the device includes:
an acquisition unit configured to acquire a first log file of a master database and a second log file of a slave database at a disconnection detection time;
a processing unit to:
comparing the first log file with the second log file, and determining a record to be synchronized, wherein the record to be synchronized is a log record which exists in the first log file and is not synchronized into the second log file;
and determining whether the master database and the slave database are in a disconnected state or not by judging the relationship between the operation time of the log record in the record to be synchronized and the disconnection detection time.
In a third aspect, an embodiment of the present invention further provides a computing device, including:
a memory for storing a computer program;
and the processor is used for calling the computer program stored in the memory and executing the detection method for the disconnection of the master-slave service of the database listed in any mode according to the obtained program.
In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, where a computer-executable program is stored, where the computer-executable program is configured to enable a computer to execute the method for detecting disconnection of a database master-slave service in any one of the manners described above.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the description of the embodiments 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 to obtain other drawings based on these drawings without creative efforts.
Fig. 1 is a schematic diagram of a system architecture according to an embodiment of the present invention;
fig. 2 is a schematic flowchart of a method for detecting disconnection of a master-slave service of a database according to an embodiment of the present invention;
fig. 3 is a schematic flowchart of a method for detecting disconnection of a master-slave service of a database according to an embodiment of the present invention;
fig. 4 is a device for detecting disconnection of a master-slave service of a database according to an embodiment of the present invention.
Detailed Description
To make the objects, embodiments and advantages of the present application clearer, the following description of exemplary embodiments of the present application will clearly and completely describe the exemplary embodiments of the present application with reference to the accompanying drawings in the exemplary embodiments of the present application, and it is to be understood that the described exemplary embodiments are only a part of the embodiments of the present application, and not all of the embodiments.
All other embodiments, which can be derived by a person skilled in the art from the exemplary embodiments described herein without inventive step, are intended to be within the scope of the claims appended hereto. In addition, while the disclosure herein has been presented in terms of one or more exemplary examples, it should be appreciated that aspects of the disclosure may be implemented solely as a complete embodiment.
It should be noted that the brief descriptions of the terms in the present application are only for the convenience of understanding the embodiments described below, and are not intended to limit the embodiments of the present application. These terms should be understood in their ordinary and customary meaning unless otherwise indicated.
The terms "first," "second," "third," and the like in the description and claims of this application and in the above-described drawings are used for distinguishing between similar or analogous objects or entities and are not necessarily intended to limit the order or sequence of any particular one, Unless otherwise indicated. It is to be understood that the terms so used are interchangeable under appropriate circumstances such that the embodiments described herein are, for example, capable of operation in sequences other than those illustrated or otherwise described herein.
Furthermore, the terms "comprises" and "comprising," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a product or device that comprises a list of elements is not necessarily limited to those elements explicitly listed, but may include other elements not expressly listed or inherent to such product or device.
Fig. 1 illustrates an exemplary system architecture to which embodiments of the present invention are applicable, which may include a master database 100, a slave database 200, a storage server 300, and a processor 400.
The master database 100 is used to write changes to the binlog file of the master database 100, such as the first log file of the master database 100;
the slave database 200 is used to obtain the binlog file from the master database 100, write the binlog file into the local binary log, read the local log, execute the change, and write the change into the binlog file of the slave database 200, such as the second log file of the slave database 200.
The binlog file records all DDL (Data Definition Language) and DML (Data Manipulation Language) operation logs of the database, records in an event form, and includes a timestamp, statement consumption time and the like. For example, DDL includes building a library, building a table, setting constraints, etc., and DML is a simple operation performed on data in a database, such as inserting, deleting, updating, selecting, etc.
The processor 400 is a control center of the entire architecture, connects various parts of the entire architecture using various interfaces and routes, performs various functions and processes data by running or executing software programs and/or modules stored in the storage server 300 and calling data stored in the storage server 300. Alternatively, processor 400 may include one or more processing units.
The storage server 300 may be used to store software programs and modules and log records uploaded from the master database 100 and the slave database 200, and the processor 400 performs various functional applications and data processing by operating the software programs and modules stored in the storage server 300. The storage server 300 may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function, and the like; the storage data area may store data created according to a business process, and the like. In addition, the storage server 300 may include high-speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other volatile solid-state storage device.
It should be noted that the structure shown in fig. 1 is only an example, and the embodiment of the present invention is not limited thereto.
Fig. 2 shows a method for detecting disconnection of a master-slave service of a database, which, as shown in fig. 2, comprises the following steps.
Step 201, at the time of disconnection detection, a first log file of the master database and a second log file of the slave database are acquired.
Firstly, MySQL master-slave service is deployed on a master database and a slave database, and log configuration is started, so that the master database and the slave database can record database operation in real time, and subsequent extraction and comparison are facilitated.
And then uploading the latest generated log record of the master database to a storage server by a log uploading module built in the master database in real time, and uploading the latest generated log record of the slave database to the storage server by a log uploading module built in the slave database in real time. By uploading the latest generated log records in real time, the subsequent comparison process can be compared based on the latest database operation, and the comparison accuracy is improved.
In this manner, the log records of the master database, which are updated in real time, and the log records of the slave database, which are updated in real time, are stored in the storage server.
At a certain disconnection detection time, acquiring a first log file from the log records of the master database and a corresponding second log file from the slave database, wherein the method for acquiring the first log file and the second log file can be various, for example, acquiring the log records of a certain time period of 8:00-9:00 from the log records of the master database as the first log file, and acquiring the log records of the corresponding time period of 8:00-9:00 from the log records of the slave database as the second log file; it is also possible to acquire, as a first log file, all log records below a certain log record in the log records arranged in time series in the master database, and acquire all log records below the certain log record in the log records arranged in time series in the slave database, as a second log file, starting from the log record of the certain specific identifier. For example, table 1 is a log record of a master database, table 2 is a log record of a slave database, the log records of the master database and the slave database are all sorted according to time, a first log file is obtained by taking the log record B as a starting point as shown in table 3, and a second log record is obtained as shown in table 4.
TABLE 1
Figure BDA0003111690930000081
TABLE 2
Figure BDA0003111690930000082
TABLE 3
Figure BDA0003111690930000083
TABLE 4
Figure BDA0003111690930000084
The above are merely examples, and embodiments of the present invention are not limited thereto.
Alternatively, the disconnection detection timing is set according to a preset rule, for example, an integer such as 8:00, 9:00 is set as the disconnection detection timing, or a fixed time such as a half hour interval between the disconnection detection timings, or the like may be provided. Therefore, the first log file and the second log file can be acquired periodically for subsequently judging whether the master-slave service is disconnected.
Step 202, comparing the first log file with the second log file, and determining the record to be synchronized, wherein the record to be synchronized is a log record existing in the first log file and not synchronized into the second log file.
Optionally, the first log file and the second log file may be firstly parsed into a first text file and a second text file, respectively, and the first text file and the second text file are compared, so that the record to be synchronized can be accurately determined.
After comparison, the log records existing in the first log file and not synchronized into the second log file, i.e. the records to be synchronized, can be determined.
Taking the first log file and the second log file listed in tables 3 and 4 as an example, after comparing the two, it is determined that the records to be synchronized are as shown in table 5, wherein the log records C and D are log records in the master database, but are not synchronized to the slave database temporarily.
TABLE 5
Figure BDA0003111690930000091
And step 203, determining whether the master database and the slave database are in a disconnected state by judging the relationship between the operation time of the log record in the record to be synchronized and the disconnection detection time.
Since the record to be synchronized determined in step 202 may not be due to disconnection of the master-slave database, or may not be due to delay in transmission, the data is not synchronized from the master database to the slave database, and therefore, further determination of the relationship between the operation time and the disconnection detection time is required.
The change time of the log records of the corresponding identifications in the master database and the slave database is compared to determine whether the master database and the slave database are in a disconnected state, the specific implementation modes are various, and a plurality of specific implementation modes are described below.
Example one
First operation time of a first log record in a record to be synchronized and sorted according to a time sequence is obtained. As in table 5, the first operation time of the first log record is 8: 20.
And then judging the relation between the difference value between the first operation time and the current disconnection detection time and a preset threshold value. The preset threshold may be set in advance by a person, and an empirical value of a time required for data to be transferred from the master database to the slave database is a preset synchronization period. For example, if it is found through many experiments that the time required for data to be synchronized from the master database to the slave database is 5min, the preset threshold may be set to 10 min. By setting a larger time preset threshold, the synchronization from the master database to the slave database can be ensured to be realized within the preset threshold.
And if the difference value between the first operation time and the disconnection detection time is greater than a preset threshold value, determining that the master database and the slave database are in a disconnected state. For example, if the current detection time is 8:32, the difference value from the first operation time is 12min, and is greater than the preset threshold, it may be determined that the master database and the slave database have been disconnected.
And if the difference value between the first operation time and the disconnection detection time is smaller than a preset threshold value, determining that the master database and the slave database are still in a connection state. For example, if the current detection time is 8:29, and the difference value from the first operation time is 9min, which is smaller than the preset threshold, it may be considered that at the current disconnection detection time, the log record C is not synchronized to the slave database due to other reasons, such as network delay, and the like, and the master database and the slave database are still in a connected state, and therefore, it is necessary to wait for the next disconnection detection time to determine whether the master database and the slave database are disconnected.
Further, if it is determined that the master-slave database is disconnected, the time of disconnection may also be determined. And determining the second operation time of the last log record in the second log file plus a preset synchronization period as the time of disconnection of the master database and the slave database. In the above example, it can be seen from table 4 that the second operation time is 8:02 and the preset synchronization time is 5min, and thus 8:07 is considered as a time for disconnection of the master database and the slave database.
Example two
The operation time of the last log record of the first log file is obtained, as in table 5, the operation time of the last log record is 8: 25.
After the preset threshold is added for 10min, 8:35 is obtained, namely the latest synchronization time of the log record D in the slave database is 8:35, 8:35 is compared with the operation time 8:02 of the last log record in the second log file, and when 8:35 is greater than 8:02, the master database and the slave database can be determined to be disconnected, wherein the disconnection time is 8:02 plus the preset synchronization time for 5min, namely 8: 07.
Optionally, after determining that the master database and the slave database are disconnected, alarm information of the master database and the slave database which are disconnected may be generated and reported, where the alarm information includes time of the master database and the slave database which are disconnected and a record to be synchronized.
Alternatively, when the first log file and the second log file are compared, the comparison may be performed according to the identifier of each log record, for example, the log record a in the first log file is compared with the log record a in the second log file, and if there is no log record a in the second log file, the log record a is determined as the record to be synchronized.
There is also a possible comparison method, that is, the comparison is not performed according to the identification of the log record, but only performed according to the time sequence of occurrence, so that the identification of each log record is not needed to be identified, and the comparison workload is reduced. However, in this manner, at a certain disconnection detection time, the following problem may occur: the record to be synchronized determined in the last disconnection detection period is synchronized to the slave database in the current detection period, for example, as shown in table 6, the current disconnection detection time is 9:00, and it is detected whether the master database and the slave database are disconnected in the detection period of 8:30-9: 00. Wherein the log records C and D in the second log file are 8:00-8:30 log records to be synchronized in the first log file in the last detection period and 8:30-9:00 log records to be synchronized in the slave database in the current detection period.
TABLE 6
Figure BDA0003111690930000111
Figure BDA0003111690930000121
In order to avoid the problem that the first log file and the second log file have non-corresponding log records so as to increase the comparison burden, the master database is added to the first log file in the next disconnection detection period at the last disconnection detection time to be synchronized, namely:
acquiring a to-be-synchronized record of a master database at the last disconnection detection time and a log record generated by the master database in a disconnection detection period;
taking the log record to be synchronously recorded at the last disconnection detection time and generated by the main database in the disconnection detection period as the first log file;
the log records generated from the database during the disconnection detection period are acquired as a second log file.
The first log file and the second log file thus obtained in the current detection period are shown in table 7.
TABLE 7
Figure BDA0003111690930000122
The first log file and the second log file obtained in the way can be directly compared without identifying the identification of each log record, so that the comparison load is reduced.
In order to better explain the embodiment of the present invention, the flow of detecting the disconnection of the database master-slave service will be described in the following specific implementation scenarios. As shown in fig. 3.
And step 301, uploading log records of the master database and the slave database to a storage server in real time.
Step 302, at the moment of disconnection detection, a first log file of the current detection period is obtained from the log records of the master database, and a second log file of the current detection period is obtained from the log records of the slave database.
Step 303, comparing the first log file with the second log file to obtain the record to be synchronized.
Step 304, determining whether the number of log records in the to-be-synchronized record is zero, if yes, ending the current detection, and if not, entering step 305.
Step 305, obtaining a first operation time of a first log record in the records to be synchronized, wherein the first log record is sorted according to a time sequence.
Step 306, determining whether the difference between the first operation time and the disconnection detection time is greater than a preset threshold, if so, entering step 307, and if not, ending the current detection.
Step 307, it is determined that the master database is disconnected from the slave database.
And step 308, determining the second operation time of the last log record in the second log file plus a preset synchronization period as the time for disconnecting the master database and the slave database.
And 309, generating alarm information for disconnecting the master database and the slave database and reporting the alarm information.
By comparing the first log file and the second log file acquired at the disconnection detection time, the record to be synchronized in the first log file can be accurately determined, and whether the master database and the slave database are in a disconnected state or not is determined according to the relationship between the operation time of the log record in the record to be synchronized and the disconnection detection time. Therefore, the service state between the master database and the slave database can be automatically determined, the data missing from the databases are obtained, manual participation is not needed, the labor cost is saved, and the data transmission efficiency is improved.
Based on the same technical concept, fig. 4 exemplarily shows a structure of a device for detecting database master-slave service disconnection provided by an embodiment of the present invention, where the structure can perform a flow of detecting database master-slave service disconnection.
As shown in fig. 4, the apparatus specifically includes:
an acquisition unit 401 for acquiring a first log file of the master database and a second log file of the slave database at the disconnection detection time;
a processing unit 402 for:
comparing the first log file with the second log file, and determining a record to be synchronized, wherein the record to be synchronized is a log record which exists in the first log file and is not synchronized into the second log file;
and determining whether the master database and the slave database are in a disconnected state or not by judging the relationship between the operation time of the log record in the record to be synchronized and the disconnection detection time.
Based on the same technical concept, an embodiment of the present invention further provides a computing device, including:
a memory for storing a computer program;
and the processor is used for calling the computer program stored in the memory and executing the detection method for the disconnection of the master-slave service of the database listed in any mode according to the obtained program.
Based on the same technical concept, an embodiment of the present invention further provides a computer-readable storage medium, where a computer-executable program is stored in the computer-readable storage medium, and the computer-executable program is configured to enable a computer to execute the method for detecting disconnection of a database master-slave service listed in any of the above manners.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present application without departing from the spirit and scope of the application. Thus, if such modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is intended to include such modifications and variations as well.

Claims (10)

1. A detection method for database master-slave service disconnection is characterized by comprising the following steps:
at the disconnection detection time, acquiring a first log file of a master database and a second log file of a slave database;
comparing the first log file with the second log file, and determining a record to be synchronized, wherein the record to be synchronized is a log record which exists in the first log file and is not synchronized into the second log file;
and determining whether the master database and the slave database are in a disconnected state or not by judging the relationship between the operation time of the log record in the record to be synchronized and the disconnection detection time.
2. The method of claim 1, wherein determining whether the master database and the slave database are in a disconnected state by determining a relationship between an operation time of a log record in the records to be synchronized and the disconnection detection time includes:
acquiring first operation time of a first log record in the records to be synchronized, wherein the first log record is ordered according to a time sequence;
and if the difference value between the first operation time and the disconnection detection time is greater than a preset threshold value, determining that the master database and the slave database are in a disconnected state.
3. The method of claim 1, wherein after determining that the master database is in a disconnected state from the slave database, further comprising:
determining a second operation time of a last log record in the second log file plus a preset synchronization period as a time when the master database and the slave database are disconnected; the preset threshold is greater than the preset synchronization time.
4. The method of claim 3, wherein after determining the time to disconnect the master database and the slave database, further comprising:
generating alarm information for disconnecting the master database and the slave database and reporting the alarm information; the alarm information includes the time when the master database and the slave database are disconnected and the record to be synchronized.
5. The method of claim 1, wherein obtaining a first log file of a master database and a second log file of a slave database at a disconnection detection time comprises:
acquiring a to-be-synchronized record of the master database at the last disconnection detection time and a log record generated by the master database in a disconnection detection period;
taking the record to be synchronized at the last disconnection detection time and the log record generated by the main database in the disconnection detection period as the first log file;
and acquiring the log record generated from the database in the disconnection detection period as the second log file.
6. The method of any one of claims 1-5, further comprising:
opening log configurations for the master database and the slave database; the log is configured to instruct the master database and the slave database to record database operations in real time;
and collecting the log records of the master database and the slave database in real time and reporting the log records to a storage server.
7. The method of any of claims 1-5, wherein comparing the first log file and the second log file to determine records to synchronize comprises:
analyzing the first log file into a first text file, and analyzing the second log file into a second text file;
and comparing the first text file with the second text file to determine the record to be synchronized.
8. A device for detecting disconnection of a master-slave service of a database, comprising:
an acquisition unit configured to acquire a first log file of a master database and a second log file of a slave database at a disconnection detection time;
a processing unit to:
comparing the first log file with the second log file, and determining a record to be synchronized, wherein the record to be synchronized is a log record which exists in the first log file and is not synchronized into the second log file;
and determining whether the master database and the slave database are in a disconnected state or not by judging the relationship between the operation time of the log record in the record to be synchronized and the disconnection detection time.
9. A computing device, comprising:
a memory for storing a computer program;
a processor for calling a computer program stored in said memory, for executing the method of any one of claims 1 to 7 in accordance with the obtained program.
10. A computer-readable storage medium, characterized in that the computer-readable storage medium stores a computer-executable program for causing a computer to execute the method of any one of claims 1 to 7.
CN202110651637.7A 2021-06-11 2021-06-11 Detection method and device for database master-slave service disconnection Pending CN113326325A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110651637.7A CN113326325A (en) 2021-06-11 2021-06-11 Detection method and device for database master-slave service disconnection

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110651637.7A CN113326325A (en) 2021-06-11 2021-06-11 Detection method and device for database master-slave service disconnection

Publications (1)

Publication Number Publication Date
CN113326325A true CN113326325A (en) 2021-08-31

Family

ID=77421208

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110651637.7A Pending CN113326325A (en) 2021-06-11 2021-06-11 Detection method and device for database master-slave service disconnection

Country Status (1)

Country Link
CN (1) CN113326325A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113836231A (en) * 2021-09-23 2021-12-24 武汉达梦数据库股份有限公司 Log analysis service switching method and device under database main and standby environment

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113836231A (en) * 2021-09-23 2021-12-24 武汉达梦数据库股份有限公司 Log analysis service switching method and device under database main and standby environment

Similar Documents

Publication Publication Date Title
CN106713487B (en) Data synchronization method and device
CN113111129B (en) Data synchronization method, device, equipment and storage medium
CN108694195B (en) Management method and system of distributed data warehouse
CN101996214B (en) Method and device for processing database operation request
CN109376196B (en) Method and device for batch synchronization of redo logs
CN106202365B (en) Method and system for database update synchronization and database cluster
CN110263095B (en) Data backup and recovery method and device, computer equipment and storage medium
CN112434043B (en) Data synchronization method, device, electronic equipment and medium
CN111711623A (en) Data verification method and device
CN107870982B (en) Data processing method, system and computer readable storage medium
CN110232095B (en) Data synchronization method, device, storage medium and server
CN113326325A (en) Detection method and device for database master-slave service disconnection
CN114490554A (en) Data synchronization method and device, electronic equipment and storage medium
KR101191832B1 (en) Database Replication Method And System Using Analyzing Network Packets
CN113672692A (en) Data processing method, data processing device, computer equipment and storage medium
CN102413154B (en) Method of data information synchronization between systems and apparatus thereof
CN109189864B (en) Method, device and equipment for determining data synchronization delay
CN114490570A (en) Production data synchronization method and device, data synchronization system and server
CN115203697A (en) File detection method, device and equipment and readable storage medium
CN102346757A (en) Data photocopying method and system in IMS (IP multimedia subsystem) database online transaction
CN111970329A (en) Method, system, equipment and medium for deploying cluster service
CN112612773A (en) Database synchronization test method and device, computer equipment and storage medium
RU172742U1 (en) Automated reference system
CN107239505B (en) Cluster mirror synchronization method and system
CN106469086B (en) Event processing method and device

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