Skip to content

Commit cc0f2d3

Browse files
committed
all: Indicate whether to only locate active deployment
The reassign_subgraph JSON-RPC call will fail if a deployment exists in multiple shards. To disambiguate that, change the call so that it only affects the active deployment. Fixes #4394
1 parent 83e4fb3 commit cc0f2d3

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

core/src/subgraph/registrar.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -411,21 +411,10 @@ where
411411
hash: &DeploymentHash,
412412
node_id: &NodeId,
413413
) -> Result<(), SubgraphRegistrarError> {
414-
let locations = self.store.locators(hash)?;
415-
let deployment = match locations.len() {
416-
0 => return Err(SubgraphRegistrarError::DeploymentNotFound(hash.to_string())),
417-
1 => locations[0].clone(),
418-
_ => {
419-
return Err(SubgraphRegistrarError::StoreError(
420-
anyhow!(
421-
"there are {} different deployments with id {}",
422-
locations.len(),
423-
hash.as_str()
424-
)
425-
.into(),
426-
))
427-
}
428-
};
414+
let locator = self.store.active_locator(hash)?;
415+
let deployment =
416+
locator.ok_or_else(|| SubgraphRegistrarError::DeploymentNotFound(hash.to_string()))?;
417+
429418
self.store.reassign_subgraph(&deployment, node_id)?;
430419

431420
Ok(())

graph/src/components/store/traits.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,13 @@ pub trait SubgraphStore: Send + Sync + 'static {
156156

157157
async fn is_healthy(&self, id: &DeploymentHash) -> Result<bool, StoreError>;
158158

159-
/// Find the deployment locators for the subgraph with the given hash
159+
/// Find all deployment locators for the subgraph with the given hash.
160160
fn locators(&self, hash: &str) -> Result<Vec<DeploymentLocator>, StoreError>;
161161

162+
/// Find the deployment locator for the active deployment with the given
163+
/// hash. Returns `None` if there is no deployment with that hash
164+
fn active_locator(&self, hash: &str) -> Result<Option<DeploymentLocator>, StoreError>;
165+
162166
/// This migrates subgraphs that existed before the raw_yaml column was added.
163167
async fn set_manifest_raw_yaml(
164168
&self,

graphql/tests/query.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ async fn setup(
138138

139139
global_init();
140140
let id = DeploymentHash::new(id).unwrap();
141-
let loc = store.subgraph_store().locators(&id).unwrap().pop();
141+
let loc = store.subgraph_store().active_locator(&id).unwrap();
142142

143143
match loc {
144144
Some(loc) if id_type.deployment_id() == loc.hash.as_str() => loc,

store/postgres/src/subgraph_store.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,6 +1397,17 @@ impl SubgraphStoreTrait for SubgraphStore {
13971397
.collect())
13981398
}
13991399

1400+
fn active_locator(&self, hash: &str) -> Result<Option<DeploymentLocator>, StoreError> {
1401+
let sites = self.mirror.find_sites(&[hash.to_string()], true)?;
1402+
if sites.len() > 1 {
1403+
return Err(constraint_violation!(
1404+
"There are {} active deployments for {hash}, there should only be one",
1405+
sites.len()
1406+
));
1407+
}
1408+
Ok(sites.first().map(DeploymentLocator::from))
1409+
}
1410+
14001411
async fn set_manifest_raw_yaml(
14011412
&self,
14021413
hash: &DeploymentHash,

0 commit comments

Comments
 (0)