CN111241200B - Master-slave synchronous processing method and device based on SQLite database - Google Patents

Master-slave synchronous processing method and device based on SQLite database Download PDF

Info

Publication number
CN111241200B
CN111241200B CN202010026319.7A CN202010026319A CN111241200B CN 111241200 B CN111241200 B CN 111241200B CN 202010026319 A CN202010026319 A CN 202010026319A CN 111241200 B CN111241200 B CN 111241200B
Authority
CN
China
Prior art keywords
file
database
node
file database
temporary
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202010026319.7A
Other languages
Chinese (zh)
Other versions
CN111241200A (en
Inventor
孙俊伟
王克彦
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zhejiang Huachuang Video Signal Technology Co Ltd
Original Assignee
Zhejiang Huachuang Video Signal Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Zhejiang Huachuang Video Signal Technology Co Ltd filed Critical Zhejiang Huachuang Video Signal Technology Co Ltd
Priority to CN202010026319.7A priority Critical patent/CN111241200B/en
Publication of CN111241200A publication Critical patent/CN111241200A/en
Application granted granted Critical
Publication of CN111241200B publication Critical patent/CN111241200B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

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
    • G06F16/275Synchronous replication
    • 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/1464Management of the backup or restore process for networked environments
    • 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/16File or folder operations, e.g. details of user interfaces specifically adapted to file systems
    • G06F16/162Delete operations
    • 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/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2365Ensuring data consistency and integrity

Abstract

The invention provides a method and a device for main and standby synchronous processing based on an SQLite database, wherein the method comprises the following steps: the first node obtains the time T1 of last file modification in the formal backup file database of the second node; acquiring the time T2 of last file modification in a temporary file database of the first node; synchronizing the files of the formal backup file database of the second node into the temporary file database under the condition that the time T1 is not equal to the time T2; under the condition that the file of the temporary file database meets the preset condition, the formal backup file database of the first node is updated through the file of the temporary file database, so that the problem that when the abnormal condition occurs in the process of performing the main-standby synchronization based on the modification log generated when the SQL statement modifies the database, the main-standby database is damaged simultaneously and cannot be recovered can be solved, and the main-standby synchronization under the dual-machine hot standby environment is realized for the small file database.

Description

Master-slave synchronous processing method and device based on SQLite database
Technical Field
The invention relates to the field of data transmission, in particular to a master-slave synchronous processing method and device based on an SQLite database.
Background
The video conference system comprises various participating devices such as MCU (multipoint control unit) video conference server and hard terminal. The terminal collects image and sound and sends the image and sound to the MCU through coding. And the MCU fuses or does not fuse the images sent by the terminals according to the conference requirements and sends the fused images to each participating terminal. Thereby realizing the audio-video call of the multiparty participants. The video conference system server is often a cluster stacking system, and may be composed of a plurality of signaling nodes and a plurality of media nodes. The signaling node needs to perform dual-machine hot standby, thereby realizing a high-availability system. One of the most troublesome technical problems in the dual-engine hot standby scheme is database data synchronization. In an industry video conference system, the number of access devices of a single system is often small, for example, 1000 video conference terminal devices are generally accessed, 100 conferences are concurrent, and the system has been of a large scale. The database requirements of such video conferencing systems are very small in size. A file database embedded on a server is very suitable for such application scenarios. The primary and backup synchronization of the file database has no good commercialized scheme.
In the related art, the main and standby synchronization is performed based on a modification log generated when the SQL statement modifies the database. The modification log is generated on the host computer, synchronized to the standby computer, and then played back on the standby computer so as to update the backup database.
The same database table structure is required to be maintained by the host and the standby, and when the system is upgraded, the database table structure is also required to be upgraded together, so that more DBA maintenance workload and upgrade module development complexity are brought.
The incremental data can be directly imported into the working database of the standby machine, and when abnormal conditions such as power failure occur, the active database and the standby database are damaged at the same time, so that the risk of irrecoverability exists.
When the network between the host and the standby is unstable, the integrity and availability of the standby database is at risk.
Aiming at the problem that when the abnormal condition occurs in the main and standby synchronization of the modification log generated when the database is modified based on the SQL statement in the related technology, the risk that the main and standby databases are damaged simultaneously and cannot be recovered exists in the main and standby databases, and no solution is proposed yet.
Disclosure of Invention
The embodiment of the invention provides a method and a device for processing main and standby synchronization based on an SQLite database, which at least solve the problem that the main and standby databases are simultaneously damaged and cannot be recovered when abnormal conditions exist in main and standby synchronization based on a modification log generated when the database is modified by SQL sentences in the related technology.
According to one embodiment of the invention, a master-slave synchronous processing method based on an SQLite database is provided, which comprises the following steps:
the method comprises the steps that a first node obtains the time T1 of last file modification in a formal backup file database of a second node, wherein the first node is a standby node, and the second node is a main node;
the first node obtains the time T2 of last file modification in a temporary file database of the first node;
in the case that the time T1 is not equal to the time T2, the first node synchronizes the file of the formal backup file database of the second node into the temporary file database;
and under the condition that the file of the temporary file database meets the preset condition, the first node updates the formal backup file database of the first node through the file of the temporary file database, wherein the formal backup file database and the temporary file database are databases which are not used by business service.
Optionally, in a case that the file of the temporary file database meets a predetermined condition, the updating, by the first node, the formal backup file database of the first node through the file of the temporary file database includes:
the first node performs integrity check on the file of the temporary file database;
under the condition of passing the integrity check, the first node replaces the file of the temporary file database with the file of the formal backup file database of the first node;
in case the integrity check is not passed, the first node deletes the file of the temporary file database.
Optionally, the method further comprises:
and under the condition that the second node is abnormal and the first node is switched to a main node, the first node moves the file of the formal backup file database of the first node to a working database, wherein the working database is a SQLite file database and a database for online use of business service.
Optionally, after the first node moves the file of the formal backup file database of the first node into the working database, the method further includes:
the first node obtains the time T3 of the last file modification in the working database and the time T4 of the last file backup in the temporary file data;
in the case that the time T3 is not equal to the time T4, the first node backs up the content of the working database to the temporary file database;
and under the condition that the file of the temporary file database meets the preset condition, the first node updates the formal backup file database through the file of the temporary file database.
Optionally, in a case that the file of the temporary file database meets the predetermined condition, the updating, by the first node, the formal backup file database through the file of the temporary file database includes:
the first node performs integrity check on the file of the temporary file database;
under the condition of passing the integrity check, the first node replaces the file of the temporary file database with the file of the formal backup file database, and updates the time T4 to the time T3;
in case the integrity check is not passed, the first node deletes the file of the temporary file database.
Optionally, the first node performing integrity check on the file of the temporary file database includes:
and the first node performs integrity check on the file of the temporary file database through a database integrity check interface.
According to another embodiment of the present invention, there is also provided a device for active-standby synchronization processing based on SQLite database, applied to a first node, including:
the first acquisition module is used for acquiring the time T1 of last file modification in the formal backup file database of the second node, wherein the first node is a standby node, and the second node is a main node;
the second acquisition module is used for acquiring the time T2 of last file modification in the temporary file database of the first node;
the synchronization module is used for synchronizing the files of the formal backup file database of the second node into the temporary file database of the first node under the condition that the time T1 is not equal to the time T2;
and the first updating module is used for updating the formal backup file database of the first node through the file of the temporary file database under the condition that the file of the temporary file database meets the preset condition, wherein the formal backup file database and the temporary file database are databases which are not used by business service.
Optionally, the first updating module includes:
the checking sub-module is used for checking the integrity of the file of the temporary file database;
a replacement sub-module, configured to replace a file of the temporary file database with a file of the formal backup file database of the first node under a condition that the integrity check is passed;
and the deleting sub-module is used for deleting the file of the temporary file database under the condition that the integrity check is not passed.
Optionally, the apparatus further comprises:
and the mobile module is used for moving the file of the formal backup file database of the first node to a working database under the condition that the second node is abnormal and the first node is switched to a main node, wherein the working database is a SQLite file database and the business service is used on line.
Optionally, the apparatus further comprises:
the third acquisition module is used for acquiring the time T3 of the last file modification in the working database and the time T4 of the last file backup in the temporary file data;
the backup module is used for backing up the content of the working database to the temporary file database under the condition that the time T3 is not equal to the time T4;
and the second updating module is used for updating the formal backup file database through the file of the temporary file database under the condition that the file of the temporary file database meets the preset condition.
Optionally, the second updating module includes:
the checking sub-module is used for checking the integrity of the file of the temporary file database;
an updating sub-module, configured to replace a file of the temporary file database with a file of the formal backup file database and update the time T4 to the time T3 under the condition that the integrity check is passed;
and the deleting sub-module is used for deleting the file of the temporary file database under the condition that the integrity check is not passed.
Optionally, the integrity check sub-module is further configured to
And carrying out integrity check on the file of the temporary file database through a database integrity check interface.
According to a further embodiment of the invention, there is also provided a computer-readable storage medium having stored therein a computer program, wherein the computer program is arranged to perform the steps of any of the method embodiments described above when run.
According to a further embodiment of the invention, there is also provided an electronic device comprising a memory having stored therein a computer program and a processor arranged to run the computer program to perform the steps of any of the method embodiments described above.
According to the invention, a first node obtains the time T1 of last file modification in a formal backup file database of a second node, wherein the first node is a standby node, and the second node is a main node; acquiring the time T2 of last file modification in a temporary file database of the first node; synchronizing a file of a formal backup file database of the second node into the temporary file database when the time T1 is not equal to the time T2; under the condition that the file of the temporary file database meets the preset condition, the formal backup file database of the first node is updated through the file of the temporary file database, wherein the formal backup file database and the temporary file database are databases which are not used by business services, the problems that when abnormal conditions occur in the process of performing the main-backup synchronization based on a modification log generated when the database is modified by SQL sentences in the related art, the main-backup database is damaged simultaneously and cannot be recovered can be solved, and the main-backup synchronization under the dual-machine hot-backup environment can be realized aiming at the small file database, and the fault recovery such as power failure, network failure and the like can be dealt with, so that the integrity and the usability of the database are ensured.
Drawings
The accompanying drawings, which are included to provide a further understanding of the invention and are incorporated in and constitute a part of this application, illustrate embodiments of the invention and together with the description serve to explain the invention and do not constitute a limitation on the invention. In the drawings:
fig. 1 is a hardware structure block diagram of a mobile terminal of a master-slave synchronous processing method based on an SQLite database according to an embodiment of the present invention;
FIG. 2 is a flowchart of a primary and backup synchronization processing method based on an SQLite database according to an embodiment of the invention;
FIG. 3 is a flow chart of an active node database backup according to an embodiment of the invention;
FIG. 4 is a flow chart of hot standby node database synchronization according to an embodiment of the invention;
fig. 5 is a block diagram of a master-slave synchronization processing apparatus based on an SQLite database according to an embodiment of the present invention.
Detailed Description
The invention will be described in detail hereinafter with reference to the drawings in conjunction with embodiments. It should be noted that, in the case of no conflict, the embodiments and features in the embodiments may be combined with each other.
It should be noted that the terms "first," "second," and the like in the description and the claims of the present invention and the above figures are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order.
Example 1
The method embodiment provided in the first embodiment of the present application may be executed in a mobile terminal, a computer terminal or a similar computing device. Taking the example of running on a mobile terminal, fig. 1 is a block diagram of a hardware structure of a mobile terminal according to an embodiment of the present invention, where, as shown in fig. 1, the mobile terminal 10 may include one or more (only one is shown in fig. 1) processors 102 (the processors 102 may include, but are not limited to, a microprocessor MCU or a processing device such as a programmable logic device FPGA) and a memory 104 for storing data, and optionally, the mobile terminal may further include a transmission device 106 for a communication function and an input/output device 108. It will be appreciated by those skilled in the art that the structure shown in fig. 1 is merely illustrative and not limiting of the structure of the mobile terminal described above. For example, the mobile terminal 10 may also include more or fewer components than shown in FIG. 1 or have a different configuration than shown in FIG. 1.
The memory 104 may be used to store a computer program, for example, a software program of application software and a module, such as a computer program corresponding to a message receiving method in an embodiment of the present invention, and the processor 102 executes the computer program stored in the memory 104 to perform various functional applications and data processing, that is, implement the method described above. Memory 104 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include memory located remotely from the processor 102, which may be connected to the mobile terminal 10 via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The transmission means 106 is arranged to receive or transmit data via a network. The specific examples of networks described above may include wireless networks provided by the communication provider of the mobile terminal 10. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, simply referred to as NIC) that can connect to other network devices through a base station to communicate with the internet. In one example, the transmission device 106 may be a Radio Frequency (RF) module, which is used to communicate with the internet wirelessly.
In this embodiment, a method for processing active and standby synchronization based on SQLite database running on the mobile terminal or network architecture is provided, and fig. 2 is a flowchart of a method for processing active and standby synchronization based on SQLite database according to an embodiment of the present invention, as shown in fig. 2, where the flowchart includes the following steps:
step S202, a first node obtains the time T1 of last file modification in a formal backup file database of a second node, wherein the first node is a standby node, and the second node is a main node;
step S204, the first node obtains the time T2 of last file modification in a temporary file database of the first node;
step S206, the first node synchronizes the files of the formal backup file database of the second node into the temporary file database under the condition that the time T1 is not equal to the time T2;
step S208, when the file of the temporary file database meets the predetermined condition, the first node updates the formal backup file database of the first node through the file of the temporary file database, where the formal backup file database and the temporary file database are both databases that are not used by the business service.
Further, the first node performs integrity check on the file of the temporary file database; under the condition of passing the integrity check, the first node replaces the file of the temporary file database with the file of the formal backup file database of the first node; in case the integrity check is not passed, the first node deletes the file of the temporary file database.
Through the steps S202 to S208, the problem that when the abnormal condition occurs in the main and standby synchronization based on the modification log generated when the database is modified by the SQL statement in the related art, the main and standby databases are damaged simultaneously and cannot be recovered can be solved, and aiming at the small-sized file database, the main and standby synchronization under the dual-machine hot standby environment is realized, and the fault recovery such as power failure and network disconnection can be dealt with, so that the integrity and the usability of the database are ensured.
The standby node (hot standby node) acquires the time T1 of last file modification in a formal backup file database of the main node (active node); according to the time T1, the following file synchronization steps are executed: acquiring the time T2 of last file modification in the temporary file database; downloading the file of the formal backup file database of the second node and storing the file of the formal backup file database of the second node into the temporary file database of the first node under the condition that the time T1 is not equal to the time T2; carrying out integrity check on the file of the temporary file database; and storing the file of the temporary file database into a formal backup file database of the first node under the condition of passing the integrity check. And under the condition that the time T1 is not equal to the time T2, re-acquiring the time T1 of the last file modification in the formal backup file database of the second node after the first preset time, and repeatedly executing the file synchronization step.
In the embodiment of the invention, under the condition that the second node is abnormal and the first node is switched to the main node, the first node moves the file of the formal backup file database of the first node to the working database of the first node, wherein the working database is a SQLite file database and a database used by business service on line.
Optionally, after the first node moves the file of the formal backup file database of the first node to the working database of the first node, acquiring the time T3 of the last file modification in the working database and the time T4 of the last file backup in the temporary file data; if the time T3 is not equal to the time T4, backing up the content of the working database to the temporary file database, and backing up the content of the sqlite database online; the first node backs up the content of the working database to the temporary file database on line, and the application program continuously works in the backup process, namely, the application program does not need to be interrupted; and under the condition that the file of the temporary file database meets the preset condition, the first node updates the formal backup file database through the file of the temporary file database.
Further, the first node performs integrity check on the file of the temporary file database; under the condition of passing the integrity check, replacing the file of the temporary file database with the file of the formal backup file database, and updating the time T4 to be the time T3; and deleting the file of the temporary file database in the case that the integrity check is not passed. Specifically, the integrity of the file of the temporary file database is checked through a database integrity check interface.
The master node (active node) obtains the time T1 of the last file modification in the online backup database, and executes the following file backup steps according to the time T3: under the condition that the time T3 is equal to the time T4 of the last file backup, the files of the online backup database are backed up into a temporary file database through a database online backup interface; carrying out integrity check on the file of the temporary file database through a database integrity check interface; updating the time T4 to the time T3 in the case of passing the integrity check, and deleting the file of the temporary file database in the case of not passing the integrity check. And in the case that the time T3 is not equal to the time T4, re-acquiring the time T3 of the last file modification in the online backup database after a preset time, and repeatedly executing the file backup steps.
When two video conference signaling nodes form a dual hot standby, only one node (such as node 1) is active and serves as an external service, namely an active node, and the other node (such as node 2) enters a hot standby state, namely a hot standby node. A hot standby node (e.g., node 2) does not provide service to the outside, but needs to maintain real-time synchronization of the database with the active node. When the active node (such as node 1) fails, the hot standby node (such as node 2) takes over comprehensively and provides the same service to the outside, so that the high availability of the video conference system is improved. The two signaling nodes have equal status, and both signaling nodes can become active nodes or hot standby nodes. A network port direct connection network can be built between the two nodes, and the network port direct connection network is specially used for database data synchronization. The web service in the signaling node may use a file database, such as sqlite, for storing relevant information for the videoconference system. Work directory of Web services such as/opt/Web. sqlite file database paths such as/opt/web/vcs. There are no other dedicated database servers in the system.
The embodiments of the present invention will be described below with respect to the path of the working database being/opt/web/vcs.db, the path of the formal backup file database being/opt/web/download/vcs.db.hotload, and the temporary file database being/opt/web/download/vcs.db.hotload.tmp or/opt/web/download/tmp/vcs.db.hotload.
FIG. 3 is a flow chart of active node database backup, as shown in FIG. 3, according to an embodiment of the invention, including:
step S301, setting a last backup time stamp backupTS (corresponding to time T3) to be zero;
step S302, acquiring/opt/web/vcs.db file latest modification timestamp now TS (corresponding to time T4);
step S303, judging whether the backup TS is equal to the nonwTS, if not, entering step S304; otherwise, jumping to step S309;
step S304, the file in the working database is backed up to a temporary file database, in particular, a database online backup interface (such as Online Backup API of sqlite) is used for backing up/opt/web/vcs.db so as not to influence service, and the backup file is stored in/opt/web/download/vcs.db.hotspot.tmp;
step S305, performing integrity check on the temporary file database, specifically, performing integrity check on the database (opt/web/download/vcs.db.hotspot.tmp) by using a database integrity check interface (such as SQL statement pragma quick_check provided by sqlite database);
step S306, judging whether the file of the temporary file database is complete, executing the step if the judgment result is yes, otherwise executing the step;
step S307, deleting the file of the temporary backup database, namely deleting the backup file/opt/web/download/vcs.db.hotpad.tmp;
step S308, replacing the file of the temporary database with the file of the formal backup database, and updating the timestamp backup TS to be the timestamp nonWTS; i.e., if the above steps check that the result is normal, the file is replaced to/opt/web/download/vcs.db.hotspot, and updating the last backup time stamp backupTS to nonwTS;
step S309, after waiting for a predetermined time (e.g., 1 second), step S2 is continued.
FIG. 4 is a flowchart of hot standby node database synchronization, as shown in FIG. 4, according to an embodiment of the invention, including:
step S401, obtaining the time T1 of the last file modification in the formal backup file database, specifically using an HTTP client to initiate an HTTP HEAD protocol to an active node WEB service, requesting to obtain the modification timestamp peerTS (corresponding to the time T1) of the active node/opt/WEB/download/vcs.db.hotspot file;
step S402, obtaining the time T2 of the last file modification in the temporary file database, namely obtaining a modification timestamp localTS (corresponding to the time T2) of the local file/opt/web/download/tmp/vcs.db.hotspot;
step S403, judging whether the time T3 is equal to the time T4, if not, executing step S404, otherwise executing step S404;
step S404, downloading the files of the formal backup database of the active node into a temporary file database of the hot standby node, specifically, if peerTS is not equal to localTS, initiating HTTP GET protocol to the WEB service of the active node by using an HTTP client, requesting to download the files/opt/WEB/download/vcs.db.hotspot, and saving the files/opt/WEB/download/tmp/vcs.db.hotspot locally;
step S405, carrying out integrity check on the temporary file database;
step S406, judging whether the file of the temporary file database is complete, executing step 407 if the judgment result is yes, otherwise executing step S408; after the file is successfully downloaded, performing database integrity check (such as a pragma quick check statement provided by sqlite) on the file/opt/web/download/tmp/vcs.db.hotspot, and if the integrity check passes, copying the temporary file/opt/web/download/tmp/vcs.db.hotspot to a formal path/opt/web/download/vcs.db.hotspot, so as to complete database synchronization once; otherwise, prompting to report errors;
step S407, replacing the files of the temporary database with the files of the formal backup database;
step S408, reporting error prompt;
step S409, wait for a predetermined time (e.g., 1 second, 5 seconds, etc.), and return to step S401.
In order to ensure that the database synchronization process does not affect normal application services, the speed limit can be downloaded by 1MB/s when the HTTP GET download/opt/web/download/vcs.db. hotspot file is carried out on the web server or the HTTP client.
In the embodiment of the present invention, when a signaling node enters an "active node" mode, the execution flow is as follows:
step 1, stopping a database synchronization program;
step 2, checking whether the synchronous database file/opt/web/download/vcs.db. hotspot service exists or not and the size is larger than 0, if so, copying and covering the data file/opt/web/download/vcs.db. hotspot service to the database file/opt/web/vcs.db in the running process;
step 3, starting an application program, including WEB service;
and step 4, starting a database backup program.
In the embodiment of the invention, when a signaling node enters a hot standby node mode, stopping an application program; stopping the database backup program, starting the database synchronization program, and processing the database when the node is upgraded.
Only the local database files/opt/web/vcs. Db need be upgraded for "active nodes", including db schema upgrades and data upgrades.
The file database is divided into an opt/web/vcs.db and an opt/web/vcs.log.db. The first vcs.db is an operation state database, which stores necessary data for system operation and keeps a small scale. The database vcs.log.db is a log library, and stores operation logs, history records and the like.
In the embodiment of the invention, the synchronization program and the backup program only process the/opt/web/vcs.db, thereby ensuring smaller scale of the database and improving the synchronization speed of the main and the backup of the database.
By the embodiment of the invention, under severe conditions such as system power failure, network disconnection and the like, the integrity and the availability of the database file can be ensured when at least one node of the two nodes is in operation, so that the high availability of the system is ensured. The change of db schema of the main machine and the standby machine is not required to be maintained, and the workload of DBA management and maintenance is not required; the database main and standby synchronous multiplexing WEB service port is not needed to be opened additionally, and the network security problem is reduced.
Example 2
According to another embodiment of the present invention, there is further provided a device for processing primary and secondary synchronization based on an SQLite database, applied to a first node, and fig. 5 is a block diagram of the device for processing primary and secondary synchronization based on the SQLite database according to an embodiment of the present invention, as shown in fig. 5, including:
a first obtaining module 52, configured to obtain a time T1 of a last file modification in a formal backup file database of a second node, where the first node is a backup node and the second node is a master node;
a second obtaining module 54, configured to obtain a time T2 of a last file modification in the temporary file database of the first node;
a synchronization module 56, configured to synchronize a file of the formal backup file database of the second node to the temporary file database if the time T1 is not equal to the time T2;
and a first updating module 58, configured to update, by using the file of the temporary file database, a formal backup file database of the first node if the file of the temporary file database meets a predetermined condition, where the formal backup file database and the temporary file database are both databases that are not used by the business service.
Optionally, the first update module 58 includes:
the checking sub-module is used for checking the integrity of the file of the temporary file database;
a replacement sub-module, configured to replace a file of the temporary file database with a file of the formal backup file database of the first node under a condition that the integrity check is passed;
and the deleting sub-module is used for deleting the file of the temporary file database under the condition that the integrity check is not passed.
Optionally, the apparatus further comprises:
and the mobile module is used for moving the file of the formal backup file database of the first node to a working database under the condition that the second node is abnormal and the first node is switched to a main node, wherein the working database is a SQLite file database and the business service is used on line.
Optionally, the apparatus further comprises:
the third acquisition module is used for acquiring the time T3 of the last file modification in the working database and the time T4 of the last file backup in the temporary file data;
the backup module is used for backing up the content of the working database to the temporary file database under the condition that the time T3 is not equal to the time T4;
and the second updating module is used for updating the formal backup file database through the file of the temporary file database under the condition that the file of the temporary file database meets the preset condition.
Optionally, the second updating module includes:
the checking sub-module is used for checking the integrity of the file of the temporary file database;
an updating sub-module, configured to replace a file of the temporary file database with a file of the formal backup file database and update the time T4 to the time T3 under the condition that the integrity check is passed;
and the deleting sub-module is used for deleting the file of the temporary file database under the condition that the integrity check is not passed.
Optionally, the integrity check sub-module is further configured to
And carrying out integrity check on the file of the temporary file database through a database integrity check interface.
It should be noted that each of the above modules may be implemented by software or hardware, and for the latter, it may be implemented by, but not limited to: the modules are all located in the same processor; alternatively, the above modules may be located in different processors in any combination.
Example 3
Embodiments of the present invention also provide a computer readable storage medium having a computer program stored therein, wherein the computer program is arranged to perform the steps of any of the method embodiments described above when run.
Alternatively, in the present embodiment, the above-described storage medium may be configured to store a computer program for performing the steps of:
s1, acquiring time T1 of last file modification in a formal backup file database of a second node, wherein the first node is a standby node, and the second node is a main node;
s2, acquiring the time T2 of last file modification in a temporary file database of the first node;
s3, synchronizing the files of the formal backup file database of the second node into the temporary file database under the condition that the time T1 is not equal to the time T2;
and S4, updating a formal backup file database of the first node through the file of the temporary file database under the condition that the file of the temporary file database meets the preset condition, wherein the formal backup file database and the temporary file database are databases which are not used by business service.
Alternatively, in the present embodiment, the storage medium may include, but is not limited to: a usb disk, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), a removable hard disk, a magnetic disk, or an optical disk, or other various media capable of storing a computer program.
Example 4
An embodiment of the invention also provides an electronic device comprising a memory having stored therein a computer program and a processor arranged to run the computer program to perform the steps of any of the method embodiments described above.
Optionally, the electronic apparatus may further include a transmission device and an input/output device, where the transmission device is connected to the processor, and the input/output device is connected to the processor.
Alternatively, in the present embodiment, the above-described processor may be configured to execute the following steps by a computer program:
s1, acquiring time T1 of last file modification in a formal backup file database of a second node, wherein the first node is a standby node, and the second node is a main node;
s2, acquiring the time T2 of last file modification in a temporary file database of the first node;
s3, synchronizing the files of the formal backup file database of the second node into the temporary file database under the condition that the time T1 is not equal to the time T2;
and S4, updating a formal backup file database of the first node through the file of the temporary file database under the condition that the file of the temporary file database meets the preset condition, wherein the formal backup file database and the temporary file database are databases which are not used by business service.
Alternatively, specific examples in this embodiment may refer to examples described in the foregoing embodiments and optional implementations, and this embodiment is not described herein.
It will be appreciated by those skilled in the art that the modules or steps of the invention described above may be implemented in a general purpose computing device, they may be concentrated on a single computing device, or distributed across a network of computing devices, they may alternatively be implemented in program code executable by computing devices, so that they may be stored in a memory device for execution by computing devices, and in some cases, the steps shown or described may be performed in a different order than that shown or described, or they may be separately fabricated into individual integrated circuit modules, or multiple modules or steps within them may be fabricated into a single integrated circuit module for implementation. Thus, the present invention is not limited to any specific combination of hardware and software.
The above description is only of the preferred embodiments of the present invention and is not intended to limit the present invention, but various modifications and variations can be made to the present invention by those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the principle of the present invention should be included in the protection scope of the present invention.

