这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@lexi-lambda
Copy link
Contributor

@lexi-lambda lexi-lambda commented Jan 13, 2020

Description

The way we perform internal metadata migrations within graphql-engine has a long and storied history.

Originally, we just reused the same infrastructure we use for CLI migrations, but this caused #2826. In #2379, we resolved the issue by dropping and recreating all system-defined metadata whenever we migrated the SQL schema, but that in turn caused #3354. The recent incremental schema cache construction changes in #3394 mostly fixed that problem, but as discovered in #3654, the process can still be very slow on underpowered Postgres instances.

This PR adds a fast path for the internal metadata migrations to improve the performance of internal server migrations. It does not affect the performance of user-defined CLI migrations, so it’s not a comprehensive fix, but it’s much simpler to make our own migrations faster (mostly because we don’t have to worry so much about the interface), so this takes advantage of that low-hanging fruit.

Affected components

  • Server

Related Issues

#3654

Solution and Design

This PR eliminates the use of the CLI migrations code path for performing internal metadata migrations, instead doing it all directly in code in a single batch of queries against the database. This is a little unsatisfying, since it means our internal migrations are “blessed” compared to user-defined CLI migrations, but it’s so easy to do that I decided to give in and make the change.

Server checklist

Catalog upgrade

Does this PR change Hasura Catalog version?

  • No

Metadata

Does this PR add a new Metadata feature?

  • No

GraphQL

  • No new GraphQL schema is generated

Breaking changes

  • No Breaking changes

@lexi-lambda lexi-lambda added the c/server Related to server label Jan 13, 2020
@netlify
Copy link

netlify bot commented Jan 13, 2020

Deploy preview for hasura-docs ready!

Built with commit f8264cd

https://deploy-preview-3686--hasura-docs.netlify.com

@hasura-bot
Copy link
Contributor

Review app for commit ce6e1bc deployed to Heroku: https://hge-ci-pull-3686.herokuapp.com
Docker image for server: hasura/graphql-engine:pull3686-ce6e1bc4

@lexi-lambda lexi-lambda force-pushed the 3654-migration-fast-path branch from fafde1e to bc925e2 Compare January 14, 2020 00:18
@lexi-lambda lexi-lambda marked this pull request as ready for review January 14, 2020 00:18
@lexi-lambda lexi-lambda force-pushed the 3654-migration-fast-path branch from bc925e2 to f8264cd Compare January 14, 2020 00:19
@hasura-bot
Copy link
Contributor

Review app for commit f8264cd deployed to Heroku: https://hge-ci-pull-3686.herokuapp.com
Docker image for server: hasura/graphql-engine:pull3686-f8264cd0

@0x777
Copy link
Member

0x777 commented Jan 14, 2020

Currently we have replace_metadata which is backed by a ReplaceMetadata type (should've been called something like GraphqlEngineMetadata) which sets graphql-engine's metadata to the given metadata.

I'm wondering if it makes sense to have a query like add_metadata which instead of replacing, 'merges' the given metadata into the existing metadata. Is it possible to have add_metadata to perform better than a bulk query of adding tables, relationships etc? If so, we can just specify our internal catalog as a single query instead of using a bulk query like we do currently.

(The implementation in this PR looks like an interface to add_metadata which can only be used internally)

@lexi-lambda
Copy link
Contributor Author

Currently we have replace_metadata which is backed by a ReplaceMetadata type (should've been called something like GraphqlEngineMetadata) which sets graphql-engine's metadata to the given metadata.

I'm wondering if it makes sense to have a query like add_metadata which instead of replacing, 'merges' the given metadata into the existing metadata. Is it possible to have add_metadata to perform better than a bulk query of adding tables, relationships etc? If so, we can just specify our internal catalog as a single query instead of using a bulk query like we do currently.

I considered this, too, and I think it’s a totally viable alternative. I wasn’t sure whether it was better to split out some ReplaceMetadata functionality to do what we want or just do it in code.

Eventually, I decided to just do it in the code because that seemed very easy, and it’s very simple to change later. I figured that what we really want is a more general solution to this that helps CLI migrations, too, and maybe at that point we could go back to sharing the same code path, but I couldn’t figure out exactly what I thought that should look like, so I opted to do the simplest thing that seemed least likely to introduce tech debt.

That said, I’m really not attached to this, and in fact I’d actually love for someone else to make this decision for me. 😄 If you think I should tweak this to keep the .yaml file but go through a ReplaceMetadata-like code path, I’m happy to do that.

@lexi-lambda
Copy link
Contributor Author

By the way, I should add why I didn’t want to implement the AddMetadata API you’re suggesting: I could not figure out how to have good error reporting for it without doing a lot of additional engineering to associate all that information properly. So I wouldn’t want to expose it as a user-facing API without thinking a lot harder about what the semantics ought to be, and at that point it seemed less clearly valuable.

We could still have something that works like that internally that we use for this code path but not actually expose it as a valid RQL query, and we could adapt it into a full API at some point in the future. But I don’t think it makes sense to add that API right now without more thought and discussion.

@0x777
Copy link
Member

0x777 commented Jan 14, 2020

I could not figure out how to have good error reporting for it without doing a lot of additional engineering to associate all that information properly

Yup, this was one of the concerns that I had.

That said, I’m really not attached to this, and in fact I’d actually love for someone else to make this decision for me

Let's keep this implementation for now, given that it improves the startup time. We should definitely think about the right semantics for an add_metadata like query and in general how to improve the performance of cli migrations.

@lexi-lambda lexi-lambda merged commit feb4a05 into hasura:master Jan 14, 2020
@hasura-bot
Copy link
Contributor

Review app https://hge-ci-pull-3686.herokuapp.com is deleted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c/server Related to server

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants