CN113177093A - Data synchronization method and device, electronic equipment and storage medium - Google Patents

Data synchronization method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN113177093A
CN113177093A CN202110565003.XA CN202110565003A CN113177093A CN 113177093 A CN113177093 A CN 113177093A CN 202110565003 A CN202110565003 A CN 202110565003A CN 113177093 A CN113177093 A CN 113177093A
Authority
CN
China
Prior art keywords
terminal
database
cloud
state
operation log
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
CN202110565003.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.)
Sensetime International Pte Ltd
Original Assignee
Sensetime International Pte 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 Sensetime International Pte Ltd filed Critical Sensetime International Pte Ltd
Priority to CN202110565003.XA priority Critical patent/CN113177093A/en
Publication of CN113177093A publication Critical patent/CN113177093A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2358Change logging, detection, and notification
    • 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 present disclosure relates to a data synchronization method and apparatus, an electronic device, and a storage medium, the method including: under the condition that communication connection exists between the terminal and the cloud server and the terminal is subscribed with a target theme of the cloud server, receiving a first operation log in the target theme sent by the cloud server; under the condition of receiving a first operation log sent by a cloud server, updating a local terminal database of the terminal according to the first operation log to obtain a terminal database with a first terminal state; the first operation log indicates that operation aiming at a cloud database of the cloud server exists, and the terminal and the cloud server establish communication connection through a message queue telemetry transmission protocol MQTT. The embodiment of the disclosure can realize the consistency of data synchronization.

Description