Claims (10)

1. A master-slave synchronous processing method based on an SQLite database is characterized by comprising the following steps:
the method comprises the steps that a first node obtains the time T1 of last file modification in a formal backup file database of a second node, wherein the first node is a standby node, and the second node is a main node;
the first node obtains the time T2 of last file modification in a temporary file database of the first node;
under the condition that the time T1 is not equal to the time T2, the first node synchronizes the files of the formal backup file database of the second node into the temporary file database through a Web service port, wherein the temporary file database and the formal backup file database are file databases in Web service;
and under the condition that the file of the temporary file database meets the preset condition, the first node updates the formal backup file database of the first node through the file of the temporary file database, wherein the formal backup file database and the temporary file database are databases which are not used by business service.
2. The method of claim 1, wherein the first node updating the primary backup file database of the first node with the file of the temporary file database if the file of the temporary file database satisfies a predetermined condition comprises:
the first node performs integrity check on the file of the temporary file database;
under the condition of passing the integrity check, the first node replaces the file of the temporary file database with the file of the formal backup file database of the first node;
in case the integrity check is not passed, the first node deletes the file of the temporary file database.
3. The method according to claim 1, wherein the method further comprises:
and under the condition that the second node is abnormal and the first node is switched to a main node, the first node moves the file of the formal backup file database of the first node to a working database, wherein the working database is a SQLite file database and a database for online use of business service.
4. A method according to claim 3, wherein after the first node moves the files of the primary backup file database of the first node into the working database, the method further comprises:
the first node obtains the time T3 of the last file modification in the working database and the time T4 of the last file backup in the temporary file data;
in the case that the time T3 is not equal to the time T4, the first node backs up the content of the working database to the temporary file database;
and under the condition that the file of the temporary file database meets the preset condition, the first node updates the formal backup file database through the file of the temporary file database.
5. The method of claim 4, wherein the first node updating the formal backup file database with the files of the temporary file database if the files of the temporary file database satisfy the predetermined condition comprises:
the first node performs integrity check on the file of the temporary file database;
under the condition of passing the integrity check, the first node replaces the file of the temporary file database with the file of the formal backup file database, and updates the time T4 to the time T3;
in case the integrity check is not passed, the first node deletes the file of the temporary file database.
6. The method of claim 2 or 5, wherein the first node performing an integrity check on the files of the temporary file database comprises:
and the first node performs integrity check on the file of the temporary file database through a database integrity check interface.
7. The primary and backup synchronous processing device based on the SQLite database is characterized by being applied to a first node and comprising:
the first acquisition module is used for acquiring the time T1 of last file modification in the formal backup file database of the second node, wherein the first node is a standby node, and the second node is a main node;
the second acquisition module is used for acquiring the time T2 of last file modification in the temporary file database of the first node;
the synchronization module is configured to synchronize, when the time T1 is not equal to the time T2, a file of a formal backup file database of the second node to the temporary file database through a Web service port, where the temporary file database and the formal backup file database are file databases in Web service;
and the first updating module is used for updating the formal backup file database of the first node through the file of the temporary file database under the condition that the file of the temporary file database meets the preset condition, wherein the formal backup file database and the temporary file database are databases which are not used by business service.
8. The apparatus of claim 7, wherein the first update module comprises:
the checking sub-module is used for checking the integrity of the file of the temporary file database;
a replacement sub-module, configured to replace a file of the temporary file database with a file of the formal backup file database of the first node under a condition that the integrity check is passed;
and the deleting sub-module is used for deleting the file of the temporary file database under the condition that the integrity check is not passed.
9. A computer-readable storage medium, characterized in that the storage medium has stored therein a computer program, wherein the computer program is arranged to execute the method of any of the claims 1 to 6 when run.
10. An electronic device comprising a memory and a processor, characterized in that the memory has stored therein a computer program, the processor being arranged to run the computer program to perform the method of any of the claims 1 to 6.
CN202010026319.7A 2020-01-10 2020-01-10 Master-slave synchronous processing method and device based on SQLite database Active CN111241200B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010026319.7A CN111241200B (en) 2020-01-10 2020-01-10 Master-slave synchronous processing method and device based on SQLite database

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010026319.7A CN111241200B (en) 2020-01-10 2020-01-10 Master-slave synchronous processing method and device based on SQLite database

