Data synchronization method and device, electronic device and storage medium

By using the MQTT protocol for data synchronization in IoT scenarios, the problem of data update under unstable network conditions is solved, and data consistency and cloud server scalability are achieved.

CN113177093BActive Publication Date: 2024-09-20SENSETIME INT PTE LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110565003.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-05-24
Publication Date
2024-09-20
Estimated Expiration
2041-05-24

AI Technical Summary

Technical Problem

Existing technology cannot effectively synchronize data updates in IoT scenarios, especially when the network is unstable, it is difficult to ensure data consistency, and the scalability of cloud servers is not high.

Method used

By establishing a communication connection with the MQTT protocol between the terminal and the cloud server, the message queue telemetry transmission protocol is used to push and subscribe to operation logs to achieve asynchronous synchronization of data, and snapshot information is used for efficient updates when the network is disconnected and reconnected.

Benefits of technology

It achieves efficient data synchronization in unstable networks, ensures data consistency, improves the scalability of cloud servers, and can support the access of a large number of terminal devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113177093B
    Figure CN113177093B
Patent Text Reader

Abstract

The present disclosure relates to a data synchronization method and device, an electronic device and a storage medium, the method comprising: when there is a communication connection between the terminal and a cloud server, and the terminal has subscribed to a target topic of the cloud server, receiving a first operation log in a target topic sent by the cloud server; when the first operation log sent by the cloud server is received, updating a terminal database local to the terminal according to the first operation log to obtain a terminal database with a first terminal state; wherein the first operation log indicates that there is an operation on the cloud database of the cloud server, and a communication connection is established between the terminal and the cloud server through the message queue telemetry transmission protocol MQTT. The embodiments of the present disclosure can achieve consistency in data synchronization.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to a data synchronization method and device, an electronic device, and a storage medium. Background Art

[0002] With the development of the Internet of Things and the continuous improvement of the computing and storage capabilities of various terminal devices, more and more task processing (such as face recognition) is transferred from being sent to cloud servers to be executed on terminal devices with computing and storage capabilities, thereby reducing the delay in network request responses and improving task processing efficiency. To process tasks on terminal devices, it is usually necessary to synchronize data stored on cloud servers to the terminal devices, where the data may be, for example, facial features used for face recognition comparison and identity information of people (name, gender, etc.).

[0003] Usually, manual copying is used, but this method is not suitable for databases with frequently changing data. It can also be done through state machine replication combined with the Hypertext Transfer Protocol HTTP, but this method requires a stable network. In the IoT scenario, the network is not stable, and data synchronization through the HTTP protocol is not applicable. It is impossible to synchronize and update data efficiently while ensuring data consistency. When there are many terminal devices, a large number of HTTP requests will put pressure on the cloud server, and the scalability is not high. Summary of the invention

[0004] The present disclosure proposes a data synchronization technical solution.

[0005] According to one aspect of the present disclosure, a data synchronization method is provided, which is applied to a terminal, including: when there is a communication connection between the terminal and a cloud server, and the terminal has subscribed to a target topic of the cloud server, receiving a first operation log in the target topic sent by the cloud server; when the first operation log sent by the cloud server is received, updating the terminal database local to the terminal according to the first operation log to obtain a terminal database with a first terminal state; wherein the first operation log indicates that there is an operation on the cloud database of the cloud server, and a communication connection is established between the terminal and the cloud server via the message queue telemetry transmission protocol MQTT. In this way, data consistency can be guaranteed, and the number of network requests can be reduced, so that the cloud server can access a large number of terminals, and the scalability is high.

[0006] In a possible implementation, the method further includes: sending a status acquisition request to the cloud server when a predetermined synchronization condition is met, the status acquisition request is used to acquire a first cloud state of the cloud database, the first cloud state representing the current database state of the cloud database; when receiving the first cloud state sent by the cloud server, determining whether the first cloud state matches the first terminal state; when the first cloud state does not match the first terminal state, acquiring the 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 duration of the interruption of 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 restored. In this way, when there is a network disconnection and reconnection between the terminal and the cloud server, the terminal database can be efficiently updated based on the snapshot information of the cloud database to quickly realize data synchronization between the cloud database and the terminal database.

[0007] In a possible implementation, the method further includes: determining whether the second terminal state matches the first cloud state; in the case where the second terminal state does not match the first cloud state, sending a difference log acquisition request to the cloud server, the difference log acquisition request is used to obtain the difference operation log corresponding to the first cloud state; in the case of receiving the difference operation log sent by the cloud server, 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, and the third terminal state is the same as the first cloud state. In this way, when there are some newly added operation logs in the cloud database that are not backed up in the first snapshot information, the difference operation log can be obtained to efficiently achieve data synchronization to ensure data consistency.

[0008] In a possible implementation, the method further includes: when a communication connection is initiated between the terminal and the cloud server, sending a snapshot topic subscription request to the cloud server, wherein the snapshot topic subscription request is used to subscribe to the snapshot topic of the cloud server to obtain the second snapshot information of the cloud database through the snapshot topic; based on the obtained second snapshot information, the terminal database of the first terminal state is updated to obtain a terminal database with a fourth terminal state. In this way, when a communication connection is initiated between the terminal and the cloud server, the second snapshot information can be obtained by subscribing to the snapshot topic for full update, and the terminal database can be efficiently synchronized to the same state as the cloud database as much as possible, reducing the number of request accesses and improving data synchronization efficiency.

[0009] In a possible implementation, after updating the terminal database of the first terminal state according to the acquired second snapshot information to obtain the terminal database with the fourth terminal state, the method further includes: sending a target topic subscription request to the cloud server to subscribe to the target topic in the cloud server; in the case of receiving the second operation log in the target topic sent by the cloud server, judging whether the second operation log matches the terminal database of the fourth terminal state; in the case of the second operation log not matching the terminal database of the fourth state, sending an interval log acquisition request to the cloud server, the interval log acquisition request is used to obtain the interval operation log between the second operation log and the second snapshot information; in the case of receiving the interval operation log sent by the cloud server, according to the interval operation log and the second operation log, updating the terminal database of the fourth terminal state to obtain a terminal database with a fifth terminal state, the fifth terminal state being the same as the second cloud state of the cloud database. In this way, by subscribing to the target topic and obtaining the interval operation log, the operation log between the full operation log of the second snapshot information and the second operation log can be effectively obtained, thereby completing the interval operation log and ensuring the consistency of data synchronization.

[0010] In a possible implementation, the method further includes: in response to an operation on a local terminal database of the terminal, sending a data update request to the cloud server, wherein the data update request is used to instruct the cloud database to be updated corresponding to the operation. In this way, the update operation on the terminal database can be synchronized to the cloud database, thereby ensuring data consistency between the terminal database and the cloud database.

[0011] According to one aspect of the present disclosure, a data synchronization method is provided, which is applied to a cloud server, including: in the case of an operation on a cloud database, determining a first operation log corresponding to the operation on the cloud database; publishing the first operation log to a target topic of the cloud server, and sending the first operation log in the target topic to a terminal that has subscribed to the target topic, so that the terminal updates the local terminal database of the terminal according to the first operation log. In this way, data synchronization in a publish / subscribe mode can be efficiently implemented based on the MQTT protocol in an unstable network, and data consistency can be guaranteed at the same time, so that the cloud server can access a large number of terminals, with high scalability.

[0012] In a possible implementation, the method further includes: upon receiving a status acquisition request sent by the terminal, sending a first cloud status of the cloud database to the terminal, so that the terminal updates the terminal database based on the first cloud status, wherein the first cloud status is the current database status of the cloud database.

[0013] In a possible implementation, the method further includes: upon 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.

[0014] In a possible implementation, the method further includes: taking a snapshot of the current full operation log of the cloud database according to a preset period to obtain snapshot information; publishing the snapshot information to a snapshot topic subscribed by the terminal to send the snapshot information to the terminal via the snapshot topic.

[0015] In a possible implementation, the method further includes: upon receiving a data update request sent by the terminal, updating the cloud database according to an operation indicated by the data update request, wherein the data update request is triggered in response to an operation on the terminal database.

[0016] According to one aspect of the present disclosure, there is provided a data synchronization device, which is applied to a terminal and includes: a receiving module, which receives a first operation log in the target topic sent by the cloud server when a communication connection exists between the terminal and a cloud server and the terminal has subscribed to the target topic of the cloud server; a first updating module, which updates a terminal database local to 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; wherein the first operation log indicates the existence of an operation on the cloud database of the cloud server, and a communication connection is established between the terminal and the cloud server via the message queue telemetry transmission protocol MQTT.

[0017] In a possible implementation, the device also includes: a state acquisition module, which is used to send a state acquisition request to the cloud server when a predetermined synchronization condition is met, and the state acquisition request is used to obtain a first cloud state of the cloud database, and the first cloud state represents the current database state of the cloud database; a first judgment module, which is used to determine whether the first cloud state matches the first terminal state when the first cloud state sent by the cloud server is received; a snapshot acquisition module, which is used to obtain the current first snapshot information of the cloud database when the first cloud state does not match the first terminal state; a second update module, which is used to update 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 duration of the interruption of 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 restored.

[0018] In a possible implementation, the device also includes: a second judgment module, used to judge whether the second terminal state matches the first cloud state; a difference log acquisition module, used to send a difference log acquisition request to the cloud server when the second terminal state does not match the first cloud state, and the difference log acquisition request is used to obtain the difference operation log corresponding to the first cloud state; a third update module, used to update the terminal database of the second terminal state according to the difference operation log when receiving the difference operation log sent by the cloud server, and obtain a terminal database with a third terminal state, and the third terminal state is the same as the first cloud state.

[0019] In a possible implementation, the device also includes: a snapshot topic subscription module, which is used to send a snapshot topic subscription request to the cloud server when a communication connection is initiated between the terminal and the cloud server, wherein the snapshot topic subscription request is used to subscribe to the snapshot topic of the cloud server to obtain the second snapshot information of the cloud database through the snapshot topic; a fourth update module, which is used to update the terminal database of the first terminal state according to the obtained second snapshot information to obtain a terminal database with a fourth terminal state.

