Skip to content

feat: add per-key locking to MemoryStore and LocalStore set_range#178

Merged
d-v-b merged 1 commit into
d-v-b:feat/byte-range-setterfrom
mkitti:feat/byte-range-setter
May 31, 2026
Merged

feat: add per-key locking to MemoryStore and LocalStore set_range#178
d-v-b merged 1 commit into
d-v-b:feat/byte-range-setterfrom
mkitti:feat/byte-range-setter

Conversation

@mkitti
Copy link
Copy Markdown

@mkitti mkitti commented May 31, 2026

MemoryStore uses per-key asyncio.Lock / threading.Lock to serialise concurrent set_range / set_range_sync calls on the same key.

LocalStore uses a double-checked file-lock protocol: the target file is atomically renamed to a key.lock sibling (via _safe_move) to signal exclusive ownership across both threads and processes, with stale-lock recovery after 60 s. The in-process asyncio.Lock / threading.Lock guards the rename so only one coroutine/thread races to the filesystem at a time.

Concurrent tests are added for both stores verifying that parallel writes to non-overlapping byte ranges produce the correct combined result.

TODO:

  • Add unit tests and/or doctests in docstrings
  • Add docstrings and API docs for any new/modified user-facing classes and functions
  • New/modified features documented in docs/user-guide/*.md
  • Changes documented as a new file in changes/
  • GitHub Actions have all passed
  • Test coverage is 100% (Codecov passes)

MemoryStore uses per-key asyncio.Lock / threading.Lock to serialise
concurrent set_range / set_range_sync calls on the same key.

LocalStore uses a double-checked file-lock protocol: the target file is
atomically renamed to a key.__lock__ sibling (via _safe_move) to signal
exclusive ownership across both threads and processes, with stale-lock
recovery after 60 s. The in-process asyncio.Lock / threading.Lock guards
the rename so only one coroutine/thread races to the filesystem at a time.

Concurrent tests are added for both stores verifying that parallel writes
to non-overlapping byte ranges produce the correct combined result.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@d-v-b d-v-b merged commit 2db2c9a into d-v-b:feat/byte-range-setter May 31, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants