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

Support for detecting concurrent modifications #887

Open
pravussum opened this issue Nov 19, 2020 · 1 comment
Open

Support for detecting concurrent modifications #887

pravussum opened this issue Nov 19, 2020 · 1 comment

Comments

@pravussum
Copy link

pravussum commented Nov 19, 2020

Thing modifications in Ditto are subject to the classic "lost updates" problem known from relational databases.
With support for a per-feature _revision field being in the loop (#778) it would be possible to detect concurrent modifications.

  1. a twin exists in Ditto having feature XYZ set to 1 (revision 0)
  2. client A sends feature update (XYZ=2, rev. 0)
  3. Ditto processes client As request
  4. client B sends feature update (XYZ=3, rev. 0)
  5. Ditto updates the twins feature to XYZ=2, rev. 1 and sends an event to client B (client A doesn't receive one since it initiated the update)
  6. client B receives the event and updates its internal state to XYZ=2, rev. 1
  7. Ditto processes client Bs request

In this last step with the current implementation Ditto would just update the twins feature to XYZ=3, rev. 2 and send the update event to client A (but not B), leaving client B with a wrong state (its update is lost).

In a future implementation Ditto should compare the revision sent along with the request of client B (rev. 0) with the twins feature revision at that time (rev. 1 after As update) and raise an error that the feature has been modified in the meanwhile.

Probably its reasonable to make this behavior configurable (system wide or per client / request)

@thjaeckle
Copy link
Member

Ah, I see. On the thing level this is already possible today using conditional requests with "If-Match" header and the Thing's revision:
https://www.eclipse.org/ditto/httpapi-concepts.html#conditional-headers

What is missing is providing that as well on a feature or even on a deeper level. There currently only the hash can be used for using in the conditional request and this hash is the Java hash code which is most of the times difficult to calculate.

So once we would have the revision number in each Json leaf as metadata, the conditional request could be done everywhere.

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

No branches or pull requests

2 participants