Skip to content

Commit

Permalink
all: Indicate whether to only locate active deployment
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lutter committed Feb 24, 2023
1 parent 336cf45 commit 2b58fb9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
19 changes: 4 additions & 15 deletions core/src/subgraph/registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,21 +411,10 @@ where
hash: &DeploymentHash,
node_id: &NodeId,
) -> Result<(), SubgraphRegistrarError> {
let locations = self.store.locators(hash)?;
let deployment = match locations.len() {
0 => return Err(SubgraphRegistrarError::DeploymentNotFound(hash.to_string())),
1 => locations[0].clone(),
_ => {
return Err(SubgraphRegistrarError::StoreError(
anyhow!(
"there are {} different deployments with id {}",
locations.len(),
hash.as_str()
)
.into(),
))
}
};
let locator = self.store.locate_active(hash)?;
let deployment =
locator.ok_or_else(|| SubgraphRegistrarError::DeploymentNotFound(hash.to_string()))?;

self.store.reassign_subgraph(&deployment, node_id)?;

Ok(())
Expand Down
6 changes: 5 additions & 1 deletion graph/src/components/store/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,13 @@ pub trait SubgraphStore: Send + Sync + 'static {

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

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

/// Find the deployment locator for the active deployment with the given
/// hash. Returns `None` if there is no deployment with that hash
fn locate_active(&self, hash: &str) -> Result<Option<DeploymentLocator>, StoreError>;

/// This migrates subgraphs that existed before the raw_yaml column was added.
async fn set_manifest_raw_yaml(
&self,
Expand Down
2 changes: 1 addition & 1 deletion graphql/tests/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ async fn setup(

global_init();
let id = DeploymentHash::new(id).unwrap();
let loc = store.subgraph_store().locators(&id).unwrap().pop();
let loc = store.subgraph_store().locate_active(&id).unwrap();

match loc {
Some(loc) if id_type.deployment_id() == loc.hash.as_str() => loc,
Expand Down
11 changes: 11 additions & 0 deletions store/postgres/src/subgraph_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,17 @@ impl SubgraphStoreTrait for SubgraphStore {
.collect())
}

fn locate_active(&self, hash: &str) -> Result<Option<DeploymentLocator>, StoreError> {
let sites = self.mirror.find_sites(&[hash.to_string()], true)?;
if sites.len() > 1 {
return Err(constraint_violation!(
"There are {} active deployments for {hash}, there should only be one",
sites.len()
));
}
Ok(sites.first().map(DeploymentLocator::from))
}

async fn set_manifest_raw_yaml(
&self,
hash: &DeploymentHash,
Expand Down

0 comments on commit 2b58fb9

Please sign in to comment.