[0020] In a possible implementation, after the terminal database of the first terminal state is updated according to the acquired second snapshot information to obtain the terminal database with the fourth terminal state, the device further includes: a target topic subscription module, which is used to send a target topic subscription request to the cloud server to subscribe to the target topic in the cloud server; a third judgment module, which is used to determine whether the second operation log matches the terminal database of the fourth terminal state when receiving the second operation log in the target topic sent by the cloud server; an interval log acquisition module, which is used to send an interval log acquisition request to the cloud server when the second operation log does not match the terminal database of the fourth state, and the interval log acquisition request is used to obtain the interval operation log between the second operation log and the second snapshot information; a fifth update module, which is used to update the terminal database of the fourth terminal state according to the interval operation log and the second operation log when receiving the interval operation log sent by the cloud server to obtain a terminal database with a fifth terminal state, and the fifth terminal state is the same as the second cloud state of the cloud database.

[0021] In a possible implementation, the device also includes: an update request sending module, which is used to send a data update request to the cloud server in response to an operation on a terminal database local to the terminal, and the data update request is used to indicate an update of the cloud database corresponding to the operation.

[0022] According to one aspect of the present disclosure, there is provided a data synchronization device, which is applied to a cloud server and includes: a determination module, which is used to determine a first operation log corresponding to an operation on a cloud database when there is an operation on the cloud database; and a publishing module, which is used to publish the first operation log to a target topic of the cloud server, and send the first operation log in the target topic to a terminal that has subscribed to the target topic, so that the terminal updates a terminal database local to the terminal according to the first operation log.

[0023] In a possible implementation, the device also includes: a cloud status sending module, which is used to send the first cloud status of the cloud database to the terminal when receiving a status acquisition request sent by the terminal, so that the terminal updates the terminal database based on the first cloud status, wherein the first cloud status is the current database status of the cloud database.

[0024] In one possible implementation, the device also includes: a difference log sending module, which is used to send a difference operation log corresponding to the first cloud state of the cloud database to the terminal when a difference log acquisition request sent by the terminal is received, so that the terminal updates the terminal database according to the difference operation log.

[0025] In a possible implementation, the device also includes: a snapshot module, which is used to take a snapshot of the current full operation log of the cloud database according to a preset period to obtain snapshot information; a snapshot publishing module, which is used to publish the snapshot information to the snapshot topic subscribed by the terminal, so as to send the snapshot information to the terminal through the snapshot topic.

[0026] In a possible implementation, the device also includes: a cloud update module, which is used to update the cloud database according to the operation indicated by the data update request when a data update request sent by the terminal is received, and the data update request is triggered in response to the operation on the terminal database.

[0027] According to one aspect of the present disclosure, an electronic device is provided, comprising: a processor; and a memory for storing processor-executable instructions; wherein the processor is configured to call the instructions stored in the memory to execute the above method.

[0028] According to one aspect of the present disclosure, a computer-readable storage medium is provided, on which computer program instructions are stored, and the computer program instructions implement the above method when executed by a processor.

[0029] In the embodiment of the present disclosure, when there is a communication connection between the terminal and the cloud server and the terminal has subscribed to the target topic, the cloud server can push the first operation log in the target topic to the terminal that has 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 in the publish / subscribe mode based on the MQTT protocol in an unstable network, while ensuring data consistency and reducing the number of network requests so that the cloud server can access a large number of terminals with high scalability.

[0030] It should be understood that the above general description and the following detailed description are exemplary and explanatory only and do not limit the present disclosure. Other features and aspects of the present disclosure will become clear from the following detailed description of exemplary embodiments with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0031] The drawings herein are incorporated into the specification and constitute a part of the specification. These drawings illustrate embodiments consistent with the present disclosure and are used to illustrate the technical solutions of the present disclosure together with the specification.

[0032] Figure 1 A flow chart of a data synchronization method according to an embodiment of the present disclosure is shown.

[0033] Figure 2 A flow chart of a data synchronization method according to an embodiment of the present disclosure is shown.

[0034] Figure 3 A schematic diagram showing the generation of snapshot information according to an embodiment of the present disclosure.

[0035] Figure 4 A schematic diagram showing a data synchronization method according to an embodiment of the present disclosure is shown.

[0036] Figure 5 A schematic diagram of interaction between a terminal and a cloud according to an embodiment of the present disclosure is shown.

[0037] Figure 6 A block diagram of a data synchronization device according to an embodiment of the present disclosure is shown.

[0038] Figure 7 A block diagram of a data synchronization device according to an embodiment of the present disclosure is shown.

[0039] Figure 8 A block diagram of an electronic device according to an embodiment of the present disclosure is shown.

[0040] Fig. 9 A block diagram of an electronic device according to an embodiment of the present disclosure is shown. DETAILED DESCRIPTION

[0041] Various exemplary embodiments, features and aspects of the present disclosure will be described in detail below with reference to the accompanying drawings. The same reference numerals in the accompanying drawings represent elements with the same or similar functions. Although various aspects of the embodiments are shown in the accompanying drawings, the drawings are not necessarily drawn to scale unless otherwise specified.

[0042] The word “exemplary” is used exclusively herein to mean “serving as an example, example, or illustration.” Any embodiment described herein as “exemplary” is not necessarily to be construed as preferred or advantageous over other embodiments.

[0043] The term "and / or" herein is only a description of the association relationship of the associated objects, indicating that there may be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the term "at least one" herein represents any combination of at least two of any one or more of a plurality of. For example, including at least one of A, B, and C can represent including any one or more elements selected from the set consisting of A, B, and C.

[0044] It should be understood that the terms "first", "second", "third", etc. in the claims, specifications and drawings of the present disclosure are used to distinguish different objects rather than to describe a specific order. The terms "include" and "comprise" used in the specifications and claims of the present disclosure indicate the presence of the described features, wholes, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or their collections.

[0045] In addition, in order to better illustrate the present disclosure, numerous specific details are given in the following specific embodiments. It should be understood by those skilled in the art that the present disclosure can also be implemented without certain specific details. In some examples, methods, means, components and circuits well known to those skilled in the art are not described in detail in order to highlight the subject matter of the present disclosure.

[0046] Figure 1 A flow chart of a data synchronization method according to an embodiment of the present disclosure is shown, wherein the method is applied to a terminal, such as Figure 1 As shown, the data synchronization method includes:

[0047] In step S11, when there is a communication connection between the terminal and the cloud server, and the terminal has subscribed to a target topic of the cloud server, a first operation log in the target topic sent by the cloud server is received;

[0048] In step S12, when the first operation log sent by the cloud server is received, the terminal database of the terminal is updated according to the first operation log to obtain a terminal database with the first terminal state;

[0049] Among them, the first operation log indicates that there is an operation on the cloud database of the cloud server, and a communication connection is established between the terminal and the cloud server through the message queue telemetry transmission protocol MQTT.

[0050] In one possible implementation, the data synchronization method can be executed by a terminal device, which may be a user equipment (UE), a mobile device, a user terminal, a 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, etc. The method can be implemented by a processor calling computer-readable instructions stored in a memory.

[0051] In a possible implementation, in step S11, there is a communication connection between the terminal and the cloud server, which can be understood as the communication network connection between the terminal and the cloud server is normal, or the data transmission is normal. It should be understood that when the network connection is normal, the terminal can receive the operation log pushed by the cloud server.

[0052] In a possible implementation, an MQTT broker may be provided in the cloud server. Through the MQTT broker, the cloud server may publish the operation log 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 to the target topic.

[0053] It is known that the MQTT (Message Queuing Telemetry Transport) protocol is a message transmission protocol based on the message publish / subscribe mode. The message publish / subscribe mode can be understood as a message publisher publishing a message to a specific message queue topic, and multiple message subscribers can receive messages in the message queue topic after subscribing to the message queue topic. Based on this, the target topic can be a message queue topic for pushing operation logs, and the operation logs in the target topic can be understood as messages in the target topic.

[0054] It should be understood that the message transmission protocol in the message publish / subscribe mode, compared with the HTTP transmission protocol in the request-response mode, is asynchronous data transmission and does not rely on network connection conditions. It can achieve efficient and consistent data synchronization under conditions such as poor network conditions and unstable network connections, thereby meeting the data synchronization needs in the Internet of Things scenario.

[0055] In a possible implementation, operations on the cloud database (such as adding, deleting, modifying, etc.) can be abstracted into operation logs. In other words, operations on the cloud database can be recorded in the form of operation logs. Accordingly, the first operation log received by the terminal can indicate that there are operations on the cloud database of the cloud server, so that when the terminal database is updated (such as incremental update) according to the first operation log, the operations on the cloud database can be synchronized to the terminal database to achieve data consistency.

[0056] In a possible implementation, in step S12, the local terminal database of the terminal is updated according to the first operation log, which may be to perform the operation indicated by the first operation log on the terminal database, for example, to add a personnel record in the personnel table.

[0057] The terminal state in the present disclosure represents the database state of the terminal database, wherein in step S12, the first terminal state represents the database state after the terminal database is updated according to the first operation log. It should be understood that the terminal database with the first terminal state can be understood as the terminal database after the operation indicated by the first operation log is executed.

[0058] It should be noted that the terminal database and the cloud database can both refer to databases. The database in the terminal is the terminal database, and the database in the cloud server is the cloud database. It should be understood that the database states of the terminal database and the cloud database can be out of sync. The database state represents the storage state of the data in the database. The purpose of data synchronization is to make the data stored in the terminal database and the cloud database the same, that is, the database states are synchronized.

[0059] In a possible implementation, 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 present disclosure does not limit the data stored in the terminal database and the cloud database.

[0060] It should be understood that data synchronization implemented based on the MQTT protocol is asynchronous data synchronization. Based on this, in one possible implementation method, the terminal may include multiple terminals, so that all terminals that have subscribed to the target topic can receive the first operation log sent by the cloud server, thereby supporting a large number of terminal accesses without bringing access pressure to the cloud server, and having high scalability.