Data synchronization method and device, electronic equipment and storage medium
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a data synchronization method and apparatus, an electronic device, and a storage medium.
Background
With the development of the internet of things and the continuous improvement of computing and storage capacities of various terminal devices, more and more task processing (such as face recognition) is transmitted to the cloud server for execution and is transferred to the terminal device with computing and storage capacities for execution, so that the delay of network request reply is reduced, and the task processing efficiency is improved. Processing tasks on the terminal device generally requires synchronizing data stored in the cloud server to the terminal device, where the data may be, for example, facial features used for face recognition comparison, and identity information (name, gender, etc.) of a person.
Usually, a manual copying mode is adopted, but the mode is not suitable for a database with frequently changed data; the data synchronization method can also be finished by copying a state machine and combining a hypertext transfer protocol (HTTP), but the method needs stable network, the network is unstable in the scene of the Internet of things, the method for synchronizing data through the HTTP is not applicable, efficient synchronous data updating cannot be achieved, meanwhile, the consistency of the data is guaranteed, and when a large number of terminal devices are provided, a large number of HTTP requests can bring pressure to a cloud server, and the expandability is not high.
Disclosure of Invention
The present disclosure provides a data synchronization technical solution.
According to an aspect of the present disclosure, there is provided a data synchronization method applied to a terminal, including: under the condition that communication connection exists between the terminal and a cloud server and the terminal is subscribed with a target theme of the cloud server, receiving a first operation log in the target theme sent by the cloud server; under the condition that the first operation log sent by the cloud server is received, updating a local terminal database of the terminal according to the first operation log to obtain a terminal database with a first terminal state; the first operation log indicates that operation aiming at a cloud database of the cloud server exists, and the terminal and the cloud server establish communication connection through a message queue telemetry transmission protocol MQTT. Through the mode, the consistency of data can be guaranteed, the network request times can be reduced, so that the cloud server can be accessed to a large number of terminals, and the expandability is high.
In one possible implementation, the method further includes: sending a state acquisition request to the cloud server under the condition that a preset synchronization condition is met, wherein the state acquisition request is used for acquiring a first cloud state of the cloud database, and the first cloud state represents the current database state of the cloud database; under the condition that the first cloud state sent by the cloud server is received, judging whether the first cloud state is matched with the first terminal state; under the condition that the first cloud state is not matched with the first terminal state, acquiring current first snapshot information of the cloud database; updating the terminal database of the first terminal state according to the acquired first snapshot information to obtain a terminal database with a second terminal state; wherein the predetermined synchronization condition includes: the time length of the communication connection interruption between the terminal and the cloud server exceeds a time threshold, and the communication connection between the terminal and the cloud server is recovered. Through the method, the terminal database can be efficiently updated based on the snapshot information of the cloud database under the condition that the network is disconnected and reconnected between the terminal and the cloud server, so that the data synchronization of the cloud database and the terminal database is rapidly realized.
In one possible implementation, the method further includes: judging whether the second terminal state is matched with the first cloud state; under the condition that the second terminal state is not matched with the first cloud state, sending a difference log obtaining request to the cloud server, wherein the difference log obtaining request is used for obtaining a difference operation log corresponding to the first cloud state; and under the condition of receiving the difference operation log sent by the cloud server, updating the terminal database in the second terminal state according to the difference operation log to obtain a terminal database in a third terminal state, wherein the third terminal state is the same as the first cloud state. By the method, under the condition that part of newly-added operation logs in the cloud database are not backed up in the first snapshot information, the difference operation logs can be acquired, and data synchronization can be efficiently realized, so that data consistency is ensured.
In one possible implementation, the method further includes: sending a snapshot theme subscription request to the cloud server under the condition that communication connection is started between the terminal and the cloud server, wherein the snapshot theme subscription request is used for subscribing a snapshot theme of the cloud server so as to obtain second snapshot information of the cloud database through the snapshot theme; and updating the terminal database in the first terminal state according to the acquired second snapshot information to obtain a terminal database in a fourth terminal state. By the method, the second snapshot information can be acquired for full updating by subscribing the snapshot theme under the condition that the terminal is in communication connection with the cloud server, the terminal database can be efficiently synchronized to the state same as the cloud database as far as possible, the number of access requests is reduced, and the data synchronization efficiency is improved.
In a possible implementation manner, after the terminal database in the first terminal state is updated according to the obtained second snapshot information to obtain a terminal database in a fourth terminal state, the method further includes: sending a target theme subscription request to the cloud server to subscribe a target theme in the cloud server; under the condition that a second operation log in the target theme sent by the cloud server is received, judging whether the second operation log is matched with a terminal database of the fourth terminal state; sending an interval log obtaining request to the cloud server under the condition that the second operation log is not matched with the terminal database in the fourth state, wherein the interval log obtaining request is used for obtaining an interval operation log between the second operation log and the second snapshot information; under the condition that an interval operation log sent by the cloud server is received, updating the terminal database in the fourth terminal state according to the interval operation log and the second operation log to obtain a terminal database in a fifth terminal state, wherein the fifth terminal state is the same as the second cloud state of the cloud database. By the method, the target subject is subscribed and the interval operation log is obtained, so that the interval operation log between the full operation log of the second snapshot information and the second operation log can be effectively obtained, the interval operation log is completed, and the consistency of data synchronization is ensured.
In one possible implementation, the method further includes: responding to an operation aiming at a terminal database local to the terminal, and sending a data updating request to the cloud server, wherein the data updating request is used for indicating that the cloud database is updated correspondingly to the operation. Through the method, the updating operation aiming at the terminal database can be synchronized to the cloud database, and the data consistency between the terminal database and the cloud database is ensured.
According to an aspect of the present disclosure, a data synchronization method is provided, which is applied to a cloud server, and includes: determining a first operation log corresponding to an operation aiming at a cloud database under the condition that the operation aiming at the cloud database exists; and publishing the first operation log to a target theme of a cloud server, and sending the first operation log in the target theme to a terminal subscribed with the target theme so that the terminal updates a local terminal database of the terminal according to the first operation log. By the mode, data synchronization of the publish/subscribe mode can be efficiently realized in an unstable network based on the MQTT protocol, and meanwhile, the consistency of data can be ensured, so that the cloud server can be accessed to a large number of terminals, and the expandability is high.
In one possible implementation, the method further includes: under the condition that a state acquisition request sent by the terminal is received, sending a first cloud state of the cloud database to the terminal so that the terminal updates the terminal database based on the first cloud state, wherein the first cloud state is the current database state of the cloud database.
In one possible implementation, the method further includes: and under the condition of receiving a difference log acquisition request sent by the terminal, sending a difference operation log corresponding to a first cloud state of the cloud database to the terminal, so that the terminal updates the terminal database according to the difference operation log.
In one possible implementation, the method further includes: according to a preset period, taking a snapshot of the current full operation log of the cloud database to obtain snapshot information; and publishing the snapshot information to a snapshot theme subscribed by the terminal so as to send the snapshot information to the terminal through the snapshot theme.
In one possible implementation, the method further includes: under the condition that a data updating request sent by the terminal is received, updating the cloud database according to the operation indicated by the data updating request, wherein the data updating request is triggered by responding to the operation of the terminal database.
According to an aspect of the present disclosure, there is provided a data synchronization apparatus applied to a terminal, including: the receiving module is used for receiving a first operation log in a target theme sent by a cloud server under the condition that the communication connection exists between the terminal and the cloud server and the terminal is subscribed with the target theme of the cloud server; the first updating module updates a local terminal database of the terminal according to the first operation log under the condition that the first operation log sent by the cloud server is received, so that a terminal database with a first terminal state is obtained; the first operation log indicates that operation aiming at a cloud database of the cloud server exists, and the terminal and the cloud server establish communication connection through a message queue telemetry transmission protocol MQTT.
In one possible implementation, the apparatus further includes: the state acquisition module is used for sending a state acquisition request to the cloud server under the condition that a preset synchronization condition is met, wherein the state acquisition request is used for acquiring a first cloud state of the cloud database, and the first cloud state represents the current database state of the cloud database; the first judgment module is used for judging whether the first cloud state is matched with the first terminal state or not under the condition that the first cloud state sent by the cloud server is received; the snapshot obtaining module is used for obtaining current first snapshot information of the cloud database under the condition that the first cloud state is not matched with the first terminal state; the second updating module is used for updating the terminal database in the first terminal state according to the acquired first snapshot information to obtain a terminal database in a second terminal state; wherein the predetermined synchronization condition includes: the time length of the communication connection interruption between the terminal and the cloud server exceeds a time threshold, and the communication connection between the terminal and the cloud server is recovered.
In one possible implementation, the apparatus further includes: the second judgment module is used for judging whether the second terminal state is matched with the first cloud state; the difference log obtaining module is used for sending a difference log obtaining request to the cloud server under the condition that the second terminal state is not matched with the first cloud state, wherein the difference log obtaining request is used for obtaining a difference operation log corresponding to the first cloud state; and the third updating module is used for updating the terminal database in the second terminal state according to the difference operation log under the condition of receiving the difference operation log sent by the cloud server to obtain the terminal database in a third terminal state, wherein the third terminal state is the same as the first cloud state.
In one possible implementation, the apparatus further includes: the snapshot theme subscription module is used for sending a snapshot theme subscription request to the cloud server under the condition that communication connection is started between the terminal and the cloud server, wherein the snapshot theme subscription request is used for subscribing a snapshot theme of the cloud server so as to obtain second snapshot information of the cloud database through the snapshot theme; and the fourth updating module is used for updating the terminal database in the first terminal state according to the acquired second snapshot information to obtain a terminal database with a fourth terminal state.
In a possible implementation manner, after the terminal database in the first terminal state is updated according to the obtained second snapshot information to obtain a terminal database in a fourth terminal state, the apparatus further includes: the target theme subscription module is used for sending a target theme subscription request to the cloud server so as to subscribe a target theme in the cloud server; the third judging module is used for judging whether a second operation log in the target theme sent by the cloud server is matched with a terminal database of the fourth terminal state or not under the condition that the second operation log is received; an interval log obtaining module, configured to send an interval log obtaining request to the cloud server when the second operation log is not matched with the terminal database in the fourth state, where the interval log obtaining request is used to obtain an interval operation log between the second operation log and the second snapshot information; and the fifth updating module is used for updating the terminal database in the fourth terminal state according to the interval operation log and the second operation log under the condition of receiving the interval operation log sent by the cloud server to obtain the terminal database in the fifth terminal state, wherein the fifth terminal state is the same as the second cloud state of the cloud database.
In one possible implementation, the apparatus further includes: the update request sending module is used for responding to an operation aiming at a terminal database local to the terminal and sending a data update request to the cloud server, wherein the data update request is used for indicating that the cloud database is updated correspondingly to the operation.
According to an aspect of the present disclosure, a data synchronization apparatus is provided, which is applied to a cloud server, and includes: the determining module is used for determining a first operation log corresponding to the operation aiming at the cloud database under the condition that the operation aiming at the cloud database exists; the publishing module is used for publishing the first operation log to a target theme of a cloud server and sending the first operation log in the target theme to a terminal subscribed with the target theme so that the terminal updates a local terminal database of the terminal according to the first operation log.
In one possible implementation, the apparatus further includes: the cloud state sending module is used for sending a first cloud state of the cloud database to the terminal under the condition that a state obtaining request sent by the terminal is received, so that the terminal updates the terminal database based on the first cloud state, wherein the first cloud state is the current database state of the cloud database.
In one possible implementation, the apparatus further includes: the difference log sending module is used for sending a difference operation log corresponding to a first cloud state of the cloud database to the terminal under the condition that a difference log obtaining request sent by the terminal is received, so that the terminal updates the terminal database according to the difference operation log.
In one possible implementation, the apparatus further includes: the snapshot module is used for taking a snapshot of the current full operation log of the cloud database according to a preset period to obtain snapshot information; and the snapshot publishing module is used for publishing the snapshot information to a snapshot theme subscribed by the terminal so as to send the snapshot information to the terminal through the snapshot theme.
In one possible implementation, the apparatus further includes: the cloud updating module is used for updating the cloud database according to the operation indicated by the data updating request under the condition that the data updating request sent by the terminal is received, wherein the data updating request is triggered by responding to the operation aiming at the terminal database.
According to an aspect of the present disclosure, there is provided an electronic device including: a processor; a memory for storing processor-executable instructions; wherein the processor is configured to invoke the memory-stored instructions to perform the above-described method.
According to an aspect of the present disclosure, there is provided a computer readable storage medium having stored thereon computer program instructions which, when executed by a processor, implement the above-described method.
In the embodiment of the disclosure, under the condition that the communication connection exists between the terminal and the cloud server and the terminal has subscribed the target topic, the cloud server can push the first operation log in the target topic to the terminal subscribed to the target topic to update the terminal database, and the communication connection established between the terminal and the cloud server through the MQTT protocol can efficiently realize data synchronization of a publish/subscribe mode based on the MQTT protocol in an unstable network, and can simultaneously ensure the consistency of data, and can also reduce the network request times, so that the cloud server can access a large number of terminals, and the expandability is high.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure. Other features and aspects of the present disclosure will become apparent from the following detailed description of exemplary embodiments, which proceeds with reference to the accompanying drawings.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the disclosure.
Fig. 1 shows a flow chart of a data synchronization method according to an embodiment of the present disclosure.
Fig. 2 shows a flow diagram of a data synchronization method according to an embodiment of the present disclosure.
Fig. 3 shows a schematic diagram of generating snapshot information according to an embodiment of the present disclosure.
Fig. 4 shows a schematic diagram of a data synchronization method according to an embodiment of the present disclosure.
Fig. 5 shows an interaction diagram of a terminal and a cloud according to an embodiment of the present disclosure.
Fig. 6 shows a block diagram of a data synchronization apparatus according to an embodiment of the present disclosure.
Fig. 7 shows a block diagram of a data synchronization apparatus according to an embodiment of the present disclosure.
FIG. 8 shows a block diagram of an electronic device in accordance with an embodiment of the disclosure.
Fig. 9 shows a block diagram of an electronic device in accordance with an embodiment of the disclosure.
Detailed Description
Various exemplary embodiments, features and aspects of the present disclosure will be described in detail below with reference to the accompanying drawings. In the drawings, like reference numbers can indicate functionally identical or similar elements. While the various aspects of the embodiments are presented in drawings, the drawings are not necessarily drawn to scale unless specifically indicated.
The word "exemplary" is used exclusively herein to mean "serving as an example, embodiment, or illustration. Any embodiment described herein as "exemplary" is not necessarily to be construed as preferred or advantageous over other embodiments.
The term "and/or" herein is merely an association describing an associated object, meaning that three relationships may exist, e.g., a and/or B, may mean: a exists alone, A and B exist simultaneously, and B exists alone. In addition, the term "at least one" herein means any one of a plurality or any combination of at least two of a plurality, for example, including at least one of A, B, C, and may mean including any one or more elements selected from the group consisting of A, B and C.
It should be understood that the terms "first," "second," and "third," etc. in the claims, description, and drawings of the present disclosure are used for distinguishing between different objects and not for describing a particular order. The terms "comprises" and "comprising," when used in the specification and claims of this disclosure, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
Furthermore, in the following detailed description, numerous specific details are set forth in order to provide a better understanding of the present disclosure. It will be understood by those skilled in the art that the present disclosure may be practiced without some of these specific details. In some instances, methods, means, elements and circuits that are well known to those skilled in the art have not been described in detail so as not to obscure the present disclosure.
Fig. 1 shows a flowchart of a data synchronization method according to an embodiment of the present disclosure, the method being applied to a terminal, as shown in fig. 1, the data synchronization method including:
in step S11, when there is a communication connection between the terminal and the cloud server and the terminal has subscribed to the target topic of the cloud server, receiving a first operation log in the target topic sent by the cloud server;
in step S12, when the first operation log sent by the cloud server is received, the terminal database local to the terminal is updated according to the first operation log, so as to obtain a terminal database with a first terminal state;
the first operation log indicates that operation aiming at a cloud database of the cloud server exists, and the terminal and the cloud server establish communication connection through a message queue telemetry transmission protocol MQTT.
In one possible implementation, the data synchronization method may be performed by a terminal device, which may be a User Equipment (UE), a mobile device, a User terminal, a cellular phone, a cordless phone, a Personal Digital Assistant (PDA), a handheld device, a computing device, a vehicle-mounted device, a wearable device, a smart camera, or the like, and the method may be implemented by a processor calling computer-readable instructions stored in a memory.
In a possible implementation manner, in step S11, a communication connection exists between the terminal and the cloud server, which may be understood that the communication network connection between the terminal and the cloud server is normal, or data transmission is normal. It should be understood that, under the condition that the network connection is normal, the terminal may receive the operation log pushed by the cloud server.
In a possible implementation manner, an MQTT broker service (MQTT broker) may be provided in the cloud server. Through the MQTT proxy service, the cloud server can publish the operation logs of the cloud database to the target topic subscribed by the terminal, and push the first operation log in the target topic to the terminal subscribed with the target topic.
As can be known, the MQTT (Message Queuing Telemetry Transport) protocol is a Message Transport protocol based on a Message publish/subscribe mode. The message publish/subscribe mode may be understood as a mode in which a message publisher publishes a message to a specific message queue topic, and a plurality of message subscribers may receive messages in the message queue topic after subscribing to the message queue topic. Based on this, the target topic may be a message queue topic for pushing oplogs, and an oplog in the target topic may be understood as a message in the target topic.
It should be understood that, compared with the HTTP transmission protocol in the request-response mode, the message transmission protocol in the message publish/subscribe mode can implement efficient and consistent data synchronization without depending on the network connection condition due to asynchronous data transmission, and can meet the data synchronization requirement in the scene of the internet of things under the conditions of poor network condition, unstable network connection, and the like.
In one possible implementation, operations (e.g., adding, deleting, modifying, etc.) for the cloud database may be abstracted into an operation log, in other words, operations for the cloud database may be recorded in the form of an operation log. Correspondingly, the first operation log received by the terminal can indicate that the operation aiming at the cloud database of the cloud server exists, so that when the terminal database is updated (such as incremental updating) according to the first operation log, the operation aiming at the cloud database can be synchronized to the terminal database, and data consistency is realized.
In a possible implementation manner, in step S12, the terminal database local to the terminal is updated according to the first operation log, which may be an operation indicated by the first operation log performed on the terminal database, for example, a person record is added to the person table.
The terminal state in the present disclosure represents a database state of the terminal database, wherein in step S12, the first terminal state represents a database state after the terminal database is updated according to the first operation log. It should be understood that the terminal database having the first terminal status may be understood as a terminal database after performing the operation indicated by the first operation log.
It should be noted that, the terminal database and the cloud database may both refer to databases, and the database local to the terminal is the terminal database, and the database of the cloud server is the cloud database. It should be understood that the database states of the terminal database and the cloud database may be asynchronous, the database state represents a storage state of data in the database, and the purpose of data synchronization is to make the data stored in the terminal database and the data stored in the cloud database identical, that is, the database states are synchronized.
In a possible implementation manner, the data in the terminal database may include at least one of a face image, face feature information, a body image, body feature information, and person identity information. Correspondingly, the data in the cloud database may include at least one of a face image, face feature information, a body image, body feature information, and person identity information. The embodiments of the present disclosure are not limited to the data stored in the terminal database and the cloud database.
It should be understood that, data synchronization realized based on the MQTT protocol is asynchronous data synchronization, and based on this, in one possible implementation manner, the terminals may include a plurality of terminals, so that all terminals subscribing to the target topic may receive the first operation log sent by the cloud server, thereby supporting access of a large number of terminals without bringing access pressure to the cloud server, and having high expandability.
In the embodiment of the disclosure, under the condition that the communication connection exists between the terminal and the cloud server and the terminal has subscribed the target topic, the cloud server can push the first operation log in the target topic to the terminal subscribed with the target topic to update the terminal database, and the communication connection established between the terminal and the cloud server through the MQTT protocol, so that data synchronization of a publish/subscribe mode can be efficiently realized based on the MQTT protocol in an unstable network, meanwhile, the consistency of data can be ensured, the number of network requests can be reduced, so that the cloud server can be accessed to a large number of terminals, and the expandability is high.
As described above, network connection in the scene of the internet of things is unstable, for example, when a bus is used for brushing a face, human face feature information and personnel information in the cloud database need to be synchronized to the intelligent terminal of the bus, and the network connection condition of the bus at a station is better, the network connection condition becomes worse after the bus leaves the station, and under the poor network connection condition, the intelligent terminal of the bus and the cloud server may not be in good communication connection.
For these cases, in one possible implementation manner, the method may further include:
step S13: the method comprises the steps that under the condition that a preset synchronization condition is met, a state obtaining request is sent to a cloud server, the state obtaining request is used for obtaining a current first cloud state of a cloud database, and the first cloud state represents the current database state of the cloud database;
step S14: under the condition of receiving a first cloud state sent by a cloud server, judging whether the first cloud state is matched with a first terminal state;
step S15: under the condition that the first cloud state is matched with the first terminal state, acquiring current first snapshot information of a cloud database;
step S16: updating the terminal database in the first terminal state according to the acquired first snapshot information to obtain a terminal database in the second terminal state;
wherein the predetermined synchronization condition includes: the time length for interrupting the communication connection between the terminal and the cloud server exceeds a time threshold, and the communication connection between the terminal and the cloud server is recovered.
In a possible implementation manner, the duration of the interruption of the communication connection between the terminal and the cloud server exceeds a time threshold, which may be understood as that the terminal and the cloud server have not been in communication or data transmission for a period of time, and at this time, it may be considered that the network connection between the terminal and the cloud server has been disconnected and exceeds the time threshold. The time threshold may be set according to actual requirements, for example, may be determined according to the running time of the bus between stations, which is not limited in this disclosure.
It should be understood that, the duration of the interruption of the communication connection between the terminal and the cloud server exceeds the time threshold, and the communication connection between the terminal and the cloud server is restored, it can be understood that the disconnection and reconnection are performed between the terminal and the cloud server, that is, the predetermined synchronization condition can be understood as the disconnection and reconnection.
The cloud state in the present disclosure represents a database state of the cloud database, wherein in step S13, the first cloud state represents a current database state of the cloud database, and the database state may represent a storage state of data in the database.
As described above, the operation log of the cloud database may be published to the target topic, the current operation log of the cloud database may reflect the current database state of the cloud database, and different operation logs may be distinguished by the log identifier. In a possible implementation manner, in step S13, the current database state of the cloud database is obtained, which may be a log identifier of a current operation log in the target topic, so as to represent the current database state of the database through the log identifier, that is, represent the first cloud state. By the method, the current first cloud state of the cloud database can be conveniently acquired.
It should be understood that, because the terminal database is updated according to the first operation log, the first operation log may reflect the data state of the updated terminal database, that is, may reflect the first terminal state of the terminal database, and therefore, the first terminal state of the terminal database may be represented by the log identifier of the first operation log.
In a possible implementation manner, in step S14, it is determined whether the first cloud status matches the first terminal status, which may be whether the log identifier representing the first cloud status and the log flag representing the first terminal status are consecutive in sequence. For example, if the log flag representing the first cloud state is 0100, if the log flag representing the first terminal state is 0101, it may represent that the log flag representing the first cloud state and the log flag representing the first terminal state are consecutive, that is, the first cloud state is matched with the first terminal state; if the log identifier representing the first terminal state is 0299, it can represent that the log identifier representing the first cloud terminal state and the log flag representing the first terminal state are not continuous, that is, the first cloud terminal state and the first terminal state are not matched.
In a possible implementation manner, in step S15, the first cloud state does not match the first terminal state, and it is understood that the log identifier representing the first cloud state and the log flag representing the first terminal state are not consecutive. In this case, considering that the duration of interrupting the communication connection between the terminal and the cloud server in the predetermined synchronization condition exceeds the time threshold, and the number of newly added operation logs in the cloud database may be more in the duration, the current first snapshot information of the cloud database may be obtained to update the terminal database, so as to reduce the volume of data transmission and improve the data synchronization efficiency.
In a possible implementation manner, the current first snapshot information of the cloud database may be snapshot information generated by snapshot-shooting a current full operation log of the cloud database. Wherein, the snapshot information can be understood as a copy or a duplicate of the full operation log, etc.; the snapshot of the full-volume operation log can be implemented by any existing snapshot technology, and the embodiment of the present disclosure is not limited.
It can be known that, taking a snapshot of the full operation log can achieve the effect of compressing the volume of the full operation log, that is, the snapshot information generated by taking a snapshot is smaller than the volume of the full operation log, so that the volume of data transmission can be reduced, and the data synchronization efficiency can be improved.
In a possible implementation manner, in step S15, the current first snapshot information of the cloud database is obtained, and the first snapshot information may be obtained in a manner of subscribing to a snapshot topic, or in a manner of sending an HTTP request to the cloud database, which is not limited in this embodiment of the disclosure.
As described above, there may be a matching situation between the first cloud status and the first terminal status, and in this case, the current database statuses of the cloud database and the terminal database may be considered to be synchronous, and in this case, the operation log in the target topic may be directly obtained without performing step S15 to obtain snapshot information, and the terminal database may be updated according to the obtained operation log.
In a possible implementation manner, in step S16, the updating the terminal database of the first terminal state according to the acquired first snapshot information may include: according to the operation indicated by the operation log in the first snapshot information, performing full update on the terminal database in the first terminal state; or according to the difference operation log between the first snapshot information and the first operation log, executing the operation indicated by the difference operation log on the terminal database, and performing incremental updating on the terminal database in the first terminal state. The updating method can be set according to actual requirements, and the embodiment of the disclosure is not limited.
The terminal database with the second terminal state can be understood as the terminal database after the operation indicated by the full operation log in the first snapshot information is executed; or terminal data after the operation indicated by the difference operation log is executed.
In the embodiment of the disclosure, the terminal database can be efficiently updated based on the snapshot information of the cloud database under the condition that the network is disconnected and reconnected between the terminal and the cloud server, so that the data synchronization between the cloud database and the terminal database is rapidly realized.
In one possible implementation manner, in step S15, in the case that the first cloud state does not match the first terminal state, acquiring current first snapshot information of the cloud database includes:
sending a snapshot address acquisition request to a cloud server, wherein the snapshot address acquisition request is used for acquiring a storage address of first snapshot information in a snapshot storage server;
and under the condition of receiving the storage address of the first snapshot information sent by the cloud server, acquiring the first snapshot information from the snapshot storage server according to the storage address.
In one possible implementation manner, the snapshot storage server may be configured to store snapshot information of the cloud database. It should be understood that, when the snapshot information is stored in the snapshot storage server, a storage address of the snapshot information may be generated, and by the storage address, the snapshot information pointed to by the storage address may be accurately obtained from the snapshot storage server. The first snapshot address may be a storage address of the first snapshot information in the storage server.
As described above, the first snapshot information may also be obtained by subscribing to the snapshot topic. In a possible implementation manner, the storage address of the first snapshot information may be published to a snapshot topic subscribed by the terminal, so that the storage address in the snapshot topic may be pushed to the terminal based on an MQTT protocol.
The snapshot topic can be a message queue topic for pushing a storage address, and the storage address in the snapshot topic can be a message in the snapshot topic.
In a possible implementation manner, the snapshot address acquisition request may also be sent to the cloud server through an HTTP request in a request-response mode, which is not limited in this embodiment of the present disclosure.
In a possible implementation manner, obtaining the first snapshot information from the snapshot storage server according to the storage address may include: and downloading the first snapshot information from the snapshot storage server according to the storage address. The first snapshot information may be downloaded in any known downloading manner, which is not limited in this embodiment of the disclosure.
In the embodiment of the disclosure, by receiving the first snapshot address of the first snapshot information sent by the cloud server, the snapshot information with a large data volume can be conveniently downloaded from the snapshot storage server based on the snapshot address, so that the data transmission efficiency in the data synchronization process is improved.
In a possible implementation manner, the cloud server may further directly publish the first snapshot information to a snapshot topic subscribed by the terminal, so that in step S15, in a case that the first cloud state does not match the first terminal state, acquiring the current first snapshot information of the cloud database may include: and under the condition that the first cloud state is not matched with the first terminal state, directly acquiring first snapshot information from the subscribed snapshot theme. By the method, the first snapshot information of the cloud database can be quickly acquired.
In view of the above, since the snapshot of the whole operation log may be performed according to a certain time period, there may be a case where the operation log newly added to the cloud database is not backed up in the first snapshot information, and thus the terminal database updated based on the first snapshot information may not be synchronized with the cloud database.
In view of that the data size of the operation log not backed up in the first snapshot information is not large, in order to quickly synchronize the terminal database and the cloud database, in a possible implementation manner, the method further includes:
step S17: judging whether the second terminal state is matched with the first cloud state;
step S18: under the condition that the second terminal state is not matched with the first cloud state, sending a difference log obtaining request to a cloud server, wherein the difference log obtaining request is used for obtaining a difference operation log corresponding to the first cloud state;
step S19: and under the condition of receiving the difference operation log sent by the cloud server, updating the terminal database in the second terminal state according to the difference operation log to obtain a terminal database in a third terminal state, wherein the third terminal state is the same as the first cloud state.
In step S17, it is determined whether the second terminal state matches the first cloud state, and the above-mentioned manner of determining whether the first cloud state matches the first terminal state may be adopted, which is not described herein again.
In a possible implementation manner, the difference log obtaining request may include a log identifier representing the state of the second terminal and a log identifier representing the state of the first cloud terminal, so that the cloud server determines the difference operation log according to the log identifier representing the state of the second terminal and the log identifier representing the state of the first cloud terminal, and returns the difference operation log to the terminal.
In one possible implementation manner, the difference operation log corresponding to the first cloud state may include: the operation log between the first snapshot information and the operation log representing the first cloud state, and the operation log representing the first cloud state. For example, as described above, the operation logs may be distinguished by the log identifier, and if the log identifier of the latest operation log in the first snapshot information is 0200 and the log identifier of the operation log representing the first cloud state is 0213, the difference operation log includes the operation logs with the log identifiers 0201 to 0213.
In a possible implementation manner, updating the terminal database of the second terminal state according to the difference operation log to obtain a terminal database with a third terminal state may include: and executing the operation indicated by the difference operation log on the terminal database to obtain the terminal database with the third terminal state.
In a possible implementation manner, there may also be a case that the second terminal state is matched with the first cloud state, and at this time, it may be considered that an operation log newly added to the cloud database portion is backed up in the first snapshot information, in this case, the operation log in the target topic may be directly obtained without performing the step S18 of obtaining the difference operation log, and the terminal database in the second terminal state may be updated according to the operation log.
In the embodiment of the disclosure, under the condition that part of newly added operation logs in the cloud database are not backed up in the first snapshot information, the difference operation logs can be acquired to efficiently realize data synchronization, so that the data consistency is ensured.
In consideration, the terminal device may also have a scenario of starting communication connection after shutdown, starting communication connection for the first time, and the like, where a time interval between shutdown and startup is usually long, for example, an interval between stop operation and start operation of an intelligent terminal on a bus may be many hours. These situations may be considered as situations in which a communication connection is initiated between the terminal and the cloud server. It should be appreciated that in such cases, the amount of data that is typically synchronized is relatively large. In one possible implementation, the method may further include:
step S21: under the condition that communication connection is started between the terminal and the cloud server, sending a snapshot theme subscription request to the cloud server, wherein the snapshot theme subscription request is used for subscribing a snapshot theme of the cloud server so as to acquire second snapshot information of a cloud database through the snapshot theme;
and step S22, updating the terminal database in the first terminal state according to the acquired second snapshot information to obtain a terminal database in a fourth terminal state.
In a possible implementation manner, the snapshot topic may be subscribed in step S21 in the case of the terminal device starting, or in the case of the terminal device starting a communication connection with the cloud server, so that the cloud server is aware of the terminal access.
As described above, the snapshot information may be stored in the snapshot storage server, and in a possible implementation manner, the cloud server may publish the storage address of the second snapshot information to a snapshot topic subscribed by the terminal, and the terminal may obtain the storage address of the second snapshot information in the snapshot topic, and then the terminal may download the second snapshot information from the snapshot storage server according to the obtained storage address of the second snapshot information.
As described above, the cloud server can also directly issue snapshot information to the snapshot topic. After the terminal subscribes the snapshot theme, the cloud server publishes the second snapshot information to the snapshot theme, so that the terminal can directly acquire the second snapshot information from the snapshot theme.
It should be understood that the current second snapshot information of the cloud database and the current first snapshot information of the cloud database may refer to snapshot information of the cloud database in different scenes or at different time points.
In a possible implementation manner, updating the terminal database in the first terminal state according to the obtained second snapshot information to obtain a terminal database in a fourth terminal state may include: and executing the operation indicated by the full operation log in the second snapshot information so as to fully update the terminal database in the first terminal state and obtain the terminal database in the fourth terminal state.
In the embodiment of the disclosure, under the condition that the terminal and the cloud server start communication connection, the second snapshot information is acquired by subscribing the snapshot theme to perform full update, so that the terminal database can be efficiently synchronized to the same state as the cloud database as much as possible, the number of access requests is reduced, and the data synchronization efficiency is improved.
In a possible implementation manner, after the step S22 updates the terminal database in the first terminal state according to the obtained second snapshot information, and obtains a terminal database in a fourth terminal state, the method may further include:
step S23: sending a target theme subscription request to a cloud server to subscribe a target theme in the cloud server;
step S24: under the condition that a second operation log in a target theme sent by the cloud server is received, judging whether the second operation log is matched with a terminal database of a fourth terminal state;
step S25: under the condition that the second operation log is not matched with the terminal database of the fourth terminal state, sending an interval log obtaining request to the cloud server, wherein the interval log obtaining request is used for obtaining the interval operation log between the second operation log and the second snapshot information;
step S26: under the condition that the interval operation logs sent by the cloud server are received, the terminal database is updated according to the interval operation logs and the second operation logs, and the terminal database with a fifth terminal state is obtained, wherein the fifth terminal state is the same as the second cloud state of the cloud database.
In step S23, the target topic of the cloud server may be subscribed, so that the operation log in the target topic is pushed to the terminal by the cloud server based on the MQTT protocol.
It is considered that the terminal database updated by the second snapshot information in the above steps S21 to S22 may not be synchronized with the cloud database, or there may be an interval operation log between the second snapshot information and the second operation log. It is determined whether the second operation log matches the terminal database of the fourth terminal status through step S24, and it is known whether there is an operation log interval between the second snapshot information and the second operation log.
In a possible implementation manner, in step S24, it is determined whether the second operation log matches with the terminal database in the fourth state, and it may be determined whether the log identifier of the second operation log and the log identifier representing the fourth terminal state are consecutive in sequence. If the discontinuity is considered as a mismatch; if consecutive can be considered matching.
In a possible implementation manner, in step S25, the interval log obtaining request may include a log identifier of the second operation log and a log identifier representing the state of the fourth terminal, so that the cloud server determines the interval operation log according to the log identifier of the second operation log and the log identifier representing the state of the fourth terminal.
It should be understood that, since the second operation log has been received in step S24, the interval operation log may include an operation log between the second operation log and the second snapshot information.
In a possible implementation manner, there may be a case where the second operation log matches with the terminal database in the fourth state, at this time, it may be considered that there is no interval between the full operation log of the second snapshot information and the second operation log, or that the full operation log of the second snapshot information and the second operation log are continuous. In this case, the operation indicated by the second operation log may be directly performed without performing step S25 to acquire the interval operation log, and the terminal database of the fourth terminal state may be updated.
In a possible implementation manner, in step S27, the incrementally updating the terminal database according to the interval operation log and the second operation log to obtain the terminal database with the sixth log identifier may include: and performing the operation indicated by the interval operation log on the terminal database, and performing the operation indicated by the second operation log to obtain the terminal database with the sixth log identifier. The terminal database having the sixth log identifier may be understood as the terminal database after performing the operation indicated by the second operation log.
In the embodiment of the disclosure, by subscribing the target topic and obtaining the interval operation log, the interval operation log between the full operation log of the second snapshot information and the second operation log can be effectively obtained, so that the interval operation log is completed, and the consistency of data synchronization is ensured.
In consideration of the above, in some scenarios, the user may further perform operations such as addition, deletion, modification, and check on the terminal database, and in this case, the operations directed to the terminal database may be synchronized to the cloud database of the cloud server.
In one possible implementation, the method further includes:
and responding to the operation of a terminal database local to the terminal, and sending a data updating request to the cloud server, wherein the data updating request is used for indicating that the cloud database is updated correspondingly to the operation.
The operation of the terminal database local to the terminal may include: at least one of adding, deleting, and modifying.
In a possible implementation manner, the data update request is sent to the cloud, and the data update request can be implemented through an HTTP protocol or an MQTT protocol. It should be understood that if the method is implemented by using the MQTT protocol, the terminal in this manner may be understood as a publisher of the message, and the cloud server may be a subscriber of the message.
The data updating request can include an operation log corresponding to the operation of the terminal database, so that the cloud server can execute the operation indicated by the operation log, namely, the cloud database is updated correspondingly to the operation.
As described above, the plurality of terminals accessing the cloud server may include a plurality of terminals, and it should be understood that, after the cloud database is updated corresponding to the operation, the operation log corresponding to the operation may be pushed to other accessed terminals by the data synchronization method in the embodiment of the present disclosure, so as to implement data synchronization with terminal data of other terminals.
In the embodiment of the disclosure, the updating operation can be synchronized to the cloud database under the condition that the user performs the updating operation on the local terminal data of the terminal, so that the data consistency between the terminal database and the cloud database is ensured.
Fig. 2 is a flowchart illustrating a data synchronization method according to an embodiment of the present disclosure, where the method is applied to a cloud server, and as shown in fig. 2, the data synchronization method includes:
in step S31, in a case where there is an operation for the cloud database, determining a first operation log corresponding to the operation for the cloud database;
in step S32, the first operation log is published to the target topic of the cloud server, and the first operation log in the target topic is sent to the terminal subscribed to the target topic, so that the local terminal database of the terminal is updated according to the first operation log.
As described above, the communication connection is established between the terminal and the cloud server through the message queue telemetry transport protocol MQTT. By the mode, data synchronization in a message publishing/subscribing mode can be realized.
In a possible implementation manner, the cloud server may provide a series of interfaces to enable a user to query a data synchronization state, and perform operations such as adding, deleting, modifying, and checking on the cloud database.
In a possible implementation manner, a structured query language (SQL statement) may be sent to the cloud database in a remote control manner, so as to perform operations such as adding, deleting, modifying, searching and the like on the cloud database; as described above, the operation of the terminal database local to the terminal may be synchronized to the cloud database, that is, the operation indicated by the data update request is performed on the cloud database, so as to update the cloud database. Based on this, in step S31, the operation on the cloud database exists, which may refer to the operation on the cloud database in any of the above manners.
In a possible implementation manner, in step S31, the determining the first operation log corresponding to the operation on the cloud database may be abstracting the operation on the cloud database into the first operation log, or recording the operation on the cloud database in the form of a log to generate the first operation log.
The log identifier may be added to the generated first operation log according to the chronological order of the generation of the first operation log. The log identifier may be a timestamp, may be a serial number (e.g., 001,002), may be any form of character string, as long as the generation order of the first operation log can be characterized, and the embodiment of the present disclosure is not limited thereto.
As described above, the cloud server may be provided with MQTT broker service (MQTT broker). In a possible implementation manner, in step S32, the first oplog may be published to a target topic subscribed by the terminal through the MQTT proxy service, and is set to be a reserved message, that is, the published first oplog may be reserved in the target topic by using a message reservation mechanism of the MQTT protocol.
It should be understood that, when the first operation log is published on the target topic, the original operation log on the target topic may be updated in an overlay manner, and the first operation log in the target topic is the current latest operation log in the cloud database.
It is known that MQTT is a message transport protocol based on a message publish/subscribe mode. The message publish/subscribe mode may be understood as a mode in which a message publisher publishes a message to a specific message queue topic, and a plurality of message subscribers may receive messages in the message queue topic after subscribing to the message queue topic. Based on this, the target topic may be a message queue topic for pushing oplogs, and an oplog in the target topic may be understood as a message in the target topic.
As described above, the terminal may include a plurality of terminals, and in step S32, the first operation log is sent to the terminals subscribed to the target topic, which may be to all the terminals subscribed to the target topic. Through the mode, all the terminal devices subscribing the target theme can receive the first operation log sent by the cloud server, so that a large number of terminals can be supported to access, access pressure cannot be brought to the cloud server, and the expandability is high.
The terminal updates the local terminal database of the terminal according to the first operation log to obtain the terminal database with the first terminal state, which may refer to the data synchronization method in the embodiment of the present disclosure and is not described herein again.
In one possible implementation manner, the cloud database includes one or more synchronization groups, and each synchronization group corresponds to a different target topic. Each synchronization group may include part data in the cloud database, for example, all people of a company are a database, a plurality of departments exist under the company, and people of each department may be divided into one synchronization group. Through this mode, can divide the many parts in whole high in the clouds database and synchronize respectively, compare in carrying out data synchronization to whole high in the clouds database, the data bulk that will synchronize in every synchronization group will be little to improve synchronous efficiency.
In a possible implementation manner, the cloud database may be a maria db database (which is a relational database), a TiDB database (which is an open-source distributed relational database), a Cassandra database (which is an open-source distributed non-relational database system), and the like, which is not limited to this embodiment of the disclosure. The storage location of the cloud database in the cloud server can be determined according to actual needs, and the embodiment of the disclosure is not limited.
In the embodiment of the disclosure, under the condition that the communication connection exists between the terminal and the cloud server and the terminal subscribes the target topic, the cloud server can push the first operation log in the target topic to the terminal subscribing the target topic to update the terminal database, and the communication connection established between the terminal and the cloud server through the MQTT protocol, so that data synchronization of a publish/subscribe mode can be efficiently realized in an unstable network based on the MQTT protocol, and meanwhile, the consistency of data can be ensured, so that the cloud server can access a large number of terminals, and the expandability is high.
In one possible implementation, the method further includes:
under the condition that a state acquisition request sent by a terminal is received, a first cloud state of a cloud database is sent to the terminal, so that the terminal updates the terminal database based on the first cloud state, wherein the first cloud state is the current database state of the cloud database.
As described above, the status obtaining request is used to obtain a current first cloud status of the cloud database, and is triggered when a predetermined synchronization condition is satisfied. The terminal updates the terminal database based on the first cloud state, which can refer to the data synchronization method in the embodiments of the present disclosure and is not described herein again.
In the embodiment of the disclosure, the current first cloud state of the cloud database can be sent to the terminal under the condition that the state acquisition request is received, so that the terminal can conveniently judge whether to update the terminal database by acquiring the snapshot information.
As described above, the terminal may send a snapshot address obtaining request to the cloud for obtaining the storage address of the first snapshot information, and in a possible implementation manner, the method further includes:
and under the condition of receiving a snapshot address acquisition request sent by the terminal, sending a storage address of the first snapshot information to the terminal so that the terminal downloads the first snapshot information from a snapshot storage server according to the storage address of the first snapshot information and updates a terminal database according to the first snapshot information, wherein the snapshot storage server is used for storing the snapshot information of the cloud database.
As described above, the snapshot address obtaining request is used to obtain the storage address of the first snapshot information in the snapshot storage server. The snapshot storage server may be configured to store snapshot information of the cloud database. It should be understood that, when the snapshot information is stored in the snapshot storage server, a storage address of the snapshot information may be generated, and the snapshot information pointed to by the storage address may be accurately obtained from the snapshot storage server through the storage address.
As described above, the terminal may send a snapshot address acquisition request to the cloud server through the HTTP request, or may acquire the storage address of the first snapshot information in a manner of subscribing to the snapshot topic. The cloud server can publish the storage address of the first snapshot information to a snapshot topic subscribed by the terminal, so that the storage snapshot address in the snapshot topic can be pushed to the terminal based on an MQTT protocol under the condition that a snapshot address acquisition request sent by the terminal is received. The snapshot topic can be a message queue topic for pushing a storage address, and the storage address in the snapshot topic can be a message in the snapshot topic.
The terminal obtains the first snapshot information from the snapshot storage server according to the storage address of the first snapshot information, and updates the terminal database according to the first snapshot information, which may refer to the data synchronization method in the embodiment of the present disclosure, and details are not described here.
In the embodiment of the disclosure, the terminal can conveniently download the first snapshot information with a large data volume from the snapshot storage server based on the storage address by sending the storage address of the first snapshot information to the terminal, so that the data transmission efficiency in the data synchronization process is improved.
In one possible implementation, the method further includes:
and under the condition of receiving a difference log acquisition request sent by the terminal, sending a difference operation log corresponding to the first cloud state of the cloud database to the terminal, so that the terminal updates the terminal database according to the difference operation log.
As described above, the difference log obtaining request may include a log identifier representing the state of the second terminal and a log identifier representing the state of the first cloud. Therefore, under the condition that a difference log obtaining request sent by the terminal is received, the difference operation log can be determined according to the log mark representing the second terminal state and the log mark representing the first cloud state, and the difference operation log is sent to the terminal.
As described above, the difference operation log corresponding to the first cloud state may include: the operation log between the first snapshot information and the operation log representing the first cloud state, and the operation log representing the first cloud state.
In one possible implementation, the difference operation log is obtained from a log library that is operable to store operation logs. The log library may be any type of database, such as a maria db database, a TiDB database, a Cassandra database, etc., and the disclosed embodiment is not limited thereto. The storage location of the log library in the cloud server is not limited in the embodiments of the present disclosure.
The terminal updates the terminal database according to the difference operation log, which may refer to the data synchronization method in the embodiment of the present disclosure, and is not described herein again.
In the embodiment of the disclosure, the difference operation log can be quickly returned to the terminal under the condition of receiving the difference log acquisition request sent by the terminal, so that data synchronization is efficiently realized, and data consistency is ensured.
In one possible implementation, the method further includes:
under the condition that a snapshot theme subscription request sent by a terminal is received, determining a snapshot theme subscribed by the terminal, and publishing second snapshot information of a cloud database or a storage address of the second snapshot information to the snapshot theme;
under the condition that a target theme subscription request sent by a terminal is received, determining a target theme subscribed by the terminal, and publishing a second operation log of a cloud database to the target theme;
and under the condition of receiving an interval log acquisition request sent by the terminal, determining an interval operation log between the second operation log and the second snapshot information, and sending the interval operation log to the terminal.
As described above, in a case where the terminal is started up, or in a case where the terminal is started up to perform communication connection with the cloud server, the snapshot theme subscription request may be sent to the cloud server, so that the cloud server knows the terminal access and subscribes to the snapshot theme.
In a possible implementation manner, the snapshot topic subscription request may include a snapshot topic to which the terminal is subscribed, so that the cloud server determines the snapshot topic subscribed by the terminal when receiving the snapshot topic subscription request, and the second snapshot information or the storage address of the second snapshot information in the cloud database is published to the snapshot topic, so that the terminal obtains the second snapshot information or the storage address of the second snapshot information from the snapshot topic.
In a possible implementation manner, the target topic subscription request may include a target topic subscribed by the terminal, so that the cloud server may determine the target topic subscribed by the terminal, and publish the second operation log of the cloud database to the target topic, so that the terminal obtains the second operation log in the target topic, and updates the terminal database in the second operation log.
The determining of the interval operation log between the second operation log and the second snapshot information may refer to the foregoing embodiments of the present disclosure, which is not described herein again.
In the embodiment of the disclosure, by responding to the snapshot topic subscription request, the target topic subscription request and the interval log acquisition request of the terminal, sending the second snapshot information or the storage address of the second snapshot information, the second operation log of the cloud database and the interval operation log to the terminal, the terminal and the cloud database can efficiently and quickly realize consistent data synchronization under the condition that the communication connection between the terminal and the cloud server is started.
As described above, the snapshot address may be sent to the terminal by subscribing to the snapshot topic, and in a possible implementation manner, the method further includes:
according to a preset period, taking a snapshot of the current full operation log of the cloud database to obtain snapshot information;
and publishing the snapshot information to a snapshot theme subscribed by the terminal so as to send the snapshot information to the terminal through the snapshot theme.
In one possible implementation, the preset period may include: an increased number of oplogs (e.g., 1000), or an interval duration (e.g., 1000 seconds). For example, every time the number of the added operation logs reaches 1000, the current full operation logs of the cloud database are snapshot; or snapshot the current full operation log of the cloud database every 1000 seconds, which is not limited in the embodiment of the present disclosure.
Fig. 3 shows a schematic diagram of generating snapshot information according to an embodiment of the present disclosure. As shown in fig. 3, Op represents an operation log, n and n +1 to m represent log identifiers of the operation log, that is, a sequence of generation of the operation log, where an Op n +1 snapshot starts to an Op m snapshot ends, and represents that the generated Op n +1 to Op m reach a certain number (e.g., 1000) or are spaced for a certain time (e.g., 1000 seconds), a snapshot is triggered to be taken on the current full-amount operation log of the cloud database, and the obtained snapshot information includes Op n +1 to Op m, so that when the terminal database is updated based on the snapshot information, the terminal database in the state of having the log identifier m can be synchronized.
As described above, snapshot information may be understood as a copy, replica, backup, etc. of a full oplog; the snapshot of the full-volume operation log can be implemented by any existing snapshot technology, and the embodiment of the present disclosure is not limited. It should be understood that, when the full-size operation log is snapshot, the effect of compressing the volume of the full-size operation log can be achieved, that is, the snapshot information generated by snapshot is smaller than the volume of the full-size operation log, so that the volume of data transmission can be reduced, and the data synchronization efficiency can be improved.
As described above, the snapshot storage server may be configured to store snapshot information of the cloud database. It should be understood that after the snapshot information is stored in the snapshot storage server, the storage address of the snapshot information in the snapshot storage server may be obtained, and the snapshot information pointed to by the storage address may be accurately obtained from the snapshot storage server through the storage address.
It should be understood that the cloud server may be a server cluster consisting of a plurality of servers. In a possible implementation manner, the snapshot storage server may be independent from the cloud server, or may belong to the cloud server, which is not limited in this embodiment of the disclosure.
In a possible implementation manner, publishing the snapshot information to the snapshot topic subscribed by the terminal may include: when the snapshot information is published on the snapshot theme, the snapshot information published on the snapshot theme before updating is covered and set as a reserved message, namely, the published snapshot information is reserved in the snapshot theme by utilizing a message reservation mechanism of an MQTT protocol; may also include: when the storage address of the snapshot information is published to the snapshot subject, the storage address published to the snapshot subject before updating is covered and set as a reserved message, namely, the published storage address is reserved in the snapshot subject by using a message reservation mechanism of the MQTT protocol.
In the embodiment of the disclosure, the snapshot information or the storage address of the snapshot information can be synchronized, so that the terminal can efficiently acquire the current latest snapshot information to update the terminal database.
In one possible implementation manner, in step S32, publishing the first operation log to the target topic of the cloud server includes: compressing the first operation log according to a preset time period; and publishing the compressed first operation log to a target subject.
In a possible implementation manner, the specific value of the time period may be set according to an actual requirement, for example, may be set to 5 seconds, and the embodiment of the present disclosure is not limited thereto. The first operation log may be compressed by any known compression technique, and the embodiment of the present disclosure is not limited thereto.
It should be understood that the number of the first operation logs in the time period may include more than one, and the first operation logs in the time period may be compressed once according to the preset time period, so as to avoid frequent calling of the compression processing flow and improve the utilization rate of the computing resource.
Of course, the compression processing may be executed once every time one first operation log is generated, and the compressed first operation log is published to the target topic, which is not limited in this embodiment of the disclosure.
In the embodiment of the disclosure, under the condition that the first operation log is generated at a relatively high frequency, at least one first operation log in a time period can be compressed and issued once, so that the processing efficiency is improved, and frequent occupation of computing resources is avoided.
In one possible implementation, the method further includes:
under the condition of receiving a data updating request sent by a terminal, updating the cloud database according to an operation indicated by the data updating request, wherein the data updating request can be triggered in response to the operation on the terminal database.
As described above, in some scenarios, the user may further perform operations such as adding, deleting, and modifying on the terminal database, and in this case, the operation on the terminal database may be synchronized to the cloud database of the cloud server.
As described above, the data update request may include an operation log of an operation on the terminal database, so that the cloud server performs the operation indicated by the operation log, that is, the operation indicated by the data update request is the operation on the terminal database.
As described above, the plurality of terminals accessing the cloud server may include a plurality of terminals, and in a possible implementation manner, after the cloud database performs the operation indicated by the data update request, the operation log corresponding to the operation indicated by the data update request may be pushed to other accessed terminals by the data synchronization method in the embodiment of the present disclosure. By the method, data synchronization between the cloud database and the plurality of terminal databases can be realized.
In the embodiment of the disclosure, the operation of the local terminal data of the terminal can be synchronized to the cloud database, so that the data consistency between the terminal database and the cloud database is ensured.
Fig. 4 shows a schematic diagram of a data synchronization method according to an embodiment of the present disclosure, as shown in fig. 4, the data synchronization method includes:
step 1: the service logic of the terminal indicates a synchronization tool package of the terminal to acquire the latest snapshot information; the synchronization tool kit is used for carrying out data synchronization with the cloud database; the service logic is used for indicating the synchronization tool packet to carry out data synchronization under the condition of meeting the preset synchronization condition (such as network disconnection and reconnection), and updating the terminal database based on the received operation log;
step 2: the synchronization tool kit sends a state acquisition request to MQTT proxy service of the cloud based on the indication of business logic so as to acquire the current cloud state of a cloud database, wherein the cloud state is represented by a log identifier of the latest operation log id;
and step 3: the MQTT proxy service returns the latest log identifier id of the operation log in the target subject to K, namely returns the cloud state of the cloud database;
and 4, step 4: under the condition that the latest log identifier id is not matched with the log identifier of the current operation log of the terminal database, namely under the condition that the cloud state is not matched with the current terminal state of the terminal database, sending a snapshot information acquisition request to a synchronous management service of the cloud;
and 5: the synchronous management service processes the snapshot information acquisition request, and returns a snapshot address of the current snapshot information and the latest log identifier id of the full operation log in the current snapshot information as N;
step 6: the synchronization toolkit downloads snapshot information from a snapshot storage service of the cloud according to the snapshot address;
and 7: downloading snapshot information from the snapshot storage service;
and 8: the synchronization toolkit transmits the downloaded snapshot information to the service logic so as to update the terminal database;
and step 9: the service logic indicates the synchronization tool package to start to acquire the operation log with the log identifier id being N + 1;
step 10: the synchronization tool packet judges whether the values of the log identifier id (N + 1) and the latest log identifier id (K) are matched or not, or whether N and K are continuous or not; under the condition that the values of the log identifier id N +1 and the latest log identifier id K are not matched, sending a difference log obtaining request to a synchronous management service, wherein the difference log obtaining request is used for obtaining a difference operation log corresponding to the log identifier id N +1 to the log identifier id K; the synchronous management service can acquire a difference operation log corresponding to the difference log acquisition request from a log library for storing the operation log;
step 11: the synchronous management service returns a difference operation log corresponding to the difference log obtaining request;
step 12: the synchronization toolkit transmits the acquired difference operation log to service logic so as to update the terminal database;
step 13: continuously acquiring an operation log from an MQTT proxy service, wherein the operation log which is pushed by a subscribed target subject from the operation log with the log identification id being K +1 is acquired;
step 14: continuously receiving an operation log pushed by the MQTT proxy service from the operation log with the log identification id being K + 1;
step 15: and the synchronization tool packet transmits the received operation log to the service logic so as to update the terminal database.
In a possible implementation manner, the MQTT proxy service may employ Kafka (a high-throughput distributed publish-subscribe messaging system) or directly employ EMQ X (an open-source, scalable, and highly-available distributed MQTT messaging server), and the embodiments of the present disclosure are not limited thereto.
In a possible implementation manner, the snapshot storage service may use MinIO (a distributed storage service software) to store the snapshot information, which is not limited to this embodiment of the present disclosure.
It should be understood that the cloud may be a server cluster composed of a plurality of servers, and in a possible implementation manner, the MQTT proxy service, the synchronization management service, and the snapshot storage service may be located in different servers, or may be located in the same server, which is not limited to this embodiment of the disclosure.
The server where the snapshot storage service is located may be referred to as a snapshot storage server, the server where the MQTT proxy service is located may be referred to as an MQTT proxy server, and the server where the synchronization management service is located may be referred to as a synchronization management server.
In one possible implementation, the log library may be used to store an operation log of the cloud database. The log library may be any type of database, such as a maria db database, a TiDB database, a Cassandra database, etc., and the disclosed embodiments are not limited thereto. The embodiment of the present disclosure does not limit the storage locations of the log library and the cloud database in the cloud server.
In a possible implementation manner, the data synchronization method may be used in a scenario where face recognition is used in a terminal device on a side, for example, in a scenario where a bus swipes a face and takes a bus, when the bus is at a station, the data synchronization method of the embodiment of the present disclosure may be utilized to synchronize the human face feature library at the cloud and the related information of the personnel to the terminal device (the terminal device on the side) on the side in a full amount, so that the bus can still swipe the face and take a bus under a weak network condition after the bus leaves the station, and the latest data synchronized in real time may also be efficiently processed, while the consistency of the data is ensured, and the data may be extended to a large number of terminal devices.
Fig. 5 shows a flowchart of an interaction between a terminal and a cloud according to an embodiment of the present disclosure. As shown in fig. 5, the interaction flow includes:
step 01: the synchronous management service confirms snapshot information to be downloaded by the terminal;
step 02: the synchronous management service informs the snapshot storage service terminal of the snapshot information to be downloaded;
step 03: the terminal requests the synchronous management service to acquire snapshot information and an operation log;
step 04: and the terminal downloads snapshot information from the snapshot storage service.
Step 05: the synchronous management service confirms that the operation log is pushed to the terminal from the operation log of the log identifier N + 1;
step 06: the synchronous management service informs the cloud database terminal of synchronous operation logs;
step 07: the synchronous management service informs the MQTT agent service to push an operation log to the terminal;
step 08: the MQTT agent service pushes an operation log to the terminal;
step 09: and transmitting the snapshot information of the cloud database to a snapshot storage service for storage.
It should be noted that the interaction flowchart shown in fig. 5 may be used to illustrate an interaction process that may occur during a data synchronization process between the cloud and the terminal, and the execution sequence of the above step 01 to step 09 is not limited in the embodiment of the present disclosure.
According to the embodiment of the disclosure, under the weak network condition, when the terminal device reconnects the cloud server, the latest operation log reserved in the MQTT proxy service is acquired, if the sequence of the latest operation log is not continuous with the sequence of the operation log of the terminal data, the latest operation log can be synchronized through snapshot, and then the synchronization is performed by acquiring the differential operation log, so that the consistency of the data is ensured.
According to the embodiment of the disclosure, based on the MQTT transmission protocol and in combination with a state machine replication mode, the data updated in real time at the cloud side can be efficiently synchronized to the terminal at the side, and the method is suitable for unstable network, ensures the consistency of the data, and has high expandability (simultaneously accesses a large number of terminal devices).
In the related art, the state machine synchronization is realized based on an HTTP protocol; the synchronization data is acquired by a request-response. The embodiment of the disclosure is based on the synchronization of the state machine realized by the MQTT protocol, and can acquire the latest snapshot and operation log more quickly by utilizing a message retention mechanism of the MQTT protocol.
According to the embodiment of the disclosure, the real-time performance of data synchronization is high, and the updating operation of each cloud database can be synchronized to the terminal database on the side in the minute level or even the second level; full and incremental updates can be supported; the method can support data synchronization under the conditions of weak networks (network interruption, network bandwidth change and the like), and can be applied to scenes such as bus face brushing and the like; the consistency of data can be ensured; the expandability is high, and the cloud side is supported to simultaneously perform data synchronization with a large number (the number is larger than 2000) of edge-end devices.
It is understood that the above-mentioned method embodiments of the present disclosure can be combined with each other to form a combined embodiment without departing from the logic of the principle, which is limited by the space, and the detailed description of the present disclosure is omitted. Those skilled in the art will appreciate that in the above methods of the specific embodiments, the specific order of execution of the steps should be determined by their function and possibly their inherent logic.
In addition, the present disclosure also provides a data synchronization apparatus, an electronic device, a computer-readable storage medium, and a program, which can be used to implement any data synchronization method provided by the present disclosure, and the corresponding technical solutions and descriptions and corresponding descriptions in the method section are not repeated.
Fig. 6 is a block diagram illustrating a data synchronization apparatus according to an embodiment of the present disclosure, as shown in fig. 6, the apparatus being applied to a terminal, the apparatus including:
the receiving module 101 is configured to receive a first operation log in a target topic sent by a cloud server when a communication connection exists between the terminal and the cloud server and the terminal has subscribed to the target topic of the cloud server;
the first updating module 102 is configured to update a local terminal database of the terminal according to the first operation log when the first operation log sent by the cloud server is received, so as to obtain a terminal database with a first terminal state; the first operation log indicates that operation aiming at a cloud database of the cloud server exists, and the terminal and the cloud server establish communication connection through a message queue telemetry transmission protocol MQTT.
In one possible implementation, the apparatus further includes: the state acquisition module is used for sending a state acquisition request to the cloud server under the condition that a preset synchronization condition is met, wherein the state acquisition request is used for acquiring a first cloud state of the cloud database, and the first cloud state represents the current database state of the cloud database; the first judgment module is used for judging whether the first cloud state is matched with the first terminal state or not under the condition that the first cloud state sent by the cloud server is received; the snapshot obtaining module is used for obtaining current first snapshot information of the cloud database under the condition that the first cloud state is not matched with the first terminal state; the second updating module is used for updating the terminal database in the first terminal state according to the acquired first snapshot information to obtain a terminal database in a second terminal state; wherein the predetermined synchronization condition includes: the time length of the communication connection interruption between the terminal and the cloud server exceeds a time threshold, and the communication connection between the terminal and the cloud server is recovered.
In one possible implementation, the apparatus further includes: the second judgment module is used for judging whether the second terminal state is matched with the first cloud state; the difference log obtaining module is used for sending a difference log obtaining request to the cloud server under the condition that the second terminal state is not matched with the first cloud state, wherein the difference log obtaining request is used for obtaining a difference operation log corresponding to the first cloud state; and the third updating module is used for updating the terminal database in the second terminal state according to the difference operation log under the condition of receiving the difference operation log sent by the cloud server to obtain the terminal database in a third terminal state, wherein the third terminal state is the same as the first cloud state.
In one possible implementation, the apparatus further includes: the snapshot theme subscription module is used for sending a snapshot theme subscription request to the cloud server under the condition that communication connection is started between the terminal and the cloud server, wherein the snapshot theme subscription request is used for subscribing a snapshot theme of the cloud server so as to obtain second snapshot information of the cloud database through the snapshot theme; and the fourth updating module is used for updating the terminal database in the first terminal state according to the acquired second snapshot information to obtain a terminal database with a fourth terminal state.
In a possible implementation manner, after the terminal database in the first terminal state is updated according to the obtained second snapshot information to obtain a terminal database in a fourth terminal state, the apparatus further includes: the target theme subscription module is used for sending a target theme subscription request to the cloud server so as to subscribe a target theme in the cloud server; the third judging module is used for judging whether a second operation log in the target theme sent by the cloud server is matched with a terminal database of the fourth terminal state or not under the condition that the second operation log is received; an interval log obtaining module, configured to send an interval log obtaining request to the cloud server when the second operation log is not matched with the terminal database in the fourth state, where the interval log obtaining request is used to obtain an interval operation log between the second operation log and the second snapshot information; and the fifth updating module is used for updating the terminal database in the fourth terminal state according to the interval operation log and the second operation log under the condition of receiving the interval operation log sent by the cloud server to obtain the terminal database in the fifth terminal state, wherein the fifth terminal state is the same as the second cloud state of the cloud database.
In one possible implementation, the apparatus further includes: the update request sending module is used for responding to an operation aiming at a terminal database local to the terminal and sending a data update request to the cloud server, wherein the data update request is used for indicating that the cloud database is updated correspondingly to the operation.
In the embodiment of the disclosure, under the condition that the communication connection exists between the terminal and the cloud server and the terminal has subscribed the target topic, the cloud server can push the first operation log in the target topic to the terminal subscribed to the target topic to update the terminal database, and the communication connection established between the terminal and the cloud server through the MQTT protocol can efficiently realize data synchronization of a publish/subscribe mode based on the MQTT protocol in an unstable network, and can simultaneously ensure the consistency of data, and can also reduce the network request times, so that the cloud server can access a large number of terminals, and the expandability is high.
Fig. 7 is a block diagram of a data synchronization apparatus according to an embodiment of the present disclosure, and as shown in fig. 7, the apparatus is applied to a cloud server, and the apparatus includes:
the determining module 301 is configured to determine, in the presence of an operation on a cloud database, a first operation log corresponding to the operation on the cloud database;
the publishing module 302 is configured to publish the first operation log to a target topic of a cloud server, and send the first operation log in the target topic to a terminal subscribed to the target topic, so that the terminal updates a terminal database local to the terminal according to the first operation log.
In one possible implementation, the apparatus further includes: the cloud state sending module is used for sending a first cloud state of the cloud database to the terminal under the condition that a state obtaining request sent by the terminal is received, so that the terminal updates the terminal database based on the first cloud state, wherein the first cloud state is the current database state of the cloud database.
In one possible implementation, the apparatus further includes: the difference log sending module is used for sending a difference operation log corresponding to a first cloud state of the cloud database to the terminal under the condition that a difference log obtaining request sent by the terminal is received, so that the terminal updates the terminal database according to the difference operation log.
In one possible implementation, the apparatus further includes: the snapshot module is used for taking a snapshot of the current full operation log of the cloud database according to a preset period to obtain snapshot information; and the snapshot publishing module is used for publishing the snapshot information to a snapshot theme subscribed by the terminal so as to send the snapshot information to the terminal through the snapshot theme.
In one possible implementation, the apparatus further includes: the cloud updating module is used for updating the cloud database according to the operation indicated by the data updating request under the condition that the data updating request sent by the terminal is received, wherein the data updating request is triggered by responding to the operation aiming at the terminal database.
In the embodiment of the disclosure, under the condition that the communication connection exists between the terminal and the cloud server and the terminal subscribes the target topic, the cloud server can push the first operation log in the target topic to the terminal subscribing the target topic to update the terminal database, and the communication connection established between the terminal and the cloud server through the MQTT protocol, so that data synchronization of a publish/subscribe mode can be efficiently realized in an unstable network based on the MQTT protocol, and meanwhile, the consistency of data can be ensured, so that the cloud server can access a large number of terminals, and the expandability is high.
In some embodiments, functions of or modules included in the apparatus provided in the embodiments of the present disclosure may be used to execute the method described in the above method embodiments, and specific implementation thereof may refer to the description of the above method embodiments, and for brevity, will not be described again here.
Embodiments of the present disclosure also provide a computer-readable storage medium having stored thereon computer program instructions, which when executed by a processor, implement the above-mentioned method. The computer readable storage medium may be a non-volatile computer readable storage medium.
An embodiment of the present disclosure further provides an electronic device, including: a processor; a memory for storing processor-executable instructions; wherein the processor is configured to invoke the memory-stored instructions to perform the above-described method.
The disclosed embodiments also provide a computer program product comprising computer readable code, which when run on a device, a processor in the device executes instructions for implementing the data synchronization method provided in any of the above embodiments.
The embodiments of the present disclosure also provide another computer program product for storing computer readable instructions, which when executed cause a computer to perform the operations of the data synchronization method provided in any of the above embodiments.
The electronic device may be provided as a terminal, server, or other form of device.
Fig. 8 illustrates a block diagram of an electronic device 800 in accordance with an embodiment of the disclosure. For example, the electronic device 800 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, or the like terminal.
Referring to fig. 8, electronic device 800 may include one or more of the following components: processing component 802, memory 804, power component 806, multimedia component 808, audio component 810, input/output (I/O) interface 812, sensor component 814, and communication component 816.
The processing component 802 generally controls overall operation of the electronic device 800, such as operations associated with display, telephone calls, data communications, camera operations, and recording operations. The processing components 802 may include one or more processors 820 to execute instructions to perform all or a portion of the steps of the methods described above. Further, the processing component 802 can include one or more modules that facilitate interaction between the processing component 802 and other components. For example, the processing component 802 can include a multimedia module to facilitate interaction between the multimedia component 808 and the processing component 802.
The memory 804 is configured to store various types of data to support operations at the electronic device 800. Examples of such data include instructions for any application or method operating on the electronic device 800, contact data, phonebook data, messages, pictures, videos, and so forth. The memory 804 may be implemented by any type or combination of volatile or non-volatile memory devices such as Static Random Access Memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic or optical disks.
The power supply component 806 provides power to the various components of the electronic device 800. The power components 806 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the electronic device 800.
The multimedia component 808 includes a screen that provides an output interface between the electronic device 800 and a user. In some embodiments, the screen may include a Liquid Crystal Display (LCD) and a Touch Panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive an input signal from a user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundary of a touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 808 includes a front facing camera and/or a rear facing camera. The front camera and/or the rear camera may receive external multimedia data when the electronic device 800 is in an operation mode, such as a shooting mode or a video mode. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
The audio component 810 is configured to output and/or input audio signals. For example, the audio component 810 includes a Microphone (MIC) configured to receive external audio signals when the electronic device 800 is in an operational mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signals may further be stored in the memory 804 or transmitted via the communication component 816. In some embodiments, audio component 810 also includes a speaker for outputting audio signals.
The I/O interface 812 provides an interface between the processing component 802 and peripheral interface modules, which may be keyboards, click wheels, buttons, etc. These buttons may include, but are not limited to: a home button, a volume button, a start button, and a lock button.
The sensor assembly 814 includes one or more sensors for providing various aspects of state assessment for the electronic device 800. For example, the sensor assembly 814 may detect an open/closed state of the electronic device 800, the relative positioning of components, such as a display and keypad of the electronic device 800, the sensor assembly 814 may also detect a change in the position of the electronic device 800 or a component of the electronic device 800, the presence or absence of user contact with the electronic device 800, orientation or acceleration/deceleration of the electronic device 800, and a change in the temperature of the electronic device 800. Sensor assembly 814 may include a proximity sensor configured to detect the presence of a nearby object without any physical contact. The sensor assembly 814 may also include a light sensor, such as a Complementary Metal Oxide Semiconductor (CMOS) or Charge Coupled Device (CCD) image sensor, for use in imaging applications. In some embodiments, the sensor assembly 814 may also include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
The communication component 816 is configured to facilitate wired or wireless communication between the electronic device 800 and other devices. The electronic device 800 may access a wireless network based on a communication standard, such as a wireless network (WiFi), a second generation mobile communication technology (2G) or a third generation mobile communication technology (3G), or a combination thereof. In an exemplary embodiment, the communication component 816 receives a broadcast signal or broadcast related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 816 further includes a Near Field Communication (NFC) module to facilitate short-range communications. For example, the NFC module may be implemented based on Radio Frequency Identification (RFID) technology, infrared data association (IrDA) technology, Ultra Wideband (UWB) technology, Bluetooth (BT) technology, and other technologies.
In an exemplary embodiment, the electronic device 800 may be implemented by one or more Application Specific Integrated Circuits (ASICs), Digital Signal Processors (DSPs), Digital Signal Processing Devices (DSPDs), Programmable Logic Devices (PLDs), Field Programmable Gate Arrays (FPGAs), controllers, micro-controllers, microprocessors or other electronic components for performing the above-described methods.
In an exemplary embodiment, a non-transitory computer-readable storage medium, such as the memory 804, is also provided that includes computer program instructions executable by the processor 820 of the electronic device 800 to perform the above-described methods.
Fig. 9 illustrates a block diagram of an electronic device 1900 in accordance with an embodiment of the disclosure. For example, the electronic device 1900 may be provided as a server. Referring to fig. 9, electronic device 1900 includes a processing component 1922 further including one or more processors and memory resources, represented by memory 1932, for storing instructions, e.g., applications, executable by processing component 1922. The application programs stored in memory 1932 may include one or more modules that each correspond to a set of instructions. Further, the processing component 1922 is configured to execute instructions to perform the above-described method.
The electronic device 1900 may also include a power component 1926 configured to perform power management of the electronic device 1900, a wired or wireless network interface 1950 configured to connect the electronic device 1900 to a network, and an input/output (I/O) interface 1958. The electronic device 1900 may operate based on an operating system, such as the Microsoft Server operating system (Windows Server), stored in the memory 1932TM) Apple Inc. of the present application based on the graphic user interface operating System (Mac OS X)TM) Multi-user, multi-process computer operating system (Unix)TM) Free and open native code Unix-like operating System (Linux)TM) Open native code Unix-like operating System (FreeBSD)TM) Or the like.
In an exemplary embodiment, a non-transitory computer readable storage medium, such as the memory 1932, is also provided that includes computer program instructions executable by the processing component 1922 of the electronic device 1900 to perform the above-described methods.
The present disclosure may be systems, methods, and/or computer program products. The computer program product may include a computer-readable storage medium having computer-readable program instructions embodied thereon for causing a processor to implement various aspects of the present disclosure.
The computer readable storage medium may be a tangible device that can hold and store the instructions for use by the instruction execution device. The computer readable storage medium may be, for example, but is not limited to, an electronic memory device, a magnetic memory device, an optical memory device, an electromagnetic memory device, a semiconductor memory device, or any suitable combination of the foregoing. More specific examples (a non-exhaustive list) of the computer readable storage medium would include the following: a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a Static Random Access Memory (SRAM), a portable compact disc read-only memory (CD-ROM), a Digital Versatile Disc (DVD), a memory stick, a floppy disk, a mechanical coding device, such as punch cards or in-groove projection structures having instructions stored thereon, and any suitable combination of the foregoing. Computer-readable storage media as used herein is not to be construed as transitory signals per se, such as radio waves or other freely propagating electromagnetic waves, electromagnetic waves propagating through a waveguide or other transmission medium (e.g., optical pulses through a fiber optic cable), or electrical signals transmitted through electrical wires.
The computer-readable program instructions described herein may be downloaded from a computer-readable storage medium to a respective computing/processing device, or to an external computer or external storage device via a network, such as the internet, a local area network, a wide area network, and/or a wireless network. The network may include copper transmission cables, fiber optic transmission, wireless transmission, routers, firewalls, switches, gateway computers and/or edge servers. The network adapter card or network interface in each computing/processing device receives computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in a computer-readable storage medium in the respective computing/processing device.
The computer program instructions for carrying out operations of the present disclosure may be assembler instructions, Instruction Set Architecture (ISA) instructions, machine-related instructions, microcode, firmware instructions, state setting data, or source or object code written in any combination of one or more programming languages, including an object oriented programming language such as Smalltalk, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The computer-readable program instructions may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider). In some embodiments, the electronic circuitry that can execute the computer-readable program instructions implements aspects of the present disclosure by utilizing the state information of the computer-readable program instructions to personalize the electronic circuitry, such as a programmable logic circuit, a Field Programmable Gate Array (FPGA), or a Programmable Logic Array (PLA).
Various aspects of the present disclosure are described herein with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the disclosure. It will be understood that each block of the flowchart illustrations and/or block diagrams, and combinations of blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer-readable program instructions.
These computer-readable program instructions may be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions/acts specified in the flowchart and/or block diagram block or blocks. These computer-readable program instructions may also be stored in a computer-readable storage medium that can direct a computer, programmable data processing apparatus, and/or other devices to function in a particular manner, such that the computer-readable medium storing the instructions comprises an article of manufacture including instructions which implement the function/act specified in the flowchart and/or block diagram block or blocks.
The computer readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other devices to cause a series of operational steps to be performed on the computer, other programmable apparatus or other devices to produce a computer implemented process such that the instructions which execute on the computer, other programmable apparatus or other devices implement the functions/acts specified in the flowchart and/or block diagram block or blocks.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of instructions, which comprises one or more executable instructions for implementing the specified logical function(s). In some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The computer program product may be embodied in hardware, software or a combination thereof. In an alternative embodiment, the computer program product is embodied in a computer storage medium, and in another alternative embodiment, the computer program product is embodied in a Software product, such as a Software Development Kit (SDK), or the like.
Having described embodiments of the present disclosure, the foregoing description is intended to be exemplary, not exhaustive, and not limited to the disclosed embodiments. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The terminology used herein is chosen in order to best explain the principles of the embodiments, the practical application, or improvements made to the technology in the marketplace, or to enable others of ordinary skill in the art to understand the embodiments disclosed herein.

