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

Small tweaks to smoke tests of planetscale driver in query-engines. #4085

Closed
wants to merge 3 commits into from

Conversation

miguelff
Copy link
Contributor

@miguelff miguelff commented Jul 26, 2023

Besides applying some naming conventions consistenly, I made changes to the connector to change the mechanics around initialisation and health checking.

In the planetscale serverless connector, I replaced maybeVersion with a promise. The query to retrieve the version executes aynchronously on the constructor as before, but it's awaited whenever the version is required, particularly to provide consistent health information. Otherwise isHealthy would be returning false while the promise hasn't resolved yet.

A potential optimization would be to consider the backend healthy until the promise is resolved and failed. That can help with coldstarts if being healthy is a precondition to send queries. Because we will be returning true for isHealthy until proven otherwise by a query failing.

@miguelff miguelff requested a review from a team as a code owner July 26, 2023 15:49
@codspeed-hq
Copy link

codspeed-hq bot commented Jul 26, 2023

CodSpeed Performance Report

Merging #4085 will improve performances by 5.01%

Comparing mff/nps4 (98af333) with main (4b132e0)

Summary

🔥 1 improvements
✅ 10 untouched benchmarks

Benchmarks breakdown

Benchmark main mff/nps4 Change
🔥 large_read 7.7 ms 7.3 ms +5.01%

@miguelff miguelff requested review from a team, SevInf and aqrln and removed request for a team July 27, 2023 10:28
The promise executes aynchrounsly on constructor, but it's awaited whenever the version is required, particularly to provide consistent health information. Otherwise isHealthy would be returning false, while the promise hasn't resolved yet.
@miguelff
Copy link
Contributor Author

I'm making further changes after neon support has been merged, will request review again once done.

provider = "@prisma/neon"
url = env("JS_NEON_DATABASE_URL")
shadowDatabaseUrl = env("JS_NEON_SHADOW_DATABASE_URL")
// Once ran `prisma migrate reset` as per instructions in README.md replace `mysql` with `@prisma/planetscale` in the line below
Copy link
Member

Choose a reason for hiding this comment

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

The comment implies that provider is mysql initially, should provider = "mysql" be committed instead, or should the comment be reworded to suggest replacing @prisma/planetscale with mysql before running prisma migrate reset?

this.versionPromise = new Promise((resolve, reject) => {
this.pool.query('SELECT VERSION()')
.then((results) => resolve(results.rows[0]['version']))
.catch((error) => reject(error));
Copy link
Member

@aqrln aqrln Jul 28, 2023

Choose a reason for hiding this comment

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

This catch will also run for errors that happen in the resolve callback and not just in this.pool.query, should this be the second argument to then instead?

Or better yet, could we replace the whole statement with

this.versionPromise = this.pool.query('SELECT VERSION()')
  .then((results) => results.rows[0]['version'])`

or is there a reason why we are wrapping it in another promise?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I think we could define it the way you suggest, if resolve is a defined symbol within the closure.

Copy link
Member

Choose a reason for hiding this comment

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

that was a copy-paste artifact, sorry, I meant

this.versionPromise = this.pool.query('SELECT VERSION()')
  .then((results) => results.rows[0]['version'])`

this.versionPromise = new Promise((resolve, reject) => {
this.client.execute('SELECT @@version')
.then((results) => resolve(results.rows[0]['@@version']))
.catch((error) => reject(error));
Copy link
Member

Choose a reason for hiding this comment

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

same as above

@jkomyno
Copy link
Contributor

jkomyno commented Aug 1, 2023

Note: I recommend deprecating this PR in favor of #4094. Please refer to the description and comments therein

@miguelff
Copy link
Contributor Author

miguelff commented Aug 1, 2023

Closing in favor of #4094

@miguelff miguelff closed this Aug 1, 2023
jkomyno added a commit that referenced this pull request Aug 3, 2023
* Renames and restructure

* Use proxy in `JsQueryable::is_healthy`

* Change neon and planetscale drivers to  use a promise for the version

The promise executes aynchrounsly on constructor, but it's awaited whenever the version is required, particularly to provide consistent health information. Otherwise isHealthy would be returning false, while the promise hasn't resolved yet.

* feat: add child parent relation migration

* feat(js-connectors): add support for transactions in PlanetScale, without touching Rust

* chore: apply renames as in #4085

* chore: use switch case syntax

* chore: add hard error if we detect intertwine transaction

* feat(js-connectors): adopt Rust's "performIO" pattern to simplify isHealthy() and version()

* feat(js-connectors): implement "is_healthy()"

* feat(js-connectors): add data conversions for neon

* feat(js-connector): add common ConnectorConfig for PlanetScale and Neon

* feat(js-connector): update type mapping in neon, use common ConnectorConfig

* feat(js-connector): use common ConnectorConfig

* test(js-connector): split + centralise tests for PlanetScale and Neon, enable "@withFlavor" test decorator

* chore: update README.md

* chore: fix typo

* chore: fix typo

* chore: restore PlanetScale transactions

* fix: address review comments

* feat: simplify neon/planetscale data-type conversions

---------

Co-authored-by: Miguel Fernandez <[email protected]>
@janpio janpio deleted the mff/nps4 branch November 15, 2023 19:35
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.

3 participants