[0061] In the embodiment of the present disclosure, when there is a communication connection between the terminal and the cloud server and the terminal has subscribed to the target topic, the cloud server can push the first operation log in the target topic to the terminal that has subscribed to the target topic to update the terminal database, as well as the communication connection established between the terminal and the cloud server through the MQTT protocol, so that in an unstable network, data synchronization in a publish / subscribe mode can be efficiently implemented based on the MQTT protocol, while ensuring data consistency and reducing the number of network requests, so that the cloud server can access a large number of terminals with high scalability.

[0062] As mentioned above, the network connection in the IoT scenario is unstable. For example, when using face recognition to board a bus, the facial feature information and personnel information in the cloud database need to be synchronized to the bus's smart terminal. The network connection of the bus is good when it is at the station, and it becomes worse after leaving the station. In the case of poor network connection, the bus's smart terminal and the cloud server may not be able to establish a good communication connection.

[0063] In view of these situations, in a possible implementation, the method may further include:

[0064] Step S13: When a predetermined synchronization condition is met, a status acquisition request is sent to the cloud server, where the status acquisition request is used to acquire a current first cloud state of the cloud database, where the first cloud state represents a current database state of the cloud database;

[0065] Step S14: upon receiving the first cloud status sent by the cloud server, determining whether the first cloud status matches the first terminal status;

[0066] Step S15: when the first cloud state matches the first terminal state, obtaining the current first snapshot information of the cloud database;

[0067] Step S16: updating the terminal database of the first terminal state according to the acquired first snapshot information to obtain a terminal database of the second terminal state;

[0068] The predetermined synchronization condition includes: the duration of interruption of 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 restored.

[0069] In a possible implementation, if the duration of the interruption of the communication connection between the terminal and the cloud server exceeds the time threshold, it can be understood that there has been no communication or data transmission between the terminal and the cloud server for a period of time. At this time, it can be considered that the network connection between the terminal and the cloud server has been disconnected for more than the time threshold. The time threshold can be set according to actual needs, for example, it can be determined according to the running time of the bus between stations, and the embodiments of the present disclosure are not limited to this.

[0070] It should be understood that when 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 terminal and the cloud server are disconnected and reconnected, that is, the predetermined synchronization condition can be understood as disconnection and reconnection.

[0071] The cloud state in the present disclosure represents the database state of the cloud database. In step S13, the first cloud state represents the current database state of the cloud database. The database state may represent the storage state of the data in the database.

[0072] As described above, the operation log of the cloud database can be published to the target topic, and the current operation log of the cloud database can reflect the current database state of the cloud database, and different operation logs can be distinguished by using log identifiers. In a possible implementation, in step S13, the current database state of the cloud database is obtained, which can be to obtain the log identifier of the current operation log in the target topic, so as to represent the current database state of the database through the log identifier, that is, to represent the first cloud state. In this way, the current first cloud state of the cloud database can be conveniently obtained.

[0073] It should be understood that since the terminal database is updated according to the first operation log, the first operation log can reflect the data status of the updated terminal database, that is, the first terminal status of the terminal database. Therefore, the log identifier of the first operation log can be used to represent the first terminal status of the terminal database.

[0074] In a possible implementation, in step S14, determining whether the first cloud state matches the first terminal state may be performed by determining whether the log identifier representing the first cloud state and the log mark representing the first terminal state are continuous in sequence. For example, assuming that the log identifier representing the first cloud state is 0100, if the log mark representing the first terminal state is 0101, it may represent that the log identifier representing the first cloud state and the log mark representing the first terminal state are continuous, that is, the first cloud state and the first terminal state match; if the log identifier representing the first terminal state is 0299, it may represent that the log identifier representing the first cloud state and the log mark representing the first terminal state are discontinuous, that is, the first cloud state and the first terminal state do not match.

[0075] In a possible implementation, in step S15, the first cloud state does not match the first terminal state, which can be understood as the log mark characterizing the first cloud state and the log mark characterizing the first terminal state are discontinuous. In this case, considering that the duration of the interruption of the communication connection between the terminal and the cloud server in the predetermined synchronization condition exceeds the time threshold, the number of newly added operation logs in the cloud database may be large during this duration. Therefore, the current first snapshot information of the cloud database can be obtained to update the terminal database to reduce the volume of data transmission and improve data synchronization efficiency.

[0076] In a possible implementation, the current first snapshot information of the cloud database may be snapshot information generated by taking a snapshot of the current full operation log of the cloud database. The snapshot information may be understood as a copy or replica of the full operation log, etc. Taking a snapshot of the full operation log may be implemented by any existing snapshot technology, which is not limited in the embodiments of the present disclosure.

[0077] It is known that taking a snapshot of the full operation log can compress the volume of the full operation log. That is to say, the snapshot information generated by taking a snapshot is smaller than the volume of the full operation log. This can reduce the volume of data transmission and improve data synchronization efficiency.

[0078] In a possible implementation, in step S15, the current first snapshot information of the cloud database is obtained, and the first snapshot information can be obtained by subscribing to a snapshot topic, or by sending an HTTP request to the cloud database, which is not limited to this embodiment of the present disclosure.

[0079] As described above, the first cloud state and the first terminal state may also match each other. In this case, it can be considered that the current database states of the cloud database and the terminal database are synchronized. In this case, step S15 may not be executed to obtain snapshot information, but the operation log in the target topic may be directly obtained, and the terminal database may be updated according to the obtained operation log.

[0080] In a possible implementation, in step S16, updating the terminal database of the first terminal state according to the acquired first snapshot information may include: fully updating the terminal database of the first terminal state according to the operation indicated by the operation log in the first snapshot information; or incrementally updating the terminal database of the first terminal state according to the difference operation log between the first snapshot information and the first operation log, performing the operation indicated by the difference operation log on the terminal database. Which update method is adopted can be set according to actual needs, and the embodiment of the present disclosure does not limit this.

[0081] 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 the terminal database after the operation indicated by the above-mentioned difference operation log is executed.

[0082] In the disclosed embodiment, when there is a network disconnection and reconnection between the terminal and the cloud server, the terminal database can be efficiently updated based on the snapshot information of the cloud database to quickly achieve data synchronization between the cloud database and the terminal database.

[0083] In a possible implementation, in step S15, when the first cloud state does not match the first terminal state, obtaining current first snapshot information of the cloud database includes:

[0084] Sending a snapshot address acquisition request to the cloud server, where the snapshot address acquisition request is used to acquire a storage address of the first snapshot information in the snapshot storage server;

[0085] When the storage address of the first snapshot information sent by the cloud server is received, the first snapshot information is obtained from the snapshot storage server according to the storage address.

[0086] In a possible implementation, the snapshot storage server may be used to store snapshot information of a 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. The first snapshot address may be a storage address of the first snapshot information in the storage server.

[0087] As described above, the first snapshot information can also be obtained by subscribing to a snapshot topic. In one possible implementation, the storage address of the first snapshot information can be published to a snapshot topic subscribed by the terminal, so that the storage address in the snapshot topic can be pushed to the terminal based on the MQTT protocol.

[0088] The snapshot topic may be a message queue topic for pushing a storage address, and the storage address in the snapshot topic may be a message in the snapshot topic.

[0089] In a possible implementation, a snapshot address acquisition request may be sent to a cloud server via an HTTP request in a request-response mode, which is not limited in the embodiments of the present disclosure.

[0090] In a possible implementation, obtaining the first snapshot information from the snapshot storage server according to the storage address may include: 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 the embodiment of the present disclosure.

[0091] In the disclosed embodiment, by receiving the first snapshot address of the first snapshot information sent by the cloud server, snapshot information with a large amount of data can be conveniently downloaded from the snapshot storage server based on the snapshot address, thereby improving data transmission efficiency during data synchronization.

[0092] In a possible implementation, the cloud server may also publish the first snapshot information directly to the snapshot topic subscribed by the terminal, so that in step S15, when the first cloud state does not match the first terminal state, obtaining the current first snapshot information of the cloud database may include: when the first cloud state does not match the first terminal state, directly obtaining the first snapshot information from the subscribed snapshot topic. In this way, the first snapshot information of the cloud database can be quickly obtained.

[0093] Consider that snapshots of all operation logs can be taken at a certain time period, so some newly added operation logs in the cloud database may not be backed up in the first snapshot information. Therefore, the terminal database updated based on the first snapshot information may not be synchronized with the cloud database.

[0094] Among them, considering that the data volume of the operation log not backed up in the first snapshot information is not large, in order to quickly synchronize the terminal database with the cloud database, in a possible implementation manner, the method further includes:

[0095] Step S17: Determine whether the second terminal state matches the first cloud state;

[0096] Step S18: When the second terminal state does not match the first cloud state, a difference log acquisition request is sent to the cloud server, where the difference log acquisition request is used to acquire a difference operation log corresponding to the first cloud state;

[0097] Step S19: When the difference operation log sent by the cloud server is received, the terminal database of the second terminal state is updated according to the difference operation log to obtain a terminal database with a third terminal state, and the third terminal state is the same as the first cloud state.

[0098] Among them, in step S17, whether the second terminal state matches the first cloud state can be determined in the same manner as the above-mentioned determination of whether the first cloud state matches the first terminal state, which will not be described in detail here.

[0099] In one possible implementation, the difference log acquisition request may include a log identifier representing the state of the second terminal and a log identifier representing the state of the first cloud, so that the cloud server can determine the difference operation log based on the log identifier representing the state of the second terminal and the log identifier representing the state of the first cloud, and return the difference operation log to the terminal.

[0100] In a possible implementation, the differential 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 can be distinguished by log identifiers. 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, then the differential operation log includes operation logs with log identifiers 0201 to 0213.

[0101] In a possible implementation, updating the terminal database of the second terminal state according to the difference operation log to obtain the terminal database of the third terminal state may include: performing the operation indicated by the difference operation log on the terminal database to obtain the terminal database of the third terminal state.

[0102] In a possible implementation, there may also be a situation where the second terminal state matches the first cloud state. At this time, it can be considered that some newly added operation logs of the cloud database have been backed up in the first snapshot information. In this case, step S18 can be omitted to obtain the difference operation log, and the operation log in the target topic can be directly obtained, and the terminal database of the second terminal state can be updated based on the operation log.

[0103] In the disclosed embodiment, when there are some newly added operation logs in the cloud database that are not backed up in the first snapshot information, differential operation logs can be obtained to efficiently implement data synchronization to ensure data consistency.