Publications (2)

Publication Number Publication Date
CN111241200A CN111241200A (en) 2020-06-05
CN111241200B true CN111241200B (en) 2024-02-20

Family

ID=70870886

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010026319.7A Active CN111241200B (en) 2020-01-10 2020-01-10 Master-slave synchronous processing method and device based on SQLite database

Country Status (1)

Country Link
CN (1) CN111241200B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112199329B (en) * 2020-09-24 2023-08-18 上海上讯信息技术股份有限公司 Double-machine operation and maintenance data archiving and cleaning method and device based on fort machine

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1677887A (en) * 2005-02-01 2005-10-05 北京北方烽火科技有限公司 N+1 duplicates data real-time synchronising method
CN101447858A (en) * 2008-01-17 2009-06-03 中兴通讯股份有限公司 Method for realizing synchronous switching of virtual router redundancy protocol in dual-machine hot backup system
CN104281506A (en) * 2014-07-10 2015-01-14 中国科学院计算技术研究所 Data maintenance method and system for file system
CN104486131A (en) * 2014-12-29 2015-04-01 浪潮电子信息产业股份有限公司 DB2 database fault detecting and switching method based on Itanium platform
CN105224637A (en) * 2015-09-24 2016-01-06 珠海许继芝电网自动化有限公司 A kind of based on PostgreSQL database active and standby/the comprehensive method of cluster application
CN106815275A (en) * 2015-12-02 2017-06-09 阿里巴巴集团控股有限公司 It is a kind of that the synchronous method and apparatus in master/slave data storehouse is realized by standby database

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20190102405A1 (en) * 2017-09-29 2019-04-04 Ca, Inc. File synchronization to support high availability of monolithic software applications

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1677887A (en) * 2005-02-01 2005-10-05 北京北方烽火科技有限公司 N+1 duplicates data real-time synchronising method
CN101447858A (en) * 2008-01-17 2009-06-03 中兴通讯股份有限公司 Method for realizing synchronous switching of virtual router redundancy protocol in dual-machine hot backup system
CN104281506A (en) * 2014-07-10 2015-01-14 中国科学院计算技术研究所 Data maintenance method and system for file system
CN104486131A (en) * 2014-12-29 2015-04-01 浪潮电子信息产业股份有限公司 DB2 database fault detecting and switching method based on Itanium platform
CN105224637A (en) * 2015-09-24 2016-01-06 珠海许继芝电网自动化有限公司 A kind of based on PostgreSQL database active and standby/the comprehensive method of cluster application
CN106815275A (en) * 2015-12-02 2017-06-09 阿里巴巴集团控股有限公司 It is a kind of that the synchronous method and apparatus in master/slave data storehouse is realized by standby database

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
张羽 ; 贺耀宜 ; 王勇 ; 陈小林 ; 高文 ; .煤矿安全监控系统文件同步组件的设计.工矿自动化.2012,(第3期),第8-9页. *
张羽 ; 贺耀宜 ; 王勇 ; 陈小林 ; 高文 ; .煤矿安全监控系统文件同步组件的设计.工矿自动化.2012,全文. *
煤矿企业纯软件方式的双机热备系统研究;钟宇;;工矿自动化;20120810(08);全文 *

