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

Adding shutdown support to sql-support #4816

Merged
merged 1 commit into from
Feb 2, 2022
Merged

Conversation

bendk
Copy link
Contributor

@bendk bendk commented Feb 1, 2022

I think 3rd time's the charm on this one. This PR is similar to #4805, but much simpler. It implements a shutdown system that hooks into the existing SqlInterruptScope and SqlInterruptHandler functionality, which means that the changes are a lot less invasive. We end up with each DB being able to create an SqlInterruptScope, but with a global shutdown mode, that interrupts all of those scopes. So we end up with being able to both globally shutdown everything and cause all operations to be interrupted and also locally shutdown a single operation (e.g. autocomplete).

You can test this with the places-utils script:
- Execute cargo run --example places-utils sync --nsyncs 2 --wait 1000

  • In the middle of the first sync hit ctrl-c
  • You should see that the first sync gets interrupted in the middle and the second sync interrupted as soon as it starts.

Pull Request checklist

  • Quality: This PR builds and tests run cleanly
    • Note:
      • For changes that need extra cross-platform testing, consider adding [ci full] to the PR title.
      • If this pull request includes a breaking change, consider cutting a new release after merging.
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Changelog: This PR includes a changelog entry in CHANGES_UNRELEASED.md or an explanation of why it does not need one
    • Any breaking changes to Swift or Kotlin binding APIs are noted explicitly
  • Dependencies: This PR follows our dependency management guidelines
    • Any new dependencies are accompanied by a summary of the due dilligence applied in selecting them.

@bendk bendk requested a review from mhammond February 1, 2022 23:07
/// - Calls `shutdown::register_interrupt_handle()` on creation
///
/// See `PlacesDb::begin_interrupt_scope()` and `PlacesApi::new_connection()` for an example of
/// how this works.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's kind of weird that this module is inside the sql-support crate, but it kind of needs to be because of how it integrates with SqlInterruptScope and SqlInterruptHandler. I think we should consider consider moving both shutdown.rs and interrupt.rs to the interrupt-support crate.

@codecov-commenter
Copy link

codecov-commenter commented Feb 1, 2022

Codecov Report

Merging #4816 (91d0bab) into main (d5c4909) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #4816   +/-   ##
=======================================
  Coverage   81.49%   81.49%           
=======================================
  Files          49       49           
  Lines        5653     5653           
=======================================
  Hits         4607     4607           
  Misses       1046     1046           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d5c4909...91d0bab. Read the comment docs.

Copy link
Member

@mhammond mhammond left a comment

Choose a reason for hiding this comment

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

Awesome, thanks for working through this!

When the user wants to shutdown the application, we should:
  - Interrupt all current `SqlInterruptScope`s
  - Interrupt all future `SqlInterruptScope`s when they're created.

The nice thing about this approach is that it didn't require invasive
changes in places to support it.  The main new requirement was we need
to have a way to get a `Weak<AsRef<SqlInterruptHandler>>` for each
database.  In order to support that, I needed to:

 - For the read/write and read-only connections: have `PlacesConnection`
   store an `SqlInterruptHandler` and implement `AsRef`.
 - For the sync connection: Added struct that wraps the
   `Mutex<PlacesDb>` and also stores a `SqlInterruptHandler` and
   implements `AsRef`.

Updated `places-utils` so that ctrl-c starts shutdown mode.
@bendk
Copy link
Contributor Author

bendk commented Feb 2, 2022

I think this is a step forward so I'm planning on merging once the checks pass. However, there are still several steps left to fully implement #1684. I left a comment in that ticket outlining the remaining work.

@bendk bendk merged commit d622b90 into mozilla:main Feb 2, 2022
@bendk bendk mentioned this pull request Feb 4, 2022
4 tasks
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.

None yet

3 participants