Skip to content

Split storage per owner, drop StorageApi and MemStorage - #27

Merged
jonasmartin merged 1 commit into
devfrom
storage-refactor
Aug 7, 2026
Merged

Split storage per owner, drop StorageApi and MemStorage#27
jonasmartin merged 1 commit into
devfrom
storage-refactor

Conversation

@KevinWahle

Copy link
Copy Markdown
Contributor

Split storage per owner, remove StorageApi and MemStorage

Previously, two unrelated storage implementations lived behind a single StorageApi trait.Treating them as interchangeable forced storage-related code to be generic when it didn't need to be.
src/storage/ now contains one concrete type for each use case:

  • BrokerServerStorage
  • BrokerNodeStorage
    The only shared type is BrokerStorageError.
    As a result, LocalChannel, BrokerService, run, and BrokerServer::new are all concrete and no longer generic over storage.

Removed the double lock

BrokerServerStorage now takes &self and performs its own internal locking. This allows Arc<Mutex<BrokerServerStorage>> to become simply BrokerServerStorage

Paths in, handles out

BrokerServer::new and BrokerNode::new now take:

server_storage_path: &str

and open the storage themselves.

LocalChannel ownership

LocalChannel is now created by the server via:

create_local_channel(id)

LocalChannel::new is now pub(crate). This guarantees that a server and its channels always share the same storage handle.

BrokerNode cleanup

node.rs is now 235 lines shorter. Many functions where moved into BrokerNodeStorage.

Key format changes

Server keys now use /-separated paths, matching the node queue layout.

Test cleanup

Two issues were fixed in the test infrastructure:

  1. close() only signaled shutdown, so the server's RocksDB handle remained alive and remove_dir_all() failed silently.
  2. test_readme_example never cleaned up its temporary directory.

@@ -0,0 +1,110 @@
// The BrokerServerStorage uses one key to store the uid and multiple keys to store the messages.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Added a subtask in the current ongoing task to: Sanitize any input that will go into the db, specially to reject anything that contains the separator /

@jonasmartin jonasmartin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks much clean now. Nice!
LGTM

  • Added a sub task to the current task

@jonasmartin
jonasmartin merged commit e92af2e into dev Aug 7, 2026
@jonasmartin
jonasmartin deleted the storage-refactor branch August 7, 2026 20:27
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.

2 participants