Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all: Indicate whether to only locate active deployment #4395

Merged
merged 2 commits into from
Feb 24, 2023
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
id: runner-tests-1
uses: actions-rs/cargo@v1
env:
TESTS_GANACHE_HARD_WAIT_SECONDS: "30"
TESTS_GANACHE_HARD_WAIT_SECONDS: "60"
with:
command: test
args: --verbose --package graph-tests -- --skip parallel_integration_tests
Expand Down
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.active_locator(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 active_locator(&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().active_locator(&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 active_locator(&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