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

Fix some graphman bugs and improve usability #3416

Merged
merged 11 commits into from
Apr 1, 2022
Merged

Fix some graphman bugs and improve usability #3416

merged 11 commits into from
Apr 1, 2022

Conversation

lutter
Copy link
Collaborator

@lutter lutter commented Mar 31, 2022

The graphman index commands wouldn't work if the same deployment is used by multiple names.

This PR also overhauls the logic for how deployments are looked up to make the lookup uniform across various commands

@leoyvens leoyvens requested a review from tilacog April 1, 2022 09:33
Comment on lines 184 to 195
let mut locators: Vec<DeploymentLocator> = HashSet::<DeploymentLocator>::from_iter(
Deployment::lookup(pool, name)?
.into_iter()
.map(|deployment| deployment.locator()),
)
.into_iter()
.collect();
let deployment_locator = match locators.len() {
0 => anyhow::bail!("Found no deployment for `{}`", name),
1 => locators.pop().unwrap(),
n => anyhow::bail!("Found {} deployments for `{}`", n, name),
};
Copy link
Contributor

@tilacog tilacog Apr 1, 2022

Choose a reason for hiding this comment

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

Interesting!
I didn't realize a deployment could have multiple names.
Makes total sense now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, that's what keeps things interesting. When people deploy an IPFS hash that was already running under a different name, we just put an entry in subgraph and subgraph_version to point to that deployment. So the subgraph name -> deployment mapping is many-to-one

Comment on lines 108 to 122
let deployments: Vec<Deployment> = match self {
DeploymentSearch::Name { name } => {
let pattern = format!("%{}%", name);
query.filter(s::name.ilike(&pattern)).load(conn)?
}
DeploymentSearch::Hash { hash, shard } => {
let query = query.filter(ds::subgraph.eq(&hash));
match shard {
Some(shard) => query.filter(ds::shard.eq(shard)).load(conn)?,
None => query.load(conn)?,
}
}
DeploymentSearch::Deployment { namespace } => {
query.filter(ds::name.eq(&namespace)).load(conn)?
}
};
Copy link
Contributor

Choose a reason for hiding this comment

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

This is awesome.

Comment on lines +33 to +41
fn locate(store: &dyn SubgraphStore, hash: &str) -> Result<DeploymentLocator, anyhow::Error> {
let mut locators = store.locators(&hash)?;
match locators.len() {
0 => bail!("could not find subgraph {hash} we just created"),
1 => Ok(locators.pop().unwrap()),
n => bail!("there are {n} subgraphs with hash {hash}"),
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

This "get a single item from a collection" pattern happens so often that I created a convenience function for it here.
In the future, I'll try to make that even more generic/flexible so we can reuse it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The reason this is special and not used with DeploymentSearch is that that wants the primary pool, and we only have a SubgraphStore here. The run code could probably be changed to also access the primary pool. But it's a smaller issue (and run needs a lot more TLC anyway)

Comment on lines +45 to +48
None => {
println!("assigning {locator} to {node}");
conn.assign_subgraph(&site, &node)?;
}
Copy link
Contributor

@tilacog tilacog Apr 1, 2022

Choose a reason for hiding this comment

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

This is very convenient.

@tilacog
Copy link
Contributor

tilacog commented Apr 1, 2022

While reviewing this, I noticed that the DeploymentId inner value is being accessed directly outside the store crate, even though it's not supposed to:

/// An internal identifer for the specific instance of a deployment. The
/// identifier only has meaning in the context of a specific instance of
/// graph-node. Only store code should ever construct or consume it; all
/// other code passes it around as an opaque token.
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct DeploymentId(pub i32);

Do you think we could prevent this by changing its inner field visibility and implementing a getter?

-pub struct DeploymentId(pub i32);
+pub struct DeploymentId(pub(crate) i32);
...
+pub fn id(&self) -> i32 { self.0 }

Please let me know if this would be useful, and I'll come up with a follow-up PR :)

@lutter
Copy link
Collaborator Author

lutter commented Apr 1, 2022

Do you think we could prevent this by changing its inner field visibility and implementing a getter?

-pub struct DeploymentId(pub i32);
+pub struct DeploymentId(pub(crate) i32);
...
+pub fn id(&self) -> i32 { self.0 }

Please let me know if this would be useful, and I'll come up with a follow-up PR :)

I don't have strong opinions either way, but a getter feels cleaner than than just self.0 - maybe a to_i32() function would be better than id

lutter added 11 commits April 1, 2022 16:51
When looking for a deployment, like `sgdNNNN`, the code would complain
about it being ambiguous if that deployment was mapped to multiple names,
even though the name denotes a unique deployment.
The current way of looking up deployments is pretty adhoc. The
`DeploymentSearch` struct will make it possible to have the same mechanism
across all commands.
Also, get rid of the weird parsing of the table name in `stats
account-like`
- the deployment is now specified with DeploymentSearch
- reassign now works for both already assigned and unassigned subgraphs
@lutter lutter merged commit 5f4b2ce into master Apr 1, 2022
@lutter lutter deleted the lutter/locator branch April 1, 2022 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants