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

Add json-rpc api support for dropping subgraphs #5651

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions core/src/subgraph/registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Comment on lines +458 to +464
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the debug logs supposed to be before the self.store.drop_subgraph(id)?; ?


/// Reassign a subgraph deployment to a different node.
///
/// Reassigning to a nodeId that does not match any reachable graph-nodes will effectively pause the
Expand Down
12 changes: 12 additions & 0 deletions docker/bin/drop
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#! /bin/bash

if [ $# != 1 ]; then
echo "usage: drop <ipfs_hash>"
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"
3 changes: 3 additions & 0 deletions graph/src/components/store/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions graph/src/components/subgraph/registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub trait SubgraphRegistrar: Send + Sync + 'static {
) -> Result<DeploymentLocator, SubgraphRegistrarError>;

async fn remove_subgraph(&self, name: SubgraphName) -> Result<(), SubgraphRegistrarError>;
async fn remove_deployment(&self, hash: &DeploymentHash) -> Result<(), SubgraphRegistrarError>;

async fn reassign_subgraph(
&self,
Expand Down
26 changes: 26 additions & 0 deletions server/json-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -150,6 +155,22 @@ impl<R: SubgraphRegistrar> ServerState<R> {
}
}

/// Handler for the `subgraph_drop` endpoint.
async fn drop_handler(&self, params: SubgraphDropParams) -> JsonRpcResult<GraphValue> {
info!(&self.logger, "Received subgraph_drop request"; "params" => format!("{:?}", params));

match self.registrar.remove_deployment(&params.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<GraphValue> {
info!(&self.logger, "Received subgraph_remove request"; "params" => format!("{:?}", params));
Expand Down Expand Up @@ -289,6 +310,11 @@ struct SubgraphRemoveParams {
name: SubgraphName,
}

#[derive(Debug, Deserialize)]
struct SubgraphDropParams {
ipfs_hash: DeploymentHash,
}

#[derive(Debug, Deserialize)]
struct SubgraphReassignParams {
ipfs_hash: DeploymentHash,
Expand Down
17 changes: 17 additions & 0 deletions store/postgres/src/subgraph_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))?,
)?;
Comment on lines +1357 to +1360
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont this delete both the pending and current version of a subgraph that belongs to the same name as hash provided? Thought we are moving away from that behaviour?

}

let locators = self.locators(hash)?;
for loc in locators.iter() {
self.inner.remove_deployment(loc.id.into())?;
}

Ok(())
}

fn reassign_subgraph(
&self,
deployment: &DeploymentLocator,
Expand Down
Loading