CN117097737A - Data synchronization method, server, client, electronic device and storage medium - Google Patents

Data synchronization method, server, client, electronic device and storage medium Download PDF

Info

Publication number
CN117097737A
CN117097737A CN202310896544.XA CN202310896544A CN117097737A CN 117097737 A CN117097737 A CN 117097737A CN 202310896544 A CN202310896544 A CN 202310896544A CN 117097737 A CN117097737 A CN 117097737A
Authority
CN
China
Prior art keywords
synchronous
file
version number
client
data
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
CN202310896544.XA
Other languages
Chinese (zh)
Inventor
曹建强
袁朝
王志海
喻波
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Wondersoft Technology Co Ltd
Original Assignee
Beijing Wondersoft Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Wondersoft Technology Co Ltd filed Critical Beijing Wondersoft Technology Co Ltd
Priority to CN202310896544.XA priority Critical patent/CN117097737A/en
Publication of CN117097737A publication Critical patent/CN117097737A/en
Pending legal-status Critical Current

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • H04L67/1095Replication or mirroring of data, e.g. scheduling or transport for data synchronisation between network nodes
    • 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
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/06Protocols specially adapted for file transfer, e.g. file transfer protocol [FTP]

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The embodiment of the application provides a data synchronization method, a server, a client, electronic equipment and a storage medium. The data synchronization method comprises the following steps: the server writes the synchronous data in the MySQL database into the synchronous file in the SQLite database according to the set rule, and records the version number of the synchronous file; after receiving a heartbeat signal sent by a client, judging whether the version number of a synchronous file in the client contained in the heartbeat signal is the same as the latest version number of the synchronous file in the SQLite database; and under the condition of different conditions, the synchronous task containing the latest version number is issued to the client, so that the client acquires the synchronous file corresponding to the latest version number after receiving the synchronous task. In the embodiment of the application, a file synchronization mode is adopted, so that the problem of data difference of service data in the transmission process is solved, the additional storage conversion process of the data by a server and a client is reduced, and the efficiency of data synchronization is improved.

Description

