storage
Persistence Storage Layer providing state persistence operations between AppState and SQLAlchemy.
- class bedrock_server_manager.db.storage.Storage(db: Database, data_dir: str)
Handle loading, persisting, and transaction boundaries between the in-memory AppState and the persistent database.
- diagnostic_snapshot() StorageDiagnostics
Return owned write/reload observations without querying the database.
- property write_lock: Lock
Serialize domain transactions with state flushes and reloads.
- subscribe(listener: Callable[[AppState, ChangeSet], Any]) None
Register a callback to receive state change notifications when changesets are persisted.
- unsubscribe(listener: Callable[[AppState, ChangeSet], Any]) None
Unregisters a state change listener.
- transaction() AsyncGenerator[AsyncSession, None]
Observe transactions without making diagnostic writes part of the transaction.
- async commit_record(state: AppState, changeset: ChangeSet, name: str, *, get_lock: Callable[[str], Lock], get: Callable[[str], Record | None], build: Callable[[Record | None], Record], save: Callable[[AsyncSession, Record], Awaitable[None]], publish: Callable[[Record], None], acknowledge: Callable[[str], None], before_publish: Callable[[], Awaitable[None]] | None = None) Record
Publish a service mutation only after its transaction commits.
- async apply_changeset(state: AppState, changeset: ChangeSet) None
Retry the complete unit of work, never a commit after a rollback.
- async load_state(state: AppState | None = None) AppState
Load persistent state from the database into the AppState model. If no AppState instance is provided, a new one is created.
- async save_players(players_data: list[dict[str, str]]) int
Save player data to the database via player repository within a transaction.
- async get_all_players() list[dict[str, str]]
Return all known players from the database via player repository within a transaction.
- async save_state(state: AppState) None
Flushes and saves all unpersisted changes from AppState to the database.