[0104] Considering that the terminal device may also have scenarios such as starting the communication connection after shutting down, starting the communication connection for the first time, etc., where the time interval between shutting down and starting up is usually long. For example, the interval between the smart terminal on the bus stopping and starting up may be several hours. These situations can be considered as the situation where the communication connection is started between the terminal and the cloud server. It should be understood that the amount of data to be synchronized in these situations is usually relatively large. In a possible implementation, the method may also include:

[0105] Step S21: When a communication connection is initiated between the terminal and the cloud server, a snapshot topic subscription request is sent to the cloud server, where the snapshot topic subscription request is used to subscribe to a snapshot topic of the cloud server to obtain second snapshot information of the cloud database through the snapshot topic;

[0106] Step S22: According to the acquired second snapshot information, the terminal database of the first terminal state is updated to obtain a terminal database of the fourth terminal state.

[0107] In a possible implementation, when the terminal device is started, or when the terminal device initiates a communication connection with the cloud server, the snapshot topic can be subscribed to in step S21 to let the cloud server know the terminal access.

[0108] As described above, the snapshot information can be stored in a snapshot storage server. In one possible implementation, the cloud server can publish the storage address of the second snapshot information to the snapshot topic subscribed by the terminal. The terminal can obtain the storage address of the second snapshot information in the snapshot topic, and then the terminal can download the second snapshot information from the snapshot storage server based on the obtained storage address of the second snapshot information.

[0109] As described above, the cloud server can also directly publish the snapshot information to the snapshot topic. After the terminal subscribes to the snapshot topic, the cloud server publishes the second snapshot information to the snapshot topic, so that the terminal can directly obtain the second snapshot information from the snapshot topic.

[0110] 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 scenarios or at different time points.

[0111] In one possible implementation, updating the terminal database of the first terminal state according to the acquired second snapshot information to obtain a terminal database with a fourth terminal state may include: executing the operation indicated by the full operation log in the second snapshot information to fully update the terminal database of the first terminal state to obtain a terminal database with the fourth terminal state.

[0112] In the disclosed embodiment, when the terminal initiates a communication connection with the cloud server, it is possible to subscribe to a snapshot topic and obtain second snapshot information for a full update, so that the terminal database can be efficiently synchronized to the same state as the cloud database as much as possible, reducing the number of access requests and improving data synchronization efficiency.

[0113] In a possible implementation, after updating the terminal database of the first terminal state according to the acquired second snapshot information in step S22 to obtain the terminal database of the fourth terminal state, the method may further include:

[0114] Step S23: Send a target topic subscription request to the cloud server to subscribe to the target topic in the cloud server;

[0115] Step S24: upon receiving the second operation log in the target topic sent by the cloud server, determining whether the second operation log matches the terminal database of the fourth terminal state;

[0116] Step S25: When the second operation log does not match the terminal database of the fourth terminal state, an interval log acquisition request is sent to the cloud server, where the interval log acquisition request is used to acquire the interval operation log between the second operation log and the second snapshot information;

[0117] Step S26: When the interval operation log sent by the cloud server is received, the terminal database is updated according to the interval operation log and the second operation log to obtain a terminal database with a fifth terminal state, which is the same as the second cloud state of the cloud database.

[0118] Among them, through step S23, the target topic of the cloud server can be subscribed, so that the cloud server can push the operation log in the target topic to the terminal based on the MQTT protocol.

[0119] Considering that the terminal database obtained by updating the second snapshot information in the above steps S21 to S22 may not be synchronized with the cloud database, or in other words, there may be an operation log gap between the second snapshot information and the second operation log. Then, by determining whether the second operation log matches the terminal database of the fourth terminal state in step S24, it can be known whether there is an operation log gap between the second snapshot information and the second operation log.

[0120] In a possible implementation, in step S24, whether the second operation log matches the terminal database of the fourth state can be determined by determining whether the log identifier of the second operation log and the log identifier representing the fourth terminal state are continuous in sequence. If they are not continuous, they can be considered to be mismatched; if they are continuous, they can be considered to be matched.

[0121] In one possible implementation, in step S25, the interval log acquisition request may include the log identifier of the second operation log and the log identifier representing the fourth terminal status, so that the cloud server can determine the interval operation log based on the log identifier of the second operation log and the log identifier representing the fourth terminal status.

[0122] It should be understood that, since the second operation log has been received in step S24, the interval operation log may include the operation log between the second operation log and the second snapshot information.

[0123] In a possible implementation, there may also be a situation where the second operation log matches the terminal database in the fourth state. In this case, it can be considered that there is no interval operation log 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, step S25 may not be executed to obtain the interval operation log, but the operation indicated by the second operation log may be directly executed to update the terminal database in the fourth terminal state.

[0124] In a possible implementation, in step S27, 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: performing the operation indicated by the interval operation log and performing the operation indicated by the second operation log on the terminal database to obtain the terminal database with the sixth log identifier. The terminal database with the sixth log identifier may be understood as the terminal database after performing the operation indicated by the second operation log.

[0125] In the embodiment of the present disclosure, by subscribing to the target topic and obtaining the interval operation log, the full operation log of the second snapshot information and the operation log of the interval between the second operation log can be effectively obtained, thereby completing the interval operation log and ensuring the consistency of data synchronization.

[0126] Considering that in some scenarios, users can also perform operations such as adding, deleting, modifying and querying the terminal database, in this case, the operations on the terminal database can also be synchronized to the cloud database of the cloud server.

[0127] In a possible implementation, the method further includes:

[0128] In response to an operation on a local terminal database of the terminal, a data update request is sent to a cloud server, where the data update request is used to instruct to update the cloud database corresponding to the operation.

[0129] The operation on the local terminal database of the terminal may include at least one of adding, deleting and modifying.

[0130] In a possible implementation, sending a data update request to the cloud can be implemented through the HTTP protocol or the MQTT protocol. It should be understood that if implemented through the MQTT protocol, the terminal in this manner can be understood as the publisher of the message, and the cloud server can be the subscriber of the message.

[0131] The data update request may include an operation log corresponding to the operation on the terminal database, so that the cloud server executes the operation indicated by the operation log, that is, updates the cloud database corresponding to the operation.

[0132] As described above, there may be multiple terminals connected to the cloud server. It should be understood that after the cloud database is updated corresponding to the operation, the operation log corresponding to the operation can be pushed to other connected terminals through the data synchronization method in the above-mentioned embodiment of the present disclosure to achieve data synchronization with the terminal data of other terminals.

[0133] In the embodiment of the present disclosure, when a user updates the local terminal data of the terminal, the update operation can be synchronized to the cloud database to ensure data consistency between the terminal database and the cloud database.

[0134] Figure 2 A flow chart of a data synchronization method according to an embodiment of the present disclosure is shown, wherein the method is applied to a cloud server, such as Figure 2 As shown, the data synchronization method includes:

[0135] In step S31, when there is an operation on the cloud database, a first operation log corresponding to the operation on the cloud database is determined;

[0136] 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 that has subscribed to the target topic, so that the terminal database local to the terminal is updated according to the first operation log.

[0137] As described above, the terminal and the cloud server establish a communication connection through the message queue telemetry transmission protocol MQTT. In this way, data synchronization in the message publish / subscribe mode can be achieved.

[0138] In one possible implementation, the cloud server may provide a series of interfaces to allow users to query the data synchronization status and perform operations such as adding, deleting, modifying, and querying the cloud database.

[0139] In a possible implementation, a structured query language (SQL statement) can be sent to the cloud database by remote control to perform operations such as adding, deleting, modifying, and searching the cloud database; as described above, operations on the local terminal database can also be synchronized to the cloud database, that is, the operations indicated by the data update request are performed on the cloud database to update the cloud database. Based on this, in step S31, there is an operation on the cloud database, which can refer to the existence of an operation on the cloud database in any of the above-mentioned ways.

[0140] In a possible implementation, in step S31, 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.

[0141] Wherein, a log identifier may be added to the generated first operation log according to the time sequence of the generation of the first operation log. The log identifier may be a timestamp, a sequence number (e.g., 001, 002), or a string of any form, as long as it can represent the generation sequence of the first operation log, and the embodiment of the present disclosure does not limit this.

[0142] As described above, an MQTT broker service may be provided in the cloud server. In a possible implementation, in step S32, the first operation log may be published to the target topic subscribed by the terminal through the MQTT broker service, and set as a retained message, that is, the message retention mechanism of the MQTT protocol may be utilized to retain the published first operation log in the target topic.

[0143] It should be understood that when the first operation log is published to the target topic, the original operation log on the target topic can be overwritten and updated. The first operation log in the target topic is the latest operation log of the cloud database.

[0144] It is known that MQTT is a message transmission protocol based on the message publish / subscribe mode. The message publish / subscribe mode can be understood as a message publisher publishing a message to a specific message queue topic, and multiple message subscribers can receive messages in the message queue topic after subscribing to the message queue topic. Based on this, the target topic can be a message queue topic for pushing operation logs, and the operation logs in the target topic can be understood as messages in the target topic.

[0145] As described above, the terminal may include multiple terminals. In step S32, the first operation log is sent to the terminal that has subscribed to the target topic, and the first operation log may be sent to all terminals that have subscribed to the target topic. In this way, all terminal devices that have subscribed to the target topic can receive the first operation log sent by the cloud server, thereby supporting a large number of terminal accesses without bringing access pressure to the cloud server, and having high scalability.

[0146] Among them, 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. The data synchronization method of the above-mentioned embodiment of the present disclosure can be referred to and will not be described in detail here.

[0147] In one possible implementation, the cloud database includes one or more synchronization groups, each of which corresponds to a different target topic. Each synchronization group may contain part of the data in the cloud database. For example, all personnel of a company is a database. The company has multiple departments, and the personnel of each department can be divided into a synchronization group. In this way, the entire cloud database can be divided into multiple parts for separate synchronization. Compared with data synchronization for the entire cloud database, the amount of data to be synchronized in each synchronization group is smaller, thereby improving synchronization efficiency.