Data synchronization method, server, client, electronic device and storage medium
Technical Field
The present application relates to the field of computer technologies, and in particular, to a data synchronization method, a server, a client, an electronic device, and a storage medium.
Background
In the application of a C/S (Client/Server) architecture, there is a need to synchronize data calculated by a Server to a Client, and in data synchronization, data transmission reliability and read/write efficiency are important indicators of performance and stability of the Client.
In the prior art, common data synchronization includes interface synchronization and file synchronization.
Interface synchronization refers to that a client directly requests an interface of a server to acquire data. However, when the amount of data returned by the interface is large or the number of clients is large, the method has great test on the occupation of network bandwidth and the interface concurrency capability of the server.
File synchronization refers to that a server writes data into an SQL (Structured Query Language ) file, then synchronizes the SQL file to a client, and the client reads the SQL file data. However, this method is not friendly to the client for reading data, and the client does not have the capability of directly reading data from the SQL file.
Disclosure of Invention
In view of the above problems, an embodiment of the present application provides a data synchronization method, a server, a client, an electronic device, and a storage medium, which are used to simplify a data synchronization process.
According to an aspect of an embodiment of the present application, there is provided a data synchronization method applied to a server, the method including:
according to a set rule, writing synchronous data in the MySQL database into a synchronous file in the SQLite database, and recording the version number of the synchronous file;
after receiving a heartbeat signal sent by a client, judging whether the version number of a synchronous file in the client contained in the heartbeat signal is the same as the latest version number of the synchronous file in the SQLite database;
and under the condition of non-uniformity, issuing a synchronous task containing the latest version number to the client so that the client acquires a synchronous file corresponding to the latest version number after receiving the synchronous task.
Optionally, writing the synchronization data in the MySQL database into the synchronization file in the SQLite database according to the set rule includes: judging whether synchronous data in the MySQL database is changed or not at regular time; and under the condition of change, writing the synchronous data in the MySQL database into a synchronous file in the SQLite database.
Optionally, the writing the synchronization data in the MySQL database into the synchronization file in the SQLite database includes: judging whether full writing is performed; writing the full-volume synchronous data in the MySQL database into a synchronous file in an SQLite database under the condition that full-volume writing is not executed; and under the condition that full writing is performed, writing the increment synchronous data in the MySQL database into a synchronous file in the SQLite database.
Optionally, the writing the incremental synchronization data in the MySQL database into the synchronization file in the SQLite database includes: acquiring a recorded writing end position; acquiring synchronous data positioned behind the writing end position in the MySQL database as incremental synchronous data; and writing the increment synchronous data into a synchronous file in the SQLite database.
According to another aspect of the embodiment of the present application, there is provided a data synchronization method applied to a client, the method including:
sending a heartbeat signal containing a version number of the synchronous file in the client to a server; after receiving the heartbeat signal, the server judges whether the version number of the synchronous file in the client is the same as the latest version number of the synchronous file in the SQLite database, and if not, issues a synchronous task containing the latest version number to the client; the server is used for writing the synchronous data in the MySQL database into the synchronous file in the SQLite database according to the set rule, and recording the version number of the synchronous file;
and after receiving the synchronization task issued by the server, acquiring a synchronization file corresponding to the latest version number.
Optionally, the obtaining the synchronization file corresponding to the latest version number includes: judging whether synchronous files corresponding to the latest version numbers exist in other clients which are located in the same local area network with the client; when the latest version number exists, acquiring a synchronous file corresponding to the latest version number from the existing client; and when the latest version number does not exist, acquiring the synchronous file corresponding to the latest version number from the server.
According to another aspect of an embodiment of the present application, there is provided a server including:
the writing module is used for writing the synchronous data in the MySQL database into the synchronous file in the SQLite database according to the set rule and recording the version number of the synchronous file;
the judging module is used for judging whether the version number of the synchronous file in the client contained in the heartbeat signal is the same as the latest version number of the synchronous file in the SQLite database after receiving the heartbeat signal sent by the client;
and the issuing module is used for issuing the synchronous task containing the latest version number to the client under the condition of different conditions, so that the client acquires the synchronous file corresponding to the latest version number after receiving the synchronous task.
Optionally, the writing module is specifically configured to determine whether the synchronous data in the MySQL database changes at regular time; and under the condition of change, writing the synchronous data in the MySQL database into a synchronous file in the SQLite database.
Optionally, the writing module includes: a write judgment unit configured to judge whether full-volume writing has been performed; the first writing unit is used for writing the full synchronous data in the MySQL database into the synchronous file in the SQLite database under the condition that the writing judging unit judges that the full writing is not executed; and the second writing unit is used for writing the increment synchronous data in the MySQL database into the synchronous file in the SQLite database under the condition that the writing judging unit judges that the full writing is executed.
Optionally, the second writing unit is specifically configured to obtain a recorded writing end position; acquiring synchronous data positioned behind the writing end position in the MySQL database as incremental synchronous data; and writing the increment synchronous data into a synchronous file in the SQLite database.
According to another aspect of an embodiment of the present application, there is provided a client including:
The sending module is used for sending a heartbeat signal containing the version number of the synchronous file in the client to the server; after receiving the heartbeat signal, the server judges whether the version number of the synchronous file in the client is the same as the latest version number of the synchronous file in the SQLite database, and if not, issues a synchronous task containing the latest version number to the client; the server is used for writing the synchronous data in the MySQL database into the synchronous file in the SQLite database according to the set rule, and recording the version number of the synchronous file;
and the acquisition module is used for acquiring the synchronous file corresponding to the latest version number after receiving the synchronous task issued by the server.
Optionally, the acquiring module includes: the file judging unit is used for judging whether synchronous files corresponding to the latest version numbers exist in other clients which are located in the same local area network with the client; the first acquisition unit is used for acquiring the synchronous file corresponding to the latest version number from the existing client when the file judgment unit judges that the file exists; and the second acquisition unit is used for acquiring the synchronous file corresponding to the latest version number from the server when the file judgment unit judges that the synchronous file does not exist.
According to another aspect of an embodiment of the present application, there is provided an electronic apparatus including: one or more processors; and one or more computer-readable storage media having instructions stored thereon; the instructions, when executed by the one or more processors, cause the processors to perform the data synchronization method of any of the above.
According to another aspect of embodiments of the present application, there is provided a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, causes the processor to perform the data synchronization method as any one of the above.
According to the embodiment of the application, a server writes synchronous data in a MySQL database into a synchronous file in an SQLite database according to a set rule, and records the version number of the synchronous file; after receiving a heartbeat signal sent by a client, a server judges whether the version number of a synchronous file in the client contained in the heartbeat signal is the same as the latest version number of the synchronous file in the SQLite database; and under the condition of non-uniformity, the server transmits a synchronization task containing the latest version number to the client so that the client acquires a synchronization file corresponding to the latest version number after receiving the synchronization task. Therefore, in the embodiment of the application, the synchronous data in the MySQL database is written into the synchronous file in the SQLite database, so that the synchronous file in the SQLite database can be synchronized to the client during data synchronization, and the client can directly read the acquired synchronous file due to the zero configuration and the capability of directly reading the file of the SQLite data.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are needed in the description of the embodiments of the present application will be briefly described below, and it is obvious that the drawings in the following description are only some drawings of the present application, and other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
Fig. 1 is a flowchart illustrating steps of a data synchronization method according to an embodiment of the present application.
FIG. 2 is a flow chart of steps of another data synchronization method according to an embodiment of the present application.
Fig. 3 is a schematic diagram of a data synchronization process according to an embodiment of the present application.
FIG. 4 is a schematic diagram of another data synchronization process according to an embodiment of the present application.
Fig. 5 is a schematic diagram of a process of synchronizing files by a client according to an embodiment of the present application.
Fig. 6 is a schematic diagram of a user information synchronization process according to an embodiment of the present application.
Fig. 7 is a block diagram of a server according to an embodiment of the present application.
Fig. 8 is a block diagram of a client according to an embodiment of the present application.
Fig. 9 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
The technical solutions of the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is apparent that the described embodiments are only some embodiments of the present application, not all embodiments of the present application. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
Embodiments of the present application may be applied in the context of a C/S architecture. The C/S architecture typically takes a two-tier architecture, namely a server and a client. The server is responsible for data management, and the client is responsible for completing interaction tasks with users.
Referring to fig. 1, a flowchart of steps of a data synchronization method according to an embodiment of the present application is shown. The data synchronization method in the embodiment is applied to a server.
As shown in fig. 1, the data synchronization method may include the steps of:
step 101, the server writes the synchronous data in the MySQL database into the synchronous file in the SQLite database according to the set rule, and records the version number of the synchronous file.
In the embodiment of the application, a MySQL database and a SQLite database can be arranged in the server.
The MySQL database is a relational database management system, and the relational database stores data in different data tables instead of placing all data in a large warehouse, so that the data processing speed is increased and the data processing flexibility is improved. To store and manipulate data using MySQL, several things need to be done: installing a MySQL server; installing a MySQL client; the MySQL client is connected with the MySQL server; the MySQL client sends commands to the MySQL server, which accepts the commands and performs the corresponding operations (add, delete, modify, check, etc.).
The SQLite database is an in-process library, implementing a self-sufficient, serverless, zero-configuration, transactional SQL database engine. It is a zero configuration database, meaning that unlike other databases, you do not need to configure in the system. The SQLite engine is not an independent process and can be connected statically or dynamically according to the requirements of application programs. The SQLite database supports direct access to its storage files.
Based on the characteristics of the database, the embodiment of the application proposes to write the synchronous data in the MySQL database into the synchronous file in the SQLite database, so that the data synchronization can be realized through the synchronous file, and the client can directly read the data from the synchronous file. The synchronization data refers to data that needs to be synchronized to the client, such as user information, etc.
For example, the server may write the synchronization data in the MySQL database to the synchronization file in the SQLite database at regular time and record the version number of the synchronization file. The time interval for writing may be set according to practical experience, for example, may be set to 6 hours, 12 hours, 1 day, or the like, which is not limited in this embodiment.
For example, the server may determine whether the synchronization data in the MySQL database changes at regular time, and if so, write the synchronization data in the MySQL database into the synchronization file in the SQLite database.
For example, a data table for storing synchronous data may be set in the MySQL database, and the server may determine whether synchronous data in the data table in the MySQL database changes at regular time.
In an alternative embodiment, the process of writing the synchronization data in the MySQL database into the synchronization file in the SQLite database may include the following steps A1 to A3:
step A1, it is determined whether full write has been performed.
The full-volume writing refers to writing the full-volume synchronous data in the MySQL database into the synchronous file in the SQLite database.
The full write may be performed at the first data synchronization, or at any other suitable time, as exemplified, but the present embodiment is not limited thereto.
For example, after the full write execution is completed, a full write executed flag may be generated and recorded. The server can determine whether full writing has been performed by determining whether there is a full writing performed flag. Specifically, if the server determines that there is a full write executed flag, it may be determined that full write has been executed; if it is determined that there is no full write executed flag, it may be determined that full write has not been executed.
And step A2, writing the full-volume synchronous data in the MySQL database into the synchronous file in the SQLite database under the condition that the full-volume writing is not executed.
And the server can write the full-volume synchronous data in the MySQL database into the synchronous file in the SQLite database under the condition that the full-volume writing is not executed.
For example, the server may read the full synchronization data from a data table in the MySQL database for storing the synchronization data, and then write the read full synchronization data to the synchronization file in the SQLite database.
The synchronization file may be created in advance, or may be created when the synchronization data is written, which is not limited in this embodiment. The synchronization file may be in db (database) file format.
And step A3, under the condition that full writing is executed, writing the increment synchronous data in the MySQL database into a synchronous file in the SQLite database.
And the server can write the increment synchronous data in the MySQL database into the synchronous file in the SQLite database under the condition that the server judges that the full writing is executed.
For example, the server may read incremental synchronization data from a data table in the MySQL database for storing the synchronization data, and then write the read incremental synchronization data to a synchronization file in the SQLite database.
For example, the server may record the writing end position of this time after each writing of the synchronization data, and the writing end position may be a corresponding position in a data table for storing the synchronization data. Thus, the process of writing incremental synchronization data in the MySQL database to a synchronization file in the SQLite database may include: acquiring a recorded writing end position; acquiring synchronous data positioned behind the writing end position in the MySQL database as incremental synchronous data; and writing the increment synchronous data into a synchronous file in the SQLite database.
The synchronization file may be created in advance, or may be created when the synchronization data is written, which is not limited in this embodiment. The synchronization file may be in db file format.
For example, when the server writes the synchronization data in the MySQL database to the synchronization file in the SQLite database, the server may write in a manner of updating the synchronization file. For example, if the writing is full writing, the original synchronous file is replaced by the written synchronous data, and if the writing is incremental writing, the written synchronous data is added to the original synchronous file. After the synchronous data is written each time, the version number of the synchronous file after the synchronous data is written this time can be recorded, namely, the version number of the synchronous file is updated once when the synchronous data is written once.
Step 102, after receiving the heartbeat signal sent by the client, the server determines whether the version number of the synchronization file in the client included in the heartbeat signal is the same as the latest version number of the synchronization file in the SQLite database.
The client and the server can perform heartbeat interaction, and the client can send heartbeat signals to the server at regular time. The time interval for the client to send the heartbeat signal may be set according to practical experience, which is not limited in this embodiment. For example, the time interval for the client to send the heartbeat signal may be set to 5 minutes, 10 minutes, etc.
In the embodiment of the application, the heartbeat signal sent by the client can contain the current version number of the synchronous file in the local client. By using the heartbeat signal to carry the version number of the local synchronous file of the client, the client does not need to independently send the version number of the local synchronous file, and the processing process is simpler and more convenient.
After receiving a heartbeat signal sent by a client, a server analyzes the heartbeat signal to obtain a version number of a synchronous file in the client, the server obtains a latest version number of the synchronous file in an SQLite database of the server, and then judges whether the version number of the synchronous file in the client, which is contained in the heartbeat signal, is the same as the latest version number of the synchronous file in the SQLite database.
Step 103, the server issues a synchronization task including the latest version number to the client under the condition that the server judges that the synchronization tasks are different, so that the client obtains a synchronization file corresponding to the latest version number after receiving the synchronization task.
When judging that the version number of the synchronous file in the client contained in the heartbeat signal is different from the latest version number of the synchronous file in the SQLite database, the server indicates that the synchronous file currently stored in the client is different from the latest synchronous file in the SQLite database in the server, so that the server can generate a synchronous task containing the latest version number and issue the synchronous task containing the latest version number to the client. After receiving the synchronization task issued by the server, the client may acquire the synchronization file corresponding to the latest version number, which will be described in detail in the following embodiments.
And when judging that the version number of the synchronous file in the client contained in the heartbeat signal is the same as the latest version number of the synchronous file in the SQLite database, the server indicates that the synchronous file currently stored in the client is the same as the latest synchronous file in the SQLite database in the server, so that the server does not need to issue a synchronous task containing the latest version number to the client and does not need to do other processing temporarily.
Referring to fig. 2, a flowchart of steps of another data synchronization method of an embodiment of the present application is shown. The data synchronization method in the embodiment of the application is applied to the client.
As shown in fig. 2, the data synchronization method may include the steps of:
in step 201, a client sends a heartbeat signal containing a version number of a synchronization file in the client to a server.
In the embodiment of the application, the client can send the heartbeat signal containing the version number of the synchronous file in the client to the server at regular time. After receiving the heartbeat signal, the server judges whether the version number of the synchronous file in the client is the same as the latest version number of the synchronous file in the SQLite database, and if not, issues a synchronous task containing the latest version number to the client. The server is used for writing the synchronous data in the MySQL database into the synchronous file in the SQLite database according to the set rule, and recording the version number of the synchronous file.
Step 202, after receiving the synchronization task issued by the server, the client obtains a synchronization file corresponding to the latest version number.
After receiving the synchronization task issued by the server, the client can acquire the synchronization file corresponding to the latest version number.
In an optional embodiment, in the process of obtaining the synchronization file corresponding to the latest version number, the client may obtain the synchronization file corresponding to the latest version number from the server. Specifically, the client may generate a download request including the latest version number, send the download request to the server, and after receiving the download request, the server parses the download request to obtain the latest version number, and issues a synchronization file corresponding to the latest version number to the client.
In an alternative embodiment, pulling the synchronization file among multiple clients may be employed, considering that if the synchronization file is pulled from the server when the number of clients is large, it may put stress on the bandwidth of the server. In an exemplary embodiment, in the process of obtaining the synchronization file corresponding to the latest version number, the client may first determine whether the synchronization file corresponding to the latest version number exists in other clients located in the same local area network as the client; when the latest version number exists, acquiring a synchronous file corresponding to the latest version number from the existing client; and when the latest version number does not exist, acquiring the synchronous file corresponding to the latest version number from the server.
If the synchronous file corresponding to the latest version number exists in other clients, the clients can acquire the synchronous file corresponding to the latest version number from the clients with the synchronous file corresponding to the latest version number through a P2P (Peer to Peer) technology. The P2P technology is a network communication method for decentralization, and is also an important means for realizing various applications such as file sharing and streaming media transmission, unlike the traditional decentralization service, the P2P technology does not need additional hardware facilities such as a server and a central node, so that resources can be saved and cost can be reduced, and in the P2P network, all nodes are mutually connected and mutually supported through interaction and communication, so that information flow and sharing are realized. Specifically, the client may generate a download request including the latest version number, send the download request to the client having the synchronization file corresponding to the latest version number through the P2P technology, parse the download request to obtain the latest version number after receiving the download request, and send the synchronization file corresponding to the latest version number to the client through the P2P technology.
For example, if there are at least two other clients with the synchronization file corresponding to the latest version number, the client may select any one of the clients to obtain the synchronization file corresponding to the latest version number.
And the client acquires the synchronous file corresponding to the latest version number, stores the synchronous file corresponding to the latest version number, and records the latest version number. Specifically, the client can replace the original synchronization file locally of the client by the synchronization file corresponding to the latest version number.
The client can also comprise an SQLite database, and the client can directly open and use the corresponding synchronous file through the SQLite.
In the embodiment of the application, the synchronous data in the MySQL database is written into the synchronous file in the SQLite database, so that the synchronous file in the SQLite database can be synchronized to the client during data synchronization, and the client can directly read the acquired synchronous file due to the zero configuration and the capability of directly reading the file of the SQLite data.
Next, a data synchronization process according to an embodiment of the present application will be described with reference to fig. 3 to 6.
Fig. 3 is a schematic diagram of a data synchronization process according to an embodiment of the present application. As shown in fig. 3, the server performs data processing on the synchronous data in the MySQL database, and writes the synchronous data into the SQLite database to obtain a db file (db file is also referred to as synchronous file); the client requests synchronization from the server through the heartbeat signal; after receiving the heartbeat signal, the server inquires the latest version number of the db file for comparison; if the version number of the db file locally stored by the client is different from the latest version number of the db file in the server, the server synchronizes the db file of the latest version to the client.
FIG. 4 is a schematic diagram of another data synchronization process according to an embodiment of the present application. As shown in fig. 4, the server starts a timing task to determine whether full writing has been performed; if not, the server performs full writing; if yes, the server performs incremental writing; the server writes the synchronous data into the SQLite database to obtain a db file (namely a synchronous file), and saves the version number of the db file; the client reports the version number of the db file in the client to the server through a heartbeat signal; the server inquires the latest version number of the db file, compares the latest version number of the db file with the latest version number of the db file in the server, and judges whether the version number of the db file in the client reported by the client is the latest version number of the db file in the server; if not, the server sends a synchronous task to the client; the client downloads the db file of the latest version from the server.
Fig. 5 is a schematic diagram of a process of synchronizing files by a client according to an embodiment of the present application. As shown in fig. 5, each client may interact with the server through a heartbeat mechanism, so that the server may check the version number, and after the client acquires the synchronization task, the P2P technology may be used to determine whether other clients in the same lan have the latest version of the synchronization file, if so, the synchronization file is directly pulled from the other clients through the lan, and if not, the synchronization file is not pulled from the server.
Fig. 6 is a schematic diagram of a user information synchronization process according to an embodiment of the present application. As shown in fig. 6, when the server synchronizes the user information (i.e. the synchronization data) from the MySQL database to the SQLite database, the state service periodically reads the user information of the MySQL database, inserts the built-in SQLite database, reads the db file of the SQLite database, and uploads the db file to the file service to create a user information synchronization task; the client reports the version number of the local db file to the server through a heartbeat signal; when the state service of the server judges that the version number reported by the client is different from the latest version number of the db file in the server, the state service of the server issues a synchronous task to the client; and the client pulls the db file from the file service, and updates the version number in the subsequent heartbeat signal after the db file is successfully pulled.
In the embodiment of the application, based on the SQLite zero configuration and the capability of directly reading the storage file, only db storage in MySQL is synchronized when data is synchronized, so that the problem of data difference caused by the problems of network, sequence and the like in the transmission process of service data is reduced, the additional storage conversion process of the server and the client to the data is reduced, and the data access efficiency is improved. And a large amount of data is transmitted in a file mode, the interface interaction times of the client and the server are reduced, the server reduces the pressure of frequent data calculation by the server through full-scale and incremental calculation, and the number of times of directly pulling files from the server is reduced by adopting a P2P local area network transmission technology for a plurality of clients.
Referring to fig. 7, a block diagram of a server according to an embodiment of the present application is shown.
As shown in fig. 7, the server may include the following modules:
the writing module 701 is configured to write the synchronization data in the MySQL database into the synchronization file in the SQLite database according to a set rule, and record a version number of the synchronization file;
the judging module 702 is configured to judge whether a version number of a synchronization file in the client included in a heartbeat signal is the same as a latest version number of the synchronization file in the SQLite database after receiving the heartbeat signal sent by the client;
And the issuing module 703 is configured to issue a synchronization task including the latest version number to the client under different conditions, so that the client obtains a synchronization file corresponding to the latest version number after receiving the synchronization task.
Optionally, the writing module 701 is specifically configured to determine whether the synchronization data in the MySQL database changes at regular time; and under the condition of change, writing the synchronous data in the MySQL database into a synchronous file in the SQLite database.
Optionally, the writing module 701 includes: a write judgment unit configured to judge whether full-volume writing has been performed; the first writing unit is used for writing the full synchronous data in the MySQL database into the synchronous file in the SQLite database under the condition that the writing judging unit judges that the full writing is not executed; and the second writing unit is used for writing the increment synchronous data in the MySQL database into the synchronous file in the SQLite database under the condition that the writing judging unit judges that the full writing is executed.
Optionally, the second writing unit is specifically configured to obtain a recorded writing end position; acquiring synchronous data positioned behind the writing end position in the MySQL database as incremental synchronous data; and writing the increment synchronous data into a synchronous file in the SQLite database.
Referring to fig. 8, a block diagram of a client according to an embodiment of the present application is shown.
As shown in fig. 8, the client may include the following modules:
a sending module 801, configured to send a heartbeat signal including a version number of a synchronization file in the client to a server; after receiving the heartbeat signal, the server judges whether the version number of the synchronous file in the client is the same as the latest version number of the synchronous file in the SQLite database, and if not, issues a synchronous task containing the latest version number to the client; the server is used for writing the synchronous data in the MySQL database into the synchronous file in the SQLite database according to the set rule, and recording the version number of the synchronous file;
and an obtaining module 802, configured to obtain a synchronization file corresponding to the latest version number after receiving the synchronization task issued by the server.
Optionally, the acquiring module 802 includes: the file judging unit is used for judging whether synchronous files corresponding to the latest version numbers exist in other clients which are located in the same local area network with the client; the first acquisition unit is used for acquiring the synchronous file corresponding to the latest version number from the existing client when the file judgment unit judges that the file exists; and the second acquisition unit is used for acquiring the synchronous file corresponding to the latest version number from the server when the file judgment unit judges that the synchronous file does not exist.
In the embodiment of the application, the synchronous data in the MySQL database is written into the synchronous file in the SQLite database, so that the synchronous file in the SQLite database can be synchronized to the client during data synchronization, and the client can directly read the acquired synchronous file due to the zero configuration and the capability of directly reading the file of the SQLite data.
For the device embodiments, since they are substantially similar to the method embodiments, the description is relatively simple, and reference is made to the description of the method embodiments for relevant points.
In an embodiment of the application, an electronic device is also provided. The electronic device may correspond to the server in the above embodiment, or may correspond to the client in the above embodiment. The electronic device may include one or more processors and one or more computer-readable storage media having instructions stored thereon, such as an application program. The instructions, when executed by the one or more processors, cause the processors to perform the data synchronization method of any of the embodiments described above.
Referring to fig. 9, a schematic diagram of an electronic device structure according to an embodiment of the present application is shown. As shown in fig. 9, the electronic device includes a processor 901, a communication interface 902, a memory 903, and a communication bus 904. The processor 901, the communication interface 902 and the memory 903 perform communication with each other through a communication bus 904.
A memory 903 for storing a computer program.
The processor 901 is configured to implement the data synchronization method of any of the above embodiments when executing the program stored in the memory 903.
The communication interface 902 is used for communication between the electronic device and other devices.
The communication bus 904 mentioned above may be a peripheral component interconnect standard (Peripheral Component Interconnect, PCI) bus or an extended industry standard architecture (Extended Industry Standard Architecture, EISA) bus, or the like. The communication bus may be classified as an address bus, a data bus, a control bus, or the like. For ease of illustration, the figures are shown with only one bold line, but not with only one bus or one type of bus.
The above-mentioned processor 901 may include, but is not limited to: central processing units (Central Processing Unit, CPU), network processors (Network Processor, NP), digital signal processors (Digital Signal Processing, DSP), application specific integrated circuits (Application Specific Integrated Circuit, ASIC), field-programmable gate arrays (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, and the like.
The above mentioned memory 903 may include, but is not limited to: read Only Memory (ROM), random access Memory (Random Access Memory RAM), compact disk Read Only Memory (Compact Disc Read Only Memory CD-ROM), electrically erasable programmable Read Only Memory (Electronic Erasable Programmable Read Only Memory EEPROM), hard disk, floppy disk, flash Memory, and the like.
In an embodiment of the present application, there is also provided a computer-readable storage medium having stored thereon a computer program executable by a processor of an electronic device, the computer program, when executed by the processor, causing the processor to perform the data synchronization method as described in any of the embodiments above.
In this specification, various embodiments are interrelated, and each embodiment is described in a progressive manner, and each embodiment is mainly described in a different manner from other embodiments, so that identical and similar parts between the various embodiments are referred to each other.
It is noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or terminal that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or terminal. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article or terminal device comprising the element.
From the above description of the embodiments, it will be clear to those skilled in the art that the above-described embodiment method may be implemented by means of software plus a necessary general hardware platform, but of course may also be implemented by means of hardware, but in many cases the former is a preferred embodiment. Based on such understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art in the form of a software product stored in a storage medium (such as ROM, RAM, magnetic disk, optical disk) and including several instructions for causing a terminal (which may be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to perform the method according to the embodiments of the present application.
The embodiments of the present application have been described above with reference to the accompanying drawings, but the present application is not limited to the above-described embodiments, which are merely illustrative and not restrictive, and many forms may be made by those having ordinary skill in the art without departing from the spirit of the present application and the scope of the claims, which are to be protected by the present application.
Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
It will be clear to those skilled in the art that, for convenience and brevity of description, specific working procedures of the above-described systems, apparatuses and units may refer to corresponding procedures in the foregoing method embodiments, and are not repeated herein.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus and method may be implemented in other manners. For example, the apparatus embodiments described above are merely illustrative, e.g., the division of the units is merely a logical function division, and there may be additional divisions when actually implemented, e.g., multiple units or components may be combined or integrated into another system, or some features may be omitted or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be an indirect coupling or communication connection via some interfaces, devices or units, which may be in electrical, mechanical or other form.
The units described as separate units may or may not be physically separate, and units shown as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional unit in the embodiments of the present application may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art or in a part of the technical solution, in the form of a software product stored in a storage medium, comprising several instructions for causing a computer device (which may be a personal computer, a server, a network device, etc.) to perform all or part of the steps of the method according to the embodiments of the present application. And the aforementioned storage medium includes: a usb disk, a removable hard disk, a ROM, a RAM, a magnetic disk, or an optical disk, etc.
The foregoing is merely illustrative of the present application, and the present application is not limited thereto, and any person skilled in the art will readily recognize that variations or substitutions are within the scope of the present application. In view of the foregoing, this description should not be construed as limiting the application.

Claims (10)

1. A method of data synchronization, for application to a server, the method comprising:
according to a set rule, writing synchronous data in the MySQL database into a synchronous file in the SQLite database, and recording the version number of the synchronous file;
after receiving a heartbeat signal sent by a client, judging whether the version number of a synchronous file in the client contained in the heartbeat signal is the same as the latest version number of the synchronous file in the SQLite database;
and under the condition of non-uniformity, issuing a synchronous task containing the latest version number to the client so that the client acquires a synchronous file corresponding to the latest version number after receiving the synchronous task.
2. The method of claim 1, wherein writing the synchronization data in the MySQL database to the synchronization file in the SQLite database according to the set rule comprises:
Judging whether synchronous data in the MySQL database is changed or not at regular time;
and under the condition of change, writing the synchronous data in the MySQL database into a synchronous file in the SQLite database.
3. The method according to claim 1 or 2, wherein writing the synchronization data in the MySQL database to the synchronization file in the SQLite database comprises:
judging whether full writing is performed;
writing the full-volume synchronous data in the MySQL database into a synchronous file in an SQLite database under the condition that full-volume writing is not executed;
and under the condition that full writing is performed, writing the increment synchronous data in the MySQL database into a synchronous file in the SQLite database.
4. The method of claim 3, wherein writing incremental synchronization data in the MySQL database to a synchronization file in a SQLite database comprises:
acquiring a recorded writing end position;
acquiring synchronous data positioned behind the writing end position in the MySQL database as incremental synchronous data;
and writing the increment synchronous data into a synchronous file in the SQLite database.
5. A method of data synchronization, for application to a client, the method comprising:
sending a heartbeat signal containing a version number of the synchronous file in the client to a server; after receiving the heartbeat signal, the server judges whether the version number of the synchronous file in the client is the same as the latest version number of the synchronous file in the SQLite database, and if not, issues a synchronous task containing the latest version number to the client; the server is used for writing the synchronous data in the MySQL database into the synchronous file in the SQLite database according to the set rule, and recording the version number of the synchronous file;
and after receiving the synchronization task issued by the server, acquiring a synchronization file corresponding to the latest version number.
6. The method of claim 5, wherein the obtaining the synchronization file corresponding to the latest version number comprises:
judging whether synchronous files corresponding to the latest version numbers exist in other clients which are located in the same local area network with the client;
when the latest version number exists, acquiring a synchronous file corresponding to the latest version number from the existing client;
And when the latest version number does not exist, acquiring the synchronous file corresponding to the latest version number from the server.
7. A server, the server comprising:
the writing module is used for writing the synchronous data in the MySQL database into the synchronous file in the SQLite database according to the set rule and recording the version number of the synchronous file;
the judging module is used for judging whether the version number of the synchronous file in the client contained in the heartbeat signal is the same as the latest version number of the synchronous file in the SQLite database after receiving the heartbeat signal sent by the client;
and the issuing module is used for issuing the synchronous task containing the latest version number to the client under the condition of different conditions, so that the client acquires the synchronous file corresponding to the latest version number after receiving the synchronous task.
8. A client, the client comprising:
the sending module is used for sending a heartbeat signal containing the version number of the synchronous file in the client to the server; after receiving the heartbeat signal, the server judges whether the version number of the synchronous file in the client is the same as the latest version number of the synchronous file in the SQLite database, and if not, issues a synchronous task containing the latest version number to the client; the server is used for writing the synchronous data in the MySQL database into the synchronous file in the SQLite database according to the set rule, and recording the version number of the synchronous file;
And the acquisition module is used for acquiring the synchronous file corresponding to the latest version number after receiving the synchronous task issued by the server.
9. An electronic device, comprising:
one or more processors; and
one or more computer-readable storage media having instructions stored thereon;
the instructions, when executed by the one or more processors, cause the processor to perform the data synchronization method of any one of claims 1 to 4 or the data synchronization method of any one of claims 5 to 6.
10. A computer readable storage medium, having stored thereon a computer program which, when executed by a processor, causes the processor to perform the data synchronization method of any of claims 1 to 4 or to perform the data synchronization method of any of claims 5 to 6.
CN202310896544.XA 2023-07-20 2023-07-20 Data synchronization method, server, client, electronic device and storage medium Pending CN117097737A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310896544.XA CN117097737A (en) 2023-07-20 2023-07-20 Data synchronization method, server, client, electronic device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310896544.XA CN117097737A (en) 2023-07-20 2023-07-20 Data synchronization method, server, client, electronic device and storage medium

Publications (1)

Publication Number Publication Date
CN117097737A true CN117097737A (en) 2023-11-21

Family

ID=88768893

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310896544.XA Pending CN117097737A (en) 2023-07-20 2023-07-20 Data synchronization method, server, client, electronic device and storage medium

Country Status (1)

Country Link
CN (1) CN117097737A (en)

Similar Documents

Publication Publication Date Title
CN111367984B (en) Method and system for loading high-timeliness data into data lake
CN111078504A (en) Distributed call chain tracking method and device, computer equipment and storage medium
US20170031948A1 (en) File synchronization method, server, and terminal
CN101808127B (en) Data backup method, system and server
CN101329685A (en) Implementing method of memory database on household gateway
CN113438275B (en) Data migration method and device, storage medium and data migration equipment
CN113111129A (en) Data synchronization method, device, equipment and storage medium
CN109150608A (en) Interface service upgrade method and system for voice dialogue platform
CN112199048B (en) Data reading method, system, device and medium
CN112948498A (en) Method and device for generating global identification of distributed system
CN110807062A (en) Data synchronization method and device and database host
CN110109866B (en) Method and equipment for managing file system directory
CN115004662A (en) Data synchronization method, data synchronization device, data storage system and computer readable medium
CN116501700B (en) APP formatted file offline storage method, device, equipment and storage medium
CN113157823A (en) Cluster system deployment method and device
CN117097737A (en) Data synchronization method, server, client, electronic device and storage medium
CN111309366A (en) Method, device, medium and electronic equipment for managing registration core
CN110515907B (en) Data synchronization method and related device for distributed storage nodes
CN113810513B (en) Configuration management method and system for elastic public network IP
CN110851411B (en) DNS dynamic change system and method based on file synchronization
CN111966650B (en) Operation and maintenance big data sharing data table processing method and device and storage medium
CN116743780A (en) Distributed storage system and method
CN114579667A (en) Method, device and system for incremental synchronization of HBase data
CN113507529A (en) Method for realizing file downloading based on Web application
CN113810463A (en) Configuration method and system for issuing CDN server

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