-
Notifications
You must be signed in to change notification settings - Fork 200
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
Added hierarchical lock for applying data updates #745
Added hierarchical lock for applying data updates #745
Conversation
✅ Deploy Preview for opal-docs canceled.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good effort but:
- You focused too much on restyling the code that it made reviewing very difficult
- You have little to no documentation / comments - (you actually removed comments) - on a super sensitive code like this - it's too risky
- and most crucial - the design breaks a core concurrency concept (queue for fetching) which would hurt the performance of this component dramatically (we actually discussed this in the design phase)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few more comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great and important work.
Few last comments placed for final touches.
Celebration:
The Hierarchical Lock mechanism is very elegant
Lessons for next time:
Keep it more focused on the core task, and add comments.
1352480
to
027d81c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Job well done.
Co-authored-by: Or Weis <orweis@gmail.com>
Co-authored-by: Or Weis <orweis@gmail.com>
if task is None: | ||
raise RuntimeError("acquire() must be called from within a task.") | ||
|
||
async with self._lock: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why access the lock directly instead the Condition ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
async with self._lock: | |
async with self._cond: |
self._locked_paths.add(path) | ||
if task not in self._task_locks: | ||
self._task_locks[task] = set() | ||
self._task_locks[task].add(path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
locked_paths basically equals to combination of all task_locks values right ?
entry=entry, | ||
exc=e, | ||
) | ||
raise Exception(f"Failed to fetch data for entry {entry.url}: {e}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from e
if task is None: | ||
raise RuntimeError("release() must be called from within a task.") | ||
|
||
async with self._lock: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment here
raise RuntimeError(f"Task {task} cannot re-acquire lock on '{path}'.") | ||
|
||
# Wait until there is no conflict with existing locked paths | ||
while any(self._is_conflicting(path, lp) for lp in self._locked_paths): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct me if I'm wrong but wouldn't this cause you to aquire the condition underlying lock ( which is a single lock for all the tasks ), and then waiting for the path to be unlocked, which blocks also other paths from being processed ( because the lock is still locked )
Fixes Issue
Changes proposed
Check List (Check all the applicable boxes)
Screenshots
Note to reviewers