[0148] In a possible implementation, the cloud database may be MariaDB database (a relational database), TiDB database (an open source distributed relational database), Cassandra database (an open source distributed non-relational database system), etc., which is not limited in the embodiments of the present disclosure. The storage location of the cloud database in the cloud server can be determined according to actual needs, which is not limited in the embodiments of the present disclosure.

[0149] In the embodiment of the present disclosure, when there is a communication connection between the terminal and the cloud server and the terminal has subscribed to the target topic, the cloud server can push the first operation log in the target topic to the terminal that has subscribed to the target topic to update the terminal database, as well as the communication connection established between the terminal and the cloud server through the MQTT protocol, so that data synchronization in the publish / subscribe mode can be efficiently implemented based on the MQTT protocol in an unstable network, and data consistency can be guaranteed at the same time, so that the cloud server can access a large number of terminals with high scalability.

[0150] In a possible implementation, the method further includes:

[0151] When receiving a status acquisition request sent by the terminal, a first cloud status of the cloud database is sent to the terminal, so that the terminal updates the terminal database based on the first cloud status, wherein the first cloud status is the current database status of the cloud database.

[0152] As described above, the state acquisition request is used to obtain the current first cloud state of the cloud database and is triggered when a predetermined synchronization condition is met. The method of updating the terminal database based on the first cloud state can refer to the data synchronization method in the above embodiment of the present disclosure, which will not be described in detail here.

[0153] In an embodiment of the present disclosure, when a status acquisition request is received, the current first cloud status of the cloud database can be sent to the terminal, so that the terminal can determine whether to update the terminal database by acquiring snapshot information.

[0154] As described above, the terminal may send a snapshot address acquisition request to the cloud to acquire the storage address of the first snapshot information. In a possible implementation, the method further includes:

[0155] When a snapshot address acquisition request is received from a terminal, the storage address of the first snapshot information is sent to the terminal, so that the terminal downloads 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. The snapshot storage server is used to store snapshot information of the cloud database.

[0156] As described above, the snapshot address acquisition request is used to obtain the storage address of the first snapshot information in the snapshot storage server. The snapshot storage server can be used to store snapshot information of the cloud database. It should be understood that when the snapshot information is stored in the snapshot storage server, the storage address of the snapshot information can be generated, and the snapshot information pointed to by the storage address can be accurately obtained from the snapshot storage server.

[0157] As described above, the terminal can send a snapshot address acquisition request to the cloud server through an HTTP request, or obtain the storage address of the first snapshot information by subscribing to a snapshot topic. Among them, the cloud server can publish the storage address of the first snapshot information to the snapshot topic subscribed by the terminal, so that when receiving the snapshot address acquisition request sent by the terminal, the storage snapshot address in the snapshot topic can be pushed to the terminal based on the MQTT protocol. Among them, the snapshot topic can be a message queue topic for pushing the storage address, and the storage address in the snapshot topic can be a message in the snapshot topic.

[0158] Among them, 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. The data synchronization method in the above-mentioned embodiment of the present disclosure can be referred to and will not be described in detail here.

[0159] In the disclosed embodiment, by sending the storage address of the first snapshot information to the terminal, the terminal can download the first snapshot information with a large amount of data from the snapshot storage server based on the storage address, thereby improving the data transmission efficiency during data synchronization.

[0160] In a possible implementation, the method further includes:

[0161] When a difference log acquisition request sent by the terminal is received, a difference operation log corresponding to the first cloud state of the cloud database is sent to the terminal, so that the terminal updates the terminal database according to the difference operation log.

[0162] As described above, the difference log acquisition request may include a log identifier representing the state of the second terminal and a log identifier representing the state of the first cloud. In this way, when a difference log acquisition request sent by a terminal is received, a difference operation log can be determined based on the log identifier representing the state of the second terminal and the log identifier representing the state of the first cloud, and the difference operation log can be sent to the terminal.

[0163] 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.

[0164] In a possible implementation, the differential operation log can be obtained from a log library that can be used to store operation logs. The log library can use any type of database, such as MariaDB database, TiDB database, Cassandra database, etc., which is not limited in the embodiments of the present disclosure. The storage location of the log library in the cloud server is not limited in the embodiments of the present disclosure.

[0165] Among them, the terminal is made to update the terminal database according to the difference operation log. The data synchronization method in the above-mentioned embodiment of the present disclosure can be referred to and will not be described in detail here.

[0166] In the embodiment of the present disclosure, when a difference log acquisition request sent by a terminal is received, a difference operation log can be quickly returned to the terminal, thereby efficiently realizing data synchronization and ensuring data consistency.

[0167] In a possible implementation, the method further includes:

[0168] In case of receiving a snapshot topic subscription request sent by the terminal, determining the snapshot topic subscribed by the terminal, and publishing the second snapshot information of the cloud database or the storage address of the second snapshot information to the snapshot topic;

[0169] In the case of receiving a target topic subscription request sent by the terminal, determining the target topic to which the terminal subscribes, and publishing the second operation log of the cloud database to the target topic;

[0170] In case of receiving the interval log acquisition request sent by the terminal, determining the interval operation log between the second operation log and the second snapshot information, and sending the interval operation log to the terminal.

[0171] As described above, when the terminal is started, or when the terminal starts a communication connection with a cloud server, a snapshot topic subscription request can be sent to the cloud server to let the cloud server know that the terminal is connected and subscribe to the snapshot topic.

[0172] In one possible implementation, the snapshot topic subscription request may include the snapshot topic to which the terminal wants to subscribe, so that when the cloud server receives the snapshot topic subscription request, it can determine the snapshot topic to which the terminal subscribes, and publish the second snapshot information of the cloud database or the storage address of the second snapshot information to the snapshot topic, so that the terminal can obtain the second snapshot information or the storage address of the second snapshot information from the snapshot topic.

[0173] In one possible implementation, the target topic subscription request may include the target topic subscribed by the terminal, so that the cloud server can 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 with the second operation log.

[0174] For determining the interval operation log between the second operation log and the second snapshot information, reference may be made to the above-mentioned embodiments of the present disclosure, which will not be described in detail here.

[0175] In the embodiment of the present disclosure, by responding to the terminal's snapshot topic subscription request, target topic subscription request, and interval log acquisition request, 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 are sent to the terminal, so that when the terminal starts a communication connection with the cloud server, the terminal database and the cloud database can efficiently and quickly achieve consistent data synchronization.

[0176] As described above, the snapshot address may be sent to the terminal by subscribing to a snapshot topic. In a possible implementation, the method further includes:

[0177] According to the preset period, take a snapshot of the current full operation log of the cloud database to obtain snapshot information;

[0178] Publish the snapshot information to the snapshot topic subscribed by the terminal to send the snapshot information to the terminal through the snapshot topic.

[0179] In a possible implementation, the preset period may include: the number of added operation logs (e.g., 1000), or the interval length (e.g., 1000 seconds). For example, whenever the number of added operation logs reaches 1000, a snapshot of the current full operation log of the cloud database is taken; or, every 1000 seconds, a snapshot of the current full operation log of the cloud database is taken, which is not limited in the embodiments of the present disclosure.

[0180] Figure 3 FIG. 2 is a schematic diagram showing the generation of snapshot information according to an embodiment of the present disclosure. Figure 3 As shown in the figure, Op represents the operation log, n, n+1~m represent the log identifiers of the operation log, that is, the order in which the operation logs are generated. The Op n+1 snapshot starts and the Op m snapshot ends, which means that when the generated Op n+1~Op m reaches a certain number (such as 1000) or a certain time interval (such as 1000 seconds), it triggers a snapshot of the current full operation log of the cloud database. The obtained snapshot information includes Op n+1~Op m. In this way, when the terminal database is updated based on the snapshot information, it can be synchronized to the terminal database with the log identifier m.

[0181] As described above, snapshot information can be understood as a copy, replica, backup, etc. of the full operation log; taking a snapshot of the full operation log can be achieved through any existing snapshot technology, and the embodiments of the present disclosure are not limited to this. It should be understood 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, which can reduce the volume of data transmission and improve data synchronization efficiency.

[0182] As described above, the snapshot storage server can be used 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 can be obtained, and the snapshot information pointed to by the storage address can be accurately obtained from the snapshot storage server.

[0183] It should be understood that the cloud server may be a server cluster composed of multiple servers. In a possible implementation, the snapshot storage server may be independent of the cloud server or may belong to the cloud server, which is not limited in the embodiments of the present disclosure.

[0184] In one possible implementation, publishing snapshot information to a snapshot topic subscribed by a terminal may include: publishing the current snapshot information to the snapshot topic, overwriting the snapshot information that has been published to the snapshot topic before the update, and setting it as a retained message, that is, using the message retention mechanism of the MQTT protocol to retain the published snapshot information in the snapshot topic; it may also include: publishing the storage address of the current snapshot information to the snapshot topic, overwriting the storage address that has been published to the snapshot topic before the update, and setting it as a retained message, that is, using the message retention mechanism of the MQTT protocol to retain the published storage address in the snapshot topic.

[0185] In the disclosed embodiment, the snapshot information or the storage address of the snapshot information can be synchronized so that the terminal can efficiently obtain the latest snapshot information to update the terminal database.

[0186] In a possible implementation, in step S32, publishing the first operation log to a 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 the target topic.

[0187] In a possible implementation, the specific value of the time period can be set according to actual needs, for example, it can be set to 5 seconds, which is not limited in the embodiment of the present disclosure. Among them, any known compression technology can be used to compress the first operation log, which is not limited in the embodiment of the present disclosure.

[0188] It should be understood that the first operation log within a time period may include more than one. By following the preset time period, the first operation log within the time period may be compressed once to avoid frequent calls to the compression process and improve the utilization of computing resources.

[0189] Of course, it is also possible that each time a first operation log is generated, a compression process is performed, and the compressed first operation log is published to the target topic, which is not limited in the embodiment of the present disclosure.

[0190] In the embodiment of the present disclosure, when the first operation logs are generated at a high frequency, at least one first operation log within a time period can be compressed and published once, thereby improving processing efficiency and avoiding frequent occupation of computing resources.

[0191] In a possible implementation, the method further includes:

[0192] When a data update request sent by the terminal is received, the cloud database is updated according to the operation indicated by the data update request. The data update request may be triggered in response to the operation on the terminal database.

