Iot scenario data synchronization method, device and storage medium
Patent Information
- Application Number
- CN202211459348.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-21
- Publication Date
- 2026-10-23
- Estimated Expiration
- 2042-11-21
AI Technical Summary
[0004]为了解决现有技术中的上述问题,即为了解决现有技术由于数据量较大导致数据混乱的情况,无法保证数据的准确性的问题,本发明提供了一种物联网场景数据同步方法,包括:
[0036]本领域技术人员能够理解的是,本发明提供的物联网场景数据同步方法、设备及存储介质,通过获取消息队列中的数据包,所述消息队列为集群服务器建立的用于存储生产终端发送的数据包的队列,所述数据包中包括数据标识、物联网场景数据的变更信息;根据所述数据标识得到内存标识,并根据所述内存标识将所述数据包存储至内存队列中;根据所述变更信息更新数据库中的数据,并保存更新后的数据的手段,实现生产终端数据被分类存储到内存队列中,并且在内存队列中保持同类时间有序性,避免多线程处理任务过程中出现数据丢失情况,提高同步数据的准确性。
Smart Images

Figure CN115774756B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of data processing technology, specifically relating to a data synchronization method, device, and storage medium for Internet of Things (IoT) scenarios. Background Technology
[0002] IoT scenario data is a special type of e-commerce data, unlike ordinary product data. Scenario data needs to vividly present scenario-related content to users. This content, combined with general e-commerce data, will generate even more data.
[0003] When existing technologies process scene data by directly acquiring it, the large amount of data can lead to data corruption and make it impossible to guarantee the accuracy of the data. Summary of the Invention
[0004] To address the aforementioned problems in existing technologies, specifically the issue of data corruption due to large data volumes and the inability to guarantee data accuracy, this invention provides a data synchronization method for IoT scenarios, comprising:
[0005] Retrieve data packets from the message queue, which is a queue established by the cluster server to store data packets sent by production terminals. The data packets include data identifiers and change information of IoT scenario data.
[0006] The memory identifier is obtained based on the data identifier, and the data packet is stored in the memory queue based on the memory identifier;
[0007] Update the data in the database according to the change information, and save the updated data.
[0008] In one possible design, the change information includes a change type and change content; the step of obtaining a memory identifier based on the data identifier and storing the data packet in a memory queue based on the memory identifier includes:
[0009] Based on the change type, determine the target memory queue corresponding to the change type, wherein different change types correspond to different memory queues;
[0010] A memory identifier is obtained based on the data identifier. The memory identifier is used to indicate the location of the target slice in the target memory queue. The memory queue is divided into multiple slices, and the multiple slices are sorted in a preset order.
[0011] Based on the location of the target fragment, the data packet is stored in the target fragment of the target memory queue.
[0012] In one possible design, obtaining the memory identifier based on the data identifier includes:
[0013] The remainder is obtained by performing a modulo operation on the number of segments based on the data identifier, wherein the data identifier is one of store number, store number, or scene number;
[0014] The remainder is used as the memory identifier, and the remainder is used to indicate the position of the target fragment among the plurality of fragments.
[0015] In one possible design, updating the data in the database based on the change information includes:
[0016] Multiple processing threads are started, and each processing thread corresponds to a memory queue.
[0017] Each processing thread is controlled to update the data in the database based on the change information in the memory queue.
[0018] In one possible design, after saving the updated data, the method further includes:
[0019] A consumption success message is sent to the cluster server, indicating that the data sent by the production terminal has been synchronized to the database of the consumption terminal.
[0020] In one possible design, the same store corresponds to multiple branches, and the same branch corresponds to multiple scenarios. After saving the updated data, the method further includes:
[0021] Based on the data source interface, obtain the first quantity of scenarios under the target store;
[0022] In the database, based on the scenario number of each scenario, a second number of scenarios under the target store is obtained; wherein, the scenario number is used to indicate the store and outlet to which the scenario belongs, and different scenario numbers are different;
[0023] If the first quantity is different from the second quantity, then update the data in the database.
[0024] In one possible design, if the first quantity differs from the second quantity, the data in the database is updated, including:
[0025] Based on the data source interface, obtain the first scenario list under the target store;
[0026] Based on the database, obtain the second scenario list under the target store;
[0027] The first scene list is compared with the second scene list. The missing data in the database is supplemented according to the missing scenes in the second scene list, and the data corresponding to the redundant scenes in the second scene list is deleted from the database.
[0028] Secondly, this application provides a data synchronization device for an Internet of Things (IoT) scenario, comprising:
[0029] The acquisition module is used to acquire data packets in the message queue. The message queue is a queue established by the cluster server to store data packets sent by production terminals. The data packets include data identifiers and change information of IoT scenario data.
[0030] The processing module is used to obtain a memory identifier based on the data identifier, and store the data packet into a memory queue based on the memory identifier;
[0031] The synchronization module is used to update the data in the database according to the change information and save the updated data.
[0032] Thirdly, this application provides an electronic device, including: a processor, and a memory communicatively connected to the processor;
[0033] The memory stores computer-executed instructions;
[0034] The processor executes computer execution instructions stored in the memory to implement a data synchronization method for IoT scenarios.
[0035] Fourthly, this application provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement a data synchronization method for an Internet of Things (IoT) scenario.
[0036] Those skilled in the art will understand that the IoT scenario data synchronization method, device, and storage medium provided by the present invention, by acquiring data packets in a message queue (a queue established by a cluster server for storing data packets sent by production terminals, the data packets including data identifiers and IoT scenario data change information); obtaining memory identifiers based on the data identifiers, and storing the data packets in a memory queue based on the memory identifiers; updating data in the database based on the change information, and saving the updated data, enables production terminal data to be categorized and stored in a memory queue, and maintains the temporal order of similar data in the memory queue, avoiding data loss during multi-threaded task processing and improving the accuracy of synchronized data. Attached Figure Description
[0037] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0038] Figure 1 This is a schematic diagram illustrating the application scenario of IoT data synchronization provided in the embodiments of this application;
[0039] Figure 2 A flowchart illustrating the IoT scenario data synchronization method provided in this application embodiment. Figure 1 ;
[0040] Figure 3 A flowchart illustrating the IoT scenario data synchronization method provided in this application embodiment. Figure 2 ;
[0041] Figure 4 This is a schematic diagram of the structure of an IoT scenario data synchronization device provided in an embodiment of this application;
[0042] Figure 5 This is a schematic diagram of the hardware structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0043] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numerals in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims, and not all embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without inventive effort are within the scope of protection of this invention.
[0044] Figure 1 This is a schematic diagram illustrating an application scenario of the IoT data synchronization method provided in this application embodiment. For example... Figure 1 As shown, the user adjusts the data through the production terminal 101, and the adjusted content is sent to the cluster server 102 in the form of data packets. The consumer terminal 103 obtains the data packets from the cluster server 102 for processing. In order to improve the data processing efficiency, a multi-threaded data processing method is adopted, that is, multiple memory queues are set in the consumer terminal 103, and multiple memory queues process multiple data packets in parallel. However, when processing scene data, this method may cause data disorder due to the large amount of data, and the accuracy of the data cannot be guaranteed.
[0045] For example, a production terminal sends messages to the cluster server to delete a link and then establish a new link, aiming to delete the existing link and then re-establish it. Since these are two commands, the cluster server stores them as two data packets in two message queues. However, due to the different processing speeds of multi-threaded processes, the later-sent link-establishing message is delivered to the consumer terminal first. The consumer terminal responds to the link-establishing network request by creating a new link. Then, the consumer terminal receives a link-deleting network request, and can only respond to the user's link-deleting network request by deleting the new link. The end result is that although the consumer terminal processes both data packets, it does not actually execute the production terminal's goal of creating a new link. The timing of multi-threaded processing leads to the loss of correct processing results, ultimately resulting in the loss of data pushed by the production terminal during synchronization, severely impacting data accuracy.
[0046] The IoT scenario data synchronization method provided in this application aims to solve the above-mentioned technical problems in the prior art. In order to avoid the timing disorder of multiple data packets during multi-threaded data processing, it is necessary to classify and store data packets. Therefore, when generating data packets, data packets need to be identified so that data of the same change type have the same data identifier. That is, newly created links and deleted links belong to the same change type of data. Then, data of the same change type can be divided into the same memory queue according to the data identifier. In the same memory queue, the first-in-first-out principle can be followed to ensure normal timing. The consumer terminal 103 updates the data in the database according to the data packets in the memory queue and saves it, so that the data in the database is consistent with the data in the production terminal 101, thus completing the data synchronization.
[0047] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will now be described with reference to the accompanying drawings.
[0048] Figure 2 A flowchart illustrating the IoT scenario data synchronization method provided in this application embodiment. Figure 1 .like Figure 2 As shown, the method includes:
[0049] S201. Obtain data packets from the message queue, wherein the message queue is a queue established by the cluster server to store data packets sent by production terminals, and the data packets include data identifiers and change information of IoT scenario data.
[0050] Specifically, scenario data is a special type of e-commerce data, unlike ordinary product data. Scenario data needs to vividly present scenario-related content to users, which requires more presentation methods, such as VR, image anchors, and scenario-related usage of products.
[0051] This content, combined with general e-commerce data, generates even more data, such as product data, various image data, image anchor data, scene sales area data, scene tag data, etc. Combined with data from various stores and outlets, it generates a large amount of data for consumer terminal applications to use. This data is not static; it changes with the producer's decisions. Therefore, the producer needs to feed these changes back to the consumer terminal through the production terminal to keep the data of the consumer terminal and the production terminal synchronized, thereby ensuring that the application uses the correct data.
[0052] Those skilled in the art will understand that, in order to ensure data accuracy, when a cluster server receives a data packet sent by a production terminal, the data packet is classified so that data of the same change type is stored in the same message queue of the cluster server in chronological order. The multiple data packets obtained by the consumer terminal from the same message queue are arranged in chronological order, thereby avoiding the loss of results.
[0053] To achieve the goal of data classification and storage, the production terminal must identify the data when sending it. The cluster server generates data identifiers and IoT scenario data change information based on the data sent by the production terminal. The message queue stores the data in separate queues based on the data identifiers and IoT scenario data change information.
[0054] S202. Obtain a memory identifier based on the data identifier, and store the data packet in a memory queue based on the memory identifier;
[0055] Specifically, after the consumer terminal obtains a data packet from the message queue of the cluster server, it first determines the change type of the data based on the change information. Data packets with the same change type are stored in the same memory queue. The same data identifier corresponds to the same change type, and the same data identifier corresponds to the same memory identifier. Thus, data packets with the same change type are stored in the same memory queue.
[0056] S203. Update the data in the database according to the change information and save the updated data.
[0057] Specifically, multiple threads are used to process data packets in multiple memory queues simultaneously. For each memory queue, the changes in the data are determined based on the data packet change information. The data already stored in the database is updated according to the changes. After the update, a save operation is performed to save the updated data in the database, thereby completing the data synchronization process.
[0058] The method provided in this embodiment obtains data packets from a message queue, which is a queue established by a cluster server to store data packets sent by production terminals. The data packets include data identifiers and change information of IoT scenario data. A memory identifier is obtained based on the data identifier, and the data packets are stored in the memory queue according to the memory identifier, wherein the same data identifier corresponds to the same memory identifier. Data in the database is updated based on the change information in the memory queue, and the updated data is saved. This method enables production terminal data to be categorized and stored in the memory queue, maintaining the temporal order of similar data in the memory queue, avoiding data loss during multi-threaded task processing, and improving the accuracy of synchronized data.
[0059] The IoT scenario data synchronization method of this application will be described in detail below with reference to a specific embodiment.
[0060] Figure 3 A flowchart illustrating the IoT scenario data synchronization method provided in this application embodiment. Figure 2 .like Figure 3 As shown, the method includes:
[0061] S301. Obtain data packets from the message queue, wherein the message queue is a queue established by the cluster server to store data packets sent by production terminals, and the data packets include data identifiers and change information of IoT scenario data;
[0062] Specifically, the data sent by the production terminals is categorized so that data from the same processing task is stored in the same message queue on the cluster server in chronological order. The multiple data packets retrieved by the consumer terminals from the same message queue are then arranged in chronological order. To achieve this categorized data storage, the production terminals identify the data before sending it. The cluster server generates data identifiers and IoT scenario data change information based on the data sent by the production terminals. The message queue then stores the data in separate queues based on these identifiers and change information. The data packets retrieved by the consumer terminals from the message queue are those with both data identifiers and change information.
[0063] S302. The change information includes change type and change content. Based on the change type, the target memory queue corresponding to the change type is determined, wherein different change types correspond to different memory queues.
[0064] Specifically, the change information in the acquired data packets includes change type and change content. Change types include store shelf removal / removal, store status change, store sales scope change, supplier sales scope change, project manager service scope change, scenario change, store information change, etc. That is, the same change type processes data within the same scope in the database. Therefore, by storing data packets in different memory queues according to different change types, it can be ensured that the same tasks can be processed sequentially according to time order when processing data. The memory queue determined according to the change type is the target memory queue.
[0065] S303. Perform a modulo operation on the number of shards according to the data identifier to obtain the remainder, wherein the data identifier is one of store number, store number or scene number, and the memory queue is divided into multiple shards, which are sorted in a preset order.
[0066] Specifically, the data identifiers in the data packets include store number, store number, or scene number. A scene is equivalent to a product being sold. The scope of a store is broader than the scope of a store, and the scope of a store is broader than the scope of a scene. Each scene can only uniquely correspond to one store, and each store can only uniquely correspond to one store. After determining the target memory queue based on the change type, the target memory queue needs to be further fragmented. This means that tasks from the same store, store, or scene are processed together. The fragmentation is based on the remainder obtained by modulo the data identifier with the number of fragments. Since the number of fragments is fixed, the remainder obtained by modulo the same data identifier with the number of fragments is also the same. This ensures that the same task with the same data identifier is assigned to the same fragment, thus ensuring that data packets with the same data identifier and the same change information are stored in the same fragment. Furthermore, the first-in-first-out principle is followed within the fragments to ensure accurate data packet timing.
[0067] S304. The remainder is used as the memory identifier, the remainder is used to indicate the position of the target fragment in the plurality of fragments, wherein the memory identifier is used to indicate the position of the target fragment in the target memory queue, and the same data identifier corresponds to the same memory identifier;
[0068] Specifically, the remainder obtained after the modulo operation needs to correspond to the slice of the memory queue in order to find the corresponding slice storage location. Therefore, the remainder is used as a memory identifier to define the slice of the memory queue. The corresponding slice storage location can be found in the memory queue based on the remainder, that is, the target slice is found based on the remainder. This ensures that data with the same remainder can find the same slice storage location in multiple slices, further guaranteeing the timing of processing tasks with the same data identifier.
[0069] S305. Based on the location of the target fragment, store the data packet into the target fragment of the target memory queue;
[0070] Specifically, after finding the target fragment in the target memory queue based on the remainder, the data packet is stored in the target fragment, completing the migration of the data packet from the cluster server to the memory queue. The entire migration process does not disrupt the timing and integrity of the data.
[0071] S306. Start multiple processing threads, each processing thread corresponding to a memory queue;
[0072] Specifically, in order to improve the efficiency of synchronous processing tasks, a multi-threaded processor is used to process multiple tasks synchronously. Each thread processes a memory queue. Since each memory queue is stored in segments according to pre-set rules, namely based on change type and data identifier, the processor only needs to process data packets in chronological order, without worrying about timing disorder.
[0073] S307. Control each processing thread to update the data in the database according to the change information in the memory queue, and save the updated data;
[0074] Specifically, the database stores all previously stored data, while the change information in the data packet only contains the data that needs to be changed. If only the changed data is saved, it cannot be directly used by the application. Therefore, the changed data needs to be updated into the already saved data.
[0075] For example, for data packets containing scene changes, since different scenes correspond to different sales areas, it is necessary to calculate and update the sales area of the scene. In particular, when the store is listed, it will include the listing of scenes under the store. Each scene needs to limit the sales area of the corresponding store.
[0076] S308. Send a consumption success message to the cluster server. The consumption success message is used to indicate that the data sent by the production terminal has been synchronized to the database of the consumption terminal.
[0077] Specifically, after saving the updated data, the consumer terminal indicates that it has successfully consumed the data packet. At this point, it needs to send feedback to the production terminal to let it know whether the pushed data has been synchronized to the consumer terminal. Therefore, the consumer terminal needs to send a consumption success message to the production terminal. Since the production terminal transmits data to the consumer terminal through the cluster server, the consumer terminal also needs to go through the cluster server when transmitting data to the production terminal. That is, the consumer terminal sends a consumption success message to the cluster server, and after receiving the consumption success message, the cluster server sends it to the production terminal. After receiving the consumption success message, the production terminal confirms that the data synchronization is complete.
[0078] S309. Based on the data source interface, obtain the first number of scenarios under the target store, where the same store corresponds to multiple stores and the same store corresponds to multiple scenarios.
[0079] Specifically, the current data information of the production terminal can be obtained through the data source interface provided by the production terminal.
[0080] S310. In the database, based on the scenario number of each scenario, obtain the second number of scenarios under the target store; wherein, the scenario number is used to indicate the store and outlet to which the scenario belongs, and different scenario numbers are different;
[0081] Specifically, the database of the consumer terminal stores the updated data information. Theoretically, if the synchronization operation is correct, the updated data information should be consistent with the data information obtained from the data source interface after the synchronization is completed. However, due to the large amount of data, directly comparing the data will consume a lot of computing resources and put a heavy burden on the processor. Therefore, the method of comparing the quantity first is adopted, and the data content is compared in detail when the data quantity is inconsistent. This method can greatly reduce the workload and reduce the system's computing burden.
[0082] When comparing data quantities, the smallest unit is prioritized for comparison, such as the number of scenes. However, calculating the number of scenes makes it difficult to pinpoint the problem after discrepancies are found. Therefore, the scope of scenes needs to be limited; here, we use stores as the limit. That is, the number of scenes under a target store can be obtained based on the scene number. This allows us to compare the number of scenes under the target store on the production terminal with the number of scenes under the target store on the consumer terminal. If they are the same, it indicates that the synchronization data of the target store is correct. The comparison then moves to the next target store, and so on, until the number of scenes under all stores has been compared. If the comparison reveals a difference in the number of scenes, it indicates a problem with the synchronization data, requiring further comparison of the specific scenes under the target store.
[0083] S311. Obtain the first scenario list under the target store based on the data source interface;
[0084] Specifically, based on further comparison of the specific scenarios under the target store, the first scenario list under the target store is obtained from the data source interface provided by the production terminal. The first scenario list includes the scenario number and the corresponding specific scenario information.
[0085] S312. Obtain the second scenario list under the target store based on the database;
[0086] Specifically, based on further comparison of the specific scenarios under the target store, a second scenario list under the target store is obtained from the consumer terminal database. The second scenario list includes the scenario number and the corresponding specific scenario information.
[0087] S313. Compare the first scene list with the second scene list, supplement the missing data in the database according to the missing scenes in the second scene list, and delete the data corresponding to the redundant scenes in the second scene list from the database.
[0088] Specifically, the scenario numbers in the first scenario list and the second scenario list are compared. The first scenario list at the production terminal is used as the standard. The extra scenario numbers and corresponding specific scenario information in the second scenario list are deleted from the database, or the missing first scenario numbers and corresponding specific scenario information in the second scenario list are added to the database to realize the detection and filling of missing data in the synchronization.
[0089] The method provided in this embodiment obtains data packets from a message queue, which is a queue established by a cluster server to store data packets sent by production terminals. The data packets include data identifiers and change information of IoT scenario data. The change information includes change type and change content. Based on the change type, the target memory queue corresponding to the change type is determined. Different change types correspond to different memory queues, thereby realizing an ordered synchronization process of storing data in queues according to data change type and improving the orderliness of data storage and consumption.
[0090] The number of shards is modulo-operated based on the data identifier to obtain the remainder. The data identifier is one of a store number, store number, or scene number. The memory queue is divided into multiple shards, which are sorted in a preset order. The remainder is used as the memory identifier, indicating the position of the target shard within the multiple shards. The memory identifier indicates the position of the target shard in the target memory queue; the same data identifier corresponds to the same memory identifier. Based on the position of the target shard, the data packet is stored in the target shard of the target memory queue. Multiple processing threads are started, each corresponding to a memory queue. Each processing thread updates the data in the database based on the change information in the memory queue and saves the updated data. This multi-threaded, queue-based data storage improves synchronization efficiency while ensuring data accuracy.
[0091] A consumption success message is sent to the cluster server, indicating that the data sent by the production terminal has been synchronized to the database of the consumption terminal. Based on the data source interface, a first number of scenarios under the target store is obtained, where the same store corresponds to multiple stores, and the same store corresponds to multiple scenarios. In the database, based on the scenario number of each scenario, a second number of scenarios under the target store is obtained, where the scenario number indicates the store and branch to which the scenario belongs, and different scenario numbers are different. Based on the data source interface, a first list of scenarios under the target store is obtained. Based on the database, a second list of scenarios under the target store is obtained. The first list of scenarios is compared with the second list of scenarios, and missing data in the database is supplemented based on missing scenarios in the second list of scenarios. Redundant data corresponding to scenarios in the second list of scenarios is deleted from the database. This simplifies the synchronization verification operation based on quantity, reduces computational resource consumption, and further ensures data accuracy.
[0092] In this embodiment of the invention, electronic devices or main control devices can be divided into functional modules according to the above method examples. For example, each function can be divided into its own functional modules, or two or more functions can be integrated into one processing unit. The integrated unit can be implemented in hardware or as a software functional module. It should be noted that the module division in this embodiment of the invention is illustrative and only represents one logical functional division; other division methods may be used in actual implementation.
[0093] Figure 4 This is a schematic diagram of the structure of the IoT scenario data synchronization device provided in this application. Figure 4 As shown, the device 40 includes:
[0094] The acquisition module 401 is used to acquire data packets in the message queue. The message queue is a queue established by the cluster server to store data packets sent by the production terminal. The data packets include data identifiers and change information of IoT scenario data.
[0095] Processing module 402 is used to obtain a memory identifier based on the data identifier, and store the data packet into a memory queue based on the memory identifier;
[0096] Specifically, the processing module 402 is used for: the change information including change type and change content; obtaining a memory identifier based on the data identifier, and storing the data packet in a memory queue based on the memory identifier, including:
[0097] Based on the change type, determine the target memory queue corresponding to the change type, wherein different change types correspond to different memory queues;
[0098] A memory identifier is obtained based on the data identifier. The memory identifier is used to indicate the location of the target slice in the target memory queue. The memory queue is divided into multiple slices, and the multiple slices are sorted in a preset order.
[0099] Based on the location of the target fragment, the data packet is stored in the target fragment of the target memory queue.
[0100] Furthermore, obtaining the memory identifier based on the data identifier includes:
[0101] The remainder is obtained by performing a modulo operation on the number of segments based on the data identifier, wherein the data identifier is one of store number, store number, or scene number;
[0102] The remainder is used as the memory identifier, and the remainder is used to indicate the position of the target fragment among the plurality of fragments.
[0103] Furthermore, updating the data in the database based on the change information in the memory queue includes:
[0104] Multiple processing threads are started, and each processing thread corresponds to a memory queue.
[0105] Each processing thread is controlled to update the data in the database based on the change information in the memory queue.
[0106] The synchronization module 403 is used to update the data in the database according to the change information and save the updated data.
[0107] Specifically, the synchronization module 403 is used to: after saving the updated data, the method further includes:
[0108] A consumption success message is sent to the cluster server, indicating that the data sent by the production terminal has been synchronized to the database of the consumption terminal.
[0109] Furthermore, if the same store corresponds to multiple branches, and the same branch corresponds to multiple scenarios, after saving the updated data, the method further includes:
[0110] Based on the data source interface, obtain the first quantity of scenarios under the target store;
[0111] In the database, based on the scenario number of each scenario, a second number of scenarios under the target store is obtained; wherein, the scenario number is used to indicate the store and outlet to which the scenario belongs, and different scenario numbers are different;
[0112] If the first quantity is different from the second quantity, then update the data in the database.
[0113] Furthermore, if the first quantity differs from the second quantity, the data in the database is updated, including:
[0114] Based on the data source interface, obtain the first scenario list under the target store;
[0115] Based on the database, obtain the second scenario list under the target store;
[0116] The first scene list is compared with the second scene list. The missing data in the database is supplemented according to the missing scenes in the second scene list, and the data corresponding to the redundant scenes in the second scene list is deleted from the database.
[0117] The IoT scene data synchronization device provided in this embodiment can execute the IoT scene data synchronization method of the above embodiment. Its implementation principle and technical effect are similar, and will not be described again here.
[0118] In the specific implementation of the aforementioned IoT scenario data synchronization device, each module can be implemented as a processor. The processor can execute computer execution instructions stored in the memory, thereby enabling the processor to execute the aforementioned IoT scenario data synchronization method.
[0119] Figure 5 A schematic diagram of the structure of the electronic device provided in this application. Figure 5 As shown, the electronic device 50 includes at least one processor 501 and a memory 502. The electronic device 50 also includes a communication component 503. The processor 501, memory 502, and communication component 503 are connected via a bus 504.
[0120] In the specific implementation process, at least one processor 501 executes the computer execution instructions stored in the memory 502, causing at least one processor 501 to execute the IoT scene data synchronization method executed on the electronic device side as described above.
[0121] The specific implementation process of processor 501 can be found in the above method embodiments, and its implementation principle and technical effect are similar. It will not be repeated here.
[0122] In the above embodiments, it should be understood that the processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), etc. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in this invention can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules within the processor.
[0123] The memory may include high-speed RAM, and may also include non-volatile storage (NVM), such as at least one disk storage.
[0124] The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of illustration, the buses shown in the accompanying drawings are not limited to a single bus or a single type of bus.
[0125] The above description of the functions implemented by electronic devices and main control devices has introduced the solutions provided by the embodiments of the present invention. It is understood that, in order to implement the above functions, the electronic device or main control device includes hardware structures and / or software modules corresponding to the execution of each function. By combining the units and algorithm steps of the various examples described in the embodiments of the present invention, the embodiments of the present invention can be implemented in hardware or a combination of hardware and computer software. Whether a function is executed by hardware or by computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the technical solutions of the embodiments of the present invention.
[0126] This application also provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, implement the above-mentioned data synchronization method for IoT scenarios.
[0127] The aforementioned computer-readable storage medium 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 storage, flash memory, magnetic disk, or optical disk. The readable storage medium can be any available medium accessible to a general-purpose or special-purpose computer.
[0128] An exemplary readable storage medium is coupled to a processor, enabling the processor to read information from and write information to the readable storage medium. Of course, the readable storage medium can also be a component of the processor. The processor and the readable storage medium can reside in an Application Specific Integrated Circuit (ASIC). Alternatively, the processor and the readable storage medium can exist as discrete components in an electronic device or a host device.
[0129] This method is widely used in whole-house intelligent digital control application scenarios such as smart homes, smart home ecosystems, and intelligence house ecosystems.
[0130] The aforementioned network may include, but is not limited to, at least one of the following: wired network, wireless network.
[0131] The aforementioned wired network may include, but is not limited to, at least one of the following: wide area network, metropolitan area network, local area network; the aforementioned wireless network may include, but is not limited to, at least one of the following: WIFI (Wireless Fidelity), Bluetooth.
[0132] Terminal devices are not limited to: PCs, mobile phones, tablets, smart air conditioners, smart range hoods, smart refrigerators, smart ovens, smart stoves, smart washing machines, smart water heaters, smart washing equipment, smart dishwashers, smart projectors, smart TVs, smart clothes racks, smart curtains, smart audio-visual equipment, smart sockets, smart speakers, smart speakers, smart fresh air systems, smart kitchen and bathroom equipment, smart bathroom equipment, smart robot vacuum cleaners, smart window cleaning robots, smart mopping robots, smart air purifiers, smart steam ovens, smart microwave ovens, smart water heaters, smart air purifiers, smart water dispensers, smart door locks, etc.
[0133] Those skilled in the art will understand that all or part of the steps of the above-described method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When executed, the program performs the steps of the above-described method embodiments; and the aforementioned storage medium includes various media capable of storing program code, such as ROM, RAM, magnetic disks, or optical disks.
[0134] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A data synchronization method for an Internet of Things (IoT) scenario, characterized in that, The method includes: Retrieve data packets from the message queue, which is a queue established by the cluster server to store data packets sent by production terminals. The data packets include data identifiers and change information of IoT scenario data; the change information includes change type and change content. Based on the change type, determine the target memory queue corresponding to the change type, wherein different change types correspond to different memory queues; obtain a memory identifier based on the data identifier, the memory identifier being used to indicate the location of the target fragment in the target memory queue, wherein the memory queue is divided into multiple fragments, and the multiple fragments are sorted in a preset order; based on the location of the target fragment, store the data packet in the target fragment of the target memory queue; Update the data in the database according to the change information, and save the updated data.
2. The IoT scenario data synchronization method according to claim 1, characterized in that, The step of obtaining the memory identifier based on the data identifier includes: The remainder is obtained by performing a modulo operation on the number of segments based on the data identifier, wherein the data identifier is one of store number, store number, or scene number; The remainder is used as the memory identifier, and the remainder is used to indicate the position of the target fragment among the plurality of fragments.
3. The IoT scenario data synchronization method according to claim 1, characterized in that, The step of updating the data in the database based on the change information includes: Multiple processing threads are started, and each processing thread corresponds to a memory queue. Each processing thread is controlled to update the data in the database based on the change information in the memory queue.
4. The IoT scenario data synchronization method according to claim 1, characterized in that, After saving the updated data, the method further includes: A consumption success message is sent to the cluster server, indicating that the data sent by the production terminal has been synchronized to the database of the consumption terminal.
5. The IoT scenario data synchronization method according to claim 2, characterized in that, The same store may correspond to multiple branches, and the same branch may correspond to multiple scenarios. After saving the updated data, the method further includes: Based on the data source interface, obtain the first quantity of scenarios under the target store; In the database, based on the scenario number of each scenario, a second number of scenarios under the target store is obtained; wherein, the scenario number is used to indicate the store and outlet to which the scenario belongs, and different scenario numbers are different; If the first quantity is different from the second quantity, then update the data in the database.
6. The IoT scenario data synchronization method according to claim 5, characterized in that, If the first quantity differs from the second quantity, then the data in the database is updated, including: Based on the data source interface, obtain the first scenario list under the target store; Based on the database, obtain the second scenario list under the target store; The first scene list is compared with the second scene list. The missing data in the database is supplemented according to the missing scenes in the second scene list, and the data corresponding to the redundant scenes in the second scene list is deleted from the database.
7. A data synchronization device for an Internet of Things (IoT) scenario, characterized in that, include: The acquisition module is used to acquire data packets in the message queue. The message queue is a queue established by the cluster server to store data packets sent by production terminals. The data packets include data identifiers and change information of IoT scenario data. The change information includes the change type and the change content; The processing module is used to obtain a memory identifier based on the data identifier, and store the data packet into a memory queue based on the memory identifier; The synchronization module is used to update the data in the database according to the change information and save the updated data; The processing module is specifically used to determine the target memory queue corresponding to the change type according to the change type, wherein different change types correspond to different memory queues; obtain a memory identifier according to the data identifier, the memory identifier being used to indicate the location of the target fragment in the target memory queue, wherein the memory queue is divided into multiple fragments, and the multiple fragments are sorted in a preset order; and store the data packet into the target fragment of the target memory queue according to the location of the target fragment.
8. An electronic device, characterized in that, include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory to implement the method as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Data processing method, device and system, server and readable storage medium
CN111131074A
Data packet synchronization method and device, equipment and storage medium
CN111737012A