optimistic concurrency different approach#115
Open
uguryiilmz wants to merge 1 commit intocosmicpython:chapter_08_events_and_message_bus_exercisefrom
Open
optimistic concurrency different approach#115uguryiilmz wants to merge 1 commit intocosmicpython:chapter_08_events_and_message_bus_exercisefrom
uguryiilmz wants to merge 1 commit intocosmicpython:chapter_08_events_and_message_bus_exercisefrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I think this may be a semantics problem, but in the book, the approach that is described as optimistic concurrency is a bit different than real optimistic concurrency. It still throws an error because of the isolation level "repeatable read" and achieves the same thing though.
As far as I understand, optimistic concurrency should try to make an update by checking the previous version, and if the version number is different than what the original version number is, it fails. Not because two processes are touching the same database row, bout because of a version difference.
I think SQL Alchemy automatically provides this field for this purpose version_id_col=products.c.version_number. Here is an integration test with two threads, both trying to update the same product field with the same sku. Only one succeeds, the other fails as stale data.
Personally, I don't know which approach is better.
I wanted to get your opinion on whether you have any preference between these two approaches @hjwp
As I said, I think they are both really similar and can act as optimistic concurrency, but usually, when I see the description for optimistic concurrency, it means that
A tries to update the database row, increase the version
B tries to update the database where version_number ={old_version} -> returns 0 because the version is changed, so it gets rejected.
The approach in the pr simulates that a bit closer.
Thank you for all the examples in the book!