Claims (15)

1. A data synchronization method is applied to a terminal and comprises the following steps:
under the condition that communication connection exists between the terminal and a cloud server and the terminal is subscribed with a target theme of the cloud server, receiving a first operation log in the target theme sent by the cloud server;
under the condition that the first operation log sent by the cloud server is received, updating a local terminal database of the terminal according to the first operation log to obtain a terminal database with a first terminal state;
the first operation log indicates that operation aiming at a cloud database of the cloud server exists, and the terminal and the cloud server establish communication connection through a message queue telemetry transmission protocol MQTT.
2. The method of claim 1, further comprising:
sending a state acquisition request to the cloud server under the condition that a preset synchronization condition is met, wherein the state acquisition request is used for acquiring a first cloud state of the cloud database, and the first cloud state represents the current database state of the cloud database;
under the condition that the first cloud state sent by the cloud server is received, judging whether the first cloud state is matched with the first terminal state;
under the condition that the first cloud state is not matched with the first terminal state, acquiring current first snapshot information of the cloud database;
updating the terminal database of the first terminal state according to the acquired first snapshot information to obtain a terminal database with a second terminal state;
wherein the predetermined synchronization condition includes: the time length of the communication connection interruption between the terminal and the cloud server exceeds a time threshold, and the communication connection between the terminal and the cloud server is recovered.
3. The method of claim 2, further comprising:
judging whether the second terminal state is matched with the first cloud state;
under the condition that the second terminal state is not matched with the first cloud state, sending a difference log obtaining request to the cloud server, wherein the difference log obtaining request is used for obtaining a difference operation log corresponding to the first cloud state;
and under the condition of receiving the difference operation log sent by the cloud server, updating the terminal database in the second terminal state according to the difference operation log to obtain a terminal database in a third terminal state, wherein the third terminal state is the same as the first cloud state.
4. The method of claim 1, further comprising:
sending a snapshot theme subscription request to the cloud server under the condition that communication connection is started between the terminal and the cloud server, wherein the snapshot theme subscription request is used for subscribing a snapshot theme of the cloud server so as to obtain second snapshot information of the cloud database through the snapshot theme;
and updating the terminal database in the first terminal state according to the acquired second snapshot information to obtain a terminal database in a fourth terminal state.
5. The method according to claim 4, wherein after the terminal database in the first terminal state is updated according to the obtained second snapshot information to obtain a terminal database in a fourth terminal state, the method further comprises:
sending a target theme subscription request to the cloud server to subscribe a target theme in the cloud server;
under the condition that a second operation log in the target theme sent by the cloud server is received, judging whether the second operation log is matched with a terminal database of the fourth terminal state;
sending an interval log obtaining request to the cloud server under the condition that the second operation log is not matched with the terminal database in the fourth state, wherein the interval log obtaining request is used for obtaining an interval operation log between the second operation log and the second snapshot information;
under the condition that an interval operation log sent by the cloud server is received, updating the terminal database in the fourth terminal state according to the interval operation log and the second operation log to obtain a terminal database in a fifth terminal state, wherein the fifth terminal state is the same as the second cloud state of the cloud database.
6. The method according to any one of claims 1-5, further comprising:
responding to an operation aiming at a terminal database local to the terminal, and sending a data updating request to the cloud server, wherein the data updating request is used for indicating that the cloud database is updated correspondingly to the operation.
7. A data synchronization method is applied to a cloud server, and the method comprises the following steps:
determining a first operation log corresponding to an operation aiming at a cloud database under the condition that the operation aiming at the cloud database exists;
and publishing the first operation log to a target theme of a cloud server, and sending the first operation log in the target theme to a terminal subscribed with the target theme so that the terminal updates a local terminal database of the terminal according to the first operation log.
8. The method of claim 7, further comprising:
under the condition that a state acquisition request sent by the terminal is received, sending a first cloud state of the cloud database to the terminal so that the terminal updates the terminal database based on the first cloud state, wherein the first cloud state is the current database state of the cloud database.
9. The method according to claim 7 or 8, characterized in that the method further comprises:
and under the condition of receiving a difference log acquisition request sent by the terminal, sending a difference operation log corresponding to a first cloud state of the cloud database to the terminal, so that the terminal updates the terminal database according to the difference operation log.
10. The method according to any one of claims 7-9, further comprising:
according to a preset period, taking a snapshot of the current full operation log of the cloud database to obtain snapshot information;
and publishing the snapshot information to a snapshot theme subscribed by the terminal so as to send the snapshot information to the terminal through the snapshot theme.
11. The method according to any one of claims 7-10, further comprising:
under the condition that a data updating request sent by the terminal is received, updating the cloud database according to the operation indicated by the data updating request, wherein the data updating request is triggered by responding to the operation of the terminal database.
12. A data synchronization device, applied to a terminal, includes:
the receiving module is used for receiving a first operation log in a target theme sent by a cloud server under the condition that the communication connection exists between the terminal and the cloud server and the terminal is subscribed with the target theme of the cloud server;
the first updating module updates a local terminal database of the terminal according to the first operation log under the condition that the first operation log sent by the cloud server is received, so that a terminal database with a first terminal state is obtained; the first operation log indicates that operation aiming at a cloud database of the cloud server exists, and the terminal and the cloud server establish communication connection through a message queue telemetry transmission protocol MQTT.
13. The utility model provides a data synchronization device, its characterized in that is applied to high in the clouds server, includes:
the determining module is used for determining a first operation log corresponding to the operation aiming at the cloud database under the condition that the operation aiming at the cloud database exists;
the publishing module is used for publishing the first operation log to a target theme of a cloud server and sending the first operation log in the target theme to a terminal subscribed with the target theme so that the terminal updates a local terminal database of the terminal according to the first operation log.
14. An electronic device, comprising:
a processor;
a memory for storing processor-executable instructions;
wherein the processor is configured to invoke the memory-stored instructions to perform the method of any of claims 1 to 11.
15. A computer readable storage medium having computer program instructions stored thereon, which when executed by a processor implement the method of any one of claims 1 to 11.
CN202110565003.XA 2021-05-24 2021-05-24 Data synchronization method and device, electronic equipment and storage medium Pending CN113177093A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110565003.XA CN113177093A (en) 2021-05-24 2021-05-24 Data synchronization method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110565003.XA CN113177093A (en) 2021-05-24 2021-05-24 Data synchronization method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN113177093A true CN113177093A (en) 2021-07-27

