Repository navigation
fix!: remove the locks on dump, load and remove of targets - #715
Merged
Merged
Conversation
kitagry
marked this pull request as ready for review
November 25, 2026 12:57
kitagry
requested review from
Hi-king,
hiro-o918,
hirosassa,
mamo3gr,
mski-iksm,
ujiuji1259 and
yokomotod
as code owners
November 25, 2026 12:57
hirosassa
approved these changes
Nov 25, 2026
hirosassa
left a comment
Collaborator
There was a problem hiding this comment.
LGTM. The reasoning for removing the dump / load / remove locks is convincing (atomic single-file writes, the load lock was released before reading, and the dump lock causes #713), and the breaking changes are clearly listed.
Merge order
- Please merge #714 before this PR. The description calls them independent, but for users who have a Redis dump lock and a local
ModelTarget/make_large_data_frame_target, the dump lock was the only protection against reading a partially written zip. With only this PR merged, that protection is gone until #714 lands. - #708 changes the underline on line 2 of
docs/using_task_task_conflict_prevention_lock.rst, which is context in this PR's first hunk, so whichever lands second needs a trivial rebase. - #710 and this PR conflict in
task_lock_wrappers.pyand its tests, as the description says. If #710 goes first, the tests that usemake_task_lock_paramsneed to be reduced to thewrap_run_with_lockcases here.
The dump lock skipped the write when the output already existed, so a task re-run by modification_time_check kept its stale output (#713). The locks no longer protect outputs: every single-file write is atomic, the load lock was released before reading, and the remove lock never covered a load in progress. Running the same task on several workers at once is prevented by the run lock. BREAKING CHANGE: dump / load / remove no longer take a Redis lock, so a Redis url without should_lock_run=True locks nothing. Removed TargetOnKart.dump(lock_at_dump=...), the task_lock_params parameter of make_target / make_model_target / make_in_memory_target and the target classes, make_task_lock_params, and wrap_dump_with_lock / wrap_load_with_lock / wrap_remove_with_lock. Closes #713 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CdA6RRA66D4V9sHzdtywtu
An old positional call such as target.dump(obj, False) or make_target(path, uid, processor, task_lock_params) would otherwise pass the removed argument as task_params or store_index_in_feather without any error. Also restore a [gokart_lock] section from the developer's luigi.cfg in the test fixture, describe redis_host / redis_port as used only by the run lock, and simplify a sentence in the docs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CdA6RNrztQZVMBnYwe8RjJ
kitagry
force-pushed
the
feat/remove-target-locks
branch
from
November 26, 2026 14:45
630f6b6 to
1b19d3d
Compare
This was referenced Nov 28, 2026
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.
Summary
Removes the locks that gokart took on
dump(),load()andremove()of targets when a Redis lock backend is configured. The run lock (should_lock_run, taken by the gokart worker on Redis, GCS or S3) is unchanged.Closes #713
Why
modification_time_checkkeeps its stale output and re-runs on every build.luigi.LocalTargetwrites<path>-luigi-tmp-*and renames it, and GCS / S3 upload a local temporary file, which becomes visible only when the upload (single, resumable or multipart) completes. The local zip ofmake_model_target/make_large_data_frame_targetis written atomically since fix: write local zip archives atomically #714. Parallel GCS downloads pin the object generation, and S3 ranged downloads sendIf-Match, so a concurrent overwrite makes a read fail instead of mixing versions.Changes
TargetOnKart.dump()/load()/remove()call the storage directly.should_lock_run=True, a configured Redis backend is not used at all, so a task no longer imports theredisclient at construction in that case.assert) when a target was built. It now runs when a task withshould_lock_run=Trueis constructed and raisesValueError, like the existing check for object storage backends.UserWarningthat the dump / load / remove locks are not taken with an object storageurl.UserWarningfor ashould_lock_run=Truetask dumped outside the gokart worker now says that no lock is taken (there is no dump lock to fall back to).TaskOnKart._lock_at_dump(private) is replaced by_run_lock_held, set by the worker while it holds the run lock, for that warning only.TypeErrorinstead of silently passing the removed value to the next parameter: everything afterobjinTargetOnKart.dump(), andstore_index_in_featherofmake_target().redis_host/redis_portsay they are only used by the run lock.using_task_task_conflict_prevention_lock.rstnow describes the run lock and says that outputs are not locked; the notes about the dump lock inefficient_run_on_multi_workers.rstandtask_on_kart.rstare removed.wrap_run_with_lock(deprecated, removed in 2.0.0 by #685) and what it uses (set_task_lock,set_lock_scheduler,RedisClient, APScheduler, and the_hold_lockcleanup from #710) are kept.Removed public API
TargetOnKart.dump(lock_at_dump=...)task_lock_paramsofgokart.target.make_target(),gokart.target.make_model_target()andgokart.in_memory.make_in_memory_target()(unique_idofmake_in_memory_targetis now keyword-only, so an old positionaltask_lock_paramsraisesTypeErrorinstead of becoming theunique_id)task_lock_paramsofSingleFileTarget,ModelTargetandInMemoryTarget(InMemoryTarget(data_key)now)TargetOnKart._get_task_lock_params()(abstract; custom subclasses can drop their implementation)gokart.conflict_prevention_lock.task_lock.make_task_lock_params()(make_task_lock_params_for_run()andTaskLockParamsstay for the run lock)wrap_dump_with_lock,wrap_load_with_lock,wrap_remove_with_lockingokart.conflict_prevention_lock.task_lock_wrappersgokart.conflict_prevention_lock.lock_config.warn_once_that_dump_locks_are_not_taken()Release notes
Breaking changes
url=redis://...of[gokart_lock](orredis_host/redis_port) withoutshould_lock_run=True, nothing is locked anymore. Outputs are still never read half-written, because every write is atomic. What changes: when the same task runs on several workers at once, the last write wins instead of the first (the dump lock skipped the write if the output already existed). To keep the same task from running on several workers at once, setshould_lock_run=Trueon it and run it withgokart.build/gokart.run. This also fixes With a Redis lock, modification_time_check never updates a stale output, so the task re-runs on every build #713.urlalone no longer needs theredisclient. A task raisesImportErrorfor a missinggokart[redis]at construction only withshould_lock_run=True. Likewise, a Redis locktimeoutof 10 seconds or less is rejected withValueErrorwhen a task withshould_lock_run=Trueis constructed (it was anAssertionErrorwhen any output was built).TargetOnKart.dump(lock_at_dump=...), thetask_lock_paramsparameter ofmake_target/make_model_target/make_in_memory_targetand of the target classes,make_task_lock_params, andwrap_dump_with_lock/wrap_load_with_lock/wrap_remove_with_lock. Drop these arguments and calls; customTargetOnKartsubclasses can drop_get_task_lock_params().task_params,custom_labelsandrequired_task_outputsofTargetOnKart.dump(), andstore_index_in_featherofmake_target(), by keyword.Relation to other PRs
wrap_run_with_lockremains, so the shared_hold_lockfrom fix: always stop the lock scheduler and release the lock once in lock wrappers #710 stays and its tests for the run wrapper are kept (rewritten withoutmake_task_lock_params); its tests for the removed dump / load / remove wrappers are removed with them.Test plan
test/conflict_prevention_lock/test_target_without_lock.py: withurl=redis://configured, dump / load / remove never acquire a Redis lock, a dump overwrites an existing output, and the With a Redis lock, modification_time_check never updates a stale output, so the task re-runs on every build #713 scenario (modification_time_checkthroughgokart.build) now replaces the stale output and becomes complete.test_redis_import.py: a Redisurl(orredis_host/redis_port) withoutshould_lock_runbuilds without theredisclient; withshould_lock_run=Trueit still raisesImportErrorat construction.test_lock_config.py: the Redis timeout check forshould_lock_runtasks, and no check without it.test_task_lock_wrappers.py: the remainingwrap_run_with_lock(deprecation, lock extension, release after success and error), and the Lock wrappers leave the lock-extending scheduler running when unlocking fails #709 cleanup cases from fix: always stop the lock scheduler and release the lock once in lock wrappers #710 for it (the scheduler is shut down and the lock released exactly once whenrelease()orshutdown()raises or the scheduler fails to start).test_run_lock.py,test_worker.py,test_task_on_kart.py) pass unchanged.uv run pytest -n 0on the related test files, ruff, pyright.🤖 Generated with Claude Code
https://claude.ai/code/session_01CdA6RRA66D4V9sHzdtywtu