mirror of
https://github.com/scylladb/scylladb.git
synced 2026-06-05 22:43:15 +00:00
The previous `persistence` implemented the `raft::persistence` interface and had two different responsibilities: - representing "persistent storage", with the ability to store and load stuff to/from it, - accessing in-memory state shared with a corresponding instance of `impure_state_machine` that is running along `persistence` inside a `raft::server`. For example, `persistence::store_snapshot_descriptor` would persist not only the snapshot descriptor, but also the corresponding snapshot. The descriptor was provided through a parameter but the snapshot wasn't. To obtain the snapshot we use a data structure (`snapshots_t`) that both `persistence` and `impure_state_machine` had a reference to. We split `persistence` into two classes: - `persistence` which handles only the first responsibility, i.e. storing and loading stuff; everything to store is provided through function parameters (e.g. now we have a `store_snapshot` function which takes both the snapshot and its descriptor through the parameters) and everything to load is returned directly by functions (e.g. `load_snapshot` returns a pair containing both the descriptor and corresponding snapshot) - `persistence_proxy` (for lack of a better name) which implements `raft::persistence`, contains the above `persistence` inside and shares a data structure with `impure_state_machine` (so `persistence_proxy` corresponds to the old `persistence`). The goal is to prepare for reusing the persisted stuff between different instances of `raft::server` running in a single test when simulating server shutdowns/crashes and restarts. When destroying a `raft::server`, we destroy its `impure_state_machine` and `persistence_proxy` (we are forced to because constructing a `raft::server` requires a `unique_ptr` to `raft::persistence`), but we will be able to keep the underlying `persistence` for the next instance (if we simulate a restart) - after a slight modification made in the next commit.