[0193] As described above, in some scenarios, the user can also add, delete, modify, and other operations on the terminal database. In this case, the operations on the terminal database can also be synchronized to the cloud database of the cloud server.

[0194] As described above, the data update request may include an operation log of operations on the terminal database, so that the cloud server can perform the operations indicated by the operation log. That is, the operations indicated by the data update request are operations on the terminal database.

[0195] As described above, there may be multiple terminals connected to the cloud server. In a possible implementation, after the cloud database executes 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 connected terminals through the data synchronization method in the above-mentioned embodiment of the present disclosure. In this way, data synchronization between the cloud database and multiple terminal databases can be achieved.

[0196] In the disclosed embodiment, operations on local terminal data of the terminal may be synchronized to a cloud database to ensure data consistency between the terminal database and the cloud database.

[0197] Figure 4 A schematic diagram showing a data synchronization method according to an embodiment of the present disclosure is shown as follows: Figure 4 As shown, the data synchronization method includes:

[0198] Step 1: The business logic of the terminal instructs the synchronization toolkit of the terminal to obtain the latest snapshot information; wherein the synchronization toolkit is used to synchronize data with the cloud database; the business logic is used to instruct the synchronization toolkit to synchronize data when a predetermined synchronization condition is met (such as disconnection and reconnection), and update the terminal database based on the received operation log;

[0199] Step 2: Based on the instructions of the business logic, the synchronization toolkit sends a status acquisition request to the MQTT proxy service in the cloud to obtain the current cloud status of the cloud database, where the cloud status is represented by the log identifier of the latest operation log id;

[0200] Step 3: The MQTT proxy service returns the latest log identifier id=K of the operation log in the target topic, that is, returns the cloud status of the cloud database;

[0201] Step 4: When the latest log identifier id=K does not match the log identifier of the current operation log of the terminal database, that is, when the cloud state does not match the current terminal state of the terminal database, a request for obtaining snapshot information is sent to the synchronization management service of the cloud;

[0202] Step 5: The synchronization management service processes the snapshot information acquisition request and returns the snapshot address of the current snapshot information and the latest log identifier id=N of the full operation log in the current snapshot information;

[0203] Step 6: The synchronization toolkit downloads the snapshot information from the snapshot storage service in the cloud according to the snapshot address;

[0204] Step 7: Download snapshot information from the snapshot storage service;

[0205] Step 8: The synchronization toolkit transmits the downloaded snapshot information to the business logic to update the terminal database;

[0206] Step 9: The business logic instructs the synchronization toolkit to start acquiring the operation log with log identifier id=N+1;

[0207] Step 10: The synchronization toolkit determines whether the values ​​of the log identifier id=N+1 and the latest log identifier id=K match, or in other words, whether N and K are continuous; if the values ​​of the log identifier id=N+1 and the latest log identifier id=K do not match, a difference log acquisition request is sent to the synchronization management service, and the difference log acquisition request is used to obtain the difference operation logs corresponding to the log identifier id=N+1 to the log identifier id=K; wherein the synchronization management service can obtain the difference operation log corresponding to the difference log acquisition request from the log library used to store the operation log;

[0208] Step 11: The synchronization management service returns the difference operation log corresponding to the difference log acquisition request;

[0209] Step 12: The synchronization toolkit transmits the acquired difference operation log to the business logic to update the terminal database;

[0210] Step 13: Continue to obtain operation logs from the MQTT proxy service, wherein the operation logs pushed by the subscribed target topic starting from the operation log with log identifier id=K+1 are obtained;

[0211] Step 14: Continue to receive the operation log pushed by the MQTT proxy service from the operation log with log identifier id=K+1;

[0212] Step 15: The synchronization toolkit transmits the received operation log to the business logic to update the terminal database.

[0213] In a possible implementation, the MQTT proxy service may use Kafka (a high-throughput distributed publish-subscribe messaging system) or may directly use EMQ X (an open source, scalable, highly available distributed MQTT messaging server), which is not limited in the embodiments of the present disclosure.

[0214] In a possible implementation, the snapshot storage service may use MinIO (a distributed storage service software) to store snapshot information, which is not limited in the embodiments of the present disclosure.

[0215] It should be understood that the cloud can be a server cluster composed of multiple servers. In one possible implementation, the above-mentioned MQTT proxy service, synchronization management service, and snapshot storage service can be located in different servers or in the same server, which is not limited to this embodiment of the present disclosure.

[0216] Among them, the server where the snapshot storage service is located can be called a snapshot storage server, the server where the MQTT proxy service is located can be called an MQTT proxy server, and the server where the synchronization management service is located can be called a synchronization management server.

[0217] In one possible implementation, the log library can be used to store the operation logs of the cloud database. The log library can use any type of database, such as MariaDB database, TiDB database, Cassandra database, etc., which is not limited in the embodiments of the present disclosure. The storage location of the log library and the cloud database in the cloud server is not limited in the embodiments of the present disclosure.

[0218] In one possible implementation, the data synchronization method can be used in scenarios where face recognition is used in edge terminal devices, such as in a scenario where face recognition is used to board a bus. When the bus is at a station, the data synchronization method of the disclosed embodiment can be used to synchronize the cloud-based facial feature library and relevant information of the personnel to the edge device (edge ​​terminal device). After the bus leaves the station, passengers can still board the bus by face recognition under weak network conditions. The method can also efficiently process and synchronize the latest data in real time, while ensuring data consistency and being expandable to a large number of edge devices.

[0219] Figure 5 FIG. 1 shows a flow chart of the interaction between the terminal and the cloud according to an embodiment of the present disclosure. Figure 5 As shown, the interaction process includes:

[0220] Step 01: The synchronization management service confirms the snapshot information that the terminal wants to download;

[0221] Step 02: The synchronization management service informs the snapshot storage service terminal of the snapshot information to be downloaded;

[0222] Step 03: The terminal requests the synchronization management service to obtain snapshot information and operation logs;

[0223] Step 04: The terminal downloads the snapshot information from the snapshot storage service.

[0224] Step 05: The synchronization management service confirms that the operation logs are pushed to the terminal starting from the operation log with log identifier N+1;

[0225] Step 06: The synchronization management service informs the cloud database terminal to synchronize the operation log;

[0226] Step 07: The synchronization management service informs the MQTT proxy service to push the operation log to the terminal;

[0227] Step 08: The MQTT proxy service pushes the operation log to the terminal;

[0228] Step 09: Transfer the snapshot information of the cloud database to the snapshot storage service for storage.

[0229] It should be noted that Figure 5 The interaction flowchart shown can be used to illustrate the interaction process that may occur between the cloud and the terminal during the data synchronization process. The embodiment of the present disclosure does not limit the execution order of the above steps 01 to 09.

[0230] According to an embodiment of the present disclosure, under weak network conditions, when the terminal device reconnects to the cloud server, it will obtain the latest operation log retained in the MQTT proxy service. If the order of the latest operation log is discontinuous with the order of the operation log of the terminal data, it can be synchronized to the latest status through a snapshot, and then synchronized by obtaining the difference operation log, thereby ensuring data consistency.

[0231] According to the embodiments of the present disclosure, based on the MQTT transmission protocol combined with the state machine replication method, the real-time updated data on the cloud side can be efficiently synchronized to the terminal on the edge side, and it can adapt to network instability, ensure data consistency, and have high scalability (connecting a large number of terminal devices at the same time).

[0232] In the related art, the state machine synchronization is implemented based on the HTTP protocol, and the synchronization data is obtained through a request-response. The embodiment of the present disclosure implements the state machine synchronization based on the MQTT protocol, and can use the message retention mechanism of the MQTT protocol to obtain the latest snapshot and operation log more quickly.

[0233] According to the embodiments of the present disclosure, data synchronization is highly real-time, and each update operation of the cloud database can be synchronized to the terminal database on the edge within minutes or even seconds; it can support full updates and incremental updates; it can support data synchronization under weak network conditions (network interruptions, network bandwidth changes, etc.), and can be applied in scenarios such as face recognition on buses; it can ensure data consistency; it has high scalability and supports data synchronization between the cloud side and a large number (number > 2000) of edge devices at the same time.

[0234] It can be understood that the above-mentioned various method embodiments mentioned in the present disclosure can be combined with each other to form a combined embodiment without violating the principle logic. Due to space limitations, the present disclosure will not repeat them. It can be understood by those skilled in the art that in the above-mentioned method of the specific implementation method, the specific execution order of each step should be determined according to its function and possible internal logic.

[0235] In addition, the present disclosure also provides a data synchronization device, an electronic device, a computer-readable storage medium, and a program, all of which can be used to implement any data synchronization method provided by the present disclosure. The corresponding technical solutions and descriptions are referred to the corresponding records in the method part and will not be repeated here.

[0236] Figure 6 A block diagram of a data synchronization device according to an embodiment of the present disclosure is shown as follows: Figure 6 As shown, the device is applied to a terminal, and the device includes:

[0237] The receiving module 101 receives a first operation log in the target topic sent by the cloud server, because 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;

[0238] The first update module 102, upon receiving the first operation log sent by the cloud server, updates the local terminal database of the terminal according to the first operation log, thereby obtaining a terminal database with a first terminal state; wherein the first operation log indicates the existence of an operation on the cloud database of the cloud server, and a communication connection is established between the terminal and the cloud server via the message queue telemetry transmission protocol MQTT.

[0239] In a possible implementation, the device also includes: a state acquisition module, which is used to send a state acquisition request to the cloud server when a predetermined synchronization condition is met, and the state acquisition request is used to obtain a first cloud state of the cloud database, and the first cloud state represents the current database state of the cloud database; a first judgment module, which is used to determine whether the first cloud state matches the first terminal state when the first cloud state sent by the cloud server is received; a snapshot acquisition module, which is used to obtain the current first snapshot information of the cloud database when the first cloud state does not match the first terminal state; a second update module, which is used to update 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 duration of the interruption of 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 restored.

