-
Notifications
You must be signed in to change notification settings - Fork 0
Restore historic skeleton endpoint #1
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
base: metacell
Are you sure you want to change the base?
Changes from all commits
581a4ec
ed5ded5
fd780dd
deb6987
de565b7
df72995
2dab4f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| import hashlib | ||
|
|
||
|
|
||
| # The base lock is formed from the multiplication of all characters of "catmaid" | ||
| # as ASCII: 99 * 97 * 116 * 109 * 97 * 105 * 100. | ||
| base_lock_id = 123666608142000 | ||
|
|
@@ -6,3 +9,16 @@ | |
| spatial_update_event_lock = base_lock_id + 1 | ||
| # Postgres advisory lock ID to update history update even handling | ||
| history_update_event_lock = base_lock_id + 2 | ||
| # Postgres advisory lock namespace for historic skeleton restores | ||
| skeleton_restore_lock_namespace = base_lock_id + 3 | ||
|
|
||
|
|
||
| def skeleton_restore_lock_id(skeleton_id): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll admit that I've not fully dug into the exact uses of these pg locks in catmaid, but I think there's a exceedingly rare problem that while is so unlikely it will pretty much never occur, I'd rather we explicitly avoid it. Technically our generated unsigned_lock_id could be the spatial update event lock or the history update event lock and it also makes it a bit hard in the future to add locks since the ID space is variable. Looking at a different signature for the |
||
| """Return a stable signed 64-bit advisory lock ID for a skeleton restore.""" | ||
| lock_key = f'{skeleton_restore_lock_namespace}:{int(skeleton_id)}'.encode( | ||
| 'ascii') | ||
| unsigned_lock_id = int.from_bytes( | ||
| hashlib.blake2b(lock_key, digest_size=8).digest(), 'big') | ||
| if unsigned_lock_id >= 2 ** 63: | ||
| return unsigned_lock_id - 2 ** 64 | ||
| return unsigned_lock_id | ||
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.
Ideally I think it would be better if this is defined in one place and reused both here and in urls.py so that this label is kept in sync between the two.
If there is no good candidate place for that then feel free to leave it.