Skip to content

Conversation

@ajm188
Copy link
Contributor

@ajm188 ajm188 commented May 18, 2020

Closes #830. Switches from using QueryRow to QueryRowContext, and
stores a context.CancelFunc in the migration context, which is called to
halt any running row count query before beginning the cut over.

Note: I'm 99% sure database/sql does what I think it should do here. I wanted to open this now in case anyone else happens to know off-hand, but in the meantime I'll keep reading through the go stdlib to convince myself this is right.

Update on the above: I smartened up and read the docs instead of the code, which say go-sql-driver does support cancelling queries via contexts

In case this PR introduced Go code changes:

  • contributed code is using same conventions as original code
  • script/cibuild returns with no formatting errors, build errors or unit test errors.

Closes github#830. Switches from using `QueryRow` to `QueryRowContext`, and
stores a context.CancelFunc in the migration context, which is called to
halt any running row count query before beginning the cut over.
Copy link
Contributor

@shlomi-noach shlomi-noach left a comment

Choose a reason for hiding this comment

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

Thank you for this important fix! To the best of my understanding the termination of the rowcount query is not fully implemented in this PR, see comments inline.

Andrew Mason added 3 commits June 28, 2020 11:04
* Explicitly grab a connection to run the count, store its connection id
* When the query context is canceled, run a `KILL QUERY ?` on that connection id
@timvaillancourt timvaillancourt self-requested a review June 4, 2022 23:06
@timvaillancourt
Copy link
Collaborator

timvaillancourt commented Jun 4, 2022

@ajm188 this PR makes a lot of sense to me. Thanks a lot!

Do you mind rebasing the PR? I think the main change is the logger 🙏

@timvaillancourt timvaillancourt requested review from a user and rashiq June 4, 2022 23:08
@timvaillancourt
Copy link
Collaborator

@ajm188 I was able to fix the CI failures myself via the GitHub UI 🤯

@dm-2 / @rashiq can we merge this and test in a train of other recent PRs?

@ajm188
Copy link
Contributor Author

ajm188 commented Jun 6, 2022

@ajm188 I was able to fix the CI failures myself via the GitHub UI 🤯

awesome, thanks for taking care of it!

@ajm188
Copy link
Contributor Author

ajm188 commented Jun 21, 2022

@timvaillancourt any update on getting this merged? 🤞

@timvaillancourt timvaillancourt merged commit b751499 into github:master Jul 6, 2022
ghost pushed a commit that referenced this pull request Jul 7, 2022
* Cancel any row count queries before attempting to cut over

Closes #830. Switches from using `QueryRow` to `QueryRowContext`, and
stores a context.CancelFunc in the migration context, which is called to
halt any running row count query before beginning the cut over.

* Make it threadsafe

* Kill the count query on the database side as well

* Explicitly grab a connection to run the count, store its connection id
* When the query context is canceled, run a `KILL QUERY ?` on that connection id

* Rewrite these to use the threadsafe functions, stop exporting the cancel func

* Update logger

* Update logger

Co-authored-by: Tim Vaillancourt <timvaillancourt@github.com>
Co-authored-by: Tim Vaillancourt <tim@timvaillancourt.com>
Co-authored-by: dm-2 <45519614+dm-2@users.noreply.github.com>
@ghost ghost mentioned this pull request Jul 7, 2022
ghost pushed a commit that referenced this pull request Jul 7, 2022
* Cancel any row count queries before attempting to cut over

Closes #830. Switches from using `QueryRow` to `QueryRowContext`, and
stores a context.CancelFunc in the migration context, which is called to
halt any running row count query before beginning the cut over.

* Make it threadsafe

* Kill the count query on the database side as well

* Explicitly grab a connection to run the count, store its connection id
* When the query context is canceled, run a `KILL QUERY ?` on that connection id

* Rewrite these to use the threadsafe functions, stop exporting the cancel func

* Update logger

* Update logger

Co-authored-by: Tim Vaillancourt <timvaillancourt@github.com>
Co-authored-by: Tim Vaillancourt <tim@timvaillancourt.com>
Co-authored-by: dm-2 <45519614+dm-2@users.noreply.github.com>
RainbowDashy pushed a commit to RainbowDashy/gh-ost that referenced this pull request Jul 13, 2022
* Cancel any row count queries before attempting to cut over

Closes github#830. Switches from using `QueryRow` to `QueryRowContext`, and
stores a context.CancelFunc in the migration context, which is called to
halt any running row count query before beginning the cut over.

* Make it threadsafe

* Kill the count query on the database side as well

* Explicitly grab a connection to run the count, store its connection id
* When the query context is canceled, run a `KILL QUERY ?` on that connection id

* Rewrite these to use the threadsafe functions, stop exporting the cancel func

* Update logger

* Update logger

Co-authored-by: Tim Vaillancourt <timvaillancourt@github.com>
Co-authored-by: Tim Vaillancourt <tim@timvaillancourt.com>
Co-authored-by: dm-2 <45519614+dm-2@users.noreply.github.com>
@ajm188 ajm188 deleted the am_cancel_row_counts branch February 22, 2023 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The --exact-rowcount option is buggy on large tables

3 participants