[0240] In a possible implementation, the device also includes: a second judgment module, used to judge whether the second terminal state matches the first cloud state; a difference log acquisition module, used to send a difference log acquisition request to the cloud server when the second terminal state does not match the first cloud state, and the difference log acquisition request is used to obtain the difference operation log corresponding to the first cloud state; a third update module, used to update the terminal database of the second terminal state according to the difference operation log when receiving the difference operation log sent by the cloud server, and obtain a terminal database with a third terminal state, and the third terminal state is the same as the first cloud state.

[0241] In a possible implementation, the device also includes: a snapshot topic subscription module, which is used to send a snapshot topic subscription request to the cloud server when a communication connection is initiated between the terminal and the cloud server, wherein the snapshot topic subscription request is used to subscribe to the snapshot topic of the cloud server to obtain the second snapshot information of the cloud database through the snapshot topic; a fourth update module, which is used to update the terminal database of the first terminal state according to the obtained second snapshot information to obtain a terminal database with a fourth terminal state.

[0242] In a possible implementation, after the terminal database of the first terminal state is updated according to the acquired second snapshot information to obtain the terminal database with the fourth terminal state, the device further includes: a target topic subscription module, which is used to send a target topic subscription request to the cloud server to subscribe to the target topic in the cloud server; a third judgment module, which is used to determine whether the second operation log matches the terminal database of the fourth terminal state when receiving the second operation log in the target topic sent by the cloud server; an interval log acquisition module, which is used to send an interval log acquisition request to the cloud server when the second operation log does not match the terminal database of the fourth state, and the interval log acquisition request is used to obtain the interval operation log between the second operation log and the second snapshot information; a fifth update module, which is used to update the terminal database of the fourth terminal state according to the interval operation log and the second operation log when receiving the interval operation log sent by the cloud server to obtain a terminal database with a fifth terminal state, and the fifth terminal state is the same as the second cloud state of the cloud database.

[0243] In a possible implementation, the device also includes: an update request sending module, which is used to send a data update request to the cloud server in response to an operation on a terminal database local to the terminal, and the data update request is used to indicate an update of the cloud database corresponding to the operation.

[0244] In the embodiment of the present disclosure, when there is a communication connection between the terminal and the cloud server and the terminal has subscribed to the target topic, the cloud server can push the first operation log in the target topic to the terminal that has 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 in the publish / subscribe mode based on the MQTT protocol in an unstable network, while ensuring data consistency and reducing the number of network requests so that the cloud server can access a large number of terminals with high scalability.

[0245] Figure 7 A block diagram of a data synchronization device according to an embodiment of the present disclosure is shown as follows: Figure 7 As shown, the device is applied to a cloud server, and the device includes:

[0246] A determination module 301 is used to determine, when there is an operation on the cloud database, a first operation log corresponding to the operation on the cloud database;

[0247] The publishing module 302 is used to publish the first operation log to the target topic of the cloud server, and send the first operation log in the target topic to the terminal that has subscribed to the target topic, so that the terminal updates the local terminal database of the terminal according to the first operation log.

[0248] In a possible implementation, the device also includes: a cloud status sending module, which is used to send the first cloud status of the cloud database to the terminal when receiving a status acquisition request sent by the terminal, so that the terminal updates the terminal database based on the first cloud status, wherein the first cloud status is the current database status of the cloud database.

[0249] In one possible implementation, the device also includes: a difference log sending module, which is used to send a difference operation log corresponding to the first cloud state of the cloud database to the terminal when a difference log acquisition request sent by the terminal is received, so that the terminal updates the terminal database according to the difference operation log.

[0250] In a possible implementation, the device also includes: a snapshot module, which is used to take a snapshot of the current full operation log of the cloud database according to a preset period to obtain snapshot information; a snapshot publishing module, which is used to publish the snapshot information to the snapshot topic subscribed by the terminal, so as to send the snapshot information to the terminal through the snapshot topic.

[0251] In a possible implementation, the device also includes: a cloud update module, which is used to update the cloud database according to the operation indicated by the data update request when a data update request sent by the terminal is received, and the data update request is triggered in response to the operation on the terminal database.

[0252] In the embodiment of the present disclosure, when there is a communication connection between the terminal and the cloud server and the terminal has subscribed to the target topic, the cloud server can push the first operation log in the target topic to the terminal that has subscribed to the target topic to update the terminal database, as well as the communication connection established between the terminal and the cloud server through the MQTT protocol, so that data synchronization in the publish / subscribe mode can be efficiently implemented based on the MQTT protocol in an unstable network, and data consistency can be guaranteed at the same time, so that the cloud server can access a large number of terminals with high scalability.

[0253] In some embodiments, the functions or modules included in the device provided by the embodiments of the present disclosure can be used to execute the method described in the above method embodiments. The specific implementation can refer to the description of the above method embodiments, and for the sake of brevity, it will not be repeated here.

[0254] The embodiment of the present disclosure also provides a computer-readable storage medium, on which computer program instructions are stored, and when the computer program instructions are executed by a processor, the above method is implemented. The computer-readable storage medium may be a non-volatile computer-readable storage medium.

[0255] An embodiment of the present disclosure further proposes an electronic device, comprising: a processor; and a memory for storing instructions executable by the processor; wherein the processor is configured to call the instructions stored in the memory to execute the above method.

[0256] The embodiments of the present disclosure also provide a computer program product, including a computer-readable code. When the computer-readable code is executed on a device, a processor in the device executes instructions for implementing the data synchronization method provided in any of the above embodiments.

[0257] The embodiments of the present disclosure also provide another computer program product for storing computer-readable instructions, which, when executed, enable a computer to perform the operations of the data synchronization method provided in any of the above embodiments.

[0258] The electronic device may be provided as a terminal, a server, or a device in other forms.

[0259] Figure 8 A block diagram of an electronic device 800 according to an embodiment of the present disclosure is shown. 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.

[0260] Reference Figure 8, the electronic device 800 may include one or more of the following components: a processing component 802 , a memory 804 , a power component 806 , a multimedia component 808 , an audio component 810 , an input / output (I / O) interface 812 , a sensor component 814 , and a communication component 816 .

[0261] The processing component 802 generally controls the overall operation of the electronic device 800, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 802 may include one or more processors 820 to execute instructions to complete all or part of the steps of the above-mentioned method. In addition, the processing component 802 may include one or more modules to facilitate the interaction between the processing component 802 and other components. For example, the processing component 802 may include a multimedia module to facilitate the interaction between the multimedia component 808 and the processing component 802.

[0262] The memory 804 is configured to store various types of data to support operations on the electronic device 800. Examples of such data include instructions for any application or method operating on the electronic device 800, contact data, phone book data, messages, pictures, videos, etc. The memory 804 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, 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 disk or optical disk.

[0263] The power supply component 806 provides power to the various components of the electronic device 800. The power supply component 806 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the electronic device 800.

[0264] The multimedia component 808 includes a screen that provides an output interface between the electronic device 800 and the 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 input signals from the 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 boundaries of the 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 camera and / or a rear camera. When the electronic device 800 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.

[0265] The audio component 810 is configured to output and / or input audio signals. For example, the audio component 810 includes a microphone (MIC), and when the electronic device 800 is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 804 or sent via the communication component 816. In some embodiments, the audio component 810 also includes a speaker for outputting audio signals.

[0266] I / O interface 812 provides an interface between processing component 802 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: home button, volume button, start button, and lock button.

[0267] The sensor assembly 814 includes one or more sensors for providing various aspects of status assessment for the electronic device 800. For example, the sensor assembly 814 can detect the open / closed state of the electronic device 800, the relative positioning of the components, such as the display and keypad of the electronic device 800, and the sensor assembly 814 can also detect the position change of the electronic device 800 or a component of the electronic device 800, the presence or absence of contact between the user and the electronic device 800, the orientation or acceleration / deceleration of the electronic device 800, and the temperature change of the electronic device 800. The 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 an optical sensor, such as a complementary metal oxide semiconductor (CMOS) or a 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.

[0268] The communication component 816 is configured to facilitate wired or wireless communication between the electronic device 800 and other devices. The electronic device 800 can 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 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.

[0269] 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, microcontrollers, microprocessors, or other electronic components to perform the above methods.

[0270] In an exemplary embodiment, a non-volatile computer-readable storage medium is also provided, such as a memory 804 including computer program instructions, which can be executed by a processor 820 of an electronic device 800 to perform the above method.

[0271] Fig. 9 1 is a block diagram of an electronic device 1900 according to an embodiment of the present disclosure. For example, the electronic device 1900 may be provided as a server. Fig. 9 , the electronic device 1900 includes a processing component 1922, which further includes one or more processors, and a memory resource represented by a memory 1932 for storing instructions executable by the processing component 1922, such as an application. The application stored in the memory 1932 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 1922 is configured to execute instructions to perform the above method.

[0272] The electronic device 1900 may also include a power supply 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 stored in the memory 1932, such as a Microsoft Server operating system (Windows Server 2003). TM), a graphical user interface operating system launched by Apple (Mac OSX TM ), a multi-user, multi-process computer operating system (Unix TM ), a free and open source Unix-like operating system (Linux TM ), an open source Unix-like operating system (FreeBSD TM ) or similar.

[0273] In an exemplary embodiment, a non-volatile computer-readable storage medium is also provided, such as a memory 1932 including computer program instructions, which can be executed by the processing component 1922 of the electronic device 1900 to perform the above method.

[0274] The present disclosure may be a system, a method and / or a computer program product. The computer program product may include a computer-readable storage medium carrying computer-readable program instructions for causing a processor to implement various aspects of the present disclosure.

[0275] Computer readable storage medium can be a tangible device that can hold and store instructions used by an instruction execution device. Computer readable storage medium can be, for example, (but not limited to) an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination thereof. More specific examples (non-exhaustive list) of computer readable storage medium include: a portable computer disk, 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 disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, for example, a punch card or a convex structure in a groove on which instructions are stored, and any suitable combination thereof. The computer readable storage medium used here is not interpreted as a transient signal itself, such as a radio wave or other freely propagating electromagnetic wave, an electromagnetic wave propagated by a waveguide or other transmission medium (for example, a light pulse by an optical fiber cable), or an electrical signal transmitted by a wire.

[0276] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded 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 can include copper transmission cables, optical fiber transmissions, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.

