Skip to content

Commit c1de008

Browse files
committed
store: Better comments/small simplification for least_used_shard
1 parent cc366fe commit c1de008

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

store/postgres/src/primary.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,7 @@ impl<'a> Connection<'a> {
12321232
.iter()
12331233
.map(|(node, count)| (node.as_str(), *count))
12341234
.chain(missing)
1235-
.min_by(|(_, a), (_, b)| a.cmp(b))
1235+
.min_by_key(|(_, count)| *count)
12361236
.map(|(node, _)| NodeId::new(node).map_err(|()| node))
12371237
.transpose()
12381238
// This can't really happen since we filtered by valid NodeId's
@@ -1260,6 +1260,8 @@ impl<'a> Connection<'a> {
12601260
.order_by(sql::<i64>("count(*)"))
12611261
.load::<(String, i64)>(self.conn.as_ref())?;
12621262

1263+
// Any shards that have no deployments in them will not be in
1264+
// 'used'; add them in with a count of 0
12631265
let missing = shards
12641266
.into_iter()
12651267
.filter(|shard| !used.iter().any(|(s, _)| s == shard.as_str()))
@@ -1268,7 +1270,7 @@ impl<'a> Connection<'a> {
12681270
used.iter()
12691271
.map(|(shard, count)| (shard.as_str(), *count))
12701272
.chain(missing)
1271-
.min_by(|(_, a), (_, b)| a.cmp(b))
1273+
.min_by_key(|(_, count)| *count)
12721274
.map(|(shard, _)| Shard::new(shard.to_string()))
12731275
.transpose()
12741276
// This can't really happen since we filtered by valid shards

store/postgres/src/subgraph_store.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,12 @@ impl ToSql<Text, Pg> for Shard {
111111
}
112112
}
113113

114-
/// Decide where a new deployment should be placed based on the subgraph name
115-
/// and the network it is indexing. If the deployment can be placed, returns
116-
/// the name of the database shard for the deployment and the names of the
117-
/// indexers that should index it. The deployment should then be assigned to
118-
/// one of the returned indexers.
114+
/// Decide where a new deployment should be placed based on the subgraph
115+
/// name and the network it is indexing. If the deployment can be placed,
116+
/// returns a list of eligible database shards for the deployment and the
117+
/// names of the indexers that should index it. The deployment should then
118+
/// be assigned to one of the returned indexers and placed into one of the
119+
/// shards.
119120
pub trait DeploymentPlacer {
120121
fn place(&self, name: &str, network: &str)
121122
-> Result<Option<(Vec<Shard>, Vec<NodeId>)>, String>;

0 commit comments

Comments
 (0)