Also Published As

Publication number Publication date
CN111241200A (en) 2020-06-05

Similar Documents

Publication Publication Date Title
US10764369B2 (en) Data storage method and server applicable to distributed server cluster
CN111090699A (en) Service data synchronization method and device, storage medium and electronic device
CN105677380B (en) Method and device for board-by-board upgrading of double master control isolations
CN105141453A (en) Control method capable of not interrupting service in upgrading process of system and system thereof
CN111124755A (en) Cluster node fault recovery method and device, electronic equipment and storage medium
US11640261B2 (en) Log processing method to avoid log collision, and related device and system
CN106817387B (en) Data synchronization method, device and system
CN111241200B (en) Master-slave synchronous processing method and device based on SQLite database
CN112929438B (en) Business processing method and device of double-site distributed database
CN112000444B (en) Database transaction processing method and device, storage medium and electronic equipment
US10776392B2 (en) Apparatus and method to establish a connection between apparatuses while synchronization of connection information thereof is suspended
CN110851527B (en) Data synchronization method for main and standby servers
CN106534758B (en) Conference backup method and device
CN115576655B (en) Container data protection system, method, device, equipment and readable storage medium
CN108881452B (en) Data synchronization method, device and storage medium
CN112905676A (en) Data file importing method and device
CN115658390A (en) Container disaster tolerance method, system, device, equipment and computer readable storage medium
CN110958287A (en) Operation object data synchronization method, device and system
JPH07114495A (en) Multiplexing file managing system
CN104850471A (en) Itanium platform-based method for realizing two places and three centers of DB2 database
CN112256484A (en) Data backup method, device and system
US7644306B2 (en) Method and system for synchronous operation of an application by a purality of processing units
CN111142921A (en) Software upgrading method and device
CN113032477A (en) Long-distance data synchronization method and device based on GTID and computing equipment
CN113890875B (en) Task allocation 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
GR01 Patent grant
GR01 Patent grant