Skip to content

Commit da1b5c6

Browse files
committed
store: Asyncify primary::Connection.least_assigned_node
1 parent 3e38a43 commit da1b5c6

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

store/postgres/src/primary.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1542,7 +1542,10 @@ impl Connection {
15421542

15431543
/// Return the name of the node that has the fewest assignments out of the
15441544
/// given `nodes`. If `nodes` is empty, return `None`
1545-
pub fn least_assigned_node(&mut self, nodes: &[NodeId]) -> Result<Option<NodeId>, StoreError> {
1545+
pub async fn least_assigned_node(
1546+
&mut self,
1547+
nodes: &[NodeId],
1548+
) -> Result<Option<NodeId>, StoreError> {
15461549
use subgraph_deployment_assignment as a;
15471550

15481551
let nodes: Vec<_> = nodes.iter().map(|n| n.as_str()).collect();

store/postgres/src/subgraph_store.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ impl SubgraphStore {
350350
// In that case, we need to use the shard and node
351351
// assignment that we used last time to avoid creating
352352
// the same deployment in another shard
353-
let (shard, node_id) = self.place(&name, &network_name, node_id)?;
353+
let (shard, node_id) = self.place(&name, &network_name, node_id).await?;
354354
let mut conn = self.primary_conn()?;
355355
let (site, site_was_created) = conn
356356
.allocate_site(shard, schema.id(), network_name, graft_base)
@@ -645,7 +645,7 @@ impl Inner {
645645
store.find_layout(site)
646646
}
647647

648-
fn place_on_node(
648+
async fn place_on_node(
649649
&self,
650650
mut nodes: Vec<NodeId>,
651651
default_node: NodeId,
@@ -660,7 +660,7 @@ impl Inner {
660660
let mut conn = self.primary_conn()?;
661661

662662
// unwrap is fine since nodes is not empty
663-
let node = conn.least_assigned_node(&nodes)?.unwrap();
663+
let node = conn.least_assigned_node(&nodes).await?.unwrap();
664664
Ok(node)
665665
}
666666
}
@@ -680,7 +680,7 @@ impl Inner {
680680
}
681681
}
682682

683-
fn place(
683+
async fn place(
684684
&self,
685685
name: &SubgraphName,
686686
network_name: &str,
@@ -699,7 +699,7 @@ impl Inner {
699699
match placement {
700700
None => Ok((PRIMARY_SHARD.clone(), default_node)),
701701
Some((shards, nodes)) => {
702-
let node = self.place_on_node(nodes, default_node)?;
702+
let node = self.place_on_node(nodes, default_node).await?;
703703
let shard = self.place_in_shard(shards)?;
704704

705705
Ok((shard, node))

0 commit comments

Comments
 (0)