pub struct ReplicatedEngine { /* private fields */ }Expand description
Wraps Engine + HttpReplicationServer (primary) or Engine + AntiEntropyLoop (replica).
Background threads are owned by this struct. When dropped, threads continue
running until the process exits — same behavior as calling start() manually.
Implementations§
Source§impl ReplicatedEngine
impl ReplicatedEngine
Sourcepub fn open_primary(
config: EdgestoreConfig,
bind_addr: &str,
) -> Result<ReplicatedEngine, EdgestoreError>
pub fn open_primary( config: EdgestoreConfig, bind_addr: &str, ) -> Result<ReplicatedEngine, EdgestoreError>
Open a primary replication node.
Starts HttpReplicationServer on bind_addr in a background thread.
The engine is writable. Other nodes point their AntiEntropyLoop at this address.
Sourcepub fn open_replica(
config: EdgestoreConfig,
primary_url: &str,
) -> Result<ReplicatedEngine, EdgestoreError>
pub fn open_replica( config: EdgestoreConfig, primary_url: &str, ) -> Result<ReplicatedEngine, EdgestoreError>
Open a replica node.
Opens the engine in read-only mode (Engine::open_readonly) and starts an
AntiEntropyLoop that pulls from primary_url. The engine rejects all write
calls with Err(EdgestoreError::ReadOnly).
primary_url must be the base URL of the primary’s HttpReplicationServer
(e.g. "http://host:8900").
Sourcepub fn promote_to_primary(
config: EdgestoreConfig,
bind_addr: &str,
old_primary_url: Option<&str>,
) -> Result<ReplicatedEngine, EdgestoreError>
pub fn promote_to_primary( config: EdgestoreConfig, bind_addr: &str, old_primary_url: Option<&str>, ) -> Result<ReplicatedEngine, EdgestoreError>
Promote a replica engine to primary with write-token fencing (BtrLog §4.2).
§Fencing protocol
- If
old_primary_urlis provided, fetch its currentwtokenviaGET /watermark. Failure (network or 404) is non-fatal — the local token is used as the floor. - Compute
new_token = max(fetched_wtoken, local_wtoken) + 1. - Persist
new_tokento{db_path}/WTOKENviaengine.set_write_token. - Start
HttpReplicationServeronbind_addr.
Anti-entropy loops on other replicas that have already seen the old primary’s
wtoken will observe the higher token and can log or refuse stale segments.
§Arguments
config— database configuration for the new primary.bind_addr— address to bind the HTTP replication server (e.g."0.0.0.0:8900").old_primary_url— base URL of the old primary, used to fetch itswtokenbefore fencing. PassNonewhen the old primary is already down.
Sourcepub fn engine(&self) -> &Arc<Mutex<Engine>> ⓘ
pub fn engine(&self) -> &Arc<Mutex<Engine>> ⓘ
Access the underlying Arc<Mutex<Engine>> for reads (replica) or reads+writes (primary).
Sourcepub fn bound_port(&self) -> Option<u16>
pub fn bound_port(&self) -> Option<u16>
Port the HttpReplicationServer is listening on, or None for a replica.