Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c5d0e81

Browse files
committed
core,graph,server: Only necessary reassign conditions: valid, unchanged
The subgraph name is no longer needed, so removed from input parameters. SubgraphRegistrarError variants added for DeploymentNotFound and DeploymentAssignmentUnchanged.
1 parent ef32859 commit c5d0e81

File tree

4 files changed

+22
-24
lines changed

4 files changed

+22
-24
lines changed

core/src/subgraph/registrar.rs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,11 @@ where
299299

300300
fn reassign_subgraph(
301301
&self,
302-
name: SubgraphName,
303302
hash: SubgraphDeploymentId,
304303
node_id: NodeId,
305304
) -> Box<Future<Item = (), Error = SubgraphRegistrarError> + Send + 'static> {
306305
Box::new(future::result(reassign_subgraph(
307306
self.store.clone(),
308-
name,
309307
hash,
310308
node_id,
311309
)))
@@ -849,36 +847,34 @@ fn remove_subgraph_versions(
849847
/// subgraph syncing process.
850848
fn reassign_subgraph(
851849
store: Arc<impl Store>,
852-
name: SubgraphName,
853850
hash: SubgraphDeploymentId,
854851
node_id: NodeId,
855852
) -> Result<(), SubgraphRegistrarError> {
856853
let mut ops = vec![];
857854

858-
// Find all subgraph version entities that point to this hash.
859-
let (version_summaries, read_summaries_abort_ops) =
860-
store.read_subgraph_version_summaries(vec![hash.clone()])?;
861-
ops.extend(read_summaries_abort_ops);
855+
let current_deployment = store.find(
856+
SubgraphDeploymentAssignmentEntity::query()
857+
.filter(EntityFilter::new_equal("id", hash.clone().to_string())),
858+
)?;
862859

863-
ops.push(EntityOperation::AbortUnless {
864-
description: "Provided name-deploymentId pair must match an existing subgraph version"
865-
.to_owned(),
866-
query: SubgraphEntity::query()
867-
.filter(EntityFilter::new_in("name", vec![name.clone().to_string()])),
868-
entity_ids: version_summaries
869-
.iter()
870-
.filter(|version| version.deployment_id == hash)
871-
.map(move |summary| summary.clone().subgraph_id)
872-
.collect(),
873-
});
860+
let current_node_id = current_deployment
861+
.first()
862+
.and_then(|d| d.get("nodeId"))
863+
.ok_or_else(|| SubgraphRegistrarError::DeploymentNotFound(hash.clone().to_string()))?;
864+
865+
if current_node_id.to_string() == node_id.to_string() {
866+
return Err(SubgraphRegistrarError::DeploymentAssignmentUnchanged(
867+
hash.clone().to_string(),
868+
));
869+
}
874870

875871
ops.push(EntityOperation::AbortUnless {
876-
description: "Target node must be different from the currently assigned one".to_owned(),
872+
description: "Deployment assignment is unchanged".to_owned(),
877873
query: SubgraphDeploymentAssignmentEntity::query().filter(EntityFilter::And(vec![
878-
EntityFilter::new_equal("nodeId", node_id.to_string()),
874+
EntityFilter::new_equal("nodeId", current_node_id.to_string()),
879875
EntityFilter::new_equal("id", hash.clone().to_string()),
880876
])),
881-
entity_ids: vec![],
877+
entity_ids: vec![hash.clone().to_string()],
882878
});
883879

884880
// Create the assignment update operations.

graph/src/components/subgraph/registrar.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ pub trait SubgraphRegistrar: Send + Sync + 'static {
3737

3838
fn reassign_subgraph(
3939
&self,
40-
name: SubgraphName,
4140
hash: SubgraphDeploymentId,
4241
node_id: NodeId,
4342
) -> Box<Future<Item = (), Error = SubgraphRegistrarError> + Send + 'static>;

graph/src/data/subgraph/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ pub enum SubgraphRegistrarError {
232232
NameExists(String),
233233
#[fail(display = "subgraph name not found: {}", _0)]
234234
NameNotFound(String),
235+
#[fail(display = "deployment not found: {}", _0)]
236+
DeploymentNotFound(String),
237+
#[fail(display = "deployment assignment unchanged: {}", _0)]
238+
DeploymentAssignmentUnchanged(String),
235239
#[fail(display = "subgraph registrar internal query error: {}", _0)]
236240
QueryExecutionError(QueryExecutionError),
237241
#[fail(display = "subgraph registrar error with store: {}", _0)]

server/json-rpc/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ struct SubgraphRemoveParams {
4747

4848
#[derive(Debug, Deserialize)]
4949
struct SubgraphReassignParams {
50-
name: SubgraphName,
5150
ipfs_hash: SubgraphDeploymentId,
5251
node_id: NodeId,
5352
}
@@ -153,7 +152,7 @@ where
153152

154153
Box::new(
155154
self.registrar
156-
.reassign_subgraph(params.name, params.ipfs_hash, params.node_id)
155+
.reassign_subgraph(params.ipfs_hash, params.node_id)
157156
.map_err(move |e| {
158157
if let SubgraphRegistrarError::Unknown(e) = e {
159158
error!(logger, "subgraph_reassignment failed: {}", e);

0 commit comments

Comments
 (0)