-
Notifications
You must be signed in to change notification settings - Fork 113
feat: tiered data storage #692
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
enigbe
wants to merge
3
commits into
lightningdevkit:main
Choose a base branch
from
enigbe:2025-10-tiered-data-storage
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| import threading | ||
|
|
||
| from abc import ABC, abstractmethod | ||
| from typing import List | ||
|
|
||
| from ldk_node import IoError | ||
|
|
||
| class AbstractKvStore(ABC): | ||
| @abstractmethod | ||
| async def list_async(self, primary_namespace: "str",secondary_namespace: "str") -> "typing.List[str]": | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| def list_sync(self, primary_namespace: "str",secondary_namespace: "str") -> "typing.List[str]": | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| async def read_async(self, primary_namespace: "str",secondary_namespace: "str",key: "str") -> "typing.List[int]": | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| def read_sync(self, primary_namespace: "str",secondary_namespace: "str",key: "str") -> "typing.List[int]": | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| async def remove_async(self, primary_namespace: "str",secondary_namespace: "str",key: "str",lazy: "bool") -> None: | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| def remove_sync(self, primary_namespace: "str",secondary_namespace: "str",key: "str",lazy: "bool") -> None: | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| async def write_async(self, primary_namespace: "str",secondary_namespace: "str",key: "str",buf: "typing.List[int]") -> None: | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| def write_sync(self, primary_namespace: "str",secondary_namespace: "str",key: "str",buf: "typing.List[int]") -> None: | ||
| pass | ||
|
|
||
| class TestKvStore(AbstractKvStore): | ||
| def __init__(self, name: str): | ||
| self.name = name | ||
| # Storage structure: {(primary_ns, secondary_ns): {key: [bytes]}} | ||
| self.storage = {} | ||
| self._lock = threading.Lock() | ||
|
|
||
| def dump(self): | ||
| print(f"\n[{self.name}] Store contents:") | ||
| for (primary_ns, secondary_ns), keys_dict in self.storage.items(): | ||
| print(f" Namespace: ({primary_ns!r}, {secondary_ns!r})") | ||
| for key, data in keys_dict.items(): | ||
| print(f" Key: {key!r} -> {len(data)} bytes") | ||
| # Optionally show first few bytes | ||
| preview = data[:20] if len(data) > 20 else data | ||
| print(f" Data preview: {preview}...") | ||
|
|
||
| # KVStoreSync methods | ||
| def list_sync(self, primary_namespace: str, secondary_namespace: str) -> List[str]: | ||
| with self._lock: | ||
| namespace_key = (primary_namespace, secondary_namespace) | ||
| if namespace_key in self.storage: | ||
| return list(self.storage[namespace_key].keys()) | ||
| return [] | ||
|
|
||
| def read_sync(self, primary_namespace: str, secondary_namespace: str, key: str) -> List[int]: | ||
| with self._lock: | ||
| print(f"[{self.name}] READ: {primary_namespace}/{secondary_namespace}/{key}") | ||
| namespace_key = (primary_namespace, secondary_namespace) | ||
|
|
||
| if namespace_key not in self.storage: | ||
| print(f" -> namespace not found, keys: {list(self.storage.keys())}") | ||
| raise IoError.NotFound(f"Namespace not found: {primary_namespace}/{secondary_namespace}") | ||
|
|
||
| if key not in self.storage[namespace_key]: | ||
| print(f" -> key not found, keys: {list(self.storage[namespace_key].keys())}") | ||
| raise IoError.NotFound(f"Key not found: {key}") | ||
|
|
||
| data = self.storage[namespace_key][key] | ||
| print(f" -> returning {len(data)} bytes") | ||
| return data | ||
|
|
||
| def write_sync(self, primary_namespace: str, secondary_namespace: str, key: str, buf: List[int]) -> None: | ||
| with self._lock: | ||
| namespace_key = (primary_namespace, secondary_namespace) | ||
| if namespace_key not in self.storage: | ||
| self.storage[namespace_key] = {} | ||
|
|
||
| self.storage[namespace_key][key] = buf.copy() | ||
|
|
||
| def remove_sync(self, primary_namespace: str, secondary_namespace: str, key: str, lazy: bool) -> None: | ||
| with self._lock: | ||
| namespace_key = (primary_namespace, secondary_namespace) | ||
| if namespace_key not in self.storage: | ||
| raise IoError.NotFound(f"Namespace not found: {primary_namespace}/{secondary_namespace}") | ||
|
|
||
| if key not in self.storage[namespace_key]: | ||
| raise IoError.NotFound(f"Key not found: {key}") | ||
|
|
||
| del self.storage[namespace_key][key] | ||
|
|
||
| if not self.storage[namespace_key]: | ||
| del self.storage[namespace_key] | ||
|
|
||
| # KVStore methods | ||
| async def list_async(self, primary_namespace: str, secondary_namespace: str) -> List[str]: | ||
| return self.list_sync(primary_namespace, secondary_namespace) | ||
|
|
||
| async def read_async(self, primary_namespace: str, secondary_namespace: str, key: str) -> List[int]: | ||
| return self.read_sync(primary_namespace, secondary_namespace, key) | ||
|
|
||
| async def write_async(self, primary_namespace: str, secondary_namespace: str, key: str, buf: List[int]) -> None: | ||
| self.write_sync(primary_namespace, secondary_namespace, key, buf) | ||
|
|
||
| async def remove_async(self, primary_namespace: str, secondary_namespace: str, key: str, lazy: bool) -> None: | ||
| self.remove_sync(primary_namespace, secondary_namespace, key, lazy) | ||
|
|
||
|
|
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.
Can we now also expose
Builder::build_with_store?