diff --git a/core/src/subgraph/registrar.rs b/core/src/subgraph/registrar.rs index fe80d118457..6c9e9e3c952 100644 --- a/core/src/subgraph/registrar.rs +++ b/core/src/subgraph/registrar.rs @@ -455,6 +455,14 @@ where Ok(()) } + async fn remove_deployment(&self, id: &DeploymentHash) -> Result<(), SubgraphRegistrarError> { + self.store.drop_subgraph(id)?; + + debug!(self.logger, "Removing deployment(s)"; "hash" => id.to_string()); + + Ok(()) + } + /// Reassign a subgraph deployment to a different node. /// /// Reassigning to a nodeId that does not match any reachable graph-nodes will effectively pause the diff --git a/docker/bin/drop b/docker/bin/drop new file mode 100755 index 00000000000..b8e96a1e7fd --- /dev/null +++ b/docker/bin/drop @@ -0,0 +1,12 @@ +#! /bin/bash + +if [ $# != 1 ]; then + echo "usage: drop " + exit 1 +fi + +api="http://index-node.default/" + +echo "Dropping deployment $1" +data=$(printf '{"jsonrpc": "2.0", "method": "subgraph_drop", "params": {"ipfs_hash":"%s"}, "id":"1"}' "$1") +curl -s -H "content-type: application/json" --data "$data" "$api" diff --git a/graph/src/components/store/traits.rs b/graph/src/components/store/traits.rs index 0ac80902a66..16c06728977 100644 --- a/graph/src/components/store/traits.rs +++ b/graph/src/components/store/traits.rs @@ -102,6 +102,9 @@ pub trait SubgraphStore: Send + Sync + 'static { /// their assignment, but keep the deployments themselves around fn remove_subgraph(&self, name: SubgraphName) -> Result<(), StoreError>; + /// Remove all the subgraph's versions, assignments and data. + fn drop_subgraph(&self, name: &DeploymentHash) -> Result<(), StoreError>; + /// Assign the subgraph with `id` to the node `node_id`. If there is no /// assignment for the given deployment, report an error. fn reassign_subgraph( diff --git a/graph/src/components/subgraph/registrar.rs b/graph/src/components/subgraph/registrar.rs index 691c341e38b..c4149212d8b 100644 --- a/graph/src/components/subgraph/registrar.rs +++ b/graph/src/components/subgraph/registrar.rs @@ -48,6 +48,7 @@ pub trait SubgraphRegistrar: Send + Sync + 'static { ) -> Result; async fn remove_subgraph(&self, name: SubgraphName) -> Result<(), SubgraphRegistrarError>; + async fn remove_deployment(&self, hash: &DeploymentHash) -> Result<(), SubgraphRegistrarError>; async fn reassign_subgraph( &self, diff --git a/server/json-rpc/src/lib.rs b/server/json-rpc/src/lib.rs index b8e5b0330b7..c2ce0b01c06 100644 --- a/server/json-rpc/src/lib.rs +++ b/server/json-rpc/src/lib.rs @@ -63,6 +63,11 @@ impl JsonRpcServer { state.remove_handler(params.parse()?).await }) .unwrap(); + rpc_module + .register_async_method("subgraph_drop", |params, state| async move { + state.drop_handler(params.parse()?).await + }) + .unwrap(); rpc_module .register_async_method("subgraph_reassign", |params, state| async move { state.reassign_handler(params.parse()?).await @@ -150,6 +155,22 @@ impl ServerState { } } + /// Handler for the `subgraph_drop` endpoint. + async fn drop_handler(&self, params: SubgraphDropParams) -> JsonRpcResult { + info!(&self.logger, "Received subgraph_drop request"; "params" => format!("{:?}", params)); + + match self.registrar.remove_deployment(¶ms.ipfs_hash).await { + Ok(_) => Ok(Value::Null), + Err(e) => Err(json_rpc_error( + &self.logger, + "subgraph_drop", + e, + Self::REMOVE_ERROR, + params, + )), + } + } + /// Handler for the `subgraph_remove` endpoint. async fn remove_handler(&self, params: SubgraphRemoveParams) -> JsonRpcResult { info!(&self.logger, "Received subgraph_remove request"; "params" => format!("{:?}", params)); @@ -289,6 +310,11 @@ struct SubgraphRemoveParams { name: SubgraphName, } +#[derive(Debug, Deserialize)] +struct SubgraphDropParams { + ipfs_hash: DeploymentHash, +} + #[derive(Debug, Deserialize)] struct SubgraphReassignParams { ipfs_hash: DeploymentHash, diff --git a/store/postgres/src/subgraph_store.rs b/store/postgres/src/subgraph_store.rs index 41cbef15982..372172df427 100644 --- a/store/postgres/src/subgraph_store.rs +++ b/store/postgres/src/subgraph_store.rs @@ -1351,6 +1351,23 @@ impl SubgraphStoreTrait for SubgraphStore { }) } + fn drop_subgraph(&self, hash: &DeploymentHash) -> Result<(), StoreError> { + let deployments = self.subgraphs_for_deployment_hash(hash)?; + for (deployment, _) in deployments.into_iter() { + self.remove_subgraph( + SubgraphName::new(deployment.clone()) + .map_err(|_| StoreError::DeploymentNotFound(deployment))?, + )?; + } + + let locators = self.locators(hash)?; + for loc in locators.iter() { + self.inner.remove_deployment(loc.id.into())?; + } + + Ok(()) + } + fn reassign_subgraph( &self, deployment: &DeploymentLocator,