Skip to content

fix!: remove the locks on dump, load and remove of targets - #715

Merged
kitagry merged 5 commits into
masterfrom
feat/remove-target-locks
Dec 2, 2026
Merged

kitagry merged 5 commits into
masterfrom
feat/remove-target-locks

Conversation

@kitagry

@kitagry kitagry commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Summary

Removes the locks that gokart took on dump(), load() and remove() 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

Changes

  • TargetOnKart.dump() / load() / remove() call the storage directly.
  • Without should_lock_run=True, a configured Redis backend is not used at all, so a task no longer imports the redis client at construction in that case.
  • The check that the Redis lock timeout is greater than the 10-second extension interval used to run (as an assert) when a target was built. It now runs when a task with should_lock_run=True is constructed and raises ValueError, like the existing check for object storage backends.
  • Removed the UserWarning that the dump / load / remove locks are not taken with an object storage url.
  • The UserWarning for a should_lock_run=True task 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.
  • The arguments after the removed ones are keyword-only, so an old positional call fails with TypeError instead of silently passing the removed value to the next parameter: everything after obj in TargetOnKart.dump(), and store_index_in_feather of make_target().
  • The descriptions of redis_host / redis_port say they are only used by the run lock.
  • Docs: using_task_task_conflict_prevention_lock.rst now describes the run lock and says that outputs are not locked; the notes about the dump lock in efficient_run_on_multi_workers.rst and task_on_kart.rst are 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_lock cleanup from #710) are kept.

Removed public API

  • TargetOnKart.dump(lock_at_dump=...)
  • task_lock_params of gokart.target.make_target(), gokart.target.make_model_target() and gokart.in_memory.make_in_memory_target() (unique_id of make_in_memory_target is now keyword-only, so an old positional task_lock_params raises TypeError instead of becoming the unique_id)
  • task_lock_params of SingleFileTarget, ModelTarget and InMemoryTarget (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() and TaskLockParams stay for the run lock)
  • wrap_dump_with_lock, wrap_load_with_lock, wrap_remove_with_lock in gokart.conflict_prevention_lock.task_lock_wrappers
  • gokart.conflict_prevention_lock.lock_config.warn_once_that_dump_locks_are_not_taken()

Release notes

Breaking changes

  • dump / load / remove of outputs no longer take a lock. If you set only url=redis://... of [gokart_lock] (or redis_host / redis_port) without should_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, set should_lock_run=True on it and run it with gokart.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.
  • A Redis url alone no longer needs the redis client. A task raises ImportError for a missing gokart[redis] at construction only with should_lock_run=True. Likewise, a Redis lock timeout of 10 seconds or less is rejected with ValueError when a task with should_lock_run=True is constructed (it was an AssertionError when any output was built).
  • Removed API: TargetOnKart.dump(lock_at_dump=...), the task_lock_params parameter of make_target / make_model_target / make_in_memory_target and of the target classes, make_task_lock_params, and wrap_dump_with_lock / wrap_load_with_lock / wrap_remove_with_lock. Drop these arguments and calls; custom TargetOnKart subclasses can drop _get_task_lock_params().
  • Keyword-only arguments: pass task_params, custom_labels and required_task_outputs of TargetOnKart.dump(), and store_index_in_feather of make_target(), by keyword.

Relation to other PRs

Test plan

🤖 Generated with Claude Code

https://claude.ai/code/session_01CdA6RRA66D4V9sHzdtywtu

@kitagry kitagry self-assigned this Nov 25, 2026
@kitagry
kitagry marked this pull request as ready for review November 25, 2026 12:57
@kitagry kitagry mentioned this pull request Nov 25, 2026
9 tasks

@hirosassa hirosassa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. 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.
  2. #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.
  3. #710 and this PR conflict in task_lock_wrappers.py and its tests, as the description says. If #710 goes first, the tests that use make_task_lock_params need to be reduced to the wrap_run_with_lock cases here.

kitagry and others added 2 commits November 26, 2026 23:41
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
kitagry merged commit 4440776 into master Dec 2, 2026
7 checks passed
@kitagry
kitagry deleted the feat/remove-target-locks branch December 2, 2026 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

With a Redis lock, modification_time_check never updates a stale output, so the task re-runs on every build

2 participants