Family

ID=76929671

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110565003.XA Pending CN113177093A (en) 2021-05-24 2021-05-24 Data synchronization method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN113177093A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113742138A (en) * 2021-09-06 2021-12-03 深圳市云鼠科技开发有限公司 Data management method and device, electronic equipment and storage medium
CN113760581A (en) * 2021-09-09 2021-12-07 四川虹美智能科技有限公司 MQTT-based method and system for synchronizing attribute information of intelligent terminal
CN115580541A (en) * 2022-09-16 2023-01-06 荣耀终端有限公司 Information synchronization method and electronic equipment

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105159795A (en) * 2015-08-21 2015-12-16 小米科技有限责任公司 Data synchronization method, apparatus and system
CN107330035A (en) * 2017-06-26 2017-11-07 努比亚技术有限公司 Operation Log synchronous method, mobile terminal and computer-readable recording medium in a kind of database
CN108073656A (en) * 2016-11-17 2018-05-25 杭州华为数字技术有限公司 A kind of method of data synchronization and relevant device
CN110019062A (en) * 2017-08-14 2019-07-16 北京京东尚科信息技术有限公司 Method of data synchronization and system
CN110321387A (en) * 2019-07-10 2019-10-11 中国联合网络通信集团有限公司 Method of data synchronization, equipment and terminal device
CN112000737A (en) * 2020-08-14 2020-11-27 苏州浪潮智能科技有限公司 Data synchronization method, system, terminal and storage medium based on multi-cloud management
CN112417033A (en) * 2020-10-19 2021-02-26 中国科学院计算机网络信息中心 Method and system for realizing multi-node data consistency of distributed graph database
CN112612853A (en) * 2020-12-28 2021-04-06 深圳壹账通智能科技有限公司 Data processing method and device based on database cluster and electronic equipment
CN112732728A (en) * 2019-10-28 2021-04-30 北京京东尚科信息技术有限公司 Data synchronization method and system

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105159795A (en) * 2015-08-21 2015-12-16 小米科技有限责任公司 Data synchronization method, apparatus and system
CN108073656A (en) * 2016-11-17 2018-05-25 杭州华为数字技术有限公司 A kind of method of data synchronization and relevant device
CN107330035A (en) * 2017-06-26 2017-11-07 努比亚技术有限公司 Operation Log synchronous method, mobile terminal and computer-readable recording medium in a kind of database
CN110019062A (en) * 2017-08-14 2019-07-16 北京京东尚科信息技术有限公司 Method of data synchronization and system
CN110321387A (en) * 2019-07-10 2019-10-11 中国联合网络通信集团有限公司 Method of data synchronization, equipment and terminal device
CN112732728A (en) * 2019-10-28 2021-04-30 北京京东尚科信息技术有限公司 Data synchronization method and system
CN112000737A (en) * 2020-08-14 2020-11-27 苏州浪潮智能科技有限公司 Data synchronization method, system, terminal and storage medium based on multi-cloud management
CN112417033A (en) * 2020-10-19 2021-02-26 中国科学院计算机网络信息中心 Method and system for realizing multi-node data consistency of distributed graph database
CN112612853A (en) * 2020-12-28 2021-04-06 深圳壹账通智能科技有限公司 Data processing method and device based on database cluster and electronic equipment

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113742138A (en) * 2021-09-06 2021-12-03 深圳市云鼠科技开发有限公司 Data management method and device, electronic equipment and storage medium
CN113760581A (en) * 2021-09-09 2021-12-07 四川虹美智能科技有限公司 MQTT-based method and system for synchronizing attribute information of intelligent terminal
CN115580541A (en) * 2022-09-16 2023-01-06 荣耀终端有限公司 Information synchronization method and electronic equipment
CN115580541B (en) * 2022-09-16 2023-10-20 荣耀终端有限公司 Information synchronization method and electronic equipment