[0277] The computer program instructions for performing the operation of the present disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages, such as Smalltalk, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. Computer-readable program instructions may be executed completely on a user's computer, partially on a user's computer, as an independent software package, partially on a user's computer, partially on a remote computer, or completely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider to connect via the Internet). In some embodiments, an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA), may be customized by utilizing the state information of the computer-readable program instructions, and the electronic circuit may execute the computer-readable program instructions, thereby realizing various aspects of the present disclosure.

[0278] Various aspects of the present disclosure are described herein with reference to the flowcharts and / or block diagrams of the methods, devices (systems) and computer program products according to the embodiments of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer-readable program instructions.

[0279] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processor of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.

[0280] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operating steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.

[0281] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to multiple embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a part of a module, program segment or instruction, and a part of the module, program segment or instruction includes one or more executable instructions for realizing the specified logical function. In some alternative implementations, the function marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous square boxes can actually be executed substantially in parallel, and they can sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs the specified function or action, or can be implemented with a combination of special hardware and computer instructions.

[0282] The computer program product may be implemented in hardware, software or a combination thereof. In one optional embodiment, the computer program product is embodied as a computer storage medium, and in another optional embodiment, the computer program product is embodied as a software product, such as a software development kit (SDK) and the like.

[0283] The embodiments of the present disclosure have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.

Claims

1. A data synchronization method, It is characterized in that Applied to terminals, including: When there is a communication connection between the terminal and the cloud server and the terminal has subscribed to a target topic of the cloud server, receiving a first operation log in the target topic sent by the cloud server; When receiving the first operation log sent by the cloud server, updating the local terminal database of the terminal according to the first operation log to obtain a terminal database with a first terminal state; Wherein, the first operation log indicates that there is an operation on the cloud database of the cloud server, and a communication connection is established between the terminal and the cloud server via the message queue telemetry transmission protocol MQTT; Wherein, the method further comprises: In the case where a communication connection is initiated between the terminal and the cloud server, a snapshot topic subscription request is sent to the cloud server, wherein the snapshot topic subscription request is used to subscribe to a snapshot topic of the cloud server to obtain second snapshot information of the cloud database through the snapshot topic; According to the acquired second snapshot information, the terminal database of the first terminal state is updated to obtain a terminal database of a fourth terminal state; Sending a target topic subscription request to the cloud server to subscribe to the target topic in the cloud server; Upon receiving the second operation log in the target topic sent by the cloud server, determining whether the second operation log matches the terminal database of the fourth terminal state; In the case where the second operation log does not match the terminal database of the fourth terminal state, sending an interval log acquisition request to the cloud server, wherein the interval log acquisition request is used to acquire the interval operation log between the second operation log and the second snapshot information; When the interval operation log sent by the cloud server is received, the terminal database of the fourth terminal state is updated according to the interval operation log and the second operation log to obtain a terminal database with a fifth terminal state, and the fifth terminal state is the same as the second cloud state of the cloud database.

2. The method according to claim 1, It is characterized in that The method further comprises: When a predetermined synchronization condition is met, sending a status acquisition request to the cloud server, wherein the status acquisition request is used to acquire a first cloud status of the cloud database, wherein the first cloud status represents a current database status of the cloud database; Upon receiving the first cloud state sent by the cloud server, determining whether the first cloud state matches the first terminal state; When the first cloud state does not match the first terminal state, obtaining current first snapshot information of the cloud database; According to the acquired first snapshot information, the terminal database of the first terminal state is updated to obtain a terminal database of the second terminal state; The predetermined synchronization condition includes: the duration of the interruption of 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 restored.

3. The method according to claim 2, It is characterized in that The method further comprises: Determining whether the second terminal state matches the first cloud state; When the second terminal state does not match the first cloud state, sending a difference log acquisition request to the cloud server, the difference log acquisition request is used to acquire a difference operation log corresponding to the first cloud state; When the difference operation log sent by the cloud server is received, the terminal database of the second terminal state is updated according to the difference operation log to obtain a terminal database with a third terminal state, and the third terminal state is the same as the first cloud state.

4. The method according to any one of claims 1 to 3, It is characterized in that The method further comprises: In response to an operation on a local terminal database of the terminal, a data update request is sent to the cloud server, where the data update request is used to instruct the cloud database to be updated corresponding to the operation.

5. A data synchronization method, It is characterized in that Applied to a cloud server, the method includes: In the case where there is an operation on the cloud database, determining a first operation log corresponding to the operation on the cloud database; Publishing the first operation log to a target topic of a cloud server, and sending the first operation log in the target topic to a terminal that has subscribed to the target topic, so that the terminal updates a local terminal database of the terminal according to the first operation log to obtain a terminal database with a first terminal state; Wherein, the terminal is also used for: In the case of initiating a communication connection with the cloud server, sending a snapshot topic subscription request to the cloud server, wherein the snapshot topic subscription request is used to subscribe to a snapshot topic of the cloud server to obtain second snapshot information of the cloud database through the snapshot topic; According to the acquired second snapshot information, the terminal database of the first terminal state is updated to obtain a terminal database of a fourth terminal state; Sending a target topic subscription request to the cloud server to subscribe to the target topic in the cloud server; Upon receiving the second operation log in the target topic sent by the cloud server, determining whether the second operation log matches the terminal database of the fourth terminal state; In the case where the second operation log does not match the terminal database of the fourth terminal state, sending an interval log acquisition request to the cloud server, wherein the interval log acquisition request is used to acquire the interval operation log between the second operation log and the second snapshot information; When the interval operation log sent by the cloud server is received, the terminal database of the fourth terminal state is updated according to the interval operation log and the second operation log to obtain a terminal database with a fifth terminal state, and the fifth terminal state is the same as the second cloud state of the cloud database.

6. The method according to claim 5, It is characterized in that The method further comprises: When receiving a status acquisition request sent by the terminal, a first cloud status of the cloud database is sent to the terminal, so that the terminal updates the terminal database based on the first cloud status, wherein the first cloud status is a current database status of the cloud database.

7. The method according to claim 5 or 6, It is characterized in that The method further comprises: When a difference log acquisition request sent by the terminal is received, a difference operation log corresponding to the first cloud state of the cloud database is sent to the terminal, so that the terminal updates the terminal database according to the difference operation log.

8. The method according to claim 5 or 6, It is characterized in that The method further comprises: Taking a snapshot of the current full operation log of the cloud database according to a preset period to obtain snapshot information; The snapshot information is published to the snapshot topic subscribed by the terminal, so as to send the snapshot information to the terminal through the snapshot topic.

9. The method according to claim 5 or 6, It is characterized in that The method further comprises: When receiving a data update request sent by the terminal, the cloud database is updated according to the operation indicated by the data update request, and the data update request is triggered in response to the operation on the terminal database.

10. A data synchronization device, It is characterized in that Applied to terminals, including: A receiving module, which receives a first operation log in the target topic sent by the cloud server, 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; A first updating module, in the case of receiving the first operation log sent by the cloud server, updates the terminal database local to the terminal according to the first operation log to obtain a terminal database with a first terminal state; wherein the first operation log indicates that there is an operation on the cloud database of the cloud server, and a communication connection is established between the terminal and the cloud server through the message queue telemetry transmission protocol MQTT; Wherein, the device further comprises: a snapshot topic subscription module, configured to send a snapshot topic subscription request to the cloud server when a communication connection is initiated between the terminal and the cloud server, wherein the snapshot topic subscription request is used to subscribe to a snapshot topic of the cloud server to obtain second snapshot information of the cloud database through the snapshot topic; a fourth updating module, configured to update the terminal database of the first terminal state according to the acquired second snapshot information, so as to obtain a terminal database of a fourth terminal state; A target topic subscription module, used to send a target topic subscription request to the cloud server to subscribe to the target topic in the cloud server; A third judgment module is used to judge whether the second operation log matches the terminal database of the fourth terminal state when receiving the second operation log in the target topic sent by the cloud server; an interval log acquisition module, configured to send an interval log acquisition request to the cloud server when the second operation log does not match the terminal database of the fourth terminal state, wherein the interval log acquisition request is used to acquire the interval operation log between the second operation log and the second snapshot information; The fifth update module is used to update the terminal database of the fourth terminal state according to the interval operation log and the second operation log when receiving the interval operation log sent by the cloud server, so as to obtain a terminal database with a fifth terminal state, and the fifth terminal state is the same as the second cloud state of the cloud database.

11. A data synchronization device, It is characterized in that Applied to cloud servers, including: A determination module, configured to, when there is an operation on the cloud database, determine a first operation log corresponding to the operation on the cloud database; A publishing module, used for publishing the first operation log to a target topic of a cloud server, and sending the first operation log in the target topic to a terminal that has subscribed to the target topic, so that the terminal updates a local terminal database of the terminal according to the first operation log to obtain a terminal database with a first terminal state; Wherein, the terminal is also used for: In the case of initiating a communication connection with the cloud server, sending a snapshot topic subscription request to the cloud server, wherein the snapshot topic subscription request is used to subscribe to a snapshot topic of the cloud server to obtain second snapshot information of the cloud database through the snapshot topic; According to the acquired second snapshot information, the terminal database of the first terminal state is updated to obtain a terminal database of a fourth terminal state; Sending a target topic subscription request to the cloud server to subscribe to the target topic in the cloud server; Upon receiving the second operation log in the target topic sent by the cloud server, determining whether the second operation log matches the terminal database of the fourth terminal state; In the case where the second operation log does not match the terminal database of the fourth terminal state, sending an interval log acquisition request to the cloud server, wherein the interval log acquisition request is used to acquire the interval operation log between the second operation log and the second snapshot information; When the interval operation log sent by the cloud server is received, the terminal database of the fourth terminal state is updated according to the interval operation log and the second operation log to obtain a terminal database with a fifth terminal state, and the fifth terminal state is the same as the second cloud state of the cloud database.

12. An electronic device, It is characterized in that include: processor; a memory for storing processor-executable instructions; The processor is configured to call the instructions stored in the memory to execute the method described in any one of claims 1 to 9.

13. A computer-readable storage medium having computer program instructions stored thereon, It is characterized in that When the computer program instructions are executed by a processor, the method according to any one of claims 1 to 9 is implemented.