use std::io;
use std::sync::atomic::{AtomicU64, Ordering};
use crate::config::Config;
use crate::store::{Shards, Store};
#[cfg(not(target_arch = "wasm32"))]
pub(crate) fn spawn_replica_runner(
config: &Config,
shards: &Shards,
) -> Option<crate::replica_runner::ReplicaRunner> {
let upstream = config.replica_upstream.as_ref()?.clone();
Some(crate::replica_runner::ReplicaRunner::spawn(
shards.clone(),
upstream,
config.replica_id.clone(),
config.replica_reconnect_min,
config.replica_reconnect_max,
))
}
#[cfg(not(target_arch = "wasm32"))]
pub(crate) fn fresh_replica_id() -> String {
static SEQ: AtomicU64 = AtomicU64::new(0);
let n = SEQ.fetch_add(1, Ordering::Relaxed);
format!("kevy-embedded-{}-{}", std::process::id(), n)
}
pub(crate) fn ensure_writable(store: &Store) -> io::Result<()> {
if store.is_replica() {
return Err(io::Error::other(
"READONLY You can't write against a kevy-embedded replica",
));
}
Ok(())
}