-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Shared storage: backend-agnostic state manager + pub/sub #3930
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
Open
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f0b21c9
Add backend-agnostic shared storage (state manager + pub/sub)
T4rk1n 984f751
End async subscriptions cleanly when the loop is shutting down
T4rk1n 6d5ed64
CHANGELOG: fill in PR number for shared storage entry
T4rk1n e69e42c
Fix stale shared-storage comments (drop plan/pickle/wire wording)
T4rk1n 0b537db
Document shared storage in .ai/ARCHITECTURE.md
T4rk1n bc582ea
Add Diskcache and Redis shared-storage backends
T4rk1n 45ae06b
Document the out-of-tree shared-storage backend seam
T4rk1n dd88bc9
Add dash[redis] extra for RedisSharedStorage
T4rk1n 53d6566
Fix mypy errors in shared-storage typing compliance
T4rk1n 6887bab
Expand shared-storage app integration tests across backends
T4rk1n 219206b
Use dash_duo browser tests for shared-storage app integration
T4rk1n File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| """Backend-agnostic shared state + pub/sub (state manager). | ||
|
|
||
| Exposes the ``BaseSharedStorage`` interface and its backends: | ||
|
|
||
| - ``LocalSharedStorage`` (default): in-memory, owner-elected -- one container. | ||
| - ``DiskcacheSharedStorage``: on a ``diskcache.Cache`` -- one machine, not pods. | ||
| - ``RedisSharedStorage``: on Redis -- across processes and containers. | ||
| """ | ||
|
|
||
| from .base import ( | ||
| BaseSharedStorage, | ||
| SharedStorageError, | ||
| SharedStorageGap, | ||
| Subscription, | ||
| ) | ||
| from .diskcache import DiskcacheSharedStorage | ||
| from .local import LocalSharedStorage | ||
| from .redis import RedisSharedStorage | ||
|
|
||
| __all__ = [ | ||
| "BaseSharedStorage", | ||
| "DiskcacheSharedStorage", | ||
| "LocalSharedStorage", | ||
| "RedisSharedStorage", | ||
| "SharedStorageError", | ||
| "SharedStorageGap", | ||
| "Subscription", | ||
| ] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| """Codec for the shared-storage socket transport. | ||
|
|
||
| Prefers ``msgspec`` (msgpack: fast, compact) and falls back to stdlib ``json``. | ||
| Both are data-only, so bytes read off the socket cannot execute code. All | ||
| workers in one deployment share a single install, hence a single codec, so the | ||
| two ends always agree on the format. | ||
|
|
||
| Payloads must be JSON-compatible (dict / list / str / int / float / bool / | ||
| None) under either codec -- the same constraint as ``dcc.Store`` and callback | ||
| outputs. | ||
| """ | ||
|
|
||
| from typing import Any | ||
|
|
||
| try: | ||
| import msgspec | ||
|
|
||
| _encoder = msgspec.msgpack.Encoder() | ||
| _decoder = msgspec.msgpack.Decoder() | ||
|
|
||
| def encode(obj: Any) -> bytes: | ||
| return _encoder.encode(obj) | ||
|
|
||
| def decode(data: bytes) -> Any: | ||
| return _decoder.decode(data) | ||
|
|
||
| CODEC = "msgpack" | ||
| except ImportError: # pragma: no cover - exercised via the fallback install | ||
| import json | ||
|
|
||
| def encode(obj: Any) -> bytes: | ||
| return json.dumps(obj).encode("utf-8") | ||
|
|
||
| def decode(data: bytes) -> Any: | ||
| return json.loads(data.decode("utf-8")) | ||
|
|
||
| CODEC = "json" | ||
Oops, something went wrong.
Oops, something went wrong.
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.
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.
This looks like a Claude-ism: is there some condition that demands a real reason to "fall back"? I'd argue we should pick 1 implementation and keep it DRY.