feat(backend): add global KV storage fallback for server-side data#243
Draft
Tjemmmic wants to merge 4 commits into
Draft
feat(backend): add global KV storage fallback for server-side data#243Tjemmmic wants to merge 4 commits into
Tjemmmic wants to merge 4 commits into
Conversation
Introduces a server-global KV store in MemoryBackend and FileIOBackend to handle application-level key-value data not tied to a specific ClientNetworkAccount (CNAC). This is primarily used for workspace metadata where the session CID is 0. Updates the file I/O layer to persist and restore global_kv.bin from the server directory.
This comment was marked as outdated.
This comment was marked as outdated.
Refactors the global_kv fallback mechanism in both FileIOBackend and MemoryBackend to properly namespace entries by session_cid. Previously, values stored without an active CNAC were only keyed by peer_cid, leading to cross-session state leakage. Includes integration tests to verify data isolation and persistence across reload cycles.
This comment was marked as outdated.
This comment was marked as outdated.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #243 +/- ##
================================================
+ Coverage 83.3963% 83.6516% +0.2553%
================================================
Files 91 91
Lines 14015 14136 +121
================================================
+ Hits 11688 11825 +137
+ Misses 2327 2311 -16
🚀 New features to boost your workflow:
|
Treats a failed bincode deserialization of the global_kv.bin file as a hard startup error. Previously this was logged but allowed startup to proceed with an empty map, meaning the next mutation would silently overwrite the corrupted file, permanently destroying all server-global data. Also expands test coverage for global KV session isolation.
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
Adds a server-global key-value storage fallback to
MemoryBackendandFileIOBackendfor byte-map data that isn't associated with any registered client account.Previously, byte-map operations (
store_byte_map_value,get_byte_map_value, etc.) would silently no-op whensession_ciddidn't resolve to an existing CNAC — returningOk(None)/Ok(Default::default()). This made it impossible for servers to persist application-level data (e.g., workspace metadata) using the standard backend KV API, since servers operate without their own CNAC and useCID 0for global state.Changes
global_kv: RwLock<HashMap<u64, HashMap<String, HashMap<String, Vec<u8>>>>>field toMemoryBackend. The four byte-map methods (get,remove,store,get_by_key,remove_by_key) now fall back toglobal_kvwhen no CNAC matches thesession_cid, instead of returning empty results.connect, loads the global KV store from<server_dir>/global_kv.binif present.save_global_kv()to persist the map via bincode.save_global_kv()whensave_cnac_by_cidreturnsClientNonExists, instead of failing the call.get_byte_map_values_by_keyno longer attempts to save a CNAC on a read path (drive-by fix).