René's URL Explorer Experiment


Title: Bug: multiple workers reserving the same key in Job.reserve() in 2.1 · Issue #1398 · datajoint/datajoint-python · GitHub

Open Graph Title: Bug: multiple workers reserving the same key in Job.reserve() in 2.1 · Issue #1398 · datajoint/datajoint-python

X Title: Bug: multiple workers reserving the same key in Job.reserve() in 2.1 · Issue #1398 · datajoint/datajoint-python

Description: Bug Report Description When using populate(reserve_jobs=True) with multiple workers (e.g., SLURM array jobs), multiple workers can successfully "reserve" the same key and call make() simultaneously. I noticed this when sumbitting multipl...

Open Graph Description: Bug Report Description When using populate(reserve_jobs=True) with multiple workers (e.g., SLURM array jobs), multiple workers can successfully "reserve" the same key and call make() simultaneously...

X Description: Bug Report Description When using populate(reserve_jobs=True) with multiple workers (e.g., SLURM array jobs), multiple workers can successfully "reserve" the same key and call make() simu...

Opengraph URL: https://github.com/datajoint/datajoint-python/issues/1398

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Bug: multiple workers reserving the same key in Job.reserve() in 2.1","articleBody":"## Bug Report\n\n### Description\nWhen using populate(reserve_jobs=True) with multiple workers (e.g., SLURM array jobs), multiple workers can successfully \"reserve\" the same key and call make() simultaneously. \nI noticed this when sumbitting multiple SLURM jobs that populate the same table: their output logs confirmed that 6/7 jobs were executing make() on the same key. This job reservation system has always been a nice feature of datajoint for distributed computing - preventing redundant computations and collisions. \n\n### Current workaround\nCurrently I think this is a rare occurance, probably made slightly more common by the fact that I am accessing my server across a network (not hosted locally) and submitting sbatch arrays. My workaround right now has been adding a random sleep (0-30s) before `populate()` in the SLURM script to stagger worker start times. With that in place I have not noticed the duplicate make / race. \n\nI'm not very familiar with how datajoint manages job reservations, but below is what claude suggested might be the issue. Adding it to this post in case it is useful.\n\n\u003e \n\u003e `Job.reserve()` in DataJoint 2.1 uses a non-atomic SELECT-then-UPDATE pattern that allows multiple workers to reserve the same job simultaneously. This is a regression from the 0.13.x approach which used an atomic `INSERT ... ON DUPLICATE KEY` pattern that was inherently atomic.\n\u003e \n\u003e ### Root Cause\n\u003e \n\u003e `Job.reserve()` (jobs.py:430-473) performs a **check-then-act** without atomicity:\n\u003e \n\u003e ```python\n\u003e def reserve(self, key: dict) -\u003e bool:\n\u003e     # Step 1: SELECT — check if job is pending\n\u003e     job = (self \u0026 key \u0026 \"status='pending'\" \u0026 \"scheduled_time \u003c= CURRENT_TIMESTAMP(3)\").to_dicts()\n\u003e     if not job:\n\u003e         return False\n\u003e \n\u003e     # Step 2: UPDATE — mark as reserved\n\u003e     pk = self._get_pk(key)\n\u003e     update_row = {**pk, \"status\": \"reserved\", ...}\n\u003e     try:\n\u003e         self.update1(update_row)  # UPDATE ... SET status='reserved' WHERE \u003cpk\u003e\n\u003e         return True\n\u003e     except Exception:\n\u003e         return False\n\u003e ```\n\u003e \n\u003e The UPDATE's WHERE clause matches only on primary key, **not** on `status='pending'`. So if two workers both read the row as `'pending'` before either updates, both UPDATEs succeed — the second simply overwrites the first worker's reservation.\n\u003e \n\u003e ### Comparison with 0.13.x\n\u003e \n\u003e The old `JobTable.reserve()` (0.13.x) used an atomic INSERT pattern:\n\u003e \n\u003e ```python\n\u003e def reserve(self, table_name, key):\n\u003e     job = dict(key, table_name=table_name, status='reserved',\n\u003e                host=platform.node(), pid=os.getpid(), ...)\n\u003e     try:\n\u003e         self.insert1(job)  # INSERT — fails with DuplicateError if row exists\n\u003e     except DuplicateError:\n\u003e         return False        # Another worker already has this key\n\u003e     return True\n\u003e ```\n\u003e \n\u003e This is inherently atomic: the first INSERT wins, all others get `DuplicateError`. No window exists between check and action.\n\u003e \n\u003e ### Suggested Fix\n\u003e \n\u003e Option A — Add a WHERE clause to the UPDATE:\n\u003e \n\u003e ```sql\n\u003e UPDATE jobs SET status='reserved', ...\n\u003e WHERE table_name=... AND key_hash=... AND status='pending'\n\u003e ```\n\u003e \n\u003e Then check `affected_rows == 1` to determine success. This is a single atomic operation.\n\u003e \n\u003e Option B — Use `SELECT ... FOR UPDATE` before the check:\n\u003e \n\u003e ```sql\n\u003e SELECT * FROM jobs WHERE ... AND status='pending' FOR UPDATE\n\u003e ```\n\u003e \n\u003e This acquires a row-level lock, preventing concurrent readers from seeing the row as pending.\n\u003e \n\u003e Option C — Restore the INSERT-based approach from 0.13.x, which was atomic by design.\n\u003e \n\u003e ### Environment\n\u003e \n\u003e - datajoint 2.1.0\n\u003e - Python 3.12\n\u003e - MySQL 8.0\n\u003e - SLURM cluster, 7 concurrent array tasks calling `populate(reserve_jobs=True)`\n\u003e \n\u003e ","author":{"url":"https://github.com/noahpettit","@type":"Person","name":"noahpettit"},"datePublished":"2026-02-14T18:57:50.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/1398/datajoint-python/issues/1398"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:f2849db1-3513-bb8d-f39a-a13d9daf5c64
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idC9AA:3F92FF:13164A:1A5A97:6A4D94E7
html-safe-nonce1eae7f491dcd11160c726852c92f9d2ceae0a1132c962dff963173de956f0d3a
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDOUFBOjNGOTJGRjoxMzE2NEE6MUE1QTk3OjZBNEQ5NEU3IiwidmlzaXRvcl9pZCI6IjYxMTk3MjExNjc1MTcyMjYyMTUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac696ef8f005588194c252c40c8a14eadc887e5e2892b32d910dc65ebc73277276
hovercard-subject-tagissue:3942069015
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/datajoint/datajoint-python/1398/issue_layout
twitter:imagehttps://opengraph.githubassets.com/c375e717ad9e0e260f6834c1d7071158335cf2d729444e369e8ece6e07b1be31/datajoint/datajoint-python/issues/1398
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/c375e717ad9e0e260f6834c1d7071158335cf2d729444e369e8ece6e07b1be31/datajoint/datajoint-python/issues/1398
og:image:altBug Report Description When using populate(reserve_jobs=True) with multiple workers (e.g., SLURM array jobs), multiple workers can successfully "reserve" the same key and call make() simultaneously...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamenoahpettit
hostnamegithub.com
expected-hostnamegithub.com
None06b8a6144231bf3a234f1c2e9993861e07ce98a905912b114aa386c2d7e84b33
turbo-cache-controlno-preview
go-importgithub.com/datajoint/datajoint-python git https://github.com/datajoint/datajoint-python.git
octolytics-dimension-user_id2375501
octolytics-dimension-user_logindatajoint
octolytics-dimension-repository_id5866704
octolytics-dimension-repository_nwodatajoint/datajoint-python
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id5866704
octolytics-dimension-repository_network_root_nwodatajoint/datajoint-python
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release74e2a9c78f1e38588de4f25885878349d721eedf
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/datajoint/datajoint-python/issues/1398#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fdatajoint%2Fdatajoint-python%2Fissues%2F1398
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fdatajoint%2Fdatajoint-python%2Fissues%2F1398
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=datajoint%2Fdatajoint-python
Reloadhttps://github.com/datajoint/datajoint-python/issues/1398
Reloadhttps://github.com/datajoint/datajoint-python/issues/1398
Reloadhttps://github.com/datajoint/datajoint-python/issues/1398
Please reload this pagehttps://github.com/datajoint/datajoint-python/issues/1398
datajoint https://github.com/datajoint
datajoint-pythonhttps://github.com/datajoint/datajoint-python
Notifications https://github.com/login?return_to=%2Fdatajoint%2Fdatajoint-python
Fork 96 https://github.com/login?return_to=%2Fdatajoint%2Fdatajoint-python
Star 194 https://github.com/login?return_to=%2Fdatajoint%2Fdatajoint-python
Code https://github.com/datajoint/datajoint-python
Issues 7 https://github.com/datajoint/datajoint-python/issues
Pull requests 4 https://github.com/datajoint/datajoint-python/pulls
Discussions https://github.com/datajoint/datajoint-python/discussions
Actions https://github.com/datajoint/datajoint-python/actions
Security and quality 0 https://github.com/datajoint/datajoint-python/security
Insights https://github.com/datajoint/datajoint-python/pulse
Code https://github.com/datajoint/datajoint-python
Issues https://github.com/datajoint/datajoint-python/issues
Pull requests https://github.com/datajoint/datajoint-python/pulls
Discussions https://github.com/datajoint/datajoint-python/discussions
Actions https://github.com/datajoint/datajoint-python/actions
Security and quality https://github.com/datajoint/datajoint-python/security
Insights https://github.com/datajoint/datajoint-python/pulse
#1399https://github.com/datajoint/datajoint-python/pull/1399
conda-forge/datajoint-feedstock#62https://github.com/conda-forge/datajoint-feedstock/pull/62
Bug: multiple workers reserving the same key in Job.reserve() in 2.1https://github.com/datajoint/datajoint-python/issues/1398#top
#1399https://github.com/datajoint/datajoint-python/pull/1399
conda-forge/datajoint-feedstock#62https://github.com/conda-forge/datajoint-feedstock/pull/62
https://github.com/dimitri-yatsenko
bugIndicates an unexpected problem or unintended behaviorhttps://github.com/datajoint/datajoint-python/issues?q=state%3Aopen%20label%3A%22bug%22
https://github.com/noahpettit
noahpettithttps://github.com/noahpettit
on Feb 14, 2026https://github.com/datajoint/datajoint-python/issues/1398#issue-3942069015
dimitri-yatsenkohttps://github.com/dimitri-yatsenko
bugIndicates an unexpected problem or unintended behaviorhttps://github.com/datajoint/datajoint-python/issues?q=state%3Aopen%20label%3A%22bug%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.