Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/client-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ pub trait ControlStateReadAccess {
// Replicas
async fn get_replica_by_id(&self, id: u64) -> anyhow::Result<Option<Replica>>;
async fn get_replicas(&self) -> anyhow::Result<Vec<Replica>>;
async fn get_leader_replica_by_database(&self, database_id: u64) -> Option<Replica>;
async fn get_leader_replica_by_database(&self, database_id: u64) -> anyhow::Result<Option<Replica>>;

// Energy
async fn get_energy_balance(&self, identity: &Identity) -> anyhow::Result<Option<EnergyBalance>>;
Expand Down Expand Up @@ -382,7 +382,7 @@ impl<T: ControlStateReadAccess + Send + Sync + Sync + ?Sized> ControlStateReadAc
(**self).get_replicas().await
}

async fn get_leader_replica_by_database(&self, database_id: u64) -> Option<Replica> {
async fn get_leader_replica_by_database(&self, database_id: u64) -> anyhow::Result<Option<Replica>> {
(**self).get_leader_replica_by_database(database_id).await
}

Expand Down
6 changes: 5 additions & 1 deletion crates/client-api/src/routes/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,11 @@ where
// even if we can't get hold of a running [ModuleHost].
Err(e) => {
warn!("could not obtain leader host for module logs: {e:#}");
let Some(replica) = worker_ctx.get_leader_replica_by_database(database.id).await else {
let Some(replica) = worker_ctx
.get_leader_replica_by_database(database.id)
.await
.map_err(log_and_500)?
else {
return Err(MISDIRECTED.into());
};
let logs_dir = worker_ctx.module_logs_dir(replica.id);
Expand Down
14 changes: 7 additions & 7 deletions crates/standalone/src/control_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,11 @@ impl ControlDb {
Ok(None)
}

pub fn get_leader_replica_by_database(&self, database_id: u64) -> Option<Replica> {
self.get_replicas()
.unwrap()
pub fn get_leader_replica_by_database(&self, database_id: u64) -> Result<Option<Replica>> {
Ok(self
.get_replicas()?
.into_iter()
.find(|instance| instance.database_id == database_id && instance.leader)
.find(|instance| instance.database_id == database_id && instance.leader))
}

pub fn get_replicas_by_database(&self, database_id: u64) -> Result<Vec<Replica>> {
Expand Down Expand Up @@ -463,7 +463,7 @@ impl ControlDb {
let id = self.db.generate_id()?;

replica.id = id;
let buf = bsatn::to_vec(&replica).unwrap();
let buf = bsatn::to_vec(&replica)?;

tree.insert(id.to_be_bytes(), buf)?;

Expand All @@ -482,7 +482,7 @@ impl ControlDb {
let scan_key: &[u8] = b"";
for result in tree.range(scan_key..) {
let (_key, value) = result?;
let node = bsatn::from_slice(&value[..]).unwrap();
let node = bsatn::from_slice(&value[..])?;
nodes.push(node);
}
Ok(nodes)
Expand All @@ -506,7 +506,7 @@ impl ControlDb {
let id = self.db.generate_id()?;

node.id = id;
let buf = bsatn::to_vec(&node).unwrap();
let buf = bsatn::to_vec(&node)?;

tree.insert(id.to_be_bytes(), buf)?;

Expand Down
6 changes: 3 additions & 3 deletions crates/standalone/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl NodeDelegate for StandaloneEnv {
}

async fn leader(&self, database_id: u64) -> Result<Host, Self::GetLeaderHostError> {
let Some(leader) = self.control_db.get_leader_replica_by_database(database_id) else {
let Some(leader) = self.control_db.get_leader_replica_by_database(database_id)? else {
return Err(GetLeaderHostError::NoSuchReplica);
};

Expand Down Expand Up @@ -233,8 +233,8 @@ impl spacetimedb_client_api::ControlStateReadAccess for StandaloneEnv {
Ok(self.control_db.get_replicas()?)
}

async fn get_leader_replica_by_database(&self, database_id: u64) -> Option<Replica> {
self.control_db.get_leader_replica_by_database(database_id)
async fn get_leader_replica_by_database(&self, database_id: u64) -> anyhow::Result<Option<Replica>> {
Ok(self.control_db.get_leader_replica_by_database(database_id)?)
}
// Energy
async fn get_energy_balance(&self, identity: &Identity) -> anyhow::Result<Option<EnergyBalance>> {
Expand Down
2 changes: 1 addition & 1 deletion crates/standalone/src/subcommands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn cli() -> clap::Command {
.default_value("0.0.0.0:3000")
.help(
"The address and port where SpacetimeDB should listen for connections. \
This defaults to to listen on all IP addresses on port 80.",
This defaults to listen on all IP addresses on port 3000.",
),
)
.arg(
Expand Down
2 changes: 1 addition & 1 deletion crates/testing/src/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl CompiledModule {
.unwrap();

let database = env.get_database_by_identity(&db_identity).await.unwrap().unwrap();
let instance = env.get_leader_replica_by_database(database.id).await.unwrap();
let instance = env.get_leader_replica_by_database(database.id).await.unwrap().unwrap();

let client_id = ClientActorId {
identity,
Expand Down