-
Notifications
You must be signed in to change notification settings - Fork 980
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
Allow redeployment of grafted subgraph even when graft_base is not available #4695
Changes from 1 commit
a54409d
2d372c9
5062fe8
f275665
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1441,6 +1441,11 @@ impl DeploymentStore { | |
.await | ||
} | ||
|
||
pub(crate) fn exists(&self, id: Arc<Site>) -> Result<bool, StoreError> { | ||
let conn = self.get_conn()?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @leoyvens i tried that initially wouldn't that mean i would have to make all the callers also async function to await on it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was unsure if i should do that, let me know if its ok. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there any non-async callers? If there are then we'd need to keep this one and add an async version. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fn create_deployment_internal is not async but its callers can be made async ( cause callers all the way is async ). Should i make them all async in that case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see now that this is a bigger problem since |
||
deployment::exists(&conn, &id) | ||
} | ||
|
||
pub(crate) fn graft_pending( | ||
&self, | ||
id: &DeploymentHash, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -424,6 +424,16 @@ impl SubgraphStoreInner { | |
store.find_layout(site) | ||
} | ||
|
||
pub(crate) fn deployment_exists(&self, id: &DeploymentHash) -> Result<bool, StoreError> { | ||
let (store, site) = match self.store(id) { | ||
Ok(pair) => pair, | ||
Err(StoreError::DeploymentNotFound(_)) => return Ok(false), | ||
Err(err) => return Err(err), | ||
}; | ||
|
||
store.exists(site) | ||
} | ||
|
||
fn place_on_node( | ||
&self, | ||
mut nodes: Vec<NodeId>, | ||
|
@@ -516,11 +526,19 @@ impl SubgraphStoreInner { | |
|
||
self.evict(schema.id())?; | ||
|
||
let graft_base = deployment | ||
.graft_base | ||
.as_ref() | ||
.map(|base| self.layout(base)) | ||
.transpose()?; | ||
let deployment_hash = schema.id(); | ||
let exists = self.deployment_exists(deployment_hash)?; | ||
let graft_base = deployment.graft_base.as_ref(); | ||
|
||
let schema_version = if exists { | ||
let layout = self.layout(deployment_hash)?; | ||
layout.site.schema_version | ||
} else if let Some(graft_base) = graft_base { | ||
let layout = self.layout(graft_base)?; | ||
layout.site.schema_version | ||
} else { | ||
DeploymentSchemaVersion::LATEST | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we could avoid the need for a
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. got it, will make that change |
||
|
||
let (site, node_id) = { | ||
// We need to deal with two situations: | ||
|
@@ -534,21 +552,31 @@ impl SubgraphStoreInner { | |
// assignment that we used last time to avoid creating | ||
// the same deployment in another shard | ||
let (shard, node_id) = self.place(&name, &network_name, node_id)?; | ||
let schema_version = match &graft_base { | ||
None => DeploymentSchemaVersion::LATEST, | ||
Some(src_layout) => src_layout.site.schema_version, | ||
}; | ||
let conn = self.primary_conn()?; | ||
let site = conn.allocate_site(shard, schema.id(), network_name, schema_version)?; | ||
let node_id = conn.assigned_node(&site)?.unwrap_or(node_id); | ||
(site, node_id) | ||
}; | ||
let site = Arc::new(site); | ||
|
||
if let Some(graft_base) = &graft_base { | ||
self.primary_conn()? | ||
.record_active_copy(graft_base.site.as_ref(), site.as_ref())?; | ||
} | ||
// if the deployment already exists, we don't need to perform any copying | ||
// so we can set graft_base to None | ||
// if it doesn't exist, we need to copy the graft base to the new deployment | ||
let graft_base = if !exists { | ||
let graft_base = deployment | ||
.graft_base | ||
.as_ref() | ||
.map(|base| self.layout(base)) | ||
.transpose()?; | ||
|
||
if let Some(graft_base) = &graft_base { | ||
self.primary_conn()? | ||
.record_active_copy(graft_base.site.as_ref(), site.as_ref())?; | ||
} | ||
graft_base | ||
} else { | ||
None | ||
}; | ||
|
||
// Create the actual databases schema and metadata entries | ||
let deployment_store = self | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an
fn graft_pending
which we perhaps should additionally check, because it checks if the subgraph has actually finished the graft process. It would be nice if we were able to use that here.