Similar Documents

Publication Publication Date Title
WO2018219178A1 (en) Data synchronization method and apparatus, server, and storage medium
CN113177093A (en) Data synchronization method and device, electronic equipment and storage medium
CN113259161B (en) Application management method and device, electronic equipment and storage medium
CN112003893B (en) Resource downloading method and device
US11184305B2 (en) Method and apparatus for updating group member data, and terminal, system and storage medium
CN106713127B (en) Method and device for acquiring and processing instant chat records
EP2950486B1 (en) Method and device for managing instant message
CN110737415A (en) Screen sharing method and device, computer equipment and storage medium
CN111259246A (en) Information pushing method and device, electronic equipment and storage medium
CN113596175A (en) Scene synchronization method, terminal, server and system
WO2023024435A1 (en) Device registration method and apparatus, electronic device, storage medium, and computer program product
CN112583896B (en) Session management method, session management device, electronic equipment, session management server and storage medium
CN112925788A (en) Data set management method, system, device, electronic equipment and storage medium
CN115113787B (en) Message processing method, device, equipment and medium
CN107483605B (en) File downloading method and device and storage medium
CN113691526A (en) Pushing method, device, system, equipment and medium based on WebRTC
CN113111123A (en) Cluster service calling method and device, electronic equipment, storage medium and product
CN109948012B (en) Serial number generation method and device and storage medium
CN110493298B (en) Information synchronization method and device
CN110611839B (en) Interactive content processing method, device and storage medium
CN112966147A (en) File access method and device, electronic equipment and storage medium
CN112131999A (en) Identity determination method and device, electronic equipment and storage medium
CN111526084A (en) Information processing method, device, equipment and storage medium
CN115794853B (en) Updating method and device of government affair data resource catalog, electronic equipment and medium
CN114143260B (en) Data transmission system and method, electronic device and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination