Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hub: efficient Device Twin Synchronization #1005

Merged
merged 7 commits into from
Sep 5, 2023
Merged

Conversation

jkralik
Copy link
Member

@jkralik jkralik commented Jul 18, 2023

In order to monitor resource changes and determine if a resource has been modified on the device, the CoAP gateway utilizes the Entity Tag (ETAG) mechanism.

For more information, please refer to the documentation.

@jkralik jkralik force-pushed the jkralik/feature/etag branch 7 times, most recently from 9a55345 to b68e708 Compare July 21, 2023 14:02
@jkralik jkralik requested a review from Danielius1922 July 27, 2023 06:26
@jkralik jkralik force-pushed the jkralik/feature/etag branch 3 times, most recently from 0bf2427 to d01851a Compare August 1, 2023 13:26
@jkralik jkralik requested a review from ondrejtomcik August 4, 2023 05:54
@jkralik jkralik force-pushed the jkralik/feature/etag branch from 2094305 to b95d062 Compare August 4, 2023 08:27
@jkralik jkralik marked this pull request as ready for review August 4, 2023 10:02
grpc-gateway/pb/updateDeviceMetadata.proto Outdated Show resolved Hide resolved
coap-gateway/coapconv/coapconv.go Outdated Show resolved Hide resolved
@jkralik jkralik force-pushed the jkralik/feature/etag branch from 102c5b5 to c9c9644 Compare August 10, 2023 09:09
In order to monitor resource changes and determine if a resource has been modified on the device, the CoAP gateway utilizes the Entity Tag (ETAG) mechanism.

For Batch Observation, the ETAG is associated with the overall state of resources. Prior to initiating resource observation, the CoAP gateway retrieves the latest ETAG among all device resources from the Hub Database. When initiating the resource observation, the CoAP gateway sends the ETAG to the device. If the received ETAG matches the highest ETAG among the device resources, the device responds with a code VALID. However, if the received ETAG does not match, the device responds with a code CONTENT and includes the current ETAG. Consequently, when a resource changes, the device sends the updated ETAG back to the CoAP gateway via a notification. The CoAP gateway transmits the ETAG together with the Content by using the NotifyResourceChanged method to the resource-aggregate. This command is then converted into a ResourceChanged event, which is saved in a database and distributed through the event bus. In cases where multiple resources change simultaneously, the CoAP gateway updates all affected resources with the same timestamp and ETAG.

The special query to the database efficiently retrieves the latest ETAG value from all device resources without loading the complete set of data. This optimized query solely focuses on performance and retrieves only the required ETAG value, excluding any additional information.
Force resynchronization refers to the process of refreshing all
resources from the device and updating the twin. Its primary
purpose is to resolve potential synchronization issues and ensure
there are no operational discrepancies between the device and its
twin. It also enable twin.
@jkralik jkralik force-pushed the jkralik/feature/etag branch from c9c9644 to 89e307d Compare August 31, 2023 11:18
@jkralik jkralik force-pushed the jkralik/feature/etag branch 2 times, most recently from 7f3c7e7 to 5597d18 Compare September 5, 2023 07:23
@jkralik jkralik force-pushed the jkralik/feature/etag branch from 5597d18 to e7d8578 Compare September 5, 2023 07:23
@sonarcloud
Copy link

sonarcloud bot commented Sep 5, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

76.1% 76.1% Coverage
0.0% 0.0% Duplication

@jkralik jkralik merged commit 1baeec6 into main Sep 5, 2023
27 checks passed
@jkralik jkralik deleted the jkralik/feature/etag branch September 5, 2023 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants